Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Unexpected null binding
icon4.gif  Unexpected null binding [message #555085] Wed, 25 August 2010 12:17 Go to next message
Nicolas Anquetil is currently offline Nicolas AnquetilFriend
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 Sad

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
Re: Unexpected null binding [message #557726 is a reply to message #555085] Wed, 08 September 2010 15:32 Go to previous message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
Not sure what the problem can be exactly, but you might want to add:
pars.setBindingsRecovery(true);
--
Olivier
Previous Topic:Formatting - "Wrap before operator" option for conditionals?
Next Topic:JRE 7 not registering with Eclipse
Goto Forum:
  


Current Time: Tue Apr 23 09:18:18 GMT 2024

Powered by FUDForum. Page generated in 0.03237 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top