[project lombok] Cannot find symbol after handler successfully creates COMPILATION_UNIT JavacNode

492 views
Skip to first unread message

Franz Allan Valencia See

unread,
May 11, 2010, 9:38:31 AM5/11/10
to Project Lombok
Good day,

I've been playing (still) with Lombok, and I ran into some trouble again. 

I am trying to create an @DelegateTo annotation. Currently, I'm trying to aim for a simple transformation, which is :

Given:
package see.fa.pract.lombok;

public class DelegatingClass {

public String greetings(String name) {
return "greetings " + name;
}
public int add(int a1, int a2) {
return a1 + a2;
}
}

and:
package see.fa.pract.lombok;

import lombok.DelegateTo;

public class DelegateTarget {

    @DelegateTo("see.fa.pract.lombok.DelegatingClass")
    private DelegatingClass delegate;

    public DelegateTarget(DelegatingClass delegate) {
        this.delegate = delegate;
    }
}

when javac compile
then:

package see.fa.pract.lombok;

public class DelegateTarget {
    private DelegatingClass delegate;
    
    public DelegateTarget(DelegatingClass delegate) {
        this.delegate = delegate;
    }
    
    public int add(final int arg0, final int arg1) {
        return this.delegate.add(arg0, arg1);
    }
    
    public java.lang.String greetings(final java.lang.String arg0) {
        return this.delegate.greetings(arg0);
    }
}

(Note: my target output is a valid java class which compiles. I tried replacing my @DelegateTarget-powered DelegateTarget with this desired DelegateTarget output and it compiles ).

After creating my @DelegateTo annotation and my DelegateToHandler JavacAnnotationHandler, I tried it on a sample project while running on debug mode. 

In lombok.javac.JavacNode:62, I can observe that COMPILATION_UNIT JavacNode has the following value:

package see.fa.pract.lombok;

public class DelegateTarget {
    private DelegatingClass delegate;
    
    public DelegateTarget(DelegatingClass delegate) {
        this.delegate = delegate;
    }
    
    public int add(final int arg0, final int arg1) {
        return this.delegate.add(arg0, arg1);
    }
    
    public java.lang.String greetings(final java.lang.String arg0) {
        return this.delegate.greetings(arg0);
    }
}
 
which is what I expected. Then continuing on the debug mode, it seems to exit without having a Throwable thrown (I added a breakpoint against Throwable but it never stopped on that).

However, while continuing with the compilation, I got this (on verbose mode):

