mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (pointless exceptions; field extracted; arrangement)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -33,11 +33,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ParameterInfoImpl implements JavaParameterInfo {
|
||||
public static final ParameterInfoImpl[] EMPTY_ARRAY = {};
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.changeSignature.ParameterInfoImpl");
|
||||
|
||||
public int oldParameterIndex;
|
||||
boolean useAnySingleVariable;
|
||||
private boolean useAnySingleVariable;
|
||||
private String name = "";
|
||||
public static final ParameterInfoImpl[] EMPTY_ARRAY = new ParameterInfoImpl[0];
|
||||
|
||||
private CanonicalTypes.Type myType;
|
||||
String defaultValue = "";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -34,407 +34,369 @@ import java.util.HashSet;
|
||||
* @author dsl
|
||||
*/
|
||||
public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
public void testSimple() throws Exception {
|
||||
private PsiElementFactory myFactory;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFactory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
}
|
||||
|
||||
public void testSimple() {
|
||||
doTest(null, null, null, new ParameterInfoImpl[0], new ThrownExceptionInfo[0], false);
|
||||
}
|
||||
|
||||
public void testParameterReorder() throws Exception {
|
||||
public void testParameterReorder() {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false);
|
||||
}
|
||||
|
||||
public void testWarnAboutContract() throws Exception {
|
||||
public void testWarnAboutContract() {
|
||||
try {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false);
|
||||
fail("Conflict expected");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException ignored) {
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException ignored) { }
|
||||
}
|
||||
|
||||
public void testGenericTypes() throws Exception {
|
||||
public void testGenericTypes() {
|
||||
doTest(null, null, "T", new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "x", factory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "y", factory.createTypeFromText("C<T>", method.getParameterList()), "null")
|
||||
new ParameterInfoImpl(-1, "x", myFactory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "y", myFactory.createTypeFromText("C<T>", method.getParameterList()), "null")
|
||||
};
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testGenericTypesInOldParameters() throws Exception {
|
||||
public void testGenericTypesInOldParameters() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
return new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(0, "t", factory.createTypeFromText("T", method), null)
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "t", myFactory.createTypeFromText("T", method), null)
|
||||
};
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testTypeParametersInMethod() throws Exception {
|
||||
public void testTypeParametersInMethod() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "t", factory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "u", factory.createTypeFromText("U", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "cu", factory.createTypeFromText("C<U>", method.getParameterList()), "null")
|
||||
};
|
||||
}
|
||||
}, false);
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "t", myFactory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "u", myFactory.createTypeFromText("U", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "cu", myFactory.createTypeFromText("C<U>", method.getParameterList()), "null")
|
||||
};
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testDefaultConstructor() throws Exception {
|
||||
public void testDefaultConstructor() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(-1, "j", PsiType.INT, "27")
|
||||
}, false);
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "j", PsiType.INT, "27")
|
||||
}, false
|
||||
);
|
||||
}
|
||||
|
||||
public void testGenerateDelegate() throws Exception {
|
||||
public void testGenerateDelegate() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "i", PsiType.INT, "27")
|
||||
}, true);
|
||||
}, true
|
||||
);
|
||||
}
|
||||
|
||||
public void testGenerateDelegateForAbstract() throws Exception {
|
||||
public void testGenerateDelegateForAbstract() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "i", PsiType.INT, "27")
|
||||
}, true);
|
||||
}, true
|
||||
);
|
||||
}
|
||||
|
||||
public void testGenerateDelegateWithReturn() throws Exception {
|
||||
public void testGenerateDelegateWithReturn() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "i", PsiType.INT, "27")
|
||||
}, true);
|
||||
}, true
|
||||
);
|
||||
}
|
||||
|
||||
public void testGenerateDelegateWithParametersReordering() throws Exception {
|
||||
public void testGenerateDelegateWithParametersReordering() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1),
|
||||
new ParameterInfoImpl(-1, "c", PsiType.CHAR, "'a'"),
|
||||
new ParameterInfoImpl(0, "j", PsiType.INT)
|
||||
}, true);
|
||||
}, true
|
||||
);
|
||||
}
|
||||
|
||||
public void testGenerateDelegateConstructor() throws Exception {
|
||||
public void testGenerateDelegateConstructor() {
|
||||
doTest(null, new ParameterInfoImpl[0], true);
|
||||
}
|
||||
|
||||
public void testGenerateDelegateDefaultConstructor() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
public void testGenerateDelegateDefaultConstructor() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "i", PsiType.INT, "27")
|
||||
}, true);
|
||||
}
|
||||
|
||||
public void testSCR40895() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
public void testSCR40895() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "y", PsiType.INT),
|
||||
new ParameterInfoImpl(1, "b", PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testJavadocGenericsLink() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(-1, "y", JavaPsiFacade.getElementFactory(getProject()).createTypeFromText("java.util.List<java.lang.String>", null)),
|
||||
public void testJavadocGenericsLink() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "y", myFactory.createTypeFromText("java.util.List<java.lang.String>", null)),
|
||||
new ParameterInfoImpl(0, "a", PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamNameSameAsFieldName() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
public void testParamNameSameAsFieldName() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "fieldName", PsiType.INT)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamNameNoConflict() throws Exception {
|
||||
public void testParamNameNoConflict() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0),
|
||||
new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadoc() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
public void testParamJavadoc() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "z", PsiType.INT),
|
||||
new ParameterInfoImpl(0, "y", PsiType.INT)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadoc0() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
public void testParamJavadoc0() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "z", PsiType.INT),
|
||||
new ParameterInfoImpl(0, "y", PsiType.INT)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadoc1() throws Exception {
|
||||
public void testParamJavadoc1() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "z", PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadoc2() throws Exception {
|
||||
public void testParamJavadoc2() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "z", PsiType.BOOLEAN),
|
||||
new ParameterInfoImpl(0, "a", PsiType.BOOLEAN),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testJavadocNoNewLineInserted() throws Exception {
|
||||
public void testJavadocNoNewLineInserted() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "newArgs", PsiType.DOUBLE),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testSuperCallFromOtherMethod() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
public void testSuperCallFromOtherMethod() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "nnn", PsiType.INT, "-222"),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testUseAnyVariable() throws Exception {
|
||||
public void testUseAnyVariable() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
|
||||
return new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(-1, "l", factory.createTypeFromText("List", method), "null", true)
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true)
|
||||
};
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testUseThisAsAnyVariable() throws Exception {
|
||||
public void testUseThisAsAnyVariable() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
|
||||
return new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(-1, "l", factory.createTypeFromText("List", method), "null", true)
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true)
|
||||
};
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testUseAnyVariableAndDefault() throws Exception {
|
||||
public void testUseAnyVariableAndDefault() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
|
||||
return new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(-1, "c", factory.createTypeFromText("C", method), "null", true)
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "c", myFactory.createTypeFromText("C", method), "null", true)
|
||||
};
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testRemoveVarargParameter() throws Exception {
|
||||
public void testRemoveVarargParameter() {
|
||||
doTest(null, null, null, new ParameterInfoImpl[]{new ParameterInfoImpl(0)}, new ThrownExceptionInfo[0], false);
|
||||
}
|
||||
|
||||
public void testEnumConstructor() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
public void testEnumConstructor() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "i", PsiType.INT, "10")
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testVarargs1() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
public void testVarargs1() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN, "true"),
|
||||
new ParameterInfoImpl(0)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testVarargs2() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
public void testVarargs2() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "i", PsiType.INT),
|
||||
new ParameterInfoImpl(0, "b", new PsiEllipsisType(PsiType.BOOLEAN))
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testCovariantReturnType() throws Exception {
|
||||
public void testCovariantReturnType() {
|
||||
doTest(CommonClassNames.JAVA_LANG_RUNNABLE, new ParameterInfoImpl[0], false);
|
||||
}
|
||||
|
||||
public void testReorderExceptions() throws Exception {
|
||||
public void testReorderExceptions() {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new SimpleExceptionsGen(new ThrownExceptionInfo[]{new JavaThrownExceptionInfo(1), new JavaThrownExceptionInfo(0)}),
|
||||
false);
|
||||
new SimpleExceptionsGen(new ThrownExceptionInfo[]{new JavaThrownExceptionInfo(1), new JavaThrownExceptionInfo(0)}), false);
|
||||
}
|
||||
|
||||
public void testAlreadyHandled() throws Exception {
|
||||
public void testAlreadyHandled() {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[] {
|
||||
new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.lang.Exception", method.getResolveScope()))
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.Exception", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
},
|
||||
false);
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
public void testConstructorException() throws Exception {
|
||||
public void testConstructorException() {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[] {
|
||||
new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.io.IOException", method.getResolveScope()))
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.io.IOException", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
},
|
||||
false);
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
public void testAddRuntimeException() throws Exception {
|
||||
public void testAddRuntimeException() {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[] {
|
||||
new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.lang.RuntimeException", method.getResolveScope()))
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.RuntimeException", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
},
|
||||
false);
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
public void testAddException() throws Exception {
|
||||
public void testAddException() {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[] {
|
||||
new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.lang.Exception", method.getResolveScope()))
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.Exception", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
},
|
||||
false);
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
public void testReorderWithVarargs() throws Exception { // IDEADEV-26977
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(1),
|
||||
new ParameterInfoImpl(0, "s", factory.createTypeFromText("java.lang.String...", getFile()))
|
||||
public void testReorderWithVarargs() { // IDEADEV-26977
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1),
|
||||
new ParameterInfoImpl(0, "s", myFactory.createTypeFromText("java.lang.String...", getFile()))
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testIntroduceParameterWithDefaultValueInHierarchy() throws Exception {
|
||||
public void testIntroduceParameterWithDefaultValueInHierarchy() {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(-1, "i", PsiType.INT, "0")}, false);
|
||||
}
|
||||
|
||||
public void testReorderMultilineMethodParameters() throws Exception {
|
||||
public void testReorderMultilineMethodParameters() {
|
||||
// Inspired by IDEA-54902
|
||||
doTest(null, new ParameterInfoImpl[] {new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false);
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false);
|
||||
}
|
||||
|
||||
public void testRemoveFirstParameter() throws Exception {
|
||||
public void testRemoveFirstParameter() {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1)}, false);
|
||||
}
|
||||
|
||||
public void testReplaceVarargWithArray() throws Exception {
|
||||
public void testReplaceVarargWithArray() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
|
||||
return new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(1, "l", factory.createTypeFromText("List<T>[]", method.getParameterList()), "null", false),
|
||||
new ParameterInfoImpl(0, "s", factory.createTypeFromText("String", method.getParameterList()))
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "l", myFactory.createTypeFromText("List<T>[]", method.getParameterList()), "null", false),
|
||||
new ParameterInfoImpl(0, "s", myFactory.createTypeFromText("String", method.getParameterList()))
|
||||
};
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testMethodParametersAlignmentAfterMethodNameChange() throws Exception {
|
||||
public void testMethodParametersAlignmentAfterMethodNameChange() {
|
||||
getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS = true;
|
||||
getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
|
||||
doTest(null, "test123asd", null, new SimpleParameterGen(), new SimpleExceptionsGen(), false);
|
||||
}
|
||||
|
||||
public void testMethodParametersAlignmentAfterMethodVisibilityChange() throws Exception {
|
||||
public void testMethodParametersAlignmentAfterMethodVisibilityChange() {
|
||||
getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS = true;
|
||||
getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
|
||||
doTest(PsiModifier.PROTECTED, null, null, new SimpleParameterGen(), new SimpleExceptionsGen(), false);
|
||||
}
|
||||
|
||||
public void testMethodParametersAlignmentAfterMethodReturnTypeChange() throws Exception {
|
||||
public void testMethodParametersAlignmentAfterMethodReturnTypeChange() {
|
||||
getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS = true;
|
||||
getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
|
||||
doTest(null, null, "Exception", new SimpleParameterGen(), new SimpleExceptionsGen(), false);
|
||||
}
|
||||
|
||||
public void testVisibilityOfOverriddenMethod() throws Exception {
|
||||
public void testVisibilityOfOverriddenMethod() {
|
||||
doTest(PsiModifier.PACKAGE_LOCAL, "foo", "void", new ParameterInfoImpl[0], new ThrownExceptionInfo[0], false);
|
||||
}
|
||||
|
||||
public void testRemoveExceptions() throws Exception {
|
||||
public void testRemoveExceptions() {
|
||||
doTest(null, null, "void", new SimpleParameterGen(), new SimpleExceptionsGen(), false);
|
||||
}
|
||||
|
||||
private void doTest(@Nullable String newReturnType,
|
||||
ParameterInfoImpl[] parameterInfos,
|
||||
final boolean generateDelegate) throws Exception {
|
||||
doTest(null, null, newReturnType, parameterInfos, new ThrownExceptionInfo[0], generateDelegate);
|
||||
}
|
||||
|
||||
private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility,
|
||||
@Nullable String newName,
|
||||
@Nullable String newReturnType,
|
||||
ParameterInfoImpl[] parameterInfo,
|
||||
ThrownExceptionInfo[] exceptionInfo,
|
||||
final boolean generateDelegate) throws Exception {
|
||||
doTest(newVisibility, newName, newReturnType, new SimpleParameterGen(parameterInfo), new SimpleExceptionsGen(exceptionInfo), generateDelegate);
|
||||
}
|
||||
|
||||
private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility,
|
||||
@Nullable String newName,
|
||||
@Nullable @NonNls String newReturnType,
|
||||
GenParams gen, final boolean generateDelegate) throws Exception {
|
||||
doTest(newVisibility, newName, newReturnType, gen, new SimpleExceptionsGen(), generateDelegate);
|
||||
}
|
||||
|
||||
private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility,
|
||||
@Nullable String newName,
|
||||
@Nullable String newReturnType,
|
||||
GenParams genParams,
|
||||
GenExceptions genExceptions,
|
||||
final boolean generateDelegate) throws Exception {
|
||||
public void testPropagateParameter() {
|
||||
String basePath = "/refactoring/changeSignature/" + getTestName(false);
|
||||
@NonNls final String filePath = basePath + ".java";
|
||||
configureByFile(filePath);
|
||||
configureByFile(basePath + ".java");
|
||||
final PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
|
||||
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
|
||||
PsiMethod method = (PsiMethod) targetElement;
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
PsiType newType = newReturnType != null ? factory.createTypeFromText(newReturnType, method) : method.getReturnType();
|
||||
new ChangeSignatureProcessor(getProject(), method, generateDelegate, newVisibility,
|
||||
newName != null ? newName : method.getName(),
|
||||
newType, genParams.genParams(method), genExceptions.genExceptions(method)).run();
|
||||
@NonNls String after = basePath + "_after.java";
|
||||
checkResultByFile(after);
|
||||
}
|
||||
|
||||
public void testPropagateParameter() throws Exception {
|
||||
String basePath = "/refactoring/changeSignature/" + getTestName(false);
|
||||
@NonNls final String filePath = basePath + ".java";
|
||||
configureByFile(filePath);
|
||||
final PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
|
||||
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
|
||||
PsiMethod method = (PsiMethod) targetElement;
|
||||
PsiMethod method = (PsiMethod)targetElement;
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
assertTrue(containingClass != null);
|
||||
final PsiMethod[] callers = containingClass.findMethodsByName("caller", false);
|
||||
@@ -443,14 +405,53 @@ public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
final HashSet<PsiMethod> propagateParametersMethods = new HashSet<PsiMethod>();
|
||||
propagateParametersMethods.add(caller);
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
new ChangeSignatureProcessor(getProject(), method, false, null,
|
||||
method.getName(),
|
||||
new ChangeSignatureProcessor(getProject(), method, false, null, method.getName(),
|
||||
CanonicalTypes.createTypeWrapper(PsiType.VOID), new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, parameters[0].getName(), parameters[0].getType()),
|
||||
new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, null,
|
||||
propagateParametersMethods, null).run();
|
||||
@NonNls String after = basePath + "_after.java";
|
||||
checkResultByFile(after);
|
||||
new ParameterInfoImpl(0, parameters[0].getName(), parameters[0].getType()),
|
||||
new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, null, propagateParametersMethods, null
|
||||
).run();
|
||||
checkResultByFile(basePath + "_after.java");
|
||||
}
|
||||
|
||||
/* workers */
|
||||
|
||||
private void doTest(@Nullable String newReturnType, ParameterInfoImpl[] parameterInfos, boolean generateDelegate) {
|
||||
doTest(null, null, newReturnType, parameterInfos, new ThrownExceptionInfo[0], generateDelegate);
|
||||
}
|
||||
|
||||
private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility,
|
||||
@Nullable String newName,
|
||||
@Nullable String newReturnType,
|
||||
ParameterInfoImpl[] parameterInfo,
|
||||
ThrownExceptionInfo[] exceptionInfo,
|
||||
boolean generateDelegate) {
|
||||
doTest(newVisibility, newName, newReturnType, new SimpleParameterGen(parameterInfo), new SimpleExceptionsGen(exceptionInfo), generateDelegate);
|
||||
}
|
||||
|
||||
private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility,
|
||||
@Nullable String newName,
|
||||
@Nullable @NonNls String newReturnType,
|
||||
GenParams gen,
|
||||
boolean generateDelegate) {
|
||||
doTest(newVisibility, newName, newReturnType, gen, new SimpleExceptionsGen(), generateDelegate);
|
||||
}
|
||||
|
||||
private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility,
|
||||
@Nullable String newName,
|
||||
@Nullable String newReturnType,
|
||||
GenParams genParams,
|
||||
GenExceptions genExceptions,
|
||||
boolean generateDelegate) {
|
||||
String basePath = "/refactoring/changeSignature/" + getTestName(false);
|
||||
configureByFile(basePath + ".java");
|
||||
PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
|
||||
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
|
||||
PsiMethod method = (PsiMethod)targetElement;
|
||||
PsiType newType = newReturnType != null ? myFactory.createTypeFromText(newReturnType, method) : method.getReturnType();
|
||||
new ChangeSignatureProcessor(getProject(), method, generateDelegate, newVisibility,
|
||||
newName != null ? newName : method.getName(),
|
||||
newType, genParams.genParams(method), genExceptions.genExceptions(method)).run();
|
||||
checkResultByFile(basePath + "_after.java");
|
||||
}
|
||||
|
||||
private interface GenParams {
|
||||
@@ -460,8 +461,7 @@ public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
private static class SimpleParameterGen implements GenParams {
|
||||
private ParameterInfoImpl[] myInfos;
|
||||
|
||||
private SimpleParameterGen() {
|
||||
}
|
||||
private SimpleParameterGen() { }
|
||||
|
||||
private SimpleParameterGen(ParameterInfoImpl[] infos) {
|
||||
myInfos = infos;
|
||||
|
||||
Reference in New Issue
Block a user