Merge branch 'master' into changeSignature
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Sat, 3 Apr 2010 10:24:50 +0000 (14:24 +0400)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Sat, 3 Apr 2010 10:24:50 +0000 (14:24 +0400)
24 files changed:
java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java
java/java-impl/src/com/intellij/refactoring/actions/ChangeSignatureAction.java
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDialog.java
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureTargetUtil.java [deleted file]
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureUtil.java
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureViewDescriptor.java
java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureHandler.java [moved from java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureHandler.java with 65% similarity]
java/java-impl/src/com/intellij/refactoring/changeSignature/ParameterTableModel.java
java/java-impl/src/com/intellij/refactoring/openapi/impl/JavaRefactoringActionHandlerFactoryImpl.java
java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTargetTest.java
platform/lang-api/src/com/intellij/lang/refactoring/DefaultRefactoringSupportProvider.java
platform/lang-api/src/com/intellij/lang/refactoring/RefactoringSupportProvider.java
platform/lang-api/src/com/intellij/refactoring/changeSignature/ChangeSignatureHandler.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringBundle.properties
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringSupportProvider.java
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.form [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureHandler.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureProcessor.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterInfo.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterTableModel.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/ui/GrCodeFragmentTableCellEditor.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/ui/GrCodeFragmentTableCellRenderer.java [new file with mode: 0644]

index 64747b2d233dd9196745bae941261c8d83489231..264d26b3a72d16c6c766d42503fc3e2331ab3c18 100644 (file)
@@ -21,9 +21,11 @@ import com.intellij.psi.search.LocalSearchScope;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.refactoring.RefactoringActionHandler;
-import com.intellij.refactoring.extractSuperclass.ExtractSuperclassHandler;
+import com.intellij.refactoring.changeSignature.ChangeSignatureHandler;
+import com.intellij.refactoring.changeSignature.JavaChangeSignatureHandler;
 import com.intellij.refactoring.extractInterface.ExtractInterfaceHandler;
 import com.intellij.refactoring.extractMethod.ExtractMethodHandler;
+import com.intellij.refactoring.extractSuperclass.ExtractSuperclassHandler;
 import com.intellij.refactoring.introduceField.IntroduceConstantHandler;
 import com.intellij.refactoring.introduceField.IntroduceFieldHandler;
 import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler;
@@ -84,6 +86,11 @@ public class JavaRefactoringSupportProvider extends DefaultRefactoringSupportPro
     return new ExtractSuperclassHandler();
   }
 
+  @Override
+  public ChangeSignatureHandler getChangeSignatureHandler() {
+    return new JavaChangeSignatureHandler();
+  }
+
   public static boolean mayRenameInplace(PsiElement elementToRename, final PsiElement nameSuggestionContext) {
     if (!(elementToRename instanceof PsiVariable)) return false;
     if (nameSuggestionContext != null && nameSuggestionContext.getContainingFile() != elementToRename.getContainingFile()) return false;
index 1da3be897e591aa43c96cc96f07ef85a83bf03b6..382cc4adb1ed328e2dd4e5509859c60332a539d2 100644 (file)
 */
 package com.intellij.refactoring.actions;
 
+import com.intellij.lang.Language;
+import com.intellij.lang.LanguageRefactoringSupport;
 import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.LangDataKeys;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.psi.*;
 import com.intellij.refactoring.RefactoringActionHandler;
 import com.intellij.refactoring.changeSignature.ChangeSignatureHandler;
-import com.intellij.refactoring.changeSignature.ChangeSignatureTargetUtil;
+import org.jetbrains.annotations.Nullable;
 
 public class ChangeSignatureAction extends BaseRefactoringAction {
   public boolean isAvailableInEditorOnly() {
@@ -35,13 +38,29 @@ public class ChangeSignatureAction extends BaseRefactoringAction {
   protected boolean isAvailableOnElementInEditor(final PsiElement element, final Editor editor) {
     final Document document = editor.getDocument();
     final PsiFile file = PsiDocumentManager.getInstance(element.getProject()).getPsiFile(document);
-    if (file != null && ChangeSignatureTargetUtil.findTargetMember(file, editor) != null) {
+    final ChangeSignatureHandler handler = getChangeSignatureHandler(element.getLanguage());
+    if (handler == null) return false;
+    if (file != null && handler.findTargetMember(file, editor) != null) {
       return true;
     }
     return element instanceof PsiMethod || element instanceof PsiClass;
   }
 
   public RefactoringActionHandler getHandler(DataContext dataContext) {
-    return new ChangeSignatureHandler();
+    final Language language = LangDataKeys.LANGUAGE.getData(dataContext);
+    if (language != null) {
+      return getChangeSignatureHandler(language);
+    }
+    return null;
+  }
+
+  @Override
+  protected boolean isAvailableForLanguage(Language language) {
+    return getChangeSignatureHandler(language) != null;
+  }
+
+  @Nullable
+  private static ChangeSignatureHandler getChangeSignatureHandler(Language language) {
+    return LanguageRefactoringSupport.INSTANCE.forLanguage(language).getChangeSignatureHandler();
   }
 }
index 510c5e1892c4f83083d4efab213d43682b883f31..7ccd058327b117d41b12f10634de4cd1ec4e8f4b 100644 (file)
@@ -282,8 +282,12 @@ public class ChangeSignatureDialog extends RefactoringDialog {
     panel.add(subPanel, BorderLayout.CENTER);
 
     JPanel subPanel1 = new JPanel(new GridBagLayout());
-    subPanel1.add(createExceptionsPanel(), new GridBagConstraints(0, 0, 1, 1, 0.5, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(4,4,4,0), 0, 0));
-    subPanel1.add(createSignaturePanel(), new GridBagConstraints(1, 0, 1, 1, 0.5, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(4,0,4,4), 0, 0));
+    subPanel1.add(createExceptionsPanel(),
+                  new GridBagConstraints(0, 0, 1, 1, 0.5, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(4, 4, 4, 0), 0,
+                                         0));
+    subPanel1.add(createSignaturePanel(),
+                  new GridBagConstraints(1, 0, 1, 1, 0.5, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(4, 0, 4, 4), 0,
+                                         0));
     panel.add(subPanel1, BorderLayout.SOUTH);
 
     return panel;
index 909b200d8e67d2baa23a288b11cce7e4ffea8248..2c7a3c5f9e79113b5b724eeb7b0cefffd3a54bbf 100644 (file)
@@ -58,6 +58,7 @@ import com.intellij.util.VisibilityUtil;
 import com.intellij.util.containers.HashSet;
 import com.intellij.util.containers.MultiMap;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.*;
 
@@ -479,7 +480,7 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
 
   protected boolean isProcessCovariantOverriders() {
     return Messages.showYesNoDialog(myProject, RefactoringBundle.message("do.you.want.to.process.overriding.methods.with.covariant.return.type"),
-                             ChangeSignatureHandler.REFACTORING_NAME, Messages.getQuestionIcon())
+                             JavaChangeSignatureHandler.REFACTORING_NAME, Messages.getQuestionIcon())
     == DialogWrapper.OK_EXIT_CODE;
   }
 
@@ -941,17 +942,13 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
             newArgs [newNonVarargCount] = createActualArgument(list, changeInfo.newParms [newNonVarargCount], toInsertDefaultValue, args);
           }
           else {
-            for (int i = 0; i < newVarargInitializers.length; i++) {
-              newArgs [i + newNonVarargCount] = newVarargInitializers [i];
-            }
+            System.arraycopy(newVarargInitializers, 0, newArgs, newNonVarargCount, newVarargInitializers.length);
           }
         }
         else {
           final int newVarargCount = newArgsLength - newNonVarargCount;
           LOG.assertTrue(newVarargCount == 0 || newVarargCount == varargCount);
-          for (int i = 0; i < newVarargCount; i++) {
-            newArgs[newNonVarargCount + i] = args[nonVarargCount + i];
-          }
+          System.arraycopy(args, nonVarargCount, newArgs, newNonVarargCount, newVarargCount);
         }
         ChangeSignatureUtil.synchronizeList(list, Arrays.asList(newArgs), ExpressionList.INSTANCE, changeInfo.toRemoveParm);
       }
@@ -973,6 +970,7 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
     }
   }
 
+  @Nullable
   private PsiExpression createDefaultValue(final PsiElementFactory factory, final ParameterInfoImpl info, final PsiExpressionList list)
     throws IncorrectOperationException {
     if (info.useAnySingleVariable) {
diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureTargetUtil.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureTargetUtil.java
deleted file mode 100644 (file)
index 5c947f4..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * User: anna
- * Date: 24-Nov-2009
- */
-package com.intellij.refactoring.changeSignature;
-
-import com.intellij.openapi.editor.Editor;
-import com.intellij.psi.*;
-import com.intellij.psi.util.PsiTreeUtil;
-import org.jetbrains.annotations.Nullable;
-
-public class ChangeSignatureTargetUtil {
-  private ChangeSignatureTargetUtil() {}
-
-  @Nullable
-  public static PsiMember findTargetMember(PsiFile file, Editor editor) {
-    PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
-    if (PsiTreeUtil.getParentOfType(element, PsiParameterList.class) != null) {
-      return PsiTreeUtil.getParentOfType(element, PsiMethod.class);
-    }
-
-    final PsiMethodCallExpression expression = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
-    if (expression != null) {
-      assert element != null;
-      final PsiExpression qualifierExpression = expression.getMethodExpression().getQualifierExpression();
-      if (PsiTreeUtil.isAncestor(qualifierExpression, element, false)) {
-        final PsiExpressionList expressionList = PsiTreeUtil.getParentOfType(qualifierExpression, PsiExpressionList.class);
-        if (expressionList != null) {
-          final PsiElement parent = expressionList.getParent();
-          if (parent instanceof PsiMethodCallExpression) {
-            return ((PsiMethodCallExpression)parent).resolveMethod();
-          }
-        }
-      } else {
-        return expression.resolveMethod();
-      }
-    }
-
-    final PsiTypeParameterList typeParameterList = PsiTreeUtil.getParentOfType(element, PsiTypeParameterList.class);
-    if (typeParameterList != null) {
-      return PsiTreeUtil.getParentOfType(typeParameterList, PsiMember.class);
-    }
-
-    final PsiReferenceParameterList referenceParameterList = PsiTreeUtil.getParentOfType(element, PsiReferenceParameterList.class);
-    if (referenceParameterList != null) {
-      final PsiJavaCodeReferenceElement referenceElement =
-        PsiTreeUtil.getParentOfType(referenceParameterList, PsiJavaCodeReferenceElement.class);
-      if (referenceElement != null) {
-        final PsiElement resolved = referenceElement.resolve();
-        if (resolved instanceof PsiClass) {
-          return (PsiMember)resolved;
-        }
-        else if (resolved instanceof PsiMethod) {
-          return (PsiMember)resolved;
-        }
-      }
-    }
-    return null;
-  }
-
-}
index 708bb92ebf5eab9ecb295303608b8aefaaaf32b4..96275d137b803f54c2b8c07ec817931631c6b848 100644 (file)
@@ -26,10 +26,13 @@ import java.util.List;
  * @author dsl
  */
 public class ChangeSignatureUtil {
-  private ChangeSignatureUtil() {}
+  private ChangeSignatureUtil() {
+  }
 
-  public static <Parent extends PsiElement, Child extends PsiElement>
-  void synchronizeList(Parent list, final List<Child> newElements, ChildrenGenerator<Parent, Child> generator, final boolean[] shouldRemoveChild)
+  public static <Parent extends PsiElement, Child extends PsiElement> void synchronizeList(Parent list,
+                                                                                           final List<Child> newElements,
+                                                                                           ChildrenGenerator<Parent, Child> generator,
+                                                                                           final boolean[] shouldRemoveChild)
     throws IncorrectOperationException {
 
     ArrayList<Child> elementsToRemove = null;
@@ -72,7 +75,7 @@ public class ChangeSignatureUtil {
     }
   }
 
-  public static interface ChildrenGenerator<Parent extends PsiElement, Child extends PsiElement> {
+  public interface ChildrenGenerator<Parent extends PsiElement, Child extends PsiElement> {
     List<Child> getChildren(Parent parent);
   }
 }
index 86ce5b030019d87ee55d17c2ea77c1ff0271f47e..cd453595851e512d4847f8948baf3292c5f91c05 100644 (file)
  */
 package com.intellij.refactoring.changeSignature;
 
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiMethod;
 import com.intellij.refactoring.RefactoringBundle;
 import com.intellij.usageView.UsageViewBundle;
 import com.intellij.usageView.UsageViewDescriptor;
 import com.intellij.usageView.UsageViewUtil;
-import com.intellij.openapi.util.text.StringUtil;
 import org.jetbrains.annotations.NotNull;
 
-class ChangeSignatureViewDescriptor implements UsageViewDescriptor {
+public class ChangeSignatureViewDescriptor implements UsageViewDescriptor {
 
   private final PsiMethod myMethod;
   private final String myProcessedElementsHeader;
similarity index 65%
rename from java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureHandler.java
rename to java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureHandler.java
index 5c099c16bb494c0cc87f9fb8be8f5e1067b171f6..d8d683553901a106e92e8a5d3e3f9c31b53fd0b1 100644 (file)
@@ -24,20 +24,19 @@ import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.ScrollType;
 import com.intellij.openapi.project.Project;
 import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.refactoring.HelpID;
-import com.intellij.refactoring.RefactoringActionHandler;
 import com.intellij.refactoring.RefactoringBundle;
 import com.intellij.refactoring.changeClassSignature.ChangeClassSignatureDialog;
 import com.intellij.refactoring.util.CommonRefactoringUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-public class ChangeSignatureHandler implements RefactoringActionHandler {
-  public static final String REFACTORING_NAME = RefactoringBundle.message("changeSignature.refactoring.name");
+public class JavaChangeSignatureHandler implements ChangeSignatureHandler {
 
   public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
     editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
-    PsiElement element = ChangeSignatureTargetUtil.findTargetMember(file, editor);
+    PsiElement element = findTargetMember(file, editor);
     if (element == null) {
       element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
     }
@@ -96,4 +95,51 @@ public class ChangeSignatureHandler implements RefactoringActionHandler {
     ChangeClassSignatureDialog dialog = new ChangeClassSignatureDialog(aClass);
     dialog.show();
   }
+
+  @Nullable
+  public PsiMember findTargetMember(PsiFile file, Editor editor) {
+    PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
+    if (PsiTreeUtil.getParentOfType(element, PsiParameterList.class) != null) {
+      return PsiTreeUtil.getParentOfType(element, PsiMethod.class);
+    }
+
+    final PsiMethodCallExpression expression = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
+    if (expression != null) {
+      assert element != null;
+      final PsiExpression qualifierExpression = expression.getMethodExpression().getQualifierExpression();
+      if (PsiTreeUtil.isAncestor(qualifierExpression, element, false)) {
+        final PsiExpressionList expressionList = PsiTreeUtil.getParentOfType(qualifierExpression, PsiExpressionList.class);
+        if (expressionList != null) {
+          final PsiElement parent = expressionList.getParent();
+          if (parent instanceof PsiMethodCallExpression) {
+            return ((PsiMethodCallExpression)parent).resolveMethod();
+          }
+        }
+      }
+      else {
+        return expression.resolveMethod();
+      }
+    }
+
+    final PsiTypeParameterList typeParameterList = PsiTreeUtil.getParentOfType(element, PsiTypeParameterList.class);
+    if (typeParameterList != null) {
+      return PsiTreeUtil.getParentOfType(typeParameterList, PsiMember.class);
+    }
+
+    final PsiReferenceParameterList referenceParameterList = PsiTreeUtil.getParentOfType(element, PsiReferenceParameterList.class);
+    if (referenceParameterList != null) {
+      final PsiJavaCodeReferenceElement referenceElement =
+        PsiTreeUtil.getParentOfType(referenceParameterList, PsiJavaCodeReferenceElement.class);
+      if (referenceElement != null) {
+        final PsiElement resolved = referenceElement.resolve();
+        if (resolved instanceof PsiClass) {
+          return (PsiMember)resolved;
+        }
+        else if (resolved instanceof PsiMethod) {
+          return (PsiMember)resolved;
+        }
+      }
+    }
+    return null;
+  }
 }
index bd09d2a2e501b8e6fa82344a74a981ec16bae94c..ed0baa1991515948eadb81521e68931fcf520d54 100644 (file)
@@ -116,8 +116,7 @@ class ParameterTableModel extends AbstractTableModel implements RowEditableTable
 
   public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
     if (rowIndex < 0 || rowIndex >= myParameterInfos.size()) return;
-    String s = aValue instanceof String ? (String)aValue : null;
-    if (s == null) s = "";
+    String s = aValue instanceof String ? (String)aValue : "";
     s = s.trim();
     ParameterInfoImpl info = myParameterInfos.get(rowIndex);
     switch (columnIndex) {
@@ -186,8 +185,8 @@ class ParameterTableModel extends AbstractTableModel implements RowEditableTable
   }
 
   private JavaCodeFragment createDefaultValueCodeFragment(final String expressionText, final PsiType expectedType) {
-    PsiExpressionCodeFragment codeFragment = JavaPsiFacade.getInstance(myParameterList.getProject()).getElementFactory().createExpressionCodeFragment(expressionText,
-                                                                                                                           myReferenceExpression, expectedType, true);
+    PsiExpressionCodeFragment codeFragment = JavaPsiFacade.getInstance(myParameterList.getProject()).getElementFactory()
+      .createExpressionCodeFragment(expressionText, myReferenceExpression, expectedType, true);
     codeFragment.setVisibilityChecker(JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE);
     return codeFragment;
   }
index d2f23b4831a6801f2ffc00f39e7b22960bfab873..23d965134c313a61e3411b8cc2326cec0b8ff106 100644 (file)
@@ -18,7 +18,7 @@ package com.intellij.refactoring.openapi.impl;
 import com.intellij.refactoring.JavaRefactoringActionHandlerFactory;
 import com.intellij.refactoring.RefactoringActionHandler;
 import com.intellij.refactoring.anonymousToInner.AnonymousToInnerHandler;
-import com.intellij.refactoring.changeSignature.ChangeSignatureHandler;
+import com.intellij.refactoring.changeSignature.JavaChangeSignatureHandler;
 import com.intellij.refactoring.convertToInstanceMethod.ConvertToInstanceMethodHandler;
 import com.intellij.refactoring.encapsulateFields.EncapsulateFieldsHandler;
 import com.intellij.refactoring.extractInterface.ExtractInterfaceHandler;
@@ -86,7 +86,7 @@ public class JavaRefactoringActionHandlerFactoryImpl extends JavaRefactoringActi
   }
 
   public RefactoringActionHandler createChangeSignatureHandler() {
-    return new ChangeSignatureHandler();
+    return new JavaChangeSignatureHandler();
   }
 
   public RefactoringActionHandler createExtractSuperclassHandler() {
index 6ac077915e711240d30619b3860684d2907694d3..c2161d9179ce9b9be48ca7f1bb8f8a25a1f466d7 100644 (file)
@@ -8,7 +8,7 @@ import com.intellij.JavaTestUtil;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
 import com.intellij.psi.PsiMember;
-import com.intellij.refactoring.changeSignature.ChangeSignatureTargetUtil;
+import com.intellij.refactoring.changeSignature.JavaChangeSignatureHandler;
 import com.intellij.testFramework.LightCodeInsightTestCase;
 import org.jetbrains.annotations.NonNls;
 
@@ -43,7 +43,7 @@ public class ChangeSignatureTargetTest extends LightCodeInsightTestCase {
     String basePath = "/refactoring/changeSignatureTarget/" + getTestName(true);
     @NonNls final String filePath = basePath + ".java";
     configureByFile(filePath);
-    final PsiMember member = ChangeSignatureTargetUtil.findTargetMember(getFile(), getEditor());
+    final PsiMember member = new JavaChangeSignatureHandler().findTargetMember(getFile(), getEditor());
     assertNotNull(member);
     assertEquals(expectedMemberName, member.getName());
   }
index e1d5f95e8bb213ea7f1d92a00d4132063cd7d9dd..3db3337d1493930debc921c8788ca818b9270dc0 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.lang.refactoring;
 
 import com.intellij.psi.PsiElement;
 import com.intellij.refactoring.RefactoringActionHandler;
+import com.intellij.refactoring.changeSignature.ChangeSignatureHandler;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -69,4 +70,8 @@ public class DefaultRefactoringSupportProvider implements RefactoringSupportProv
   public boolean doInplaceRenameFor(final PsiElement element, final PsiElement context) {
     return false;
   }
+
+  public ChangeSignatureHandler getChangeSignatureHandler() {
+    return null;
+  }
 }
index 46b8ed98a5dba9c1c9c76418719e21ff362ca7bb..7aa9480d5e7ba9679d86045874d0df09c32992fb 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.lang.refactoring;
 
 import com.intellij.psi.PsiElement;
 import com.intellij.refactoring.RefactoringActionHandler;
+import com.intellij.refactoring.changeSignature.ChangeSignatureHandler;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -91,5 +92,11 @@ public interface RefactoringSupportProvider {
    */
   @Nullable RefactoringActionHandler getExtractSuperClassHandler();
 
+  /**
+   * @return  handler for changing signature in this language
+   * @see com.intellij.refactoring.RefactoringActionHandler
+   */
+  @Nullable ChangeSignatureHandler getChangeSignatureHandler();
+
   boolean doInplaceRenameFor(PsiElement element, PsiElement context);
 }
diff --git a/platform/lang-api/src/com/intellij/refactoring/changeSignature/ChangeSignatureHandler.java b/platform/lang-api/src/com/intellij/refactoring/changeSignature/ChangeSignatureHandler.java
new file mode 100644 (file)
index 0000000..00a8816
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.refactoring.changeSignature;
+
+import com.intellij.openapi.editor.Editor;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.refactoring.RefactoringActionHandler;
+import com.intellij.refactoring.RefactoringBundle;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Maxim.Medvedev
+ */
+public interface ChangeSignatureHandler extends RefactoringActionHandler{
+  String REFACTORING_NAME = RefactoringBundle.message("changeSignature.refactoring.name");
+
+  @Nullable
+  PsiElement findTargetMember(PsiFile file, Editor editor);
+}
index 10fd18f55e55a0aed957cda5889b333f3efb4e7e..eb617f3e9cb6763b372574f6b7b932187e804ca0 100644 (file)
@@ -99,3 +99,9 @@ variable.conflicts.with.field.0=Chosen name  will conflict with field {0}
 introduce.parameter.title=Introduce Parameter
 groovy.does.not.support.inner.classes.but.it.is.used.in.parameter.initializer=Groovy does not support inner classes but it is used in parameter initializer.
 groovy.does.not.support.anonymous.classes.but.it.is.used.in.parameter.initializer=Groovy does not support anonymous classes but it is used in parameter initializer.
+error.wrong.caret.position.method.name=The caret should be positioned at the name of the method to be refactored.
+changeSignature.refactoring.name=Change Signature
+column.name.type=Type
+column.name.name=Name
+column.name.default.initializer=Default initializer
+column.name.default.value=Default value\
index 1aa3631adcf4b13f6097b62fa6b2cb45e8ccc775..61e08638e865ae709c8b3f36161bcfac5b73c4a1 100644 (file)
@@ -19,8 +19,10 @@ package org.jetbrains.plugins.groovy.refactoring;
 import com.intellij.lang.refactoring.DefaultRefactoringSupportProvider;
 import com.intellij.psi.PsiElement;
 import com.intellij.refactoring.RefactoringActionHandler;
+import com.intellij.refactoring.changeSignature.ChangeSignatureHandler;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
+import org.jetbrains.plugins.groovy.refactoring.changeSignature.GrChangeSignatureHandler;
 import org.jetbrains.plugins.groovy.refactoring.extractMethod.GroovyExtractMethodHandler;
 import org.jetbrains.plugins.groovy.refactoring.introduceVariable.GroovyIntroduceVariableHandler;
 
@@ -47,4 +49,9 @@ public class GroovyRefactoringSupportProvider extends DefaultRefactoringSupportP
   public RefactoringActionHandler getExtractMethodHandler() {
     return new GroovyExtractMethodHandler();
   }
+
+  @Override
+  public ChangeSignatureHandler getChangeSignatureHandler() {
+    return new GrChangeSignatureHandler();
+  }
 }
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.form b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.form
new file mode 100644 (file)
index 0000000..9036d53
--- /dev/null
@@ -0,0 +1,194 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.groovy.refactoring.changeSignature.GrChangeSignatureDialog">
+  <grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+    <margin top="0" left="0" bottom="0" right="0"/>
+    <constraints>
+      <xy x="20" y="20" width="500" height="400"/>
+    </constraints>
+    <properties>
+      <opaque value="true"/>
+    </properties>
+    <border type="none"/>
+    <children>
+      <component id="de28c" class="javax.swing.JLabel">
+        <constraints>
+          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text value="Name:"/>
+        </properties>
+      </component>
+      <component id="c4b75" class="javax.swing.JLabel">
+        <constraints>
+          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text value="Return type:"/>
+        </properties>
+      </component>
+      <grid id="f46e6" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+        <margin top="0" left="0" bottom="0" right="0"/>
+        <constraints>
+          <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties/>
+        <border type="none"/>
+        <children>
+          <grid id="6ca6f" binding="myParametersPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+            <margin top="0" left="0" bottom="0" right="0"/>
+            <constraints>
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties/>
+            <border type="none" title="Parameters">
+              <font/>
+            </border>
+            <children>
+              <grid id="e15c7" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+                <margin top="0" left="0" bottom="0" right="0"/>
+                <constraints>
+                  <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+                </constraints>
+                <properties/>
+                <border type="none"/>
+                <children>
+                  <component id="3fac3" class="javax.swing.JButton" binding="myAddButton" default-binding="true">
+                    <constraints>
+                      <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+                    </constraints>
+                    <properties>
+                      <text value="Add"/>
+                    </properties>
+                  </component>
+                  <component id="3ce7d" class="javax.swing.JButton" binding="myRemoveButton" default-binding="true">
+                    <constraints>
+                      <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+                    </constraints>
+                    <properties>
+                      <text value="Remove"/>
+                    </properties>
+                  </component>
+                  <component id="92633" class="javax.swing.JButton" binding="myMoveUpButton" default-binding="true">
+                    <constraints>
+                      <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+                    </constraints>
+                    <properties>
+                      <text value="Move Up"/>
+                    </properties>
+                  </component>
+                  <component id="68d42" class="javax.swing.JButton" binding="myMoveDownButton" default-binding="true">
+                    <constraints>
+                      <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+                    </constraints>
+                    <properties>
+                      <text value="Move Down"/>
+                    </properties>
+                  </component>
+                  <vspacer id="b8dbf">
+                    <constraints>
+                      <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+                    </constraints>
+                  </vspacer>
+                </children>
+              </grid>
+              <scrollpane id="63081">
+                <constraints>
+                  <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+                </constraints>
+                <properties/>
+                <border type="none"/>
+                <children>
+                  <component id="ac049" class="com.intellij.util.ui.Table" binding="myParameterTable" custom-create="true">
+                    <constraints/>
+                    <properties/>
+                  </component>
+                </children>
+              </scrollpane>
+            </children>
+          </grid>
+          <grid id="b2211" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+            <margin top="0" left="0" bottom="0" right="0"/>
+            <constraints>
+              <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties/>
+            <border type="none" title="Visibility"/>
+            <children>
+              <component id="ea67d" class="javax.swing.JRadioButton" binding="myPublicRadioButton" default-binding="true">
+                <constraints>
+                  <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+                </constraints>
+                <properties>
+                  <enabled value="true"/>
+                  <selected value="true"/>
+                  <text value="Public"/>
+                </properties>
+              </component>
+              <component id="2093c" class="javax.swing.JRadioButton" binding="myProtectedRadioButton" default-binding="true">
+                <constraints>
+                  <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+                </constraints>
+                <properties>
+                  <text value="Protected"/>
+                </properties>
+              </component>
+              <component id="8f6d2" class="javax.swing.JRadioButton" binding="myPrivateRadioButton" default-binding="true">
+                <constraints>
+                  <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+                </constraints>
+                <properties>
+                  <text value="Private"/>
+                </properties>
+              </component>
+              <vspacer id="4fecc">
+                <constraints>
+                  <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+                </constraints>
+              </vspacer>
+            </children>
+          </grid>
+        </children>
+      </grid>
+      <grid id="7651b" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+        <margin top="0" left="0" bottom="0" right="0"/>
+        <constraints>
+          <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties/>
+        <border type="none" title="Signature Preview"/>
+        <children>
+          <component id="9dd0b" class="javax.swing.JLabel" binding="mySignatureLabel">
+            <constraints>
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <text value="Label"/>
+            </properties>
+          </component>
+          <vspacer id="7079b">
+            <constraints>
+              <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+            </constraints>
+          </vspacer>
+        </children>
+      </grid>
+      <component id="eb288" class="com.intellij.ui.EditorTextField" binding="myNameField" custom-create="true">
+        <constraints>
+          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+        </constraints>
+      </component>
+      <component id="f22ad" class="com.intellij.ui.EditorTextField" binding="myReturnTypeField" custom-create="true">
+        <constraints>
+          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+        </constraints>
+      </component>
+    </children>
+  </grid>
+  <buttonGroups>
+    <group name="myVisibilityGroup">
+      <member id="ea67d"/>
+      <member id="2093c"/>
+      <member id="8f6d2"/>
+    </group>
+  </buttonGroups>
+</form>
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.java
new file mode 100644 (file)
index 0000000..220d82b
--- /dev/null
@@ -0,0 +1,327 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.refactoring.changeSignature;
+
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.psi.JavaPsiFacade;
+import com.intellij.psi.PsiDocumentManager;
+import com.intellij.psi.PsiType;
+import com.intellij.psi.PsiTypeCodeFragment;
+import com.intellij.refactoring.HelpID;
+import com.intellij.refactoring.ui.CodeFragmentTableCellEditor;
+import com.intellij.refactoring.ui.CodeFragmentTableCellRenderer;
+import com.intellij.refactoring.ui.RefactoringDialog;
+import com.intellij.refactoring.util.CanonicalTypes;
+import com.intellij.refactoring.util.CommonRefactoringUtil;
+import com.intellij.ui.EditorTextField;
+import com.intellij.ui.TableUtil;
+import com.intellij.util.ui.Table;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.debugger.fragments.GroovyCodeFragment;
+import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
+import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
+import org.jetbrains.plugins.groovy.refactoring.ui.GrCodeFragmentTableCellEditor;
+import org.jetbrains.plugins.groovy.refactoring.ui.GrCodeFragmentTableCellRenderer;
+
+import javax.swing.*;
+import javax.swing.event.TableModelEvent;
+import javax.swing.event.TableModelListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.List;
+
+/**
+ * @author Maxim.Medvedev
+ */
+public class GrChangeSignatureDialog extends RefactoringDialog {
+  private EditorTextField myNameField;
+  private EditorTextField myReturnTypeField;
+  private JRadioButton myPublicRadioButton;
+  private JRadioButton myProtectedRadioButton;
+  private JRadioButton myPrivateRadioButton;
+  private JPanel myParametersPanel;
+  private Table myParameterTable;
+  private JButton myAddButton;
+  private JButton myRemoveButton;
+  private JButton myMoveUpButton;
+  private JButton myMoveDownButton;
+  private JPanel contentPane;
+  private JLabel mySignatureLabel;
+  private GrParameterTableModel myParameterModel;
+  private GrMethod myMethod;
+//  private Project myProject;
+  private PsiTypeCodeFragment myReturnTypeCodeFragment;
+  private GroovyCodeFragment myNameCodeFragment;
+
+  public GrChangeSignatureDialog(@NotNull Project project, GrMethod method) {
+    super(project, true);
+    myMethod = method;
+    init();
+    configureParameterButtons();
+    updateSignature();
+  }
+
+  private void configureParameterButtons() {
+    myAddButton.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) {
+        int selectedColumn = myParameterTable.getSelectedColumn();
+        myParameterModel.addRow();
+        myParameterTable.setRowSelectionInterval(myParameterModel.getRowCount() - 1, myParameterModel.getRowCount() - 1);
+        myParameterTable.setColumnSelectionInterval(selectedColumn, selectedColumn);
+      }
+    });
+    myRemoveButton.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) {
+        int selectedRow = myParameterTable.getSelectedRow();
+        int selectedColumn = myParameterTable.getSelectedColumn();
+
+        myParameterModel.removeRow(myParameterTable.getSelectedRow());
+
+        if (selectedRow == myParameterModel.getRowCount()) selectedRow--;
+        if (myParameterModel.getRowCount() == 0) return;
+        myParameterTable.setRowSelectionInterval(selectedRow, selectedRow);
+        myParameterTable.setColumnSelectionInterval(selectedColumn, selectedColumn);
+      }
+    });
+
+    myMoveUpButton.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) {
+        final int selectedRow = myParameterTable.getSelectedRow();
+        int selectedColumn = myParameterTable.getSelectedColumn();
+        myParameterModel.exchangeRows(selectedRow, selectedRow - 1);
+        myParameterTable.setRowSelectionInterval(selectedRow - 1, selectedRow - 1);
+        myParameterTable.setColumnSelectionInterval(selectedColumn, selectedColumn);
+      }
+    });
+
+    myMoveDownButton.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) {
+        final int selectedRow = myParameterTable.getSelectedRow();
+        int selectedColumn = myParameterTable.getSelectedColumn();
+        myParameterModel.exchangeRows(selectedRow, selectedRow + 1);
+        myParameterTable.setRowSelectionInterval(selectedRow + 1, selectedRow + 1);
+        myParameterTable.setColumnSelectionInterval(selectedColumn, selectedColumn);
+      }
+    });
+  }
+
+  protected void init() {
+    super.init();
+  }
+
+  private void stopEditing() {
+    TableUtil.stopEditing(myParameterTable);
+  }
+
+  @Override
+  protected JComponent createCenterPanel() {
+    return contentPane;
+  }
+
+
+  private void createUIComponents() {
+    createNameAndReturnTypeEditors();
+    createParametersModel();
+  }
+
+  private void createNameAndReturnTypeEditors() {
+    myNameCodeFragment = new GroovyCodeFragment(myProject, "");
+    myNameField = new EditorTextField(PsiDocumentManager.getInstance(myProject).getDocument(myNameCodeFragment), myProject,
+                                      myNameCodeFragment.getFileType());
+
+    myReturnTypeCodeFragment = JavaPsiFacade.getInstance(myProject).getElementFactory().createTypeCodeFragment("", myMethod, true, true);
+    final Document document = PsiDocumentManager.getInstance(myProject).getDocument(myReturnTypeCodeFragment);
+    myReturnTypeField = new EditorTextField(document, myProject, myReturnTypeCodeFragment.getFileType());
+
+    myNameField.setText(myMethod.getName());
+    final GrTypeElement element = myMethod.getReturnTypeElementGroovy();
+    if (element != null) {
+      myReturnTypeField.setText(element.getText());
+    }
+  }
+
+  private void createParametersModel() {
+    myParameterModel = new GrParameterTableModel(myMethod, this, myProject);
+    myParameterTable = new Table(myParameterModel);
+    myParameterTable.setCellSelectionEnabled(true);
+
+    myParameterTable.getColumnModel().getColumn(0).setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
+    myParameterTable.getColumnModel().getColumn(1).setCellRenderer(new GrCodeFragmentTableCellRenderer(myProject));
+    myParameterTable.getColumnModel().getColumn(2).setCellRenderer(new GrCodeFragmentTableCellRenderer(myProject));
+    myParameterTable.getColumnModel().getColumn(3).setCellRenderer(new GrCodeFragmentTableCellRenderer(myProject));
+
+    myParameterTable.getColumnModel().getColumn(0).setCellEditor(new CodeFragmentTableCellEditor(myProject));
+    myParameterTable.getColumnModel().getColumn(1).setCellEditor(new GrCodeFragmentTableCellEditor(myProject));
+    myParameterTable.getColumnModel().getColumn(2).setCellEditor(new GrCodeFragmentTableCellEditor(myProject));
+    myParameterTable.getColumnModel().getColumn(3).setCellEditor(new GrCodeFragmentTableCellEditor(myProject));
+
+    if (myParameterTable.getRowCount() > 0) {
+      myParameterTable.setRowSelectionInterval(0, 0);
+      myParameterTable.setColumnSelectionInterval(0, 0);
+    }
+
+    myParameterModel.addTableModelListener(new TableModelListener() {
+      public void tableChanged(TableModelEvent e) {
+        updateSignature();
+      }
+    });
+
+  }
+
+  private void updateSignature() {
+    final int selectedRow = myParameterTable.getSelectedRow();
+    final int rowCount = myParameterModel.getRowCount();
+    myMoveUpButton.setEnabled(selectedRow > 0);
+    myMoveDownButton.setEnabled(selectedRow + 1 < rowCount && rowCount > 1);
+    myRemoveButton.setEnabled(rowCount > 0);
+
+    mySignatureLabel.setText(generateSignatureText());
+  }
+
+  private String generateSignatureText() {
+    String name = getNewName();
+    String type = myReturnTypeField.getText().trim();
+
+    StringBuilder builder = new StringBuilder();
+    if (myPublicRadioButton.isSelected() && type.length() == 0) {
+      builder.append(GrModifier.DEF);
+    }
+    if (myPrivateRadioButton.isSelected()) {
+      builder.append(GrModifier.PRIVATE).append(' ');
+    }
+    else if (myProtectedRadioButton.isSelected()) {
+      builder.append(GrModifier.PROTECTED).append(' ');
+    }
+    builder.append(type).append(' ');
+    builder.append(name).append('(');
+    final List<GrParameterInfo> infos = myParameterModel.getParameterInfos();
+    for (int i = 0, infosSize = infos.size() - 1; i < infosSize; i++) {
+      generateParameterText(infos.get(i), builder);
+      builder.append(", ");
+    }
+    if (infos.size() > 0) {
+      generateParameterText(infos.get(infos.size() - 1), builder);
+    }
+
+    builder.append(')');
+    return builder.toString();
+  }
+
+
+  private static void generateParameterText(GrParameterInfo info, StringBuilder builder) {
+    final PsiTypeCodeFragment typeFragment = info.getTypeFragment();
+    builder.append(typeFragment != null ? typeFragment.getText().trim() : GrModifier.DEF).append(' ');
+    final GroovyCodeFragment nameFragment = info.getNameFragment();
+    builder.append(nameFragment != null ? nameFragment.getText().trim() : "");
+    final GroovyCodeFragment defaultInitializer = info.getDefaultInitializer();
+
+    final String defaultInitializerText = defaultInitializer != null ? defaultInitializer.getText().trim() : "";
+    if (defaultInitializerText.length() > 0) {
+      builder.append(" = ").append(defaultInitializerText);
+    }
+  }
+
+  @Override
+  protected void doAction() {
+    if (!validateInputData()) {
+      return;
+    }
+
+    stopEditing();
+    String modifier = "";
+    if (myPublicRadioButton.isSelected()) {
+      modifier = GrModifier.PUBLIC;
+    }
+    else if (myPrivateRadioButton.isSelected()) {
+      modifier = GrModifier.PRIVATE;
+    }
+    else if (myProtectedRadioButton.isSelected()) {
+      modifier = GrModifier.PROTECTED;
+    }
+
+    PsiType returnType = null;
+    try {
+      returnType = myReturnTypeCodeFragment.getType();
+    }
+    catch (PsiTypeCodeFragment.TypeSyntaxException e) {
+      e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+    }
+    catch (PsiTypeCodeFragment.NoTypeException e) {
+      returnType = PsiType.NULL;
+    }
+
+    String newName = getNewName();
+    final List<GrParameterInfo> parameterInfos = myParameterModel.getParameterInfos();
+    invokeRefactoring(new GrChangeSignatureProcessor(myProject, new GrChangeSignatureProcessor.GrChangeInfoImpl(myMethod, modifier,
+                                                                                                                CanonicalTypes.createTypeWrapper(
+                                                                                                                  returnType), newName,
+                                                                                                                parameterInfos)));
+
+  }
+
+  private String getNewName() {
+    return myNameField.getText().trim();
+  }
+
+  private boolean validateInputData() {
+    if (!checkName()) {
+      CommonRefactoringUtil.showErrorHint(myProject, null, "Name is wrong", "Incorrect data", HelpID.CHANGE_SIGNATURE);
+      return false;
+    }
+
+    if (!checkType(myReturnTypeCodeFragment)) {
+      CommonRefactoringUtil.showErrorHint(myProject, null, "Return type is wrong", "Incorrect data", HelpID.CHANGE_SIGNATURE);
+    }
+
+    for (GrParameterInfo info : myParameterModel.getParameterInfos()) {
+      if (!checkType(info.getTypeFragment())) {
+        CommonRefactoringUtil
+          .showErrorHint(myProject, null, "Type for parameter " + info.getName() + " is wrong", "Incorrect data", HelpID.CHANGE_SIGNATURE);
+        return false;
+      }
+    }
+    return true;
+  }
+
+  private boolean checkType(PsiTypeCodeFragment typeCodeFragment) {
+    try {
+      typeCodeFragment.getType();
+    }
+    catch (PsiTypeCodeFragment.TypeSyntaxException e) {
+      return false;
+    }
+    catch (PsiTypeCodeFragment.NoTypeException e) {
+      return true; //Groovy accepts methods and parameters without explicit type
+    }
+    return true;
+  }
+
+  private boolean checkName() {
+    final String newName = getNewName();
+    if (StringUtil.isJavaIdentifier(newName)) return true;
+    try {
+      GroovyPsiElementFactory.getInstance(myProject).createMethodFromText("def " + newName + "(){}");
+    }
+    catch (Throwable e) {
+      return false;
+    }
+    return true;
+  }
+}
\ No newline at end of file
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureHandler.java
new file mode 100644 (file)
index 0000000..7383624
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.refactoring.changeSignature;
+
+import com.intellij.codeInsight.TargetElementUtil;
+import com.intellij.ide.util.SuperMethodWarningUtil;
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.LangDataKeys;
+import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.ScrollType;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.refactoring.HelpID;
+import com.intellij.refactoring.RefactoringBundle;
+import com.intellij.refactoring.changeSignature.ChangeSignatureHandler;
+import com.intellij.refactoring.util.CommonRefactoringUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
+import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringBundle;
+
+/**
+ * @author Maxim.Medvedev
+ */
+public class GrChangeSignatureHandler implements ChangeSignatureHandler {
+  public static final String REFACTORING_NAME = GroovyRefactoringBundle.message("changeSignature.refactoring.name");
+
+  public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
+    editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
+    PsiElement element = findTargetMember(file, editor);
+    if (element == null) {
+      element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
+    }
+    invokeOnElement(project, editor, element);
+  }
+
+  private static void invokeOnElement(Project project, Editor editor, PsiElement element) {
+    if (element instanceof PsiMethod) {
+      invoke((PsiMethod)element, project, editor);
+    }
+    else {
+      String message =
+        RefactoringBundle.getCannotRefactorMessage(GroovyRefactoringBundle.message("error.wrong.caret.position.method.name"));
+      CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.CHANGE_SIGNATURE);
+    }
+  }
+
+  public void invoke(@NotNull final Project project, @NotNull final PsiElement[] elements, final DataContext dataContext) {
+    if (elements.length != 1) return;
+    Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
+    invokeOnElement(project, editor, elements[0]);
+  }
+
+  private static void invoke(final PsiMethod method, final Project project, @Nullable final Editor editor) {
+    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, method)) return;
+
+    PsiMethod newMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
+    if (newMethod == null) return;
+
+    if (!newMethod.equals(method)) {
+      invoke(newMethod, project, editor);
+      return;
+    }
+
+    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, method)) return;
+
+    final PsiClass containingClass = method.getContainingClass();
+    final PsiReference refExpr = editor != null ? TargetElementUtil.findReference(editor) : null;
+    if (!(method instanceof GrMethod)) return; //todo
+    final GrChangeSignatureDialog dialog = new GrChangeSignatureDialog(project, (GrMethod)method);
+    dialog.show();
+  }
+
+  @Nullable
+  public PsiMethod findTargetMember(PsiFile file, Editor editor) {
+    final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
+    final GrParameterList parameterList = PsiTreeUtil.getParentOfType(element, GrParameterList.class);
+    if (parameterList != null) {
+      final PsiElement parent = parameterList.getParent();
+      if (parent instanceof PsiMethod) return (PsiMethod)parent;
+    }
+    final GrMethodCallExpression expression = PsiTreeUtil.getParentOfType(element, GrMethodCallExpression.class);
+    if (expression == null) return null;
+    return expression.resolveMethod();
+  }
+}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureProcessor.java
new file mode 100644 (file)
index 0000000..6fd842d
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.refactoring.changeSignature;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Ref;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiMethod;
+import com.intellij.psi.PsiReference;
+import com.intellij.psi.search.searches.MethodReferencesSearch;
+import com.intellij.refactoring.BaseRefactoringProcessor;
+import com.intellij.refactoring.changeSignature.ChangeInfo;
+import com.intellij.refactoring.changeSignature.ChangeSignatureViewDescriptor;
+import com.intellij.refactoring.changeSignature.ParameterInfo;
+import com.intellij.refactoring.util.CanonicalTypes;
+import com.intellij.usageView.UsageInfo;
+import com.intellij.usageView.UsageViewDescriptor;
+import com.intellij.util.containers.MultiMap;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Maxim.Medvedev
+ */
+public class GrChangeSignatureProcessor extends BaseRefactoringProcessor {
+  private final GrChangeInfoImpl myInfo;
+
+  //private
+
+  public GrChangeSignatureProcessor(Project project, GrChangeInfoImpl changeInfo) {
+    super(project);
+    myInfo = changeInfo;
+  }
+
+  @Override
+  protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) {
+    return new ChangeSignatureViewDescriptor(myInfo.getMethod());
+  }
+
+  @NotNull
+  @Override
+  protected UsageInfo[] findUsages() {
+    final Collection<PsiReference> collection = MethodReferencesSearch.search(myInfo.getMethod()).findAll();
+    return new UsageInfo[0];  //To change body of implemented methods use File | Settings | File Templates.
+  }
+
+  @Override
+  protected void refreshElements(PsiElement[] elements) {
+    //To change body of implemented methods use File | Settings | File Templates.
+  }
+
+  @Override
+  protected void performRefactoring(UsageInfo[] usages) {
+    changeMethod();
+  }
+
+  private void changeMethod() {
+    final PsiMethod method = myInfo.getMethod();
+    if (myInfo.isChangeName()) {
+      method.setName(myInfo.getNewName());
+    }
+
+    if (myInfo.isChangeVisibility()) {
+      method.getModifierList().setModifierProperty(myInfo.getVisibilityModifier(), true);
+    }
+  }
+
+  @Override
+  protected String getCommandName() {
+    return "";
+    //return RefactoringBundle.message("changing.signature.of.0", UsageViewUtil.getDescriptiveName(myInfo.getMethod()));
+  }
+
+
+  private MultiMap<PsiElement, String> findConflicts(Ref<UsageInfo[]> refUsages) {
+    return new MultiMap<PsiElement, String>();//todo
+  }
+
+  @Override
+  protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
+    return showConflicts(findConflicts(refUsages));
+  }
+
+  static class GrChangeInfoImpl implements ChangeInfo {
+    private GrMethod myMethod;
+    private String myNewName;
+    private CanonicalTypes.Type myReturnType;
+    private String myVisibilityModifier;
+    private List<GrParameterInfo> myParameters;
+    private boolean myChangeParameters = false;
+
+    public GrChangeInfoImpl(GrMethod method,
+                             String visibilityModifier,
+                             CanonicalTypes.Type returnType,
+                             String newName,
+                             List<GrParameterInfo> parameters) {
+      myMethod = method;
+      myVisibilityModifier = visibilityModifier;
+      myReturnType = returnType;
+      myParameters = parameters;
+      myNewName = newName;
+
+      final int oldParameterCount = myMethod.getParameters().length;
+      if (oldParameterCount != myParameters.size()) {
+        myChangeParameters = true;
+      }
+
+      for (int i = 0, parametersSize = parameters.size(); i < parametersSize; i++) {
+        GrParameterInfo parameter = parameters.get(i);
+        if (parameter.getOldIndex() != i) {
+          myChangeParameters = true;
+        }
+      }
+    }
+
+    @NotNull
+    public ParameterInfo[] getNewParameters() {
+      return myParameters.toArray(new GrParameterInfo[myParameters.size()]);
+    }
+
+    public boolean isParameterSetOrOrderChanged() {
+      return myChangeParameters;
+    }
+
+    public PsiMethod getMethod() {
+      return myMethod;
+    }
+
+    public boolean isChangeVisibility() {
+      return !myMethod.getModifierList().hasModifierProperty(myVisibilityModifier);
+    }
+
+    public boolean isChangeName() {
+      return !myMethod.getName().equals(myNewName);
+    }
+
+    public String getNewName() {
+      return myNewName;
+    }
+
+    public String getVisibilityModifier() {
+      return myVisibilityModifier;
+    }
+  }
+}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterInfo.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterInfo.java
new file mode 100644 (file)
index 0000000..781a625
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.refactoring.changeSignature;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.JavaPsiFacade;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiType;
+import com.intellij.psi.PsiTypeCodeFragment;
+import com.intellij.refactoring.changeSignature.ParameterInfo;
+import org.jetbrains.plugins.groovy.debugger.fragments.GroovyCodeFragment;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
+
+/**
+ * @author Maxim.Medvedev
+ */
+public class GrParameterInfo implements ParameterInfo {
+  private GroovyCodeFragment myName;
+  private GroovyCodeFragment myDefaultValue;
+  private PsiTypeCodeFragment myType;
+  private GroovyCodeFragment myDefaultInitializer;
+  private final int myPosition;
+
+  public GrParameterInfo(GrParameter parameter, int position) {
+    myPosition = position;
+    final Project project = parameter.getProject();
+    myName = new GroovyCodeFragment(project, parameter.getName());
+    final PsiType type = parameter.getDeclaredType();
+    if (type != null) {
+      myType = JavaPsiFacade.getElementFactory(project).createTypeCodeFragment(type.getCanonicalText(), parameter, true, true);
+    }
+    else {
+      myType = JavaPsiFacade.getElementFactory(project).createTypeCodeFragment("", parameter, true, true);
+    }
+    final GrExpression defaultInitializer = parameter.getDefaultInitializer();
+    if (defaultInitializer != null) {
+      myDefaultInitializer = new GroovyCodeFragment(project, defaultInitializer.getText());
+    }
+    else {
+      myDefaultInitializer = new GroovyCodeFragment(project, "");
+    }
+    myDefaultValue = new GroovyCodeFragment(project, "");
+  }
+
+  public GrParameterInfo(Project project, PsiElement context) {
+    this.myPosition = -1;
+    myName = new GroovyCodeFragment(project, "");
+    myDefaultValue = new GroovyCodeFragment(project, "");
+    myType = JavaPsiFacade.getElementFactory(project).createTypeCodeFragment("", context, true, true);
+    myDefaultInitializer = new GroovyCodeFragment(project, "");
+  }
+
+  public GroovyCodeFragment getNameFragment() {
+    return myName;
+  }
+
+  public GroovyCodeFragment getDefaultValueFragment() {
+    return myDefaultValue;
+  }
+
+  public PsiTypeCodeFragment getTypeFragment() {
+    return myType;
+  }
+
+  public GroovyCodeFragment getDefaultInitializer() {
+    return myDefaultInitializer;
+  }
+
+  public String getName() {
+    return myName.getText().trim();
+  }
+
+  public int getOldIndex() {
+    return myPosition;
+  }
+
+  public String getDefaultValue() {
+    return myDefaultValue.getText().trim();
+  }
+}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterTableModel.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterTableModel.java
new file mode 100644 (file)
index 0000000..14086ba
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.refactoring.changeSignature;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiCodeFragment;
+import com.intellij.ui.RowEditableTableModel;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.groovy.debugger.fragments.GroovyCodeFragment;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
+import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringBundle;
+
+import javax.swing.table.AbstractTableModel;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Maxim.Medvedev
+ */
+public class GrParameterTableModel extends AbstractTableModel implements RowEditableTableModel {
+  private final List<GrParameterInfo> infos;
+  private final GrMethod myMethod;
+  private final GrChangeSignatureDialog myDialog;
+  private final Project myProject;
+
+  public GrParameterTableModel(GrMethod method, GrChangeSignatureDialog dialog, Project project) {
+    myMethod = method;
+    myDialog = dialog;
+    final GrParameter[] parameters = myMethod.getParameters();
+    infos = new ArrayList<GrParameterInfo>(parameters.length);
+    for (int i = 0; i < parameters.length; i++) {
+      GrParameter parameter = parameters[i];
+      infos.add(new GrParameterInfo(parameter, i));
+    }
+    myProject = project;
+  }
+
+  public void addRow() {
+    final int row = infos.size();
+    infos.add(new GrParameterInfo(myProject, myMethod));
+    fireTableRowsInserted(row, row);
+  }
+
+  public void removeRow(int index) {
+    infos.remove(index);
+    fireTableRowsDeleted(index, index);
+  }
+
+  public void exchangeRows(int index1, int index2) {
+    final GrParameterInfo info = infos.get(index1);
+    infos.set(index1, infos.get(index2));
+    infos.set(index2, info);
+    fireTableRowsUpdated(Math.min(index1, index2), Math.max(index1, index2));
+  }
+
+
+  public int getRowCount() {
+    return infos.size();
+  }
+
+  public int getColumnCount() {
+    return 4;
+  }
+
+  @Nullable
+  public Object getValueAt(int rowIndex, int columnIndex) {
+    if (rowIndex < 0 || rowIndex >= infos.size()) return null;
+    final GrParameterInfo info = infos.get(rowIndex);
+    switch (columnIndex) {
+      case 0:
+        return info.getTypeFragment();
+      case 1:
+        return info.getNameFragment();
+      case 2:
+        return info.getDefaultInitializer();
+      case 3:
+        return info.getDefaultValueFragment();
+      default:
+        throw new IllegalArgumentException();
+    }
+  }
+
+  @Override
+  public void setValueAt(Object value, int rowIndex, int columnIndex) {
+    if (rowIndex < 0 || rowIndex >= infos.size()) return;
+    if (columnIndex < 0 || columnIndex > 3) return;
+    /*String s = value instanceof String ? (String)value : "";
+    s = s.trim();
+    final GrParameterInfo info = infos.get(rowIndex);
+    switch (columnIndex) {
+      case 0:
+        info.setType(s);
+      case 1:
+        info.setName(s);
+      case 2:
+        info.setDefaultInitializer(s);
+      case 3:
+        info.setDefaultValue(s);
+    }*/
+    fireTableCellUpdated(rowIndex, columnIndex);
+  }
+
+
+  @Override
+  public String getColumnName(int column) {
+    switch (column) {
+      case 0:
+        return GroovyRefactoringBundle.message("column.name.type");
+      case 1:
+        return GroovyRefactoringBundle.message("column.name.name");
+      case 2:
+        return GroovyRefactoringBundle.message("column.name.default.initializer");
+      case 3:
+        return GroovyRefactoringBundle.message("column.name.default.value");
+      default:
+        throw new IllegalArgumentException();
+    }
+  }
+
+  @Override
+  public Class<?> getColumnClass(int columnIndex) {
+    switch (columnIndex) {
+      case 0:
+        return PsiCodeFragment.class;
+      case 1:
+      case 2:
+      case 3:
+        return GroovyCodeFragment.class;
+      default:
+        throw new IllegalArgumentException();
+    }
+  }
+
+  @Override
+  public boolean isCellEditable(int rowIndex, int columnIndex) {
+    return true;
+  }
+
+  public List<GrParameterInfo> getParameterInfos() {
+    return infos;
+  }
+}
\ No newline at end of file
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/ui/GrCodeFragmentTableCellEditor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/ui/GrCodeFragmentTableCellEditor.java
new file mode 100644 (file)
index 0000000..b14f9b1
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.refactoring.ui;
+
+import com.intellij.codeInsight.daemon.impl.JavaReferenceImporter;
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiDocumentManager;
+import com.intellij.ui.EditorTextField;
+import org.jetbrains.plugins.groovy.GroovyFileType;
+import org.jetbrains.plugins.groovy.debugger.fragments.GroovyCodeFragment;
+
+import javax.swing.*;
+import javax.swing.table.TableCellEditor;
+import java.awt.*;
+
+/**
+ * @author Maxim.Medvedev
+ */
+public class GrCodeFragmentTableCellEditor extends AbstractCellEditor implements TableCellEditor {
+  private GroovyCodeFragment myCodeFragment;
+  private Document myDocument;
+  private Project myProject;
+  private EditorTextField myEditorTextField;
+
+  public GrCodeFragmentTableCellEditor(Project project) {
+    myProject = project;
+  }
+
+  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
+    myCodeFragment = (GroovyCodeFragment)value;
+
+    myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myCodeFragment);
+    myEditorTextField = new EditorTextField(myDocument, myProject, GroovyFileType.GROOVY_FILE_TYPE) {
+      protected boolean shouldHaveBorder() {
+        return false;
+      }
+    };
+    return myEditorTextField;
+  }
+
+  public Object getCellEditorValue() {
+    return myCodeFragment;
+  }
+
+  @Override
+  public boolean stopCellEditing() {
+    final Editor editor = myEditorTextField.getEditor();
+    if (editor != null) {
+      JavaReferenceImporter.autoImportReferenceAtCursor(editor, myCodeFragment, true);
+    }
+    super.stopCellEditing();
+    PsiDocumentManager.getInstance(myProject).commitDocument(myDocument);
+    return true;
+  }
+}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/ui/GrCodeFragmentTableCellRenderer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/ui/GrCodeFragmentTableCellRenderer.java
new file mode 100644 (file)
index 0000000..6b56982
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.refactoring.ui;
+
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiCodeFragment;
+import com.intellij.psi.PsiDocumentManager;
+import com.intellij.ui.EditorTextField;
+import org.jetbrains.plugins.groovy.GroovyFileType;
+import org.jetbrains.plugins.groovy.debugger.fragments.GroovyCodeFragment;
+
+import javax.swing.*;
+import javax.swing.table.TableCellRenderer;
+import java.awt.*;
+
+/**
+ * @author Maxim.Medvedev
+ */
+public class GrCodeFragmentTableCellRenderer implements TableCellRenderer {
+  private final Project myProject;
+
+  public GrCodeFragmentTableCellRenderer(Project project) {
+    myProject = project;
+  }
+
+  public Component getTableCellRendererComponent(JTable table,
+                                                 Object value,
+                                                 boolean isSelected,
+                                                 final boolean hasFocus,
+                                                 int row,
+                                                 int column) {
+    PsiCodeFragment codeFragment = (GroovyCodeFragment)value;
+
+    final EditorTextField editorTextField;
+    if (codeFragment != null) {
+      Document document = PsiDocumentManager.getInstance(myProject).getDocument(codeFragment);
+      editorTextField = new EditorTextField(document, myProject, GroovyFileType.GROOVY_FILE_TYPE) {
+        protected boolean shouldHaveBorder() {
+          return false;
+        }
+      };
+    }
+    else {
+      editorTextField = new EditorTextField("", myProject, GroovyFileType.GROOVY_FILE_TYPE) {
+        protected boolean shouldHaveBorder() {
+          return false;
+        }
+      };
+    }
+    editorTextField.setBorder(hasFocus ? BorderFactory.createLineBorder(table.getForeground()) : null);
+    return editorTextField;
+  }
+}