|
From: David C. <dc...@us...> - 2005-10-09 22:13:10
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/ast In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21652/src/org/rubypeople/rdt/internal/core/ast Modified Files: DumpAst.java Log Message: Upgraded to JRuby head. More work on Updating the Symbol Index for class names. Index: DumpAst.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/ast/DumpAst.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DumpAst.java 1 Oct 2005 23:10:58 -0000 1.2 --- DumpAst.java 9 Oct 2005 22:13:01 -0000 1.3 *************** *** 5,8 **** --- 5,9 ---- import java.lang.reflect.Method; import java.lang.reflect.Proxy; + import java.util.Iterator; import org.jruby.ast.Node; *************** *** 13,21 **** public class DumpAst { private static class DumpingInvocationHandler implements InvocationHandler { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Node node = (Node) args[0]; ! System.out.println("Start: " + node.getClass().getName()); return null; --- 14,24 ---- public class DumpAst { + private static final String RUBY_CODE = "class Alpha::Beta::Gamma::Delta; end"; + private static class DumpingInvocationHandler implements InvocationHandler { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Node node = (Node) args[0]; ! System.out.println(node); return null; *************** *** 24,28 **** public static void main(String[] args) throws Exception { ! new DumpAst().dump("require 'x'; class Foo; end"); } --- 27,31 ---- public static void main(String[] args) throws Exception { ! new DumpAst().dump(RUBY_CODE); } *************** *** 34,38 **** NodeVisitor dumpVisitor = (NodeVisitor) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {NodeVisitor.class}, new DumpingInvocationHandler()); ! rootNode.accept(dumpVisitor); } --- 37,51 ---- NodeVisitor dumpVisitor = (NodeVisitor) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {NodeVisitor.class}, new DumpingInvocationHandler()); ! dumpNode(rootNode, dumpVisitor, 0); ! } ! ! private void dumpNode(Node node, NodeVisitor visitor, int depth) { ! System.out.print(" ".substring(0,depth*2)); ! node.accept(visitor); ! for (Iterator iter = node.childNodes().iterator(); iter.hasNext();) { ! Node childNode = (Node) iter.next(); ! dumpNode(childNode, visitor, depth + 1); ! } ! } |