void () { final String in = """ class A { void method(Object... os) {} void f(Object a, Object b, Object c) { method(a, b, c, "one" + "two"); method(a); } }"""; final String what = "method('_arg+)"; final String by = "method($newarg$)"; final ReplacementVariableDefinition variable = options.addNewVariableDefinition("newarg"); variable.setScriptCodeConstraint("arg.collect { \"(String)\" + it.getText() }.join(',')"); final String expected = """ class A { void method(Object... os) {} void f(Object a, Object b, Object c) { method((String)a,(String)b,(String)c,(String)"one" + "two"); method((String)a); } }"""; assertEquals(expected, replace(in, what, by)); options.clearVariableDefinitions(); final String in2 = """ class Limitless { public int id; public String field; public Limitless() { this.field = "default"; this.id = 01; } public int getId() { return id; } public String getField() { return field; } public static void main(String [] args) { Limitless myClass = new Limitless(); System.out.println(myClass.getField()+" "+myClass.getId()); Example example = new Example(1, "name"); int r = example.getI()+9; myClass.getId(); } }"""; final String what2 = "'_Instance:[exprtype( Limitless )].'property:[regex( get(.*) )]()"; final String by2 = "$Instance$.$field$"; final ReplacementVariableDefinition variable2 = options.addNewVariableDefinition("field"); variable2.setScriptCodeConstraint("String name = property.methodExpression.referenceName[3..-1]\n" + "name[0].toLowerCase() + name[1..-1]"); assertEquals(""" class Limitless { public int id; public String field; public Limitless() { this.field = "default"; this.id = 01; } public int getId() { return id; } public String getField() { return field; } public static void main(String [] args) { Limitless myClass = new Limitless(); System.out.println(myClass.field+" "+myClass.id); Example example = new Example(1, "name"); int r = example.getI()+9; myClass.id; } }""", replace(in2, what2, by2)); options.clearVariableDefinitions(); }