public static void doTreeAction(string f, AST t, string[] tokenNames) { if (t == null) { return; } if (showTree) { BaseAST.setVerboseStringConversion(true, tokenNames); ASTFactory factory = new ASTFactory(); AST r = factory.create(0, "AST ROOT"); r.setFirstChild(t); ASTFrame frame = new ASTFrame("Java AST", r); frame.ShowDialog(); //frame.Visible = true; // System.out.println(t.toStringList()); } JavaTreeParser tparse = new JavaTreeParser(); JavaRecognizer.initializeASTFactory(tparse.getASTFactory()); try { tparse.compilationUnit(t); // System.out.println("successful walk of result AST for "+f); } catch (RecognitionException e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } }
public void Load(string path) { var tokens = new CommonTokenStream(GetLexer(path)); var parser = new JavaParser(tokens); parser.enableErrorMessageCollection(true); var tree = parser.JavaSource().Tree; var nodes = new CommonTreeNodeStream(tree); var xs = new JavaTreeParser(nodes); xs.enableErrorMessageCollection(true); var rootNode = xs.JavaSource(); if (!parser.hasErrors() && !xs.hasErrors()) { } else { foreach (var message in parser.getMessages()) { Console.WriteLine(message); } foreach (var message in xs.getMessages()) { Console.WriteLine(message); } throw new NotImplementedException(); } }
public static void doTreeAction(string f, AST t, string[] tokenNames) { if (t == null) return ; if (showTree) { BaseAST.setVerboseStringConversion(true, tokenNames); ASTFactory factory = new ASTFactory(); AST r = factory.create(0, "AST ROOT"); r.setFirstChild(t); ASTFrame frame = new ASTFrame("Java AST", r); frame.ShowDialog(); //frame.Visible = true; // System.out.println(t.toStringList()); } JavaTreeParser tparse = new JavaTreeParser(); try { tparse.compilationUnit(t); // System.out.println("successful walk of result AST for "+f); } catch (RecognitionException e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } }
public static IApexNode JavaSource(this JavaTreeParser parser) { var type = parser.GetType(); var methodInfos = type.GetMethod("javaSource", BindingFlags.NonPublic | BindingFlags.Instance); var method = methodInfos; return((IApexNode)method.Invoke(parser, new object[0])); }