Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » parsing with bindings for class in Java library
parsing with bindings for class in Java library [message #222114] Thu, 12 January 2006 13:42 Go to next message
Eclipse UserFriend
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 #222269 is a reply to message #222114] Mon, 16 January 2006 12:57 Go to previous messageGo to next message
Eclipse UserFriend
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 #222379 is a reply to message #222269] Tue, 17 January 2006 16:18 Go to previous messageGo to next message
Eclipse UserFriend
> - 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 Go to previous message
Eclipse UserFriend
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
Previous Topic:Compile Java to Windows Native Code (.exe)
Next Topic:Quick Fix Question
Goto Forum:
  


Current Time: Fri Nov 07 06:51:32 EST 2025

Powered by FUDForum. Page generated in 0.08377 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top