Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » ASTVisitor and SimpleType.resolveBinding(): wrong ITypeBinding
ASTVisitor and SimpleType.resolveBinding(): wrong ITypeBinding [message #662625] Thu, 31 March 2011 10:30 Go to next message
Carsten Reckord is currently offline Carsten ReckordFriend
Messages: 139
Registered: July 2009
Senior Member
Hi all,

I have a little problem with resolving some bindings for SimpleTypes.

Take this example:


import org.eclipse.uml2.uml.Package;

public abstract class JavaLangImports
{
public abstract Package m1();
public abstract java.lang.Package m2 ();
}


When I look at it with the Java Editor, the Package for m1() is correctly
resolved as org.eclipse.uml2.uml.Package (maybe it is worth mentioning here
that this is also the case when opening the source file externally without
having it in a source path anywhere. So I guess that the compiler has no
hand in this).

When I visit the file with my own ASTVisitor however, I get a TypeBinding
for java.lang.Package for both methods.

The AST visitor is created like this:

IJavaElement javaElement = JavaCore.create(file);
ICompilationUnit compilationUnit = (ICompilationUnit)javaElement;
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(unit);
parser.setResolveBindings(true);
CompilationUnit parsedUnit =
(CompilationUnit)parser.createAST(monitor);
MyVisitor visitor = new MyVisitor(visitProgress);
parsedUnit.accept(visitor);

and in MyVisitor

public boolean visit(SimpleType node)
{
ITypeBinding b = node.resolveBinding();
//is java.lang.Package in both cases
System.out.println(b.getQualifiedName());
return false;
}

Is there some magic I need to perform to make the AST resolve the correct
types? Or is this a bug?


Best regards,
Carsten Reckord
Re: ASTVisitor and SimpleType.resolveBinding(): wrong ITypeBinding [message #662659 is a reply to message #662625] Thu, 31 March 2011 13:00 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
Hi,

Please open a bug report against JDT/Core with steps to reproduce, build id and anything that might help us to fix it.
I'll take a look.

Thanks,

Olivier
Re: ASTVisitor and SimpleType.resolveBinding(): wrong ITypeBinding [message #662838 is a reply to message #662659] Fri, 01 April 2011 07:24 Go to previous message
Carsten Reckord is currently offline Carsten ReckordFriend
Messages: 139
Registered: July 2009
Senior Member
Argh, dangit. I found my problem. Why is it that it always hits you after
hitting submit...

The sample code I posted was not in my workspace, but part of a unit test
suite where it gets imported into a test workspace. So without the compiler
complaining to me, I didn't see that there was no org.eclipse.uml2 in the
classpath...

Everything works as intended now.

Thanks,
Carsten

On 31.03.2011 15:00, Olivier Thomann wrote:
> Hi,
>
> Please open a bug report against JDT/Core with steps to reproduce, build id and anything that might help us to fix it.
> I'll take a look.
>
> Thanks,
>
> Olivier
Previous Topic:Debug with ClickIDE
Next Topic:String.format problem
Goto Forum:
  


Current Time: Fri Apr 26 11:05:27 GMT 2024

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

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

Back to the top