package com.squirrel_explorer.eagleeye.lint.rules.performance.system;

import com.android.tools.lint.detector.api.JavaContext;
import com.squirrel_explorer.eagleeye.types.base.BaseAstVisitor;

import lombok.ast.ConstructorInvocation;
import lombok.ast.TypeReference;

/**
 * Created by squirrel-explorer on 16/02/22.
 */
public class NewMessageAstVisitor extends BaseAstVisitor {
    public NewMessageAstVisitor(JavaContext context) {
        super(context);
    }

    @Override
    public boolean visitConstructorInvocation(ConstructorInvocation node) {
        TypeReference typeRef = node.astTypeReference();
        if (null != typeRef && "Message".equals(typeRef.getTypeName())) {
            mContext.report(
                    NewMessageDetector.ISSUE,
                    mContext.getLocation(node),
                    "Please use Message.obtain() instead of new Message()"
            );
        }

        return super.visitConstructorInvocation(node);
    }
}

@@ -64,16 +64,69 @@
 ystem;%0A%0A
+import com.android.tools.lint.client.api.JavaParser;%0A
 import c
@@ -173,16 +173,16 @@
 ontext;%0A
-
 import c
@@ -283,41 +283,8 @@
 ion;
-%0Aimport lombok.ast.TypeReference;
 %0A%0A/*
@@ -581,126 +581,466 @@
     
-TypeReference typeRef = node.astTypeReference();%0A        if (null != typeRef && %22Message%22.equals(typeRef.getTypeName()
+JavaParser.ResolvedNode resolvedNode = mContext.resolve(node);%0A        if (!(resolvedNode instanceof JavaParser.ResolvedMethod)) %7B%0A            return super.visitConstructorInvocation(node);%0A        %7D%0A        JavaParser.ResolvedMethod resolvedMethod = (JavaParser.ResolvedMethod)resolvedNode;%0A%0A        JavaParser.ResolvedClass typeClass = resolvedMethod.getContainingClass();%0A        if (null != typeClass && typeClass.isSubclassOf(%22android.os.Message%22, false
 )) %7B

更新NewMessageDetector规则，提升检测的准确性