当我为Lint实现自定义检测器时,如何调试java源代码?
我是一名安卓开发者。我已经通过实现新的XXXDetector和XXXIssueRegistry来设计自己的lint规则,这是我的源代码片段:
我的 XXXIssueRegistry 文件:
public class MyIssueRegistry extends IssueRegistry {
@Override
public List<Issue> getIssues() {
System.out.println("!!!!!!!!!!!!! ljf MyIssueRegistry lint rules works");
return Arrays.asList(AttrPrefixDetector.ISSUE,
LoggerUsageDetector.ISSUE);
}
}
我的 XXXDetector 文件:
public class LoggerUsageDetector extends Detector
implements Detector.ClassScanner {
public static final Issue ISSUE = Issue.create("LogUtilsNotUsed",
"You must use our `LogUtils`",
"Logging should be avoided in production for security and performance reasons. Therefore, we created a LogUtils that wraps all our calls to Logger and disable them for release flavor.",
Category.MESSAGES,
9,
Severity.ERROR,
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) {
String owner = call.owner;
if (owner.startsWith("android/util/Log")) {
context.report(ISSUE,
method,
call,
context.getLocation(call),
"You must use our `LogUtils`");
}
}
}
现在我可以通过runnig命令运行我的自定义lint规则:
$gradle lint
我将像在控制台中预期的那样获得输出消息。
但是我想调试我的XXXDetector源文件。我该怎么做?如果我单击“调试”或“运行”或“构建”,我的自定义lint规则将不会运行!所以我必须在不支持调试的控制台中运行它。我该如何解决这个问题?