| parsing with bindings for class in Java library [message #222114] |
Thu, 12 January 2006 13:42  |
Eclipse User |
|
|
|
Hi,
I'm trying to parse the source associated with a Java library class
(e.g. java.util.ArrayList) with bindings. I wrote the following code to
do so (with version 3.1.1):
IClassFile classFile = ...; // library class
ASTParser astParser = ASTParser.newParser(AST.JLS3);
astParser.setSource(classFile);
astParser.setResolveBindings(true);
CompilationUnit astRoot = (CompilationUnit) astParser.createAST(null);
When I run this code for the java.util.ArrayList class, it succeeds in
building an AST. However, when I call resolveBinding() on a
MethodDeclaration node in the AST, it returns null. Is this the
expected behavior? If so, is there any way I can create an AST that
would associate bindings with the MethodDeclaration nodes (and other
nodes) for such a class? Thanks a lot in advance.
-Manu
|
|
|
|
| Re: parsing with bindings for class in Java library [message #222379 is a reply to message #222269] |
Tue, 17 January 2006 16:18   |
Eclipse User |
|
|
|
> - could it be an issue with 1.4 and 5.0 compiler settings, e.g. that the
> project is set to 1.4 but the library is 5.0?
This was the issue. Is this issue documented elsewhere? If not, maybe
it should be, as I would have had great difficulty figuring this out
without help. Thanks a lot!
-Manu
Markus Keller wrote:
> Manu Sridharan wrote:
>
>> Hi,
>>
>> I'm trying to parse the source associated with a Java library class
>> (e.g. java.util.ArrayList) with bindings. I wrote the following code
>> to do so (with version 3.1.1):
>>
>> IClassFile classFile = ...; // library class
>> ASTParser astParser = ASTParser.newParser(AST.JLS3);
>> astParser.setSource(classFile);
>> astParser.setResolveBindings(true);
>> CompilationUnit astRoot = (CompilationUnit) astParser.createAST(null);
>>
>> When I run this code for the java.util.ArrayList class, it succeeds in
>> building an AST. However, when I call resolveBinding() on a
>> MethodDeclaration node in the AST, it returns null. Is this the
>> expected behavior? If so, is there any way I can create an AST that
>> would associate bindings with the MethodDeclaration nodes (and other
>> nodes) for such a class? Thanks a lot in advance.
>>
>> -Manu
>
> This should work. Things to check:
> - ensure that the source attachment is correctly set to the library
> (right version of the sources, etc.)
> - could it be an issue with 1.4 and 5.0 compiler settings, e.g. that the
> project is set to 1.4 but the library is 5.0?
>
> Markus
|
|
|
| Re: parsing with bindings for class in Java library [message #222393 is a reply to message #222379] |
Wed, 18 January 2006 08:49  |
Eclipse User |
|
|
|
You can enable the compiler option "Java > Compiler > Building > Build path
problems > Incompatible required binaries" to get a warning/error in such cases.
CompilationUnit#getProblems() should always contain corresponding problems
if bindings could not be resolved.
If you think this is not enough (or that the option above should have a
higher default severity), please file a bug report for JDT/Core, giving
steps to reproduce the problem.
Markus
Manu Sridharan wrote:
>> - could it be an issue with 1.4 and 5.0 compiler settings, e.g. that
>> the project is set to 1.4 but the library is 5.0?
>
>
> This was the issue. Is this issue documented elsewhere? If not, maybe
> it should be, as I would have had great difficulty figuring this out
> without help. Thanks a lot!
>
> -Manu
>
> Markus Keller wrote:
>
>> Manu Sridharan wrote:
>>
>>> Hi,
>>>
>>> I'm trying to parse the source associated with a Java library class
>>> (e.g. java.util.ArrayList) with bindings. I wrote the following code
>>> to do so (with version 3.1.1):
>>>
>>> IClassFile classFile = ...; // library class
>>> ASTParser astParser = ASTParser.newParser(AST.JLS3);
>>> astParser.setSource(classFile);
>>> astParser.setResolveBindings(true);
>>> CompilationUnit astRoot = (CompilationUnit) astParser.createAST(null);
>>>
>>> When I run this code for the java.util.ArrayList class, it succeeds
>>> in building an AST. However, when I call resolveBinding() on a
>>> MethodDeclaration node in the AST, it returns null. Is this the
>>> expected behavior? If so, is there any way I can create an AST that
>>> would associate bindings with the MethodDeclaration nodes (and other
>>> nodes) for such a class? Thanks a lot in advance.
>>>
>>> -Manu
>>
>>
>> This should work. Things to check:
>> - ensure that the source attachment is correctly set to the library
>> (right version of the sources, etc.)
>> - could it be an issue with 1.4 and 5.0 compiler settings, e.g. that
>> the project is set to 1.4 but the library is 5.0?
>>
>> Markus
|
|
|
Powered by
FUDForum. Page generated in 0.08377 seconds