[
https://issues.apache.org/jira/browse/GROOVY-6865?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149103#comment-18149103
]
Daniel Sun commented on GROOVY-6865:
------------------------------------
Fixed on master; added a regression test in
209597f34058ff763ec6425559829befaa01534d
(https://github.com/apache/groovy/commit/209597f34058ff763ec6425559829befaa01534d).
> @Delegate does not work with generated stubs
> --------------------------------------------
>
> Key: GROOVY-6865
> URL: https://issues.apache.org/jira/browse/GROOVY-6865
> Project: Groovy
> Issue Type: Bug
> Components: Stub generator / Joint compiler
> Affects Versions: 2.3.2
> Reporter: Jan Bols
> Assignee: Daniel Sun
> Priority: Major
> Fix For: 7.0.0-alpha-1
>
> Attachments: delegateTest.zip
>
>
> I created a groovy class containing a delegate. The delegate has a getter:
> {code}
> class SomeGroovyClass {
> @Delegate
> SomeDelegate delegate
> SomeGroovyClass(SomeDelegate delegate) {
> this.delegate = delegate
> }
> }
> class SomeDelegate {
> String value
> SomeDelegate(String value) {
> this.value = value
> }
> }
> {code}
> I have a java client creating the groovy class:
> {code}
> 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());
> }
> }
> {code}
> When I compile this using the GMavenPlus plugin in maven, I get the following
> error:
> {code}
> [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
> {code}
> This is because the generated stub doesn't contain the {{getValue()}} method
> from the delegate:
> {code}
> 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) { }
> }
> {code}
> You can find a sample in attachment using maven
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)