Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JDT and binding
JDT and binding [message #699907] Fri, 22 July 2011 15:03 Go to next message
Federico Tomassetti is currently offline Federico TomassettiFriend
Messages: 190
Registered: July 2009
Location: Dublin
Senior Member

I am not able to use the JDT binding capabilities.


public class ASTBindingTest extends ASTVisitor {

	@Override
	public boolean visit(ExpressionStatement node) {
		return super.visit(node);
	}

	@Override
	public boolean visit(FieldAccess node) {
		System.out.println("Field binding: "+node.resolveFieldBinding());
		return super.visit(node);
	}

	@Override
	public boolean visit(SimpleName node) {
		System.out.println("Simple name binding: "+node.resolveBinding());
		return super.visit(node);
	}
	

	public static void main(String[] args) throws IOException {
		String source = ...
		
		ASTParser parser = ASTParser.newParser(AST.JLS3);
		parser.setResolveBindings(true);
		parser.setSource(source.toCharArray());		
		org.eclipse.jdt.core.dom.CompilationUnit node = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);		
		node.accept(new ASTBindingTest());
		

		
		
	}
}


Source examined:
package a.b.c;

class A {
	int i;
}

class D extends A {
	
	public void setI(int i){
		this.i = i;
	}
	
	public int getI(){
		return i;
	}

}


Output:
Simple name binding: null
Simple name binding: null
Simple name binding: null
Simple name binding: null
Simple name binding: null
Simple name binding: null
Field binding: null
Simple name binding: null
Simple name binding: null
Simple name binding: null
Simple name binding: null


All the examples I have found are very similar to what I have done and I really do not get my error.


Re: JDT and binding [message #703068 is a reply to message #699907] Wed, 27 July 2011 06:10 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
Add the following lines before calling createAST()
parser.setEnvironment(null, null, null, true);
parser.setUnitName("D.java");
Re: JDT and binding [message #703112 is a reply to message #703068] Wed, 27 July 2011 07:27 Go to previous message
Federico Tomassetti is currently offline Federico TomassettiFriend
Messages: 190
Registered: July 2009
Location: Dublin
Senior Member

It works... thank you!

Previous Topic:Access to source code of method (getBody()) from IMethodBinding
Next Topic:ASTRequestor.acceptAST(...) is never called
Goto Forum:
  


Current Time: Thu Apr 25 05:26:22 GMT 2024

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

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

Back to the top