|
|
|
|
|
|
|
|
|
Re: There is a way to use ASTParser outside Eclipse? [message #515395 is a reply to message #515332] |
Thu, 18 February 2010 11:18   |
Eclipse User |
|
|
|
Olivier Thomann wrote:
> Le 2010-02-18 05:21, David Goodenough a écrit :
>> The basic question was as to why the scope might be null, and what I
>> was supposed to do when it happened. I have come across comments that
>> this might happen when serious errors have occurred earlier in the
>> process, but in this particular case there were no other errors (that
>> I could see). I can try to put together a test case (although it will
>> involve the basic Lombok code as well as my handler) but I would like
>> to understand if there are circumstances when I am supposed to get null
>> and action should be taken by an ASTVisitor if this happens.
> I would need to know when you are calling the ASTVisitor.
> After cleanup is called, most of the scopes are null.
>
> If you give me an example, I can have a look.
> --
> Olivier
It is happening during Annotation processing.
I will put together an example, but it will require Lombok, and is
invoked through Lombok rather than directly from the eclipse compiler.
It may that this is a problem in Lombok, but they (the authors of Lombok)
seem to think not.
I am afraid that getting an example of this is not going to be simple,
which is why I was trying to find out in principle what having a null
scope might mean.
You can find the source for lombok on github at:-
git://github.com/rzwitserloot/lombok.git
My code can be found at:-
git://dga.co.uk/git/lombok-beans.git
There is some detail of Lombok at projectlombok.org and of my beans code
at dga.co.uk/lombokbeans
The problem occurs in the HandleFieldRef class. At the top of this is a
visitCompilationUnit method, to which is passed a CompilationUnit which
contains a Scope. The visitCompilationUnit code is called from within
Lombok for each object which has @ProviderFor(EclipseASTVisitor.class).
Exactly where the scope value comes from I am not sure, but my guess
is that it is whatever was passed to Lombok. Lombok hooks itself into
Eclipse in a rather odd way, it is (as I understand it) not entirely
an Annotation processor, but it is at about that time in the compilation.
That scope is sometimes null, and so when I call my
inner ASTVisitor it has no Scopes to do resolution with. If I add a
line in the visitCompilationUnit method which reads:-
if(unit.scope == null) top.addError("Null scope found");
then I will get errors displayed at the top of some of my source code.
This seems to happen most on modules with inner classes, and also
sometimes in constructors. I have yet to spot any other patterns
than these.
You will need to install lombok.jar (which you build using ant from
the directory that you download lombok.git into) and also beans.jar
(which you get from running ant on the directory used for lombok-beans.git).
If you run the lombok jar it will run up an installer, and tell you
where it is installing itself (in the same directory as eclipse.ini)
and beans.jar needs to be installed there as well.
I will dig out some samples of classes that cause the problem, but
the problem is that the ones I am using are part of a larger framework
and getting all of that (and its prereqs) to you would be difficult.
David
|
|
|
|
|
|
Re: There is a way to use ASTParser outside Eclipse? [message #515635 is a reply to message #515617] |
Fri, 19 February 2010 10:16  |
Eclipse User |
|
|
|
Olivier,
Thank you for that. I will pass that on to the Lombok guys. They are
rewriting the whole thing at the moment, so I will make sure that they
get this right next time around.
David
Olivier Thomann wrote:
> Le 2010-02-18 15:26, David Goodenough a écrit :
>> at
>>
org.eclipse.jdt.internal.compiler.parser.Parser.endParse(Par ser.java:8351)
>> at
>>
org.eclipse.jdt.internal.core.util.CommentRecorderParser.end Parse(CommentRecorderParser.java:116)
>> at
>>
org.eclipse.jdt.internal.compiler.SourceElementParser.endPar se(SourceElementParser.java:714)
>> at
>> org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser .java:9360)
>> at
>> org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser .java:9670)
>> at
>>
org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.pars eStatements(MethodDeclaration.java:119)
>> at
>>
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.parseM ethods(TypeDeclaration.java:830)
>> at
>>
org.eclipse.jdt.internal.compiler.parser.Parser.getMethodBod ies(Parser.java:8542)
> That explains it. The scopes are not created yet.
> They are created in the buildTypeBindings(..) method which is called
> later. So now I can tell you for sure that at that time all scopes are
> null. I am in fact surprised that you find some non-null scopes.
> --
> Olivier
|
|
|
Powered by
FUDForum. Page generated in 0.04276 seconds