java - Using Eclipse JDT to find all identifiers visible within a specific node -


i'm working on plug-in eclipse jdt parses java files , offers automatic corrections them. i'm doing using eclipse's api analyzing ast.

i'm trying write method calculates environment of method - list of identifiers visible within scope of method. way @ list of identifiers can auto-completed specific point in eclipse.

for example:

import ...  public class myclass {     private static final int = 3;     private boolean b;      float somemethod(string s) {         int c = 3;         (x);         } } 

the environment in (x) composed of identifiers a, b, c , s.

how can calculate environment of method in eclipse?

you have obtain icompilationunit class want parse. can make visitors node types need, methoddeclaration.

public class mainmethodvisitor extends astvisitor {      list<methoddeclaration> methods = new arraylist<methoddeclaration>();      @override     public boolean visit(methoddeclaration node) {      ... //do stuff node 

and call with:

icompilationunit unit; //... compilationunit parse = parse(unit); mainmethodvisitor visitor = new mainmethodvisitor(); parse.accept(visitor); 

having method node, can access paramenters node.parameters() obtain s. you'll have find out type of nodes class's members variables (a, b). last thing access to, think, variabledeclaration inside method node in order obtain c.

thats have you. hope helps.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -