I am an Android developer. I already developed my own lint rules by running the new XXXDetector and XXXIssueRegistry, here is my snip source code:
My XXXIssueRegistry file:
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); } }
My XXXDetector file:
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`"); } } }
Now I can run my custom lint rules with the runnig command:
$gradle lint
And I will get the output message as I expected in the console.
But I want to debug the source XXXDetector file. How can i do this? If I press "debug" or "run" or "build", my custom lint rules will not run! Therefore, I have to run it in a console that does not support debug. How can i solve this?