Replace property getters with IntelliJ Structural Search and Replace

Due to changes in the library I'm using, getters have been replaced with direct access to the property. For example:

public class MyLibraryClass { private String field; public String getField() { return field; } } 

has become

 public class MyLibraryClass { public String field; } 

Therefore, I would like to use the IntelliJ SSR to replace getter calls with the Bean property. However, I am stuck on how to use regexp capture groups for my replacement. If there is another IntelliJ shortcut to accomplish what I want, I'm glad to use it.

The following SSR search options find getters, but it seems I can not use the capture group for $property$ in the replacement. I tried \1 and \$1 and $1 to see ( using backlinks in IntelliJ )

I also tried changing the search to $instance$.get$property$() (clearing the constraints for $property$ , but the search did not return any results.

  • How to access the capture group ( $1 )
  • Is it possible to do any processing at $1 before replacing (to fix the case)

I noticed a Script text parameter that accepts Groovy code, however I could not find the documentation for this function.

SSR search templateinstance variable configproperty variable config

+8
intellij-idea intellij-13 structural-search
source share
1 answer

Insert the replacement template $instance$.$field$ . This template introduces a new field variable, which should contain the following script text:

 String name = property.methodExpression.referenceName.substring(3) name[0].toLowerCase() + name.substring(1) 
+5
source share

All Articles