I am trying to migrate an annotation from a field to it's getter using Intellij's fancy structural replace:
From:
class MyClass {
@SomeAnnotation
private final double a;
@SomeAnnotation
private final double b;
public double getA() {
return a;
}
public double getB() {
return b;
}
}
To:
class MyClass {
private final double a;
private final double b;
@SomeAnnotation
public double getA() {
return a;
}
@SomeAnnotation
public double getB() {
return b;
}
}
I am most of the way there with:
Search template:
class $Class$ {
@SomeAnnotation
private final $type$ $fieldName$;
public $type$ $getter$() {
return $value$;
}
}
Replace template:
class $Class$ {
private final $type$ $fieldName$;
@SomeAnnotation
public $type$ $getter$() {
return $value$;
}
}
There is also a filter on getter that matches get.*
, and a Script on the whole template to try to make sure we find the matching getter:
if (getter.name.toLowerCase().contains(fieldName.get(0).name.toLowerCase())) {
return true;
}
return false;
The problem is that this only matches the first getter, and the script doesn't get a chance to try with all of them.
Any way I could alter my search for this to work?