Creating a compiler with type bindings

I am working with an API API in java and I am trying to create a “Compilation Block” with type bindings. I wrote the following code:

private static CompilationUnit parse(ICompilationUnit unit) {
 ASTParser parser = ASTParser.newParser(AST.JLS3);
 parser.setKind(ASTParser.K_COMPILATION_UNIT);
 parser.setSource(unit);
 parser.setResolveBindings(true);
 CompilationUnit compiUnit = (CompilationUnit) parser.createAST(null);
 return compiUnit;
}

Unfortunately, when I run this code in debug mode and check compiUnit, I find that it compiUnit.ast.resolver.isRecoveringBindingsis false.
Can anyone think of a reason why this will not be true, as I indicated that it will be?
Thanks you

+3
source share
2 answers

You mix the two parts of the API: binding and binding restoration. From JavaDoc to setBindingsRecovery:

void org.eclipse.jdt.core.dom.ASTParser.setBindingsRecovery(boolean enabled)

Requests that the compiler should perform bindings recovery. When bindings recovery is enabled the compiler returns incomplete bindings.

Default to false.

This should be set to true only if bindings are resolved. It has no effect if there is no binding resolution.

Parameters:
enabled true if incomplete bindings are expected, and false if only complete bindings are expected.

, . , false, . , , , true AST. AST.hasBindingsResolved(), , .

: , / AST, - , . , , , , , .

+2

, , compiUnit.ast.resolver.isRecoveringBindings dosen't , , (API API java ...). , , , .

, , , NullPointerException arg.resolveTypeBinding().getName();. , arg . , AST, java, arg = ASTNode.copySubtree(classAst, arg2);.
resolveTypeBinding().getName() arg2, arg, .

+1

Source: https://habr.com/ru/post/1785575/


All Articles