|
From: <tc...@us...> - 2007-05-07 13:15:03
|
Revision: 2439
http://svn.sourceforge.net/rubyeclipse/?rev=2439&view=rev
Author: tcorbat
Date: 2007-05-07 06:14:59 -0700 (Mon, 07 May 2007)
Log Message:
-----------
Comment handling improved in ConvertTempToField refactoring
Modified Paths:
--------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConverter.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldEditProvider.java
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorEditProvider.java 2007-05-05 10:50:49 UTC (rev 2438)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorEditProvider.java 2007-05-07 13:14:59 UTC (rev 2439)
@@ -50,7 +50,7 @@
public InitInConstructorEditProvider(LocalNodeWrapper originalNode, LocalToFieldConfig config) {
super(true);
- LocalToFieldEditProvider conversion = new LocalToFieldEditProvider(originalNode, config.getNewName(), config.isClassField());
+ LocalToFieldEditProvider conversion = new LocalToFieldEditProvider(originalNode, config.getNewName(), config.isClassField(), true);
insertNode = conversion.getEditNode(0, null);
enclosingClassNode = config.getEnclosingClassNode();
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConverter.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConverter.java 2007-05-05 10:50:49 UTC (rev 2438)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConverter.java 2007-05-07 13:14:59 UTC (rev 2439)
@@ -116,7 +116,8 @@
LocalNodeWrapper firstLocalNode = localNodes.toArray(new LocalNodeWrapper[localNodes.size()])[0];
for (LocalNodeWrapper aktLocalNode : localNodes) {
- LocalToFieldEditProvider conversion = new LocalToFieldEditProvider(aktLocalNode, config.getNewName(), config.isClassField());
+ boolean initInConstructor = (initPlace == INIT_IN_CONSTRUCTOR);
+ LocalToFieldEditProvider conversion = new LocalToFieldEditProvider(aktLocalNode, config.getNewName(), config.isClassField(),initInConstructor);
editProviderMap.put(aktLocalNode, conversion);
}
if (initPlace == INIT_IN_CONSTRUCTOR) {
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldEditProvider.java 2007-05-05 10:50:49 UTC (rev 2438)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldEditProvider.java 2007-05-07 13:14:59 UTC (rev 2439)
@@ -32,6 +32,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import org.jruby.ast.Node;
import org.rubypeople.rdt.refactoring.editprovider.ReplaceEditProvider;
@@ -40,10 +41,12 @@
public class LocalToFieldEditProvider extends ReplaceEditProvider {
private LocalNodeWrapper localNode;
+ private boolean initInConstructor;
- public LocalToFieldEditProvider(LocalNodeWrapper localNode, String newName, boolean isClassField) {
+ public LocalToFieldEditProvider(LocalNodeWrapper localNode, String newName, boolean isClassField, boolean initInConstructor) {
super(false);
this.localNode = localNode;
+ this.initInConstructor = initInConstructor;
newName = ((isClassField) ? "@@" : "@") + newName; //$NON-NLS-1$ //$NON-NLS-2$
Collection<LocalNodeWrapper> allLocalNodes = new ArrayList<LocalNodeWrapper>();
allLocalNodes.add(localNode);
@@ -66,16 +69,36 @@
@Override
protected int getOffsetLength() {
- return localNode.getWrappedNode().getPosition().getEndOffset() - getOffset(null);
+ if(initInConstructor)
+ return localNode.getWrappedNode().getPositionIncludingComments().getEndOffset() - getOffset(null);
+ else
+ return localNode.getWrappedNode().getPosition().getEndOffset() - getOffset(null);
}
@Override
protected Node getEditNode(int offset, String document) {
- return localNode.getWrappedNode();
+ if(initInConstructor)
+ return localNode.getWrappedNode();
+ else
+ return stripComments(localNode.getWrappedNode());
}
+ private Node stripComments(Node wrappedNode) {
+
+ wrappedNode.getComments().clear();
+ List childs = wrappedNode.childNodes();
+ for(int i = 0; i < childs.size(); i++){
+ if(childs.get(i) instanceof Node)
+ stripComments((Node)childs.get(i));
+ }
+ return wrappedNode;
+ }
+
@Override
protected int getOffset(String document) {
- return localNode.getWrappedNode().getPosition().getStartOffset();
+ if(initInConstructor)
+ return localNode.getWrappedNode().getPositionIncludingComments().getStartOffset();
+ else
+ return localNode.getWrappedNode().getPosition().getStartOffset();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|