Java – Create a custom lint Java detector

Create a custom lint Java detector… here is a solution to the problem.

Create a custom lint Java detector

I’m trying to create a custom rule for lint, which will alter the existing deprecation warning test.

The documentation I’ve read so far tells me almost no how to implement a class (I think needed) that implements Detector.JavaScanner

http://tools.android.com/tips/lint-custom-rules

I

guess this is a fairly general question, but anyone who knows about this issue, or where can I find actually useful documentation on this issue?

Thanks!

Solution

There is very little documentation in this area, so don’t worry if you don’t find more.

The best way to start custom lint rule development is actually to tweak existing rules, as mentioned earlierhere

Here’s where the Android default rule set comes from: Choose an implementation JavaScanner to see how it works.

If you’re looking for a basic Gradle-based project template for custom rules, check out one custom rule I created. Simply replace the HardcodedValueDetector with your detector and reference it in the CustomIssuesRegistry.

One final note: I held a workshop at Droidcon 2015 in Berlin detailing how to write custom lint rules. Part of it is on JavaScanners. After that workshop, I’ll post all the resources.

Related Problems and Solutions