change signature: setup default type value as default type; setup selection
authoranna <Anna.Kozlova@jetbrains.com>
Tue, 14 Sep 2010 16:29:47 +0000 (20:29 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Wed, 15 Sep 2010 11:53:37 +0000 (15:53 +0400)
java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureUsageProcessor.java
platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.form
platform/lang-impl/src/com/intellij/refactoring/changeSignature/DefaultValueChooser.java

index 60e76508a167024c067eb0f526bd4a7fec9fb3b2..b878b76f45ade05e985d1288d4f1c1aca43fe991 100644 (file)
@@ -28,10 +28,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
 import com.intellij.psi.codeStyle.VariableKind;
 import com.intellij.psi.scope.processor.VariablesProcessor;
 import com.intellij.psi.scope.util.PsiScopesUtil;
-import com.intellij.psi.util.MethodSignatureUtil;
-import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.psi.util.PsiUtil;
-import com.intellij.psi.util.TypeConversionUtil;
+import com.intellij.psi.util.*;
 import com.intellij.refactoring.RefactoringBundle;
 import com.intellij.refactoring.rename.RenameUtil;
 import com.intellij.refactoring.util.*;
@@ -542,7 +539,9 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
       if (usageInfo instanceof  MethodCallUsageInfo) {
         MethodCallUsageInfo methodCallUsageInfo = (MethodCallUsageInfo)usageInfo;
         if (methodCallUsageInfo.isToChangeArguments()){
-          final boolean needDefaultValue = needDefaultValue(changeInfo, RefactoringUtil.getEnclosingMethod(methodCallUsageInfo.getElement()));
+          final PsiElement element = methodCallUsageInfo.getElement();
+          if (element == null) continue;
+          final boolean needDefaultValue = needDefaultValue(changeInfo, RefactoringUtil.getEnclosingMethod(element));
           if (needDefaultValue) {
             final ParameterInfo[] parameters = changeInfo.getNewParameters();
             for (ParameterInfo parameter : parameters) {
@@ -550,7 +549,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
               if (defaultValue == null && parameter.getOldIndex() == -1) {
                 ((ParameterInfoImpl)parameter).setDefaultValue("");
                 if (!ApplicationManager.getApplication().isUnitTestMode()) {
-                  final DefaultValueChooser chooser = new DefaultValueChooser(project, parameter.getName());
+                  final PsiType type = ((ParameterInfoImpl)parameter).getTypeWrapper().getType(element, element.getManager());
+                  final DefaultValueChooser chooser = new DefaultValueChooser(project, parameter.getName(), PsiTypesUtil.getDefaultValueOfType(type));
                   chooser.show();
                   if (chooser.isOK()) {
                     if (chooser.feelLucky()) {
index 3ba0c32c2a0cef3a1aa601c5649be6fe3052b883..f12544a32d5ffd9729140b536aec4f786a2df793 100644 (file)
@@ -2,7 +2,7 @@
 <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"/>
+      <xy x="258" y="615" width="592" height="231"/>
     </constraints>
     <properties/>
     <border type="none"/>
@@ -72,7 +72,9 @@
           <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/>
+        <properties>
+          <minimumSize width="10" height="24"/>
+        </properties>
       </component>
     </children>
   </grid>
index 56e1dbce8074801c495d7e11ca9a22dadca41cce..62a2d2bc1cc2d0fb1b65bc84cfa3e39e0daf76b8 100644 (file)
@@ -38,13 +38,17 @@ public class DefaultValueChooser extends DialogWrapper{
   private JPanel myWholePanel;
   private JLabel myBlankDescription;
 
-  public DefaultValueChooser(Project project, String name) {
+  public DefaultValueChooser(Project project, String name, String defaultValue) {
     super(project);
     new RadioUpDownListener(myLeaveBlankRadioButton, myFeelLuckyRadioButton, myUseValueRadioButton);
     final ActionListener actionListener = new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent e) {
         myValueEditor.setEnabled(myUseValueRadioButton.isSelected());
+        if (myUseValueRadioButton.isSelected()) {
+          myValueEditor.selectAll();
+          myValueEditor.requestFocus();
+        }
       }
     };
     myLeaveBlankRadioButton.addActionListener(actionListener);
@@ -58,6 +62,7 @@ public class DefaultValueChooser extends DialogWrapper{
                                    "Blank place would be used otherwise");
     myFeelLuckyDescription.setUI(new MultiLineLabelUI());
     myBlankDescription.setUI(new MultiLineLabelUI());
+    myValueEditor.setText(defaultValue);
     init();
   }