mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not need parenthesis for associative operations (IDEADEV-41569); move to java-tests
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class IntroduceVariableMultifileTest extends MultiFileTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
LanguageLevelProjectExtension.getInstance(myJavaFacade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
}
|
||||
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/introduceVariable/";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
public void testSamePackageRef() throws Exception {
|
||||
doTest(
|
||||
createAction("pack1.A",
|
||||
new MockIntroduceVariableHandler("b", false, false, false, "pack1.B")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void testGenericTypeWithInner() throws Exception {
|
||||
doTest(
|
||||
createAction("test.Client",
|
||||
new MockIntroduceVariableHandler("l", false, true, true, "test.List<test.A.B>")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void testGenericTypeWithInner1() throws Exception {
|
||||
doTest(
|
||||
createAction("test.Client",
|
||||
new MockIntroduceVariableHandler("l", false, true, true, "test.List<test.A.B>")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void testGenericWithTwoParameters() throws Exception {
|
||||
doTest(
|
||||
createAction("Client",
|
||||
new MockIntroduceVariableHandler("p", false, false, true,
|
||||
"util.Pair<java.lang.String,util.Pair<java.lang.Integer,java.lang.Boolean>>")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void testGenericWithTwoParameters2() throws Exception {
|
||||
doTest(
|
||||
createAction("Client",
|
||||
new MockIntroduceVariableHandler("p", false, false, true,
|
||||
"Pair<java.lang.String,Pair<java.lang.Integer,java.lang.Boolean>>")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void testDummy() {
|
||||
|
||||
}
|
||||
|
||||
PerformAction createAction(final String className, final IntroduceVariableBase testMe) {
|
||||
return new PerformAction() {
|
||||
public void performAction(VirtualFile vroot, VirtualFile rootAfter) {
|
||||
final JavaPsiFacade psiManager = getJavaFacade();
|
||||
final PsiClass aClass = psiManager.findClass(className);
|
||||
assertTrue(aClass != null);
|
||||
final PsiFile containingFile = aClass.getContainingFile();
|
||||
final VirtualFile virtualFile = containingFile.getVirtualFile();
|
||||
assertTrue(virtualFile != null);
|
||||
final Editor editor = createEditor(virtualFile);
|
||||
setupCursorAndSelection(editor);
|
||||
testMe.invoke(myProject, editor, containingFile, null);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class IntroduceVariableSuite extends TestCase {
|
||||
public static Test suite() {
|
||||
final TestSuite suite = new TestSuite();
|
||||
suite.addTestSuite(IntroduceVariableTest.class);
|
||||
suite.addTestSuite(IntroduceVariableMultifileTest.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableSettings;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
public void testSimpleExpression() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("i", false, false, true, "int"));
|
||||
}
|
||||
|
||||
public void testInsideFor() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", false, false, true, "int"));
|
||||
}
|
||||
|
||||
public void testReplaceAll() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("s", true, true, true, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testIDEADEV3678() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("component", true, true, true, "java.lang.Object"));
|
||||
}
|
||||
|
||||
public void testIDEADEV13369() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("ints", true, true, true, "int[]"));
|
||||
}
|
||||
|
||||
public void testAnonymousClass() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, true, "int"));
|
||||
}
|
||||
|
||||
public void testAnonymousClass1() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("runnable", false, false, false, "java.lang.Runnable"));
|
||||
}
|
||||
|
||||
public void testAnonymousClass2() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("j", true, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testParenthized() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testMethodCall() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, true, true, "java.lang.Object"));
|
||||
}
|
||||
|
||||
public void testMethodCallInSwitch() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("i", true, true, true, "int"));
|
||||
}
|
||||
|
||||
public void testParenthizedOccurence() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("empty", true, true, true, "boolean"));
|
||||
}
|
||||
|
||||
public void testConflictingField() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("name", true, false, true, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testConflictingFieldInExpression() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("name", false, false, true, "int"));
|
||||
}
|
||||
|
||||
public void testStaticConflictingField() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("name", false, false, true, "int"));
|
||||
}
|
||||
|
||||
public void testScr16910() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("i", true, true, false, "int"));
|
||||
}
|
||||
|
||||
public void testSCR18295() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("it", true, false, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testSCR18295a() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("it", false, false, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testSCR10412() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("newVar", false, false, false, "java.lang.String[]"));
|
||||
}
|
||||
|
||||
public void testSCR22718() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("object", true, true, false, "java.lang.Object"));
|
||||
}
|
||||
|
||||
public void testSCR26075() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("wrong", false, false, false, "java.lang.String") {
|
||||
protected void assertValidationResult(boolean validationResult) {
|
||||
assertFalse(validationResult);
|
||||
}
|
||||
|
||||
protected boolean reportConflicts(MultiMap<PsiElement,String> conflicts, final Project project, IntroduceVariableSettings dialog) {
|
||||
assertEquals(2, conflicts.size());
|
||||
Collection<? extends String> conflictsMessages = conflicts.values();
|
||||
assertTrue(conflictsMessages.contains("Introducing variable may break code logic."));
|
||||
assertTrue(conflictsMessages.contains("Local variable <b><code>c</code></b> is modified in loop body."));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testConflictingFieldInOuterClass() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("text", true, true, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testSkipSemicolon() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("mi5", false, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testInsideIf() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("s1", false, false, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testInsideElse() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("s1", false, false, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testInsideWhile() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", false, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testSCR40281() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", false, false, false, "Set<? extends Map<?,String>.Entry<?,String>>"));
|
||||
}
|
||||
|
||||
public void testWithIfBranches() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testDuplicateGenericExpressions() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "Foo2<? extends Runnable>"));
|
||||
}
|
||||
|
||||
public void testStaticImport() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("i", true, true, false, "int"));
|
||||
}
|
||||
|
||||
public void testThisQualifier() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("count", true, true, false, "int"));
|
||||
}
|
||||
|
||||
public void testSubLiteral() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("str", false, false, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testSubLiteral1() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("str", false, false, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testSubLiteralFromExpression() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("str", false, false, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testSubPrimitiveLiteral() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("str", false, false, false, "boolean"));
|
||||
}
|
||||
|
||||
public void testNonExpression() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("sum", true, true, false, "int"));
|
||||
}
|
||||
public void testTypeAnnotations() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("y1", true, false, false, "@TA C"));
|
||||
}
|
||||
|
||||
public void testReturnStatementWithoutSemicolon() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("b", true, true, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testAndAndSubExpression() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("ab", true, true, false, "boolean"));
|
||||
}
|
||||
|
||||
public void testNonExpressionPriorityFailure() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("sum", true, true, false, "int"){
|
||||
@Override
|
||||
protected void showErrorMessage(Project project, Editor editor, String message) {
|
||||
assertEquals("Cannot perform refactoring.\n" + "Selected block should represent an expression.", message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest(IntroduceVariableBase testMe) throws Exception {
|
||||
@NonNls String baseName = "/refactoring/introduceVariable/" + getTestName(false);
|
||||
configureByFile(baseName + ".java");
|
||||
testMe.invoke(getProject(), getEditor(), getFile(), null);
|
||||
checkResultByFile(baseName + ".after.java");
|
||||
}
|
||||
|
||||
private LanguageLevel myOldLanguageLevel;
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myOldLanguageLevel = LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).getLanguageLevel();
|
||||
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(myOldLanguageLevel);
|
||||
super.tearDown();
|
||||
}
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return JavaSdkImpl.getMockJdk17("java 1.7");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.refactoring.introduceVariable.InputValidator;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableSettings;
|
||||
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
class MockIntroduceVariableHandler extends IntroduceVariableBase {
|
||||
private final String myName;
|
||||
private final boolean myReplaceAll;
|
||||
private final boolean myDeclareFinal;
|
||||
private final boolean myReplaceLValues;
|
||||
private final String myExpectedTypeCanonicalName;
|
||||
|
||||
public MockIntroduceVariableHandler(@NonNls final String name, final boolean replaceAll,
|
||||
final boolean declareFinal, final boolean replaceLValues,
|
||||
@NonNls final String expectedTypeCanonicalName) {
|
||||
|
||||
myName = name;
|
||||
myReplaceAll = replaceAll;
|
||||
myDeclareFinal = declareFinal;
|
||||
myReplaceLValues = replaceLValues;
|
||||
myExpectedTypeCanonicalName = expectedTypeCanonicalName;
|
||||
}
|
||||
|
||||
|
||||
protected IntroduceVariableSettings getSettings(Project project, Editor editor, PsiExpression expr, final PsiElement[] occurrences,
|
||||
boolean anyAssignmentLHS, final boolean declareFinalIfAll, final PsiType type,
|
||||
TypeSelectorManagerImpl typeSelectorManager, InputValidator validator) {
|
||||
Assert.assertTrue(type.getCanonicalText(), type.equalsToText(myExpectedTypeCanonicalName));
|
||||
IntroduceVariableSettings introduceVariableSettings = new IntroduceVariableSettings() {
|
||||
public String getEnteredName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public boolean isReplaceAllOccurrences() {
|
||||
return myReplaceAll && occurrences.length > 1;
|
||||
}
|
||||
|
||||
public boolean isDeclareFinal() {
|
||||
return myDeclareFinal || isReplaceAllOccurrences() && declareFinalIfAll;
|
||||
}
|
||||
|
||||
public boolean isReplaceLValues() {
|
||||
return myReplaceLValues;
|
||||
}
|
||||
|
||||
public PsiType getSelectedType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isOK() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
final boolean validationResult = validator.isOK(introduceVariableSettings);
|
||||
assertValidationResult(validationResult);
|
||||
return introduceVariableSettings;
|
||||
}
|
||||
|
||||
protected void assertValidationResult(final boolean validationResult) {
|
||||
Assert.assertTrue(validationResult);
|
||||
}
|
||||
|
||||
protected void showErrorMessage(Project project, Editor editor, String message) {
|
||||
throw new RuntimeException("Error message:" + message);
|
||||
}
|
||||
|
||||
protected void highlightReplacedOccurences(final Project project, Editor editor, final PsiElement[] replacedOccurences) {
|
||||
|
||||
}
|
||||
|
||||
protected boolean reportConflicts(final MultiMap<PsiElement,String> conflicts, final Project project, IntroduceVariableSettings dialog) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import junit.textui.TestRunner;
|
||||
import junit.framework.TestSuite;
|
||||
import com.intellij.TestAll;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class Run {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new TestRunner().doRun(new TestSuite(IntroduceVariableTest.class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user