Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6865

@Delegate does not work with generated stubs

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.3.2
    • None
    • None

    Description

      I created a groovy class containing a delegate. The delegate has a getter:

      class SomeGroovyClass {
          @Delegate
          SomeDelegate delegate
      
          SomeGroovyClass(SomeDelegate delegate) {
              this.delegate = delegate
          }
      }
      
      class SomeDelegate {
      
          String value
      
          SomeDelegate(String value) {
              this.value = value
          }
      }
      

      I have a java client creating the groovy class:

      public class Client {
          public static void main(String[] args) {
              SomeDelegate delegate = new SomeDelegate("val1");
              System.out.println(delegate.getValue());
      
              SomeGroovyClass groovyClass = new SomeGroovyClass(delegate);
              System.out.println(groovyClass.getValue());
      
          }
      }
      

      When I compile this using the GMavenPlus plugin in maven, I get the following error:

      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project delegateTest: Compilation failure
      [ERROR] C:\dev\projects\delegateTest\src\main\java\Client.java:[24,38] error: cannot find symbol
      

      This is because the generated stub doesn't contain the getValue() method from the delegate:

      import java.lang.*;
      import java.io.*;
      import java.net.*;
      import java.util.*;
      import groovy.lang.*;
      import groovy.util.*;
      
      public class SomeGroovyClass
        extends java.lang.Object  implements
          groovy.lang.GroovyObject {
      public SomeGroovyClass
      (SomeDelegate delegate) {}
      public  groovy.lang.MetaClass getMetaClass() { return (groovy.lang.MetaClass)null;}
      public  void setMetaClass(groovy.lang.MetaClass mc) { }
      public  java.lang.Object invokeMethod(java.lang.String method, java.lang.Object arguments) { return null;}
      public  java.lang.Object getProperty(java.lang.String property) { return null;}
      public  void setProperty(java.lang.String property, java.lang.Object value) { }
      public  SomeDelegate getDelegate() { return (SomeDelegate)null;}
      public  void setDelegate(SomeDelegate value) { }
      }
      

      You can find a sample in attachment using maven

      Attachments

        1. delegateTest.zip
          4 kB
          Jan Bols

        Issue Links

          Activity

            People

              Unassigned Unassigned
              janbols Jan Bols
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: