I am writing an Eclipse plugin that uses the AST ASTParser JDT to analyze a method. I am considering this method for creating a specific type of object.
When I find ClassInstanceCreation , I call getType() on it to see which type is being created. I want to be sure that the fully resolved type with which it deals is the one that I think, so I tell the resulting Type object to resolveBinding() . I am returning null back although there are no compilation errors, and although I called setResolveBindings(true) on my ASTParser . I passed ASTParser (via setSource() ) an ICompilationUnit containing my method, so the analyzer has access to the entire context of the workspace.
final IMethod method = ...; final ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setResolveBindings(true); parser.setSource(method.getCompilationUnit()); parser.setSourceRange(method.getSourceRange().getOffset(), method.getSourceRange().getLength()); parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); final TypeDeclaration astRoot = (TypeDeclaration) parser.createAST(null); final ClassInstanceCreation classInstanceCreation = walkAstAndFindMyExpression(astRoot); final Type instantiatedType = classInstanceCreation.getType(); System.out.println("BINDING: " + instantiatedType.resolveBinding());
Why resolveBinding() returns null ? How to get binding information?
eclipse-plugin eclipse-jdt
Woody zenfell iii
source share