Due to changes in a library I'm using, the getters were replaced with direct access to the property. Eg:
public class MyLibraryClass {
private String field;
public String getField() { return field; }
}
has become
public class MyLibraryClass {
public String field;
}
Consequently I'd want to use IntelliJ's SSR to replace the getter calls with the Bean property. However I've gotten stuck on how to use regexp capture groups for my replacement. If there's another IntelliJ shortcut to do what I want, I'm happy to use it.
The following SSR search parameters find the getters, but I can't seem to be able to use the capture group for $property$
in the replacement. I've tried \1
and \$1
and $1
see (using backreferences in IntelliJ)
I also tried changing the search to $instance$.get$property$()
(clearing the constraints for $property$
but the search didn't return any results.
$1
)$1
before substitution (to fix the case)I noticed the Script text
option which accepts Groovy code, however I couldn't find any documentation on this feature.
From the main menu, select Edit | Find | Search Structurally. In the Structural Search dialog, under the Java | Class-based node, select All Fields of a Class which will look for all field declarations and click Find. As a result, in the Find tool window, IntelliJ IDEA shows all the fields declared in our Java code.
Press Ctrl+R or select Edit | Find | Replace from the main menu to open the Replace in File window. located in the replace field. for a multi-line replace. For example, if you want to replace a comma with a comma and a new line, enter a comma in the search field and a comma and the new line in the replace field.
Press Ctrl+H or choose Edit | Find | Replace from the main menu. The search and replace pane appears on top of the active editor. If necessary, specify the search and replace options. In the search field, start typing the search string.
Put in the replacement template $instance$.$field$
. This template introduces new variable field
which should contain following script text:
String name = property.methodExpression.referenceName.substring(3)
name[0].toLowerCase() + name.substring(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With