mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
convert refactoring tests to java 8
This commit is contained in:
@@ -46,28 +46,22 @@ public abstract class ChangeSignatureBaseTest extends LightRefactoringTestCase {
|
||||
@Nullable final String[] parameters,
|
||||
@Nullable final String[] exceptions,
|
||||
boolean delegate) {
|
||||
GenParams genParams = parameters == null ? new SimpleParameterGen() : new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
ParameterInfoImpl[] parameterInfos = new ParameterInfoImpl[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiType type = myFactory.createTypeFromText(parameters[i], method);
|
||||
parameterInfos[i] = new ParameterInfoImpl(-1, "p" + (i + 1), type);
|
||||
}
|
||||
return parameterInfos;
|
||||
GenParams genParams = parameters == null ? new SimpleParameterGen() : method -> {
|
||||
ParameterInfoImpl[] parameterInfos = new ParameterInfoImpl[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiType type = myFactory.createTypeFromText(parameters[i], method);
|
||||
parameterInfos[i] = new ParameterInfoImpl(-1, "p" + (i + 1), type);
|
||||
}
|
||||
return parameterInfos;
|
||||
};
|
||||
|
||||
GenExceptions genExceptions = exceptions == null ? new SimpleExceptionsGen() : new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) throws IncorrectOperationException {
|
||||
ThrownExceptionInfo[] exceptionInfos = new ThrownExceptionInfo[exceptions.length];
|
||||
for (int i = 0; i < exceptions.length; i++) {
|
||||
PsiType type = myFactory.createTypeFromText(exceptions[i], method);
|
||||
exceptionInfos[i] = new JavaThrownExceptionInfo(-1, (PsiClassType)type);
|
||||
}
|
||||
return exceptionInfos;
|
||||
GenExceptions genExceptions = exceptions == null ? new SimpleExceptionsGen() : method -> {
|
||||
ThrownExceptionInfo[] exceptionInfos = new ThrownExceptionInfo[exceptions.length];
|
||||
for (int i = 0; i < exceptions.length; i++) {
|
||||
PsiType type = myFactory.createTypeFromText(exceptions[i], method);
|
||||
exceptionInfos[i] = new JavaThrownExceptionInfo(-1, (PsiClassType)type);
|
||||
}
|
||||
return exceptionInfos;
|
||||
};
|
||||
|
||||
doTest(null, null, returnType, genParams, genExceptions, delegate);
|
||||
|
||||
@@ -102,34 +102,28 @@ public class ChangeSignatureGestureTest extends LightCodeInsightFixtureTestCase
|
||||
}
|
||||
|
||||
public void testOnAnotherMethod() {
|
||||
doTest(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myFixture.type("int param");
|
||||
final int nextMethodOffset = ((PsiJavaFile)myFixture.getFile()).getClasses()[0].getMethods()[1].getTextOffset();
|
||||
myFixture.getEditor().getCaretModel().moveToOffset(nextMethodOffset);
|
||||
}
|
||||
doTest(() -> {
|
||||
myFixture.type("int param");
|
||||
final int nextMethodOffset = ((PsiJavaFile)myFixture.getFile()).getClasses()[0].getMethods()[1].getTextOffset();
|
||||
myFixture.getEditor().getCaretModel().moveToOffset(nextMethodOffset);
|
||||
}, false, ChangeSignatureDetectorAction.CHANGE_SIGNATURE);
|
||||
}
|
||||
|
||||
public void testAddParamChangeReturnType() {
|
||||
doTest(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myFixture.type("int param");
|
||||
CaretModel model = myFixture.getEditor().getCaretModel();
|
||||
PsiElement element = myFixture.getElementAtCaret();
|
||||
PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false);
|
||||
assertTrue(method != null);
|
||||
PsiTypeElement returnTypeElement = method.getReturnTypeElement();
|
||||
assertTrue(returnTypeElement != null);
|
||||
model.moveToOffset(returnTypeElement.getTextRange().getEndOffset());
|
||||
int i = returnTypeElement.getTextLength();
|
||||
while (i-- > 0) {
|
||||
myFixture.type('\b');
|
||||
}
|
||||
myFixture.type("boolean");
|
||||
doTest(() -> {
|
||||
myFixture.type("int param");
|
||||
CaretModel model = myFixture.getEditor().getCaretModel();
|
||||
PsiElement element = myFixture.getElementAtCaret();
|
||||
PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false);
|
||||
assertTrue(method != null);
|
||||
PsiTypeElement returnTypeElement = method.getReturnTypeElement();
|
||||
assertTrue(returnTypeElement != null);
|
||||
model.moveToOffset(returnTypeElement.getTextRange().getEndOffset());
|
||||
int i = returnTypeElement.getTextLength();
|
||||
while (i-- > 0) {
|
||||
myFixture.type('\b');
|
||||
}
|
||||
myFixture.type("boolean");
|
||||
}, true, ChangeSignatureDetectorAction.CHANGE_SIGNATURE);
|
||||
}
|
||||
|
||||
@@ -154,12 +148,7 @@ public class ChangeSignatureGestureTest extends LightCodeInsightFixtureTestCase
|
||||
}
|
||||
|
||||
private void doTypingTest(final String param, final String hint) {
|
||||
doTest(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myFixture.type(param);
|
||||
}
|
||||
}, true, hint);
|
||||
doTest(() -> myFixture.type(param), true, hint);
|
||||
}
|
||||
|
||||
public void testReturnValue() {
|
||||
@@ -175,12 +164,7 @@ public class ChangeSignatureGestureTest extends LightCodeInsightFixtureTestCase
|
||||
}
|
||||
|
||||
private void doTypingNoBorderTest(final String param) {
|
||||
doTest(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myFixture.type(param);
|
||||
}
|
||||
}, false, ChangeSignatureDetectorAction.CHANGE_SIGNATURE);
|
||||
doTest(() -> myFixture.type(param), false, ChangeSignatureDetectorAction.CHANGE_SIGNATURE);
|
||||
}
|
||||
|
||||
public void testDeleteParamInSuperUsed() {
|
||||
@@ -188,17 +172,14 @@ public class ChangeSignatureGestureTest extends LightCodeInsightFixtureTestCase
|
||||
}
|
||||
|
||||
private void doDeleteTest() {
|
||||
doTest(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Editor editor = myFixture.getEditor();
|
||||
final Document document = editor.getDocument();
|
||||
final int selectionStart = editor.getSelectionModel().getSelectionStart();
|
||||
final int selectionEnd = editor.getSelectionModel().getSelectionEnd();
|
||||
CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP);
|
||||
document.deleteString(selectionStart, selectionEnd);
|
||||
editor.getCaretModel().moveToOffset(selectionStart);
|
||||
}
|
||||
doTest(() -> {
|
||||
final Editor editor = myFixture.getEditor();
|
||||
final Document document = editor.getDocument();
|
||||
final int selectionStart = editor.getSelectionModel().getSelectionStart();
|
||||
final int selectionEnd = editor.getSelectionModel().getSelectionEnd();
|
||||
CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP);
|
||||
document.deleteString(selectionStart, selectionEnd);
|
||||
editor.getCaretModel().moveToOffset(selectionStart);
|
||||
}, true, ChangeSignatureDetectorAction.CHANGE_SIGNATURE);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -34,7 +34,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase {
|
||||
|
||||
public void testParamTypeSubst() throws Exception {
|
||||
final PsiMethod method = getPrimaryMethod();
|
||||
final HashSet<PsiMethod> methods = new HashSet<PsiMethod>();
|
||||
final HashSet<PsiMethod> methods = new HashSet<>();
|
||||
for (PsiReference reference : ReferencesSearch.search(method)) {
|
||||
final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(reference.getElement(), PsiMethod.class);
|
||||
if (psiMethod != null) {
|
||||
@@ -63,7 +63,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
private static HashSet<PsiMethod> collectNonPhysicalMethodsToPropagate(PsiMethod method) {
|
||||
final HashSet<PsiMethod> methodsToPropagate = new HashSet<PsiMethod>();
|
||||
final HashSet<PsiMethod> methodsToPropagate = new HashSet<>();
|
||||
final PsiReference[] references =
|
||||
MethodReferencesSearch.search(method, GlobalSearchScope.allScope(getProject()), true).toArray(PsiReference.EMPTY_ARRAY);
|
||||
for (PsiReference reference : references) {
|
||||
@@ -91,7 +91,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
private static HashSet<PsiMethod> collectDefaultConstructorsToPropagate(PsiMethod method) {
|
||||
final HashSet<PsiMethod> methodsToPropagate = new HashSet<PsiMethod>();
|
||||
final HashSet<PsiMethod> methodsToPropagate = new HashSet<>();
|
||||
for (PsiClass inheritor : ClassInheritorsSearch.search(method.getContainingClass())) {
|
||||
methodsToPropagate.add(inheritor.getConstructors()[0]);
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase {
|
||||
|
||||
private void parameterPropagationTest(final PsiClassType paramType) throws Exception {
|
||||
final PsiMethod method = getPrimaryMethod();
|
||||
parameterPropagationTest(method, new HashSet<PsiMethod>(Arrays.asList(method.getContainingClass().getMethods())),
|
||||
parameterPropagationTest(method, new HashSet<>(Arrays.asList(method.getContainingClass().getMethods())),
|
||||
paramType);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase {
|
||||
|
||||
private void exceptionPropagationTest() throws Exception {
|
||||
final PsiMethod method = getPrimaryMethod();
|
||||
exceptionPropagationTest(method, new HashSet<PsiMethod>(Arrays.asList(method.getContainingClass().getMethods())));
|
||||
exceptionPropagationTest(method, new HashSet<>(Arrays.asList(method.getContainingClass().getMethods())));
|
||||
}
|
||||
|
||||
private void exceptionPropagationTest(final PsiMethod method, final Set<PsiMethod> methodsToPropagateExceptions) throws Exception {
|
||||
|
||||
@@ -54,38 +54,23 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
}
|
||||
|
||||
public void testGenericTypes() {
|
||||
doTest(null, null, "T", new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "x", myFactory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "y", myFactory.createTypeFromText("C<T>", method.getParameterList()), "null")
|
||||
};
|
||||
}
|
||||
doTest(null, null, "T", method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "x", myFactory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "y", myFactory.createTypeFromText("C<T>", method.getParameterList()), "null")
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testGenericTypesInOldParameters() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "t", myFactory.createTypeFromText("T", method), null)
|
||||
};
|
||||
}
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "t", myFactory.createTypeFromText("T", method), null)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testTypeParametersInMethod() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "t", myFactory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "u", myFactory.createTypeFromText("U", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "cu", myFactory.createTypeFromText("C<U>", method.getParameterList()), "null")
|
||||
};
|
||||
}
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "t", myFactory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "u", myFactory.createTypeFromText("U", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(-1, "cu", myFactory.createTypeFromText("C<U>", method.getParameterList()), "null")
|
||||
}, false);
|
||||
}
|
||||
|
||||
@@ -215,35 +200,20 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
}
|
||||
|
||||
public void testUseAnyVariable() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true)
|
||||
};
|
||||
}
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testUseThisAsAnyVariable() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true)
|
||||
};
|
||||
}
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testUseAnyVariableAndDefault() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "c", myFactory.createTypeFromText("C", method), "null", true)
|
||||
};
|
||||
}
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(-1, "c", myFactory.createTypeFromText("C", method), "null", true)
|
||||
}, false);
|
||||
}
|
||||
|
||||
@@ -282,13 +252,10 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
|
||||
public void testAlreadyHandled() {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.Exception", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
method -> {
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.Exception", method.getResolveScope()))
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
@@ -296,13 +263,10 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
|
||||
public void testConstructorException() {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.io.IOException", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
method -> {
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.io.IOException", method.getResolveScope()))
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
@@ -310,13 +274,10 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
|
||||
public void testAddRuntimeException() {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.RuntimeException", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
method -> {
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.RuntimeException", method.getResolveScope()))
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
@@ -324,13 +285,10 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
|
||||
public void testAddException() {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.Exception", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
method -> {
|
||||
return new ThrownExceptionInfo[]{
|
||||
new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.Exception", method.getResolveScope()))
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
@@ -357,14 +315,9 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
}
|
||||
|
||||
public void testReplaceVarargWithArray() {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "l", myFactory.createTypeFromText("List<T>[]", method.getParameterList()), "null", false),
|
||||
new ParameterInfoImpl(0, "s", myFactory.createTypeFromText("String", method.getParameterList()))
|
||||
};
|
||||
}
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "l", myFactory.createTypeFromText("List<T>[]", method.getParameterList()), "null", false),
|
||||
new ParameterInfoImpl(0, "s", myFactory.createTypeFromText("String", method.getParameterList()))
|
||||
}, false);
|
||||
}
|
||||
|
||||
@@ -405,7 +358,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
final PsiMethod[] callers = containingClass.findMethodsByName("caller", false);
|
||||
assertTrue(callers.length > 0);
|
||||
final PsiMethod caller = callers[0];
|
||||
final HashSet<PsiMethod> propagateParametersMethods = new HashSet<PsiMethod>();
|
||||
final HashSet<PsiMethod> propagateParametersMethods = new HashSet<>();
|
||||
propagateParametersMethods.add(caller);
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
new ChangeSignatureProcessor(getProject(), method, false, null, method.getName(),
|
||||
|
||||
@@ -74,16 +74,10 @@ public class CopyClassTest extends CodeInsightTestCase {
|
||||
private PsiElement performAction(final String oldName, final String copyName) throws IncorrectOperationException {
|
||||
final PsiClass oldClass = JavaPsiFacade.getInstance(myProject).findClass(oldName, ProjectScope.getAllScope(myProject));
|
||||
|
||||
return WriteCommandAction.runWriteCommandAction(null, new Computable<PsiElement>(){
|
||||
@Override
|
||||
public PsiElement compute() {
|
||||
return CopyClassesHandler.doCopyClasses(
|
||||
Collections.singletonMap(oldClass.getNavigationElement().getContainingFile(), new PsiClass[]{oldClass}), copyName,
|
||||
myPsiManager.findDirectory(myRootDir),
|
||||
myProject);
|
||||
|
||||
}
|
||||
});
|
||||
return WriteCommandAction.runWriteCommandAction(null, (Computable<PsiElement>)() -> CopyClassesHandler.doCopyClasses(
|
||||
Collections.singletonMap(oldClass.getNavigationElement().getContainingFile(), new PsiClass[]{oldClass}), copyName,
|
||||
myPsiManager.findDirectory(myRootDir),
|
||||
myProject));
|
||||
}
|
||||
|
||||
public void testPackageLocalClasses() throws Exception {
|
||||
@@ -101,7 +95,7 @@ public class CopyClassTest extends CodeInsightTestCase {
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
|
||||
|
||||
final HashMap<PsiFile, PsiClass[]> map = new HashMap<PsiFile, PsiClass[]>();
|
||||
final HashMap<PsiFile, PsiClass[]> map = new HashMap<>();
|
||||
final VirtualFile sourceDir = rootDir.findChild("p1");
|
||||
for (VirtualFile file : sourceDir.getChildren()) {
|
||||
final PsiFile psiFile = myPsiManager.findFile(file);
|
||||
|
||||
@@ -36,23 +36,11 @@ public class DndMoveTest extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testPublicJavaClass() throws Exception {
|
||||
doTest("d", new Computable<PsiElement>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement compute() {
|
||||
return getJavaFacade().findClass("d.MyClass");
|
||||
}
|
||||
}, true);
|
||||
doTest("d", () -> getJavaFacade().findClass("d.MyClass"), true);
|
||||
}
|
||||
|
||||
public void testSecondJavaClass() throws Exception {
|
||||
doTest("d", new Computable<PsiElement>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement compute() {
|
||||
return getJavaFacade().findClass("d.Second");
|
||||
}
|
||||
}, false);
|
||||
doTest("d", () -> getJavaFacade().findClass("d.Second"), false);
|
||||
}
|
||||
|
||||
private void doTest(final String targetDirName, final Computable<PsiElement> source, final boolean expected) throws Exception {
|
||||
|
||||
@@ -77,15 +77,12 @@ public class EncapsulateFieldsTest extends MultiFileTestCase{
|
||||
}
|
||||
|
||||
public void testMoveJavadocToGetter() throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
final PsiClass aClass = myJavaFacade.findClass("A", GlobalSearchScope.projectScope(myProject));
|
||||
assertNotNull("Tested class not found", aClass);
|
||||
final PsiField field = aClass.findFieldByName("i", false);
|
||||
assertNotNull(field);
|
||||
doTest(aClass, field, null, true, true);
|
||||
}
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass aClass = myJavaFacade.findClass("A", GlobalSearchScope.projectScope(myProject));
|
||||
assertNotNull("Tested class not found", aClass);
|
||||
final PsiField field = aClass.findFieldByName("i", false);
|
||||
assertNotNull(field);
|
||||
doTest(aClass, field, null, true, true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,16 +103,13 @@ public class EncapsulateFieldsTest extends MultiFileTestCase{
|
||||
}
|
||||
|
||||
private void doTest(final String fieldName, final String className, final String conflicts) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.projectScope(myProject));
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.projectScope(myProject));
|
||||
|
||||
assertNotNull("Tested class not found", aClass);
|
||||
assertNotNull("Tested class not found", aClass);
|
||||
|
||||
|
||||
doTest(aClass, aClass.findFieldByName(fieldName, false), conflicts, true, true);
|
||||
}
|
||||
doTest(aClass, aClass.findFieldByName(fieldName, false), conflicts, true, true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -67,18 +67,15 @@ public class ExtractClassTest extends MultiFileTestCase{
|
||||
private void doTestMethod(final String methodName,
|
||||
final String conflicts,
|
||||
final String qualifiedName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass(qualifiedName, GlobalSearchScope.projectScope(myProject));
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass(qualifiedName, GlobalSearchScope.projectScope(myProject));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<PsiMethod>();
|
||||
methods.add(aClass.findMethodsByName(methodName, false)[0]);
|
||||
|
||||
doTest(aClass, methods, new ArrayList<PsiField>(), conflicts, false);
|
||||
}
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<>();
|
||||
methods.add(aClass.findMethodsByName(methodName, false)[0]);
|
||||
|
||||
doTest(aClass, methods, new ArrayList<>(), conflicts, false);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -151,21 +148,18 @@ public class ExtractClassTest extends MultiFileTestCase{
|
||||
}
|
||||
|
||||
private void doTestFieldAndMethod(final String methodName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<PsiMethod>();
|
||||
methods.add(aClass.findMethodsByName(methodName, false)[0]);
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<>();
|
||||
methods.add(aClass.findMethodsByName(methodName, false)[0]);
|
||||
|
||||
final ArrayList<PsiField> fields = new ArrayList<PsiField>();
|
||||
fields.add(aClass.findFieldByName("myT", false));
|
||||
final ArrayList<PsiField> fields = new ArrayList<>();
|
||||
fields.add(aClass.findFieldByName("myT", false));
|
||||
|
||||
doTest(aClass, methods, fields, null, false);
|
||||
}
|
||||
doTest(aClass, methods, fields, null, false);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -174,27 +168,24 @@ public class ExtractClassTest extends MultiFileTestCase{
|
||||
}
|
||||
|
||||
private void doTestField(final String conflicts, final boolean generateGettersSetters) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<PsiMethod>();
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<>();
|
||||
|
||||
final ArrayList<PsiField> fields = new ArrayList<PsiField>();
|
||||
fields.add(aClass.findFieldByName("myT", false));
|
||||
final ArrayList<PsiField> fields = new ArrayList<>();
|
||||
fields.add(aClass.findFieldByName("myT", false));
|
||||
|
||||
doTest(aClass, methods, fields, conflicts, generateGettersSetters);
|
||||
}
|
||||
doTest(aClass, methods, fields, conflicts, generateGettersSetters);
|
||||
});
|
||||
}
|
||||
|
||||
private static void doTest(final PsiClass aClass, final ArrayList<PsiMethod> methods, final ArrayList<PsiField> fields, final String conflicts,
|
||||
boolean generateGettersSetters) {
|
||||
try {
|
||||
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, methods, new ArrayList<PsiClass>(), StringUtil.getPackageName(aClass.getQualifiedName()), null,
|
||||
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, methods, new ArrayList<>(), StringUtil.getPackageName(aClass.getQualifiedName()), null,
|
||||
"Extracted", null, generateGettersSetters, Collections.<MemberInfo>emptyList());
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
@@ -233,39 +224,33 @@ public class ExtractClassTest extends MultiFileTestCase{
|
||||
}
|
||||
|
||||
public void testPublicFieldDelegation() throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final ArrayList<PsiField> fields = new ArrayList<PsiField>();
|
||||
fields.add(aClass.findFieldByName("myT", false));
|
||||
final ArrayList<PsiField> fields = new ArrayList<>();
|
||||
fields.add(aClass.findFieldByName("myT", false));
|
||||
|
||||
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, new ArrayList<PsiMethod>(), new ArrayList<PsiClass>(), "", "Extracted");
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, new ArrayList<>(), new ArrayList<>(), "", "Extracted");
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
private void doTestInnerClass() throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final ArrayList<PsiClass> classes = new ArrayList<PsiClass>();
|
||||
classes.add(aClass.findInnerClassByName("Inner", false));
|
||||
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, new ArrayList<PsiField>(), new ArrayList<PsiMethod>(), classes, "", "Extracted");
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
final ArrayList<PsiClass> classes = new ArrayList<>();
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -302,25 +287,22 @@ public class ExtractClassTest extends MultiFileTestCase{
|
||||
}
|
||||
|
||||
public void testPublicVisibility() throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<PsiMethod>();
|
||||
methods.add(aClass.findMethodsByName("foos", false)[0]);
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<>();
|
||||
methods.add(aClass.findMethodsByName("foos", false)[0]);
|
||||
|
||||
final ArrayList<PsiField> fields = new ArrayList<PsiField>();
|
||||
fields.add(aClass.findFieldByName("myT", false));
|
||||
final ArrayList<PsiField> fields = new ArrayList<>();
|
||||
fields.add(aClass.findFieldByName("myT", false));
|
||||
|
||||
final ExtractClassProcessor processor =
|
||||
new ExtractClassProcessor(aClass, fields, methods, new ArrayList<PsiClass>(), "", null, "Extracted", PsiModifier.PUBLIC, false, Collections.<MemberInfo>emptyList());
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
final ExtractClassProcessor processor =
|
||||
new ExtractClassProcessor(aClass, fields, methods, new ArrayList<>(), "", null, "Extracted", PsiModifier.PUBLIC, false, Collections.<MemberInfo>emptyList());
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -144,53 +144,50 @@ public class ExtractEnumTest extends MultiFileTestCase {
|
||||
private void doTest(final String conflicts,
|
||||
final boolean generateAccessors,
|
||||
final RefactoringTestUtil.MemberDescriptor... memberDescriptors) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
final PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final ArrayList<PsiField> fields = new ArrayList<PsiField>();
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<PsiMethod>();
|
||||
final List<MemberInfo> enumConstants = new ArrayList<MemberInfo>();
|
||||
for (MemberInfo memberInfo : RefactoringTestUtil.findMembers(aClass, memberDescriptors)) {
|
||||
final PsiMember member = memberInfo.getMember();
|
||||
if (member instanceof PsiField) {
|
||||
fields.add((PsiField)member);
|
||||
if (member.hasModifierProperty(PsiModifier.STATIC) && member.hasModifierProperty(PsiModifier.FINAL) && ((PsiField)member).hasInitializer()) {
|
||||
if (memberInfo.isToAbstract()) {
|
||||
enumConstants.add(memberInfo);
|
||||
memberInfo.setChecked(true);
|
||||
}
|
||||
final ArrayList<PsiField> fields = new ArrayList<>();
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<>();
|
||||
final List<MemberInfo> enumConstants = new ArrayList<>();
|
||||
for (MemberInfo memberInfo : RefactoringTestUtil.findMembers(aClass, memberDescriptors)) {
|
||||
final PsiMember member = memberInfo.getMember();
|
||||
if (member instanceof PsiField) {
|
||||
fields.add((PsiField)member);
|
||||
if (member.hasModifierProperty(PsiModifier.STATIC) && member.hasModifierProperty(PsiModifier.FINAL) && ((PsiField)member).hasInitializer()) {
|
||||
if (memberInfo.isToAbstract()) {
|
||||
enumConstants.add(memberInfo);
|
||||
memberInfo.setChecked(true);
|
||||
}
|
||||
}
|
||||
else if (member instanceof PsiMethod) {
|
||||
methods.add((PsiMethod)member);
|
||||
}
|
||||
}
|
||||
try {
|
||||
final ExtractClassProcessor processor =
|
||||
new ExtractClassProcessor(aClass, fields, methods, new ArrayList<PsiClass>(), "", null, "EEnum",
|
||||
null, generateAccessors, enumConstants);
|
||||
else if (member instanceof PsiMethod) {
|
||||
methods.add((PsiMethod)member);
|
||||
}
|
||||
}
|
||||
try {
|
||||
final ExtractClassProcessor processor =
|
||||
new ExtractClassProcessor(aClass, fields, methods, new ArrayList<>(), "", null, "EEnum",
|
||||
null, generateAccessors, enumConstants);
|
||||
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
if (conflicts != null) {
|
||||
TreeSet expectedConflictsSet = new TreeSet(Arrays.asList(conflicts.split("\n")));
|
||||
TreeSet actualConflictsSet = new TreeSet(Arrays.asList(e.getMessage().split("\n")));
|
||||
Assert.assertEquals(expectedConflictsSet, actualConflictsSet);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
if (conflicts != null) {
|
||||
fail("Conflicts were not detected: " + conflicts);
|
||||
TreeSet expectedConflictsSet = new TreeSet(Arrays.asList(conflicts.split("\n")));
|
||||
TreeSet actualConflictsSet = new TreeSet(Arrays.asList(e.getMessage().split("\n")));
|
||||
Assert.assertEquals(expectedConflictsSet, actualConflictsSet);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
if (conflicts != null) {
|
||||
fail("Conflicts were not detected: " + conflicts);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,10 +41,8 @@ public class ExtractMethodObjectTest extends LightRefactoringTestCase {
|
||||
extractProcessor.prepare();
|
||||
extractProcessor.testPrepare();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ExtractMethodObjectHandler.run(getProject(), getEditor(), processor, extractProcessor);
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
ExtractMethodObjectHandler.run(getProject(), getEditor(), processor, extractProcessor);
|
||||
});
|
||||
|
||||
|
||||
|
||||
+2
-4
@@ -48,10 +48,8 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightRefactor
|
||||
processor.setCreateInnerClass(createInnerClass);
|
||||
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ExtractMethodObjectHandler.run(getProject(), getEditor(), processor, extractProcessor);
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
ExtractMethodObjectHandler.run(getProject(), getEditor(), processor, extractProcessor);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ public class ExtractSuperClassTest extends RefactoringTestCase {
|
||||
newClassName,
|
||||
psiClass, members,
|
||||
false,
|
||||
new DocCommentPolicy<PsiComment>(DocCommentPolicy.ASIS));
|
||||
new DocCommentPolicy<>(DocCommentPolicy.ASIS));
|
||||
final PsiPackage targetPackage;
|
||||
if (targetDirectory != null) {
|
||||
targetPackage = JavaDirectoryService.getInstance().getPackage(targetDirectory);
|
||||
@@ -184,18 +184,14 @@ public class ExtractSuperClassTest extends RefactoringTestCase {
|
||||
}
|
||||
final PsiClass superClass = psiClass.getExtendsListTypes().length > 0 ? psiClass.getSuperClass() : null;
|
||||
final MultiMap<PsiElement, String> conflictsMap =
|
||||
PullUpConflictsUtil.checkConflicts(members, psiClass, superClass, targetPackage, targetDirectory, new InterfaceContainmentVerifier() {
|
||||
@Override
|
||||
public boolean checkedInterfacesContain(PsiMethod psiMethod) {
|
||||
return PullUpProcessor.checkedInterfacesContain(Arrays.asList(members), psiMethod);
|
||||
}
|
||||
}, false);
|
||||
PullUpConflictsUtil.checkConflicts(members, psiClass, superClass, targetPackage, targetDirectory,
|
||||
psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(members), psiMethod), false);
|
||||
if (conflicts != null) {
|
||||
if (conflictsMap.isEmpty()) {
|
||||
fail("Conflicts were not detected");
|
||||
}
|
||||
final HashSet<String> expectedConflicts = new HashSet<String>(Arrays.asList(conflicts));
|
||||
final HashSet<String> actualConflicts = new HashSet<String>(conflictsMap.values());
|
||||
final HashSet<String> expectedConflicts = new HashSet<>(Arrays.asList(conflicts));
|
||||
final HashSet<String> actualConflicts = new HashSet<>(conflictsMap.values());
|
||||
assertEquals(expectedConflicts.size(), actualConflicts.size());
|
||||
for (String actualConflict : actualConflicts) {
|
||||
if (!expectedConflicts.contains(actualConflict)) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class FixMethodJavadocTest extends FileSetTestCase {
|
||||
final PsiManager manager = PsiManager.getInstance(myProject);
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
final PsiMethod method = factory.createMethodFromText(data[0], null);
|
||||
final HashSet<PsiParameter> newParameters = new HashSet<PsiParameter>();
|
||||
final HashSet<PsiParameter> newParameters = new HashSet<>();
|
||||
if (data.length == 2) {
|
||||
final String[] strings = data[1].split("\\s+");
|
||||
collectNewParameters(method, strings, newParameters);
|
||||
@@ -42,7 +42,7 @@ public abstract class FixMethodJavadocTest extends FileSetTestCase {
|
||||
}
|
||||
|
||||
private void collectNewParameters(PsiMethod method, String[] names, Set<PsiParameter> newParameters) {
|
||||
Set<String> newNames = new HashSet<String>(Arrays.asList(names));
|
||||
Set<String> newNames = new HashSet<>(Arrays.asList(names));
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
|
||||
@@ -139,30 +139,27 @@ public class InheritanceToDelegationTest extends MultiFileTestCase {
|
||||
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 new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class " + className + " not found", aClass);
|
||||
PsiClass baseClass = myJavaFacade.findClass(baseClassName, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Base class " + baseClassName + " not found", baseClass);
|
||||
final PsiMethod[] methods = baseClass.getMethods();
|
||||
final PsiMethod[] delegatedMethods = new PsiMethod[methodIndices.length];
|
||||
for (int i = 0; i < methodIndices.length; i++) {
|
||||
delegatedMethods[i] = methods[methodIndices[i]];
|
||||
}
|
||||
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()));
|
||||
assertNotNull(anInterface);
|
||||
delegatedInterfaces[i] = anInterface;
|
||||
}
|
||||
new InheritanceToDelegationProcessor(
|
||||
myProject,
|
||||
aClass, baseClass, fieldName, innerClassName, delegatedInterfaces, delegatedMethods, delegateOtherMembers,
|
||||
generateGetter).run();
|
||||
return (rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class " + className + " not found", aClass);
|
||||
PsiClass baseClass = myJavaFacade.findClass(baseClassName, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Base class " + baseClassName + " not found", baseClass);
|
||||
final PsiMethod[] methods = baseClass.getMethods();
|
||||
final PsiMethod[] delegatedMethods = new PsiMethod[methodIndices.length];
|
||||
for (int i = 0; i < methodIndices.length; i++) {
|
||||
delegatedMethods[i] = methods[methodIndices[i]];
|
||||
}
|
||||
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()));
|
||||
assertNotNull(anInterface);
|
||||
delegatedInterfaces[i] = anInterface;
|
||||
}
|
||||
new InheritanceToDelegationProcessor(
|
||||
myProject,
|
||||
aClass, baseClass, fieldName, innerClassName, delegatedInterfaces, delegatedMethods, delegateOtherMembers,
|
||||
generateGetter).run();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -170,34 +167,31 @@ public class InheritanceToDelegationTest extends MultiFileTestCase {
|
||||
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 new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class " + className + " not found", aClass);
|
||||
PsiClass baseClass = myJavaFacade.findClass(baseClassName, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Base class " + baseClassName + " not found", baseClass);
|
||||
final PsiMethod[] delegatedMethods;
|
||||
final List<PsiMethod> methodsList = new ArrayList<PsiMethod>();
|
||||
for (String name : methodNames) {
|
||||
final PsiMethod[] methodsByName = baseClass.findMethodsByName(name, false);
|
||||
ContainerUtil.addAll(methodsList, methodsByName);
|
||||
}
|
||||
delegatedMethods = methodsList.toArray(new PsiMethod[methodsList.size()]);
|
||||
|
||||
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()));
|
||||
assertNotNull(anInterface);
|
||||
delegatedInterfaces[i] = anInterface;
|
||||
}
|
||||
new InheritanceToDelegationProcessor(
|
||||
myProject,
|
||||
aClass, baseClass, fieldName, innerClassName, delegatedInterfaces, delegatedMethods, delegateOtherMembers,
|
||||
generateGetter).run();
|
||||
//FileDocumentManager.getInstance().saveAllDocuments();
|
||||
return (rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class " + className + " not found", aClass);
|
||||
PsiClass baseClass = myJavaFacade.findClass(baseClassName, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Base class " + baseClassName + " not found", baseClass);
|
||||
final PsiMethod[] delegatedMethods;
|
||||
final List<PsiMethod> methodsList = new ArrayList<>();
|
||||
for (String name : methodNames) {
|
||||
final PsiMethod[] methodsByName = baseClass.findMethodsByName(name, false);
|
||||
ContainerUtil.addAll(methodsList, methodsByName);
|
||||
}
|
||||
delegatedMethods = methodsList.toArray(new PsiMethod[methodsList.size()]);
|
||||
|
||||
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()));
|
||||
assertNotNull(anInterface);
|
||||
delegatedInterfaces[i] = anInterface;
|
||||
}
|
||||
new InheritanceToDelegationProcessor(
|
||||
myProject,
|
||||
aClass, baseClass, fieldName, innerClassName, delegatedInterfaces, delegatedMethods, delegateOtherMembers,
|
||||
generateGetter).run();
|
||||
//FileDocumentManager.getInstance().saveAllDocuments();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -77,18 +77,15 @@ public class InlineSuperClassTest extends MultiFileTestCase {
|
||||
|
||||
private void doTest(boolean fail, final boolean inlineOne) {
|
||||
try {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", scope);
|
||||
if (aClass == null) aClass = myJavaFacade.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);
|
||||
assertNotNull("Class Super not found", superClass);
|
||||
new InlineSuperClassRefactoringProcessor(myProject, inlineOne ? aClass : null, superClass, DocCommentPolicy.ASIS, aClass).run();
|
||||
}
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", scope);
|
||||
if (aClass == null) aClass = myJavaFacade.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);
|
||||
assertNotNull("Class Super not found", superClass);
|
||||
new InlineSuperClassRefactoringProcessor(myProject, inlineOne ? aClass : null, superClass, DocCommentPolicy.ASIS, aClass).run();
|
||||
});
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
@@ -105,17 +102,14 @@ public class InlineSuperClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTestMultipleSubclasses() {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
|
||||
PsiClass superClass = myJavaFacade.findClass("Super", scope);
|
||||
if (superClass == null) superClass = myJavaFacade.findClass("p1.Super", scope);
|
||||
assertNotNull("Class Super not found", superClass);
|
||||
PsiClass target1 = myJavaFacade.findClass("Test", scope);
|
||||
PsiClass target2 = myJavaFacade.findClass("Test1", scope);
|
||||
new InlineSuperClassRefactoringProcessor(myProject, null, superClass, DocCommentPolicy.ASIS, target1, target2).run();
|
||||
}
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
|
||||
PsiClass superClass = myJavaFacade.findClass("Super", scope);
|
||||
if (superClass == null) superClass = myJavaFacade.findClass("p1.Super", scope);
|
||||
assertNotNull("Class Super not found", superClass);
|
||||
PsiClass target1 = myJavaFacade.findClass("Test", scope);
|
||||
PsiClass target2 = myJavaFacade.findClass("Test1", scope);
|
||||
new InlineSuperClassRefactoringProcessor(myProject, null, superClass, DocCommentPolicy.ASIS, target1, target2).run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+48
-69
@@ -23,7 +23,6 @@ package com.intellij.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.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.introduceparameterobject.IntroduceParameterObjectProcessor;
|
||||
@@ -48,31 +47,23 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase{
|
||||
}
|
||||
|
||||
private void doTest(final boolean delegate, final boolean createInner) throws Exception {
|
||||
doTest(delegate, createInner, new Function<PsiMethod, VariableData[]>() {
|
||||
@Override
|
||||
public VariableData[] fun(PsiMethod psiMethod) {
|
||||
return generateParams(psiMethod);
|
||||
}
|
||||
});
|
||||
doTest(delegate, createInner, IntroduceParameterObjectTest::generateParams);
|
||||
}
|
||||
|
||||
private void doTest(final boolean delegate,
|
||||
final boolean createInner,
|
||||
final Function<PsiMethod, VariableData[]> function) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final PsiMethod method = aClass.findMethodsByName("foo", false)[0];
|
||||
final VariableData[] datas = function.fun(method);
|
||||
final PsiMethod method = aClass.findMethodsByName("foo", false)[0];
|
||||
final VariableData[] datas = function.fun(method);
|
||||
|
||||
IntroduceParameterObjectProcessor processor = new IntroduceParameterObjectProcessor("Param", "", null, method, datas, delegate, false,
|
||||
createInner, null, false);
|
||||
processor.run();
|
||||
}
|
||||
IntroduceParameterObjectProcessor processor = new IntroduceParameterObjectProcessor("Param", "", null, method, datas, delegate, false,
|
||||
createInner, null, false);
|
||||
processor.run();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -134,53 +125,44 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase{
|
||||
}
|
||||
|
||||
public void testSameTypeAndVarargs() throws Exception {
|
||||
doTest(false, false, new Function<PsiMethod, VariableData[]>() {
|
||||
@Override
|
||||
public VariableData[] fun(PsiMethod method) {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
doTest(false, false, method -> {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
|
||||
final VariableData[] datas = new VariableData[parameters.length - 1];
|
||||
for (int i = 0; i < parameters.length - 1; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
datas[i] = new VariableData(parameter);
|
||||
datas[i].name = parameter.getName();
|
||||
datas[i].passAsParameter = true;
|
||||
}
|
||||
return datas;
|
||||
final VariableData[] datas = new VariableData[parameters.length - 1];
|
||||
for (int i = 0; i < parameters.length - 1; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
datas[i] = new VariableData(parameter);
|
||||
datas[i].name = parameter.getName();
|
||||
datas[i].passAsParameter = true;
|
||||
}
|
||||
return datas;
|
||||
});
|
||||
}
|
||||
|
||||
public void testCopyJavadoc1() throws Exception {
|
||||
doTest(false, true, new Function<PsiMethod, VariableData[]>() {
|
||||
@Override
|
||||
public VariableData[] fun(PsiMethod method) {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
doTest(false, true, method -> {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
|
||||
final VariableData[] datas = new VariableData[parameters.length - 1];
|
||||
for (int i = 0; i < parameters.length - 1; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
datas[i] = new VariableData(parameter);
|
||||
datas[i].name = parameter.getName();
|
||||
datas[i].passAsParameter = true;
|
||||
}
|
||||
return datas;
|
||||
final VariableData[] datas = new VariableData[parameters.length - 1];
|
||||
for (int i = 0; i < parameters.length - 1; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
datas[i] = new VariableData(parameter);
|
||||
datas[i].name = parameter.getName();
|
||||
datas[i].passAsParameter = true;
|
||||
}
|
||||
return datas;
|
||||
});
|
||||
}
|
||||
|
||||
public void testTypeParametersWithChosenSubtype() throws Exception {
|
||||
doTest(false, true, new Function<PsiMethod, VariableData[]>() {
|
||||
@Override
|
||||
public VariableData[] fun(PsiMethod psiMethod) {
|
||||
final PsiParameter parameter = psiMethod.getParameterList().getParameters()[0];
|
||||
final PsiClass collectionClass = getJavaFacade().findClass(CommonClassNames.JAVA_UTIL_COLLECTION);
|
||||
final VariableData variableData =
|
||||
new VariableData(parameter, JavaPsiFacade.getElementFactory(getProject()).createType(collectionClass));
|
||||
variableData.name = parameter.getName();
|
||||
variableData.passAsParameter = true;
|
||||
return new VariableData[]{variableData};
|
||||
}
|
||||
doTest(false, true, psiMethod -> {
|
||||
final PsiParameter parameter = psiMethod.getParameterList().getParameters()[0];
|
||||
final PsiClass collectionClass = getJavaFacade().findClass(CommonClassNames.JAVA_UTIL_COLLECTION);
|
||||
final VariableData variableData =
|
||||
new VariableData(parameter, JavaPsiFacade.getElementFactory(getProject()).createType(collectionClass));
|
||||
variableData.name = parameter.getName();
|
||||
variableData.passAsParameter = true;
|
||||
return new VariableData[]{variableData};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -198,23 +180,20 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase{
|
||||
|
||||
private void doTestExistingClass(final String existingClassName, final String existingClassPackage, final boolean generateAccessors,
|
||||
final String newVisibility) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
if (aClass == null) {
|
||||
aClass = myJavaFacade.findClass("p2.Test", GlobalSearchScope.projectScope(getProject()));
|
||||
}
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final PsiMethod method = aClass.findMethodsByName("foo", false)[0];
|
||||
IntroduceParameterObjectProcessor processor = new IntroduceParameterObjectProcessor(existingClassName, existingClassPackage, null, method,
|
||||
generateParams(method), false, true,
|
||||
false, newVisibility, generateAccessors);
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
if (aClass == null) {
|
||||
aClass = myJavaFacade.findClass("p2.Test", GlobalSearchScope.projectScope(getProject()));
|
||||
}
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final PsiMethod method = aClass.findMethodsByName("foo", false)[0];
|
||||
IntroduceParameterObjectProcessor processor = new IntroduceParameterObjectProcessor(existingClassName, existingClassPackage, null, method,
|
||||
generateParams(method), false, true,
|
||||
false, newVisibility, generateAccessors);
|
||||
processor.run();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+11
-14
@@ -94,20 +94,17 @@ public class IntroduceVariableMultifileTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
PerformAction createAction(final String className, final IntroduceVariableBase testMe) {
|
||||
return new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile vroot, VirtualFile rootAfter) {
|
||||
final JavaPsiFacade psiManager = getJavaFacade();
|
||||
final PsiClass aClass = psiManager.findClass(className, GlobalSearchScope.allScope(myProject));
|
||||
assertTrue(className + " class not found", aClass != null);
|
||||
final PsiFile containingFile = aClass.getContainingFile();
|
||||
final VirtualFile virtualFile = containingFile.getVirtualFile();
|
||||
assertTrue(virtualFile != null);
|
||||
final Editor editor = createEditor(virtualFile);
|
||||
setupCursorAndSelection(editor);
|
||||
testMe.invoke(myProject, editor, containingFile, null);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
return (vroot, rootAfter) -> {
|
||||
final JavaPsiFacade psiManager = getJavaFacade();
|
||||
final PsiClass aClass = psiManager.findClass(className, GlobalSearchScope.allScope(myProject));
|
||||
assertTrue(className + " class not found", aClass != null);
|
||||
final PsiFile containingFile = aClass.getContainingFile();
|
||||
final VirtualFile virtualFile = containingFile.getVirtualFile();
|
||||
assertTrue(virtualFile != null);
|
||||
final Editor editor = createEditor(virtualFile);
|
||||
setupCursorAndSelection(editor);
|
||||
testMe.invoke(myProject, editor, containingFile, null);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+29
-42
@@ -51,57 +51,44 @@ public abstract class LightRefactoringParameterizedTestCase extends LightRefacto
|
||||
public void runSingle() throws Throwable {
|
||||
final Throwable[] throwables = new Throwable[1];
|
||||
|
||||
final Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Runnable runnable = () -> {
|
||||
try {
|
||||
final String filePath = getBeforeFile(myFileSuffix);
|
||||
configureByFile(filePath);
|
||||
|
||||
final File testDir = new File(getTestDataPath(), filePath).getParentFile();
|
||||
final String afterName = getAfterFile(myFileSuffix);
|
||||
final boolean conflictShouldBeFound = !new File(testDir, afterName).exists();
|
||||
try {
|
||||
final String filePath = getBeforeFile(myFileSuffix);
|
||||
configureByFile(filePath);
|
||||
|
||||
final File testDir = new File(getTestDataPath(), filePath).getParentFile();
|
||||
final String afterName = getAfterFile(myFileSuffix);
|
||||
final boolean conflictShouldBeFound = !new File(testDir, afterName).exists();
|
||||
try {
|
||||
perform();
|
||||
if (conflictShouldBeFound) {
|
||||
fail("Conflict expected.");
|
||||
}
|
||||
perform();
|
||||
if (conflictShouldBeFound) {
|
||||
fail("Conflict expected.");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException exception) {
|
||||
if (!conflictShouldBeFound) {
|
||||
fail("Conflict not expected");
|
||||
} else {
|
||||
final File conflicts = new File(testDir, FileUtilRt.getNameWithoutExtension(myFileSuffix) + CONFLICTS_SUFFIX);
|
||||
if (!conflicts.exists()) {
|
||||
fail("Conflict file " + conflicts.getPath() + " not found");
|
||||
}
|
||||
final VirtualFile conflictsFile = VfsUtil.findFileByIoFile(conflicts, false);
|
||||
assertNotNull(conflictsFile);
|
||||
assertEquals(LoadTextUtil.loadText(conflictsFile).toString(), exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException exception) {
|
||||
if (!conflictShouldBeFound) {
|
||||
checkResultByFile(getAfterFile(myFileSuffix));
|
||||
fail("Conflict not expected");
|
||||
} else {
|
||||
final File conflicts = new File(testDir, FileUtilRt.getNameWithoutExtension(myFileSuffix) + CONFLICTS_SUFFIX);
|
||||
if (!conflicts.exists()) {
|
||||
fail("Conflict file " + conflicts.getPath() + " not found");
|
||||
}
|
||||
final VirtualFile conflictsFile = VfsUtil.findFileByIoFile(conflicts, false);
|
||||
assertNotNull(conflictsFile);
|
||||
assertEquals(LoadTextUtil.loadText(conflictsFile).toString(), exception.getMessage());
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
throwables[0] = e;
|
||||
|
||||
if (!conflictShouldBeFound) {
|
||||
checkResultByFile(getAfterFile(myFileSuffix));
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
throwables[0] = e;
|
||||
}
|
||||
};
|
||||
|
||||
invokeTestRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.run();
|
||||
}
|
||||
}, "", null);
|
||||
}
|
||||
});
|
||||
invokeTestRunnable(() -> CommandProcessor.getInstance().executeCommand(getProject(), runnable::run, "", null));
|
||||
|
||||
if (throwables[0] != null) {
|
||||
throw throwables[0];
|
||||
|
||||
@@ -83,7 +83,7 @@ public class MakeClassStaticTest extends LightRefactoringTestCase {
|
||||
PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
|
||||
assertTrue(element instanceof PsiClass);
|
||||
PsiClass aClass = (PsiClass)element;
|
||||
final ArrayList<VariableData> parametersForFields = new ArrayList<VariableData>();
|
||||
final ArrayList<VariableData> parametersForFields = new ArrayList<>();
|
||||
final boolean addClassParameter = MakeStaticUtil.buildVariableData(aClass, parametersForFields);
|
||||
|
||||
new MakeClassStaticProcessor(
|
||||
|
||||
@@ -248,7 +248,7 @@ public class MakeMethodStaticTest extends LightRefactoringTestCase {
|
||||
PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
|
||||
assertTrue(element instanceof PsiMethod);
|
||||
PsiMethod method = (PsiMethod) element;
|
||||
final ArrayList<VariableData> parametersForFields = new ArrayList<VariableData>();
|
||||
final ArrayList<VariableData> parametersForFields = new ArrayList<>();
|
||||
final boolean addClassParameter = MakeStaticUtil.buildVariableData(method, parametersForFields);
|
||||
|
||||
new MakeMethodStaticProcessor(
|
||||
|
||||
@@ -222,11 +222,8 @@ public class MoveMembersTest extends MultiFileTestCase {
|
||||
final String defaultVisibility,
|
||||
final int... memberIndices)
|
||||
throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
MoveMembersTest.this.performAction(sourceClassName, targetClassName, memberIndices, defaultVisibility);
|
||||
}
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
MoveMembersTest.this.performAction(sourceClassName, targetClassName, memberIndices, defaultVisibility);
|
||||
}, lowercaseFirstLetter);
|
||||
}
|
||||
|
||||
@@ -237,14 +234,14 @@ public class MoveMembersTest extends MultiFileTestCase {
|
||||
assertNotNull("Class " + targetClassName + " not found", targetClass);
|
||||
|
||||
PsiElement[] children = sourceClass.getChildren();
|
||||
ArrayList<PsiMember> members = new ArrayList<PsiMember>();
|
||||
ArrayList<PsiMember> members = new ArrayList<>();
|
||||
for (PsiElement child : children) {
|
||||
if (child instanceof PsiMember) {
|
||||
members.add(((PsiMember) child));
|
||||
}
|
||||
}
|
||||
|
||||
LinkedHashSet<PsiMember> memberSet = new LinkedHashSet<PsiMember>();
|
||||
LinkedHashSet<PsiMember> memberSet = new LinkedHashSet<>();
|
||||
for (int index : memberIndices) {
|
||||
PsiMember member = members.get(index);
|
||||
assertTrue(member.hasModifierProperty(PsiModifier.STATIC));
|
||||
|
||||
@@ -52,16 +52,13 @@ public class MovePackageAsDirectoryTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void testRenamePackage() throws Exception {
|
||||
final PerformAction action = new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
|
||||
final PsiPackage sourcePackage = psiFacade.findPackage("pack1");
|
||||
assertNotNull(sourcePackage);
|
||||
|
||||
RenamePsiPackageProcessor.createRenameMoveProcessor("pack1.pack2", sourcePackage, false, false).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
final PerformAction action = (rootDir, rootAfter) -> {
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
|
||||
final PsiPackage sourcePackage = psiFacade.findPackage("pack1");
|
||||
assertNotNull(sourcePackage);
|
||||
|
||||
RenamePsiPackageProcessor.createRenameMoveProcessor("pack1.pack2", sourcePackage, false, false).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
};
|
||||
doTest(action);
|
||||
}
|
||||
@@ -105,21 +102,15 @@ public class MovePackageAsDirectoryTest extends MultiFileTestCase {
|
||||
protected void preprocessSrcDir(PsiDirectory srcDirectory) {
|
||||
final PsiFile empty = srcDirectory.findFile(EMPTY_TXT);
|
||||
assert empty != null;
|
||||
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
|
||||
public void run() {
|
||||
empty.delete();
|
||||
}
|
||||
});
|
||||
WriteCommandAction.runWriteCommandAction(null, empty::delete);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessTargetDir(PsiDirectory targetDirectory) {
|
||||
final PsiDirectory subdirectory = targetDirectory.findSubdirectory(packageName);
|
||||
assert subdirectory != null;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
subdirectory.createFile(EMPTY_TXT);
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
subdirectory.createFile(EMPTY_TXT);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -133,11 +124,7 @@ public class MovePackageAsDirectoryTest extends MultiFileTestCase {
|
||||
protected void preprocessSrcDir(PsiDirectory srcDirectory) {
|
||||
final PsiClass empty = JavaPsiFacade.getInstance(getProject()).findClass(FOO, GlobalSearchScope.projectScope(getProject()));
|
||||
assert empty != null;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
empty.delete();
|
||||
}
|
||||
});
|
||||
ApplicationManager.getApplication().runWriteAction(empty::delete);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,10 +133,8 @@ public class MovePackageAsDirectoryTest extends MultiFileTestCase {
|
||||
assert subdirectory != null;
|
||||
final PsiDirectory emptyDir = subdirectory.findSubdirectory("subPack");
|
||||
assert emptyDir != null;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
emptyDir.createFile(EMPTY_TXT);
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
emptyDir.createFile(EMPTY_TXT);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -182,12 +167,8 @@ public class MovePackageAsDirectoryTest extends MultiFileTestCase {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
|
||||
final Comparator<PsiDirectory> directoryComparator = new Comparator<PsiDirectory>() {
|
||||
@Override
|
||||
public int compare(PsiDirectory o1, PsiDirectory o2) {
|
||||
return o1.getVirtualFile().getPresentableUrl().compareTo(o2.getVirtualFile().getPresentableUrl());
|
||||
}
|
||||
};
|
||||
final Comparator<PsiDirectory> directoryComparator =
|
||||
(o1, o2) -> o1.getVirtualFile().getPresentableUrl().compareTo(o2.getVirtualFile().getPresentableUrl());
|
||||
|
||||
final PsiPackage sourcePackage = psiFacade.findPackage(myPackageName);
|
||||
assertNotNull(sourcePackage);
|
||||
|
||||
@@ -51,23 +51,20 @@ public class MovePackageMultirootTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private PerformAction createAction(final String[] packageNames, final String targetPackageName) {
|
||||
return new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
final PsiManager manager = PsiManager.getInstance(myProject);
|
||||
PsiPackage[] sourcePackages = new PsiPackage[packageNames.length];
|
||||
for (int i = 0; i < packageNames.length; i++) {
|
||||
String packageName = packageNames[i];
|
||||
sourcePackages[i] = JavaPsiFacade.getInstance(manager.getProject()).findPackage(packageName);
|
||||
assertNotNull(sourcePackages[i]);
|
||||
}
|
||||
PsiPackage targetPackage = JavaPsiFacade.getInstance(manager.getProject()).findPackage(targetPackageName);
|
||||
assertNotNull(targetPackage);
|
||||
new MoveClassesOrPackagesProcessor(myProject, sourcePackages,
|
||||
new MultipleRootsMoveDestination(new PackageWrapper(targetPackage)),
|
||||
true, true, null).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
return (rootDir, rootAfter) -> {
|
||||
final PsiManager manager = PsiManager.getInstance(myProject);
|
||||
PsiPackage[] sourcePackages = new PsiPackage[packageNames.length];
|
||||
for (int i = 0; i < packageNames.length; i++) {
|
||||
String packageName = packageNames[i];
|
||||
sourcePackages[i] = JavaPsiFacade.getInstance(manager.getProject()).findPackage(packageName);
|
||||
assertNotNull(sourcePackages[i]);
|
||||
}
|
||||
PsiPackage targetPackage = JavaPsiFacade.getInstance(manager.getProject()).findPackage(targetPackageName);
|
||||
assertNotNull(targetPackage);
|
||||
new MoveClassesOrPackagesProcessor(myProject, sourcePackages,
|
||||
new MultipleRootsMoveDestination(new PackageWrapper(targetPackage)),
|
||||
true, true, null).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -56,12 +56,7 @@ public class MovePackageTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTest(final String[] packageNames, final String newPackageName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
MovePackageTest.this.performAction(packageNames, newPackageName);
|
||||
}
|
||||
});
|
||||
doTest((rootDir, rootAfter) -> MovePackageTest.this.performAction(packageNames, newPackageName));
|
||||
}
|
||||
|
||||
private void performAction(String[] packageNames, String newPackageName) throws Exception {
|
||||
|
||||
@@ -21,13 +21,11 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.memberPullUp.PullUpConflictsUtil;
|
||||
import com.intellij.refactoring.memberPullUp.PullUpProcessor;
|
||||
import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import com.intellij.refactoring.util.classMembers.InterfaceContainmentVerifier;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -49,42 +47,35 @@ public class PullUpMultifileTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTest(final String... conflicts) throws Exception {
|
||||
final MultiMap<PsiElement, String> conflictsMap = new MultiMap<PsiElement, String>();
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
|
||||
final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
|
||||
final PsiMethod[] methods = srcClass.getMethods();
|
||||
assertTrue("No methods found", methods.length > 0);
|
||||
final MemberInfo[] membersToMove = new MemberInfo[1];
|
||||
final MemberInfo memberInfo = new MemberInfo(methods[0]);
|
||||
memberInfo.setChecked(true);
|
||||
membersToMove[0] = memberInfo;
|
||||
final PsiMethod[] methods = srcClass.getMethods();
|
||||
assertTrue("No methods found", methods.length > 0);
|
||||
final MemberInfo[] membersToMove = new MemberInfo[1];
|
||||
final MemberInfo memberInfo = new MemberInfo(methods[0]);
|
||||
memberInfo.setChecked(true);
|
||||
membersToMove[0] = memberInfo;
|
||||
|
||||
final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
|
||||
final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
|
||||
conflictsMap.putAllValues(
|
||||
PullUpConflictsUtil.checkConflicts(membersToMove, srcClass, targetClass, targetPackage, targetDirectory, new InterfaceContainmentVerifier() {
|
||||
@Override
|
||||
public boolean checkedInterfacesContain(PsiMethod psiMethod) {
|
||||
return PullUpProcessor.checkedInterfacesContain(Arrays.asList(membersToMove), psiMethod);
|
||||
}
|
||||
}));
|
||||
final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
|
||||
final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
|
||||
conflictsMap.putAllValues(
|
||||
PullUpConflictsUtil.checkConflicts(membersToMove, srcClass, targetClass, targetPackage, targetDirectory,
|
||||
psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(membersToMove), psiMethod)));
|
||||
|
||||
new PullUpProcessor(srcClass, targetClass, membersToMove, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
|
||||
}
|
||||
new PullUpProcessor(srcClass, targetClass, membersToMove, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
|
||||
});
|
||||
|
||||
if (conflicts.length != 0 && conflictsMap.isEmpty()) {
|
||||
fail("Conflict was not detected");
|
||||
}
|
||||
final HashSet<String> values = new HashSet<String>(conflictsMap.values());
|
||||
final HashSet<String> expected = new HashSet<String>(Arrays.asList(conflicts));
|
||||
final HashSet<String> values = new HashSet<>(conflictsMap.values());
|
||||
final HashSet<String> expected = new HashSet<>(Arrays.asList(conflicts));
|
||||
|
||||
assertEquals(expected.size(), values.size());
|
||||
for (String value : values) {
|
||||
|
||||
@@ -189,7 +189,7 @@ public class PullUpTest extends LightRefactoringTestCase {
|
||||
private void doTest(final boolean checkMembersMovedCount,
|
||||
String conflictMessage,
|
||||
RefactoringTestUtil.MemberDescriptor... membersToFind) {
|
||||
final MultiMap<PsiElement, String> conflictsMap = new MultiMap<PsiElement, String>();
|
||||
final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
PsiElement elementAt = getFile().findElementAt(getEditor().getCaretModel().getOffset());
|
||||
final PsiClass sourceClass = PsiTreeUtil.getParentOfType(elementAt, PsiClass.class);
|
||||
@@ -206,24 +206,17 @@ public class PullUpTest extends LightRefactoringTestCase {
|
||||
final MemberInfo[] infos = RefactoringTestUtil.findMembers(sourceClass, membersToFind);
|
||||
|
||||
final int[] countMoved = {0};
|
||||
final MoveMemberListener listener = new MoveMemberListener() {
|
||||
@Override
|
||||
public void memberMoved(PsiClass aClass, PsiMember member) {
|
||||
assertEquals(sourceClass, aClass);
|
||||
countMoved[0]++;
|
||||
}
|
||||
final MoveMemberListener listener = (aClass, member) -> {
|
||||
assertEquals(sourceClass, aClass);
|
||||
countMoved[0]++;
|
||||
};
|
||||
JavaRefactoringListenerManager.getInstance(getProject()).addMoveMembersListener(listener);
|
||||
final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
|
||||
final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
|
||||
conflictsMap.putAllValues(
|
||||
PullUpConflictsUtil
|
||||
.checkConflicts(infos, sourceClass, targetClass, targetPackage, targetDirectory, new InterfaceContainmentVerifier() {
|
||||
@Override
|
||||
public boolean checkedInterfacesContain(PsiMethod psiMethod) {
|
||||
return PullUpProcessor.checkedInterfacesContain(Arrays.asList(infos), psiMethod);
|
||||
}
|
||||
})
|
||||
.checkConflicts(infos, sourceClass, targetClass, targetPackage, targetDirectory,
|
||||
psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(infos), psiMethod))
|
||||
);
|
||||
final PullUpProcessor helper = new PullUpProcessor(sourceClass, targetClass, infos, new DocCommentPolicy(DocCommentPolicy.ASIS));
|
||||
helper.run();
|
||||
|
||||
@@ -54,28 +54,25 @@ public class PushDownMultifileTest extends MultiFileTestCase {
|
||||
|
||||
private void doTest(final boolean fail, final String sourceClassName, final String targetClassName) throws Exception {
|
||||
try {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
final PsiClass srcClass = myJavaFacade.findClass(sourceClassName, GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass srcClass = myJavaFacade.findClass(sourceClassName, GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
|
||||
final PsiClass targetClass = myJavaFacade.findClass(targetClassName, GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
final PsiClass targetClass = myJavaFacade.findClass(targetClassName, GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
|
||||
final PsiMethod[] methods = srcClass.getMethods();
|
||||
assertTrue("No methods found", methods.length > 0);
|
||||
final MemberInfo[] membersToMove = new MemberInfo[1];
|
||||
final MemberInfo memberInfo = new MemberInfo(methods[0]);
|
||||
memberInfo.setChecked(true);
|
||||
membersToMove[0] = memberInfo;
|
||||
final PsiMethod[] methods = srcClass.getMethods();
|
||||
assertTrue("No methods found", methods.length > 0);
|
||||
final MemberInfo[] membersToMove = new MemberInfo[1];
|
||||
final MemberInfo memberInfo = new MemberInfo(methods[0]);
|
||||
memberInfo.setChecked(true);
|
||||
membersToMove[0] = memberInfo;
|
||||
|
||||
new PushDownProcessor(getProject(), membersToMove, srcClass, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
|
||||
new PushDownProcessor(getProject(), membersToMove, srcClass, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
|
||||
|
||||
|
||||
//LocalFileSystem.getInstance().refresh(false);
|
||||
//FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
//LocalFileSystem.getInstance().refresh(false);
|
||||
//FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
@@ -110,28 +107,25 @@ public class PushDownMultifileTest extends MultiFileTestCase {
|
||||
|
||||
public void testUsagesInXml() throws Exception {
|
||||
try {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
|
||||
final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
|
||||
final PsiField[] fields = srcClass.getFields();
|
||||
assertTrue("No methods found", fields.length > 0);
|
||||
final MemberInfo[] membersToMove = new MemberInfo[1];
|
||||
final MemberInfo memberInfo = new MemberInfo(fields[0]);
|
||||
memberInfo.setChecked(true);
|
||||
membersToMove[0] = memberInfo;
|
||||
final PsiField[] fields = srcClass.getFields();
|
||||
assertTrue("No methods found", fields.length > 0);
|
||||
final MemberInfo[] membersToMove = new MemberInfo[1];
|
||||
final MemberInfo memberInfo = new MemberInfo(fields[0]);
|
||||
memberInfo.setChecked(true);
|
||||
membersToMove[0] = memberInfo;
|
||||
|
||||
new PushDownProcessor(getProject(), membersToMove, srcClass, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
|
||||
new PushDownProcessor(getProject(), membersToMove, srcClass, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
|
||||
|
||||
|
||||
//LocalFileSystem.getInstance().refresh(false);
|
||||
//FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
//LocalFileSystem.getInstance().refresh(false);
|
||||
//FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
|
||||
@@ -78,7 +78,7 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
|
||||
assert currentClass != null;
|
||||
|
||||
final List<MemberInfo> membersToMove = new ArrayList<MemberInfo>();
|
||||
final List<MemberInfo> membersToMove = new ArrayList<>();
|
||||
|
||||
final PsiField fieldByName = currentClass.findFieldByName("fieldToMove", false);
|
||||
if (fieldByName != null) {
|
||||
@@ -109,12 +109,7 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
|
||||
PsiClass currentClass = JavaPsiFacade.getInstance(getProject()).findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
MemberInfoStorage memberInfoStorage = new MemberInfoStorage(currentClass, new MemberInfo.Filter<PsiMember>() {
|
||||
@Override
|
||||
public boolean includeMember(PsiMember element) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
MemberInfoStorage memberInfoStorage = new MemberInfoStorage(currentClass, element -> true);
|
||||
List<MemberInfo> members = memberInfoStorage.getClassMemberInfos(currentClass);
|
||||
for (MemberInfo member : members) {
|
||||
member.setChecked(true);
|
||||
|
||||
@@ -50,34 +50,31 @@ public class RemoveMiddleManTest extends MultiFileTestCase{
|
||||
}
|
||||
|
||||
private void doTest(final String conflict) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(getProject()));
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(getProject()));
|
||||
|
||||
if (aClass == null) aClass = myJavaFacade.findClass("p.Test", GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
if (aClass == null) aClass = myJavaFacade.findClass("p.Test", GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final PsiField field = aClass.findFieldByName("myField", false);
|
||||
final Set<PsiMethod> methods = DelegationUtils.getDelegatingMethodsForField(field);
|
||||
List<MemberInfo> infos = new ArrayList<MemberInfo>();
|
||||
for (PsiMethod method : methods) {
|
||||
final MemberInfo info = new MemberInfo(method);
|
||||
info.setChecked(true);
|
||||
info.setToAbstract(true);
|
||||
infos.add(info);
|
||||
}
|
||||
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) {
|
||||
if (conflict == null) throw e;
|
||||
assertEquals(conflict, e.getMessage());
|
||||
}
|
||||
final PsiField field = aClass.findFieldByName("myField", false);
|
||||
final Set<PsiMethod> methods = DelegationUtils.getDelegatingMethodsForField(field);
|
||||
List<MemberInfo> infos = new ArrayList<>();
|
||||
for (PsiMethod method : methods) {
|
||||
final MemberInfo info = new MemberInfo(method);
|
||||
info.setChecked(true);
|
||||
info.setToAbstract(true);
|
||||
infos.add(info);
|
||||
}
|
||||
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) {
|
||||
if (conflict == null) throw e;
|
||||
assertEquals(conflict, e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,20 +75,17 @@ public class RenameClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doRenameClass(final String className, final String newName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class XX not found", aClass);
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class XX not found", aClass);
|
||||
|
||||
final RenameProcessor processor = new RenameProcessor(myProject, aClass, newName, true, true);
|
||||
for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
|
||||
processor.addRenamerFactory(factory);
|
||||
}
|
||||
processor.run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
final RenameProcessor processor = new RenameProcessor(myProject, aClass, newName, true, true);
|
||||
for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
|
||||
processor.addRenamerFactory(factory);
|
||||
}
|
||||
processor.run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,12 +98,7 @@ public class RenameClassTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String qClassName, @NonNls final String newName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
RenameClassTest.this.performAction(qClassName, newName);
|
||||
}
|
||||
});
|
||||
doTest((rootDir, rootAfter) -> RenameClassTest.this.performAction(qClassName, newName));
|
||||
}
|
||||
|
||||
private void performAction(String qClassName, String newName) throws Exception {
|
||||
|
||||
@@ -283,7 +283,7 @@ public class RenameCollisionsTest extends LightRefactoringTestCase {
|
||||
PsiElement element = TargetElementUtil
|
||||
.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
|
||||
assertNotNull(element);
|
||||
final UsageInfo[] usageInfos = RenameUtil.findUsages(element, "newName", true, true, new HashMap<PsiElement, String>());
|
||||
final UsageInfo[] usageInfos = RenameUtil.findUsages(element, "newName", true, true, new HashMap<>());
|
||||
assertSize(1, usageInfos);
|
||||
for (UsageInfo usageInfo : usageInfos) {
|
||||
assertTrue(usageInfo instanceof MoveRenameUsageInfo);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class RenameLocalTest extends LightRefactoringTestCase {
|
||||
PsiElement element = TargetElementUtil
|
||||
.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
|
||||
assertNotNull(element);
|
||||
final HashSet<String> result = new HashSet<String>();
|
||||
final HashSet<String> result = new HashSet<>();
|
||||
new JavaNameSuggestionProvider().getSuggestedNames(element, getFile(), result);
|
||||
assertTrue(result.toString(), result.contains("window"));
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class RenameMembersInplaceTest extends LightCodeInsightTestCase {
|
||||
final PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.getInstance().getAllAccepted());
|
||||
assertNotNull(element);
|
||||
|
||||
final Set<String> result = new LinkedHashSet<String>();
|
||||
final Set<String> result = new LinkedHashSet<>();
|
||||
new JavaNameSuggestionProvider().getSuggestedNames(element, getFile(), result);
|
||||
|
||||
CodeInsightTestUtil.doInlineRename(new MemberInplaceRenameHandler(), result.iterator().next(), getEditor(), element);
|
||||
|
||||
@@ -99,41 +99,35 @@ public class RenameMethodMultiTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTest(final String className, final String methodSignature, final String newName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
final JavaPsiFacade manager = getJavaFacade();
|
||||
final PsiClass aClass = manager.findClass(className, GlobalSearchScope.moduleScope(myModule));
|
||||
assertNotNull(aClass);
|
||||
final PsiMethod methodBySignature = aClass.findMethodBySignature(manager.getElementFactory().createMethodFromText(
|
||||
methodSignature + "{}", null), false);
|
||||
assertNotNull(methodBySignature);
|
||||
final RenameProcessor renameProcessor = new RenameProcessor(myProject, methodBySignature, newName, false, false);
|
||||
renameProcessor.run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final JavaPsiFacade manager = getJavaFacade();
|
||||
final PsiClass aClass = manager.findClass(className, GlobalSearchScope.moduleScope(myModule));
|
||||
assertNotNull(aClass);
|
||||
final PsiMethod methodBySignature = aClass.findMethodBySignature(manager.getElementFactory().createMethodFromText(
|
||||
methodSignature + "{}", null), false);
|
||||
assertNotNull(methodBySignature);
|
||||
final RenameProcessor renameProcessor = new RenameProcessor(myProject, methodBySignature, newName, false, false);
|
||||
renameProcessor.run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
private void doAutomaticRenameMethod(final String className, final String methodSignature, final String newName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
final JavaPsiFacade manager = getJavaFacade();
|
||||
final PsiClass aClass = manager.findClass(className, GlobalSearchScope.moduleScope(myModule));
|
||||
assertNotNull(aClass);
|
||||
final PsiMethod methodBySignature = aClass.findMethodBySignature(manager.getElementFactory().createMethodFromText(
|
||||
methodSignature + "{}", null), false);
|
||||
assertNotNull(methodBySignature);
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final JavaPsiFacade manager = getJavaFacade();
|
||||
final PsiClass aClass = manager.findClass(className, GlobalSearchScope.moduleScope(myModule));
|
||||
assertNotNull(aClass);
|
||||
final PsiMethod methodBySignature = aClass.findMethodBySignature(manager.getElementFactory().createMethodFromText(
|
||||
methodSignature + "{}", null), false);
|
||||
assertNotNull(methodBySignature);
|
||||
|
||||
final RenameProcessor processor = new RenameProcessor(myProject, methodBySignature, newName, false, false);
|
||||
for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
|
||||
processor.addRenamerFactory(factory);
|
||||
}
|
||||
processor.run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
final RenameProcessor processor = new RenameProcessor(myProject, methodBySignature, newName, false, false);
|
||||
for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
|
||||
processor.addRenamerFactory(factory);
|
||||
}
|
||||
processor.run();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+30
-33
@@ -62,13 +62,13 @@ public class ReplaceConstructorWithBuilderTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void testConstructorChain() throws Exception {
|
||||
final HashMap<String, String> defaults = new HashMap<String, String>();
|
||||
final HashMap<String, String> defaults = new HashMap<>();
|
||||
defaults.put("i", "2");
|
||||
doTest(true, defaults);
|
||||
}
|
||||
|
||||
public void testConstructorChainWithoutDefaults() throws Exception {
|
||||
final HashMap<String, String> defaults = new HashMap<String, String>();
|
||||
final HashMap<String, String> defaults = new HashMap<>();
|
||||
defaults.put("i", "2");
|
||||
defaults.put("j", null);
|
||||
doTest(true, defaults);
|
||||
@@ -102,39 +102,36 @@ public class ReplaceConstructorWithBuilderTest extends MultiFileTestCase {
|
||||
final Map<String, String> expectedDefaults,
|
||||
final String conflicts,
|
||||
final String packageName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
final PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
final PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
|
||||
final LinkedHashMap<String, ParameterData> map = new LinkedHashMap<String, ParameterData>();
|
||||
final PsiMethod[] constructors = aClass.getConstructors();
|
||||
for (PsiMethod constructor : constructors) {
|
||||
ParameterData.createFromConstructor(constructor, "set", map);
|
||||
}
|
||||
if (expectedDefaults != null) {
|
||||
for (Map.Entry<String, String> entry : expectedDefaults.entrySet()) {
|
||||
final ParameterData parameterData = map.get(entry.getKey());
|
||||
assertNotNull(parameterData);
|
||||
assertEquals(entry.getValue(), parameterData.getDefaultValue());
|
||||
}
|
||||
}
|
||||
try {
|
||||
new ReplaceConstructorWithBuilderProcessor(getProject(), constructors, map, "Builder", packageName, null, createNewBuilderClass).run();
|
||||
if (conflicts != null) {
|
||||
fail("Conflicts were not detected:" + conflicts);
|
||||
}
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
|
||||
if (conflicts == null) {
|
||||
fail("Conflict detected:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
final LinkedHashMap<String, ParameterData> map = new LinkedHashMap<>();
|
||||
final PsiMethod[] constructors = aClass.getConstructors();
|
||||
for (PsiMethod constructor : constructors) {
|
||||
ParameterData.createFromConstructor(constructor, "set", map);
|
||||
}
|
||||
if (expectedDefaults != null) {
|
||||
for (Map.Entry<String, String> entry : expectedDefaults.entrySet()) {
|
||||
final ParameterData parameterData = map.get(entry.getKey());
|
||||
assertNotNull(parameterData);
|
||||
assertEquals(entry.getValue(), parameterData.getDefaultValue());
|
||||
}
|
||||
}
|
||||
try {
|
||||
new ReplaceConstructorWithBuilderProcessor(getProject(), constructors, map, "Builder", packageName, null, createNewBuilderClass).run();
|
||||
if (conflicts != null) {
|
||||
fail("Conflicts were not detected:" + conflicts);
|
||||
}
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
|
||||
if (conflicts == null) {
|
||||
fail("Conflict detected:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -278,11 +278,8 @@ public class SafeDeleteTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String qClassName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
SafeDeleteTest.this.performAction(qClassName);
|
||||
}
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
SafeDeleteTest.this.performAction(qClassName);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -67,11 +67,8 @@ 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) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
TurnRefsToSuperTest.this.performAction(className, superClassName, replaceInstanceOf);
|
||||
}
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
TurnRefsToSuperTest.this.performAction(className, superClassName, replaceInstanceOf);
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -672,12 +672,7 @@ public class TypeCookTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
public void start(final boolean cookObjects) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
TypeCookTest.this.performAction("Test", rootDir.getName(), cookObjects);
|
||||
}
|
||||
});
|
||||
doTest((rootDir, rootAfter) -> TypeCookTest.this.performAction("Test", rootDir.getName(), cookObjects));
|
||||
}
|
||||
|
||||
private void performAction(String className, String rootDir, final boolean cookObjects) throws Exception {
|
||||
|
||||
@@ -70,18 +70,15 @@ public class WrapReturnValueTest extends MultiFileTestCase {
|
||||
|
||||
private void doTest(final boolean existing, String exceptionMessage, final boolean createInnerClass) {
|
||||
try {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
PsiMethod method = aClass.findMethodsByName("foo", false)[0];
|
||||
String wrapperClassName = "Wrapper";
|
||||
PsiClass wrapperClass = myJavaFacade.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();
|
||||
}
|
||||
doTest((rootDir, rootAfter) -> {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
PsiMethod method = aClass.findMethodsByName("foo", false)[0];
|
||||
String wrapperClassName = "Wrapper";
|
||||
PsiClass wrapperClass = myJavaFacade.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();
|
||||
});
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
|
||||
+22
-77
@@ -22,120 +22,65 @@ public class ChangeClassSignatureTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
public void testNoParams() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) throws IncorrectOperationException {
|
||||
return new TypeParameterInfo[]{
|
||||
new TypeParameterInfo(aClass, "T", "java.lang.String")
|
||||
};
|
||||
}
|
||||
doTest(aClass -> new TypeParameterInfo[]{
|
||||
new TypeParameterInfo(aClass, "T", "java.lang.String")
|
||||
});
|
||||
}
|
||||
|
||||
public void testInstanceOf() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) throws IncorrectOperationException {
|
||||
return new TypeParameterInfo[]{
|
||||
new TypeParameterInfo(aClass, "T", "java.lang.String")
|
||||
};
|
||||
}
|
||||
doTest(aClass -> new TypeParameterInfo[]{
|
||||
new TypeParameterInfo(aClass, "T", "java.lang.String")
|
||||
});
|
||||
}
|
||||
|
||||
public void testSubstituteParamInsideClass() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) throws IncorrectOperationException {
|
||||
return new TypeParameterInfo[0];
|
||||
}
|
||||
});
|
||||
doTest(aClass -> new TypeParameterInfo[0]);
|
||||
}
|
||||
|
||||
public void testRemoveAllParams() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) {
|
||||
return new TypeParameterInfo[0];
|
||||
}
|
||||
});
|
||||
doTest(aClass -> new TypeParameterInfo[0]);
|
||||
}
|
||||
|
||||
public void testReorderParams() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) {
|
||||
return new TypeParameterInfo[] {
|
||||
new TypeParameterInfo(1),
|
||||
new TypeParameterInfo(0)
|
||||
};
|
||||
}
|
||||
doTest(aClass -> new TypeParameterInfo[] {
|
||||
new TypeParameterInfo(1),
|
||||
new TypeParameterInfo(0)
|
||||
});
|
||||
}
|
||||
|
||||
public void testAddParam() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) throws IncorrectOperationException {
|
||||
return new TypeParameterInfo[] {
|
||||
new TypeParameterInfo(0),
|
||||
new TypeParameterInfo(aClass, "E", "L<T>")
|
||||
};
|
||||
}
|
||||
doTest(aClass -> new TypeParameterInfo[] {
|
||||
new TypeParameterInfo(0),
|
||||
new TypeParameterInfo(aClass, "E", "L<T>")
|
||||
});
|
||||
}
|
||||
|
||||
public void testAddParamDiamond() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) throws IncorrectOperationException {
|
||||
return new TypeParameterInfo[] {
|
||||
new TypeParameterInfo(0),
|
||||
new TypeParameterInfo(aClass, "I", "Integer")
|
||||
};
|
||||
}
|
||||
doTest(aClass -> new TypeParameterInfo[] {
|
||||
new TypeParameterInfo(0),
|
||||
new TypeParameterInfo(aClass, "I", "Integer")
|
||||
});
|
||||
}
|
||||
|
||||
public void testAddOneFirst() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) throws IncorrectOperationException {
|
||||
return new TypeParameterInfo[]{
|
||||
new TypeParameterInfo(aClass, "T", "java.lang.String")
|
||||
};
|
||||
}
|
||||
doTest(aClass -> new TypeParameterInfo[]{
|
||||
new TypeParameterInfo(aClass, "T", "java.lang.String")
|
||||
}, "Zero.java", "OneString.java");
|
||||
}
|
||||
|
||||
public void testAddManyFirst() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) throws IncorrectOperationException {
|
||||
return new TypeParameterInfo[]{
|
||||
new TypeParameterInfo(aClass, "U", "SubjectFace"),
|
||||
new TypeParameterInfo(aClass, "V", "java.util.Set<java.lang.Object>")
|
||||
};
|
||||
}
|
||||
doTest(aClass -> new TypeParameterInfo[]{
|
||||
new TypeParameterInfo(aClass, "U", "SubjectFace"),
|
||||
new TypeParameterInfo(aClass, "V", "java.util.Set<java.lang.Object>")
|
||||
}, "Zero.java", "TwoSubjectFaceSetObject.java");
|
||||
}
|
||||
|
||||
public void testRemoveOneLast() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) throws IncorrectOperationException {
|
||||
return new TypeParameterInfo[0];
|
||||
}
|
||||
}, "OneString.java", "Zero.java");
|
||||
doTest(aClass -> new TypeParameterInfo[0], "OneString.java", "Zero.java");
|
||||
}
|
||||
|
||||
public void testRemoveManyLast() throws Exception {
|
||||
doTest(new GenParams() {
|
||||
@Override
|
||||
public TypeParameterInfo[] gen(PsiClass aClass) throws IncorrectOperationException {
|
||||
return new TypeParameterInfo[0];
|
||||
}
|
||||
}, "TwoSubjectFaceSetObject.java", "Zero.java");
|
||||
doTest(aClass -> new TypeParameterInfo[0], "TwoSubjectFaceSetObject.java", "Zero.java");
|
||||
}
|
||||
|
||||
private void doTest(GenParams gen) throws Exception {
|
||||
|
||||
+6
-8
@@ -51,14 +51,12 @@ public class InlineLibraryMethodTest extends RefactoringTestCase {
|
||||
PsiClass fileClass = getJavaFacade().findClass("mycompany.File");
|
||||
assertNotNull(fileClass);
|
||||
final PsiFile file = fileClass.getContainingFile();
|
||||
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
((VirtualFileSystemEntry)file.getVirtualFile()).setWritable(false);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
WriteCommandAction.runWriteCommandAction(null, () -> {
|
||||
try {
|
||||
((VirtualFileSystemEntry)file.getVirtualFile()).setWritable(false);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -57,12 +57,9 @@ public class MigrationTest extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private MultiFileTestCase.PerformAction createAction(final MigrationMap migrationMap) {
|
||||
return new MultiFileTestCase.PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
new MigrationProcessor(myProject, migrationMap).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
return (rootDir, rootAfter) -> {
|
||||
new MigrationProcessor(myProject, migrationMap).run();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user