|
From: <jas...@us...> - 2006-07-19 05:42:21
|
Revision: 1519 Author: jasonpmorrison Date: 2006-07-18 22:42:12 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1519&view=rev Log Message: ----------- IOccurrencesFinder and implementors updated to return List<Position> Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java 2006-07-19 05:41:35 UTC (rev 1518) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java 2006-07-19 05:42:12 UTC (rev 1519) @@ -35,7 +35,7 @@ return null; } - public String initialize(Node root, int offset, int length) { + public String initialize(String source, int offset, int length) { // TODO Auto-generated method stub return null; } Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java 2006-07-19 05:41:35 UTC (rev 1518) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java 2006-07-19 05:42:12 UTC (rev 1519) @@ -1,8 +1,10 @@ package org.rubypeople.rdt.internal.ti; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import org.eclipse.jface.text.Position; import org.jruby.ast.ArgumentNode; import org.jruby.ast.BlockNode; import org.jruby.ast.CallNode; @@ -22,6 +24,8 @@ import org.jruby.ast.VCallNode; import org.jruby.lexer.yacc.ISourcePosition; import org.jruby.lexer.yacc.SourcePosition; +import org.jruby.lexer.yacc.SyntaxException; +import org.rubypeople.rdt.internal.core.parser.RubyParser; import org.rubypeople.rdt.internal.ti.util.FirstPrecursorNodeLocator; import org.rubypeople.rdt.internal.ti.util.INodeAcceptor; import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator; @@ -40,8 +44,16 @@ // Originating node; corresponds to cursor selection private Node orig; - public String initialize(Node root, int offset, int length) { - this.root = root; + public String initialize(String source, int offset, int length) { + + try { + this.root = (new RubyParser()).parse(source); + } + //TODO: Is there anything else the parsing could choke on that should be silently ignored with no markings? + catch (SyntaxException se) + { + this.root = null; + } this.orig = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset); if ( orig.getPosition().getEndOffset() > offset + length ) { @@ -55,7 +67,10 @@ /** * Determines the kind of originating node, and collects occurrences accordingly */ - public List<ISourcePosition> perform() { + public List<Position> perform() { + // Mark no occurrences if root is null (AST couldn't be parsed correctly.) + if ( root == null ) return new LinkedList<Position>(); + // occurrences to return List<ISourcePosition> occurrences = new LinkedList<ISourcePosition>(); @@ -80,7 +95,14 @@ pushConstRefs( root, orig, occurrences ); } - return occurrences; + // Convert ISourcePosition to IPosition + List<Position> positions = new LinkedList<Position>(); + for (ISourcePosition occurrence : occurrences) { + Position position = new Position(occurrence.getStartOffset(),occurrence.getEndOffset() - occurrence.getStartOffset()); + positions.add(position); + } + + return positions; } // **************************************************************************** @@ -139,7 +161,7 @@ * @param occurrences */ private void pushLocalVarRefs( Node root, Node orig, List<ISourcePosition> occurrences ) { - System.out.println("Finding occurrences for a local variable " + orig.toString()); +// System.out.println("Finding occurrences for a local variable " + orig.toString()); // Find the search space Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() { @@ -180,7 +202,7 @@ * @param occurrences */ private void pushInstVarRefs( Node root, Node orig, List<ISourcePosition> occurrences ) { - System.out.println("Finding occurrences for an instance variable " + orig.toString() ); +// System.out.println("Finding occurrences for an instance variable " + orig.toString() ); Node searchSpace; Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java 2006-07-19 05:41:35 UTC (rev 1518) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java 2006-07-19 05:42:12 UTC (rev 1519) @@ -21,15 +21,15 @@ /** * - * @param root - * root AST Node + * @param source + * Ruby source to search for occurrences * @param offset * position in source where selection is * @param length * length of the selection * @return */ - public String initialize(Node root, int offset, int length); + public String initialize(String source, int offset, int length); /** * Returns a lit of AST Nodes back (which contain their associated This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |