mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactor to LightMultiFileTestCase
This commit is contained in:
+1
-1
@@ -3,6 +3,6 @@ package b;
|
||||
import a.Test;
|
||||
|
||||
public class TestSubclass extends Test {
|
||||
@java.lang.Override void x() {
|
||||
@Override void x() {
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
public class TestSubclass extends Test {
|
||||
@java.lang.Override
|
||||
@Override
|
||||
void x() {
|
||||
xx();
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Test extends ArrayList {
|
||||
public Test(int capacity) {
|
||||
super(capacity);
|
||||
public Test(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ class Test<G, R> {
|
||||
}
|
||||
|
||||
void bar(R r){
|
||||
foo(new Param<R>(r));
|
||||
foo(new Param<>(r));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@ class Test<R> {
|
||||
}
|
||||
|
||||
void bar(R r){
|
||||
foo(new Param<R>(r));
|
||||
foo(new Param<>(r));
|
||||
}
|
||||
}
|
||||
+17
-27
@@ -17,18 +17,16 @@ package com.intellij.java.codeInsight.intention;
|
||||
|
||||
import com.intellij.codeInsight.intention.impl.CreateSubclassAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class CreateSubclassTest extends MultiFileTestCase {
|
||||
public class CreateSubclassTest extends LightMultiFileTestCase {
|
||||
public void testGenerics() {
|
||||
doTest();
|
||||
}
|
||||
@@ -46,35 +44,27 @@ public class CreateSubclassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTestInner() {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) {
|
||||
PsiClass superClass = myJavaFacade.findClass("Test", ProjectScope.getAllScope(myProject));
|
||||
assertNotNull(superClass);
|
||||
final PsiClass inner = superClass.findInnerClassByName("Inner", false);
|
||||
assertNotNull(inner);
|
||||
CreateSubclassAction.createInnerClass(inner);
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
doTest(() -> {
|
||||
PsiClass superClass = myFixture.findClass("Test");
|
||||
final PsiClass inner = superClass.findInnerClassByName("Inner", false);
|
||||
assertNotNull(inner);
|
||||
CreateSubclassAction.createInnerClass(inner);
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) {
|
||||
PsiDirectory root = myPsiManager.findDirectory(rootDir);
|
||||
PsiClass superClass = myJavaFacade.findClass("Superclass", ProjectScope.getAllScope(myProject));
|
||||
ApplicationManager.getApplication().invokeLater(
|
||||
() -> CreateSubclassAction.createSubclass(superClass, root, "Subclass"));
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
doTest(() -> {
|
||||
PsiDirectory root = getPsiManager().findDirectory(myFixture.getTempDirFixture().findOrCreateDir(""));
|
||||
PsiClass superClass = myFixture.findClass("Superclass");
|
||||
ApplicationManager.getApplication().invokeLater(
|
||||
() -> CreateSubclassAction.createSubclass(superClass, root, "Subclass"));
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/codeInsight/createSubclass/";
|
||||
protected String getTestDataPath() {
|
||||
return PathManagerEx.getTestDataPath() + "/codeInsight/createSubclass/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,35 +2,28 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.copy.CopyClassesHandler;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
@PlatformTestCase.WrapInCommand
|
||||
public class CopyClassTest extends CodeInsightTestCase {
|
||||
private VirtualFile myRootDir;
|
||||
public class CopyClassTest extends LightMultiFileTestCase {
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/";
|
||||
}
|
||||
|
||||
public void testReplaceAllOccurrences() throws Exception {
|
||||
doTest("Foo", "Bar");
|
||||
@@ -51,94 +44,74 @@ public class CopyClassTest extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
private void doTest(final String oldName, final String copyName) throws Exception {
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/" + getTestName(true);
|
||||
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
myRootDir = createTestProjectStructure(root);
|
||||
|
||||
myFixture.copyDirectoryToProject(getTestName(true), "");
|
||||
performAction(oldName, copyName);
|
||||
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
|
||||
VirtualFile fileAfter = myRootDir.findChild(copyName + ".java");
|
||||
VirtualFile fileExpected = myRootDir.findChild(copyName + ".expected.java");
|
||||
|
||||
VirtualFile fileAfter = myFixture.findFileInTempDir(copyName + ".java");
|
||||
VirtualFile fileExpected = myFixture.findFileInTempDir(copyName + ".expected.java");
|
||||
|
||||
PlatformTestUtil.assertFilesEqual(fileExpected, fileAfter);
|
||||
}
|
||||
|
||||
private void performAction(final String oldName, final String copyName) throws IncorrectOperationException {
|
||||
final PsiClass oldClass = JavaPsiFacade.getInstance(myProject).findClass(oldName, ProjectScope.getAllScope(myProject));
|
||||
private void performAction(final String oldName, final String copyName) throws Exception {
|
||||
final PsiClass oldClass = myFixture.findClass(oldName);
|
||||
|
||||
WriteCommandAction.runWriteCommandAction(null, (Computable<Collection<PsiFile>>)() -> CopyClassesHandler.doCopyClasses(
|
||||
Collections.singletonMap(oldClass.getNavigationElement().getContainingFile(), new PsiClass[]{oldClass}), copyName,
|
||||
myPsiManager.findDirectory(myRootDir),
|
||||
myProject));
|
||||
WriteCommandAction.writeCommandAction(getProject()).run(
|
||||
() -> {
|
||||
PsiDirectory targetDirectory =
|
||||
getPsiManager().findDirectory(myFixture.getTempDirFixture().findOrCreateDir(""));
|
||||
Map<PsiFile, PsiClass[]> sourceClasses =
|
||||
Collections.singletonMap(oldClass.getNavigationElement().getContainingFile(),
|
||||
new PsiClass[]{oldClass});
|
||||
CopyClassesHandler.doCopyClasses(sourceClasses, copyName, targetDirectory, getProject());
|
||||
getProject().getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
});
|
||||
}
|
||||
|
||||
public void testPackageLocalClasses() throws Exception {
|
||||
public void testPackageLocalClasses() {
|
||||
doMultifileTest();
|
||||
}
|
||||
|
||||
public void testPackageLocalMethods() throws Exception {
|
||||
public void testPackageLocalMethods() {
|
||||
doMultifileTest();
|
||||
}
|
||||
|
||||
public void testPackageLocalAndExtends() throws Exception {
|
||||
public void testPackageLocalAndExtends() {
|
||||
doMultifileTest();
|
||||
}
|
||||
|
||||
//copy all classes from p1 -> p2
|
||||
private void doMultifileTest() throws Exception {
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
|
||||
String rootBefore = root + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
VirtualFile rootDir = createTestProjectStructure(rootBefore);
|
||||
|
||||
final HashMap<PsiFile, PsiClass[]> map = new HashMap<>();
|
||||
final VirtualFile sourceDir = rootDir.findChild("p1");
|
||||
for (VirtualFile file : sourceDir.getChildren()) {
|
||||
final PsiFile psiFile = myPsiManager.findFile(file);
|
||||
if (psiFile instanceof PsiJavaFile) {
|
||||
map.put(psiFile, ((PsiJavaFile)psiFile).getClasses());
|
||||
private void doMultifileTest() {
|
||||
doTest(() -> {
|
||||
final HashMap<PsiFile, PsiClass[]> map = new HashMap<>();
|
||||
final VirtualFile sourceDir = myFixture.findFileInTempDir("p1");
|
||||
for (VirtualFile file : sourceDir.getChildren()) {
|
||||
final PsiFile psiFile = getPsiManager().findFile(file);
|
||||
if (psiFile instanceof PsiJavaFile) {
|
||||
map.put(psiFile, ((PsiJavaFile)psiFile).getClasses());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final VirtualFile targetVDir = rootDir.findChild("p2");
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
CopyClassesHandler.doCopyClasses(map, null, myPsiManager.findDirectory(targetVDir), myProject);
|
||||
});
|
||||
|
||||
|
||||
String rootAfter = root + "/after";
|
||||
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
|
||||
ApplicationManager.getApplication().runWriteAction(() -> myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting());
|
||||
|
||||
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
|
||||
final VirtualFile targetVDir = myFixture.findFileInTempDir("p2");
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
|
||||
CopyClassesHandler.doCopyClasses(map, null, getPsiManager().findDirectory(targetVDir), getProject());
|
||||
});
|
||||
}, "multifile/" + getTestName(true));
|
||||
}
|
||||
|
||||
public void testPackageHierarchy() throws Exception {
|
||||
public void testPackageHierarchy() {
|
||||
doPackageCopy();
|
||||
}
|
||||
|
||||
public void testPackageOneLevelHierarchy() throws Exception {
|
||||
public void testPackageOneLevelHierarchy() {
|
||||
doPackageCopy();
|
||||
}
|
||||
|
||||
private void doPackageCopy() throws Exception {
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
|
||||
String rootBefore = root + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
VirtualFile rootDir = createTestProjectStructure(rootBefore);
|
||||
|
||||
final VirtualFile targetVDir = rootDir.findChild("p2");
|
||||
final PsiDirectory sourceP1Dir = myPsiManager.findDirectory(rootDir.findChild("p1"));
|
||||
final PsiDirectory targetP2Dir = myPsiManager.findDirectory(targetVDir);
|
||||
new CopyClassesHandler().doCopy(new PsiElement[]{sourceP1Dir}, targetP2Dir);
|
||||
|
||||
String rootAfter = root + "/after";
|
||||
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
|
||||
private void doPackageCopy() {
|
||||
doTest(() -> {
|
||||
final PsiDirectory sourceP1Dir = getPsiManager().findDirectory(myFixture.findFileInTempDir("p1"));
|
||||
final PsiDirectory targetP2Dir = getPsiManager().findDirectory(myFixture.findFileInTempDir("p2"));
|
||||
new CopyClassesHandler().doCopy(new PsiElement[]{sourceP1Dir}, targetP2Dir);
|
||||
}, "multifile/" + getTestName(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,16 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.copy.CopyHandler;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
|
||||
public class CopyTest extends CodeInsightTestCase {
|
||||
|
||||
private String getRoot() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/copy/multifile/" + getTestName(true);
|
||||
public class CopyTest extends LightCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/copy/multifile/";
|
||||
}
|
||||
|
||||
public void testCopyAvailable() throws Exception {
|
||||
@@ -25,27 +23,22 @@ public class CopyTest extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
String rootBefore = getRoot();
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
createTestProjectStructure(rootBefore);
|
||||
PsiPackage pack1 = myJavaFacade.findPackage("pack1");
|
||||
PsiPackage pack2 = myJavaFacade.findPackage("pack2");
|
||||
myFixture.copyDirectoryToProject(getTestName(true), "");
|
||||
PsiPackage pack1 = myFixture.findPackage("pack1");
|
||||
PsiPackage pack2 = myFixture.findPackage("pack2");
|
||||
assertTrue(CopyHandler.canCopy(new PsiElement[]{pack1.getDirectories()[0], pack2.getDirectories()[0]}));
|
||||
}
|
||||
|
||||
public void testMultipleClasses() throws Exception {
|
||||
String rootBefore = getRoot();
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
final VirtualFile root = createTestProjectStructure(rootBefore);
|
||||
final PsiClass aClass = myJavaFacade.findClass("pack1.Klass");
|
||||
assertNotNull(aClass);
|
||||
|
||||
VirtualFile root = myFixture.copyDirectoryToProject(getTestName(true), "");
|
||||
final PsiClass aClass = myFixture.findClass("pack1.Klass");
|
||||
|
||||
final PsiFile containingFile = aClass.getContainingFile();
|
||||
|
||||
assertTrue(CopyHandler.canCopy(new PsiElement[]{containingFile}));
|
||||
assertFalse(CopyHandler.canClone(new PsiElement[]{containingFile}));
|
||||
|
||||
PsiPackage pack2 = myJavaFacade.findPackage("pack2");
|
||||
PsiPackage pack2 = myFixture.findPackage("pack2");
|
||||
final PsiDirectory targetDirectory = pack2.getDirectories()[0];
|
||||
CopyHandler.doCopy(new PsiElement[]{containingFile}, targetDirectory);
|
||||
|
||||
@@ -56,23 +49,21 @@ public class CopyTest extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testMultipleFiles() throws Exception {
|
||||
String rootBefore = getRoot();
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
final VirtualFile root = createTestProjectStructure(rootBefore);
|
||||
VirtualFile root = myFixture.copyDirectoryToProject(getTestName(true), "");
|
||||
|
||||
final VirtualFile first = root.findFileByRelativePath("from/1.txt");
|
||||
assertNotNull(first);
|
||||
final VirtualFile second = root.findFileByRelativePath("from/2.txt");
|
||||
assertNotNull(second);
|
||||
|
||||
final PsiFile firstPsi = myPsiManager.findFile(first);
|
||||
final PsiFile secondPsi = myPsiManager.findFile(second);
|
||||
final PsiFile firstPsi = getPsiManager().findFile(first);
|
||||
final PsiFile secondPsi = getPsiManager().findFile(second);
|
||||
|
||||
assertTrue(CopyHandler.canCopy(new PsiElement[]{firstPsi, secondPsi}));
|
||||
|
||||
final VirtualFile toDir = root.findChild("to");
|
||||
assertNotNull(toDir);
|
||||
final PsiDirectory targetDirectory = myPsiManager.findDirectory(toDir);
|
||||
final PsiDirectory targetDirectory = getPsiManager().findDirectory(toDir);
|
||||
|
||||
CopyHandler.doCopy(new PsiElement[]{firstPsi, secondPsi}, targetDirectory);
|
||||
|
||||
@@ -81,20 +72,17 @@ public class CopyTest extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testPackageInfo() throws Exception {
|
||||
String rootBefore = getRoot();
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
final VirtualFile root = createTestProjectStructure(rootBefore);
|
||||
|
||||
VirtualFile root = myFixture.copyDirectoryToProject(getTestName(true), "");
|
||||
final VirtualFile first = root.findFileByRelativePath("from/package-info.java");
|
||||
assertNotNull(first);
|
||||
|
||||
final PsiFile firstPsi = myPsiManager.findFile(first);
|
||||
|
||||
final PsiFile firstPsi = getPsiManager().findFile(first);
|
||||
|
||||
assertTrue(CopyHandler.canCopy(new PsiElement[]{firstPsi}));
|
||||
|
||||
final VirtualFile toDir = root.findChild("to");
|
||||
assertNotNull(toDir);
|
||||
final PsiDirectory targetDirectory = myPsiManager.findDirectory(toDir);
|
||||
final PsiDirectory targetDirectory = getPsiManager().findDirectory(toDir);
|
||||
|
||||
CopyHandler.doCopy(new PsiElement[]{firstPsi}, targetDirectory);
|
||||
|
||||
|
||||
@@ -15,43 +15,36 @@
|
||||
*/
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.move.MoveHandler;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
*/
|
||||
public class DndMoveTest extends CodeInsightTestCase {
|
||||
@NotNull
|
||||
public class DndMoveTest extends LightCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/dndMove/";
|
||||
protected String getTestDataPath() {
|
||||
return PathManagerEx.getTestDataPath() + "/refactoring/dndMove/";
|
||||
}
|
||||
|
||||
public void testPublicJavaClass() throws Exception {
|
||||
doTest("d", () -> getJavaFacade().findClass("d.MyClass"), true);
|
||||
public void testPublicJavaClass() {
|
||||
doTest("d", () -> myFixture.findClass("d.MyClass"), true);
|
||||
}
|
||||
|
||||
public void testSecondJavaClass() throws Exception {
|
||||
doTest("d", () -> getJavaFacade().findClass("d.Second"), false);
|
||||
public void testSecondJavaClass() {
|
||||
doTest("d", () -> myFixture.findClass("d.Second"), false);
|
||||
}
|
||||
|
||||
private void doTest(final String targetDirName, final Computable<PsiElement> source, final boolean expected) throws Exception {
|
||||
String testName = getTestName(true);
|
||||
String root = getTestDataPath() + getTestRoot() + testName;
|
||||
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete, false);
|
||||
PsiTestUtil.addSourceContentToRoots(myModule, rootDir);
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
private void doTest(final String targetDirName, final Computable<PsiElement> source, final boolean expected) {
|
||||
VirtualFile rootDir = myFixture.copyDirectoryToProject(getTestName(true), "");
|
||||
final VirtualFile child1 = rootDir.findChild(targetDirName);
|
||||
assertNotNull("File " + targetDirName + " not found", child1);
|
||||
final PsiDirectory targetDirectory = myPsiManager.findDirectory(child1);
|
||||
final PsiDirectory targetDirectory = getPsiManager().findDirectory(child1);
|
||||
assertEquals(expected, MoveHandler.isMoveRedundant(source.compute(), targetDirectory));
|
||||
}
|
||||
}
|
||||
@@ -17,35 +17,25 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.extractclass.ExtractClassProcessor;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class ExtractClassTest extends MultiFileTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/extractClass/";
|
||||
}
|
||||
|
||||
public class ExtractClassTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/extractClass/";
|
||||
}
|
||||
|
||||
private void doTestMethod() {
|
||||
@@ -63,8 +53,8 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
private void doTestMethod(final String methodName,
|
||||
final String conflicts,
|
||||
final String qualifiedName) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass(qualifiedName, GlobalSearchScope.projectScope(myProject));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass(qualifiedName);
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
@@ -160,8 +150,8 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTestFieldAndMethod(final String methodName) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
@@ -180,8 +170,8 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTestField(final String conflicts, final boolean generateGettersSetters) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
@@ -195,8 +185,8 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void testInnerClass() {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
@@ -225,8 +215,6 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, methods, new ArrayList<>(), StringUtil.getPackageName(aClass.getQualifiedName()), null,
|
||||
"Extracted", null, generateGettersSetters, Collections.emptyList(), inner);
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
if (conflicts != null) {
|
||||
@@ -261,8 +249,8 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void testPublicFieldDelegation() {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
@@ -271,14 +259,12 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
|
||||
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, new ArrayList<>(), new ArrayList<>(), "", "Extracted");
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
private void doTestInnerClass() {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
@@ -286,8 +272,6 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
classes.add(aClass.findInnerClassByName("Inner", false));
|
||||
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, new ArrayList<>(), new ArrayList<>(), classes, "", "Extracted");
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -324,8 +308,8 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void testPublicVisibility() {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
@@ -338,8 +322,6 @@ public class ExtractClassTest extends MultiFileTestCase {
|
||||
final ExtractClassProcessor processor =
|
||||
new ExtractClassProcessor(aClass, fields, methods, new ArrayList<>(), "", null, "Extracted", PsiModifier.PUBLIC, false, Collections.emptyList(), false);
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -16,30 +16,27 @@
|
||||
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.extractclass.ExtractClassProcessor;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class ExtractEnumTest extends MultiFileTestCase {
|
||||
|
||||
@NotNull
|
||||
public class ExtractEnumTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/extractEnum/";
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/extractEnum/";
|
||||
}
|
||||
|
||||
|
||||
public void testOneConstant() {
|
||||
doTest(new RefactoringTestUtil.MemberDescriptor("FOO", PsiField.class, true));
|
||||
}
|
||||
@@ -151,8 +148,8 @@ public class ExtractEnumTest extends MultiFileTestCase {
|
||||
private void doTest(final String conflicts,
|
||||
final boolean generateAccessors,
|
||||
final RefactoringTestUtil.MemberDescriptor... memberDescriptors) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest(() -> {
|
||||
final PsiClass aClass = myFixture.findClass("Test");
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final ArrayList<PsiField> fields = new ArrayList<>();
|
||||
|
||||
@@ -3,28 +3,19 @@ package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.refactoring.RefactoringTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.extractSuperclass.ExtractSuperClassProcessor;
|
||||
import com.intellij.refactoring.extractSuperclass.ExtractSuperClassUtil;
|
||||
import com.intellij.refactoring.memberPullUp.PullUpConflictsUtil;
|
||||
import com.intellij.refactoring.memberPullUp.PullUpProcessor;
|
||||
import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -32,142 +23,137 @@ import java.util.HashSet;
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class ExtractSuperClassTest extends RefactoringTestCase {
|
||||
public void testFinalFieldInitialization() throws Exception { // IDEADEV-19704
|
||||
public class ExtractSuperClassTest extends LightMultiFileTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_1_5;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/extractSuperClass/";
|
||||
}
|
||||
|
||||
public void testFinalFieldInitialization() { // IDEADEV-19704
|
||||
doTest("Test", "TestSubclass", new RefactoringTestUtil.MemberDescriptor("X", PsiClass.class),
|
||||
new RefactoringTestUtil.MemberDescriptor("x", PsiField.class));
|
||||
}
|
||||
|
||||
public void testFieldInitializationWithCast() throws Exception {
|
||||
public void testFieldInitializationWithCast() {
|
||||
doTest("Test", "TestSubclass", new RefactoringTestUtil.MemberDescriptor("x", PsiField.class));
|
||||
}
|
||||
|
||||
public void testMethodTypeParameter() throws Exception {
|
||||
public void testMethodTypeParameter() {
|
||||
doTest("Test", "TestSubclass", new RefactoringTestUtil.MemberDescriptor("m", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testMultipleTypeParameters() throws Exception {
|
||||
public void testMultipleTypeParameters() {
|
||||
doTest("Test", "TestSubclass", new RefactoringTestUtil.MemberDescriptor("m", PsiMethod.class));
|
||||
}
|
||||
|
||||
|
||||
public void testEmptyForeach() throws Exception {
|
||||
public void testEmptyForeach() {
|
||||
doTest("Test", "TestSubclass", new RefactoringTestUtil.MemberDescriptor("m", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testConflictUsingPrivateMethod() throws Exception {
|
||||
public void testConflictUsingPrivateMethod() {
|
||||
doTest("Test", "TestSubclass",
|
||||
new String[] {"Method <b><code>Test.foo()</code></b> is private and will not be accessible from method <b><code>x()</code></b>."},
|
||||
new RefactoringTestUtil.MemberDescriptor("x", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testConflictMoveAbstractWithPrivateMethod() throws Exception {
|
||||
public void testConflictMoveAbstractWithPrivateMethod() {
|
||||
doTest("Test", "TestSubclass",
|
||||
new String[] {"Method <b><code>x()</code></b> uses method <b><code>Test.xx()</code></b> which won't be accessible from the subclass."},
|
||||
new RefactoringTestUtil.MemberDescriptor("x", PsiMethod.class, true),
|
||||
new RefactoringTestUtil.MemberDescriptor("xx", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testConflictAbstractPackageLocalMethod() throws Exception {
|
||||
public void testConflictAbstractPackageLocalMethod() {
|
||||
doTest("a.Test", "TestSubclass",
|
||||
new String[] {"Can't make method <b><code>x()</code></b> abstract as it won't be accessible from the subclass."},
|
||||
"b",
|
||||
new RefactoringTestUtil.MemberDescriptor("x", PsiMethod.class, true));
|
||||
}
|
||||
|
||||
public void testConflictUsingPackageLocalMethod() throws Exception {
|
||||
public void testConflictUsingPackageLocalMethod() {
|
||||
doTest("a.Test", "TestSubclass",
|
||||
new String[] {"method <b><code>Sup.foo()</code></b> won't be accessible"},
|
||||
"b",
|
||||
new RefactoringTestUtil.MemberDescriptor("x", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testConflictUsingPackageLocalSuperClass() throws Exception {
|
||||
public void testConflictUsingPackageLocalSuperClass() {
|
||||
doTest("a.Test", "TestSubclass",
|
||||
new String[] {"class <b><code>a.Sup</code></b> won't be accessible from package <b><code>b</code></b>"},
|
||||
"b",
|
||||
new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testNoConflictUsingProtectedMethodFromSuper() throws Exception {
|
||||
public void testNoConflictUsingProtectedMethodFromSuper() {
|
||||
doTest("Test", "TestSubclass",
|
||||
new RefactoringTestUtil.MemberDescriptor("x", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testParameterNameEqualsFieldName() throws Exception { // IDEADEV-10629
|
||||
public void testParameterNameEqualsFieldName() { // IDEADEV-10629
|
||||
doTest("Test", "TestSubclass", new RefactoringTestUtil.MemberDescriptor("a", PsiField.class), new RefactoringTestUtil.MemberDescriptor("b", PsiField.class));
|
||||
}
|
||||
|
||||
public void testSameTypeParameterName() throws Exception {
|
||||
public void testSameTypeParameterName() {
|
||||
doTest("Test", "TestSubclass", new RefactoringTestUtil.MemberDescriptor("A", PsiClass.class), new RefactoringTestUtil.MemberDescriptor("B", PsiClass.class));
|
||||
}
|
||||
|
||||
public void testExtendsLibraryClass() throws Exception {
|
||||
public void testExtendsLibraryClass() {
|
||||
doTest("Test", "TestSubclass");
|
||||
}
|
||||
|
||||
public void testRequiredImportRemoved() throws Exception {
|
||||
public void testRequiredImportRemoved() {
|
||||
doTest("foo.impl.B", "BImpl", new RefactoringTestUtil.MemberDescriptor("getInstance", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testSubstituteGenerics() throws Exception {
|
||||
public void testSubstituteGenerics() {
|
||||
doTest("B", "AB");
|
||||
}
|
||||
|
||||
public void testExtendsList() throws Exception {
|
||||
public void testExtendsList() {
|
||||
doTest("Test", "TestSubclass", new RefactoringTestUtil.MemberDescriptor("List", PsiClass.class));
|
||||
}
|
||||
|
||||
public void testImportsCorruption() throws Exception {
|
||||
public void testImportsCorruption() {
|
||||
doTest("p1.A", "AA", new RefactoringTestUtil.MemberDescriptor("m1", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testAnonymClass() throws Exception {
|
||||
String rootBefore = getRoot() + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk14());
|
||||
final VirtualFile rootDir = createTestProjectStructure(rootBefore);
|
||||
PsiClass psiClass = myJavaFacade.findClass("Test", ProjectScope.getAllScope(myProject));
|
||||
assertNotNull(psiClass);
|
||||
final PsiField[] fields = psiClass.getFields();
|
||||
assertTrue(fields.length == 1);
|
||||
final PsiExpression initializer = fields[0].getInitializer();
|
||||
assertNotNull(initializer);
|
||||
assertInstanceOf(initializer, PsiNewExpression.class);
|
||||
final PsiAnonymousClass anonymousClass = ((PsiNewExpression)initializer).getAnonymousClass();
|
||||
assertNotNull(anonymousClass);
|
||||
final ArrayList<MemberInfo> infos = new ArrayList<>();
|
||||
MemberInfo.extractClassMembers(anonymousClass, infos, member -> true, false);
|
||||
for (MemberInfo info : infos) {
|
||||
info.setChecked(true);
|
||||
}
|
||||
WriteCommandAction.writeCommandAction(myProject).run(() -> ExtractSuperClassUtil
|
||||
.extractSuperClass(myProject, psiClass.getContainingFile().getContainingDirectory(), "TestSubclass", anonymousClass,
|
||||
infos.toArray(new MemberInfo[0]), new DocCommentPolicy(DocCommentPolicy.ASIS)));
|
||||
String rootAfter = getRoot() + "/after";
|
||||
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
LanguageLevelProjectExtension.getInstance(myJavaFacade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
}
|
||||
|
||||
@NonNls
|
||||
private String getRoot() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/extractSuperClass/" + getTestName(true);
|
||||
public void testAnonymClass() {
|
||||
doTest(() -> {
|
||||
PsiClass psiClass = myFixture.findClass("Test");
|
||||
assertNotNull(psiClass);
|
||||
final PsiField[] fields = psiClass.getFields();
|
||||
assertEquals(1, fields.length);
|
||||
final PsiExpression initializer = fields[0].getInitializer();
|
||||
assertNotNull(initializer);
|
||||
assertInstanceOf(initializer, PsiNewExpression.class);
|
||||
final PsiAnonymousClass anonymousClass = ((PsiNewExpression)initializer).getAnonymousClass();
|
||||
assertNotNull(anonymousClass);
|
||||
final ArrayList<MemberInfo> infos = new ArrayList<>();
|
||||
MemberInfo.extractClassMembers(anonymousClass, infos, member -> true, false);
|
||||
for (MemberInfo info : infos) {
|
||||
info.setChecked(true);
|
||||
}
|
||||
WriteCommandAction.writeCommandAction(getProject()).run(() -> ExtractSuperClassUtil
|
||||
.extractSuperClass(getProject(), psiClass.getContainingFile().getContainingDirectory(), "TestSubclass", anonymousClass,
|
||||
infos.toArray(new MemberInfo[0]), new DocCommentPolicy(DocCommentPolicy.ASIS)));
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String className, @NonNls final String newClassName,
|
||||
RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception {
|
||||
RefactoringTestUtil.MemberDescriptor... membersToFind) {
|
||||
doTest(className, newClassName, null, membersToFind);
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String className, @NonNls final String newClassName,
|
||||
String[] conflicts,
|
||||
RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception {
|
||||
RefactoringTestUtil.MemberDescriptor... membersToFind) {
|
||||
doTest(className, newClassName, conflicts, null, membersToFind);
|
||||
}
|
||||
|
||||
@@ -175,31 +161,29 @@ public class ExtractSuperClassTest extends RefactoringTestCase {
|
||||
@NonNls final String newClassName,
|
||||
String[] conflicts,
|
||||
String targetPackageName,
|
||||
RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception {
|
||||
String rootBefore = getRoot() + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk14());
|
||||
final VirtualFile rootDir = createTestProjectStructure(rootBefore);
|
||||
PsiClass psiClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
|
||||
assertNotNull(psiClass);
|
||||
final MemberInfo[] members = RefactoringTestUtil.findMembers(psiClass, membersToFind);
|
||||
doTest(members, newClassName, targetPackageName, rootDir, psiClass, conflicts);
|
||||
RefactoringTestUtil.MemberDescriptor... membersToFind) {
|
||||
doTest(() -> {
|
||||
PsiClass psiClass = myFixture.findClass(className);
|
||||
assertNotNull(psiClass);
|
||||
final MemberInfo[] members = RefactoringTestUtil.findMembers(psiClass, membersToFind);
|
||||
doTest(members, newClassName, targetPackageName, psiClass, conflicts);
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest(MemberInfo[] members,
|
||||
@NonNls String newClassName,
|
||||
String targetPackageName,
|
||||
VirtualFile rootDir,
|
||||
PsiClass psiClass,
|
||||
String[] conflicts) throws IOException {
|
||||
String[] conflicts) {
|
||||
PsiDirectory targetDirectory;
|
||||
if (targetPackageName == null) {
|
||||
targetDirectory = psiClass.getContainingFile().getContainingDirectory();
|
||||
} else {
|
||||
final PsiPackage aPackage = myJavaFacade.findPackage(targetPackageName);
|
||||
final PsiPackage aPackage = myFixture.findPackage(targetPackageName);
|
||||
assertNotNull(aPackage);
|
||||
targetDirectory = aPackage.getDirectories()[0];
|
||||
}
|
||||
ExtractSuperClassProcessor processor = new ExtractSuperClassProcessor(myProject,
|
||||
ExtractSuperClassProcessor processor = new ExtractSuperClassProcessor(getProject(),
|
||||
targetDirectory,
|
||||
newClassName,
|
||||
psiClass, members,
|
||||
@@ -232,12 +216,5 @@ public class ExtractSuperClassTest extends RefactoringTestCase {
|
||||
fail("Unexpected conflicts!!!");
|
||||
}
|
||||
processor.run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
|
||||
String rootAfter = getRoot() + "/after";
|
||||
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-23
@@ -18,12 +18,11 @@ package com.intellij.java.refactoring;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.inheritanceToDelegation.InheritanceToDelegationProcessor;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -31,16 +30,10 @@ import java.util.List;
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class InheritanceToDelegationTest extends MultiFileTestCase {
|
||||
public class InheritanceToDelegationTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/inheritanceToDelegation/";
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/inheritanceToDelegation/";
|
||||
}
|
||||
|
||||
public void testSimpleInsertion() {
|
||||
@@ -135,14 +128,14 @@ public class InheritanceToDelegationTest extends MultiFileTestCase {
|
||||
doTest(createPerformAction("A", "myDelegate", "MyIntf", "Intf", new int[]{}, ArrayUtil.EMPTY_STRING_ARRAY, true, false));
|
||||
}
|
||||
|
||||
private PerformAction createPerformAction(
|
||||
private ThrowableRunnable<Exception> createPerformAction(
|
||||
final String className, final String fieldName, final String innerClassName,
|
||||
final String baseClassName, final int[] methodIndices, final String[] delegatedInterfaceNames,
|
||||
final boolean delegateOtherMembers, final boolean generateGetter) {
|
||||
return (rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
return () -> {
|
||||
PsiClass aClass = myFixture.findClass(className);
|
||||
assertNotNull("Class " + className + " not found", aClass);
|
||||
PsiClass baseClass = myJavaFacade.findClass(baseClassName, GlobalSearchScope.allScope(getProject()));
|
||||
PsiClass baseClass = myFixture.findClass(baseClassName);
|
||||
assertNotNull("Base class " + baseClassName + " not found", baseClass);
|
||||
final PsiMethod[] methods = baseClass.getMethods();
|
||||
final PsiMethod[] delegatedMethods = new PsiMethod[methodIndices.length];
|
||||
@@ -152,25 +145,25 @@ public class InheritanceToDelegationTest extends MultiFileTestCase {
|
||||
final PsiClass[] delegatedInterfaces = new PsiClass[delegatedInterfaceNames.length];
|
||||
for (int i = 0; i < delegatedInterfaceNames.length; i++) {
|
||||
String delegatedInterfaceName = delegatedInterfaceNames[i];
|
||||
PsiClass anInterface = myJavaFacade.findClass(delegatedInterfaceName, GlobalSearchScope.allScope(getProject()));
|
||||
PsiClass anInterface = myFixture.findClass(delegatedInterfaceName);
|
||||
assertNotNull(anInterface);
|
||||
delegatedInterfaces[i] = anInterface;
|
||||
}
|
||||
new InheritanceToDelegationProcessor(
|
||||
myProject,
|
||||
getProject(),
|
||||
aClass, baseClass, fieldName, innerClassName, delegatedInterfaces, delegatedMethods, delegateOtherMembers,
|
||||
generateGetter).run();
|
||||
};
|
||||
}
|
||||
|
||||
private PerformAction createPerformAction2(
|
||||
private ThrowableRunnable<Exception> createPerformAction2(
|
||||
final String className, final String fieldName, final String innerClassName,
|
||||
final String baseClassName, final String[] methodNames, final String[] delegatedInterfaceNames,
|
||||
final boolean delegateOtherMembers, final boolean generateGetter) {
|
||||
return (rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
return () -> {
|
||||
PsiClass aClass = myFixture.findClass(className);
|
||||
assertNotNull("Class " + className + " not found", aClass);
|
||||
PsiClass baseClass = myJavaFacade.findClass(baseClassName, GlobalSearchScope.allScope(getProject()));
|
||||
PsiClass baseClass = myFixture.findClass(baseClassName);
|
||||
assertNotNull("Base class " + baseClassName + " not found", baseClass);
|
||||
final PsiMethod[] delegatedMethods;
|
||||
final List<PsiMethod> methodsList = new ArrayList<>();
|
||||
@@ -183,12 +176,12 @@ public class InheritanceToDelegationTest extends MultiFileTestCase {
|
||||
final PsiClass[] delegatedInterfaces = new PsiClass[delegatedInterfaceNames.length];
|
||||
for (int i = 0; i < delegatedInterfaceNames.length; i++) {
|
||||
String delegatedInterfaceName = delegatedInterfaceNames[i];
|
||||
PsiClass anInterface = myJavaFacade.findClass(delegatedInterfaceName, GlobalSearchScope.allScope(getProject()));
|
||||
PsiClass anInterface = myFixture.findClass(delegatedInterfaceName);
|
||||
assertNotNull(anInterface);
|
||||
delegatedInterfaces[i] = anInterface;
|
||||
}
|
||||
new InheritanceToDelegationProcessor(
|
||||
myProject,
|
||||
getProject(),
|
||||
aClass, baseClass, fieldName, innerClassName, delegatedInterfaces, delegatedMethods, delegateOtherMembers,
|
||||
generateGetter).run();
|
||||
//FileDocumentManager.getInstance().saveAllDocuments();
|
||||
|
||||
@@ -19,24 +19,17 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.inlineSuperClass.InlineSuperClassRefactoringProcessor;
|
||||
import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
*/
|
||||
public class InlineSuperClassTest extends MultiFileTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/inlineSuperClass/";
|
||||
}
|
||||
|
||||
public class InlineSuperClassTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/inlineSuperClass/";
|
||||
}
|
||||
|
||||
public void testInlineOneClass() { doTest(false, true); }
|
||||
@@ -90,15 +83,15 @@ public class InlineSuperClassTest extends MultiFileTestCase {
|
||||
|
||||
private void doTest(boolean fail, final boolean inlineOne) {
|
||||
try {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", scope);
|
||||
if (aClass == null) aClass = myJavaFacade.findClass("p.Test", scope);
|
||||
doTest(() -> {
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
|
||||
PsiClass aClass = myFixture.getJavaFacade().findClass("Test", scope);
|
||||
if (aClass == null) aClass = myFixture.getJavaFacade().findClass("p.Test", scope);
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
PsiClass superClass = myJavaFacade.findClass("Super", scope);
|
||||
if (superClass == null) superClass = myJavaFacade.findClass("p1.Super", scope);
|
||||
PsiClass superClass = myFixture.getJavaFacade().findClass("Super", scope);
|
||||
if (superClass == null) superClass = myFixture.getJavaFacade().findClass("p1.Super", scope);
|
||||
assertNotNull("Class Super not found", superClass);
|
||||
new InlineSuperClassRefactoringProcessor(myProject, inlineOne ? aClass : null, superClass, DocCommentPolicy.ASIS).run();
|
||||
new InlineSuperClassRefactoringProcessor(getProject(), inlineOne ? aClass : null, superClass, DocCommentPolicy.ASIS).run();
|
||||
});
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
@@ -115,12 +108,12 @@ public class InlineSuperClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTestMultipleSubclasses() {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
|
||||
PsiClass superClass = myJavaFacade.findClass("Super", scope);
|
||||
if (superClass == null) superClass = myJavaFacade.findClass("p1.Super", scope);
|
||||
doTest(() -> {
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
|
||||
PsiClass superClass = myFixture.getJavaFacade().findClass("Super", scope);
|
||||
if (superClass == null) superClass = myFixture.getJavaFacade().findClass("p1.Super", scope);
|
||||
assertNotNull("Class Super not found", superClass);
|
||||
new InlineSuperClassRefactoringProcessor(myProject, null, superClass, DocCommentPolicy.ASIS).run();
|
||||
new InlineSuperClassRefactoringProcessor(getProject(), null, superClass, DocCommentPolicy.ASIS).run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+9
-16
@@ -24,7 +24,7 @@ import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.changeSignature.JavaMethodDescriptor;
|
||||
import com.intellij.refactoring.changeSignature.ParameterInfoImpl;
|
||||
import com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectProcessor;
|
||||
@@ -35,15 +35,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IntroduceParameterObjectTest extends MultiFileTestCase {
|
||||
public class IntroduceParameterObjectTest extends LightMultiFileTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/introduceParameterObject/";
|
||||
}
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/introduceParameterObject/";
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
@@ -57,11 +53,8 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase {
|
||||
private void doTest(final boolean delegate,
|
||||
final boolean createInner,
|
||||
final Function<PsiMethod, ParameterInfoImpl[]> function) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
final PsiMethod method = aClass.findMethodsByName("foo", false)[0];
|
||||
final ParameterInfoImpl[] datas = function.fun(method);
|
||||
|
||||
@@ -181,7 +174,7 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase {
|
||||
public void testTypeParametersWithChosenSubtype() {
|
||||
doTest(false, true, psiMethod -> {
|
||||
final PsiParameter parameter = psiMethod.getParameterList().getParameters()[0];
|
||||
final PsiClass collectionClass = getJavaFacade().findClass(CommonClassNames.JAVA_UTIL_COLLECTION);
|
||||
final PsiClass collectionClass = myFixture.findClass(CommonClassNames.JAVA_UTIL_COLLECTION);
|
||||
final ParameterInfoImpl variableData =
|
||||
new ParameterInfoImpl(0, parameter.getName(), JavaPsiFacade.getElementFactory(getProject()).createType(collectionClass));
|
||||
return new ParameterInfoImpl[]{variableData};
|
||||
@@ -211,10 +204,10 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase {
|
||||
final boolean generateAccessors,
|
||||
final String newVisibility,
|
||||
final Function<PsiMethod, ParameterInfoImpl[]> function) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.getJavaFacade().findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
if (aClass == null) {
|
||||
aClass = myJavaFacade.findClass("p2.Test", GlobalSearchScope.projectScope(getProject()));
|
||||
aClass = myFixture.getJavaFacade().findClass("p2.Test", GlobalSearchScope.projectScope(getProject()));
|
||||
}
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
|
||||
+14
-28
@@ -16,40 +16,30 @@
|
||||
package com.intellij.java.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.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
@PlatformTestCase.WrapInCommand
|
||||
public class IntroduceVariableMultifileTest extends MultiFileTestCase {
|
||||
public class IntroduceVariableMultifileTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
LanguageLevelProjectExtension.getInstance(myJavaFacade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/introduceVariable/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/introduceVariable/";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_1_5;
|
||||
}
|
||||
|
||||
public void testSamePackageRef() {
|
||||
@@ -94,18 +84,14 @@ public class IntroduceVariableMultifileTest extends MultiFileTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
PerformAction createAction(final String className, final IntroduceVariableBase testMe) {
|
||||
return (vroot, rootAfter) -> {
|
||||
final JavaPsiFacade psiManager = getJavaFacade();
|
||||
final PsiClass aClass = psiManager.findClass(className, GlobalSearchScope.allScope(myProject));
|
||||
assertTrue(className + " class not found", aClass != null);
|
||||
ThrowableRunnable<Exception> createAction(final String className, final IntroduceVariableBase testMe) {
|
||||
return () -> {
|
||||
final PsiClass aClass = myFixture.findClass(className);
|
||||
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();
|
||||
assertNotNull(virtualFile);
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile);
|
||||
testMe.invoke(getProject(), getEditor(), containingFile, null);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,78 +2,59 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.RefactoringTestCase;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.move.moveFilesOrDirectories.JavaMoveFilesOrDirectoriesHandler;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class MoveClassAndFileTest extends RefactoringTestCase {
|
||||
|
||||
public void testAllClassesInFile() throws Exception {
|
||||
doTest("allClassesInFile", "t", "txt2move.txt", "s.MyClass", "s.MyOneMoreClass");
|
||||
public class MoveClassAndFileTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClassAndFile/";
|
||||
}
|
||||
|
||||
public void testOnlyPackageLocalClass() throws Exception {
|
||||
doTest("onlyPackageLocalClass", "t", "txt2move.txt", "s.MyLocal");
|
||||
public void testAllClassesInFile() {
|
||||
doTest("t", "txt2move.txt", "s.MyClass", "s.MyOneMoreClass");
|
||||
}
|
||||
|
||||
public void testPackageInfo() throws Exception {
|
||||
doTest("classAndPackageInfo", "t", "package-info.java", "s.MyClass");
|
||||
public void testOnlyPackageLocalClass() {
|
||||
doTest("t", "txt2move.txt", "s.MyLocal");
|
||||
}
|
||||
|
||||
public void testLeavePackageLocalClass() throws Exception {
|
||||
doTest("leavePackageLocalClass", "t", "txt2move.txt", "s.MyClass");
|
||||
public void testClassAndPackageInfo() {
|
||||
doTest("t", "package-info.java", "s.MyClass");
|
||||
}
|
||||
|
||||
public void testNestedClassesInFile() throws Exception {
|
||||
doTest("nestedClassesInFile", "t", null, "s.MyClass.F1", "s.MyClass.F2");
|
||||
public void testLeavePackageLocalClass() {
|
||||
doTest("t", "txt2move.txt", "s.MyClass");
|
||||
}
|
||||
|
||||
private void doTest(String testName, String newPackageName, String fileNameNearFirstClass, String... classNames) throws Exception {
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClassAndFile/" + testName;
|
||||
public void testNestedClassesInFile() {
|
||||
doTest("t", null, "s.MyClass.F1", "s.MyClass.F2");
|
||||
}
|
||||
|
||||
String rootBefore = root + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
VirtualFile rootDir = createTestProjectStructure(rootBefore);
|
||||
|
||||
performAction(newPackageName, fileNameNearFirstClass, classNames);
|
||||
|
||||
String rootAfter = root + "/after";
|
||||
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
|
||||
private void doTest(String newPackageName, String fileNameNearFirstClass, String... classNames) {
|
||||
doTest(() -> performAction(newPackageName, fileNameNearFirstClass, classNames));
|
||||
}
|
||||
|
||||
private void performAction(String newPackageName, String fileName, String... classNames) {
|
||||
final PsiElement[] elements = new PsiElement[classNames.length + (fileName != null ? 1 : 0)];
|
||||
for(int i = 0; i < classNames.length; i++){
|
||||
String className = classNames[i];
|
||||
elements[i] = myJavaFacade.findClass(className, GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class " + className + " not found", elements[i]);
|
||||
elements[i] = myFixture.findClass(className);
|
||||
}
|
||||
if (fileName != null) {
|
||||
elements[classNames.length] = elements[0].getContainingFile().getContainingDirectory().findFile(fileName);
|
||||
}
|
||||
|
||||
PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(newPackageName);
|
||||
assertNotNull("Package " + newPackageName + " not found", aPackage);
|
||||
PsiPackage aPackage = myFixture.findPackage(newPackageName);
|
||||
final PsiDirectory[] dirs = aPackage.getDirectories();
|
||||
assertEquals(1, dirs.length);
|
||||
|
||||
final JavaMoveFilesOrDirectoriesHandler handler = new JavaMoveFilesOrDirectoriesHandler();
|
||||
assertTrue(handler.canMove(elements, dirs[0]));
|
||||
handler.doMove(getProject(), elements, dirs[0], null);
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,52 +2,52 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.JavaDirectoryService;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.PackageWrapper;
|
||||
import com.intellij.refactoring.RefactoringTestCase;
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor;
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class MoveClassTest extends RefactoringTestCase {
|
||||
public void testContextChange() throws Exception{
|
||||
doTest("contextChange1", new String[]{"pack1.Class1"}, "pack2");
|
||||
doTest("contextChange2", new String[]{"pack1.Class1"}, "pack2");
|
||||
public class MoveClassTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClass/";
|
||||
}
|
||||
|
||||
public void testMoveMultiple() throws Exception{
|
||||
doTest("moveMultiple1", new String[]{"pack1.Class1", "pack1.Class2"}, "pack2");
|
||||
public void testContextChange1() {
|
||||
doTest(new String[]{"pack1.Class1"}, "pack2");
|
||||
}
|
||||
public void testContextChange2() {
|
||||
doTest(new String[]{"pack1.Class1"}, "pack2");
|
||||
}
|
||||
|
||||
public void testSecondaryClass() throws Exception{
|
||||
doTest("secondaryClass", new String[]{"pack1.Class2"}, "pack1");
|
||||
public void testMoveMultiple1() {
|
||||
doTest(new String[]{"pack1.Class1", "pack1.Class2"}, "pack2");
|
||||
}
|
||||
|
||||
public void testStringsAndComments() throws Exception{
|
||||
doTest("stringsAndComments", new String[]{"pack1.Class1"}, "pack2");
|
||||
public void testSecondaryClass() {
|
||||
doTest(new String[]{"pack1.Class2"}, "pack1");
|
||||
}
|
||||
|
||||
public void testStringsAndComments2() throws Exception{
|
||||
doTest("stringsAndComments2", new String[]{"pack1.AClass"}, "pack2");
|
||||
public void testStringsAndComments() {
|
||||
doTest(new String[]{"pack1.Class1"}, "pack2");
|
||||
}
|
||||
|
||||
public void testNonJava() throws Exception{
|
||||
doTest("nonJava", new String[]{"pack1.Class1"}, "pack2");
|
||||
public void testStringsAndComments2() {
|
||||
doTest(new String[]{"pack1.AClass"}, "pack2");
|
||||
}
|
||||
|
||||
public void testRefInPropertiesFile() throws Exception{
|
||||
doTest("refInPropertiesFile", new String[]{"p1.MyClass"}, "p");
|
||||
public void testNonJava() {
|
||||
doTest(new String[]{"pack1.Class1"}, "pack2");
|
||||
}
|
||||
|
||||
public void testRefInPropertiesFile() {
|
||||
doTest(new String[]{"p1.MyClass"}, "p");
|
||||
}
|
||||
|
||||
/* IMPLEMENT: getReferences() in JspAttributeValueImpl should be dealed with (soft refs?)
|
||||
@@ -57,13 +57,13 @@ public class MoveClassTest extends RefactoringTestCase {
|
||||
}
|
||||
*/
|
||||
|
||||
public void testLocalClass() throws Exception{
|
||||
doTest("localClass", new String[]{"pack1.A"}, "pack2");
|
||||
public void testLocalClass() {
|
||||
doTest(new String[]{"pack1.A"}, "pack2");
|
||||
}
|
||||
|
||||
public void testClassAndSecondary() throws Exception{
|
||||
public void testClassAndSecondary() {
|
||||
try {
|
||||
doTest("classAndSecondary", new String[]{"pack1.Class1", "pack1.Class2"}, "pack2");
|
||||
doTest(new String[]{"pack1.Class1", "pack1.Class2"}, "pack2");
|
||||
fail("Conflicts expected");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
@@ -71,55 +71,41 @@ public class MoveClassTest extends RefactoringTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIdeadev27996() throws Exception {
|
||||
doTest("ideadev27996", new String[] { "pack1.X" }, "pack2");
|
||||
public void testIdeadev27996() {
|
||||
doTest(new String[] { "pack1.X" }, "pack2");
|
||||
}
|
||||
|
||||
public void testUnusedImport() throws Exception {
|
||||
doTest("unusedImport", new String[]{"p2.F2"}, "p1");
|
||||
public void testUnusedImport() {
|
||||
doTest(new String[]{"p2.F2"}, "p1");
|
||||
}
|
||||
|
||||
public void testQualifiedReferenceAfterFailedMethodConflictResolution() throws Exception {
|
||||
doTest("qualifiedRef", new String[]{"p1.Test"}, "p2");
|
||||
public void testQualifiedRef() {
|
||||
doTest(new String[]{"p1.Test"}, "p2");
|
||||
}
|
||||
|
||||
public void testConflictingClassNames() throws Exception {
|
||||
doTest("conflictingNames", new String[] {"p1.First", "p1.Second"}, "p3");
|
||||
public void testConflictingNames() {
|
||||
doTest(new String[] {"p1.First", "p1.Second"}, "p3");
|
||||
}
|
||||
|
||||
private void doTest(@NonNls String testName, @NonNls String[] classNames, @NonNls String newPackageName) throws Exception{
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClass/" + testName;
|
||||
|
||||
String rootBefore = root + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
VirtualFile rootDir = createTestProjectStructure(rootBefore);
|
||||
|
||||
performAction(classNames, newPackageName);
|
||||
|
||||
String rootAfter = root + "/after";
|
||||
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
|
||||
private void doTest(@NonNls String[] classNames, @NonNls String newPackageName) {
|
||||
doTest(() -> performAction(classNames, newPackageName));
|
||||
}
|
||||
|
||||
private void performAction(String[] classNames, String newPackageName) {
|
||||
final PsiClass[] classes = new PsiClass[classNames.length];
|
||||
for(int i = 0; i < classes.length; i++){
|
||||
String className = classNames[i];
|
||||
classes[i] = myJavaFacade.findClass(className, GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class " + className + " not found", classes[i]);
|
||||
classes[i] = myFixture.findClass(className);
|
||||
}
|
||||
|
||||
PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(newPackageName);
|
||||
PsiPackage aPackage = myFixture.findPackage(newPackageName);
|
||||
assertNotNull("Package " + newPackageName + " not found", aPackage);
|
||||
final PsiDirectory[] dirs = aPackage.getDirectories();
|
||||
assertEquals(dirs.length, 1);
|
||||
assertEquals(1, dirs.length);
|
||||
|
||||
new MoveClassesOrPackagesProcessor(myProject, classes,
|
||||
new MoveClassesOrPackagesProcessor(getProject(), classes,
|
||||
new SingleSourceRootMoveDestination(PackageWrapper.create(JavaDirectoryService
|
||||
.getInstance().getPackage(dirs[0])), dirs[0]),
|
||||
true, true, null).run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,159 +2,128 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.refactoring.RefactoringTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassToInnerProcessor;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class MoveClassToInnerTest extends RefactoringTestCase {
|
||||
public void testContextChange1() throws Exception {
|
||||
public class MoveClassToInnerTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClassToInner/";
|
||||
}
|
||||
|
||||
public void testContextChange1() {
|
||||
doTest(new String[] { "pack1.Class1" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testContextChange2() throws Exception {
|
||||
public void testContextChange2() {
|
||||
doTest(new String[] { "pack1.Class1" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testInnerImport() throws Exception {
|
||||
public void testInnerImport() {
|
||||
doTest(new String[] { "pack1.Class1" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testInnerEnum() throws Exception {
|
||||
public void testInnerEnum() {
|
||||
doTest(new String[] { "pack2.AEnum" }, "pack1.Class1");
|
||||
}
|
||||
|
||||
public void testInnerInsideMoved() throws Exception {
|
||||
public void testInnerInsideMoved() {
|
||||
doTest(new String[] { "pack1.Class1" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testInsertInnerClassImport() throws Exception {
|
||||
public void testInsertInnerClassImport() {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
doTest(new String[] { "pack1.Class1" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testSimultaneousMove() throws Exception {
|
||||
public void testSimultaneousMove() {
|
||||
doTest(new String[] { "pack1.Class1", "pack0.Class0" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testMoveMultiple1() throws Exception {
|
||||
public void testMoveMultiple1() {
|
||||
doTest(new String[] { "pack1.Class1", "pack1.Class2" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testRefToInner() throws Exception {
|
||||
public void testRefToInner() {
|
||||
doTest(new String[] { "pack1.Class1" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testRefToConstructor() throws Exception {
|
||||
public void testRefToConstructor() {
|
||||
doTest(new String[] { "pack1.Class1" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testSecondaryClass() throws Exception {
|
||||
public void testSecondaryClass() {
|
||||
doTest(new String[] { "pack1.Class2" }, "pack1.User");
|
||||
}
|
||||
|
||||
public void testStringsAndComments() throws Exception {
|
||||
public void testStringsAndComments() {
|
||||
doTest(new String[] { "pack1.Class1" }, "pack1.A");
|
||||
}
|
||||
|
||||
public void testStringsAndComments2() throws Exception {
|
||||
public void testStringsAndComments2() {
|
||||
doTest(new String[] { "pack1.Class1" }, "pack1.A");
|
||||
}
|
||||
|
||||
public void testNonJava() throws Exception {
|
||||
public void testNonJava() {
|
||||
doTest(new String[] { "pack1.Class1" }, "pack1.A");
|
||||
}
|
||||
|
||||
public void testLocallyUsedPackageLocalToPublicInterface() throws Exception {
|
||||
public void testLocallyUsedPackageLocalToPublicInterface() {
|
||||
doTest(new String[]{"pack1.Class1"}, "pack2.A");
|
||||
}
|
||||
|
||||
public void testPackageLocalClass() throws Exception {
|
||||
public void testPackageLocalClass() {
|
||||
doTestConflicts("pack1.Class1", "pack2.A", "Field <b><code>Class1.c2</code></b> uses package-private class <b><code>pack1.Class2</code></b>");
|
||||
}
|
||||
|
||||
public void testMoveIntoPackageLocalClass() throws Exception {
|
||||
public void testMoveIntoPackageLocalClass() {
|
||||
doTestConflicts("pack1.Class1", "pack2.A", "Class <b><code>Class1</code></b> will no longer be accessible from field <b><code>Class2.c1</code></b>");
|
||||
}
|
||||
|
||||
public void testMoveOfPackageLocalClass() throws Exception {
|
||||
public void testMoveOfPackageLocalClass() {
|
||||
doTestConflicts("pack1.Class1", "pack2.A", "Class <b><code>Class1</code></b> will no longer be accessible from field <b><code>Class2.c1</code></b>");
|
||||
}
|
||||
|
||||
public void testMoveIntoPrivateInnerClass() throws Exception {
|
||||
public void testMoveIntoPrivateInnerClass() {
|
||||
doTestConflicts("pack1.Class1", "pack1.A.PrivateInner", "Class <b><code>Class1</code></b> will no longer be accessible from field <b><code>Class2.c1</code></b>");
|
||||
}
|
||||
|
||||
public void testMoveWithPackageLocalMember() throws Exception {
|
||||
public void testMoveWithPackageLocalMember() {
|
||||
doTestConflicts("pack1.Class1", "pack2.A", "Method <b><code>Class1.doStuff()</code></b> will no longer be accessible from method <b><code>Class2.test()</code></b>");
|
||||
}
|
||||
|
||||
public void testDuplicateInner() throws Exception {
|
||||
public void testDuplicateInner() {
|
||||
doTestConflicts("pack1.Class1", "pack2.A", "Class <b><code>pack2.A</code></b> already contains an inner class named <b><code>Class1</code></b>");
|
||||
}
|
||||
|
||||
private void doTest(String[] classNames, String targetClassName) throws Exception{
|
||||
VirtualFile rootDir = prepareTest();
|
||||
|
||||
performAction(classNames, targetClassName);
|
||||
|
||||
String rootAfter = getRoot() + "/after";
|
||||
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
|
||||
private void doTest(String[] classNames, String targetClassName) {
|
||||
doTest(() -> {
|
||||
final PsiClass[] classes = new PsiClass[classNames.length];
|
||||
for(int i = 0; i < classes.length; i++){
|
||||
String className = classNames[i];
|
||||
classes[i] = myFixture.findClass(className);
|
||||
}
|
||||
PsiClass targetClass = myFixture.findClass(targetClassName);
|
||||
new MoveClassToInnerProcessor(getProject(), classes, targetClass, true, true, null).run();
|
||||
});
|
||||
}
|
||||
|
||||
private VirtualFile prepareTest() throws Exception {
|
||||
String rootBefore = getRoot() + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
return createTestProjectStructure(rootBefore);
|
||||
}
|
||||
|
||||
private String getRoot() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClassToInner/" + getTestName(true);
|
||||
}
|
||||
|
||||
private void doTestConflicts(String className, String targetClassName, String... expectedConflicts) throws Exception {
|
||||
prepareTest();
|
||||
PsiClass classToMove = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
|
||||
PsiClass targetClass = myJavaFacade.findClass(targetClassName, ProjectScope.getAllScope(myProject));
|
||||
MoveClassToInnerProcessor processor = new MoveClassToInnerProcessor(myProject, new PsiClass[]{classToMove}, targetClass, true, true, null);
|
||||
private void doTestConflicts(String className, String targetClassName, String... expectedConflicts) {
|
||||
myFixture.copyDirectoryToProject(getTestName(true) + "/before", "");
|
||||
PsiClass classToMove = myFixture.findClass(className);
|
||||
PsiClass targetClass = myFixture.findClass(targetClassName);
|
||||
MoveClassToInnerProcessor processor = new MoveClassToInnerProcessor(getProject(), new PsiClass[]{classToMove}, targetClass, true, true, null);
|
||||
UsageInfo[] usages = processor.findUsages();
|
||||
MultiMap<PsiElement,String> conflicts = processor.getConflicts(usages);
|
||||
assertSameElements(conflicts.values() , expectedConflicts);
|
||||
}
|
||||
|
||||
private void performAction(String[] classNames, String targetClassName) {
|
||||
final PsiClass[] classes = new PsiClass[classNames.length];
|
||||
for(int i = 0; i < classes.length; i++){
|
||||
String className = classNames[i];
|
||||
classes[i] = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
|
||||
assertNotNull("Class " + className + " not found", classes[i]);
|
||||
}
|
||||
|
||||
PsiClass targetClass = myJavaFacade.findClass(targetClassName, ProjectScope.getAllScope(myProject));
|
||||
assertNotNull(targetClass);
|
||||
|
||||
new MoveClassToInnerProcessor(myProject, classes, targetClass, true, true, null).run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,34 +17,25 @@ package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.move.moveInner.MoveInnerDialog;
|
||||
import com.intellij.refactoring.move.moveInner.MoveInnerImpl;
|
||||
import com.intellij.refactoring.move.moveInner.MoveInnerProcessor;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class MoveInnerTest extends MultiFileTestCase {
|
||||
public class MoveInnerTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/moveInner/";
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveInner/";
|
||||
}
|
||||
|
||||
public void testScr13730() {
|
||||
@@ -133,26 +124,26 @@ public class MoveInnerTest extends MultiFileTestCase {
|
||||
false, false, null) {
|
||||
@Override
|
||||
protected boolean isPassOuterClass() {
|
||||
final PsiClass outerClass = getJavaFacade().findClass("pack1.DImpl", GlobalSearchScope.moduleScope(myModule));
|
||||
final PsiClass outerClass = myFixture.getJavaFacade().findClass("pack1.DImpl", GlobalSearchScope.moduleScope(myModule));
|
||||
assertNotNull(outerClass);
|
||||
final PsiClass innerClass = getJavaFacade().findClass(innerClassName, GlobalSearchScope.moduleScope(myModule));
|
||||
final PsiClass innerClass = myFixture.getJavaFacade().findClass(innerClassName, GlobalSearchScope.moduleScope(myModule));
|
||||
assertNotNull(innerClass);
|
||||
return MoveInnerDialog.isThisNeeded(innerClass, outerClass);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private PerformAction createAction(@NonNls final String innerClassName,
|
||||
@NonNls final String newClassName,
|
||||
final boolean passOuterClass,
|
||||
@NonNls final String parameterName,
|
||||
final boolean searchInComments,
|
||||
final boolean searchInNonJava,
|
||||
@NonNls @Nullable final String packageName) {
|
||||
private ThrowableRunnable<Exception> createAction(@NonNls final String innerClassName,
|
||||
@NonNls final String newClassName,
|
||||
final boolean passOuterClass,
|
||||
@NonNls final String parameterName,
|
||||
final boolean searchInComments,
|
||||
final boolean searchInNonJava,
|
||||
@NonNls @Nullable final String packageName) {
|
||||
return new MyPerformAction(innerClassName, newClassName, passOuterClass, parameterName, searchInComments, searchInNonJava, packageName);
|
||||
}
|
||||
|
||||
private class MyPerformAction implements PerformAction {
|
||||
private class MyPerformAction implements ThrowableRunnable<Exception> {
|
||||
private final String myInnerClassName;
|
||||
private final String myPackageName;
|
||||
private final String myNewClassName;
|
||||
@@ -174,17 +165,14 @@ public class MoveInnerTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) {
|
||||
final JavaPsiFacade manager = getJavaFacade();
|
||||
public void run() {
|
||||
final JavaPsiFacade manager = myFixture.getJavaFacade();
|
||||
final PsiClass aClass = manager.findClass(myInnerClassName, GlobalSearchScope.moduleScope(myModule));
|
||||
final MoveInnerProcessor moveInnerProcessor = new MoveInnerProcessor(myProject, null);
|
||||
final MoveInnerProcessor moveInnerProcessor = new MoveInnerProcessor(getProject(), null);
|
||||
final PsiElement targetContainer = myPackageName != null ? findDirectory(myPackageName) : MoveInnerImpl.getTargetContainer(aClass, false);
|
||||
assertNotNull(targetContainer);
|
||||
moveInnerProcessor.setup(aClass, myNewClassName, isPassOuterClass(), myParameterName, mySearchInComments, mySearchInNonJava, targetContainer);
|
||||
moveInnerProcessor.run();
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
|
||||
protected boolean isPassOuterClass() {
|
||||
@@ -192,7 +180,7 @@ public class MoveInnerTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private PsiElement findDirectory(final String packageName) {
|
||||
final PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(packageName);
|
||||
final PsiPackage aPackage = myFixture.getJavaFacade().findPackage(packageName);
|
||||
assert aPackage != null;
|
||||
final PsiDirectory[] directories = aPackage.getDirectories();
|
||||
return directories [0];
|
||||
|
||||
@@ -16,28 +16,25 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.move.moveMembers.MockMoveMembersOptions;
|
||||
import com.intellij.refactoring.move.moveMembers.MoveMembersProcessor;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
public class MoveMembersTest extends MultiFileTestCase {
|
||||
public class MoveMembersTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveMembers/";
|
||||
}
|
||||
|
||||
public void testJavadocRefs() {
|
||||
@@ -233,12 +230,6 @@ public class MoveMembersTest extends MultiFileTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/moveMembers/";
|
||||
}
|
||||
|
||||
private void doTest(final String sourceClassName, final String targetClassName, final int... memberIndices) {
|
||||
doTest(sourceClassName, targetClassName, true, memberIndices);
|
||||
}
|
||||
@@ -255,15 +246,12 @@ public class MoveMembersTest extends MultiFileTestCase {
|
||||
final boolean lowercaseFirstLetter,
|
||||
final String defaultVisibility,
|
||||
final int... memberIndices) {
|
||||
doTest((rootDir, rootAfter) -> this.performAction(sourceClassName, targetClassName, memberIndices, defaultVisibility), lowercaseFirstLetter);
|
||||
doTest(() -> this.performAction(sourceClassName, targetClassName, memberIndices, defaultVisibility), lowercaseFirstLetter);
|
||||
}
|
||||
|
||||
private void performAction(String sourceClassName, String targetClassName, int[] memberIndices, final String visibility) {
|
||||
PsiClass sourceClass = myJavaFacade.findClass(sourceClassName, ProjectScope.getProjectScope(myProject));
|
||||
assertNotNull("Class " + sourceClassName + " not found", sourceClass);
|
||||
PsiClass targetClass = myJavaFacade.findClass(targetClassName, ProjectScope.getProjectScope(myProject));
|
||||
assertNotNull("Class " + targetClassName + " not found", targetClass);
|
||||
|
||||
PsiClass sourceClass = myFixture.findClass(sourceClassName);
|
||||
PsiClass targetClass = myFixture.findClass(targetClassName);
|
||||
PsiElement[] children = sourceClass.getChildren();
|
||||
ArrayList<PsiMember> members = new ArrayList<>();
|
||||
for (PsiElement child : children) {
|
||||
@@ -281,7 +269,6 @@ public class MoveMembersTest extends MultiFileTestCase {
|
||||
|
||||
MockMoveMembersOptions options = new MockMoveMembersOptions(targetClass.getQualifiedName(), memberSet);
|
||||
options.setMemberVisibility(visibility);
|
||||
new MoveMembersProcessor(myProject, null, options).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
new MoveMembersProcessor(getProject(), null, options).run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,23 +2,18 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.PackageWrapper;
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor;
|
||||
import com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MovePackageTest extends MultiFileTestCase {
|
||||
public class MovePackageTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/movePackage/";
|
||||
}
|
||||
|
||||
public void testMoveSingle() {
|
||||
@@ -34,26 +29,20 @@ public class MovePackageTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void testPackageAndReferencedClass() {
|
||||
Project project = myPsiManager.getProject();
|
||||
JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
|
||||
doTest((rootDir, rootAfter) -> performAction(new PsiElement[]{facade.findPackage("a"), facade.findClass("B", GlobalSearchScope.allScope(project))}, "b"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/movePackage/";
|
||||
doTest(() -> performAction(new PsiElement[]{
|
||||
myFixture.findPackage("a"),
|
||||
myFixture.findClass("B")}, "b"));
|
||||
}
|
||||
|
||||
private void doTest(final String[] packageNames, final String newPackageName) {
|
||||
doTest((rootDir, rootAfter) -> this.performAction(packageNames, newPackageName));
|
||||
doTest(() -> this.performAction(packageNames, newPackageName));
|
||||
}
|
||||
|
||||
private void performAction(String[] packageNames, String newPackageName) {
|
||||
final PsiPackage[] packages = new PsiPackage[packageNames.length];
|
||||
for (int i = 0; i < packages.length; i++) {
|
||||
String packageName = packageNames[i];
|
||||
packages[i] = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(packageName);
|
||||
packages[i] = myFixture.findPackage(packageName);
|
||||
assertNotNull("Package " + packageName + " not found", packages[i]);
|
||||
}
|
||||
|
||||
@@ -61,14 +50,13 @@ public class MovePackageTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void performAction(PsiElement[] packagesAndClasses, String newPackageName) {
|
||||
PsiPackage newParentPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(newPackageName);
|
||||
PsiPackage newParentPackage = myFixture.findPackage(newPackageName);
|
||||
assertNotNull(newParentPackage);
|
||||
final PsiDirectory[] dirs = newParentPackage.getDirectories();
|
||||
assertEquals(1, dirs.length);
|
||||
|
||||
new MoveClassesOrPackagesProcessor(myProject, packagesAndClasses,
|
||||
new MoveClassesOrPackagesProcessor(getProject(), packagesAndClasses,
|
||||
new SingleSourceRootMoveDestination(PackageWrapper.create(newParentPackage), dirs[0]),
|
||||
true, false, null).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,38 +18,30 @@ package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.memberPullUp.PullUpConflictsUtil;
|
||||
import com.intellij.refactoring.memberPullUp.PullUpProcessor;
|
||||
import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
//pull first method from class a.A to class b.B
|
||||
public class PullUpMultifileTest extends MultiFileTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/pullUp/";
|
||||
}
|
||||
|
||||
public class PullUpMultifileTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/pullUp/";
|
||||
}
|
||||
|
||||
private void doTest(final String... conflicts) {
|
||||
final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
|
||||
doTest(() -> {
|
||||
final PsiClass srcClass = myFixture.findClass("a.A");
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
|
||||
final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
|
||||
final PsiClass targetClass = myFixture.findClass("b.B");
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
|
||||
final PsiMethod[] methods = srcClass.getMethods();
|
||||
@@ -102,11 +94,11 @@ public class PullUpMultifileTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void testClassPackageConflict() {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass srcClass = myJavaFacade.findClass("a.a", GlobalSearchScope.allScope(myProject));
|
||||
doTest(() -> {
|
||||
final PsiClass srcClass = myFixture.findClass("a.a");
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
|
||||
final PsiClass targetClass = myJavaFacade.findClass("a.B", GlobalSearchScope.allScope(myProject));
|
||||
final PsiClass targetClass = myFixture.findClass("a.B");
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
|
||||
final PsiMethod[] methods = srcClass.getMethods();
|
||||
|
||||
@@ -20,27 +20,19 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.memberPushDown.PushDownProcessor;
|
||||
import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
//push first method from class a.A to class b.B
|
||||
public class PushDownMultifileTest extends MultiFileTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/pushDown/";
|
||||
}
|
||||
|
||||
public class PushDownMultifileTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/pushDown/";
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
@@ -53,11 +45,11 @@ public class PushDownMultifileTest extends MultiFileTestCase {
|
||||
|
||||
private void doTest(final boolean fail, final String sourceClassName, final String targetClassName) {
|
||||
try {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass srcClass = myJavaFacade.findClass(sourceClassName, GlobalSearchScope.allScope(myProject));
|
||||
doTest(() -> {
|
||||
final PsiClass srcClass = myFixture.findClass(sourceClassName);
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
|
||||
final PsiClass targetClass = myJavaFacade.findClass(targetClassName, GlobalSearchScope.allScope(myProject));
|
||||
final PsiClass targetClass = myFixture.findClass(targetClassName);
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
|
||||
final PsiMethod[] methods = srcClass.getMethods();
|
||||
@@ -103,11 +95,11 @@ public class PushDownMultifileTest extends MultiFileTestCase {
|
||||
|
||||
public void testUsagesInXml() {
|
||||
try {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
|
||||
doTest(() -> {
|
||||
final PsiClass srcClass = myFixture.findClass("a.A");
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
|
||||
final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
|
||||
final PsiClass targetClass = myFixture.findClass("b.B");
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
|
||||
final PsiField[] fields = srcClass.getFields();
|
||||
|
||||
@@ -17,40 +17,33 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.removemiddleman.DelegationUtils;
|
||||
import com.intellij.refactoring.removemiddleman.RemoveMiddlemanProcessor;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class RemoveMiddleManTest extends MultiFileTestCase {
|
||||
public class RemoveMiddleManTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/removemiddleman/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/removemiddleman/";
|
||||
}
|
||||
|
||||
private void doTest(final String conflict) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(getProject()));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
if (aClass == null) aClass = myJavaFacade.findClass("p.Test", GlobalSearchScope.allScope(getProject()));
|
||||
if (aClass == null) aClass = myFixture.findClass("p.Test");
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final PsiField field = aClass.findFieldByName("myField", false);
|
||||
@@ -65,8 +58,6 @@ public class RemoveMiddleManTest extends MultiFileTestCase {
|
||||
try {
|
||||
RemoveMiddlemanProcessor processor = new RemoveMiddlemanProcessor(field, infos);
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
if (conflict != null) fail("Conflict expected");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
|
||||
@@ -2,22 +2,18 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RenameClassTest extends MultiFileTestCase {
|
||||
public class RenameClassTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/renameClass/";
|
||||
}
|
||||
|
||||
public void testNonJava() {
|
||||
@@ -70,17 +66,15 @@ public class RenameClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doRenameClass(final String className, final String newName) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass(className);
|
||||
assertNotNull("Class XX not found", aClass);
|
||||
|
||||
final RenameProcessor processor = new RenameProcessor(myProject, aClass, newName, true, true);
|
||||
final RenameProcessor processor = new RenameProcessor(getProject(), aClass, newName, true, true);
|
||||
for (AutomaticRenamerFactory factory : AutomaticRenamerFactory.EP_NAME.getExtensionList()) {
|
||||
processor.addRenamerFactory(factory);
|
||||
}
|
||||
processor.run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -93,26 +87,19 @@ public class RenameClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String qClassName, @NonNls final String newName) {
|
||||
doTest((rootDir, rootAfter) -> this.performAction(qClassName, newName));
|
||||
doTest(() -> this.performAction(qClassName, newName));
|
||||
}
|
||||
|
||||
private void performAction(String qClassName, String newName) {
|
||||
PsiClass aClass = myJavaFacade.findClass(qClassName, GlobalSearchScope.allScope(getProject()));
|
||||
PsiClass aClass = myFixture.findClass(qClassName);
|
||||
assertNotNull("Class " + qClassName + " not found", aClass);
|
||||
|
||||
new RenameProcessor(myProject, aClass, newName, true, true).run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
new RenameProcessor(getProject(), aClass, newName, true, true).run();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/renameClass/";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getTestProjectJdk() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,33 +4,23 @@ package com.intellij.java.refactoring;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class RenameMethodMultiTest extends MultiFileTestCase {
|
||||
public class RenameMethodMultiTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/renameMethod/multi/";
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/renameMethod/multi/";
|
||||
}
|
||||
|
||||
public void testStaticImport1() {
|
||||
@@ -75,7 +65,7 @@ public class RenameMethodMultiTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void testAlignedMultilineParameters() {
|
||||
CommonCodeStyleSettings javaSettings = CodeStyle.getSettings(myProject).getCommonSettings(JavaLanguage.INSTANCE);
|
||||
CommonCodeStyleSettings javaSettings = CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaSettings.ALIGN_MULTILINE_PARAMETERS = true;
|
||||
javaSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
|
||||
doTest("void test123(int i, int j)", "test123asd");
|
||||
@@ -98,35 +88,30 @@ public class RenameMethodMultiTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTest(final String className, final String methodSignature, final String newName) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final JavaPsiFacade manager = getJavaFacade();
|
||||
final PsiClass aClass = manager.findClass(className, GlobalSearchScope.moduleScope(myModule));
|
||||
doTest(() -> {
|
||||
final PsiClass aClass = myFixture.findClass(className);
|
||||
assertNotNull(aClass);
|
||||
final PsiMethod methodBySignature = aClass.findMethodBySignature(manager.getElementFactory().createMethodFromText(
|
||||
final PsiMethod methodBySignature = aClass.findMethodBySignature(getElementFactory().createMethodFromText(
|
||||
methodSignature + "{}", null), false);
|
||||
assertNotNull(methodBySignature);
|
||||
final RenameProcessor renameProcessor = new RenameProcessor(myProject, methodBySignature, newName, false, false);
|
||||
final RenameProcessor renameProcessor = new RenameProcessor(getProject(), methodBySignature, newName, false, false);
|
||||
renameProcessor.run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
private void doAutomaticRenameMethod(final String className, final String methodSignature, final String newName) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final JavaPsiFacade manager = getJavaFacade();
|
||||
final PsiClass aClass = manager.findClass(className, GlobalSearchScope.moduleScope(myModule));
|
||||
doTest(() -> {
|
||||
final PsiClass aClass = myFixture.getJavaFacade().findClass(className, GlobalSearchScope.moduleScope(myModule));
|
||||
assertNotNull(aClass);
|
||||
final PsiMethod methodBySignature = aClass.findMethodBySignature(manager.getElementFactory().createMethodFromText(
|
||||
final PsiMethod methodBySignature = aClass.findMethodBySignature(getElementFactory().createMethodFromText(
|
||||
methodSignature + "{}", null), false);
|
||||
assertNotNull(methodBySignature);
|
||||
|
||||
final RenameProcessor processor = new RenameProcessor(myProject, methodBySignature, newName, false, false);
|
||||
final RenameProcessor processor = new RenameProcessor(getProject(), methodBySignature, newName, false, false);
|
||||
for (AutomaticRenamerFactory factory : AutomaticRenamerFactory.EP_NAME.getExtensionList()) {
|
||||
processor.addRenamerFactory(factory);
|
||||
}
|
||||
processor.run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+6
-20
@@ -17,25 +17,21 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.replaceConstructorWithBuilder.ParameterData;
|
||||
import com.intellij.refactoring.replaceConstructorWithBuilder.ReplaceConstructorWithBuilderProcessor;
|
||||
import java.util.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReplaceConstructorWithBuilderTest extends MultiFileTestCase {
|
||||
public class ReplaceConstructorWithBuilderTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/replaceConstructorWithBuilder/";
|
||||
}
|
||||
|
||||
public void testVarargs() {
|
||||
@@ -99,9 +95,8 @@ public class ReplaceConstructorWithBuilderTest extends MultiFileTestCase {
|
||||
final Map<String, String> expectedDefaults,
|
||||
final String conflicts,
|
||||
final String packageName) {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
doTest(() -> {
|
||||
final PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
final LinkedHashMap<String, ParameterData> map = new LinkedHashMap<>();
|
||||
final PsiMethod[] constructors = aClass.getConstructors();
|
||||
@@ -127,15 +122,6 @@ public class ReplaceConstructorWithBuilderTest extends MultiFileTestCase {
|
||||
fail("Conflict detected:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/replaceConstructorWithBuilder/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,16 +15,14 @@
|
||||
*/
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.turnRefsToSuper.TurnRefsToSuperProcessor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TurnRefsToSuperTest extends MultiFileTestCase {
|
||||
public class TurnRefsToSuperTest extends LightMultiFileTestCase {
|
||||
public void testSuperClass() { doTest("AClass", "ASuper", true); }
|
||||
public void testMethodFromSuper() { doTest("AClass", "ASuper", true); }
|
||||
public void testRemoveImport() { doTest("pack1.AClass", "pack1.AnInterface", true); }
|
||||
@@ -67,22 +65,20 @@ public class TurnRefsToSuperTest extends MultiFileTestCase {
|
||||
//public void testForEach2() throws Exception { doTest("Test.MyIterableImpl", "Test.MyIterable", false); }
|
||||
|
||||
private void doTest(@NonNls final String className, @NonNls final String superClassName, final boolean replaceInstanceOf) {
|
||||
doTest((rootDir, rootAfter) -> this.performAction(className, superClassName, replaceInstanceOf), true);
|
||||
doTest(() -> this.performAction(className, superClassName, replaceInstanceOf), true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTestRoot() {
|
||||
return "/refactoring/turnRefsToSuper/";
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/turnRefsToSuper/";
|
||||
}
|
||||
|
||||
private void performAction(final String className, final String superClassName, boolean replaceInstanceOf) {
|
||||
final PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(myProject));
|
||||
final PsiClass aClass = myFixture.findClass(className);
|
||||
assertNotNull("Class " + className + " not found", aClass);
|
||||
PsiClass superClass = myJavaFacade.findClass(superClassName, GlobalSearchScope.allScope(myProject));
|
||||
PsiClass superClass = myFixture.findClass(superClassName);
|
||||
assertNotNull("Class " + superClassName + " not found", superClass);
|
||||
|
||||
new TurnRefsToSuperProcessor(myProject, aClass, superClass, replaceInstanceOf).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
new TurnRefsToSuperProcessor(getProject(), aClass, superClass, replaceInstanceOf).run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,36 +16,22 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.typeCook.Settings;
|
||||
import com.intellij.refactoring.typeCook.deductive.builder.ReductionSystem;
|
||||
import com.intellij.refactoring.typeCook.deductive.builder.SystemBuilder;
|
||||
import com.intellij.refactoring.typeCook.deductive.resolver.Binding;
|
||||
import com.intellij.refactoring.typeCook.deductive.resolver.ResolverTree;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class TypeCookTest extends MultiFileTestCase {
|
||||
public class TypeCookTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTestRoot() {
|
||||
return "/refactoring/typeCook/";
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/typeCook/";
|
||||
}
|
||||
|
||||
public void testT01() {
|
||||
@@ -678,15 +664,13 @@ public class TypeCookTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void start(final boolean cookObjects) {
|
||||
doTest((rootDir, rootAfter) -> this.performAction("Test", rootDir.getName(), cookObjects));
|
||||
doTest(() -> this.performAction(cookObjects));
|
||||
}
|
||||
|
||||
private void performAction(String className, String rootDir, final boolean cookObjects) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(myProject));
|
||||
|
||||
assertNotNull("Class " + className + " not found", aClass);
|
||||
|
||||
SystemBuilder b = new SystemBuilder(myPsiManager.getProject(),
|
||||
private void performAction(final boolean cookObjects) throws Exception {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
|
||||
SystemBuilder b = new SystemBuilder(getProject(),
|
||||
new Settings() {
|
||||
@Override
|
||||
public boolean dropObsoleteCasts() {
|
||||
@@ -747,36 +731,14 @@ public class TypeCookTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
String itemRepr = system != null ? system.dumpString() : commonSystem.dumpString();// d.resultString();
|
||||
doStuff(rootDir, itemRepr, className + ".items");
|
||||
myFixture.getTempDirFixture().createFile("Test.items", itemRepr);
|
||||
itemRepr = system != null ? system.dumpResult(binding) : commonSystem.dumpString(); //d.resultString();
|
||||
|
||||
doStuff(rootDir, itemRepr, className + ".1.items");
|
||||
myFixture.getTempDirFixture().createFile("Test.1.items", itemRepr);
|
||||
}
|
||||
|
||||
private void doStuff(String rootDir, String itemRepr, String itemName) throws FileNotFoundException {
|
||||
String patternName = getTestDataPath() + getTestRoot() + getTestName(true) + "/after/" + itemName;
|
||||
|
||||
File patternFile = new File(patternName);
|
||||
|
||||
if (!patternFile.exists()) {
|
||||
try (PrintWriter writer = new PrintWriter(new FileOutputStream(patternFile))) {
|
||||
writer.print(itemRepr);
|
||||
}
|
||||
|
||||
System.err.println("Pattern not found, file " + patternName + " created.");
|
||||
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(patternFile);
|
||||
}
|
||||
|
||||
File graFile = new File(FileUtil.getTempDirectory() + File.separator + rootDir + File.separator + itemName);
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(new FileOutputStream(graFile))) {
|
||||
writer.print(itemRepr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(graFile);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_1_6;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,24 +21,17 @@ import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.wrapreturnvalue.WrapReturnValueProcessor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
*/
|
||||
public class WrapReturnValueTest extends MultiFileTestCase {
|
||||
public class WrapReturnValueTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/wrapReturnValue/";
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/wrapReturnValue/";
|
||||
}
|
||||
|
||||
public void testSimple() { doTest(false); }
|
||||
@@ -71,12 +64,11 @@ public class WrapReturnValueTest extends MultiFileTestCase {
|
||||
|
||||
private void doTest(final boolean existing, String exceptionMessage, final boolean createInnerClass) {
|
||||
try {
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass("Test");
|
||||
PsiMethod method = aClass.findMethodsByName("foo", false)[0];
|
||||
String wrapperClassName = "Wrapper";
|
||||
PsiClass wrapperClass = myJavaFacade.findClass(wrapperClassName, GlobalSearchScope.projectScope(getProject()));
|
||||
PsiClass wrapperClass = myFixture.getJavaFacade().findClass(wrapperClassName, GlobalSearchScope.projectScope(getProject()));
|
||||
assertTrue(!existing || wrapperClass != null);
|
||||
PsiField delegateField = existing ? wrapperClass.findFieldByName("myField", false) : null;
|
||||
new WrapReturnValueProcessor(wrapperClassName, "", null, method, existing, createInnerClass, delegateField).run();
|
||||
|
||||
+9
-10
@@ -16,14 +16,13 @@
|
||||
package com.intellij.java.refactoring.inline;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.refactoring.RefactoringTestCase;
|
||||
import com.intellij.refactoring.inline.InlineMethodProcessor;
|
||||
import com.intellij.refactoring.util.InlineUtil;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -31,23 +30,23 @@ import java.io.IOException;
|
||||
/**
|
||||
* @author anna
|
||||
*/
|
||||
public class InlineLibraryMethodTest extends RefactoringTestCase {
|
||||
public class InlineLibraryMethodTest extends LightCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
public void testInlineAllInProjectFromLibrary() throws Exception {
|
||||
configureByText(JavaFileType.INSTANCE, "package mycompany;\n" +
|
||||
public void testInlineAllInProjectFromLibrary() {
|
||||
myFixture.addClass("package mycompany;\n" +
|
||||
"public class File {\n" +
|
||||
" public static File createTempFile(String pr, String postfix){return createTempFile(pr, postfix, null);}\n" +
|
||||
" public static File createTempFile(String pr, String postfix, String base){return new File();}\n" +
|
||||
"}");
|
||||
@NonNls String fileName = "/refactoring/inlineMethod/" + getTestName(false) + ".java";
|
||||
configureByFile(fileName);
|
||||
myFixture.configureByFile(fileName);
|
||||
|
||||
PsiClass fileClass = myFixture.findClass("mycompany.File");
|
||||
|
||||
PsiClass fileClass = getJavaFacade().findClass("mycompany.File");
|
||||
assertNotNull(fileClass);
|
||||
final PsiFile file = fileClass.getContainingFile();
|
||||
WriteCommandAction.runWriteCommandAction(null, () -> {
|
||||
try {
|
||||
@@ -70,8 +69,8 @@ public class InlineLibraryMethodTest extends RefactoringTestCase {
|
||||
PsiMethod method = element;
|
||||
final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method);
|
||||
assertFalse("Bad returns found", condition);
|
||||
final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, null, myEditor, false);
|
||||
final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, null, getEditor(), false);
|
||||
processor.run();
|
||||
checkResultByFile(fileName + ".after");
|
||||
myFixture.checkResultByFile(fileName + ".after");
|
||||
}
|
||||
}
|
||||
|
||||
+20
-34
@@ -2,58 +2,44 @@
|
||||
package com.intellij.java.refactoring.inline;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.MockInlineMethodOptions;
|
||||
import com.intellij.refactoring.RefactoringTestCase;
|
||||
import com.intellij.refactoring.inline.InlineMethodProcessor;
|
||||
import com.intellij.refactoring.inline.InlineOptions;
|
||||
import com.intellij.refactoring.util.InlineUtil;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
public class InlineMethodMultifileTest extends LightMultiFileTestCase {
|
||||
|
||||
|
||||
public class InlineMethodMultifileTest extends RefactoringTestCase {
|
||||
|
||||
private String getRoot() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/inlineMethod/multifile/" + getTestName(true);
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/inlineMethod/multifile/";
|
||||
}
|
||||
|
||||
public void testRemoveStaticImports() throws Exception {
|
||||
public void testRemoveStaticImports() {
|
||||
doTest("Foo", "foo");
|
||||
}
|
||||
public void testPreserveStaticImportsIfOverloaded() throws Exception {
|
||||
public void testPreserveStaticImportsIfOverloaded() {
|
||||
doTest("Foo", "foo");
|
||||
}
|
||||
|
||||
public void testDecodeQualifierInMethodReference() throws Exception {
|
||||
public void testDecodeQualifierInMethodReference() {
|
||||
doTest("Foo", "foo");
|
||||
}
|
||||
|
||||
private void doTest(String className, String methodName) throws Exception {
|
||||
String rootBefore = getRoot() + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
final VirtualFile rootDir = createTestProjectStructure(rootBefore);
|
||||
PsiClass aClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
|
||||
assertNotNull(aClass);
|
||||
PsiMethod method = aClass.findMethodsByName(methodName, false)[0];
|
||||
final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method);
|
||||
assertFalse("Bad returns found", condition);
|
||||
private void doTest(String className, String methodName) {
|
||||
doTest(() -> {
|
||||
PsiClass aClass = myFixture.findClass(className);
|
||||
assertNotNull(aClass);
|
||||
PsiMethod method = aClass.findMethodsByName(methodName, false)[0];
|
||||
final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method);
|
||||
assertFalse("Bad returns found", condition);
|
||||
|
||||
InlineOptions options = new MockInlineMethodOptions();
|
||||
final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, null, myEditor, options.isInlineThisOnly());
|
||||
processor.run();
|
||||
|
||||
String rootAfter = getRoot() + "/after";
|
||||
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
|
||||
InlineOptions options = new MockInlineMethodOptions();
|
||||
final InlineMethodProcessor processor =
|
||||
new InlineMethodProcessor(getProject(), method, null, getEditor(), options.isInlineThisOnly());
|
||||
processor.run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+52
-48
@@ -2,7 +2,9 @@
|
||||
package com.intellij.java.refactoring.inline;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
@@ -12,76 +14,78 @@ import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.refactoring.RefactoringTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.inline.InlineToAnonymousClassHandler;
|
||||
import com.intellij.refactoring.inline.InlineToAnonymousClassProcessor;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
|
||||
import java.io.File;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class InlineToAnonymousClassMultifileTest extends RefactoringTestCase {
|
||||
public void testProtectedMember() throws Exception { // IDEADEV-18738
|
||||
public class InlineToAnonymousClassMultifileTest extends LightMultiFileTestCase {
|
||||
|
||||
private static final String BASE_PATH = JavaTestUtil.getJavaTestDataPath() + "/refactoring/inlineToAnonymousClass/multifile/";
|
||||
private static final DefaultLightProjectDescriptor PROJECT_DESCRIPTOR = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
super.configureModule(module, model, contentEntry);
|
||||
LibraryTable libraryTable = model.getModuleLibraryTable();
|
||||
Library library = libraryTable.createLibrary("test");
|
||||
Library.ModifiableModel libraryModel = library.getModifiableModel();
|
||||
String path = BASE_PATH + "/lib/simple.jar";
|
||||
VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path);
|
||||
VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libJarLocal);
|
||||
assertNotNull(jarRoot);
|
||||
libraryModel.addRoot(jarRoot, OrderRootType.CLASSES);
|
||||
libraryModel.addRoot(VfsUtilCore.pathToUrl(BASE_PATH + "/lib/src"), OrderRootType.SOURCES);
|
||||
libraryModel.commit();
|
||||
}
|
||||
};
|
||||
|
||||
public void testProtectedMember() { // IDEADEV-18738
|
||||
doTest("p1.SubjectWithSuper");
|
||||
}
|
||||
|
||||
public void testImportForConstructor() throws Exception { // IDEADEV-18714
|
||||
public void testImportForConstructor() { // IDEADEV-18714
|
||||
doTest("p1.ChildCtor");
|
||||
}
|
||||
|
||||
public void testStaticImports() throws Exception { // IDEADEV-18745
|
||||
public void testStaticImports() { // IDEADEV-18745
|
||||
doTest("p1.Inlined");
|
||||
}
|
||||
|
||||
public void testFromLibrary() throws Exception { // IDEADEV-18745
|
||||
public void testFromLibrary() { // IDEADEV-18745
|
||||
doTest("p.P");
|
||||
}
|
||||
|
||||
private String getRoot() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/inlineToAnonymousClass/multifile/" + getTestName(true);
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return BASE_PATH;
|
||||
}
|
||||
|
||||
private void doTest(String className) throws Exception {
|
||||
String rootBefore = getRoot() + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
final VirtualFile rootDir = createTestProjectStructure(rootBefore);
|
||||
String path = getRoot() + "/lib/simple.jar";
|
||||
VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path);
|
||||
if (libJarLocal != null) {
|
||||
ModuleRootModificationUtil.updateModel(myModule, model -> {
|
||||
LibraryTable libraryTable = model.getModuleLibraryTable();
|
||||
Library library = libraryTable.createLibrary("test");
|
||||
Library.ModifiableModel libraryModel = library.getModifiableModel();
|
||||
VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libJarLocal);
|
||||
assertNotNull(jarRoot);
|
||||
libraryModel.addRoot(jarRoot, OrderRootType.CLASSES);
|
||||
libraryModel.addRoot(VfsUtilCore.pathToUrl(getRoot() + "/lib/src"), OrderRootType.SOURCES);
|
||||
libraryModel.commit();
|
||||
});
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return PROJECT_DESCRIPTOR;
|
||||
}
|
||||
|
||||
PsiClass classToInline = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
|
||||
classToInline = (PsiClass)classToInline.getNavigationElement();
|
||||
assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
|
||||
InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(myProject,
|
||||
classToInline,
|
||||
null, false, false, false);
|
||||
UsageInfo[] usages = processor.findUsages();
|
||||
MultiMap<PsiElement,String> conflicts = processor.getConflicts(usages);
|
||||
assertEquals(0, conflicts.size());
|
||||
processor.run();
|
||||
private void doTest(String className) {
|
||||
|
||||
String rootAfter = getRoot() + "/after";
|
||||
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
|
||||
doTest(() -> {
|
||||
PsiClass classToInline = myFixture.findClass(className);
|
||||
classToInline = (PsiClass)classToInline.getNavigationElement();
|
||||
assertNull(InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
|
||||
InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(getProject(),
|
||||
classToInline,
|
||||
null, false, false, false);
|
||||
UsageInfo[] usages = processor.findUsages();
|
||||
MultiMap<PsiElement, String> conflicts = processor.getConflicts(usages);
|
||||
assertEquals(0, conflicts.size());
|
||||
processor.run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,16 @@
|
||||
package com.intellij.java.refactoring.migration;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.migration.MigrationMap;
|
||||
import com.intellij.refactoring.migration.MigrationMapEntry;
|
||||
import com.intellij.refactoring.migration.MigrationProcessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class MigrationTest extends MultiFileTestCase {
|
||||
public class MigrationTest extends LightMultiFileTestCase {
|
||||
public void testUnexistingClassInUnexistingPackage() {
|
||||
doTest(createAction(new MigrationMap(new MigrationMapEntry[]{
|
||||
new MigrationMapEntry("qqq.aaa.Yahoo", "java.lang.String", MigrationMapEntry.CLASS, false)
|
||||
@@ -64,21 +63,12 @@ public class MigrationTest extends MultiFileTestCase {
|
||||
})));
|
||||
}
|
||||
|
||||
private MultiFileTestCase.PerformAction createAction(final MigrationMap migrationMap) {
|
||||
return (rootDir, rootAfter) -> {
|
||||
new MigrationProcessor(myProject, migrationMap).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/migration/";
|
||||
private ThrowableRunnable<Exception> createAction(final MigrationMap migrationMap) {
|
||||
return () -> new MigrationProcessor(getProject(), migrationMap).run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/migration/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
package com.intellij.java.spi;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.RenamePsiElementProcessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SPIRenameTest extends MultiFileTestCase {
|
||||
public class SPIRenameTest extends LightMultiFileTestCase {
|
||||
public void testRenameProviderImplementation() {
|
||||
doRenameTest("Test1", "foo/Test.java");
|
||||
}
|
||||
@@ -37,26 +37,22 @@ public class SPIRenameTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doRenameTest(final String newName, final String relPath) {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) {
|
||||
final VirtualFile file = rootDir.findFileByRelativePath(relPath);
|
||||
assert file != null;
|
||||
configureByExistingFile(file);
|
||||
final PsiElement element = TargetElementUtil.findTargetElement(myEditor,
|
||||
TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED |
|
||||
TargetElementUtil.ELEMENT_NAME_ACCEPTED);
|
||||
assert element != null;
|
||||
final PsiElement substitution = RenamePsiElementProcessor.forElement(element).substituteElementToRename(element, myEditor);
|
||||
assert substitution != null;
|
||||
new RenameProcessor(getProject(), substitution, newName, true, true).run();
|
||||
}
|
||||
doTest(() -> {
|
||||
final VirtualFile file = myFixture.findFileInTempDir(relPath);
|
||||
assert file != null;
|
||||
myFixture.configureFromExistingVirtualFile(file);
|
||||
final PsiElement element = TargetElementUtil.findTargetElement(getEditor(),
|
||||
TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED |
|
||||
TargetElementUtil.ELEMENT_NAME_ACCEPTED);
|
||||
assert element != null;
|
||||
final PsiElement substitution = RenamePsiElementProcessor.forElement(element).substituteElementToRename(element, getEditor());
|
||||
assert substitution != null;
|
||||
new RenameProcessor(getProject(), substitution, newName, true, true).run();
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/spi/";
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/spi/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
|
||||
public abstract class RefactoringTestCase extends CodeInsightTestCase {
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2000-2019 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 com.intellij.refactoring;
|
||||
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class LightMultiFileTestCase extends LightCodeInsightFixtureTestCase {
|
||||
protected void doTest(final ThrowableRunnable<? extends Exception> performAction) {
|
||||
doTest(performAction, getTestName(true));
|
||||
}
|
||||
|
||||
protected void doTest(final ThrowableRunnable<? extends Exception> performAction, final boolean lowercaseFirstLetter) {
|
||||
doTest(performAction, getTestName(lowercaseFirstLetter));
|
||||
}
|
||||
|
||||
protected void doTest (final ThrowableRunnable<? extends Exception> performAction, final String testName) {
|
||||
try {
|
||||
|
||||
VirtualFile actualDirectory = myFixture.copyDirectoryToProject(testName + "/before", "");
|
||||
|
||||
performAction.run();
|
||||
|
||||
final VirtualFile rootAfter = LocalFileSystem.getInstance().findFileByPath(getTestDataPath().replace(File.separatorChar, '/') + testName + "/after");
|
||||
assertNotNull(rootAfter);
|
||||
|
||||
PlatformTestUtil.assertDirectoriesEqual(rootAfter, actualDirectory);
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected interface PerformAction {
|
||||
void performAction() throws Exception;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
* Heavy weight: creates project for each test method. Consider using {@link LightMultiFileTestCase} instead
|
||||
*/
|
||||
public abstract class MultiFileTestCase extends CodeInsightTestCase {
|
||||
protected boolean myDoCompare = true;
|
||||
|
||||
@@ -6,30 +6,29 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTestRoot() {
|
||||
return "/refactoring/migrateTypeSignature/";
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/refactoring/migrateTypeSignature/";
|
||||
}
|
||||
|
||||
public void testExprAccess2Lvalue() {
|
||||
doTestFieldType("myForAccess", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("ClassParent", null));
|
||||
getElementFactory().createTypeFromText("ClassParent", null));
|
||||
}
|
||||
|
||||
public void testExprAccess2Rvalue() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("ClassGrandChild", null));
|
||||
getElementFactory().createTypeFromText("ClassGrandChild", null));
|
||||
}
|
||||
|
||||
public void testExprAccessParent2Lvalue() {
|
||||
doTestFieldType("myForSuperAccess", "Ession",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("ClassParent", null));
|
||||
getElementFactory().createTypeFromText("ClassParent", null));
|
||||
}
|
||||
|
||||
public void testExprAccessParent2Rvalue() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("ClassGrandChild", null));
|
||||
getElementFactory().createTypeFromText("ClassGrandChild", null));
|
||||
}
|
||||
|
||||
public void testExprArrayAccessNegative() {
|
||||
@@ -46,7 +45,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testExprCalcBooleanNumeric() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, null));
|
||||
getElementFactory().createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, null));
|
||||
}
|
||||
|
||||
public void testExprCalcBooleanReference() {
|
||||
@@ -68,12 +67,12 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testExprCalcNumeric2String() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
}
|
||||
|
||||
public void testExprCast2LvalueNeg() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
}
|
||||
|
||||
public void testExprCast2LvaluePos() {
|
||||
@@ -82,12 +81,12 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testExprConcatNumeric2Reference() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, null));
|
||||
getElementFactory().createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, null));
|
||||
}
|
||||
|
||||
public void testExprConcatNumeric2String() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
}
|
||||
|
||||
public void testExprConcatString2Numeric() {
|
||||
@@ -97,17 +96,17 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testExprConcatString2Reference() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, null));
|
||||
getElementFactory().createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, null));
|
||||
}
|
||||
|
||||
public void testExprInstanceofNeg() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_LIST, null));
|
||||
getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_LIST, null));
|
||||
}
|
||||
|
||||
public void testExprInstanceofPos() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.AbstractMap", null));
|
||||
getElementFactory().createTypeFromText("java.util.AbstractMap", null));
|
||||
}
|
||||
|
||||
public void testExprLiteralBoolean() {
|
||||
@@ -127,37 +126,37 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testExprLiteralClassExtends() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Class<? extends java.util.Collection[]>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Class<? extends java.util.Collection[]>", null));
|
||||
}
|
||||
|
||||
public void testExprLiteralClassPrimitive() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Class<Integer>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Class<Integer>", null));
|
||||
}
|
||||
|
||||
public void testExprLiteralClassPrimitiveArray() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Class<int[]>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Class<int[]>", null));
|
||||
}
|
||||
|
||||
public void testExprLiteralClassRaw() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Class", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Class", null));
|
||||
}
|
||||
|
||||
public void testExprLiteralClassReference() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Class<java.util.Set>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Class<java.util.Set>", null));
|
||||
}
|
||||
|
||||
public void testExprLiteralClassReferenceArray() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Class<java.util.Set[]>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Class<java.util.Set[]>", null));
|
||||
}
|
||||
|
||||
public void testExprLiteralClassSuper() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Class<? super java.util.AbstractSet[]>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Class<? super java.util.AbstractSet[]>", null));
|
||||
}
|
||||
|
||||
public void testExprLiteralDouble() {
|
||||
@@ -187,22 +186,22 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testExprLiteralString() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
}
|
||||
|
||||
public void testExprNewArrayArray2Lvalue() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("FaceParent", null).createArrayType());
|
||||
getElementFactory().createTypeFromText("FaceParent", null).createArrayType());
|
||||
}
|
||||
|
||||
public void testExprNewArrayArray2Rvalue() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("ClassParent", null).createArrayType().createArrayType().createArrayType());
|
||||
getElementFactory().createTypeFromText("ClassParent", null).createArrayType().createArrayType().createArrayType());
|
||||
}
|
||||
|
||||
public void testExprNewArrayGen2Rvalue() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<java.lang.Integer>", null).createArrayType());
|
||||
getElementFactory().createTypeFromText("java.util.Set<java.lang.Integer>", null).createArrayType());
|
||||
}
|
||||
|
||||
public void testExprNewArrayPrimitive2Lvalue() {
|
||||
@@ -216,47 +215,47 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testExprNewArrayReftype2Lvalue() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("FaceParent", null));
|
||||
getElementFactory().createTypeFromText("FaceParent", null));
|
||||
}
|
||||
|
||||
public void testExprNewArrayReftype2Rvalue() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("ClassParent", null).createArrayType().createArrayType());
|
||||
getElementFactory().createTypeFromText("ClassParent", null).createArrayType().createArrayType());
|
||||
}
|
||||
|
||||
public void testExprNewGen() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<Subject>", null));
|
||||
getElementFactory().createTypeFromText("java.util.Set<Subject>", null));
|
||||
}
|
||||
|
||||
public void testExprNewGenExtends() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<? extends Subject>", null));
|
||||
getElementFactory().createTypeFromText("java.util.Set<? extends Subject>", null));
|
||||
}
|
||||
|
||||
public void testExprNewGenSuper() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<? super Subject>", null));
|
||||
getElementFactory().createTypeFromText("java.util.Set<? super Subject>", null));
|
||||
}
|
||||
|
||||
public void testExprNewReference() {
|
||||
doTestFieldType("myField", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("Expr.Subject", null));
|
||||
getElementFactory().createTypeFromText("Expr.Subject", null));
|
||||
}
|
||||
|
||||
public void testExprReturn2Lvalue() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
}
|
||||
|
||||
public void testExprReturn2Rvalue() {
|
||||
doTestMethodType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
}
|
||||
|
||||
public void testExprTernary() {
|
||||
doTestFirstParamType("meth", "Expr",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
}
|
||||
|
||||
public void testOverridingDown() {
|
||||
@@ -271,7 +270,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_ALWAYS;
|
||||
doTestFirstParamType("meth", "Spec",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_SET, null));
|
||||
getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_SET, null));
|
||||
}
|
||||
|
||||
public void testSpecNotUsed() {
|
||||
@@ -280,37 +279,37 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeArrayReftype2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("Subject", null).createArrayType());
|
||||
getElementFactory().createTypeFromText("Subject", null).createArrayType());
|
||||
}
|
||||
|
||||
public void testTypeArrayReftype2Rvalue() {
|
||||
doTestFieldType("myField", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("Subject", null).createArrayType().createArrayType());
|
||||
getElementFactory().createTypeFromText("Subject", null).createArrayType().createArrayType());
|
||||
}
|
||||
|
||||
public void testTypeArrayRoots2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("Holder", null).createArrayType());
|
||||
getElementFactory().createTypeFromText("Holder", null).createArrayType());
|
||||
}
|
||||
|
||||
public void testTypeArrayVararg2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
new PsiEllipsisType(myJavaFacade.getElementFactory().createTypeFromText("Subject", null)));
|
||||
new PsiEllipsisType(getElementFactory().createTypeFromText("Subject", null)));
|
||||
}
|
||||
|
||||
public void testTypeArrayVararg2RvalueNeg() {
|
||||
doTestFieldType("myField", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("Descendant", null).createArrayType());
|
||||
getElementFactory().createTypeFromText("Descendant", null).createArrayType());
|
||||
}
|
||||
|
||||
public void testTypeArrayVararg2RvaluePos() {
|
||||
doTestFieldType("myField", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("Subject", null).createArrayType());
|
||||
getElementFactory().createTypeFromText("Subject", null).createArrayType());
|
||||
}
|
||||
|
||||
public void testTypeAutoboxBoolean2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Boolean", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Boolean", null));
|
||||
}
|
||||
|
||||
public void testTypeAutoboxBoolean2Rvalue() {
|
||||
@@ -320,7 +319,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeAutoboxByte2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Byte", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Byte", null));
|
||||
}
|
||||
|
||||
public void testTypeAutoboxByte2Rvalue() {
|
||||
@@ -330,7 +329,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeAutoboxChar2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Character", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Character", null));
|
||||
}
|
||||
|
||||
public void testTypeAutoboxChar2Rvalue() {
|
||||
@@ -340,7 +339,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeAutoboxDouble2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Double", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Double", null));
|
||||
}
|
||||
|
||||
public void testTypeAutoboxDouble2Rvalue() {
|
||||
@@ -350,7 +349,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeAutoboxFloat2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Float", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Float", null));
|
||||
}
|
||||
|
||||
public void testTypeAutoboxFloat2Rvalue() {
|
||||
@@ -360,7 +359,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeAutoboxInt2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Integer", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Integer", null));
|
||||
}
|
||||
|
||||
public void testTypeAutoboxInt2Rvalue() {
|
||||
@@ -370,7 +369,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeAutoboxLong2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Long", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Long", null));
|
||||
}
|
||||
|
||||
public void testTypeAutoboxLong2Rvalue() {
|
||||
@@ -380,7 +379,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeAutoboxShort2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Short", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Short", null));
|
||||
}
|
||||
|
||||
public void testTypeAutoboxShort2Rvalue() {
|
||||
@@ -390,32 +389,32 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeGenAncestor2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<Subject>", null));
|
||||
getElementFactory().createTypeFromText("java.util.Set<Subject>", null));
|
||||
}
|
||||
|
||||
public void testTypeGenAncestorWildcard2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<? extends Subject>", null));
|
||||
getElementFactory().createTypeFromText("java.util.Set<? extends Subject>", null));
|
||||
}
|
||||
|
||||
public void testTypeGenDescendant2Rvalue() {
|
||||
doTestFieldType("myField", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<Subject>", null));
|
||||
getElementFactory().createTypeFromText("java.util.Set<Subject>", null));
|
||||
}
|
||||
|
||||
public void testTypeGenDescendantWildcard2Rvalue() {
|
||||
doTestFieldType("myField", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<? super Subject>", null));
|
||||
getElementFactory().createTypeFromText("java.util.Set<? super Subject>", null));
|
||||
}
|
||||
|
||||
public void testTypeGenRaw2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_SET, null));
|
||||
getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_SET, null));
|
||||
}
|
||||
|
||||
public void testTypeGenRaw2Rvalue() {
|
||||
doTestFieldType("myField", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_SET, null));
|
||||
getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_SET, null));
|
||||
}
|
||||
|
||||
public void testTypePrimsubBoolean2Lvalue() {
|
||||
@@ -476,42 +475,42 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
|
||||
public void testTypeRefClassChild2Rvalue() {
|
||||
doTestFieldType("myField", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("ClassChild", null));
|
||||
getElementFactory().createTypeFromText("ClassChild", null));
|
||||
}
|
||||
|
||||
public void testTypeRefClassParent2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("ClassParent", null));
|
||||
getElementFactory().createTypeFromText("ClassParent", null));
|
||||
}
|
||||
|
||||
public void testTypeRefClassParent2Rvalue() {
|
||||
doTestFieldType("myField", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("ClassParent", null));
|
||||
getElementFactory().createTypeFromText("ClassParent", null));
|
||||
}
|
||||
|
||||
public void testTypeRefFaceChild2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("FaceChild", null));
|
||||
getElementFactory().createTypeFromText("FaceChild", null));
|
||||
}
|
||||
|
||||
public void testTypeRefFaceChild2Rvalue() {
|
||||
doTestFieldType("myField", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("FaceChild", null));
|
||||
getElementFactory().createTypeFromText("FaceChild", null));
|
||||
}
|
||||
|
||||
public void testTypeRefFaceParent2Lvalue() {
|
||||
doTestFirstParamType("meth", "Type",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("FaceParent", null));
|
||||
getElementFactory().createTypeFromText("FaceParent", null));
|
||||
}
|
||||
|
||||
public void testMigrateAnonymousClassTypeParameters() {
|
||||
doTestAnonymousClassMethod("invoke",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
}
|
||||
|
||||
public void testMigrateAnonymousClassTypeParameters2() {
|
||||
doTestAnonymousClassMethod("invoke",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Long", null));
|
||||
getElementFactory().createTypeFromText("java.lang.Long", null));
|
||||
}
|
||||
|
||||
protected void doTestAnonymousClassMethod(@NotNull final String methodName,
|
||||
|
||||
+14
-16
@@ -1,20 +1,18 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.psi.PsiType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicIntegerArray;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
public class TypeMigrationByAtomicRuleTest extends TypeMigrationTestBase{
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/typeMigrationByAtomic/";
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/refactoring/typeMigrationByAtomic/";
|
||||
}
|
||||
|
||||
private void doTestDirectMigration() {
|
||||
doTestFieldType("i", myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicInteger", null));
|
||||
doTestFieldType("i", getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicInteger", null));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,38 +25,38 @@ public class TypeMigrationByAtomicRuleTest extends TypeMigrationTestBase{
|
||||
}
|
||||
|
||||
public void testDirectConditions() {
|
||||
doTestFieldType("b", myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicBoolean", null));
|
||||
doTestFieldType("b", getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicBoolean", null));
|
||||
}
|
||||
|
||||
public void testDirectConditionalExpression() {
|
||||
doTestFieldType("s",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.String>", null));
|
||||
getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.String>", null));
|
||||
}
|
||||
|
||||
|
||||
public void testDirectByte() {
|
||||
doTestFieldType("b",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.Byte>", null));
|
||||
getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.Byte>", null));
|
||||
}
|
||||
|
||||
public void testDirectString() {
|
||||
doTestFieldType("s",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.String>", null));
|
||||
getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.lang.String>", null));
|
||||
}
|
||||
|
||||
public void testDirectForeach() {
|
||||
doTestFieldType("lst",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.util.List<java.lang.String>>", null));
|
||||
getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicReference<java.util.List<java.lang.String>>", null));
|
||||
}
|
||||
|
||||
public void testDirectStringArray() {
|
||||
doTestFieldType("s",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(AtomicReferenceArray.class.getName() + "<java.lang.String>", null));
|
||||
getElementFactory().createTypeFromText(AtomicReferenceArray.class.getName() + "<java.lang.String>", null));
|
||||
}
|
||||
|
||||
public void testDirectIntArray() {
|
||||
doTestFieldType("a",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(AtomicIntegerArray.class.getName(), null));
|
||||
getElementFactory().createTypeFromText(AtomicIntegerArray.class.getName(), null));
|
||||
}
|
||||
|
||||
private void doTestReverseMigration() {
|
||||
@@ -84,12 +82,12 @@ public class TypeMigrationByAtomicRuleTest extends TypeMigrationTestBase{
|
||||
|
||||
public void testReverseString() {
|
||||
doTestFieldType("s",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
getElementFactory().createTypeFromText("java.lang.String", null));
|
||||
}
|
||||
|
||||
public void testReverseStringArray() {
|
||||
doTestFieldType("s",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.String", null).createArrayType());
|
||||
getElementFactory().createTypeFromText("java.lang.String", null).createArrayType());
|
||||
}
|
||||
|
||||
public void testReverseIntArray() {
|
||||
@@ -98,10 +96,10 @@ public class TypeMigrationByAtomicRuleTest extends TypeMigrationTestBase{
|
||||
}
|
||||
|
||||
public void testChainedInitialization() {
|
||||
doTestFieldType("a", myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicInteger", null));
|
||||
doTestFieldType("a", getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicInteger", null));
|
||||
}
|
||||
|
||||
public void testLiteralMigration() {
|
||||
doTestFieldType("a", myJavaFacade.getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicLong", null));
|
||||
doTestFieldType("a", getElementFactory().createTypeFromText("java.util.concurrent.atomic.AtomicLong", null));
|
||||
}
|
||||
}
|
||||
@@ -16,35 +16,33 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.refactoring.typeMigration.rules.LongAdderConversionRule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Dmitry Batkovich
|
||||
*/
|
||||
public class TypeMigrationByLongAdderTest extends TypeMigrationTestBase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/typeMigrationByLongAdder/";
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/refactoring/typeMigrationByLongAdder/";
|
||||
}
|
||||
|
||||
public void testDirectCallsWithoutAssignment() {
|
||||
doTestFieldType("l",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(LongAdderConversionRule.JAVA_UTIL_CONCURRENT_ATOMIC_LONG_ADDER, null));
|
||||
getElementFactory().createTypeFromText(LongAdderConversionRule.JAVA_UTIL_CONCURRENT_ATOMIC_LONG_ADDER, null));
|
||||
}
|
||||
|
||||
public void testIncrementDecrement() {
|
||||
doTestFieldType("l",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(LongAdderConversionRule.JAVA_UTIL_CONCURRENT_ATOMIC_LONG_ADDER, null));
|
||||
getElementFactory().createTypeFromText(LongAdderConversionRule.JAVA_UTIL_CONCURRENT_ATOMIC_LONG_ADDER, null));
|
||||
}
|
||||
|
||||
public void testToPrimitivesAndString() {
|
||||
doTestFieldType("i",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(LongAdderConversionRule.JAVA_UTIL_CONCURRENT_ATOMIC_LONG_ADDER, null));
|
||||
getElementFactory().createTypeFromText(LongAdderConversionRule.JAVA_UTIL_CONCURRENT_ATOMIC_LONG_ADDER, null));
|
||||
}
|
||||
|
||||
public void testUnconvertable() {
|
||||
doTestFieldType("i",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(LongAdderConversionRule.JAVA_UTIL_CONCURRENT_ATOMIC_LONG_ADDER, null));
|
||||
getElementFactory().createTypeFromText(LongAdderConversionRule.JAVA_UTIL_CONCURRENT_ATOMIC_LONG_ADDER, null));
|
||||
}
|
||||
}
|
||||
|
||||
+8
-18
@@ -1,38 +1,28 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
|
||||
public class TypeMigrationByThreadLocalRuleTest extends TypeMigrationTestBase{
|
||||
@NotNull
|
||||
public class TypeMigrationByThreadLocalRuleTest extends TypeMigrationTestBase {
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/typeMigrationByThreadLocal/";
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/refactoring/typeMigrationByThreadLocal/";
|
||||
}
|
||||
|
||||
|
||||
public void testDirectInt() {
|
||||
doTestFieldType("i", myJavaFacade.getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.lang.Integer>", null));
|
||||
doTestFieldType("i", getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.lang.Integer>", null));
|
||||
}
|
||||
|
||||
public void testDirectByte() {
|
||||
doTestFieldType("i", myJavaFacade.getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.lang.Byte>", null));
|
||||
doTestFieldType("i", getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.lang.Byte>", null));
|
||||
}
|
||||
|
||||
public void testDirectString() {
|
||||
doTestFieldType("myS", myJavaFacade.getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.lang.String>", null));
|
||||
doTestFieldType("myS", getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.lang.String>", null));
|
||||
}
|
||||
|
||||
public void testLanguageLevel() {
|
||||
final LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(getProject());
|
||||
final LanguageLevel languageLevel = extension.getLanguageLevel();
|
||||
try {
|
||||
extension.setLanguageLevel(LanguageLevel.JDK_1_3);
|
||||
doTestFieldType("i", myJavaFacade.getElementFactory().createTypeFromText("java.lang.ThreadLocal", null));
|
||||
}
|
||||
finally {
|
||||
extension.setLanguageLevel(languageLevel);
|
||||
}
|
||||
IdeaTestUtil.withLevel(myModule, LanguageLevel.JDK_1_3, () -> doTestFieldType("i", getElementFactory().createTypeFromText("java.lang.ThreadLocal", null)));
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -16,17 +17,22 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class TypeMigrationTest extends TypeMigrationTestBase {
|
||||
private PsiElementFactory myFactory;
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/refactoring/typeMigration/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTestRoot() {
|
||||
return "/refactoring/typeMigration/";
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_LATEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.HIGHEST);
|
||||
myFactory = myJavaFacade.getElementFactory();
|
||||
myFactory = getElementFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -675,7 +681,7 @@ public class TypeMigrationTest extends TypeMigrationTestBase {
|
||||
|
||||
// Checking preserving method parameters alignment
|
||||
public void testT127() {
|
||||
CommonCodeStyleSettings javaSettings = CodeStyle.getSettings(myProject).getCommonSettings(JavaLanguage.INSTANCE);
|
||||
CommonCodeStyleSettings javaSettings = CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaSettings.ALIGN_MULTILINE_PARAMETERS = true;
|
||||
javaSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
|
||||
doTestMethodType("test234",
|
||||
@@ -745,9 +751,9 @@ public class TypeMigrationTest extends TypeMigrationTestBase {
|
||||
}
|
||||
|
||||
public void testT136() {
|
||||
final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
|
||||
final GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
|
||||
doTestFirstParamType("foo", "Test",
|
||||
PsiType.getJavaLangString(myPsiManager, scope));
|
||||
PsiType.getJavaLangString(getPsiManager(), scope));
|
||||
}
|
||||
|
||||
public void testT137() {
|
||||
@@ -831,11 +837,11 @@ public class TypeMigrationTest extends TypeMigrationTestBase {
|
||||
}
|
||||
|
||||
public void testMigrationToSuper() {
|
||||
doTestFieldType("b", myJavaFacade.getElementFactory().createTypeFromText("Test.A<java.lang.String>", null));
|
||||
doTestFieldType("b", myFactory.createTypeFromText("Test.A<java.lang.String>", null));
|
||||
}
|
||||
|
||||
public void testMigrationToSuper2() {
|
||||
doTestFieldType("b", myJavaFacade.getElementFactory().createTypeFromText("Test.Base<java.lang.String>", null));
|
||||
doTestFieldType("b", myFactory.createTypeFromText("Test.Base<java.lang.String>", null));
|
||||
}
|
||||
|
||||
public void testMultiVarDeclaration1() {
|
||||
@@ -863,15 +869,15 @@ public class TypeMigrationTest extends TypeMigrationTestBase {
|
||||
}
|
||||
|
||||
public void testGenericEllipsis() {
|
||||
doTestFieldType("migrationField", myJavaFacade.getElementFactory().createTypeFromText("Test<Short>", null));
|
||||
doTestFieldType("migrationField", myFactory.createTypeFromText("Test<Short>", null));
|
||||
}
|
||||
|
||||
public void testGenericEllipsis2() {
|
||||
doTestFieldType("migrationField", myJavaFacade.getElementFactory().createTypeFromText("Test<Short>", null));
|
||||
doTestFieldType("migrationField", myFactory.createTypeFromText("Test<Short>", null));
|
||||
}
|
||||
|
||||
public void testTypeParameterMigrationInInvalidCode() {
|
||||
doTestFieldType("migrationField", myJavaFacade.getElementFactory().createTypeFromText("Test<Short>", null));
|
||||
doTestFieldType("migrationField", myFactory.createTypeFromText("Test<Short>", null));
|
||||
}
|
||||
|
||||
private void doTestReturnType(final String methodName, final String migrationType) {
|
||||
|
||||
@@ -4,17 +4,14 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.typeMigration.TypeMigrationProcessor;
|
||||
import com.intellij.refactoring.typeMigration.TypeMigrationRules;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.Functions;
|
||||
@@ -22,15 +19,12 @@ import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
*/
|
||||
public abstract class TypeMigrationTestBase extends MultiFileTestCase {
|
||||
public abstract class TypeMigrationTestBase extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PlatformTestUtil.getCommunityPath() + "/java/typeMigration/testData";
|
||||
@@ -141,19 +135,11 @@ public abstract class TypeMigrationTestBase extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void start(final RulesProvider provider, final String className) {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
TypeMigrationTestBase.this.performAction(className, rootDir.getName(), provider);
|
||||
}
|
||||
});
|
||||
doTest(() -> this.performAction(className, provider));
|
||||
}
|
||||
|
||||
private void performAction(String className, String rootDir, RulesProvider provider) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
|
||||
assertNotNull("Class " + className + " not found", aClass);
|
||||
|
||||
private void performAction(String className, RulesProvider provider) throws Exception {
|
||||
PsiClass aClass = myFixture.findClass(className);
|
||||
final PsiElement[] migrationElements = provider.victims(aClass);
|
||||
final PsiType migrationType = provider.migrationType(migrationElements[0]);
|
||||
final TypeMigrationRules rules = new TypeMigrationRules(getProject());
|
||||
@@ -165,30 +151,9 @@ public abstract class TypeMigrationTestBase extends MultiFileTestCase {
|
||||
|
||||
WriteCommandAction.runWriteCommandAction(null, () -> pr.performRefactoring(usages));
|
||||
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), () -> getProject().getComponent(PostprocessReformattingAspect.class).doPostponedFormatting());
|
||||
|
||||
String itemName = className + ".items";
|
||||
String patternName = getTestDataPath() + getTestRoot() + getTestName(true) + "/after/" + itemName;
|
||||
|
||||
File patternFile = new File(patternName);
|
||||
|
||||
if (!patternFile.exists()) {
|
||||
try (PrintWriter writer = new PrintWriter(new FileOutputStream(patternFile))) {
|
||||
writer.print(report);
|
||||
}
|
||||
|
||||
System.err.println("Pattern not found, file " + patternName + " created.");
|
||||
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(patternFile);
|
||||
}
|
||||
|
||||
File graFile = new File(FileUtil.getTempDirectory() + File.separator + rootDir + File.separator + itemName);
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(new FileOutputStream(graFile))) {
|
||||
writer.print(report);
|
||||
}
|
||||
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(graFile);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
myFixture.getTempDirFixture().createFile(className + ".items", report);
|
||||
}
|
||||
|
||||
interface RulesProvider {
|
||||
@@ -209,4 +174,10 @@ public abstract class TypeMigrationTestBase extends MultiFileTestCase {
|
||||
super(project, roots, Functions.constant(migrationType), rules, true);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_1_6;
|
||||
}
|
||||
}
|
||||
@@ -1,144 +1,142 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WildcardTypeMigrationTest extends TypeMigrationTestBase{
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/wildcard/";
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/refactoring/wildcard/";
|
||||
}
|
||||
|
||||
public void testProducerExtends() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<? extends java.lang.Number>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<? extends java.lang.Number>", null));
|
||||
}
|
||||
|
||||
public void testProducerSuper() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<? super java.lang.Integer>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<? super java.lang.Integer>", null));
|
||||
}
|
||||
|
||||
public void testProducerUnbounded() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
}
|
||||
|
||||
public void testProducerCollectionChanged() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<? super java.lang.Integer>", null));
|
||||
getElementFactory().createTypeFromText("java.util.Set<? super java.lang.Integer>", null));
|
||||
}
|
||||
|
||||
public void testProducerExtendsCollectionChanged() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.Set<? extends java.lang.Object>", null));
|
||||
getElementFactory().createTypeFromText("java.util.Set<? extends java.lang.Object>", null));
|
||||
}
|
||||
|
||||
public void testProducerStopAtWildcard() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.List<? super java.lang.Number>", null));
|
||||
getElementFactory().createTypeFromText("java.util.List<? super java.lang.Number>", null));
|
||||
}
|
||||
|
||||
public void testProducerFailToStopAtWildcard() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.List<? super java.lang.Integer>", null));
|
||||
getElementFactory().createTypeFromText("java.util.List<? super java.lang.Integer>", null));
|
||||
}
|
||||
|
||||
public void testProducerExtendsFailToStopAtWildcard() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.List<? extends java.lang.Number>", null));
|
||||
getElementFactory().createTypeFromText("java.util.List<? extends java.lang.Number>", null));
|
||||
}
|
||||
|
||||
|
||||
public void testConsumerExtends() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<? extends java.lang.Number>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<? extends java.lang.Number>", null));
|
||||
}
|
||||
|
||||
public void testConsumerSuper() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<? super java.lang.Number>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<? super java.lang.Number>", null));
|
||||
}
|
||||
|
||||
public void testConsumerUnbounded() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
}
|
||||
|
||||
// array -> list
|
||||
public void testAssignmentExtends() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<? extends java.lang.Integer>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<? extends java.lang.Integer>", null));
|
||||
}
|
||||
|
||||
public void testAssignmentSuper() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<? super java.lang.Integer>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<? super java.lang.Integer>", null));
|
||||
}
|
||||
|
||||
public void testAssignmentUnbounded() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
}
|
||||
|
||||
public void testGetExtends() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<? extends java.lang.Integer>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<? extends java.lang.Integer>", null));
|
||||
}
|
||||
|
||||
public void testGetSuper() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<? super java.lang.Integer>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<? super java.lang.Integer>", null));
|
||||
}
|
||||
|
||||
public void testGetUnbounded() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
|
||||
}
|
||||
|
||||
public void testLengthSize() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
getElementFactory().createTypeFromText("java.util.ArrayList<?>", null));
|
||||
|
||||
}
|
||||
|
||||
//list -> array
|
||||
public void testGetAssignmentExtendsToType() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Number", null).createArrayType());
|
||||
getElementFactory().createTypeFromText("java.lang.Number", null).createArrayType());
|
||||
}
|
||||
|
||||
public void testGetAssignmentExtendsToSuperType() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, null).createArrayType());
|
||||
getElementFactory().createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, null).createArrayType());
|
||||
}
|
||||
|
||||
public void testGetAssignmentExtendsToChildType() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.Integer", null).createArrayType());
|
||||
getElementFactory().createTypeFromText("java.lang.Integer", null).createArrayType());
|
||||
}
|
||||
|
||||
// -> threadlocal with wildcard
|
||||
public void testThreadLocalProducerExtends() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.util.List<? extends String>>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.util.List<? extends String>>", null));
|
||||
}
|
||||
|
||||
//List<? super String> is not assignable to List<String> though it is possible to pass string where ? super String was
|
||||
public void _testThreadLocalProducerSuper() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.util.List<? super String>>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.ThreadLocal<java.util.List<? super String>>", null));
|
||||
}
|
||||
|
||||
public void testThreadLocalConsumerSuper() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.ThreadLocal<? super String>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.ThreadLocal<? super String>", null));
|
||||
}
|
||||
|
||||
public void testThreadLocalConsumerExtends() {
|
||||
doTestFirstParamType("method",
|
||||
myJavaFacade.getElementFactory().createTypeFromText("java.lang.ThreadLocal<? extends String>", null));
|
||||
getElementFactory().createTypeFromText("java.lang.ThreadLocal<? extends String>", null));
|
||||
}
|
||||
}
|
||||
@@ -16,25 +16,17 @@
|
||||
package com.intellij.uiDesigner.refactoring;
|
||||
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.LightMultiFileTestCase;
|
||||
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MoveFileTest extends MultiFileTestCase {
|
||||
public class MoveFileTest extends LightMultiFileTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PluginPathManager.getPluginHomePath("ui-designer") + "/testData";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/move/";
|
||||
return PluginPathManager.getPluginHomePath("ui-designer") + "/testData/move/";
|
||||
}
|
||||
|
||||
public void testMoveIcon() {
|
||||
@@ -43,27 +35,17 @@ public class MoveFileTest extends MultiFileTestCase {
|
||||
|
||||
//Both names are relative to root directory
|
||||
private void doTest(final String targetDirName, final String fileToMove) {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) {
|
||||
final VirtualFile child = rootDir.findFileByRelativePath(fileToMove);
|
||||
assertNotNull("File " + fileToMove + " not found", child);
|
||||
PsiFile file = myPsiManager.findFile(child);
|
||||
doTest(() -> {
|
||||
final VirtualFile child = myFixture.findFileInTempDir(fileToMove);
|
||||
assertNotNull("File " + fileToMove + " not found", child);
|
||||
PsiFile file = getPsiManager().findFile(child);
|
||||
|
||||
final VirtualFile child1 = rootDir.findChild(targetDirName);
|
||||
assertNotNull("File " + targetDirName + " not found", child1);
|
||||
final PsiDirectory targetDirectory = myPsiManager.findDirectory(child1);
|
||||
final VirtualFile child1 = myFixture.findFileInTempDir(targetDirName);
|
||||
assertNotNull("File " + targetDirName + " not found", child1);
|
||||
final PsiDirectory targetDirectory = getPsiManager().findDirectory(child1);
|
||||
|
||||
new MoveFilesOrDirectoriesProcessor(myProject, new PsiElement[] {file}, targetDirectory,
|
||||
false, false, null, null).run();
|
||||
/*assert targetDirectory != null;
|
||||
final PsiFile psiFile = targetDirectory.findFile(fileToMove);
|
||||
assert psiFile != null;
|
||||
final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiFile);
|
||||
assert document != null;
|
||||
PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(document);*/
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
new MoveFilesOrDirectoriesProcessor(getProject(), new PsiElement[]{file}, targetDirectory,
|
||||
false, false, null, null).run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user