|
From: <mir...@us...> - 2007-04-16 09:07:30
|
Revision: 2322
http://svn.sourceforge.net/rubyeclipse/?rev=2322&view=rev
Author: mirkostocker
Date: 2007-04-16 02:07:25 -0700 (Mon, 16 Apr 2007)
Log Message:
-----------
rename module: correctly rename module-method definitions, todo: usages and includes
Modified Paths:
--------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/ModuleNodeProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/ChildClassesRenameEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/ConstructorRenameEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleConfig.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentWithIncluding.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/ScopingNodeRenameEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/ModuleNodeWrapper.java
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_2.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_3.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_4.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_4.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TC_ModuleNodeProvider.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/ModuleMethodDefRenameEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/SimpleNodeEditProvider.java
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_FindMultipleMethods.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_FindSingleMethod.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_TwoSimpleModules.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.includedFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.includedFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.test_properties
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/ModuleNodeProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/ModuleNodeProvider.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/ModuleNodeProvider.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -26,16 +26,18 @@
* the terms of any one of the CPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
-
package org.rubypeople.rdt.refactoring.core;
import java.util.ArrayList;
+import java.util.Collection;
+import org.jruby.ast.ConstNode;
import org.jruby.ast.ModuleNode;
import org.jruby.ast.Node;
+import org.rubypeople.rdt.refactoring.documentprovider.IDocumentProvider;
import org.rubypeople.rdt.refactoring.nodewrapper.ModuleNodeWrapper;
-public class ModuleNodeProvider {
+public abstract class ModuleNodeProvider {
public static ModuleNodeWrapper getSelectedModuleNode(Node root, int pos) {
@@ -43,7 +45,36 @@
if(module == null) {
return null;
}
+ return createModuleNodeWrapper(root, module);
+ }
+
+ public static Collection<ModuleNodeWrapper> findOtherParts(IDocumentProvider doc, ModuleNodeWrapper module) {
+ ArrayList<ModuleNodeWrapper> modules = new ArrayList<ModuleNodeWrapper>();
+ for (String file : doc.getFileNames()) {
+ for (Node node : NodeProvider.getSubNodes(doc.getRootNode(file), ModuleNode.class)) {
+ ModuleNode moduleNode = (ModuleNode) node;
+ ModuleNodeWrapper wrapper = createModuleNodeWrapper(doc.getRootNode(file), moduleNode);
+ if(wrapper.getFullName().equals(module.getFullName())) {
+ modules.add(wrapper);
+ }
+ }
+ }
+
+ return modules;
+ }
+
+ public static Collection<ConstNode> getAllModuleMethodDefinitions(Collection<ModuleNodeWrapper> modules) {
+ ArrayList<ConstNode> methods = new ArrayList<ConstNode>();
+
+ for (ModuleNodeWrapper wrapper : modules) {
+ methods.addAll(wrapper.getModuleMethodConstNodes());
+ }
+
+ return methods;
+ }
+
+ private static ModuleNodeWrapper createModuleNodeWrapper(Node root, ModuleNode module) {
ArrayList<ModuleNode> modules = new ArrayList<ModuleNode>();
modules.add(module);
ModuleNode parent = null;
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/ChildClassesRenameEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/ChildClassesRenameEditProvider.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/ChildClassesRenameEditProvider.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -33,37 +33,11 @@
import org.jruby.ast.ClassNode;
import org.jruby.ast.ConstNode;
-import org.jruby.ast.Node;
import org.rubypeople.rdt.refactoring.editprovider.FileEditProvider;
-import org.rubypeople.rdt.refactoring.editprovider.ReplaceEditProvider;
+import org.rubypeople.rdt.refactoring.editprovider.SimpleNodeEditProvider;
public class ChildClassesRenameEditProvider {
- private static class ChildClassEditProvider extends ReplaceEditProvider {
-
- private final Node node;
-
- public ChildClassEditProvider(Node node) {
- this.node = node;
- }
-
- @Override
- protected int getOffsetLength() {
- return node.getPosition().getEndOffset() - node.getPosition().getStartOffset();
- }
-
- @Override
- protected Node getEditNode(int offset, String document) {
- return node;
- }
-
- @Override
- protected int getOffset(String document) {
- return node.getPosition().getStartOffset();
- }
-
- }
-
private final Collection<ClassNode> classes;
private final String newName;
@@ -77,7 +51,7 @@
for(ClassNode klass : classes) {
((ConstNode) klass.getSuperNode()).setName(newName);
- edits.add(new FileEditProvider(klass.getPosition().getFile(), new ChildClassEditProvider(klass.getSuperNode())));
+ edits.add(new FileEditProvider(klass.getPosition().getFile(), new SimpleNodeEditProvider(klass.getSuperNode())));
}
return edits;
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/ConstructorRenameEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/ConstructorRenameEditProvider.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renameclass/ConstructorRenameEditProvider.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -59,7 +59,6 @@
protected int getOffset(String document) {
return call.getReceiverOffset();
}
-
}
private final Collection<ConstructorCall> calls;
Added: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/ModuleMethodDefRenameEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/ModuleMethodDefRenameEditProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/ModuleMethodDefRenameEditProvider.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,58 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * 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"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
+package org.rubypeople.rdt.refactoring.core.renamemodule;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.jruby.ast.ConstNode;
+import org.rubypeople.rdt.refactoring.editprovider.FileEditProvider;
+import org.rubypeople.rdt.refactoring.editprovider.SimpleNodeEditProvider;
+
+public class ModuleMethodDefRenameEditProvider {
+
+ private final Collection<ConstNode> nodes;
+ private final String newName;
+
+ public ModuleMethodDefRenameEditProvider(Collection<ConstNode> nodes, String newName) {
+ this.nodes = nodes;
+ this.newName = newName;
+ }
+
+ public Collection<FileEditProvider> getEditProviders() {
+ Collection<FileEditProvider> edits = new ArrayList<FileEditProvider>();
+
+ for(ConstNode node : nodes) {
+ node.setName(newName);
+ edits.add(new FileEditProvider(node.getPosition().getFile(), new SimpleNodeEditProvider(node)));
+ }
+
+ return edits;
+ }
+}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleConditionChecker.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleConditionChecker.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -1,3 +1,31 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * 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"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
package org.rubypeople.rdt.refactoring.core.renamemodule;
import org.rubypeople.rdt.refactoring.core.IRefactoringConfig;
@@ -33,10 +61,10 @@
return;
}
config.setNewName(selectedModule.getName());
+ config.setModuleParts(ModuleNodeProvider.findOtherParts(config.getDocumentProvider(), config.getSelectedModule()));
}
private boolean caretIsNotOnModuleName(ModuleNodeWrapper selectedModule) {
return !NodeUtil.positionIsInNode(config.getCarretPosition(), selectedModule.getWrappedNode().getCPath());
}
-
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleConfig.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleConfig.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleConfig.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -1,6 +1,37 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * 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"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
package org.rubypeople.rdt.refactoring.core.renamemodule;
+import java.util.Collection;
+
import org.rubypeople.rdt.refactoring.core.IRefactoringConfig;
+import org.rubypeople.rdt.refactoring.documentprovider.DocumentWithIncluding;
import org.rubypeople.rdt.refactoring.documentprovider.IDocumentProvider;
import org.rubypeople.rdt.refactoring.nodewrapper.ModuleNodeWrapper;
import org.rubypeople.rdt.refactoring.ui.INewNameReceiver;
@@ -11,6 +42,7 @@
private final int carretPosition;
private ModuleNodeWrapper selectedModule;
private String newName;
+ private Collection<ModuleNodeWrapper> moduleParts;
public RenameModuleConfig(IDocumentProvider doc, int carretPosition) {
this.doc = doc;
@@ -22,7 +54,7 @@
}
public void setDocumentProvider(IDocumentProvider doc) {
- this.doc = doc;
+ this.doc = new DocumentWithIncluding(doc);
}
public void setNewName(String newName) {
@@ -48,4 +80,12 @@
public String getNewName() {
return newName;
}
+
+ public void setModuleParts(Collection<ModuleNodeWrapper> moduleParts) {
+ this.moduleParts = moduleParts;
+ }
+
+ public Collection<ModuleNodeWrapper> getModuleParts() {
+ return moduleParts;
+ }
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleEditProvider.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemodule/RenameModuleEditProvider.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -1,3 +1,32 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * 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"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
+
package org.rubypeople.rdt.refactoring.core.renamemodule;
import java.util.ArrayList;
@@ -4,10 +33,12 @@
import java.util.Collection;
import org.jruby.ast.IScopingNode;
+import org.rubypeople.rdt.refactoring.core.ModuleNodeProvider;
import org.rubypeople.rdt.refactoring.editprovider.FileMultiEditProvider;
import org.rubypeople.rdt.refactoring.editprovider.IMultiFileEditProvider;
import org.rubypeople.rdt.refactoring.editprovider.MultiFileEditProvider;
import org.rubypeople.rdt.refactoring.editprovider.ScopingNodeRenameEditProvider;
+import org.rubypeople.rdt.refactoring.nodewrapper.ModuleNodeWrapper;
public class RenameModuleEditProvider implements IMultiFileEditProvider {
@@ -16,17 +47,26 @@
public RenameModuleEditProvider(RenameModuleConfig config) {
this.config = config;
}
-
+
private ScopingNodeRenameEditProvider getModuleEditProvider() {
ArrayList<IScopingNode> modules = new ArrayList<IScopingNode>();
- modules.add(config.getSelectedModule().getWrappedNode());
+
+ for (ModuleNodeWrapper node : config.getModuleParts()) {
+ modules.add(node.getWrappedNode());
+ }
+
return new ScopingNodeRenameEditProvider(modules, config.getNewName());
}
+
+ private ModuleMethodDefRenameEditProvider getModuleModuleMethodDefEditProvider() {
+ return new ModuleMethodDefRenameEditProvider(ModuleNodeProvider.getAllModuleMethodDefinitions(config.getModuleParts()), config.getNewName());
+ }
public Collection<FileMultiEditProvider> getFileEditProviders() {
MultiFileEditProvider fileEdits = new MultiFileEditProvider();
fileEdits.addEditProviders(getModuleEditProvider().getEditProviders());
+ fileEdits.addEditProviders(getModuleModuleMethodDefEditProvider().getEditProviders());
return fileEdits.getFileEditProviders();
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentWithIncluding.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentWithIncluding.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/DocumentWithIncluding.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -66,7 +66,7 @@
continue;
}
for (FCallNode node : getRequires(actFileName)) {
- if(nodeRequiresMe(node)) {
+ if(nodeRequiresMe(node) && !getFileNames().contains(actFileName)) {
addAndRemove(markedForRemoval, actFileName, fileName);
}
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/ScopingNodeRenameEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/ScopingNodeRenameEditProvider.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/ScopingNodeRenameEditProvider.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -33,35 +33,9 @@
import org.jruby.ast.IScopingNode;
import org.jruby.ast.Node;
-import org.rubypeople.rdt.refactoring.editprovider.FileEditProvider;
-import org.rubypeople.rdt.refactoring.editprovider.ReplaceEditProvider;
public class ScopingNodeRenameEditProvider {
- private static class ScopingNodeRenameEdit extends ReplaceEditProvider {
-
- private final IScopingNode node;
-
- public ScopingNodeRenameEdit(IScopingNode klass) {
- this.node = klass;
- }
-
- @Override
- protected int getOffsetLength() {
- return node.getCPath().getPosition().getEndOffset() - node.getCPath().getPosition().getStartOffset();
- }
-
- @Override
- protected Node getEditNode(int offset, String document) {
- return node.getCPath();
- }
-
- @Override
- protected int getOffset(String document) {
- return node.getCPath().getPosition().getStartOffset();
- }
- }
-
private final Collection<? extends IScopingNode> nodes;
private final String newName;
@@ -75,7 +49,7 @@
for(IScopingNode klass : nodes) {
klass.getCPath().setName(newName);
- edits.add(new FileEditProvider(((Node) klass).getPosition().getFile(), new ScopingNodeRenameEdit(klass)));
+ edits.add(new FileEditProvider(((Node) klass).getPosition().getFile(), new SimpleNodeEditProvider(klass.getCPath())));
}
return edits;
Added: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/SimpleNodeEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/SimpleNodeEditProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/editprovider/SimpleNodeEditProvider.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,55 @@
+/***** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ *
+ * 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"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
+
+package org.rubypeople.rdt.refactoring.editprovider;
+
+import org.jruby.ast.Node;
+
+public class SimpleNodeEditProvider extends ReplaceEditProvider {
+
+ private final Node node;
+
+ public SimpleNodeEditProvider(Node node) {
+ this.node = node;
+ }
+
+ @Override
+ protected int getOffsetLength() {
+ return node.getPosition().getEndOffset() - node.getPosition().getStartOffset();
+ }
+
+ @Override
+ protected Node getEditNode(int offset, String document) {
+ return node;
+ }
+
+ @Override
+ protected int getOffset(String document) {
+ return node.getPosition().getStartOffset();
+ }
+}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/ModuleNodeWrapper.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/ModuleNodeWrapper.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/ModuleNodeWrapper.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -1,14 +1,23 @@
package org.rubypeople.rdt.refactoring.nodewrapper;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.jruby.ast.ConstNode;
+import org.jruby.ast.DefsNode;
import org.jruby.ast.ModuleNode;
+import org.jruby.ast.Node;
+import org.rubypeople.rdt.refactoring.core.NodeProvider;
public class ModuleNodeWrapper implements INodeWrapper {
private final ModuleNode moduleNode;
private ModuleNodeWrapper parentModule;
+ private ArrayList<ConstNode> moduleMethodNodes = new ArrayList<ConstNode>();;
public ModuleNodeWrapper(ModuleNode moduleNode, ModuleNodeWrapper parentModule) {
this.moduleNode = moduleNode;
- this.parentModule = parentModule;
+ this.parentModule = parentModule;
+ initModuleMethodConstNodes();
}
public ModuleNode getWrappedNode() {
@@ -30,4 +39,18 @@
public String getFullName() {
return (parentModule != null ? parentModule.getFullName() + "::" : "") + getName();
}
+
+ public Collection<ConstNode> getModuleMethodConstNodes() {
+
+ return moduleMethodNodes;
+ }
+
+ private void initModuleMethodConstNodes() {
+ for (Node node : NodeProvider.getSubNodes(getWrappedNode(), DefsNode.class)) {
+ ConstNode constNode = (ConstNode) ((DefsNode) node).getReceiverNode();
+ if(constNode.getName().equals(getName())) {
+ moduleMethodNodes.add(constNode);
+ }
+ }
+ }
}
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_FindMultipleMethods.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_FindMultipleMethods.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_FindMultipleMethods.rb 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,20 @@
+module Modul
+ def Modul.test_method
+ end
+end
+
+module OuterModul
+ module Modul
+ def Modul.test_method
+ end
+ end
+end
+
+module Modul
+ def Modul.test_method
+ end
+ def Modul.second_method
+ end
+ def Modul.third_method
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_FindSingleMethod.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_FindSingleMethod.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_FindSingleMethod.rb 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,16 @@
+module Modul
+ def Modul.test_method
+ end
+end
+
+module OuterModul
+ module Modul
+ def Modul.test_method
+ end
+ end
+end
+
+module Modul
+ def Modul.test_method
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_TwoSimpleModules.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_TwoSimpleModules.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/TC_ModuleNodeProvider_TwoSimpleModules.rb 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,12 @@
+module Modul
+end
+
+module Modul
+ module Modul
+ end
+end
+
+module Crap
+ module Modul
+ end
+end
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_2.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_2.test_properties 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_2.test_properties 2007-04-16 09:07:25 UTC (rev 2322)
@@ -1,3 +1,3 @@
-name=Debug
+name=Moral
pos=8
activeFile=activeFile.rb
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_3.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_3.test_properties 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_3.test_properties 2007-04-16 09:07:25 UTC (rev 2322)
@@ -1,3 +1,3 @@
-name=NewModule
+name=Debug
pos=8
activeFile=activeFile.rb
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_4.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_4.activeFile.rb.result 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_4.activeFile.rb.result 2007-04-16 09:07:25 UTC (rev 2322)
@@ -6,15 +6,15 @@
end
module Module
- module CentralModule
+ module InnerModule
end
end
-module CentralModule
+module InnerModule
end
class ModulTest
include OuterModule::Module::CentralModule
- include Module::CentralModule
- include CentralModule
+ include Module::InnerModule
+ include InnerModule
end
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_4.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_4.test_properties 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_4.test_properties 2007-04-16 09:07:25 UTC (rev 2322)
@@ -1,3 +1,3 @@
-name=NewModule
-pos=8
+name=CentralModule
+pos=47
activeFile=activeFile.rb
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.activeFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.activeFile.rb.result 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,5 @@
+module NewModule
+end
+
+module NewModule
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.activeFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.activeFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.activeFile.rb.source 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,5 @@
+module Modul
+end
+
+module Modul
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_5.test_properties 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,3 @@
+name=NewModule
+pos=8
+activeFile=activeFile.rb
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.activeFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.activeFile.rb.result 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,7 @@
+require 'includedFile'
+
+module NewModule
+end
+
+module NewModule
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.activeFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.activeFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.activeFile.rb.source 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,7 @@
+require 'includedFile'
+
+module Modul
+end
+
+module Modul
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.includedFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.includedFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.includedFile.rb.result 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,5 @@
+module NewModule
+end
+
+module NewModule
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.includedFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.includedFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.includedFile.rb.source 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,5 @@
+module Modul
+end
+
+module Modul
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_6.test_properties 2007-04-16 09:07:25 UTC (rev 2322)
@@ -0,0 +1,4 @@
+name=NewModule
+pos=52
+activeFile=activeFile.rb
+destinationFiles=includedFile.rb
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TC_ModuleNodeProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TC_ModuleNodeProvider.java 2007-04-16 00:20:37 UTC (rev 2321)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/TC_ModuleNodeProvider.java 2007-04-16 09:07:25 UTC (rev 2322)
@@ -28,7 +28,12 @@
package org.rubypeople.rdt.refactoring.tests.core;
+import java.util.Collection;
+
+import org.jruby.ast.ConstNode;
+import org.jruby.lexer.yacc.SourcePosition;
import org.rubypeople.rdt.refactoring.core.ModuleNodeProvider;
+import org.rubypeople.rdt.refactoring.documentprovider.StringDocumentProvider;
import org.rubypeople.rdt.refactoring.nodewrapper.ModuleNodeWrapper;
import org.rubypeople.rdt.refactoring.tests.FileTestCase;
@@ -42,6 +47,10 @@
return ModuleNodeProvider.getSelectedModuleNode(getRootNode(file),position);
}
+ private Collection<ModuleNodeWrapper> findModules(String file, ModuleNodeWrapper moduleNode) {
+ return ModuleNodeProvider.findOtherParts(new StringDocumentProvider("TC_ModuleNodeProvider", getSource(file)), moduleNode);
+ }
+
public void testSimpleModule() {
ModuleNodeWrapper moduleNode = findModule("TC_ModuleNodeProvider_SimpleModule.rb", 8);
@@ -68,4 +77,47 @@
assertEquals("M5", moduleNode.getName());
assertEquals("M1::M2::M3::M4::M5", moduleNode.getFullName());
}
+
+ public void testTwoSimpleModules() {
+ ModuleNodeWrapper[] nodeWrappers = getModules("TC_ModuleNodeProvider_TwoSimpleModules.rb", 8).toArray(new ModuleNodeWrapper[]{});
+
+ assertEquals(2, nodeWrappers.length);
+ assertEquals("Modul", nodeWrappers[0].getFullName());
+ assertEquals("Modul", nodeWrappers[1].getFullName());
+ }
+
+ private Collection<ModuleNodeWrapper> getModules(String fileName, int pos) {
+ ModuleNodeWrapper moduleNode = findModule(fileName, pos);
+ return findModules(fileName, moduleNode);
+ }
+
+ public void testFindSingleMethod() {
+ Collection<ModuleNodeWrapper> modules = getModules("TC_ModuleNodeProvider_FindSingleMethod.rb", 8);
+ ConstNode[] nodes = ModuleNodeProvider.getAllModuleMethodDefinitions(modules).toArray(new ConstNode[]{});
+
+ assertEquals(2, nodes.length);
+ assertEquals("Modul", nodes[0].getName());
+ assertEquals(new SourcePosition("TC_ModuleNodeProvider", 1, 1, 19, 24), nodes[0].getPosition());
+
+ assertEquals("Modul", nodes[1].getName());
+ assertEquals(new SourcePosition("TC_ModuleNodeProvider", 13, 13, 145, 150), nodes[1].getPosition());
+ }
+
+ public void testFindMultipleMethods() {
+ Collection<ModuleNodeWrapper> modules = getModules("TC_ModuleNodeProvider_FindMultipleMethods.rb", 8);
+ ConstNode[] nodes = ModuleNodeProvider.getAllModuleMethodDefinitions(modules).toArray(new ConstNode[]{});
+
+ assertEquals(4, nodes.length);
+ assertEquals("Modul", nodes[0].getName());
+ assertEquals(new SourcePosition("TC_ModuleNodeProvider", 1, 1, 19, 24), nodes[0].getPosition());
+
+ assertEquals("Modul", nodes[1].getName());
+ assertEquals(new SourcePosition("TC_ModuleNodeProvider", 13, 13, 145, 150), nodes[1].getPosition());
+
+ assertEquals("Modul", nodes[2].getName());
+ assertEquals(new SourcePosition("TC_ModuleNodeProvider", 15, 15, 175, 180), nodes[2].getPosition());
+
+ assertEquals("Modul", nodes[3].getName());
+ assertEquals(new SourcePosition("TC_ModuleNodeProvider", 17, 17, 207, 212), nodes[3].getPosition());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|