...
[INFO] Compilation failure
Failure executing javac, but could not parse the error:
[parsing started /home/franz/src/lombok-sample/under-test/src/main/java/see/fa/pract/lombok/DelegateTarget.java]
[parsing completed 20ms]
[parsing started /home/franz/src/lombok-sample/under-test/src/main/java/see/fa/pract/lombok/HelloTarget.java]
[parsing completed 1ms]
[search path for source files: /home/franz/src/lombok-sample/under-test/target/classes,/home/franz/src/lombok-sample/dependency/target/lombok-sample-dependency-1.0-SNAPSHOT.jar,/home/franz/data/repository/org/projectlombok/lombok/0.9.3-EDGE/lombok-0.9.3-EDGE.jar,.]
[search path for class files: /opt/java/64/jdk1.6.0_17/jre/lib/resources.jar,/opt/java/64/jdk1.6.0_17/jre/lib/rt.jar,/opt/java/64/jdk1.6.0_17/jre/lib/sunrsasign.jar,/opt/java/64/jdk1.6.0_17/jre/lib/jsse.jar,/opt/java/64/jdk1.6.0_17/jre/lib/jce.jar,/opt/java/64/jdk1.6.0_17/jre/lib/charsets.jar,/opt/java/64/jdk1.6.0_17/jre/classes,/opt/java/64/jdk1.6.0_17/jre/lib/ext/dnsns.jar,/opt/java/64/jdk1.6.0_17/jre/lib/ext/sunjce_provider.jar,/opt/java/64/jdk1.6.0_17/jre/lib/ext/sunpkcs11.jar,/opt/java/64/jdk1.6.0_17/jre/lib/ext/localedata.jar,/home/franz/src/lombok-sample/under-test/target/classes,/home/franz/src/lombok-sample/dependency/target/lombok-sample-dependency-1.0-SNAPSHOT.jar,/home/franz/data/repository/org/projectlombok/lombok/0.9.3-EDGE/lombok-0.9.3-EDGE.jar,.]
[loading lombok/DelegateTo.class(lombok:DelegateTo.class)]
[loading java/lang/Object.class(java/lang:Object.class)]
[loading see/fa/pract/lombok/DelegatingClass.class(see/fa/pract/lombok:DelegatingClass.class)]
[loading lombok/Getter.class(lombok:Getter.class)]
[loading lombok/Setter.class(lombok:Setter.class)]
[loading lombok/Hello.class(lombok:Hello.class)]
[loading java/lang/String.class(java/lang:String.class)]
[loading java/lang/annotation/Annotation.class(java/lang/annotation:Annotation.class)]
[loading java/lang/annotation/Target.class(java/lang/annotation:Target.class)]
[loading java/lang/annotation/ElementType.class(java/lang/annotation:ElementType.class)]
[loading java/lang/annotation/Retention.class(java/lang/annotation:Retention.class)]
[loading java/lang/annotation/RetentionPolicy.class(java/lang/annotation:RetentionPolicy.class)]
[loading lombok/AccessLevel.class(lombok:AccessLevel.class)]
Round 1:
input files: {see.fa.pract.lombok.DelegateTarget, see.fa.pract.lombok.HelloTarget}
annotations: [lombok.DelegateTo, lombok.Getter, lombok.Setter, lombok.Hello]
last round: false
Processor lombok.core.AnnotationProcessor matches [lombok.Getter, lombok.DelegateTo, lombok.Setter, lombok.Hello] and returns false.
Round 2:
input files: {}
annotations: []
last round: true
[search path for source files: /home/franz/src/lombok-sample/under-test/target/classes,/home/franz/src/lombok-sample/dependency/target/lombok-sample-dependency-1.0-SNAPSHOT.jar,/home/franz/data/repository/org/projectlombok/lombok/0.9.3-EDGE/lombok-0.9.3-EDGE.jar,.]
[search path for class files: /opt/java/64/jdk1.6.0_17/jre/lib/resources.jar,/opt/java/64/jdk1.6.0_17/jre/lib/rt.jar,/opt/java/64/jdk1.6.0_17/jre/lib/sunrsasign.jar,/opt/java/64/jdk1.6.0_17/jre/lib/jsse.jar,/opt/java/64/jdk1.6.0_17/jre/lib/jce.jar,/opt/java/64/jdk1.6.0_17/jre/lib/charsets.jar,/opt/java/64/jdk1.6.0_17/jre/classes,/opt/java/64/jdk1.6.0_17/jre/lib/ext/dnsns.jar,/opt/java/64/jdk1.6.0_17/jre/lib/ext/sunjce_provider.jar,/opt/java/64/jdk1.6.0_17/jre/lib/ext/sunpkcs11.jar,/opt/java/64/jdk1.6.0_17/jre/lib/ext/localedata.jar,/home/franz/src/lombok-sample/under-test/target/classes,/home/franz/src/lombok-sample/dependency/target/lombok-sample-dependency-1.0-SNAPSHOT.jar,/home/franz/data/repository/org/projectlombok/lombok/0.9.3-EDGE/lombok-0.9.3-EDGE.jar,.]
[loading java/lang/Object.class(java/lang:Object.class)]
[loading see/fa/pract/lombok/DelegatingClass.class(see/fa/pract/lombok:DelegatingClass.class)]
error: cannot find symbol
symbol  : class int
location: class see.fa.pract.lombok.DelegateTarget
[loading java/lang/String.class(java/lang:String.class)]
[checking see.fa.pract.lombok.DelegateTarget]
[checking see.fa.pract.lombok.HelloTarget]
[total 894ms]
1 error
...
Any ideas why there's a "cannot find symbol" compilation error?

Note: 
I tried modifying the signatures of DelegateTargets to narrow down the problem:
* DelegateTarget#add(int,int):int into DelegateTarget#add(Integer,Integer):Integer results to a : ''error: cannot find symbol ... symbol  : class java.lang.Integer".
* Removing DelegateTarget#add(int,int):int results to a ''error: cannot find symbol ... symbol  : class java.lang.String".
* Removing both DelegateTarget#add(int,int):int and DelegateTarget#greetings(String):String results to a successful compilation

Thanks,
--
Franz Allan Valencia See | Java Software Engineer
fran...@gmail.com
LinkedIn: http://www.linkedin.com/in/franzsee
Twitter: http://www.twitter.com/franz_see

--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/
 
To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en
Message has been deleted

Reinier Zwitserloot

