mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Groovy] convert GrIntroduceParameterTest to Java (IDEA-327339)
GitOrigin-RevId: 8f98421f15c28999fe82bfbb569b957764eda875
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7d53e00e8b
commit
5dfc9435c4
+259
-259
@@ -1,248 +1,249 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.refactoring.introduceParameter
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.groovy.refactoring.introduceParameter;
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect
|
||||
import com.intellij.refactoring.IntroduceParameterRefactoring
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.plugins.groovy.LightGroovyTestCase
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression
|
||||
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.lang.psi.impl.statements.expressions.TypesUtil
|
||||
import org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceHandlerBase
|
||||
import org.jetbrains.plugins.groovy.refactoring.introduce.parameter.*
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
import org.junit.Assert
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.refactoring.IntroduceParameterRefactoring;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.LightGroovyTestCase;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
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.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
import org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceHandlerBase;
|
||||
import org.jetbrains.plugins.groovy.refactoring.introduce.parameter.*;
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
class GrIntroduceParameterTest extends LightGroovyTestCase {
|
||||
public class GrIntroduceParameterTest extends LightGroovyTestCase {
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return TestUtils.getTestDataPath() + "refactoring/introduceParameterGroovy/" + getTestName(true) + '/'
|
||||
return TestUtils.getTestDataPath() + "refactoring/introduceParameterGroovy/" + getTestName(true) + "/";
|
||||
}
|
||||
|
||||
private void doDelegateTest() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, true)
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, true);
|
||||
}
|
||||
|
||||
private boolean doTest(int replaceFieldsWithGetters, boolean removeUnusedParameters, boolean declareFinal) {
|
||||
return doTest(replaceFieldsWithGetters, removeUnusedParameters, declareFinal, null)
|
||||
private void doTest(int replaceFieldsWithGetters, boolean removeUnusedParameters, boolean declareFinal) {
|
||||
doTest(replaceFieldsWithGetters, removeUnusedParameters, declareFinal, null);
|
||||
}
|
||||
|
||||
private boolean doTest(final int replaceFieldsWithGetters,
|
||||
final boolean removeUnusedParameters,
|
||||
final boolean declareFinal,
|
||||
@Nullable final String conflicts) {
|
||||
return doTest(replaceFieldsWithGetters, removeUnusedParameters, declareFinal, conflicts, false)
|
||||
private void doTest(int replaceFieldsWithGetters, boolean removeUnusedParameters, boolean declareFinal, @Nullable String conflicts) {
|
||||
doTest(replaceFieldsWithGetters, removeUnusedParameters, declareFinal, conflicts, false);
|
||||
}
|
||||
|
||||
private boolean doTest(final int replaceFieldsWithGetters,
|
||||
final boolean removeUnusedParameters,
|
||||
final boolean declareFinal,
|
||||
@Nullable final String conflicts,
|
||||
final boolean generateDelegate) {
|
||||
final String beforeGroovy = getTestName(false)+"Before.groovy"
|
||||
final String afterGroovy = getTestName(false) + "After.groovy"
|
||||
final String clazz = getTestName(false) + "MyClass.groovy"
|
||||
final String afterClazz = getTestName(false) + "MyClass_after.groovy"
|
||||
private void doTest(int replaceFieldsWithGetters,
|
||||
boolean removeUnusedParameters,
|
||||
boolean declareFinal,
|
||||
@Nullable String conflicts,
|
||||
boolean generateDelegate) {
|
||||
final String beforeGroovy = getTestName(false) + "Before.groovy";
|
||||
final String afterGroovy = getTestName(false) + "After.groovy";
|
||||
final String clazz = getTestName(false) + "MyClass.groovy";
|
||||
final String afterClazz = getTestName(false) + "MyClass_after.groovy";
|
||||
|
||||
final boolean beforeExists = exists(beforeGroovy)
|
||||
final boolean beforeExists = exists(beforeGroovy);
|
||||
if (beforeExists) {
|
||||
myFixture.copyFileToProject(beforeGroovy)
|
||||
myFixture.copyFileToProject(beforeGroovy);
|
||||
}
|
||||
myFixture.configureByFile(clazz)
|
||||
myFixture.configureByFile(clazz);
|
||||
|
||||
execute(replaceFieldsWithGetters, removeUnusedParameters, declareFinal, conflicts, generateDelegate, getProject(),
|
||||
myFixture.getEditor(), myFixture.getFile())
|
||||
myFixture.getEditor(), myFixture.getFile());
|
||||
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting()
|
||||
myFixture.getEditor().getSelectionModel().removeSelection()
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
myFixture.getEditor().getSelectionModel().removeSelection();
|
||||
if (beforeExists) {
|
||||
myFixture.checkResultByFile(beforeGroovy, afterGroovy, true)
|
||||
myFixture.checkResultByFile(beforeGroovy, afterGroovy, true);
|
||||
}
|
||||
|
||||
if (exists(afterClazz)) {
|
||||
myFixture.checkResultByFile(afterClazz)
|
||||
myFixture.checkResultByFile(afterClazz);
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private void doTest(final int replaceFieldsWithGetters,
|
||||
final boolean removeUnusedParameters,
|
||||
final boolean declareFinal,
|
||||
@Nullable final String conflicts,
|
||||
final boolean generateDelegate, String before, String after) {
|
||||
myFixture.configureByText('before.groovy', before)
|
||||
private void doTest(int replaceFieldsWithGetters,
|
||||
boolean removeUnusedParameters,
|
||||
boolean declareFinal,
|
||||
@Nullable String conflicts,
|
||||
boolean generateDelegate,
|
||||
String before,
|
||||
String after) {
|
||||
myFixture.configureByText("before.groovy", before);
|
||||
|
||||
execute(replaceFieldsWithGetters, removeUnusedParameters, declareFinal, conflicts, generateDelegate, getProject(),
|
||||
myFixture.getEditor(), myFixture.getFile())
|
||||
myFixture.getEditor(), myFixture.getFile());
|
||||
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting()
|
||||
myFixture.getEditor().getSelectionModel().removeSelection()
|
||||
|
||||
myFixture.checkResult(after)
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
myFixture.getEditor().getSelectionModel().removeSelection();
|
||||
myFixture.checkResult(after);
|
||||
}
|
||||
|
||||
|
||||
private boolean exists(String sourceFilePath) {
|
||||
File file = new File(getTestDataPath() + "/" + sourceFilePath)
|
||||
return file.exists()
|
||||
return new File(getTestDataPath() + "/" + sourceFilePath).exists();
|
||||
}
|
||||
|
||||
static void execute(final int replaceFieldsWithGetters,
|
||||
final boolean removeUnusedParameters,
|
||||
final boolean declareFinal,
|
||||
final String conflicts,
|
||||
final boolean generateDelegate,
|
||||
final Project project,
|
||||
final Editor editor,
|
||||
final PsiFile file) {
|
||||
public static void execute(int replaceFieldsWithGetters,
|
||||
boolean removeUnusedParameters,
|
||||
boolean declareFinal,
|
||||
String conflicts,
|
||||
boolean generateDelegate,
|
||||
Project project,
|
||||
Editor editor,
|
||||
PsiFile file) {
|
||||
try {
|
||||
final GrIntroduceParameterHandler hackedHandler = new GrIntroduceParameterHandler() {
|
||||
@Override
|
||||
protected void showDialog(IntroduceParameterInfo info) {
|
||||
final GrIntroduceParameterSettings hackedSettings =
|
||||
getSettings(info, removeUnusedParameters, replaceFieldsWithGetters, declareFinal, generateDelegate)
|
||||
getSettings(info, removeUnusedParameters, replaceFieldsWithGetters, declareFinal, generateDelegate);
|
||||
if (info.getToReplaceIn() instanceof GrMethod) {
|
||||
new GrIntroduceParameterProcessor(hackedSettings).run()
|
||||
new GrIntroduceParameterProcessor(hackedSettings).run();
|
||||
}
|
||||
else {
|
||||
new GrIntroduceClosureParameterProcessor(hackedSettings).run()
|
||||
new GrIntroduceClosureParameterProcessor(hackedSettings).run();
|
||||
}
|
||||
}
|
||||
}
|
||||
hackedHandler.invoke(project, editor, file, null)
|
||||
if (conflicts != null) fail("Conflicts were expected")
|
||||
};
|
||||
hackedHandler.invoke(project, editor, file, null);
|
||||
if (conflicts != null) fail("Conflicts were expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (conflicts == null) {
|
||||
e.printStackTrace()
|
||||
fail("Conflicts were not expected")
|
||||
e.printStackTrace();
|
||||
fail("Conflicts were not expected");
|
||||
}
|
||||
Assert.assertEquals(conflicts, e.getMessage())
|
||||
assertEquals(conflicts, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static GrIntroduceParameterSettings getSettings(final IntroduceParameterInfo context,
|
||||
final boolean removeUnusedParameters,
|
||||
final int replaceFieldsWithGetters,
|
||||
final boolean declareFinal,
|
||||
final boolean generateDelegate) {
|
||||
private static GrIntroduceParameterSettings getSettings(IntroduceParameterInfo context,
|
||||
boolean removeUnusedParameters,
|
||||
int replaceFieldsWithGetters,
|
||||
boolean declareFinal,
|
||||
boolean generateDelegate) {
|
||||
|
||||
IntArrayList toRemove = new IntArrayList()
|
||||
IntList toRemove = new IntArrayList();
|
||||
if (removeUnusedParameters) {
|
||||
Object2IntMap<GrParameter> map = GroovyIntroduceParameterUtil.findParametersToRemove(context)
|
||||
Object2IntMap<GrParameter> map = GroovyIntroduceParameterUtil.findParametersToRemove(context);
|
||||
for (int i : map.values()) {
|
||||
toRemove.add(i)
|
||||
toRemove.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
final GrStatement[] statements = context.getStatements()
|
||||
GrExpression expr = statements.length == 1 ? GrIntroduceHandlerBase.findExpression(statements[0]) : null
|
||||
GrVariable var = context.var
|
||||
final PsiType type = TypesUtil.unboxPrimitiveTypeWrapper(var != null ? var.getType() : expr != null ? expr.getType() : context.stringPartInfo.literal.type)
|
||||
final GrStatement[] statements = context.getStatements();
|
||||
GrExpression expr = statements.length == 1 ? GrIntroduceHandlerBase.findExpression(statements[0]) : null;
|
||||
GrVariable var = context.getVar();
|
||||
final PsiType type = TypesUtil.unboxPrimitiveTypeWrapper(
|
||||
var != null ? var.getType() : expr != null ? expr.getType() : context.getStringPartInfo().getLiteral().getType());
|
||||
return new GrIntroduceExpressionSettingsImpl(context, "anObject", declareFinal, toRemove, generateDelegate, replaceFieldsWithGetters,
|
||||
expr, var, type, var !=null, var != null, true)
|
||||
expr, var, type, var != null, var != null, true);
|
||||
}
|
||||
|
||||
|
||||
void testSimpleOverridedMethod() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testSimpleOverridedMethod() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testOverridedMethodWithRemoveUnusedParameters() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false)
|
||||
public void testOverridedMethodWithRemoveUnusedParameters() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false);
|
||||
}
|
||||
|
||||
void testSimpleUsage() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testSimpleUsage() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testMethodWithoutParams() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testMethodWithoutParams() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testParameterSubstitution() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testParameterSubstitution() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testThisSubstitution() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testThisSubstitution() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testThisSubstitutionInQualifier() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, "field <b><code>Test.i</code></b> is not accessible from method <b><code>XTest.n()</code></b>. Value for introduced parameter in that method call will be incorrect.")
|
||||
public void testThisSubstitutionInQualifier() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false,
|
||||
"field <b><code>Test.i</code></b> is not accessible from method <b><code>XTest.n()</code></b>. Value for introduced parameter in that method call will be incorrect.");
|
||||
}
|
||||
|
||||
void testQualifiedThisSubstitution() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null)
|
||||
public void testQualifiedThisSubstitution() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null);
|
||||
}
|
||||
|
||||
void testFieldAccess() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testFieldAccess() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testMethodAccess() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testMethodAccess() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testStaticFieldAccess() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testStaticFieldAccess() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testFieldWithGetterReplacement() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, false, false)
|
||||
public void testFieldWithGetterReplacement() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, false, false);
|
||||
}
|
||||
|
||||
void testFieldWithInaccessibleGetterReplacement() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false)
|
||||
public void testFieldWithInaccessibleGetterReplacement() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false);
|
||||
}
|
||||
|
||||
void testWeirdQualifier() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false)
|
||||
public void testWeirdQualifier() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false);
|
||||
}
|
||||
|
||||
void testSuperInExpression() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, "Parameter initializer contains <b><code>super</code></b>, but not all calls to method are in its class")
|
||||
public void testSuperInExpression() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false,
|
||||
"Parameter initializer contains <b><code>super</code></b>, but not all calls to method are in its class");
|
||||
}
|
||||
|
||||
void testWeirdQualifierAndParameter() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false)
|
||||
public void testWeirdQualifierAndParameter() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false);
|
||||
}
|
||||
|
||||
void testImplicitSuperCall() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false)
|
||||
public void testImplicitSuperCall() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false);
|
||||
}
|
||||
|
||||
void testImplicitDefaultConstructor() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false)
|
||||
public void testImplicitDefaultConstructor() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false);
|
||||
}
|
||||
|
||||
void testInternalSideEffect() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false)
|
||||
public void testInternalSideEffect() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false);
|
||||
}
|
||||
|
||||
|
||||
/* public void testAnonymousClass() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, false);
|
||||
}*/
|
||||
|
||||
void testSuperWithSideEffect() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, "Parameter initializer contains <b><code>super</code></b>, but not all calls to method are in its class")
|
||||
public void testSuperWithSideEffect() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false,
|
||||
"Parameter initializer contains <b><code>super</code></b>, but not all calls to method are in its class");
|
||||
}
|
||||
|
||||
void testConflictingField() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false)
|
||||
public void testConflictingField() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false);
|
||||
}
|
||||
|
||||
|
||||
/*public void testParameterJavaDoc1() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, true);
|
||||
}
|
||||
@@ -259,151 +260,150 @@ class GrIntroduceParameterTest extends LightGroovyTestCase {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, false, false, true);
|
||||
}*/
|
||||
|
||||
void testRemoveParameterInHierarchy() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false)
|
||||
public void testRemoveParameterInHierarchy() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false);
|
||||
}
|
||||
|
||||
|
||||
/*public void testRemoveParameterWithJavadoc() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false, false);
|
||||
}*/
|
||||
|
||||
void testVarargs() { // IDEADEV-16828
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false, false);
|
||||
}*/
|
||||
|
||||
public void testVarargs() { // IDEADEV-16828
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testMethodUsageInThisMethodInheritor() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testMethodUsageInThisMethodInheritor() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testIncorrectArgumentList() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, true)
|
||||
public void testIncorrectArgumentList() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, true);
|
||||
}
|
||||
|
||||
void testClosure() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false)
|
||||
public void testClosure() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false);
|
||||
}
|
||||
|
||||
void testDelegate1() { doDelegateTest() }
|
||||
public void testDelegate1() { doDelegateTest(); }
|
||||
|
||||
void testDelegate2() { doDelegateTest() }
|
||||
public void testDelegate2() { doDelegateTest(); }
|
||||
|
||||
void testDelegaterInSuper() { doDelegateTest() }
|
||||
public void testDelegaterInSuper() { doDelegateTest(); }
|
||||
|
||||
void testClosureArg() { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false) }
|
||||
public void testClosureArg() { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false); }
|
||||
|
||||
void testClosureArgWithEmptyArgList() { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false) }
|
||||
public void testClosureArgWithEmptyArgList() { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false); }
|
||||
|
||||
void testScriptMethod() { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false) }
|
||||
public void testScriptMethod() { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, true, false); }
|
||||
|
||||
void testAppStatement() { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false) }
|
||||
public void testAppStatement() { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false); }
|
||||
|
||||
void testStringPart0() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, '''\
|
||||
def foo() {
|
||||
print 'a<selection>b</selection>c'
|
||||
}
|
||||
|
||||
foo()
|
||||
''', '''\
|
||||
def foo(String anObject) {
|
||||
print 'a' + anObject<caret> + 'c'
|
||||
}
|
||||
|
||||
foo('b')
|
||||
''')
|
||||
public void testStringPart0() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, """
|
||||
def foo() {
|
||||
print 'a<selection>b</selection>c'
|
||||
}
|
||||
|
||||
foo()
|
||||
""", """
|
||||
def foo(String anObject) {
|
||||
print 'a' + anObject<caret> + 'c'
|
||||
}
|
||||
|
||||
foo('b')
|
||||
""");
|
||||
}
|
||||
|
||||
void testIntroduceToConstructorUsedByAnonymousClass() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, '''\
|
||||
class X {
|
||||
def X() {
|
||||
print <selection>2</selection>
|
||||
}
|
||||
}
|
||||
|
||||
print new X() {
|
||||
}
|
||||
''', '''\
|
||||
class X {
|
||||
def X(int anObject) {
|
||||
print anObject
|
||||
}
|
||||
}
|
||||
|
||||
print new X(2) {
|
||||
}
|
||||
''')
|
||||
public void testIntroduceToConstructorUsedByAnonymousClass() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, """
|
||||
class X {
|
||||
def X() {
|
||||
print <selection>2</selection>
|
||||
}
|
||||
}
|
||||
|
||||
print new X() {
|
||||
}
|
||||
""", """
|
||||
class X {
|
||||
def X(int anObject) {
|
||||
print anObject
|
||||
}
|
||||
}
|
||||
|
||||
print new X(2) {
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
|
||||
void testNullType() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, '''\
|
||||
def foo() {
|
||||
def a = '4'
|
||||
<selection>print a</selection>
|
||||
}
|
||||
|
||||
foo()
|
||||
''', '''\
|
||||
def foo(anObject) {
|
||||
def a = '4'
|
||||
anObject
|
||||
}
|
||||
|
||||
foo(print(a))
|
||||
''')
|
||||
public void testNullType() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, """
|
||||
def foo() {
|
||||
def a = '4'
|
||||
<selection>print a</selection>
|
||||
}
|
||||
|
||||
foo()
|
||||
""", """
|
||||
def foo(anObject) {
|
||||
def a = '4'
|
||||
anObject
|
||||
}
|
||||
|
||||
foo(print(a))
|
||||
""");
|
||||
}
|
||||
|
||||
void testIntroduceFromLocalVar() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, '''\
|
||||
def foo() {
|
||||
def <selection>var = 5</selection>
|
||||
|
||||
print var + var
|
||||
}
|
||||
|
||||
foo()
|
||||
''', '''\
|
||||
def foo(anObject) {
|
||||
|
||||
print anObject + anObject
|
||||
}
|
||||
|
||||
foo(5)
|
||||
''')
|
||||
public void testIntroduceFromLocalVar() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, """
|
||||
def foo() {
|
||||
def <selection>var = 5</selection>
|
||||
|
||||
print var + var
|
||||
}
|
||||
|
||||
foo()
|
||||
""", """
|
||||
def foo(anObject) {
|
||||
|
||||
print anObject + anObject
|
||||
}
|
||||
|
||||
foo(5)
|
||||
""");
|
||||
}
|
||||
|
||||
void testIntroduceFromInjection() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false ,'''\
|
||||
def foo() {
|
||||
def bar = "bar"
|
||||
println "$<selection>bar</selection>"
|
||||
}
|
||||
''', '''\
|
||||
def foo(String anObject) {
|
||||
def bar = "bar"
|
||||
println "${anObject}"
|
||||
}
|
||||
''')
|
||||
public void testIntroduceFromInjection() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, """
|
||||
def foo() {
|
||||
def bar = "bar"
|
||||
println "$<selection>bar</selection>"
|
||||
}
|
||||
""", """
|
||||
def foo(String anObject) {
|
||||
def bar = "bar"
|
||||
println "${anObject}"
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
void testIntroduceFromStringByCaret() {
|
||||
doTest IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, '''\
|
||||
def test() {
|
||||
createFile();
|
||||
}
|
||||
|
||||
def createFile() {
|
||||
new File("na<caret>me").createNewFile()
|
||||
}
|
||||
''', '''\
|
||||
def test() {
|
||||
createFile("name");
|
||||
}
|
||||
|
||||
def createFile(String anObject) {
|
||||
new File(anObject).createNewFile()
|
||||
}
|
||||
'''
|
||||
public void testIntroduceFromStringByCaret() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, null, false, """
|
||||
def test() {
|
||||
createFile();
|
||||
}
|
||||
|
||||
def createFile() {
|
||||
new File("na<caret>me").createNewFile()
|
||||
}
|
||||
""", """
|
||||
def test() {
|
||||
createFile("name");
|
||||
}
|
||||
|
||||
def createFile(String anObject) {
|
||||
new File(anObject).createNewFile()
|
||||
}
|
||||
""");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user