Unexpected null binding [message #555085] |
Wed, 25 August 2010 12:17 |
Nicolas Anquetil Messages: 20 Registered: May 2010 |
Junior Member |
|
|
Hi,
I am using JDT to get AST and binding from a java project.
I am using a derivation (subclass) of BatchParser
I am getting null bindings that I did not expect.
For example, I was assuming a class/method/ ... declaration would always have a binding associated to it.
I created a method (that uses generics) that did not answer my expectations. That is to say JDT does not create a binding for this method
Can any one explain this? Is it a bug (or a feature)?
If so, is there a way around?
the simplest method exhibiting the problem is:
public <T extends Object> T boggusMethod(Class<T> fmxClass) {
return null;
}
I have a file with all the code to expose the problem.
I tried to make it as short as possible (sorry it is still a bit long).
It should be run on itself as a Java Application.
package misc;
import java.io.PrintWriter;
import java.util.Map;
import org.eclipse.jdt.core.compiler.CompilationProgress;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FileASTRequestor;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath ;
import org.eclipse.jdt.internal.compiler.batch.Main;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
public class Snippet extends Main {
public static void main(String[] args) {
new Snippet(new PrintWriter(System.out), new PrintWriter(System.err), true/*systemExit*/, null/*options*/, null/*progress*/).compile(args);
}
public Snippet(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map customDefaultOptions, CompilationProgress compilationProgress) {
super(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions, compilationProgress);
}
/*
* Low-level API performing the actual parsing
* Overwrite the one in org.eclipse.jdt.internal.compiler.batch.Main;
*/
public void performCompilation() {
//FileSystem environment = getLibraryAccess();
this.compilerOptions = new CompilerOptions(this.options);
this.compilerOptions.performMethodsFullRecovery = false;
this.compilerOptions.performStatementsRecovery = false;
String[] tmpclasspath=null;
if (this.checkedClasspaths!=null) {
tmpclasspath = new String[this.checkedClasspaths.length];
int i = 0;
for (Classpath cp : this.checkedClasspaths) {
tmpclasspath[i++] = cp.getPath();
}
}
ASTParser pars = ASTParser.newParser(AST.JLS3);
pars.setEnvironment(/*classpathEntries*/tmpclasspath,
/*sourcepathEntries*/new String[0],
/*encodings*/null,
/*includeRunningVMBootclasspath*/true);
pars.setResolveBindings(true);
pars.setKind(ASTParser.K_COMPILATION_UNIT);
pars.createASTs(/*sourceFilePaths*/this.filenames,
/*encodings*/this.encodings,
/*bindingKeys*/new String[0],
/*requestor*/new MyRequestor(),
/*monitor*/null);
}
public <T extends Object> T boggusMethod(Class<T> fmxClass) {
return null;
}
}
class MyRequestor extends FileASTRequestor {
public MyRequestor() { super(); }
public void acceptAST(String sourceFilePath, CompilationUnit ast) {
ast.accept(new MyVisitor());
}
}
class MyVisitor extends ASTVisitor {
public MyVisitor() { super(); }
public boolean visit(TypeDeclaration node) {
if (node.resolveBinding() == null) {
System.err.println("Unexpected null type binding:"+node.getName().getFullyQualifiedName());
}
return super.visit(node);
}
public boolean visit(MethodDeclaration node) {
if (node.resolveBinding() == null) {
System.err.println("Unexpected null method binding:"+node.getName().getFullyQualifiedName());
}
return super.visit(node);
}
}
nicolas
|
|
|
|
Powered by
FUDForum. Page generated in 0.03237 seconds