unread,
May 11, 2010, 3:21:22 PM5/11/10
to Project Lombok
You sort of jumped over a big step there - you applied resolution.
You're querying (somehow - care to share some code?) the methods in
see.fa.pract.lombok.DelegatingClass so you can recreate them in
DelegateTarget. We haven't tackled resolution yet, partly because when
we reason it through it should be more complicated than it apparently
seems to be, and partly because in eclipse resolution works quite
differently.

Possibly by calling whatever methods you used to figure out the
methods, the ordering within javac's own process gets distorted. i.e.
you're creating new MethodInvocation etc. AST nodes *after* resolution
has occurred, and thus they don't get resolved, and as a result
perfectly valid-looking types such as "int" or "Integer" aren't in the
symbol table or otherwise aren't resolved correctly resulting in these
errors. Interesting, though, that "Integer" *IS* being resolved to
"java.lang.Integer" before the failure occurs.

At any rate, what you're doing isn't, technically, something lombok
supports. But we really really like to; @Delegate is one of our
favourite future lombok features. Whatever you can figure out on how
to make javac (re)resolve so this error goes away, please share it
with the group. Thanks!

On May 11, 3:38 pm, Franz Allan Valencia See <franz....@gmail.com>
wrote:
> error: *cannot find symbol*
>
> symbol  : class int
>
> location: class see.fa.pract.lombok.DelegateTarget
>
> [loading java/lang/String.class(java/lang:String.class)]
>
> [checking see.fa.pract.lombok.DelegateTarget]
>
> [checking see.fa.pract.lombok.HelloTarget]
>
> [total 894ms]
>
> 1 error
>
> ...
>
> Any ideas why there's a "*cannot find symbol*" compilation error?
>
> Note:
> I tried modifying the signatures of DelegateTargets to narrow down the
> problem:
> * DelegateTarget#add(int,int):int
> into DelegateTarget#add(Integer,Integer):Integer results to a :
> ''error: cannot find symbol* ... *symbol  : class *java.lang.Integer*".
> * Removing DelegateTarget#add(int,int):int results to a ''error: cannot find
> symbol* ... *symbol  : class *java.lang.String*".
> * Removing both DelegateTarget#add(int,int):int
> and DelegateTarget#greetings(String):String results to a *successful
> compilation*
>
> Thanks,
> --
> Franz Allan Valencia See | Java Software Engineer
> franz....@gmail.com
> LinkedIn:http://www.linkedin.com/in/franzsee
> Twitter:http://www.twitter.com/franz_see
>
> --
> You received this message because you are subscribed to the Google
> Groups group forhttp://projectlombok.org/

Franz Allan Valencia See

unread,
May 11, 2010, 9:07:40 PM5/11/10
to project...@googlegroups.com
Yes I did. I got the same errors (except that it complains about 'java.lang.Integer' instead of 'int'). 

> Note:
> I tried modifying the signatures of DelegateTargets to narrow down the problem:
> * DelegateTarget#add(int,int):int into DelegateTarget#add(Integer,Integer):Integer results to a : ''error: cannot find symbol* ... *symbol  : class *java.lang.Integer*".
> * Removing DelegateTarget#add(int,int):int results to a ''error: cannot find symbol* ... *symbol  : class *java.lang.String*".
> * Removing both DelegateTarget#add(int,int):int and DelegateTarget#greetings(String):String results to a *successful compilation*

Thanks,
-- 
Franz Allan Valencia See | Java Software Engineer 
fran...@gmail.com
LinkedIn: http://www.linkedin.com/in/franzsee
Twitter: http://www.twitter.com/franz_see

On Tue, May 11, 2010 at 11:28 PM, daver <roden...@gmail.com> wrote:
Do you get the same error if you use Integer instead of int?

I'm wondering if your code needs to output the primitives differently
than the classes...

On May 11, 6:38 am, Franz Allan Valencia See <franz....@gmail.com>
wrote:
> error: *cannot find symbol*

>
> symbol  : class int
>
> location: class see.fa.pract.lombok.DelegateTarget
>
> [loading java/lang/String.class(java/lang:String.class)]
>
> [checking see.fa.pract.lombok.DelegateTarget]
>
> [checking see.fa.pract.lombok.HelloTarget]
>
> [total 894ms]
>
> 1 error
>
> ...
>
> Any ideas why there's a "*cannot find symbol*" compilation error?

>
> Note:
> I tried modifying the signatures of DelegateTargets to narrow down the
> problem:
> * DelegateTarget#add(int,int):int
> into DelegateTarget#add(Integer,Integer):Integer results to a :
> ''error: cannot find symbol* ... *symbol  : class *java.lang.Integer*".

