Woo*_*III 6 eclipse-plugin eclipse-jdt
我正在编写一个Eclipse插件,它使用JDT AST ASTParser来解析方法.我在该方法中寻找创建特定类型的对象.
当我找到a时ClassInstanceCreation,我会调用getType()它来查看实例化的类型.我想确保那里处理的完全解析类型是我认为的那个,所以我告诉结果Type对象resolveBinding().我得null回去,即使没有编译错误,即使我叫setResolveBindings(true)上我ASTParser.我给了我的ASTParser(via setSource())ICompilationUnit包含我的方法,因此解析器可以访问整个工作区上下文.
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());
Run Code Online (Sandbox Code Playgroud)
为什么要resolveBinding()回来null?我怎样才能获得绑定信息?
| 归档时间: |
|
| 查看次数: |
2054 次 |
| 最近记录: |