IDEA-64581 Groovy: Change Signature Refactoring shouldn't use parameter's initializer as default value

This commit is contained in:
Maxim Medvedev
2011-01-26 00:30:36 +03:00
parent b476414cfc
commit aff1af7be8
3 changed files with 13 additions and 5 deletions
@@ -511,6 +511,10 @@ public class GrChangeSignatureUsageProcessor implements ChangeSignatureUsageProc
else {
if (skipOptionals && isParameterOptional(parameter)) continue;
GrExpression fromText = null;
if (forceOptional(parameter)) {
skipOptionals = true;
continue;
}
try {
fromText = factory.createExpressionFromText(parameter.getDefaultValue());
}
@@ -535,6 +539,10 @@ public class GrChangeSignatureUsageProcessor implements ChangeSignatureUsageProc
}
}
protected static boolean forceOptional(JavaParameterInfo parameter) {
return parameter instanceof GrParameterInfo && ((GrParameterInfo)parameter).forceOptional();
}
private static void fixExceptions(PsiElement element, PsiClassType[] exceptions) {
if (exceptions.length == 0) return;
final GroovyPsiElement context =
@@ -15,7 +15,6 @@
*/
package org.jetbrains.plugins.groovy.refactoring.changeSignature;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.refactoring.changeSignature.JavaParameterInfo;
import com.intellij.refactoring.util.CanonicalTypes;
@@ -37,7 +36,6 @@ public class GrParameterInfo implements JavaParameterInfo {
public GrParameterInfo(GrParameter parameter, int position) {
myPosition = position;
final Project project = parameter.getProject();
myName = parameter.getName();
final PsiType type = parameter.getDeclaredType();
if (type != null) {
@@ -82,6 +80,7 @@ public class GrParameterInfo implements JavaParameterInfo {
}
public String getDefaultValue() {
if (forceOptional()) return getDefaultInitializer();
return myDefaultValue;
}
@@ -133,6 +132,10 @@ public class GrParameterInfo implements JavaParameterInfo {
return getTypeText().length() == 0;
}
public boolean forceOptional() {
return myPosition < 0 && myDefaultValue.length() == 0;
}
/**
* for testing only
*/
@@ -119,9 +119,6 @@ public class GrTableParameterInfo {
type = null;
}
String defaultValue = getDefaultValue();
if (defaultValue.length() == 0) {
defaultValue = defaultInitializer;
}
return new GrParameterInfo(getName(), defaultValue, defaultInitializer, type, myPosition);
}
}