|
From: <tc...@us...> - 2007-03-23 11:05:11
|
Revision: 2212
http://svn.sourceforge.net/rubyeclipse/?rev=2212&view=rev
Author: tcorbat
Date: 2007-03-23 04:05:08 -0700 (Fri, 23 Mar 2007)
Log Message:
-----------
Improved position treatment in EditProviders for handing comments.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/DeleteEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/EditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/util/NodeUtil.java
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/DeleteEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/DeleteEditProvider.java 2007-03-22 19:28:46 UTC (rev 2211)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/DeleteEditProvider.java 2007-03-23 11:05:08 UTC (rev 2212)
@@ -12,6 +12,7 @@
* rights and limitations under the License.
*
* Copyright (C) 2006 Lukas Felber <lf...@hs...>
+ * Copyright (C) 2007 Lukas Felber <lf...@hs...>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@@ -35,6 +36,7 @@
import org.eclipse.text.edits.TextEdit;
import org.jruby.ast.Node;
import org.rubypeople.rdt.refactoring.util.Constants;
+import org.rubypeople.rdt.refactoring.util.NodeUtil;
public class DeleteEditProvider extends EditProvider {
@@ -69,7 +71,7 @@
}
private int getStartOffset(String document) {
- int startLine = fromNode.getPosition().getStartLine();
+ int startLine = NodeUtil.subPositionUnion(fromNode).getStartLine();
int pos = -1;
for (int i = 0; i < startLine; i++) {
pos = document.indexOf(Constants.NL, pos + 1);
@@ -77,16 +79,16 @@
if (pos < 0) {
pos = 0;
}
- String leadingStr = document.substring(pos, fromNode.getPosition().getStartOffset());
+ String leadingStr = document.substring(pos, NodeUtil.subPositionUnion(fromNode).getStartOffset());
if (leadingStr.trim().equals("")) { //$NON-NLS-1$
return pos;
}
- return fromNode.getPosition().getStartOffset();
+ return NodeUtil.subPositionUnion(fromNode).getStartOffset();
}
private int getEndOffset(String document) {
- int offset = toNode.getPosition().getEndOffset();
+ int offset = NodeUtil.subPositionUnion(toNode).getEndOffset();
int aktPos = offset;
Matcher matcher = Pattern.compile("[\\s;]").matcher(document); //$NON-NLS-1$
while (matcher.find(aktPos)) {
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/EditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/EditProvider.java 2007-03-22 19:28:46 UTC (rev 2211)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/EditProvider.java 2007-03-23 11:05:08 UTC (rev 2212)
@@ -12,6 +12,7 @@
* rights and limitations under the License.
*
* Copyright (C) 2006 Lukas Felber <lf...@hs...>
+ * Copyright (C) 2006 Thomas Corbat <tc...@hs...>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@@ -29,10 +30,13 @@
package org.rubypeople.rdt.refactoring.editprovider;
import org.eclipse.text.edits.TextEdit;
+import org.jruby.ast.NewlineNode;
import org.jruby.ast.Node;
import org.jruby.ast.visitor.rewriter.DefaultFormatHelper;
import org.jruby.ast.visitor.rewriter.FormatHelper;
import org.jruby.ast.visitor.rewriter.ReWriteVisitor;
+import org.jruby.lexer.yacc.ISourcePosition;
+import org.rubypeople.rdt.refactoring.core.NodeFactory;
import org.rubypeople.rdt.refactoring.util.Constants;
import org.rubypeople.rdt.refactoring.util.HsrFormatter;
@@ -91,4 +95,18 @@
int pos = document.indexOf(Constants.NL, offset);
return (pos != -1) ? pos : document.length() - 1;
}
+
+ protected ISourcePosition getExtendedPosition(Node node){
+ if(node instanceof NewlineNode){
+ node = ((NewlineNode)node).getNextNode();
+ }
+ ISourcePosition extendedPosition = node.getPositionIncludingComments();
+
+ for(Object currentChild : node.childNodes()){
+ extendedPosition = NodeFactory.unionPositions(extendedPosition, getExtendedPosition((Node) currentChild));
+ }
+
+ return extendedPosition;
+
+ }
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/util/NodeUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/util/NodeUtil.java 2007-03-22 19:28:46 UTC (rev 2211)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/util/NodeUtil.java 2007-03-23 11:05:08 UTC (rev 2212)
@@ -30,10 +30,13 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.List;
import org.jruby.ast.IterNode;
import org.jruby.ast.MethodDefNode;
import org.jruby.ast.Node;
+import org.jruby.lexer.yacc.ISourcePosition;
+import org.jruby.lexer.yacc.SourcePosition;
import org.jruby.parser.StaticScope;
public class NodeUtil {
@@ -100,4 +103,18 @@
}
return false;
}
+
+ public static ISourcePosition subPositionUnion(Node node){
+
+ ISourcePosition enclosingPosition = node.getPositionIncludingComments();
+
+ List<Node> childList = node.childNodes();
+
+ for(Node currentChild : childList){
+ enclosingPosition = SourcePosition.combinePosition(enclosingPosition, subPositionUnion(currentChild));
+ }
+
+ return enclosingPosition;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|