我是Android开发人员。 我已经通过实现新的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源文件。我怎样才能做到这一点? 如果我点击&#34; debug&#34;或&#34;运行&#34;或&#34;构建&#34; ,我的自定义lint规则不会运行!所以我必须在控制台中运行它,它不支持调试。 我该如何解决这个问题?