using antlr from java to obtain meta data about Java classes -


i have downloaded antlr 3.3 , antlr works, along java.g antlr site. able generate javaparser, javalexer.java , tokens using antlr works java.g. mounted antlr jar in ide , following following instructions use in code: http://www.antlr.org/wiki/pages/viewpage.action?pageid=789

the first problem arose when documentation above says code following line:

rulereturnscope result = parser.compilationunit(); 

the problem parser.compilationunit() not return result.

then tried following example further down under "parsing tree", incomplete.

i can't find documentation on how use library.

here want do: -in java submit file name, file object or file contents string antlr , have return sort of object can navigate in code give me things imports, methods, class variables, expressions etc.

basically netbeans ide 6.9.1 refactoring, fix imports, go source, rename variables etc. need meta data class, , not sure how obtain it.

thanks.

to answer question why compilationunit not return result because if don't specify return type on rule yourself, parser rule gets translated

public void nameoftheparserrule() {      ...  }  

if set output ast in options { ... } section of grammar, parser rules default return object of type rulereturnscope, suspect went wrong in case, not able since did not post grammar , link gave grammar java.g not generate anything: 1 needs things before being able generate parser , lexer it. did wrong things :).

best of luck!


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -