change signature: do not show dialog
authoranna <Anna.Kozlova@jetbrains.com>
Tue, 14 Sep 2010 11:03:39 +0000 (15:03 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Wed, 15 Sep 2010 11:53:07 +0000 (15:53 +0400)
13 files changed:
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureUtil.java
java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDetector.java
java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java
java/java-impl/src/com/intellij/refactoring/changeSignature/ParameterInfoImpl.java
java/java-tests/testData/refactoring/changeSignatureGesture/NewParamInSuperUsed_after.java
platform/lang-api/src/com/intellij/refactoring/changeSignature/ChangeSignatureUsageProcessor.java
platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDetectorAction.java
platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureGestureDetector.java
platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.form [new file with mode: 0644]
platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java [new file with mode: 0644]
platform/platform-resources-en/src/messages/RefactoringBundle.properties
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureUsageProcessor.java

index 2eaf2abea66465bd8583aaab43135643fdf5597a..3f31c68e55bead30e652ee3edb2e7db852bafa70 100644 (file)
@@ -130,6 +130,9 @@ public class ChangeSignatureProcessor extends ChangeSignatureProcessorBase {
   }
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
+    for (ChangeSignatureUsageProcessor processor : ChangeSignatureUsageProcessor.EP_NAME.getExtensions()) {
+      processor.setupDefaultValues(myChangeInfo, refUsages, myProject);
+    }
     MultiMap<PsiElement, String> conflictDescriptions = new MultiMap<PsiElement, String>();
     for (ChangeSignatureUsageProcessor usageProcessor : ChangeSignatureUsageProcessor.EP_NAME.getExtensions()) {
       final MultiMap<PsiElement, String> conflicts = usageProcessor.findConflicts(myChangeInfo, refUsages);
index 96275d137b803f54c2b8c07ec817931631c6b848..f23cabd6143b1ce44dfd1626cbe6ad549cbc7b26 100644 (file)
  */
 package com.intellij.refactoring.changeSignature;
 
+import com.intellij.psi.JavaTokenType;
 import com.intellij.psi.PsiElement;
+import com.intellij.psi.impl.source.tree.Factory;
+import com.intellij.psi.impl.source.tree.SharedImplUtil;
 import com.intellij.psi.util.PsiUtilBase;
 import com.intellij.util.IncorrectOperationException;
 
@@ -54,18 +57,35 @@ public class ChangeSignatureUtil {
 
       Child oldElement = index < elements.size() ? elements.get(index) : null;
       Child newElement = newElements.get(index);
-      if (!newElement.equals(oldElement)) {
-        if (oldElement != null && elementsToRemove.contains(oldElement)) {
-          oldElement.delete();
-          index--;
-        }
-        else {
-          assert list.isWritable() : PsiUtilBase.getVirtualFile(list);
-          list.addBefore(newElement, oldElement);
-          if (list.equals(newElement.getParent())) {
-            newElement.delete();
+      if (newElement != null) {
+        if (!newElement.equals(oldElement)) {
+          if (oldElement != null && elementsToRemove.contains(oldElement)) {
+            oldElement.delete();
+            index--;
+          }
+          else {
+            assert list.isWritable() : PsiUtilBase.getVirtualFile(list);
+            list.addBefore(newElement, oldElement);
+            if (list.equals(newElement.getParent())) {
+              newElement.delete();
+            }
           }
         }
+      } else {
+        PsiElement anchor = null;
+        if (index == 0) {
+          anchor = list.getFirstChild();
+        } else {
+          anchor = elements.get(index - 1);
+        }
+        final PsiElement psi = Factory
+          .createSingleLeafElement(JavaTokenType.COMMA, ",", 0, 1, SharedImplUtil.findCharTableByTree(list.getNode()), list.getManager())
+          .getPsi();
+        if (anchor != null) {
+          list.addAfter(psi, anchor);
+        } else {
+          list.add(psi);
+        }
       }
       index++;
     }
index c9102b3fb4c4d78fa75f184610e0dc82cc30912f..7ccbc8f6cb37de5ae1f16c537dd210609b22d628 100644 (file)
@@ -17,7 +17,6 @@ package com.intellij.refactoring.changeSignature;
 
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.Result;
-import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.command.WriteCommandAction;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
@@ -26,16 +25,13 @@ import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.psi.*;
 import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.refactoring.BaseRefactoringProcessor;
-import com.intellij.refactoring.RefactoringBundle;
 import com.intellij.refactoring.util.CanonicalTypes;
-import com.intellij.usageView.UsageViewUtil;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.VisibilityUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.HashSet;
+import java.util.*;
 
 /**
  * User: anna
@@ -68,29 +64,7 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
         final MyJavaChangeInfo info = (MyJavaChangeInfo)changeInfo;
         if (!info.getMethod().equals(method)) return null;
         if (!info.equals(fromMethod)) {
-          final JavaParameterInfo[] oldParameters = info.getNewParameters();
-          for (int i = 0; i < parameterInfos.length; i++) {
-            ParameterInfoImpl parameterInfo = parameterInfos[i];
-            JavaParameterInfo oldParameter = null;
-            for (JavaParameterInfo parameter : oldParameters) {
-              if (Comparing.strEqual(parameter.getName(), parameterInfo.getName()) &&
-                  Comparing.strEqual(parameter.getTypeText(), parameterInfo.getTypeText())) {
-                oldParameter = parameter;
-                break;
-              }
-            }
-            if (oldParameter == null && oldParameters.length > i && info.getOldParameterNames().length > i) {
-              if (Comparing.strEqual(info.getOldParameterNames()[i], parameterInfo.getName()) ||
-                  Comparing.strEqual(info.getOldParameterTypes()[i], parameterInfo.getTypeText())) {
-                oldParameter = oldParameters[i];
-              }
-            }
-            final int oldParameterIndex = oldParameter != null ? oldParameter.getOldIndex() : -1;
-            parameterInfos[i] = new ParameterInfoImpl(oldParameterIndex,
-                                                      parameterInfo.getName(),
-                                                      parameterInfo.getTypeWrapper().getType(element, element.getManager()),
-                                                      oldParameterIndex == -1 ? "intellijidearulezzz" : "");
-          }
+          createParametersInfo(element, parameterInfos, info);
           if (info.isReturnTypeChanged()) {
             final String visibility = info.getNewVisibility();
             if (Comparing.strEqual(visibility, PsiModifier.PRIVATE) &&
@@ -123,11 +97,61 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
           javaChangeInfo.setSuperMethod(info.getSuperMethod());
           return javaChangeInfo;
         }
+        return changeInfo;
       }
     }
     return null;
   }
 
+  private static void createParametersInfo(PsiElement element,
+                                           ParameterInfoImpl[] parameterInfos,
+                                           MyJavaChangeInfo info) {
+
+    final JavaParameterInfo[] oldParameters = info.getNewParameters();
+    final String[] oldParameterNames = info.getOldParameterNames();
+    final String[] oldParameterTypes =  info.getOldParameterTypes();
+    final Map<JavaParameterInfo, Integer> untouchedParams = new HashMap<JavaParameterInfo, Integer>();
+    for (int i = 0; i < parameterInfos.length; i++) {
+      ParameterInfoImpl parameterInfo = parameterInfos[i];
+      JavaParameterInfo oldParameter = null;
+      for (JavaParameterInfo parameter : oldParameters) {
+        if (Comparing.strEqual(parameter.getName(), parameterInfo.getName()) &&
+            Comparing.strEqual(parameter.getTypeText(), parameterInfo.getTypeText())) {
+          oldParameter = parameter;
+          break;
+        }
+      }
+
+      if (oldParameter != null) {
+        parameterInfos[i] = new ParameterInfoImpl(oldParameter.getOldIndex(),
+                                                  oldParameter.getName(),
+                                                  oldParameter.getTypeWrapper().getType(element, element.getManager()),
+                                                  null);
+        untouchedParams.put(parameterInfos[i], oldParameter.getOldIndex());
+      }
+    }
+
+    for (int i = 0; i < parameterInfos.length; i++) {
+      ParameterInfoImpl parameterInfo = parameterInfos[i];
+      if (!untouchedParams.containsKey(parameterInfo)) {
+        JavaParameterInfo oldParameter = null;
+        if (oldParameters.length > i && oldParameterNames.length > i) {
+          if (Comparing.strEqual(oldParameterNames[i], parameterInfo.getName()) ||
+              Comparing.strEqual(oldParameterTypes[i], parameterInfo.getTypeText())) {
+            if (!untouchedParams.containsValue(oldParameters[i].getOldIndex())) {
+              oldParameter = oldParameters[i];
+            }
+          }
+        }
+        parameterInfos[i] = new ParameterInfoImpl(oldParameter != null ? oldParameter.getOldIndex() : - 1,
+                                                  parameterInfo.getName(),
+                                                  parameterInfo.getTypeWrapper().getType(element, element.getManager()),
+                                                  null);
+      }
+    }
+  }
+
+
   private static class MyJavaChangeInfo extends JavaChangeInfoImpl  {
     private PsiMethod mySuperMethod;
     private MyJavaChangeInfo(String newVisibility,
@@ -164,11 +188,11 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
       final MyJavaChangeInfo info = (MyJavaChangeInfo)changeInfo;
       final PsiMethod method = info.getSuperMethod();
 
-      if (ApplicationManager.getApplication().isUnitTestMode()) {
+      //if (ApplicationManager.getApplication().isUnitTestMode()) {
         temporallyRevertChanges(method, oldText);
         createChangeSignatureProcessor(info, method).run();
         return true;
-      }
+      /*}
       final JavaChangeSignatureDialog dialog =
         new JavaChangeSignatureDialog(method.getProject(), new JavaMethodDescriptor(info.getMethod()) {
           @Override
@@ -196,7 +220,7 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
           }
         };
       dialog.show();
-      return dialog.isOK();
+      return dialog.isOK();*/
     }
     return false;
 
index 4bc0184be9a70564d630846d7eba6ab6f07bf867..60e76508a167024c067eb0f526bd4a7fec9fb3b2 100644 (file)
@@ -17,7 +17,9 @@ package com.intellij.refactoring.changeSignature;
 
 import com.intellij.codeInsight.ExceptionUtil;
 import com.intellij.lang.StdLanguages;
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Ref;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.*;
@@ -228,7 +230,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
     final PsiMethod caller = RefactoringUtil.getEnclosingMethod(ref);
     if (toChangeArguments) {
       final PsiExpressionList list = RefactoringUtil.getArgumentListByMethodReference(ref);
-      boolean toInsertDefaultValue = !(changeInfo instanceof JavaChangeInfoImpl) || !((JavaChangeInfoImpl)changeInfo).propagateParametersMethods.contains(caller);
+      boolean toInsertDefaultValue = needDefaultValue(changeInfo, caller);
       if (toInsertDefaultValue && ref instanceof PsiReferenceExpression) {
         final PsiExpression qualifierExpression = ((PsiReferenceExpression)ref).getQualifierExpression();
         if (qualifierExpression instanceof PsiSuperExpression && callerSignatureIsAboutToChangeToo(caller, usages)) {
@@ -513,7 +515,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
       }
     }
     final PsiCallExpression callExpression = PsiTreeUtil.getParentOfType(list, PsiCallExpression.class);
-    return callExpression != null ? info.getValue(callExpression) : factory.createExpressionFromText(info.getDefaultValue(), list);
+    final String defaultValue = info.getDefaultValue();
+    return callExpression != null ? info.getValue(callExpression) : defaultValue.length() > 0 ? factory.createExpressionFromText(defaultValue, list) : null;
   }
 
 
@@ -532,6 +535,44 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
     return false;
   }
 
+  @Override
+  public void setupDefaultValues(ChangeInfo changeInfo, Ref<UsageInfo[]> refUsages, Project project) {
+    if (!(changeInfo instanceof JavaChangeInfo)) return;
+    for (UsageInfo usageInfo : refUsages.get()) {
+      if (usageInfo instanceof  MethodCallUsageInfo) {
+        MethodCallUsageInfo methodCallUsageInfo = (MethodCallUsageInfo)usageInfo;
+        if (methodCallUsageInfo.isToChangeArguments()){
+          final boolean needDefaultValue = needDefaultValue(changeInfo, RefactoringUtil.getEnclosingMethod(methodCallUsageInfo.getElement()));
+          if (needDefaultValue) {
+            final ParameterInfo[] parameters = changeInfo.getNewParameters();
+            for (ParameterInfo parameter : parameters) {
+              final String defaultValue = parameter.getDefaultValue();
+              if (defaultValue == null && parameter.getOldIndex() == -1) {
+                ((ParameterInfoImpl)parameter).setDefaultValue("");
+                if (!ApplicationManager.getApplication().isUnitTestMode()) {
+                  final DefaultValueChooser chooser = new DefaultValueChooser(project, parameter.getName());
+                  chooser.show();
+                  if (chooser.isOK()) {
+                    if (chooser.feelLucky()) {
+                      parameter.setUseAnySingleVariable(true);
+                    } else {
+                      ((ParameterInfoImpl)parameter).setDefaultValue(chooser.getDefaultValue());
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+
+  private static boolean needDefaultValue(ChangeInfo changeInfo, PsiMethod method) {
+    return !(changeInfo instanceof JavaChangeInfoImpl) ||
+           !((JavaChangeInfoImpl)changeInfo).propagateParametersMethods.contains(method);
+  }
+
   private static void generateDelegate(JavaChangeInfo changeInfo) throws IncorrectOperationException {
     final PsiMethod delegate = (PsiMethod)changeInfo.getMethod().copy();
     final PsiClass targetClass = changeInfo.getMethod().getContainingClass();
index 7f8aad2f12d55ecc110da2b80331c7f477603251..d5ecd31c44f19e9b5e4fbaf022ffbe7ddd8dcc9d 100644 (file)
@@ -145,6 +145,7 @@ public class ParameterInfoImpl implements JavaParameterInfo {
 
   @Nullable
   public PsiExpression getValue(final PsiCallExpression expr) throws IncorrectOperationException {
+    if (defaultValue != null && defaultValue.length() == 0) return null;
     return JavaPsiFacade.getInstance(expr.getProject()).getElementFactory().createExpressionFromText(defaultValue, expr);
   }
 
index e899bd939bec5a19a18ac2367170523f73bd844e..bef49981f717b7291135458d7e6bc3e5bdcd2a62 100644 (file)
@@ -9,6 +9,6 @@ class Child extends Parent {
   }
 
   void bar() {
-    foo(1,intellijidearulezzz);
+    foo(1,);
   }
 }
\ No newline at end of file
index 240c05f885f846a37c0704bbd30994635953d8d6..a798a1e96d2501c1124111549e02e20f114da762 100644 (file)
@@ -16,6 +16,7 @@
 package com.intellij.refactoring.changeSignature;
 
 import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Ref;
 import com.intellij.psi.PsiElement;
 import com.intellij.usageView.UsageInfo;
@@ -37,4 +38,6 @@ public interface ChangeSignatureUsageProcessor {
   boolean processPrimaryMethod(ChangeInfo changeInfo);
 
   boolean shouldPreviewUsages(ChangeInfo changeInfo, UsageInfo[] usages);
+
+  void setupDefaultValues(ChangeInfo changeInfo, Ref<UsageInfo[]> refUsages, Project project);
 }
index 531aca65ed405c8d48c3087c01217a8fb20a5449..a587700673cfea21d5caa102339df298e506ec9e 100644 (file)
@@ -44,7 +44,7 @@ public class ChangeSignatureDetectorAction implements IntentionAction {
 
   @Override
   public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
-    return true;
+    return ChangeSignatureGestureDetector.getInstance(project).containsChangeSignatureChange(file);
   }
 
   @Override
index a350fd739b122352278f9ecdf54f008c2190a429..07920f8f02ff35f9b16e990e53d20824f412f52e 100644 (file)
@@ -74,8 +74,7 @@ public class ChangeSignatureGestureDetector extends PsiTreeChangeAdapter impleme
       final ChangeInfo currentInfo = changeBean.getCurrentInfo();
       final LanguageChangeSignatureDetector detector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(currentInfo.getLanguage());
       if (detector.showDialog(currentInfo, changeBean.getInitialText())) {
-        changeBean.setInitialText(null);
-        changeBean.setCurrentInfo(null);
+        changeBean.reinit();
       }
     }
     finally {
@@ -139,10 +138,11 @@ public class ChangeSignatureGestureDetector extends PsiTreeChangeAdapter impleme
     if (file != null) {
       final MyDocumentChangeAdapter changeBean = myListenerMap.get(file);
       if (changeBean != null && changeBean.getInitialText() != null) {
-        final ChangeInfo info = LanguageChangeSignatureDetectors.createCurrentChangeInfo(child, changeBean.getCurrentInfo());
-        changeBean.setCurrentInfo(info);
+        final ChangeInfo info = LanguageChangeSignatureDetectors.createCurrentChangeInfo(child, changeBean.getInitialChangeInfo());
         if (info == null) {
-          changeBean.setInitialText(null);
+          changeBean.reinit();
+        } else if (!info.equals(changeBean.getInitialChangeInfo())) {
+          changeBean.setCurrentInfo(info);
         }
       }
     }
@@ -179,13 +179,13 @@ public class ChangeSignatureGestureDetector extends PsiTreeChangeAdapter impleme
     final MyDocumentChangeAdapter adapter = myListenerMap.get(file);
     if (adapter != null) {
       adapter.setBannedChangeInfo(adapter.getCurrentInfo());
-      adapter.setCurrentInfo(null);
-      adapter.setInitialText(null);
+      adapter.reinit();
     }
   }
 
   private class MyDocumentChangeAdapter extends DocumentAdapter {
     private String myInitialText;
+    private ChangeInfo myInitialChangeInfo;
     private ChangeInfo myCurrentInfo;
     private ChangeInfo myBannedChangeInfo;
 
@@ -229,7 +229,7 @@ public class ChangeSignatureGestureDetector extends PsiTreeChangeAdapter impleme
               final ChangeInfo info = LanguageChangeSignatureDetectors.createCurrentChangeInfo(element, myCurrentInfo);
               if (info != null) {
                 myInitialText = document.getText();
-                myCurrentInfo = info;
+                myInitialChangeInfo = info;
               }
             }
           }
@@ -237,9 +237,19 @@ public class ChangeSignatureGestureDetector extends PsiTreeChangeAdapter impleme
       }
     }
 
+    public ChangeInfo getInitialChangeInfo() {
+      return myInitialChangeInfo;
+    }
+
     public void setBannedChangeInfo(ChangeInfo bannedChangeInfo) {
       myBannedChangeInfo = bannedChangeInfo;
     }
+
+    public void reinit() {
+      myInitialText = null;
+      myInitialChangeInfo = null;
+      myCurrentInfo = null;
+    }
   }
 
 }
diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.form b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.form
new file mode 100644 (file)
index 0000000..3ba0c32
--- /dev/null
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.refactoring.changeSignature.DefaultValueChooser">
+  <grid id="27dc6" binding="myWholePanel" layout-manager="GridBagLayout">
+    <constraints>
+      <xy x="8" y="296" width="898" height="428"/>
+    </constraints>
+    <properties/>
+    <border type="none"/>
+    <children>
+      <component id="3caee" class="javax.swing.JRadioButton" binding="myLeaveBlankRadioButton" 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"/>
+          <gridbag weightx="0.0" weighty="0.0"/>
+        </constraints>
+        <properties>
+          <font style="1"/>
+          <text resource-bundle="messages/RefactoringBundle" key="change.signature.leave.blank.default.value"/>
+        </properties>
+      </component>
+      <hspacer id="f0897">
+        <constraints>
+          <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+          <gridbag weightx="0.0" weighty="0.0"/>
+        </constraints>
+      </hspacer>
+      <vspacer id="b7f80">
+        <constraints>
+          <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+          <gridbag weightx="0.0" weighty="0.0"/>
+        </constraints>
+      </vspacer>
+      <component id="f5c81" class="javax.swing.JLabel" binding="myBlankDescription">
+        <constraints>
+          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
+          <gridbag top="0" left="20" bottom="0" right="0" weightx="0.0" weighty="0.0"/>
+        </constraints>
+        <properties>
+          <text value="In method call place blank would be inserted instead of new parameter value"/>
+        </properties>
+      </component>
+      <component id="433d4" class="javax.swing.JRadioButton" binding="myFeelLuckyRadioButton" 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"/>
+          <gridbag top="5" left="0" bottom="0" right="0" weightx="0.0" weighty="0.0"/>
+        </constraints>
+        <properties>
+          <font style="1"/>
+          <text resource-bundle="messages/RefactoringBundle" key="change.signature.feel.lucky"/>
+        </properties>
+      </component>
+      <component id="a623e" class="javax.swing.JLabel" binding="myFeelLuckyDescription">
+        <constraints>
+          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+          <gridbag top="0" left="20" bottom="0" right="0" weightx="0.0" weighty="0.0"/>
+        </constraints>
+        <properties>
+          <text value=""/>
+        </properties>
+      </component>
+      <component id="fd524" class="javax.swing.JRadioButton" binding="myUseValueRadioButton" default-binding="true">
+        <constraints>
+          <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+          <gridbag top="5" left="0" bottom="0" right="0" weightx="0.0" weighty="0.0"/>
+        </constraints>
+        <properties>
+          <font style="1"/>
+          <text resource-bundle="messages/RefactoringBundle" key="change.signature.use.selected.value"/>
+        </properties>
+      </component>
+      <component id="10901" class="com.intellij.ui.EditorTextField" binding="myValueEditor">
+        <constraints>
+          <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+          <gridbag top="0" left="20" bottom="0" right="0" weightx="1.0" weighty="0.0"/>
+        </constraints>
+        <properties/>
+      </component>
+    </children>
+  </grid>
+  <buttonGroups>
+    <group name="buttonGroup1">
+      <member id="3caee"/>
+      <member id="433d4"/>
+      <member id="fd524"/>
+    </group>
+  </buttonGroups>
+</form>
diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java
new file mode 100644 (file)
index 0000000..56e1dbc
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.openapi.ui.MultiLineLabelUI;
+import com.intellij.refactoring.util.RadioUpDownListener;
+import com.intellij.ui.EditorTextField;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * User: anna
+ * Date: Sep 13, 2010
+ */
+public class DefaultValueChooser extends DialogWrapper{
+  private JRadioButton myLeaveBlankRadioButton;
+  private JRadioButton myFeelLuckyRadioButton;
+  private JLabel myFeelLuckyDescription;
+  private JRadioButton myUseValueRadioButton;
+  private EditorTextField myValueEditor;
+  private JPanel myWholePanel;
+  private JLabel myBlankDescription;
+
+  public DefaultValueChooser(Project project, String name) {
+    super(project);
+    new RadioUpDownListener(myLeaveBlankRadioButton, myFeelLuckyRadioButton, myUseValueRadioButton);
+    final ActionListener actionListener = new ActionListener() {
+      @Override
+      public void actionPerformed(ActionEvent e) {
+        myValueEditor.setEnabled(myUseValueRadioButton.isSelected());
+      }
+    };
+    myLeaveBlankRadioButton.addActionListener(actionListener);
+    myFeelLuckyRadioButton.addActionListener(actionListener);
+    myUseValueRadioButton.addActionListener(actionListener);
+    setTitle("Default value for parameter \"" + name + "\" needed");
+    myLeaveBlankRadioButton.setSelected(true);
+    myValueEditor.setEnabled(false);
+    myFeelLuckyDescription.setText("In method call place variable of the same type would be searched.\n" +
+                                   "When exactly one is found - it would be used.\n" +
+                                   "Blank place would be used otherwise");
+    myFeelLuckyDescription.setUI(new MultiLineLabelUI());
+    myBlankDescription.setUI(new MultiLineLabelUI());
+    init();
+  }
+
+  public boolean feelLucky() {
+    return myFeelLuckyRadioButton.isSelected();
+  }
+
+
+  public String getDefaultValue() {
+    if (myLeaveBlankRadioButton.isSelected()) {
+      return "";
+    }
+    return myValueEditor.getText();
+  }
+
+  @Override
+  public JComponent getPreferredFocusedComponent() {
+    return myLeaveBlankRadioButton;
+  }
+
+  @Override
+  protected JComponent createCenterPanel() {
+    return myWholePanel;
+  }
+}
index 62c8c9b9cba36c4421d02437fb26d1f40a45def3..b259600d80bf1a5bd1a2578dad37bd51cb908f31 100644 (file)
@@ -739,3 +739,6 @@ refactoring.extract.method.dialog.parameters=Parameters:
 refactoring.extract.method.dialog.output.variables=Output variables:
 refactoring.extract.method.dialog.signature.preview=Signature preview:
 refactoring.extract.method.dialog.empty=Empty
+change.signature.leave.blank.default.value=Leave &blank
+change.signature.feel.lucky=Feel &lucky
+change.signature.use.selected.value=Use selected &value
index 39d262425a95a8afe72bf92b178ced0145afa944..c975352fff7e227700e3fa4d3ba460e701451290 100644 (file)
@@ -16,6 +16,7 @@
 package org.jetbrains.plugins.groovy.refactoring.changeSignature;
 
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.Ref;
 import com.intellij.openapi.util.text.StringUtil;
@@ -116,6 +117,10 @@ public class GrChangeSignatureUsageProcessor implements ChangeSignatureUsageProc
     return false;
   }
 
+  @Override
+  public void setupDefaultValues(ChangeInfo changeInfo, Ref<UsageInfo[]> refUsages, Project project) {
+  }
+
   private static boolean generateDelegate(GrChangeInfoImpl grInfo) {
     final GrMethod method = grInfo.getMethod();
     final PsiClass psiClass = method.getContainingClass();