0

I searched high and low and can't seem to find the answer or any examples.

I am using Java ruby DLTK

I want to parse a string that has Ruby source code (.rb file). I am using it this way:

JRubySourceParser jRubyParser = new JRubySourceParser();
ModuleDeclaration result = jRubyParser.parse(getSampleStr());
ASTNode parent = result.getChilds().get(0)

Now I am stuck. I don't know how to traverse the ASTNode using a visitor. I don't want to use getChilds.

The end goal is, to get all Method Names, Classes, require files, include files, and make them into a visible tree (which I already know how to).

Is there any examples that I have missed? It really took me half a day just researching, I can't seem to find one.

Thank you.

grassJava
  • 43
  • 6

1 Answers1

0
ModuleDeclaration.traverse(new ASTVisitor() {

});
zulus
  • 2,506
  • 19
  • 20
  • I know how to instantiate ASTVisitor in a module declaration. My question is how to traverse it using ASTVisitor. I am using source element requestor for now. – grassJava Jun 10 '15 at 02:42
  • If you run .traverse on ModuleDeclaration or any other ASTNode, your node automaticaly perform visiting, visit(ClassName s), andVisit(ClassName s) ets.. And also always visitGeneral.See how look .traverse implementation on each ASTNode. ASTNode will select childrens if you allow (return true on visit(* s)) – zulus Jun 10 '15 at 19:34
  • Yes, that is my question. I can't seem to find examples how ASTNode visitor itself is implemented. – grassJava Jun 12 '15 at 02:55
  • ASTVisitor in general it's only callback class (for visit(ClassName x) methods. Real implementation is available in AST nodes. MethodDeclaration: ASTVisitor: https://github.com/eclipse/dltk.core/blob/b3acda5e47155e00e27d3a7f3d2f061dc73cb618/core/plugins/org.eclipse.dltk.core/ast/org/eclipse/dltk/ast/ASTVisitor.java#L46 and MethodDeclaration.traverse method: https://github.com/eclipse/dltk.core/blob/b3acda5e47155e00e27d3a7f3d2f061dc73cb618/core/plugins/org.eclipse.dltk.core/ast/org/eclipse/dltk/ast/declarations/MethodDeclaration.java#L68 – zulus Jun 12 '15 at 10:17