|
From: <mir...@us...> - 2007-03-19 13:07:51
|
Revision: 2200
http://svn.sourceforge.net/rubyeclipse/?rev=2200&view=rev
Author: mirkostocker
Date: 2007-03-19 06:07:45 -0700 (Mon, 19 Mar 2007)
Log Message:
-----------
rename fields if an accessor method is renamed
Modified Paths:
--------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/movemethod/DelegateMethodEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/movemethod/MoveMethodConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/FieldProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/FieldRenamer.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/RenameFieldConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/MethodRenamer.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/RenameMethodConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/RenameMethodConfig.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/StringDocumentProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/ClassNodeWrapper.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/MethodNodeWrapper.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/PartialClassNodeWrapper.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/signatureprovider/MethodSignature.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/ui/pages/OccurenceReplaceSelectionPage.java
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_10.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/TS_All.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/nodewrapper/TS_NodeWrapper.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/renamemethod/selection/RenameMethodSelectionTester.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/InstVarAccessesFinder.java
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.test_properties
Removed Paths:
-------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/FieldProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/MethodDefinitionWrapper.java
Deleted: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/FieldProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/FieldProvider.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/FieldProvider.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -1,206 +0,0 @@
-/***** 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 Lukas Felber <lf...@hs...>
- * Copyright (C) 2006 Mirko Stocker <me...@mi...>
- * 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"),
- * 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;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-
-import org.jruby.ast.FCallNode;
-import org.jruby.ast.InstAsgnNode;
-import org.jruby.ast.InstVarNode;
-import org.jruby.ast.Node;
-import org.jruby.ast.SymbolNode;
-import org.jruby.lexer.yacc.ISourcePosition;
-import org.rubypeople.rdt.refactoring.nodewrapper.AttrAccessorNodeWrapper;
-import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
-
-public class FieldProvider {
-
- private ClassNodeWrapper classNode;
-
- private LinkedHashMap<String, ArrayList<FCallNode>> attrs;
-
- private LinkedHashMap<String, ArrayList<AttrAccessorNodeWrapper>> accessors;
-
- private LinkedHashMap<String, ArrayList<InstVarNode>> instVars;
-
- private LinkedHashMap<String, ArrayList<InstAsgnNode>> instAsgns;
-
- public FieldProvider(ClassNodeWrapper classNode){
- this.classNode = classNode;
- initAttrs();
- initAccessors();
- }
-
- private void initAccessors() {
-
- accessors = new LinkedHashMap<String, ArrayList<AttrAccessorNodeWrapper>>();
-
- for(AttrAccessorNodeWrapper currentAccessor : classNode.getAccessorNodes()){
-
- String name = fieldName(currentAccessor.getAttrName());
-
- if(!accessors.containsKey(name)){
- accessors.put(name, new ArrayList<AttrAccessorNodeWrapper>());
- }
- ArrayList<AttrAccessorNodeWrapper> accessorList = accessors.get(name);
- accessorList.add(currentAccessor);
- }
- }
-
- private void initAttrs() {
-
- attrs = new LinkedHashMap<String, ArrayList<FCallNode>>();
- instVars = new LinkedHashMap<String, ArrayList<InstVarNode>>();
- instAsgns = new LinkedHashMap<String, ArrayList<InstAsgnNode>>();
-
- Collection<Node> allAttrs = classNode.getAttrNodes();
-
- for(Node currentAttr : allAttrs){
- if(currentAttr instanceof FCallNode){
- addAttr((FCallNode)currentAttr);
- }
- else if (currentAttr instanceof InstVarNode){
- addInstVar((InstVarNode)currentAttr );
- }
- else if (currentAttr instanceof InstAsgnNode){
- addInstAsgn((InstAsgnNode)currentAttr);
- }
- }
- }
-
- private void addInstAsgn(InstAsgnNode currentAttr) {
-
- String name = fieldName(currentAttr.getName());
-
- if(!attrs.containsKey(name)){
- instAsgns.put(name, new ArrayList<InstAsgnNode>());
- }
- ArrayList<InstAsgnNode> asgnList = instAsgns.get(name);
- asgnList.add(currentAttr);
- }
-
-
- public static String fieldName(String name) {
- return name.replaceAll("@|:", ""); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private void addInstVar(InstVarNode currentAttr) {
- String name = fieldName(currentAttr.getName());
-
- if(!attrs.containsKey(name)){
- instVars.put(name, new ArrayList<InstVarNode>());
- }
- ArrayList<InstVarNode> varList = instVars.get(name);
- varList.add(currentAttr);
- }
-
- private void addAttr(FCallNode currentAttr) {
- SymbolNode symbol = (SymbolNode)currentAttr.getArgsNode();
- String name = fieldName(symbol.getName());
-
- if(!attrs.containsKey(name)){
- attrs.put(name, new ArrayList<FCallNode>());
- }
- ArrayList<FCallNode> attrList = attrs.get(name);
- attrList.add(currentAttr);
- }
-
- public ArrayList<AttrAccessorNodeWrapper> getAccessors(String fieldName) {
- return accessors.get(fieldName);
- }
-
- public ArrayList<FCallNode> getAttrs(String fieldName) {
- return attrs.get(fieldName);
- }
-
- public ArrayList<InstAsgnNode> getInstAsgns(String fieldName) {
- return instAsgns.get(fieldName);
- }
-
- public ArrayList<InstVarNode> getInstVars(String fieldName) {
- return instVars.get(fieldName);
- }
-
- public Collection<String> getFieldNames() {
- HashSet<String> names = new HashSet<String>();
- names.addAll(attrs.keySet());
- names.addAll(accessors.keySet());
- names.addAll(instVars.keySet());
- names.addAll(instAsgns.keySet());
- return names;
- }
-
- public String getNameAtPosition(int caretPosition) {
-
- for(String currentName : attrs.keySet()){
- for(FCallNode currentFCall : attrs.get(currentName)){
- if(containsPosition(caretPosition, currentFCall.getArgsNode().getPosition())){
- return currentName;
- }
- }
- }
-
- for(String currentName : accessors.keySet()){
- for(AttrAccessorNodeWrapper currentAccessorWrapper : accessors.get(currentName)){
- for(FCallNode currentAccessor : currentAccessorWrapper.getAccessorNodes()){
- if(containsPosition(caretPosition, currentAccessor.getArgsNode().getPosition())){
- return currentName;
- }
- }
- }
- }
-
- for(String currentName : instVars.keySet()){
- for(InstVarNode currentInstVar : instVars.get(currentName)){
- if(containsPosition(caretPosition, currentInstVar.getPosition())){
- return currentName;
- }
- }
- }
-
- for(String currentName : instAsgns.keySet()){
- for(InstAsgnNode currentInstAsgn : instAsgns.get(currentName)){
- if(containsPosition(caretPosition, currentInstAsgn.getPosition())){
- return currentName;
- }
- }
- }
-
- return null;
- }
-
- private boolean containsPosition(int offset, ISourcePosition pos){
- return (pos.getStartOffset() <= offset) && (pos.getEndOffset() >= offset);
- }
-}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/movemethod/DelegateMethodEditProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/movemethod/DelegateMethodEditProvider.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/movemethod/DelegateMethodEditProvider.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -49,7 +49,7 @@
super(false);
this.config = config;
oldMethod = config.getMethodNode();
- scopePos = NodeProvider.unwrap(oldMethod.getScopeNode()).getPosition();
+ scopePos = NodeProvider.unwrap(oldMethod.getBodyNode()).getPosition();
}
@Override
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/movemethod/MoveMethodConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/movemethod/MoveMethodConditionChecker.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/movemethod/MoveMethodConditionChecker.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -68,7 +68,7 @@
/*don't care*/
}
MethodDefNode methodDefNode = (MethodDefNode) SelectionNodeProvider.getSelectedNodeOfType(rootNode, caretPos, MethodDefNode.class);
- MethodNodeWrapper methodNode = (methodDefNode == null) ? null : new MethodNodeWrapper(methodDefNode);
+ MethodNodeWrapper methodNode = (methodDefNode == null) ? null : new MethodNodeWrapper(methodDefNode, config.getSourceClassNode());
config.setMethodNode(methodNode);
initTargetClassNames();
if(config.getSourceClassNode() != null) {
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/FieldProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/FieldProvider.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/FieldProvider.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -220,7 +220,7 @@
public ArrayList<FieldItem> getFieldItems(String fieldName, boolean concernsClassField) {
ArrayList<FieldItem> matchingItems = new ArrayList<FieldItem>();
-
+
for(FieldItem currentItem : fields.get(fieldName)){
if(currentItem.concernsClassField() == concernsClassField){
matchingItems.add(currentItem);
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/FieldRenamer.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/FieldRenamer.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/FieldRenamer.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -80,6 +80,7 @@
ISourcePosition methodPosition = currentMethod.getWrappedNode().getPosition();
RenameMethodConfig methodConfig = new RenameMethodConfig(config.getDocumentProvider(), methodPosition.getStartOffset());
new RenameMethodConditionChecker(methodConfig);
+ methodConfig.setRenameFields(false);
if(currentMethod.getName().equals(config.getSelectedName())){
methodConfig.setNewName(config.getNewName());
MethodRenamer methodRenamer = new MethodRenamer(methodConfig);
Added: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/InstVarAccessesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/InstVarAccessesFinder.java (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/InstVarAccessesFinder.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,76 @@
+/***** 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 Lukas Felber <lf...@hs...>
+ * Copyright (C) 2006 Mirko Stocker <me...@mi...>
+ * 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"),
+ * 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.renamefield;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.jruby.ast.CallNode;
+import org.jruby.ast.Node;
+import org.rubypeople.rdt.refactoring.core.SelectionNodeProvider;
+import org.rubypeople.rdt.refactoring.core.renamefield.fielditems.FieldCallItem;
+import org.rubypeople.rdt.refactoring.core.renamefield.fielditems.FieldItem;
+import org.rubypeople.rdt.refactoring.documentprovider.IDocumentProvider;
+import org.rubypeople.rdt.refactoring.exception.NoClassNodeException;
+
+public class InstVarAccessesFinder {
+
+ public static Collection<FieldItem> find(IDocumentProvider document, String selectedName) {
+ ArrayList<FieldItem> fieldCallNodes = new ArrayList<FieldItem>();
+
+ Collection<Node> allNodes = document.getAllNodes();
+ for (Node currentNode : allNodes) {
+ if (isPossibleCall(currentNode, document, selectedName)) {
+ fieldCallNodes.add(new FieldCallItem((CallNode) currentNode));
+ }
+ }
+
+ return fieldCallNodes;
+ }
+
+ private static boolean isPossibleCall(Node candidateNode, IDocumentProvider document, String selectedName) {
+ if ((candidateNode instanceof CallNode)) {
+
+ CallNode callNode = (CallNode) candidateNode;
+ if (callNode.getName().replaceAll("=", "").equals(selectedName)) { //$NON-NLS-1$ //$NON-NLS-2$
+ String fileName = callNode.getPosition().getFile();
+ Node rootNode = document.getRootNode(fileName);
+ try {
+ SelectionNodeProvider.getSelectedClassNode(rootNode, callNode.getPosition().getStartOffset());
+ } catch (NoClassNodeException e) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/RenameFieldConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/RenameFieldConditionChecker.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamefield/RenameFieldConditionChecker.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -33,16 +33,12 @@
import java.util.ArrayList;
import java.util.Collection;
-import org.jruby.ast.CallNode;
-import org.jruby.ast.Node;
import org.jruby.ast.RootNode;
import org.rubypeople.rdt.refactoring.classnodeprovider.ClassNodeProvider;
import org.rubypeople.rdt.refactoring.classnodeprovider.IncludedClassesProvider;
import org.rubypeople.rdt.refactoring.core.IRefactoringConfig;
-import org.rubypeople.rdt.refactoring.core.NodeProvider;
import org.rubypeople.rdt.refactoring.core.RefactoringConditionChecker;
import org.rubypeople.rdt.refactoring.core.SelectionNodeProvider;
-import org.rubypeople.rdt.refactoring.core.renamefield.fielditems.FieldCallItem;
import org.rubypeople.rdt.refactoring.core.renamefield.fielditems.FieldItem;
import org.rubypeople.rdt.refactoring.documentprovider.DocumentWithIncluding;
import org.rubypeople.rdt.refactoring.exception.NoClassNodeException;
@@ -98,42 +94,13 @@
possibleItems.addAll(selectedItems);
if (!concernsClassField) {
- possibleItems.addAll(getInstVarAccesses());
+ possibleItems.addAll(InstVarAccessesFinder.find(config.getDocumentProvider(), config.getSelectedName()));
}
config.setPossibleCalls(possibleItems);
}
- private Collection<FieldItem> getInstVarAccesses() {
- ArrayList<FieldItem> fieldCallNodes = new ArrayList<FieldItem>();
- Collection<Node> allNodes = NodeProvider.getAllNodes(rootNode);
- for (Node currentNode : allNodes) {
- if (isPossibleCall(currentNode)) {
- fieldCallNodes.add(new FieldCallItem((CallNode) currentNode));
- }
- }
-
- return fieldCallNodes;
- }
-
- private boolean isPossibleCall(Node candidateNode) {
- if ((candidateNode instanceof CallNode)) {
-
- CallNode callNode = (CallNode) candidateNode;
- if (callNode.getName().replaceAll("=", "").equals(config.getSelectedName())) { //$NON-NLS-1$ //$NON-NLS-2$
- String fileName = callNode.getPosition().getFile();
- Node rootNode = config.getDocumentProvider().getRootNode(fileName);
- try {
- SelectionNodeProvider.getSelectedClassNode(rootNode, callNode.getPosition().getStartOffset());
- } catch (NoClassNodeException e) {
- return true;
- }
- }
- }
- return false;
- }
-
@Override
protected void checkFinalConditions() {
String newName = config.getNewName();
Deleted: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/MethodDefinitionWrapper.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/MethodDefinitionWrapper.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/MethodDefinitionWrapper.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -1,65 +0,0 @@
-/***** 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 Lukas Felber <lf...@hs...>
- * Copyright (C) 2006 Mirko Stocker <me...@mi...>
- * 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"),
- * 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.renamemethod;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.jruby.ast.MethodDefNode;
-import org.jruby.ast.SymbolNode;
-import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
-import org.rubypeople.rdt.refactoring.nodewrapper.MethodCallNodeWrapper;
-import org.rubypeople.rdt.refactoring.nodewrapper.MethodNodeWrapper;
-
-public class MethodDefinitionWrapper extends MethodNodeWrapper{
-
- public MethodDefinitionWrapper(MethodDefNode methodDefinition){
- super(methodDefinition);
- }
-
- public Collection<MethodCallNodeWrapper> getCallCandidatesInClass(ClassNodeWrapper classNode) {
- if(classNode == null){
- return new ArrayList<MethodCallNodeWrapper>();
- }
- Collection<MethodCallNodeWrapper> calls = classNode.getMethodCalls(methodNode);
-
- return calls;
- }
-
- public Collection<SymbolNode> getSymbolCandidatesInClass(ClassNodeWrapper classNode) {
- if(classNode == null){
- return new ArrayList<SymbolNode>();
- }
- Collection<SymbolNode> symbols = classNode.getMethodSymbols(methodNode);
-
- return symbols;
- }
-}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/MethodRenamer.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/MethodRenamer.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/MethodRenamer.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -43,6 +43,8 @@
import org.rubypeople.rdt.refactoring.classnodeprovider.ClassNodeProvider;
import org.rubypeople.rdt.refactoring.core.NodeProvider;
import org.rubypeople.rdt.refactoring.core.SelectionNodeProvider;
+import org.rubypeople.rdt.refactoring.core.renamefield.FieldRenameEditProvider;
+import org.rubypeople.rdt.refactoring.core.renamefield.fielditems.FieldItem;
import org.rubypeople.rdt.refactoring.core.renamemethod.methoditems.CallCandidateItem;
import org.rubypeople.rdt.refactoring.core.renamemethod.methoditems.MethodNameArgumentItem;
import org.rubypeople.rdt.refactoring.core.renamemethod.methoditems.SymbolItem;
@@ -62,12 +64,11 @@
public Collection<String> getAllMethodsFromClass() {
Collection<String> names = new ArrayList<String>();
- try {
- for(MethodNodeWrapper method : config.getAllMethodsInClass()) {
+
+ if(config.getSelectedClass() != null) {
+ for(MethodNodeWrapper method : config.getSelectedClass().getMethods()) {
names.add(method.getName());
}
- } catch (NoClassNodeException e) {
- /*we don't care*/
}
return names;
}
@@ -75,8 +76,9 @@
public MethodRenamer(RenameMethodConfig config){
this.config = config;
- Collection<MethodCallNodeWrapper> probableClass = getCallCandidatesInClass();
+ Collection<INodeWrapper> probableClass = getCallCandidatesInClass();
probableClass.addAll(getSubsequentCalls());
+ probableClass.addAll(config.getSelectedCalls());
config.setSelectedCalls(probableClass);
}
@@ -91,7 +93,7 @@
if(!config.getTargetMethod().isClassMethod()){
addSymbolRenamers(fileEdits);
}
-
+
return fileEdits.getFileEditProviders();
}
@@ -101,18 +103,33 @@
}
String file = config.getDocumentProvider().getActiveFileName();
for(SymbolNode currentNode : getSymbolCandidatesInClass()){
- SymbolItem currentItem = new SymbolItem(currentNode);
- fileEdits.addEditProvider(new FileEditProvider(file, new MethodRenameEditProvider(currentItem, config.getNewName())));
+ addSymbolRenamer(fileEdits, file, currentNode, config.getNewName());
}
}
+ private void addSymbolRenamer(MultiFileEditProvider fileEdits, String file, SymbolNode currentNode, String name) {
+ SymbolItem currentItem = new SymbolItem(currentNode);
+ fileEdits.addEditProvider(new FileEditProvider(file, new MethodRenameEditProvider(currentItem, name)));
+ }
+
private void addCallRenamers(MultiFileEditProvider fileEdits) {
for(INodeWrapper currentCandidate : config.getSelectedCalls()){
String file = currentCandidate.getWrappedNode().getPosition().getFile();
- //Were expecting only MethodCallNodeWrappers in this refactoring
- CallCandidateItem candidateItem = new CallCandidateItem((MethodCallNodeWrapper)currentCandidate);
- fileEdits.addEditProvider(new FileEditProvider(file, new MethodRenameEditProvider(candidateItem, config.getNewName())));
+
+ String newName = config.getNewName();
+
+ if(currentCandidate instanceof MethodCallNodeWrapper) {
+ CallCandidateItem candidateItem = new CallCandidateItem((MethodCallNodeWrapper) currentCandidate);
+ fileEdits.addEditProvider(new FileEditProvider(file, new MethodRenameEditProvider(candidateItem, newName)));
+ } else if(config.renameFields()) {
+ if(config.getTargetMethod().isWriter()) {
+ newName = newName.replace("=", "");
+ }
+
+ FieldRenameEditProvider currentRenameProvider = new FieldRenameEditProvider((FieldItem) currentCandidate, newName);
+ fileEdits.addEditProvider(new FileEditProvider(file, currentRenameProvider));
+ }
}
}
@@ -129,12 +146,37 @@
continue;
}
String currentFile = currentMethodDef.getPosition().getFile();
- MethodNameArgumentItem argumentItem = new MethodNameArgumentItem(currentMethodDef.getWrappedNode().getNameNode());
- fileEdits.addEditProvider(new FileEditProvider(currentFile, new MethodRenameEditProvider(argumentItem, config.getNewName())));
+ addMethodNameRenamer(fileEdits, currentMethodDef, currentFile, config.getNewName());
}
}
+
+ if(config.getTargetMethod().isAccessor() && config.renameFields()) {
+ String theOtherAccessor;
+ String newName;
+ if(config.getTargetMethod().isReader()) {
+ theOtherAccessor = config.getTargetMethod().getName() + "=";
+ newName = config.getNewName() + "=";
+ } else {
+ theOtherAccessor = config.getTargetMethod().getName().replace("=", "");
+ newName = config.getNewName().replace("=", "");
+ }
+
+ MethodNodeWrapper method = config.getSelectedClass().getMethod(theOtherAccessor);
+ if(method != null) {
+ addMethodNameRenamer(fileEdits, method, method.getPosition().getFile(), newName);
+
+ for (SymbolNode node : method.getSymbolCandidatesInClass(config.getSelectedClass())) {
+ addSymbolRenamer(fileEdits, method.getPosition().getFile(), node, newName);
+ }
+ }
+ }
}
+ private void addMethodNameRenamer(MultiFileEditProvider fileEdits, MethodNodeWrapper currentMethodDef, String currentFile, String newName) {
+ MethodNameArgumentItem argumentItem = new MethodNameArgumentItem(currentMethodDef.getWrappedNode().getNameNode());
+ fileEdits.addEditProvider(new FileEditProvider(currentFile, new MethodRenameEditProvider(argumentItem, newName)));
+ }
+
private ArrayList<ClassNodeWrapper> findRelatedClasses() {
ClassNodeProvider projectClassProvider = config.getDocumentProvider().getProjectClassNodeProvider();
@@ -148,9 +190,9 @@
return config;
}
- public Collection<MethodCallNodeWrapper> getCallCandidatesInClass(){
+ public Collection<INodeWrapper> getCallCandidatesInClass(){
- ArrayList<MethodCallNodeWrapper> callCandidates = new ArrayList<MethodCallNodeWrapper>();
+ ArrayList<INodeWrapper> callCandidates = new ArrayList<INodeWrapper>();
if(config.getSelectedClass() != null){
for(ClassNodeWrapper currentClass : findRelatedClasses()){
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/RenameMethodConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/RenameMethodConditionChecker.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/RenameMethodConditionChecker.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -42,10 +42,13 @@
import org.rubypeople.rdt.refactoring.core.NodeProvider;
import org.rubypeople.rdt.refactoring.core.RefactoringConditionChecker;
import org.rubypeople.rdt.refactoring.core.SelectionNodeProvider;
+import org.rubypeople.rdt.refactoring.core.renamefield.FieldProvider;
+import org.rubypeople.rdt.refactoring.core.renamefield.InstVarAccessesFinder;
import org.rubypeople.rdt.refactoring.documentprovider.DocumentWithIncluding;
import org.rubypeople.rdt.refactoring.exception.NoClassNodeException;
import org.rubypeople.rdt.refactoring.nodewrapper.ArgsNodeWrapper;
import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
+import org.rubypeople.rdt.refactoring.nodewrapper.INodeWrapper;
import org.rubypeople.rdt.refactoring.nodewrapper.MethodCallNodeWrapper;
import org.rubypeople.rdt.refactoring.nodewrapper.MethodNodeWrapper;
import org.rubypeople.rdt.refactoring.nodewrapper.PartialClassNodeWrapper;
@@ -58,7 +61,6 @@
public RenameMethodConditionChecker(RenameMethodConfig config) {
super(config);
}
-
@Override
public void init(IRefactoringConfig configObj) {
@@ -75,9 +77,8 @@
}
}
-
private void setSelectedMethodNode(Node rootNode) {
-
+
MethodDefNode methodNode = (MethodDefNode) SelectionNodeProvider.getSelectedNodeOfType(rootNode, this.config.getCaretPosition(), MethodDefNode.class);
if(methodNode == null) {
SymbolNode selectedSymbolNode = (SymbolNode) SelectionNodeProvider.getSelectedNodeOfType(rootNode, config.getCaretPosition(), SymbolNode.class);
@@ -88,17 +89,18 @@
}
}
}
- MethodDefinitionWrapper targetMethod = new MethodDefinitionWrapper(methodNode);
+
+ MethodNodeWrapper targetMethod = new MethodNodeWrapper(methodNode, config.getSelectedClass());
this.config.setTargetMethod(targetMethod);
if(methodNode != null && config.getNewName() == null) {
this.config.setNewName(targetMethod.getName());
}
}
- private Collection<MethodCallNodeWrapper> getAllCallCandidates() {
+ private Collection<INodeWrapper> getAllCallCandidates() {
Collection<Node> allNodes = config.getDocumentProvider().getAllNodes();
- ArrayList<MethodCallNodeWrapper> possibleCalls = new ArrayList<MethodCallNodeWrapper>();
+ ArrayList<INodeWrapper> possibleCalls = new ArrayList<INodeWrapper>();
for(Node currentNode : allNodes){
MethodCallNodeWrapper callNode = new MethodCallNodeWrapper(currentNode);
@@ -106,6 +108,22 @@
possibleCalls.add(callNode);
}
}
+
+ if(config.getTargetMethod().isAccessor() && config.renameFields()) {
+ String name;
+
+ if(config.getTargetMethod().isWriter()) {
+ name = config.getTargetMethod().getName().replace("=", "");
+
+ } else {
+ name = config.getTargetMethod().getName();
+ }
+
+ possibleCalls.addAll(InstVarAccessesFinder.find(config.getDocumentProvider(), name));
+ possibleCalls.addAll(new FieldProvider(config.getSelectedClass(), config.getDocumentProvider()).getFieldItems(name, false));
+ config.setSelectedCalls(new FieldProvider(config.getSelectedClass(), config.getDocumentProvider()).getFieldItems(name, false));
+ }
+
return possibleCalls;
}
@@ -183,15 +201,13 @@
public Collection<String> getAlreadyUsedNames() {
HashSet<String> usedNames = new HashSet<String>();
- try {
- Collection<MethodNodeWrapper> methods = config.getAllMethodsInClass();
-
- for (MethodNodeWrapper currentMethod : methods){
+ if(config.getSelectedClass() != null) {
+ for (MethodNodeWrapper currentMethod : config.getSelectedClass().getMethods()){
if(isSameTypeAsSelectedMethod(currentMethod)){
usedNames.add(currentMethod.getName());
}
}
- } catch (NoClassNodeException e) {
+ } else {
Node rootNode = config.getDocumentProvider().getActiveFileRootNode();
Collection<MethodDefNode> methods = NodeProvider.getMethodNodes(rootNode);
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/RenameMethodConfig.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/RenameMethodConfig.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamemethod/RenameMethodConfig.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -33,14 +33,10 @@
import java.util.ArrayList;
import java.util.Collection;
-import org.jruby.ast.Node;
import org.jruby.ast.SymbolNode;
-import org.rubypeople.rdt.refactoring.classnodeprovider.IncludedClassesProvider;
import org.rubypeople.rdt.refactoring.core.IRefactoringConfig;
-import org.rubypeople.rdt.refactoring.core.SelectionNodeProvider;
import org.rubypeople.rdt.refactoring.documentprovider.DocumentWithIncluding;
import org.rubypeople.rdt.refactoring.documentprovider.IDocumentProvider;
-import org.rubypeople.rdt.refactoring.exception.NoClassNodeException;
import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
import org.rubypeople.rdt.refactoring.nodewrapper.INodeWrapper;
import org.rubypeople.rdt.refactoring.nodewrapper.MethodNodeWrapper;
@@ -62,8 +58,10 @@
private ClassNodeWrapper classNode;
- private MethodDefinitionWrapper targetMethod;
+ private MethodNodeWrapper targetMethod;
+ private boolean renameFields = true;
+
public RenameMethodConfig(IDocumentProvider docProvider, int caretPosition) {
this.docProvider = docProvider;
this.caretPosition = caretPosition;
@@ -107,11 +105,11 @@
classNode = selectedClassNode;
}
- public void setTargetMethod(MethodDefinitionWrapper selectedMethod) {
+ public void setTargetMethod(MethodNodeWrapper selectedMethod) {
this.targetMethod = selectedMethod;
}
- public MethodDefinitionWrapper getTargetMethod() {
+ public MethodNodeWrapper getTargetMethod() {
return targetMethod;
}
@@ -126,16 +124,6 @@
public void setPossibleCalls(Collection<? extends INodeWrapper> possibleCalls){
this.possibleCalls = possibleCalls;
}
-
- public Collection<MethodNodeWrapper> getAllMethodsInClass() throws NoClassNodeException {
- Node rootNode = docProvider.getActiveFileRootNode();
- ClassNodeWrapper enclosingClass = SelectionNodeProvider.getSelectedClassNode(rootNode, targetMethod.getWrappedNode().getPosition().getStartOffset());
- IncludedClassesProvider classesProvider = new IncludedClassesProvider(docProvider);
- ClassNodeWrapper wholeClass = classesProvider.getClassNode(enclosingClass.getName());
-
- Collection<MethodNodeWrapper> methods = wholeClass.getMethods();
- return methods;
- }
public void setDocProvider(DocumentWithIncluding docProvider) {
this.docProvider = docProvider;
@@ -144,4 +132,12 @@
public void setDocumentProvider(IDocumentProvider doc) {
this.docProvider = doc;
}
+
+ public boolean renameFields() {
+ return renameFields;
+ }
+
+ public void setRenameFields(boolean renameFields) {
+ this.renameFields = renameFields;
+ }
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/StringDocumentProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/StringDocumentProvider.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/documentprovider/StringDocumentProvider.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -41,11 +41,11 @@
protected Map<String, String> files;
- public StringDocumentProvider(String documentName, String document) {
+ public StringDocumentProvider(String name, String document) {
this.document = document;
- this.docName = documentName;
+ this.docName = name;
files = new LinkedHashMap<String, String>();
- files.put(documentName, document);
+ files.put(name, document);
}
public StringDocumentProvider(IDocumentProvider other) {
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/ClassNodeWrapper.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/ClassNodeWrapper.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/ClassNodeWrapper.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -93,7 +93,7 @@
public MethodNodeWrapper getConstructorNode() {
Collection<MethodNodeWrapper> constructors = getExistingConstructors();
if (constructors.isEmpty()) {
- return new MethodNodeWrapper(NodeFactory.createDefaultConstructor());
+ return new MethodNodeWrapper(NodeFactory.createDefaultConstructor(), this);
}
return constructors.toArray(new MethodNodeWrapper[constructors.size()])[constructors.size() - 1];
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/MethodNodeWrapper.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/MethodNodeWrapper.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/MethodNodeWrapper.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -28,12 +28,13 @@
package org.rubypeople.rdt.refactoring.nodewrapper;
+import java.util.ArrayList;
import java.util.Collection;
-import org.jruby.ast.DefnNode;
import org.jruby.ast.DefsNode;
import org.jruby.ast.MethodDefNode;
import org.jruby.ast.Node;
+import org.jruby.ast.SymbolNode;
import org.jruby.lexer.yacc.ISourcePosition;
import org.rubypeople.rdt.refactoring.core.NodeProvider;
import org.rubypeople.rdt.refactoring.signatureprovider.MethodSignature;
@@ -42,14 +43,11 @@
public class MethodNodeWrapper implements INodeWrapper {
protected MethodDefNode methodNode;
- private boolean isClassMethod;
- public MethodNodeWrapper(MethodDefNode methodDef) {
+ private final ClassNodeWrapper containingClass;
+
+ public MethodNodeWrapper(MethodDefNode methodDef, ClassNodeWrapper containingClass) {
this.methodNode = methodDef;
- if (methodNode instanceof DefnNode) {
- isClassMethod = false;
- } else if (methodNode instanceof DefsNode) {
- isClassMethod = true;
- }
+ this.containingClass = containingClass;
}
public String getName() {
@@ -57,8 +55,7 @@
}
public MethodSignature getSignature() {
- ArgsNodeWrapper argsNode = new ArgsNodeWrapper(methodNode.getArgsNode());
- return new MethodSignature(methodNode.getName(), argsNode);
+ return new MethodSignature(methodNode.getName(), getArgsNode());
}
public ArgsNodeWrapper getArgsNode() {
@@ -70,7 +67,7 @@
}
public boolean isClassMethod() {
- return isClassMethod;
+ return methodNode instanceof DefsNode;
}
public Collection<MethodCallNodeWrapper> getMethodCallNodes() {
@@ -81,7 +78,7 @@
public int hashCode() {
final int PRIME = 31;
int result = 1;
- result = PRIME * result + (isClassMethod ? 1231 : 1237);
+ result = PRIME * result + (isClassMethod() ? 1231 : 1237);
return result;
}
@@ -106,7 +103,49 @@
return methodNode.getScope().getVariables();
}
- public Node getScopeNode() {
+ public Node getBodyNode() {
return methodNode.getBodyNode();
}
+
+ public Collection<MethodCallNodeWrapper> getCallCandidatesInClass(ClassNodeWrapper classNode) {
+ if(classNode == null){
+ return new ArrayList<MethodCallNodeWrapper>();
+ }
+ return classNode.getMethodCalls(methodNode);
+ }
+
+ public Collection<SymbolNode> getSymbolCandidatesInClass(ClassNodeWrapper classNode) {
+ if(classNode == null){
+ return new ArrayList<SymbolNode>();
+ }
+ return classNode.getMethodSymbols(methodNode);
+ }
+
+ public boolean isAccessor() {
+ return isWriter() || isReader();
+ }
+
+ public boolean isWriter() {
+ if(containingClass == null) {
+ return false;
+ }
+ for (FieldNodeWrapper field : containingClass.getFields()) {
+ if ((field.getNameWithoutAts() + "=").equals(getName()) && getSignature().getArguments().size() == 1) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean isReader() {
+ if(containingClass == null) {
+ return false;
+ }
+ for (FieldNodeWrapper field : containingClass.getFields()) {
+ if(field.getNameWithoutAts().equals(getName()) && getSignature().getArguments().isEmpty()) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/PartialClassNodeWrapper.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/PartialClassNodeWrapper.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/PartialClassNodeWrapper.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -114,7 +114,7 @@
methods = new ArrayList<MethodNodeWrapper>();
Collection<Node> methodNodes = NodeProvider.getSubNodes(wrappedNode, MethodDefNode.class);
for (Node methodNode : methodNodes) {
- methods.add(new MethodNodeWrapper((MethodDefNode) methodNode));
+ methods.add(new MethodNodeWrapper((MethodDefNode) methodNode, new ClassNodeWrapper(this)));
}
}
return methods;
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/signatureprovider/MethodSignature.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/signatureprovider/MethodSignature.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/signatureprovider/MethodSignature.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -106,7 +106,4 @@
}
return false;
}
-
-
-
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/ui/pages/OccurenceReplaceSelectionPage.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/ui/pages/OccurenceReplaceSelectionPage.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/ui/pages/OccurenceReplaceSelectionPage.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -117,7 +117,7 @@
private void initPossibilityTable(Composite control) {
possibilityTable = new Table(control, SWT.BORDER | SWT.CHECK);
- TreeSet<INodeWrapper> possibleCalls = new TreeSet<INodeWrapper>(new Comparator<INodeWrapper>(){
+ TreeSet<INodeWrapper> possibleCalls = new TreeSet<INodeWrapper>(new Comparator<INodeWrapper>() {
public int compare(INodeWrapper left, INodeWrapper right) {
return left.getWrappedNode().getPosition().getStartOffset() - right.getWrappedNode().getPosition().getStartOffset();
@@ -125,10 +125,10 @@
possibleCalls.addAll(selector.getPossibleCalls());
- for(INodeWrapper currentCall : possibleCalls){
+ for(INodeWrapper currentCall : possibleCalls) {
TableItem currentItem = new TableItem(possibilityTable, SWT.NONE);
currentItem.setText(getTableCaption(currentCall));
- if(probableCall(currentCall)){
+ if(probableCall(currentCall)) {
currentItem.setChecked(true);
}
currentItem.setData(currentCall);
@@ -153,6 +153,4 @@
private boolean hasSamePosition(INodeWrapper currentCall, INodeWrapper targetCall) {
return JRubyRefactoringUtils.hasSamePosition(currentCall.getWrappedNode(), targetCall.getWrappedNode());
}
-
-
}
Modified: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_10.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_10.activeFile.rb.result 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_10.activeFile.rb.result 2007-03-19 13:07:45 UTC (rev 2200)
@@ -33,7 +33,7 @@
@plant
end
def tree1
- @tree
+ @tree1
end
def goo
p 5
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.activeFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.activeFile.rb.result 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,5 @@
+class Test
+ def foo
+ @foo
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.activeFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.activeFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.activeFile.rb.source 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,5 @@
+class Test
+ def wunder
+ @wunder
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_16.test_properties 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,4 @@
+activeFile=activeFile.rb
+destinationFiles=
+caretPosition=18
+newName=foo
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.activeFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.activeFile.rb.result 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,8 @@
+class Test
+ def foo
+ @foo
+ end
+ def foo= value
+ @foo = value
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.activeFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.activeFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.activeFile.rb.source 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,8 @@
+class Test
+ def wunder
+ @wunder
+ end
+ def wunder= value
+ @wunder = value
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_17.test_properties 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,4 @@
+activeFile=activeFile.rb
+destinationFiles=
+caretPosition=18
+newName=foo
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.activeFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.activeFile.rb.result 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,10 @@
+class Test
+ def foo
+ @foo
+ end
+ public :foo
+
+ def foo= value
+ @foo = value
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.activeFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.activeFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.activeFile.rb.source 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,10 @@
+class Test
+ def wunder
+ @wunder
+ end
+ public :wunder
+
+ def wunder= value
+ @wunder = value
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_18.test_properties 2007-03-19 13:07:45 UTC (rev 2200)
@@ -0,0 +1,4 @@
+activeFile=activeFile.rb
+destinationFiles=
+caretPosition=18
+newName=foo
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/TS_All.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/TS_All.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/TS_All.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -46,6 +46,7 @@
import org.rubypeople.rdt.refactoring.tests.core.mergewithexternalclassparts.TS_MergeWithExternalClassParts;
import org.rubypeople.rdt.refactoring.tests.core.movefield.TS_MoveField;
import org.rubypeople.rdt.refactoring.tests.core.movemethod.TS_MoveMethod;
+import org.rubypeople.rdt.refactoring.tests.core.nodewrapper.TS_NodeWrapper;
import org.rubypeople.rdt.refactoring.tests.core.overridemethod.TS_OverrideMethod;
import org.rubypeople.rdt.refactoring.tests.core.pushdown.TS_PushDown;
import org.rubypeople.rdt.refactoring.tests.core.rename.TS_Rename;
@@ -86,6 +87,7 @@
suite.addTest(TS_MoveMethod.suite());
suite.addTest(TS_MoveField.suite());
suite.addTest(TS_Rename.suite());
+ suite.addTest(TS_NodeWrapper.suite());
return suite;
}
Modified: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/nodewrapper/TS_NodeWrapper.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/nodewrapper/TS_NodeWrapper.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/nodewrapper/TS_NodeWrapper.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -34,6 +34,7 @@
public static TestSuite suite() {
TestSuite suite = new TestSuite("Node Wrapper");
suite.addTestSuite(TC_FieldNodeWrapper.class);
+ suite.addTestSuite(TC_MethodNodeWrapper.class);
return suite;
}
}
Modified: trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/renamemethod/selection/RenameMethodSelectionTester.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/renamemethod/selection/RenameMethodSelectionTester.java 2007-03-17 15:08:16 UTC (rev 2199)
+++ trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/renamemethod/selection/RenameMethodSelectionTester.java 2007-03-19 13:07:45 UTC (rev 2200)
@@ -39,41 +39,41 @@
import org.rubypeople.rdt.refactoring.core.renamemethod.MethodRenamer;
import org.rubypeople.rdt.refactoring.core.renamemethod.RenameMethodConditionChecker;
import org.rubypeople.rdt.refactoring.core.renamemethod.RenameMethodConfig;
-import org.rubypeople.rdt.refactoring.nodewrapper.MethodCallNodeWrapper;
+import org.rubypeople.rdt.refactoring.nodewrapper.INodeWrapper;
import org.rubypeople.rdt.refactoring.tests.MultiFileTestData;
import org.rubypeople.rdt.refactoring.tests.RefactoringTestCase;
-public class RenameMethodSelectionTester extends RefactoringTestCase{
+public class RenameMethodSelectionTester extends RefactoringTestCase {
private String fileName;
+
private MultiFileTestData testData;
-
- public RenameMethodSelectionTester(String fileName)
- {
+
+ public RenameMethodSelectionTester(String fileName) {
this.fileName = fileName;
}
-
+
@Override
public void runTest() throws FileNotFoundException, IOException, BadLocationException {
- testData = new MultiFileTestData(fileName);
- int caretPosition = testData.getIntProperty("caretPosition");
-
- RenameMethodConfig config = new RenameMethodConfig(testData, caretPosition);
- new RenameMethodConditionChecker(config);
-
- MethodRenamer renamer = new MethodRenamer(config);
- config.setNewName(testData.getProperty("newName"));
-
- Collection<MethodCallNodeWrapper> calls = renamer.getCallCandidatesInClass();
- calls.addAll(renamer.getSubsequentCalls());
- config.setSelectedCalls(calls);
-
- Collection<SymbolNode> symbols = renamer.getSymbolCandidatesInClass();
- config.setRenamedSymbols(symbols);
-
- checkMultiFileEdits(renamer, testData);
+ testData = new MultiFileTestData(fileName);
+ int caretPosition = testData.getIntProperty("caretPosition");
+
+ RenameMethodConfig config = new RenameMethodConfig(testData, caretPosition);
+ new RenameMethodConditionChecker(config);
+
+ MethodRenamer renamer = new MethodRenamer(config);
+ config.setNewName(testData.getProperty("newName"));
+
+ Collection<INodeWrapper> calls = renamer.getCallCandidatesInClass();
+ calls.addAll(renamer.getSubsequentCalls());
+ config.setSelectedCalls(calls);
+
+ Collection<SymbolNode> symbols = renamer.getSymbolCandidatesInClass();
+ config.setRenamedSymbols(symbols);
+
+ checkMultiFileEdits(renamer, testData);
}
-
+
@Override
public String getName() {
return fileName;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|