> * Removing DelegateTarget#add(int,int):int results to a ''error: cannot find
> symbol* ... *symbol  : class *java.lang.String*".

> * Removing both DelegateTarget#add(int,int):int
> and DelegateTarget#greetings(String):String results to a *successful
> compilation*

>
> Thanks,
> --
> Franz Allan Valencia See | Java Software Engineer

> --
> You received this message because you are subscribed to the Google
> Groups group forhttp://projectlombok.org/

>
> To post to this group, send email to project...@googlegroups.com
> To unsubscribe from this group, send email to
> project-lombo...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/project-lombok?hl=en

--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/

To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en

Franz Allan Valencia See

unread,
May 11, 2010, 10:01:52 PM5/11/10
to project...@googlegroups.com
Sure. I'll attach the codes here for now (since I haven't created a public repo yet).

Pardon the 'messiness' of the code because I'm still exploring it :-)

What I have for now is a javac Handler. And my test project has two modules - 'under-test' and 'dependency' (wherein 'under-test' depends on 'dependency'). The 'under-test' module (which contains the DelegateTarget) depends on the 'dependency' module (which contains the DelegatingClass). I haven't figured out how to do this with DelegateTarget and DelgatingClass compile in one go so I separated them into two modules for now.

However, even with that 'cheat', I'm still encountering a problem - which is the 'cannot find symbol' error. 

Thanks,
-- 
Franz Allan Valencia See | Java Software Engineer 
DelegateTo.java
DelegateToHandler.java
lombok-sample.tar.gz

Franz Allan Valencia See

unread,
May 13, 2010, 8:28:21 PM5/13/10
to project...@googlegroups.com
I found out what my problem was:

a.) I need to use TreeMaker#TypeIdent(..) instead of TreeMaker#Ident(..) to properly generate primitives.
b.) I passed the fully qualified class name to chainDots(..) without splitting them into tokens (i.e. I passed in "java.lang.String" instead of new String[]{"java", "lang", "String"})

Thanks,
-- 
Franz Allan Valencia See | Java Software Engineer 
fran...@gmail.com
LinkedIn: http://www.linkedin.com/in/franzsee
Twitter: http://www.twitter.com/franz_see

Reinier Zwitserloot

unread,
May 17, 2010, 5:46:23 AM5/17/10
to Project Lombok
And... now your @Delegate thing works?

In eclipse and javac?

If so, excuse me while I pick my jaw back up from the floor.

On May 14, 2:28 am, Franz Allan Valencia See <franz....@gmail.com>
wrote:
> I found out what my problem was:
>
> a.) I need to use TreeMaker#TypeIdent(..) instead of TreeMaker#Ident(..) to
> properly generate primitives.
> b.) I passed the fully qualified class name to chainDots(..) without
> splitting them into tokens (i.e. I passed in "java.lang.String" instead of
> new String[]{"java", "lang", "String"})
>
> Thanks,
> --
> Franz Allan Valencia See | Java Software Engineer
> On Wed, May 12, 2010 at 10:01 AM, Franz Allan Valencia See <
>
>
>
> franz....@gmail.com> wrote:
> > Sure. I'll attach the codes here for now (since I haven't created a public
> > repo yet).
>
> > Pardon the 'messiness' of the code because I'm still exploring it :-)
>
> > What I have for now is a javac Handler. And my test project has two modules
> > - 'under-test' and 'dependency' (wherein 'under-test' depends on
> > 'dependency'). The 'under-test' module (which contains the DelegateTarget)
> > depends on the 'dependency' module (which contains the DelegatingClass). I
> > haven't figured out how to do this with DelegateTarget and DelgatingClass
> > compile in one go so I separated them into two modules for now.
>
> > However, even with that 'cheat', I'm still encountering a problem - which
> > is the 'cannot find symbol' error.
>
> > Thanks,
> > --
> > Franz Allan Valencia See | Java Software Engineer
> ...
>
> read more »

Franz Allan Valencia See

unread,
May 17, 2010, 6:24:30 AM5/17/10
to project...@googlegroups.com
Just javac for now. I haven't worked on the eclipse side yet.

Plus, there's a big workaround for it (the class where you're going to delegate to must already be compiled before you compile the annotated class, and you must (redundantly) specify that class).

Hopefully, I can get back on it within this weekend.

Cheers,
-- 
Franz Allan Valencia See | Java Software Engineer 
Reply all
Reply to author
Forward
0 new messages