We are constantly getting 'null' for 'binding of TypeDeclaration' in some specific java files in https://github.com/bazelbuild/bazel
Over 3000+ files show this behaviour. We are querious and concerned if we are missing something.ITypeBinding binding = typeDec.resolveBinding();
While debugging, we found that 'compilationResult' of 'org.eclipse.jdt.internal.compiler.ast.TypeDeclaration' shows some strange problems and showing 'COMPILED type(s)' as empty.
Filename : /bazel-master/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/GcovJsonParser.java
COMPILED type(s)
1 PROBLEM(s) detected
- Pb(324) The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
Filename : /bazel-master/src/main/java/com/google/devtools/build/lib/rules/objc/AppleBinary.java
COMPILED type(s)
1 PROBLEM(s) detected
- Pb(324) The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
Filename : /bazel-master/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.java
COMPILED type(s)
2 PROBLEM(s) detected
- Pb(324) The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
- Pb(1455) The package java.lang is accessible from more than one module: <unnamed>, java.base
Filename : /bazel-master/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryBaseRule.java
COMPILED type(s)
No PROBLEM
We are using the following code to parse AST
protected CompilationUnit parse(String filename) {
IModelFileElement fileElement = Model.getInstance().getFile(filename);
ASTParser parser = ASTParser.newParser(AST.JLS11);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
if (fileElement instanceof EclipseModelFileElement) {
parser.setSource(((EclipseModelFileElement)fileElement).getCompilationUnit());
} else {
File file = new File(fileElement.getFullPath());
parser.setUnitName(fileElement.getName());
parser.setEnvironment(null, null, null, true);
try {
parser.setSource(readFileToString(file).toCharArray());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
try {
ASTNode node = parser.createAST(null);
if (node instanceof CompilationUnit) {
return (CompilationUnit)node;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Thanks and regards,
Md. Rishadur Rahman
Software Engineer
OpenRefactory Inc.