Newify classNamePattern support: Non-static inner classes ?

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Newify classNamePattern support: Non-static inner classes ?

@Newify classNamePattern support ( looks to be working (I am using maps for lookup everywhere and have added globally available types explicitely in NewifyASTTransformation), except for non-static inner classes. The test below fails with:

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: Foo$A(String)

The same test with static inner classes (e.g. @Canonical static class A { String a }) is green.

How do I make this work ?
Or should we not support non-static inner classes for Newify with classNamePattern for now ?

void testInnerClassNewifyWithNamePattern() {
  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

      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") ]
          [ l.collect { it.getClass().getCanonicalName() }, l.collect { it.toString() } ]
      final Foo foo = new Foo()

  println "script=|$script|"
  final List resultList = (List) evalScript(script)
  println "result=$resultList"

  assert resultList[0] == ['Foo.A', 'Foo.AB', 'Foo.ABC']
  assert resultList[1] == ['Foo$A(2018-04-08)', 'Foo$AB(I am, class AB)', 'Foo$ABC(A, B, C)']