@@ -29,64 +29,61 @@ import org.jetbrains.uast.ULiteralExpression
29
29
import org.jetbrains.uast.evaluateString
30
30
31
31
/* *
32
- * Sample detector showing how to analyze Kotlin/Java code. This example
33
- * flags all string literals in the code that contain the word "lint".
32
+ * Sample detector showing how to analyze Kotlin/Java code. This example flags all string literals
33
+ * in the code that contain the word "lint".
34
34
*/
35
- @Suppress(" UnstableApiUsage" )
36
35
class SampleCodeDetector : Detector (), UastScanner {
37
- override fun getApplicableUastTypes (): List <Class <out UElement ?>> {
38
- return listOf (ULiteralExpression ::class .java)
39
- }
36
+ override fun getApplicableUastTypes (): List <Class <out UElement ?>> {
37
+ return listOf (ULiteralExpression ::class .java)
38
+ }
40
39
41
- override fun createUastHandler (context : JavaContext ): UElementHandler {
42
- // Note: Visiting UAST nodes is a pretty general purpose mechanism;
43
- // Lint has specialized support to do common things like "visit every class
44
- // that extends a given super class or implements a given interface", and
45
- // "visit every call site that calls a method by a given name" etc.
46
- // Take a careful look at UastScanner and the various existing lint check
47
- // implementations before doing things the "hard way".
48
- // Also be aware of context.getJavaEvaluator() which provides a lot of
49
- // utility functionality.
50
- return object : UElementHandler () {
51
- override fun visitLiteralExpression (node : ULiteralExpression ) {
52
- val string = node.evaluateString() ? : return
53
- if (string.contains(" lint" ) && string.matches(Regex (" .*\\ blint\\ b.*" ))) {
54
- context.report(
55
- ISSUE , node, context.getLocation(node) ,
56
- " This code mentions `lint`: **Congratulations** "
57
- )
58
- }
59
- }
40
+ override fun createUastHandler (context : JavaContext ): UElementHandler {
41
+ // Note: Visiting UAST nodes is a pretty general purpose mechanism;
42
+ // Lint has specialized support to do common things like "visit every class
43
+ // that extends a given super class or implements a given interface", and
44
+ // "visit every call site that calls a method by a given name" etc.
45
+ // Take a careful look at UastScanner and the various existing lint check
46
+ // implementations before doing things the "hard way".
47
+ // Also be aware of context.getJavaEvaluator() which provides a lot of
48
+ // utility functionality.
49
+ return object : UElementHandler () {
50
+ override fun visitLiteralExpression (node : ULiteralExpression ) {
51
+ val string = node.evaluateString() ? : return
52
+ if (string.contains(" lint" ) && string.matches(Regex (" .*\\ blint\\ b.*" ))) {
53
+ context.report(
54
+ ISSUE ,
55
+ node,
56
+ context.getLocation(node),
57
+ " This code mentions `lint`: **Congratulations** " ,
58
+ )
60
59
}
60
+ }
61
61
}
62
+ }
62
63
63
- companion object {
64
- /* *
65
- * Issue describing the problem and pointing to the detector
66
- * implementation.
67
- */
68
- @JvmField
69
- val ISSUE : Issue = Issue .create(
70
- // ID: used in @SuppressLint warnings etc
71
- id = " SampleId" ,
72
- // Title -- shown in the IDE's preference dialog, as category headers in the
73
- // Analysis results window, etc
74
- briefDescription = " Lint Mentions" ,
75
- // Full explanation of the issue; you can use some markdown markup such as
76
- // `monospace`, *italic*, and **bold**.
77
- explanation = """
78
- This check highlights string literals in code which mentions the word `lint`. \
79
- Blah blah blah.
64
+ companion object {
65
+ /* * Issue describing the problem and pointing to the detector implementation. */
66
+ @JvmField
67
+ val ISSUE : Issue =
68
+ Issue .create(
69
+ // ID: used in @SuppressLint warnings etc
70
+ id = " SampleId" ,
71
+ // Title -- shown in the IDE's preference dialog, as category headers in the
72
+ // Analysis results window, etc
73
+ briefDescription = " Lint Mentions" ,
74
+ // Full explanation of the issue; you can use some markdown markup such as
75
+ // `monospace`, *italic*, and **bold**.
76
+ explanation =
77
+ """
78
+ This check highlights string literals in code which mentions the word `lint`. \
79
+ Blah blah blah.
80
80
81
- Another paragraph here.
82
- """ , // no need to .trimIndent(), lint does that automatically
83
- category = Category .CORRECTNESS ,
84
- priority = 6 ,
85
- severity = Severity .WARNING ,
86
- implementation = Implementation (
87
- SampleCodeDetector ::class .java,
88
- Scope .JAVA_FILE_SCOPE
89
- )
90
- )
91
- }
81
+ Another paragraph here.
82
+ """ , // no need to .trimIndent(), lint does that automatically
83
+ category = Category .CORRECTNESS ,
84
+ priority = 6 ,
85
+ severity = Severity .WARNING ,
86
+ implementation = Implementation (SampleCodeDetector ::class .java, Scope .JAVA_FILE_SCOPE ),
87
+ )
88
+ }
92
89
}
0 commit comments