I'm trying to figure out a Structural replacement template in IntelliJ IDEA (future inspection) for adding a missing annotation to a class/interface/enum without removing any other existing annotations.
So far I tried several varieties of following
Search template:
@$OtherPossibleAnnotation$ // min: 0, max: 0, text/regexp: AnnotationName, invert condition: true
@$MissingAnnotation$ // min: 0, max: 0, text/regexp: AnnotationName
class $C$ {
$Content$ // min: 0, max: unlimited
}
Replacement template:
@$OtherPossibleAnnotation$
@AnnotationName
class $C$ {
$Content$
}
But none of my attempts worked. I expect it to work
- with any set of existing class annotations and it must also keep their potential values,
- if there is no annotation on the class at all,
- in Idea 14 as well as in Idea 15,
- should also keep content of the class untouched.
So for instance following
@ProductArea("Area A")
class A {
public void method1() {
System.out.println("Should remain");
}
}
should be replaced with
@ProductArea("Area A")
@AnnotationName
class A {
public void method1() {
System.out.println("Should remain");
}
}
Could someone please advise?