Android Logger探测器自定义点击

时间:2017-01-03 15:59:51

标签: android lint android-lint

我正在尝试编写一个自定义linter,它可以在项目中找到Log类的任何用法。

所有东西都编译好了,而且我确实有其他能够很好地工作的短绒,所以看起来所有东西都应该按照它应该被整合。

你能告诉我我错过了什么吗?

public class LoggerUsageDetector extends Detector
    implements Detector.ClassScanner {

public static final Issue ISSUE = Issue.create("SywLogIsNotUsed",
        "You must use our `SywLog`",
        "Logging should be avoided in production for security and performance reasons."
        + " Therefore, we created a SywLog that wraps all our calls to Logger and disable them for release flavor.",
        Category.CORRECTNESS,
        9,
        Severity.FATAL,
        new Implementation(LoggerUsageDetector.class,
                Scope.CLASS_FILE_SCOPE));

@Override
public List<String> getApplicableCallNames() {
    return Arrays.asList("v", "d", "i", "w", "e", "wtf");
}

@Override
public List<String> getApplicableMethodNames() {
    return Arrays.asList("v", "d", "i", "w", "e", "wtf");
}

@Override
public void checkCall(@NonNull ClassContext context,
                      @NonNull ClassNode classNode,
                      @NonNull MethodNode method,
                      @NonNull MethodInsnNode call) {
        context.report(ISSUE,
                method,
                call,
                context.getLocation(call),
                "You must use our `SywLog`");

}
}

以下是注册表:

public class LintersIssueRegistry extends IssueRegistry {

@Override
public List<Issue> getIssues() {
    return new ArrayList<Issue>() {{
        add(MyAnnotationDetector.CAREFUL_NOW_ISSUE);
        add(LoggerUsageDetector.ISSUE);
    }};
}

}

应该抛出错误的“目标”代码:

    private void doSomething() {
    Log.v("ta", "");
    Log.d("ta", "");
    Log.wtf("ta", "");
}

0 个答案:

没有答案