Passing the outer class' this reference explicitely to the non-static inner classes' ctors makes the test green (see below; evidently this is not necessary when using the new keyword). Any suggestions on how to best adapt the code to achieve this behavior ?
Here is the Github of the current state of Newify classNamePattern support:


@Test void testInnerClassesNewifyWithNamePattern() {
final String script =""" import groovy.transform.Canonical import groovy.transform.CompileStatic import groovy.lang.Newify import groovy.transform.ASTTest import static org.codehaus.groovy.control.CompilePhase.SEMANTIC_ANALYSIS @Newify(classNamePattern=/[A-Z].*/) class Foo { @Canonical class A { String a } @Canonical class AB { String a; String b } @Canonical class ABC { String a; String b; String c } List createClassList() { //final l = [ A('2018-04-08'), AB("I am", "class AB"), ABC("A","B","C") ] final l = [ A(this, '2018-04-08'), AB(this, "I am", "class AB"), ABC(this, "A","B","C") ] [ l.collect { it.getClass().getCanonicalName() }, l.collect { it.toString() } ] } } final Foo foo = new Foo() foo.createClassList() """ println"script=|$script|" final List resultList = (List)evalScript(script)
  println"result=$resultList" assert resultList[0] == 
  assert resultList[1] == ['Foo$A(2018-04-08)','Foo$AB(I am, class 
AB)','Foo$ABC(A, B, C)']

Reply via email to