|
From: David C. <dc...@us...> - 2005-10-09 22:14:14
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21686/src/org/rubypeople/rdt/internal/core/builder Modified Files: IndexUpdater.java Log Message: Upgraded to JRuby head. More work on Updating the Symbol Index for class names. Index: IndexUpdater.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/builder/IndexUpdater.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IndexUpdater.java 1 Oct 2005 23:01:00 -0000 1.1 --- IndexUpdater.java 9 Oct 2005 22:14:06 -0000 1.2 *************** *** 1,7 **** --- 1,13 ---- package org.rubypeople.rdt.internal.core.builder; + import java.util.Iterator; + import java.util.Stack; + import org.eclipse.core.resources.IFile; import org.jruby.ast.ClassNode; + import org.jruby.ast.Colon2Node; + import org.jruby.ast.IScopingNode; import org.jruby.ast.Node; + import org.jruby.ast.types.INameNode; import org.rubypeople.rdt.internal.core.symbols.ClassSymbol; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; *************** *** 10,15 **** private final SymbolIndex index; ! ! public IndexUpdater(SymbolIndex index) { this.index = index; --- 16,21 ---- private final SymbolIndex index; ! private Stack scopeStack = new Stack(); ! public IndexUpdater(SymbolIndex index) { this.index = index; *************** *** 19,26 **** public void update(IFile file, Node rootNode) { index.flush(file.getFullPath()); ! if (rootNode instanceof ClassNode) { ! ClassNode classNode = (ClassNode) rootNode; ! index.add(new ClassSymbol(classNode.getClassName()), file, classNode.getPosition()); } } --- 25,85 ---- public void update(IFile file, Node rootNode) { index.flush(file.getFullPath()); ! processNode(file, rootNode); ! } ! ! ! private void processNode(IFile file, Node node) { ! if (isScopingNode(node)) { ! IScopingNode classNode = (IScopingNode) node; ! String name = getFullyQualifiedName(classNode); ! ! scopeStack.push(name); ! if (node instanceof ClassNode) ! index.add(new ClassSymbol(name), file, node.getPosition()); } + + for (Iterator iter = node.childNodes().iterator(); iter.hasNext();) { + Node childNode = (Node) iter.next(); + processNode(file, childNode); + } + + if (isScopingNode(node)) { + scopeStack.pop(); + } + } + + + private boolean isScopingNode(Node node) { + return node instanceof IScopingNode; + } + + + private String getFullyQualifiedName(IScopingNode classNode) { + Colon2Node path = classNode.getCPath(); + return getContext() + assembleQualifiedName(path); + } + + + private String getContext() { + StringBuffer buffer = new StringBuffer(); + for (Iterator iter = scopeStack.iterator(); iter.hasNext();) { + String name = (String) iter.next(); + buffer.append(name); + buffer.append("::"); + } + return buffer.toString(); + } + + + private String assembleQualifiedName(INameNode path) { + String name = ""; + if (path instanceof Colon2Node) { + Colon2Node colon2Node = ((Colon2Node)path); + INameNode leftNode = (INameNode) colon2Node.getLeftNode(); + if (leftNode != null) + name += assembleQualifiedName(leftNode) + "::"; + } + + return name + path.getName(); } |