Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » ASTNode type and variable bindings(how to get type and variable bindings)
ASTNode type and variable bindings [message #890819] Sat, 23 June 2012 01:52 Go to next message
Zvonimir Pavlinovic is currently offline Zvonimir Pavlinovic
Messages: 10
Registered: June 2012
Junior Member
Hi!

I am new to Eclipse JDT. I am working with ASTParser and I am currently stuck with bindings. I load the code from the text source and I would like to get type (and possibly variable) bindings. So, pretty much this is my initialization code:

ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(source);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
Map options = JavaCore.getOptions(); 
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
parser.setCompilerOptions(options);
parser.setResolveBindings(true);
CompilationUnit cu = (CompilationUnit)parser.createAST(null);


and this is the bogus code I would like to examine:
class A{

   public A(){}

   public void kill(){
      String s = "bogus";
      String a = s + " code";
   }

}


However, when analyzing SimpleName I always get null for getBinding() and getTypeBinding(). What am I doing wrong? Can somebody explain how this works generally.

Thanks!

I saw that astviewer does not work with plain text yet just with CompilationUnit. However, I doubt that is the reason why I am not seeing the bindings.
Re: ASTNode type and variable bindings [message #890934 is a reply to message #890819] Sat, 23 June 2012 09:40 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak Azad
Messages: 545
Registered: July 2009
Senior Member
See
http://wiki.eclipse.org/JDT/FAQ#Can_I_use_JDT_outside_Eclipse_to_manipulate_Java_code.3F

--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
Re: ASTNode type and variable bindings [message #891167 is a reply to message #890934] Sun, 24 June 2012 02:51 Go to previous message
Zvonimir Pavlinovic is currently offline Zvonimir Pavlinovic
Messages: 10
Registered: June 2012
Junior Member
Thanks Deepak, but I am still not able to get any binding information.

First, I realized that I had old jars so I was not able to use setEnvironment. Now, I am using jdt.core_3.7.3. This how my initialization code looks like now:

ASTParser parser = ASTParser.newParser(AST.JLS3);
Properties prop = System.getProperties();
String [] classPathEntries = prop.getProperty("java.class.path").split(":"); 
String [] sourcePathEntries = new String[]{"/path/to/project/src/dir"};
parser.setEnvironment(classPathEntries, sourcePathEntries, null, true); //does not work with "false" either
parser.setResolveBindings(true);
parser.setSource(source);
parser.setKind(ASTParser.K_STATEMENTS);
Map options = JavaCore.getOptions(); 
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
parser.setCompilerOptions(options);
Block block = (Block) parser.createAST(null);


Am I using wrong binaries? I am asking since ASTviewer works just fine; it shows all the binding information.

Binaries:
org.eclipse.core.runtime_3.5.0.v20090525.jar
org.eclipse.equinox.common_3.5.1.R35x_v20090807-1100.jar
org.eclipse.core.resources_3.5.2.R35x_v20091203-1235.jar
org.eclipse.core.jobs_3.4.100.v20090429-1800.jar
org.eclipse.osgi.jar
org.eclipse.core.contenttype_3.4.1.R35x_v20090826-0451.jar
org.eclipse.equinox.preferences_3.2.301.R35x_v20091117.jar
org.eclipse.jdt.core_3.7.3.v20120119-1537.jar
Previous Topic:Console Encoding Setting
Next Topic: Eclipse will not start in Ubuntu 12.04 - 64 bits
Goto Forum:
  


Current Time: Wed Apr 16 09:33:57 EDT 2014

Powered by FUDForum. Page generated in 0.02165 seconds