|
From: <jas...@us...> - 2006-07-06 20:12:07
|
Revision: 1507 Author: jasonpmorrison Date: 2006-07-06 13:11:55 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1507&view=rev Log Message: ----------- Added tests for & implemented more occurence marking Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java Added Paths: ----------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java Added: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java 2006-07-06 20:11:55 UTC (rev 1507) @@ -0,0 +1,58 @@ +package org.rubypeople.rdt.internal.ti; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.jface.text.IDocument; +import org.jruby.ast.Node; +import org.rubypeople.rdt.core.IRubyElement; +import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator; +//import org.rubypeople.rdt.internal.ui.search.IOccurrencesFinder; + +public class DefaultOccurenceFinder /* implements IOccurrencesFinder */ { + + public void collectOccurrenceMatches(IRubyElement element, IDocument document, Collection resultingMatches) { + // TODO Auto-generated method stub + } + + public String getElementName() { + // TODO Auto-generated method stub + return null; + } + + public String getJobLabel() { + // TODO Auto-generated method stub + return null; + } + + public String getUnformattedPluralLabel() { + // TODO Auto-generated method stub + return null; + } + + public String getUnformattedSingularLabel() { + // TODO Auto-generated method stub + return null; + } + + private Node root; + private Node orig; + + public String initialize(Node root, int offset, int length) { + this.root = root; + this.orig = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset); + if ( orig.getPosition().getEndOffset() > offset + length ) + { + // Selection spans nodes; not handling that for now. + return "Selection spans nodes; can only search for a single node."; + } + + return null; + } + + public List perform() { + // TODO Auto-generated method stub + return null; + } + +} Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java 2006-07-06 20:11:46 UTC (rev 1506) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java 2006-07-06 20:11:55 UTC (rev 1507) @@ -13,6 +13,7 @@ import org.jruby.ast.CallNode; import org.jruby.ast.ClassNode; import org.jruby.ast.Colon2Node; +import org.jruby.ast.ConstNode; import org.jruby.ast.DVarNode; import org.jruby.ast.DefnNode; import org.jruby.ast.DefsNode; @@ -76,6 +77,11 @@ if ( isMethodRefNode(orig)) { pushMethodRefs( root, orig, references ); } + + if ( orig instanceof ConstNode ) + { + pushConstRefs( root, orig, references ); + } return references; } @@ -85,13 +91,14 @@ ISourcePosition pos = node.getPosition(); //todo: refactor the getting-of-name - String name = getLocalVarRefName(node, scope); + String name = null; + if ( isLocalVarRef(node) ) { name = getLocalVarRefName(node, scope); } + if ( isInstanceVarRef(node) ) { name = getInstVarRefName(node, scope); } + if ( isGlobalVarRef(node) ) { name = getGlobalVarRefName(node); } + if ( node instanceof ConstNode ) { name = ((ConstNode)node).getName(); } + if ( name == null ) { - name = getInstVarRefName(node, scope); - } - if ( name == null ) - { System.err.println("Couldn't get the name for: " + node.toString() + " in " + scope.toString() ); } return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length() ); @@ -179,6 +186,35 @@ return null; } + private String getGlobalVarRefName( Node node ) { + if ( node instanceof GlobalVarNode ) + { + return ((GlobalVarNode)node).getName(); + } + if ( node instanceof GlobalAsgnNode ) { + return ((GlobalAsgnNode)node).getName(); + } + return null; + } + + private String getMethodRefName( Node node ) { + if ( node instanceof DefnNode ) { + return ((DefnNode)node).getName(); + } + if ( node instanceof DefsNode ) { + return ((DefsNode)node).getName(); + } + if ( node instanceof CallNode ) { + return ((CallNode)node).getName(); + } + if ( node instanceof VCallNode ) { + return ((VCallNode)node).getMethodName(); + } + return null; + } + + + private boolean isLocalVarRef( Node node ) { return ( ( node instanceof LocalAsgnNode ) || ( node instanceof ArgumentNode ) || ( node instanceof LocalVarNode ) ); } @@ -262,8 +298,7 @@ return false; } }); - //todo: is this cool with the "n/a" and all? - BlockNode blockNode = new BlockNode(new SourcePosition("n/a",0));//new ListNode(new SourcePosition("n/a",0)); + BlockNode blockNode = new BlockNode(new SourcePosition("",0)); for ( Node classNode : classNodes ) { blockNode.add( classNode ); @@ -280,8 +315,12 @@ // Find all pertinent nodes List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { public boolean doesAccept(Node node) { - String name = getInstVarRefName(node, finalSearchSpace); - return ( name != null && name.equals(origName)); + if ( isInstanceVarRef(node) ) + { + String name = getInstVarRefName(node, finalSearchSpace); + return ( name != null && name.equals(origName)); + } + return false; } }); @@ -293,13 +332,62 @@ } private void pushGlobalVarRefs( Node root, Node orig, List<ISourcePosition> references ) { + final Node searchSpace = root; + final String origName = getGlobalVarRefName(orig); + // Find all pertinent nodes + List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { + public boolean doesAccept(Node node) { + return isGlobalVarRef(node) && getGlobalVarRefName(node).equals(origName); + } + }); + + // Scrape position from pertinent nodes + for ( Node searchResult : searchResults ) { + references.add(getPositionOfName(searchResult, searchSpace)); + } } private void pushMethodRefs( Node root, Node orig, List<ISourcePosition> references) { + + // DefnNode DefsNode CallNode VCallNode + System.out.println("Finding references for method reference node " + orig.toString() ); + + final Node searchSpace = root; + String origName = getMethodRefName(orig); + + // If orig is a method definition, find all references to that selector for the orig's enclosing type + if ( orig instanceof DefnNode || orig instanceof DefsNode ) + { + ((DefnNode)orig).g + } + + Node receiver = getMethodReceiver(orig); } + private void pushConstRefs( Node root, Node orig, List<ISourcePosition> references) { + if ( !( orig instanceof ConstNode) ) + { + return; + } + + final String matchName = ((ConstNode)orig).getName(); + List <Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() { + public boolean doesAccept(Node node) { + if ( node instanceof ConstNode ) + { + return ((ConstNode)node).getName().equals(matchName); + } + return false; + } + }); + + for ( Node searchResult : searchResults ) { + references.add(getPositionOfName(searchResult, root ) ); + } + } + } Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java 2006-07-06 20:11:46 UTC (rev 1506) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java 2006-07-06 20:11:55 UTC (rev 1507) @@ -50,7 +50,7 @@ */ public Instruction handleNode(Node iVisited) { - System.out.println("Looking for node at offset, checking: " + iVisited.getClass().getName() + "[" + iVisited.getPosition().getStartOffset() + ".." + iVisited.getPosition().getEndOffset() + "]" ); +// System.out.println("Looking for node at offset, checking: " + iVisited.getClass().getName() + "[" + iVisited.getPosition().getStartOffset() + ".." + iVisited.getPosition().getEndOffset() + "]" ); if (nodeDoesSpanOffset(iVisited, offset)) { //note: careful... should this be <=? I think so; since it traverses in-order, this should find the "most specific" closest node. i.e. //def foo;x;end offset at 'x' is a 1-char ScopingNode and 1-char LocalVarNode; it should identify the LocalVarNode, which <= does. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |