9

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. How can I access the capture group ($1)
  2. Is it possible to perform any processing on $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.

SSR search template instance variable config property variable config

Community
  • 1
  • 1
kierans
  • 2,034
  • 1
  • 16
  • 43

1 Answers1

7

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) 
Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
parsons
  • 221
  • 2
  • 3
  • Geweldige @bas-leijdekkers! absolutely outstanding! – 62mkv Nov 09 '17 at 07:46
  • 2
    for those seeking some more examples of structural replacement: https://gist.github.com/62mkv/d1cdbac42e225d157226b3f8337c84af – 62mkv Nov 09 '17 at 08:12