|
From: <mir...@us...> - 2007-03-16 12:18:38
|
Revision: 2183
http://svn.sourceforge.net/rubyeclipse/?rev=2183&view=rev
Author: mirkostocker
Date: 2007-03-16 05:18:37 -0700 (Fri, 16 Mar 2007)
Log Message:
-----------
rename temp to local continued
Modified Paths:
--------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/ConvertTempToFieldRefactoring.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/Messages.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/messages.properties
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinelocal/InlineTempRefactoring.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinelocal/TempInliner.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinelocal/TempValueReplaceProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/splitlocal/Messages.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/splitlocal/SplitTempEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/splitlocal/SplitTempRefactoring.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/ui/pages/ConvertTempToFieldPage.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/ui/pages/InlineTempPage.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/TempToFieldTester.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/converttemptofield/conditionchecks/TempToFieldConditionTester.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/inlinetemp/TempInlinerTester.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/inlinetemp/conditionchecks/InlineTempConditionTester.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/splittemp/SplitTempTester.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/splittemp/conditionchecks/SplitTempConditionTester.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConfig.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConverter.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldEditProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinelocal/InlineLocalConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinelocal/InlineLocalConfig.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/splitlocal/SplitLocalConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/splitlocal/SplitLocalConfig.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/Conversion.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorConversion.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConfig.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConverter.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinelocal/InlineTempConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinelocal/InlineTempConfig.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/splitlocal/SplitTempConditionChecker.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/splitlocal/SplitTempConfig.java
Deleted: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/Conversion.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/Conversion.java 2007-03-16 12:11:02 UTC (rev 2182)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/Conversion.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -1,81 +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.convertlocaltofield;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.jruby.ast.Node;
-import org.rubypeople.rdt.refactoring.editprovider.ReplaceEditProvider;
-import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
-
-public class Conversion extends ReplaceEditProvider {
-
- private LocalNodeWrapper localNode;
-
- public Conversion(LocalNodeWrapper localNode, String newName, boolean isClassField) {
- super(false);
- this.localNode = localNode;
- newName = ((isClassField) ? "@@" : "@") + newName; //$NON-NLS-1$ //$NON-NLS-2$
- Collection<LocalNodeWrapper> allLocalNodes = new ArrayList<LocalNodeWrapper>();
- allLocalNodes.add(localNode);
- allLocalNodes.addAll(LocalNodeWrapper.gatherLocalNodes(localNode.getWrappedNode()));
- replaceAllNames(allLocalNodes, LocalNodeWrapper.getLocalNodeName(localNode), newName);
- }
-
- private void replaceAllNames(Collection<LocalNodeWrapper> allLocalNodes, String orgName, String newName) {
- for (LocalNodeWrapper aktNode : allLocalNodes) {
- String aktNodeName = LocalNodeWrapper.getLocalNodeName(aktNode);
- if (aktNodeName.equals(orgName)) {
- setNodeName(aktNode, newName);
- }
- }
- }
-
- private void setNodeName(LocalNodeWrapper localNode, String newName) {
- localNode.setName(newName);
- }
-
- @Override
- protected int getOffsetLength() {
- return localNode.getWrappedNode().getPosition().getEndOffset() - getOffset(null);
- }
-
- @Override
- protected Node getEditNode(int offset, String document) {
- return localNode.getWrappedNode();
- }
-
- @Override
- protected int getOffset(String document) {
- return localNode.getWrappedNode().getPosition().getStartOffset();
- }
-}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/ConvertTempToFieldRefactoring.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/ConvertTempToFieldRefactoring.java 2007-03-16 12:11:02 UTC (rev 2182)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/ConvertTempToFieldRefactoring.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -35,18 +35,18 @@
public class ConvertTempToFieldRefactoring extends RubyRefactoring {
- public static final String NAME = Messages.ConvertTempToFieldRefactoring_Name;
+ public static final String NAME = Messages.ConvertLocalToFieldRefactoring_Name;
public ConvertTempToFieldRefactoring(TextSelectionProvider selectionProvider) {
super(NAME);
- TempToFieldConfig config = new TempToFieldConfig(getDocumentProvider(), selectionProvider.getCarretPosition());
- TempToFieldConditionChecker checker = new TempToFieldConditionChecker(config);
+ LocalToFieldConfig config = new LocalToFieldConfig(getDocumentProvider(), selectionProvider.getCarretPosition());
+ LocalToFieldConditionChecker checker = new LocalToFieldConditionChecker(config);
setRefactoringConditionChecker(checker);
if(checker.shouldPerform()) {
- TempToFieldConverter tempToFieldConverter = new TempToFieldConverter(config);
+ LocalToFieldConverter tempToFieldConverter = new LocalToFieldConverter(config);
setEditProvider(tempToFieldConverter);
ConverterPageParameters pageParameters = createPageParameters(tempToFieldConverter);
ConvertTempToFieldPage page = new ConvertTempToFieldPage(tempToFieldConverter, pageParameters);
@@ -54,7 +54,7 @@
}
}
- private ConverterPageParameters createPageParameters(TempToFieldConverter tempToFieldConverter) {
+ private ConverterPageParameters createPageParameters(LocalToFieldConverter tempToFieldConverter) {
ConverterPageParameters pageParameters = new ConverterPageParameters();
if (tempToFieldConverter.isVariableInConstructor()) {
Deleted: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorConversion.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorConversion.java 2007-03-16 12:11:02 UTC (rev 2182)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorConversion.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -1,80 +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.convertlocaltofield;
-
-import org.jruby.ast.BlockNode;
-import org.jruby.ast.DefnNode;
-import org.jruby.ast.NewlineNode;
-import org.jruby.ast.Node;
-import org.rubypeople.rdt.refactoring.core.NodeFactory;
-import org.rubypeople.rdt.refactoring.editprovider.InsertEditProvider;
-import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
-import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
-import org.rubypeople.rdt.refactoring.offsetprovider.AfterLastNodeInMethodOffsetProvider;
-import org.rubypeople.rdt.refactoring.offsetprovider.ConstructorOffsetProvider;
-import org.rubypeople.rdt.refactoring.offsetprovider.OffsetProvider;
-
-public class InitInConstructorConversion extends InsertEditProvider {
-
- private ClassNodeWrapper enclosingClassNode;
-
- private Node insertNode;
-
- public InitInConstructorConversion(LocalNodeWrapper originalNode, TempToFieldConfig config) {
- super(true);
- Conversion conversion = new Conversion(originalNode, config.getNewName(), config.isClassField());
- insertNode = conversion.getEditNode(0, null);
- enclosingClassNode = config.getEnclosingClassNode();
- }
-
- @Override
- protected int getOffset(String document) {
- OffsetProvider offsetProvider;
- if (enclosingClassNode.hasConstructor()) {
- offsetProvider = new AfterLastNodeInMethodOffsetProvider(enclosingClassNode.getConstructorNode(), document);
- } else {
- offsetProvider = new ConstructorOffsetProvider(enclosingClassNode, document);
- }
- return offsetProvider.getOffset();
-
- }
-
- @Override
- protected Node getInsertNode(int offset, String document) {
- BlockNode blockNode = NodeFactory.createBlockNode(true, !isNextLineEmpty(offset, document), insertNode);
- if (!enclosingClassNode.hasConstructor()) {
- DefnNode constructorNode = NodeFactory.createConstructor(blockNode);
- NewlineNode newlineNode = NodeFactory.createNewLineNode(constructorNode);
- blockNode = NodeFactory.createBlockNode(true, !isNextLineEmpty(offset, document), newlineNode);
- }
- return blockNode;
- }
-}
Copied: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorEditProvider.java (from rev 2182, trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorConversion.java)
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorEditProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/InitInConstructorEditProvider.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -0,0 +1,80 @@
+/***** 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.convertlocaltofield;
+
+import org.jruby.ast.BlockNode;
+import org.jruby.ast.DefnNode;
+import org.jruby.ast.NewlineNode;
+import org.jruby.ast.Node;
+import org.rubypeople.rdt.refactoring.core.NodeFactory;
+import org.rubypeople.rdt.refactoring.editprovider.InsertEditProvider;
+import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
+import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
+import org.rubypeople.rdt.refactoring.offsetprovider.AfterLastNodeInMethodOffsetProvider;
+import org.rubypeople.rdt.refactoring.offsetprovider.ConstructorOffsetProvider;
+import org.rubypeople.rdt.refactoring.offsetprovider.OffsetProvider;
+
+public class InitInConstructorEditProvider extends InsertEditProvider {
+
+ private ClassNodeWrapper enclosingClassNode;
+
+ private Node insertNode;
+
+ public InitInConstructorEditProvider(LocalNodeWrapper originalNode, LocalToFieldConfig config) {
+ super(true);
+ LocalToFieldEditProvider conversion = new LocalToFieldEditProvider(originalNode, config.getNewName(), config.isClassField());
+ insertNode = conversion.getEditNode(0, null);
+ enclosingClassNode = config.getEnclosingClassNode();
+ }
+
+ @Override
+ protected int getOffset(String document) {
+ OffsetProvider offsetProvider;
+ if (enclosingClassNode.hasConstructor()) {
+ offsetProvider = new AfterLastNodeInMethodOffsetProvider(enclosingClassNode.getConstructorNode(), document);
+ } else {
+ offsetProvider = new ConstructorOffsetProvider(enclosingClassNode, document);
+ }
+ return offsetProvider.getOffset();
+
+ }
+
+ @Override
+ protected Node getInsertNode(int offset, String document) {
+ BlockNode blockNode = NodeFactory.createBlockNode(true, !isNextLineEmpty(offset, document), insertNode);
+ if (!enclosingClassNode.hasConstructor()) {
+ DefnNode constructorNode = NodeFactory.createConstructor(blockNode);
+ NewlineNode newlineNode = NodeFactory.createNewLineNode(constructorNode);
+ blockNode = NodeFactory.createBlockNode(true, !isNextLineEmpty(offset, document), newlineNode);
+ }
+ return blockNode;
+ }
+}
Copied: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConditionChecker.java (from rev 2182, trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConditionChecker.java)
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConditionChecker.java (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConditionChecker.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -0,0 +1,143 @@
+/***** 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.convertlocaltofield;
+
+import java.util.Collection;
+
+import org.jruby.ast.DAsgnNode;
+import org.jruby.ast.DVarNode;
+import org.jruby.ast.IterNode;
+import org.jruby.ast.LocalAsgnNode;
+import org.jruby.ast.LocalVarNode;
+import org.jruby.ast.MethodDefNode;
+import org.jruby.ast.Node;
+import org.jruby.ast.RootNode;
+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.exception.NoClassNodeException;
+import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
+import org.rubypeople.rdt.refactoring.nodewrapper.FieldNodeWrapper;
+import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
+import org.rubypeople.rdt.refactoring.util.JRubyRefactoringUtils;
+
+public class LocalToFieldConditionChecker extends RefactoringConditionChecker {
+
+ private LocalToFieldConfig config;
+ private RootNode rootNode;
+
+ public LocalToFieldConditionChecker(LocalToFieldConfig config) {
+ super(config);
+ }
+
+ public void init(IRefactoringConfig configObj) {
+ config = (LocalToFieldConfig) configObj;
+ rootNode = config.getDocumentProvider().getActiveFileRootNode();
+ Node selectedNode = findSelectedNode(LocalAsgnNode.class, LocalVarNode.class, DVarNode.class, DAsgnNode.class);
+ if (selectedNode != null) {
+ config.setSelectedNode(new LocalNodeWrapper(selectedNode));
+ config.setEnclosingMethod((MethodDefNode) findSelectedNode(MethodDefNode.class));
+ config.setEnclosingClassNode(getClassNode());
+ }
+ }
+
+ private Node findSelectedNode(Class<?>... filterNodes) {
+ return SelectionNodeProvider.getSelectedNodeOfType(rootNode.getBodyNode(), config.getCaretPosition(), filterNodes);
+ }
+
+ private ClassNodeWrapper getClassNode() {
+ try {
+ return SelectionNodeProvider.getSelectedClassNode(rootNode, config.getCaretPosition());
+ } catch (NoClassNodeException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public void checkFinalConditions() {
+ String fieldTypeName = (config.isClassField()) ? "Class" : "Instance"; //$NON-NLS-1$ //$NON-NLS-2$
+ for(FieldNodeWrapper aktField : config.getEnclosingClassNode().getFields()) {
+ if(checkFieldName(config.getNewName(), aktField.getNameWithoutAts(), fieldTypeName)) {
+ return;
+ }
+ }
+ }
+
+ private boolean checkFieldName(String newName, String aktNodeName, String fieldTypeName) {
+ if (newName.equals(aktNodeName)) {
+ addError(fieldTypeName + Messages.TempToFieldConditionChecker_FieldWithName + newName + Messages.TempToFieldConditionChecker_AlreadyExists);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void checkInitialConditions() {
+
+ if (config.getSelectedNode() == null) {
+ addError(Messages.TempToFieldConditionChecker_NoLocalVarAtpos);
+ } else if (config.getEnclosingClassNode() == null) {
+ addError(Messages.TempToFieldConditionChecker_NoEnclosingClassToInsert);
+ } else if (config.getEnclosingMethod() == null) {
+ addError(Messages.TempToFieldConditionChecker_CannotConvertNonlocalVars);
+ } else if (JRubyRefactoringUtils.isParameter(LocalNodeWrapper.getLocalNodeName(config.getSelectedNode()), config.getEnclosingMethod())) {
+ addError(Messages.TempToFieldConditionChecker_CannotConvertMethodParameters);
+ } else if (isIterParameter()) {
+ addError(Messages.TempToFieldConditionChecker_CannotConvertBlockParameters);
+ }
+ }
+
+ private boolean isIterParameter() {
+ Collection<Node> allIterNodes = NodeProvider.getSubNodes(config.getEnclosingMethod(), IterNode.class);
+ for (Node aktNode : allIterNodes) {
+ IterNode aktIterNode = (IterNode) aktNode;
+ if (iterNodeContainsAsArg(aktIterNode, config.getSelectedNode())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean iterNodeContainsAsArg(IterNode iterNode, LocalNodeWrapper localNode) {
+ if (iterNode.getVarNode() == null) {
+ return false;
+ }
+ String localNodeName = LocalNodeWrapper.getLocalNodeName(localNode);
+ for (LocalNodeWrapper aktIterArg : LocalNodeWrapper.gatherLocalNodes(iterNode.getVarNode())) {
+ String aktIterArgName = LocalNodeWrapper.getLocalNodeName(aktIterArg);
+ if (aktIterArgName.equals(localNodeName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Copied: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConfig.java (from rev 2182, trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConfig.java)
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConfig.java (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConfig.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -0,0 +1,105 @@
+/***** 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.convertlocaltofield;
+
+import org.jruby.ast.MethodDefNode;
+import org.rubypeople.rdt.refactoring.core.IRefactoringConfig;
+import org.rubypeople.rdt.refactoring.documentprovider.IDocumentProvider;
+import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
+import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
+
+public class LocalToFieldConfig implements IRefactoringConfig {
+
+ private IDocumentProvider docProvider;
+ private int caretPosition;
+ private LocalNodeWrapper selectedNode;
+ private ClassNodeWrapper enclosingClassNode;
+ private MethodDefNode enclosingMethod;
+ private boolean classField;
+ private String newName;
+
+ public LocalToFieldConfig(IDocumentProvider docProvider, int caretPosition) {
+ this.docProvider = docProvider;
+ this.caretPosition = caretPosition;
+ }
+
+ public boolean isClassField() {
+ return classField;
+ }
+
+ public void setClassField(boolean classField) {
+ this.classField = classField;
+ }
+
+ public String getNewName() {
+ return newName;
+ }
+
+ public void setNewName(String newName) {
+ this.newName = newName;
+ }
+
+ public int getCaretPosition() {
+ return caretPosition;
+ }
+
+ public ClassNodeWrapper getEnclosingClassNode() {
+ return enclosingClassNode;
+ }
+
+ public void setEnclosingClassNode(ClassNodeWrapper enclosingClassNode) {
+ this.enclosingClassNode = enclosingClassNode;
+ }
+
+ public MethodDefNode getEnclosingMethod() {
+ return enclosingMethod;
+ }
+
+ public void setEnclosingMethod(MethodDefNode enclosingMethod) {
+ this.enclosingMethod = enclosingMethod;
+ }
+
+ public LocalNodeWrapper getSelectedNode() {
+ return selectedNode;
+ }
+
+ public void setSelectedNode(LocalNodeWrapper selectedItem) {
+ this.selectedNode = selectedItem;
+ }
+
+ public IDocumentProvider getDocumentProvider() {
+ return docProvider;
+ }
+
+ public void setDocumentProvider(IDocumentProvider doc) {
+ this.docProvider = doc;
+ }
+}
Copied: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConverter.java (from rev 2182, trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConverter.java)
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConverter.java (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldConverter.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -0,0 +1,204 @@
+/***** 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.convertlocaltofield;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.jruby.ast.ClassVarNode;
+import org.jruby.ast.DAsgnNode;
+import org.jruby.ast.FixnumNode;
+import org.jruby.ast.InstVarNode;
+import org.jruby.ast.LocalAsgnNode;
+import org.jruby.ast.MethodDefNode;
+import org.jruby.ast.MultipleAsgnNode;
+import org.jruby.ast.Node;
+import org.jruby.ast.StrNode;
+import org.jruby.ast.VCallNode;
+import org.rubypeople.rdt.refactoring.core.SelectionNodeProvider;
+import org.rubypeople.rdt.refactoring.editprovider.DeleteEditProvider;
+import org.rubypeople.rdt.refactoring.editprovider.EditProvider;
+import org.rubypeople.rdt.refactoring.editprovider.MultiEditProvider;
+import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
+import org.rubypeople.rdt.refactoring.util.Constants;
+import org.rubypeople.rdt.refactoring.util.NodeUtil;
+
+public class LocalToFieldConverter extends MultiEditProvider {
+
+ public static final int INIT_IN_METHOD = 1;
+
+ public static final int INIT_IN_CONSTRUCTOR = 2;
+
+ private int initPlace;
+
+ private Collection<LocalNodeWrapper> localNodes;
+
+ private LocalToFieldConfig config;
+
+ public LocalToFieldConverter(LocalToFieldConfig config) {
+ this.config = config;
+ config.setNewName(getLocalVarName());
+ localNodes = gatherLocalNodes();
+ }
+
+ private Collection<LocalNodeWrapper> gatherLocalNodes() {
+
+ Collection<Node> allNodes = gatherLocalNodes(NodeUtil.getBody(config.getEnclosingMethod()));
+ Collection<LocalNodeWrapper> allLocalNodes = LocalNodeWrapper.createLocalNodes(allNodes);
+
+ Collection<LocalNodeWrapper> affectedLocalNodes = new ArrayList<LocalNodeWrapper>();
+ String selectedNodeName = LocalNodeWrapper.getLocalNodeName(config.getSelectedNode());
+ for (LocalNodeWrapper aktLokalNode : allLocalNodes) {
+ String aktLokalNodeName = LocalNodeWrapper.getLocalNodeName(aktLokalNode);
+ if (selectedNodeName.equals(aktLokalNodeName)) {
+ affectedLocalNodes.add(aktLokalNode);
+ }
+ }
+ return affectedLocalNodes;
+ }
+
+ private Collection<Node> gatherLocalNodes(Node baseNode) {
+ ArrayList<Node> candidates = new ArrayList<Node>();
+
+ if (baseNode == null || baseNode instanceof MethodDefNode) {
+ return candidates;
+ }
+
+ for (Object o : baseNode.childNodes()) {
+ Node n = (Node) o;
+ if (NodeUtil.nodeAssignableFrom(n, LocalNodeWrapper.LOCAL_NODES_CLASSES)) {
+ candidates.add(n);
+ }
+ if (!NodeUtil.nodeAssignableFrom(n, DAsgnNode.class, LocalAsgnNode.class)) {
+ candidates.addAll(gatherLocalNodes(n));
+ }
+ }
+ return candidates;
+ }
+
+ @Override
+ protected Collection<EditProvider> getEditProviders() {
+ return getConversions(localNodes);
+ }
+
+ private Collection<EditProvider> getConversions(Collection<LocalNodeWrapper> localNodes) {
+ Map<LocalNodeWrapper, EditProvider> editProviderMap = new LinkedHashMap<LocalNodeWrapper, EditProvider>();
+ LocalNodeWrapper firstLocalNode = localNodes.toArray(new LocalNodeWrapper[localNodes.size()])[0];
+
+ for (LocalNodeWrapper aktLocalNode : localNodes) {
+ LocalToFieldEditProvider conversion = new LocalToFieldEditProvider(aktLocalNode, config.getNewName(), config.isClassField());
+ editProviderMap.put(aktLocalNode, conversion);
+ }
+ if (initPlace == INIT_IN_CONSTRUCTOR) {
+ editProviderMap.remove(firstLocalNode);
+ }
+ Collection<EditProvider> editProviders = new ArrayList<EditProvider>(editProviderMap.values());
+
+ if (initPlace == INIT_IN_CONSTRUCTOR) {
+ editProviders.add(new InitInConstructorEditProvider(firstLocalNode, config));
+ editProviders.add(new DeleteEditProvider(firstLocalNode.getWrappedNode()));
+ }
+
+ return editProviders;
+ }
+
+ public void setNewName(String newName) {
+ config.setNewName(newName);
+ }
+
+ public void setInitPlace(int initPlace) {
+ this.initPlace = initPlace;
+ }
+
+ public void setIsClassField(boolean isClassField) {
+ config.setClassField(isClassField);
+ }
+
+ public String getLocalVarName() {
+ return LocalNodeWrapper.getLocalNodeName(config.getSelectedNode());
+ }
+
+ private Node findSelectedNode(Class<?>... filterNodes) {
+ return SelectionNodeProvider.getSelectedNodeOfType(config.getDocumentProvider().getActiveFileRootNode(), config.getCaretPosition(), filterNodes);
+ }
+
+ boolean isInitializationExternalizable() {
+
+ if (config.getEnclosingMethod() == null) {
+ return false;
+ }
+
+ LocalNodeWrapper firstNodeInAST = getFirstLocalNodeWrapper();
+ if (firstNodeInAST == null) {
+ return false;
+ }
+
+ if (findSelectedNode(MultipleAsgnNode.class) != null) {
+ return false;
+ }
+
+ if (firstNodeInAST.getWrappedNode() instanceof LocalAsgnNode) {
+ LocalAsgnNode firstAssignment = (LocalAsgnNode) firstNodeInAST.getWrappedNode();
+ Node assignmentValue = firstAssignment.getValueNode();
+
+ return hasSameClass(assignmentValue, FixnumNode.class, StrNode.class, VCallNode.class, InstVarNode.class, ClassVarNode.class);
+ }
+ return false;
+ }
+
+ private boolean hasSameClass(Node assignmentValue, Class<?>... klasses) {
+
+ for (Class klass : klasses) {
+ if (assignmentValue.getClass().equals(klass)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private LocalNodeWrapper getFirstLocalNodeWrapper() {
+
+ if (localNodes == null || localNodes.isEmpty()) {
+ return null;
+ }
+
+ return localNodes.toArray(new LocalNodeWrapper[localNodes.size()])[0];
+ }
+
+ boolean isVariableInConstructor() {
+ if (config.getEnclosingMethod() == null) {
+ return false;
+ }
+ return config.getEnclosingMethod().getName().equals(Constants.CONSTRUCTOR_NAME);
+ }
+}
Copied: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldEditProvider.java (from rev 2182, trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/Conversion.java)
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldEditProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/LocalToFieldEditProvider.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -0,0 +1,81 @@
+/***** 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.convertlocaltofield;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.jruby.ast.Node;
+import org.rubypeople.rdt.refactoring.editprovider.ReplaceEditProvider;
+import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
+
+public class LocalToFieldEditProvider extends ReplaceEditProvider {
+
+ private LocalNodeWrapper localNode;
+
+ public LocalToFieldEditProvider(LocalNodeWrapper localNode, String newName, boolean isClassField) {
+ super(false);
+ this.localNode = localNode;
+ newName = ((isClassField) ? "@@" : "@") + newName; //$NON-NLS-1$ //$NON-NLS-2$
+ Collection<LocalNodeWrapper> allLocalNodes = new ArrayList<LocalNodeWrapper>();
+ allLocalNodes.add(localNode);
+ allLocalNodes.addAll(LocalNodeWrapper.gatherLocalNodes(localNode.getWrappedNode()));
+ replaceAllNames(allLocalNodes, LocalNodeWrapper.getLocalNodeName(localNode), newName);
+ }
+
+ private void replaceAllNames(Collection<LocalNodeWrapper> allLocalNodes, String orgName, String newName) {
+ for (LocalNodeWrapper aktNode : allLocalNodes) {
+ String aktNodeName = LocalNodeWrapper.getLocalNodeName(aktNode);
+ if (aktNodeName.equals(orgName)) {
+ setNodeName(aktNode, newName);
+ }
+ }
+ }
+
+ private void setNodeName(LocalNodeWrapper localNode, String newName) {
+ localNode.setName(newName);
+ }
+
+ @Override
+ protected int getOffsetLength() {
+ return localNode.getWrappedNode().getPosition().getEndOffset() - getOffset(null);
+ }
+
+ @Override
+ protected Node getEditNode(int offset, String document) {
+ return localNode.getWrappedNode();
+ }
+
+ @Override
+ protected int getOffset(String document) {
+ return localNode.getWrappedNode().getPosition().getStartOffset();
+ }
+}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/Messages.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/Messages.java 2007-03-16 12:11:02 UTC (rev 2182)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/Messages.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -3,9 +3,9 @@
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
- private static final String BUNDLE_NAME = "org.rubypeople.rdt.refactoring.core.converttemptofield.messages"; //$NON-NLS-1$
+ private static final String BUNDLE_NAME = "org.rubypeople.rdt.refactoring.core.convertlocaltofield.messages"; //$NON-NLS-1$
- public static String ConvertTempToFieldRefactoring_Name;
+ public static String ConvertLocalToFieldRefactoring_Name;
public static String TempToFieldConditionChecker_AlreadyExists;
Deleted: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConditionChecker.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConditionChecker.java 2007-03-16 12:11:02 UTC (rev 2182)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConditionChecker.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -1,143 +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.convertlocaltofield;
-
-import java.util.Collection;
-
-import org.jruby.ast.DAsgnNode;
-import org.jruby.ast.DVarNode;
-import org.jruby.ast.IterNode;
-import org.jruby.ast.LocalAsgnNode;
-import org.jruby.ast.LocalVarNode;
-import org.jruby.ast.MethodDefNode;
-import org.jruby.ast.Node;
-import org.jruby.ast.RootNode;
-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.exception.NoClassNodeException;
-import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
-import org.rubypeople.rdt.refactoring.nodewrapper.FieldNodeWrapper;
-import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
-import org.rubypeople.rdt.refactoring.util.JRubyRefactoringUtils;
-
-public class TempToFieldConditionChecker extends RefactoringConditionChecker {
-
- private TempToFieldConfig config;
- private RootNode rootNode;
-
- public TempToFieldConditionChecker(TempToFieldConfig config) {
- super(config);
- }
-
- public void init(IRefactoringConfig configObj) {
- config = (TempToFieldConfig) configObj;
- rootNode = config.getDocumentProvider().getActiveFileRootNode();
- Node selectedNode = findSelectedNode(LocalAsgnNode.class, LocalVarNode.class, DVarNode.class, DAsgnNode.class);
- if (selectedNode != null) {
- config.setSelectedNode(new LocalNodeWrapper(selectedNode));
- config.setEnclosingMethod((MethodDefNode) findSelectedNode(MethodDefNode.class));
- config.setEnclosingClassNode(getClassNode());
- }
- }
-
- private Node findSelectedNode(Class<?>... filterNodes) {
- return SelectionNodeProvider.getSelectedNodeOfType(rootNode.getBodyNode(), config.getCaretPosition(), filterNodes);
- }
-
- private ClassNodeWrapper getClassNode() {
- try {
- return SelectionNodeProvider.getSelectedClassNode(rootNode, config.getCaretPosition());
- } catch (NoClassNodeException e) {
- return null;
- }
- }
-
- @Override
- public void checkFinalConditions() {
- String fieldTypeName = (config.isClassField()) ? "Class" : "Instance"; //$NON-NLS-1$ //$NON-NLS-2$
- for(FieldNodeWrapper aktField : config.getEnclosingClassNode().getFields()) {
- if(checkFieldName(config.getNewName(), aktField.getNameWithoutAts(), fieldTypeName)) {
- return;
- }
- }
- }
-
- private boolean checkFieldName(String newName, String aktNodeName, String fieldTypeName) {
- if (newName.equals(aktNodeName)) {
- addError(fieldTypeName + Messages.TempToFieldConditionChecker_FieldWithName + newName + Messages.TempToFieldConditionChecker_AlreadyExists);
- return true;
- }
- return false;
- }
-
- @Override
- public void checkInitialConditions() {
-
- if (config.getSelectedNode() == null) {
- addError(Messages.TempToFieldConditionChecker_NoLocalVarAtpos);
- } else if (config.getEnclosingClassNode() == null) {
- addError(Messages.TempToFieldConditionChecker_NoEnclosingClassToInsert);
- } else if (config.getEnclosingMethod() == null) {
- addError(Messages.TempToFieldConditionChecker_CannotConvertNonlocalVars);
- } else if (JRubyRefactoringUtils.isParameter(LocalNodeWrapper.getLocalNodeName(config.getSelectedNode()), config.getEnclosingMethod())) {
- addError(Messages.TempToFieldConditionChecker_CannotConvertMethodParameters);
- } else if (isIterParameter()) {
- addError(Messages.TempToFieldConditionChecker_CannotConvertBlockParameters);
- }
- }
-
- private boolean isIterParameter() {
- Collection<Node> allIterNodes = NodeProvider.getSubNodes(config.getEnclosingMethod(), IterNode.class);
- for (Node aktNode : allIterNodes) {
- IterNode aktIterNode = (IterNode) aktNode;
- if (iterNodeContainsAsArg(aktIterNode, config.getSelectedNode())) {
- return true;
- }
- }
- return false;
- }
-
- private boolean iterNodeContainsAsArg(IterNode iterNode, LocalNodeWrapper localNode) {
- if (iterNode.getVarNode() == null) {
- return false;
- }
- String localNodeName = LocalNodeWrapper.getLocalNodeName(localNode);
- for (LocalNodeWrapper aktIterArg : LocalNodeWrapper.gatherLocalNodes(iterNode.getVarNode())) {
- String aktIterArgName = LocalNodeWrapper.getLocalNodeName(aktIterArg);
- if (aktIterArgName.equals(localNodeName)) {
- return true;
- }
- }
- return false;
- }
-}
Deleted: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConfig.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConfig.java 2007-03-16 12:11:02 UTC (rev 2182)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConfig.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -1,105 +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.convertlocaltofield;
-
-import org.jruby.ast.MethodDefNode;
-import org.rubypeople.rdt.refactoring.core.IRefactoringConfig;
-import org.rubypeople.rdt.refactoring.documentprovider.IDocumentProvider;
-import org.rubypeople.rdt.refactoring.nodewrapper.ClassNodeWrapper;
-import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
-
-public class TempToFieldConfig implements IRefactoringConfig {
-
- private IDocumentProvider docProvider;
- private int caretPosition;
- private LocalNodeWrapper selectedNode;
- private ClassNodeWrapper enclosingClassNode;
- private MethodDefNode enclosingMethod;
- private boolean classField;
- private String newName;
-
- public TempToFieldConfig(IDocumentProvider docProvider, int caretPosition) {
- this.docProvider = docProvider;
- this.caretPosition = caretPosition;
- }
-
- public boolean isClassField() {
- return classField;
- }
-
- public void setClassField(boolean classField) {
- this.classField = classField;
- }
-
- public String getNewName() {
- return newName;
- }
-
- public void setNewName(String newName) {
- this.newName = newName;
- }
-
- public int getCaretPosition() {
- return caretPosition;
- }
-
- public ClassNodeWrapper getEnclosingClassNode() {
- return enclosingClassNode;
- }
-
- public void setEnclosingClassNode(ClassNodeWrapper enclosingClassNode) {
- this.enclosingClassNode = enclosingClassNode;
- }
-
- public MethodDefNode getEnclosingMethod() {
- return enclosingMethod;
- }
-
- public void setEnclosingMethod(MethodDefNode enclosingMethod) {
- this.enclosingMethod = enclosingMethod;
- }
-
- public LocalNodeWrapper getSelectedNode() {
- return selectedNode;
- }
-
- public void setSelectedNode(LocalNodeWrapper selectedItem) {
- this.selectedNode = selectedItem;
- }
-
- public IDocumentProvider getDocumentProvider() {
- return docProvider;
- }
-
- public void setDocumentProvider(IDocumentProvider doc) {
- this.docProvider = doc;
- }
-}
Deleted: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConverter.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConverter.java 2007-03-16 12:11:02 UTC (rev 2182)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/convertlocaltofield/TempToFieldConverter.java 2007-03-16 12:18:37 UTC (rev 2183)
@@ -1,204 +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.convertlocaltofield;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.jruby.ast.ClassVarNode;
-import org.jruby.ast.DAsgnNode;
-import org.jruby.ast.FixnumNode;
-import org.jruby.ast.InstVarNode;
-import org.jruby.ast.LocalAsgnNode;
-import org.jruby.ast.MethodDefNode;
-import org.jruby.ast.MultipleAsgnNode;
-import org.jruby.ast.Node;
-import org.jruby.ast.StrNode;
-import org.jruby.ast.VCallNode;
-import org.rubypeople.rdt.refactoring.core.SelectionNodeProvider;
-import org.rubypeople.rdt.refactoring.editprovider.DeleteEditProvider;
-import org.rubypeople.rdt.refactoring.editprovider.EditProvider;
-import org.rubypeople.rdt.refactoring.editprovider.MultiEditProvider;
-import org.rubypeople.rdt.refactoring.nodewrapper.LocalNodeWrapper;
-import org.rubypeople.rdt.refactoring.util.Constants;
-import org.rubypeople.rdt.refactoring.util.NodeUtil;
-
-public class TempToFieldConverter extends MultiEditProvider {
-
- public static final int INIT_IN_METHOD = 1;
-
- public static final int INIT_IN_CONSTRUCTOR = 2;
-
- private int initPlace;
-
- private Collection<LocalNodeWrapper> localNodes;
-
- private TempToFieldConfig config;
-
- public TempToFieldConverter(TempToFieldConfig config) {
- this.config = config;
- config.setNewName(getLocalVarName());
- localNodes = gatherLocalNodes();
- }
-
- private Collection<LocalNodeWrapper> gatherLocalNodes() {
-
- Collection<Node> allNodes = gatherLocalNodes(NodeUtil.getBody(config.getEnclosingMethod()));
- Collection<LocalNodeWrapper> allLocalNodes = LocalNodeWrapper.createLocalNodes(allNodes);
-
- Collection<LocalNodeWrapper> affectedLocalNodes = new ArrayList<LocalNodeWrapper>();
- String selectedNodeName = LocalNodeWrapper.getLocalNodeName(config.getSelectedNode());
- for (LocalNodeWrapper aktLokalNode : allLocalNodes) {
- String aktLokalNodeName = LocalNodeWrapper.getLocalNodeName(aktLokalNode);
- if (selectedNodeName.equals(aktLokalNodeName)) {
- affectedLocalNodes.add(aktLokalNode);
- }
- }
- return affectedLocalNodes;
- }
-
- private Collection<Node> gatherLocalNodes(Node baseNode) {
- ArrayList<Node> candidates = new ArrayList<Node>();
-
- if (baseNode == null || baseNode instanceof MethodDefNode) {
- return candidates;
- }
-
- for (Object o : baseNode.childNodes()) {
- Node n = (Node) o;
- if (NodeUtil.nodeAssignableFrom(n, LocalNodeWrapper.LOCAL_NODES_CLASSES)) {
- candidates.add(n);
- }
- if (!NodeUtil.nodeAssignableFrom(n, DAsgnNode.class, LocalAsgnNode.class)) {
- candidates.addAll(gatherLocalNodes(n));
- }
- }
- return candidates;
- }
-
- @Override
- protected Collection<EditProvider> getEditProviders() {
- return getConversions(localNodes);
- }
-
- private Collection<EditProvider> getConversions(Collection<LocalNodeWrapper> localNodes) {
- Map<LocalNodeWrapper, EditProvider> editProviderMap = new LinkedHashMap<LocalNodeWrapper, EditProvider>();
- LocalNodeWrapper firstLocalNode = localNodes.toArray(new LocalNodeWrapper[localNodes.size()])[0];
-
- for (LocalNodeWrapper aktLocalNode : localNodes) {
- Conversion conversion = new Conversion(aktLocalNode, config.getNewName(), config.isClassField());
- editProviderMap.put(aktLocalNode, conversion);
- }
- if (initPlace == INIT_IN_CONSTRUCTOR) {
- editProviderMap.remove(firstLocalNode);
- }
- Collection<EditProvider> editProviders = new ArrayList<EditProvider>(editProviderMap.values());
-
- if (initPlace == INIT_IN_CONSTRUCTOR) {
- editProviders.add(new InitInConstructorConversion(firstLocalNode, config));
- editProviders.add(new DeleteEditProvider(firstLocalNode.getWrappedNode()));
- }
-
- return editProviders;
- }
-
- public void setNewName(String newName) {
- config.setNewName(newName);
- }
-
- public void setInitPlace(int initPlace) {
- this.initPlace = initPlace;
- }
-
- public void setIsClassField(boolean isClassField) {
- config.setClassField(isClassField);
- }
-
- public String getLocalVarName() {
- return LocalNodeWrapper.getLocalNodeName(config.getSelectedNode());
- }
-
- private Node findSelectedNode(Class<?>... filterN...
[truncated message content] |