Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » how to extract scope information from Eclipse JDT core batch compiler?
how to extract scope information from Eclipse JDT core batch compiler? [message #1096045] Tue, 27 August 2013 22:32
Ray Wu is currently offline Ray WuFriend
Messages: 4
Registered: August 2013
Junior Member
What I want to achieve is extract language structure of source code, for example
class Test {
  String name; // (1)

  Test(String name) { // (2)
    this.name = name; // (3) (4)
  }
  
  String toString() {
    return name; // (5)
  }
}


I want to figure out what is each "name" refering to. Like (3) and (5) are refering to (1) and (4) is refering to (2). another example is

Test t = new Test("t");
System.out.println(t);


I want to know t is type Test and where is it declared.

I use JDT batch compiler (ecjsrc-4.3) downloaded from Eclipse 4.3 release for this task. The reason I choose this instead of whole JDT framework is because there is an existed JDTCompilerAdapter of this compiler for Ant, which is what I need in the future.

So far I add a custom AstVisitor at line 540 in org.eclipse.jdt.internal.compiler.Compiler, where compiler already generate AstTree and scope information for all files.

My problem is, I don't know how to use the scope in each visit method in AstVisitor to get those information. Like in the first example, in line this.name = name;. on the LHS, it's a FieldReference for this.name and a ThisReference for this. There is no AstNode for name on the LHS, therefore I have no idea how to get which field is it referring to. On the RHS, it's a SingleNameReference. However if I first invoke node.resolve(scope) then try to print out 'node.resolvedType and node.binding, what I'll get is null and java.lang.String name. Since both argument and field are String, I can't distinguish between them.

In second example, I don't know how to get the type information of t either, I could only get null for resolveType and "<no type> t" for binding.

Any one have done this before?
Previous Topic:Javadoc server port number
Next Topic:Compiled Java JDBC MySQL Class Not Found
Goto Forum:
  


Current Time: Thu Apr 25 20:15:28 GMT 2024

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

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

Back to the top