I am investigation custom Lint Rules development in my current Android Application.
My detector finds all Activities in my project that are not annotated with a specific annotation.
I would like to create a LintFix that adds the missing annotation as follows:-
Activity in Error
class MyActivity : AppCompatActivity() {
...
}
Activity fixed
@MyMissingAnnotation
class MyActivity : AppCompatActivity() {
...
}
The code I have developed is :-
val fix = LintFix.create()
.replace()
.text("")
.with("@MyMissingAnnotation")
.build()
however this results in the following corrupt code
class @MyMissingAnnotationMyActivity : AppCompatActivity() {
...
}
as my report resembles this
context.report(
ISSUE, node,
context.getNameLocation(node),
"Activities require the @MyMissingAnnotation annotation.",
fix
)
How can I add the required annotation at the correct location in my class?