我正在使用Java AST。如何获取FieldDeclaration或VariableDeclaration的Type(例如String或MyOwnType)?在ASTView中,我可以在SimpleName>下看到它。类型绑定,但使用getter我无法访问该成员。 我尝试了FieldDeclaration to IField - Getting IBinding from FieldDeclaration的解决方案,但在访问FieldDeclaration时,resolveBinding返回null。
Why does resolveBinding() return null even though I setResolveBindings(true) on my ASTParser?无法正常工作
答案 0 :(得分:1)
varDeclFrag.resolveBinding().getType().getQualifiedName();
检索类型,虽然我已经认为在引用sources
时我在setEnvironment中做了同样的事情:
String[] sources = { "C:\\a\\TheMightyExampleProject\\src" };
String[] classPaths = { "C:\\a\\antlr-4.1-complete.jar" };
parser.setEnvironment(classPaths, sources, new String[] { "UTF-8" }, true);
parser.setBindingsRecovery(true);
parser.setResolveBindings(true);
parser.setCompilerOptions(options);
parser.setStatementsRecovery(true);
parser.setUnitName("C:\\a\\TheMightyExampleProject\\src"); // ftw
您还可以查看Ida bindings not resolving with AST processing in eclipse
的答案