use of com.intellij.refactoring.extractclass.ExtractClassProcessor in project intellij-community by JetBrains.
the class ExtractClassTest method testPublicVisibility.
public void testPublicVisibility() throws Exception {
doTest((rootDir, rootAfter) -> {
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
assertNotNull("Class Test not found", aClass);
final ArrayList<PsiMethod> methods = new ArrayList<>();
methods.add(aClass.findMethodsByName("foos", false)[0]);
final ArrayList<PsiField> fields = new ArrayList<>();
fields.add(aClass.findFieldByName("myT", false));
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();
});
}
use of com.intellij.refactoring.extractclass.ExtractClassProcessor in project intellij-community by JetBrains.
the class ExtractClassTest method testPublicFieldDelegation.
public void testPublicFieldDelegation() throws Exception {
doTest((rootDir, rootAfter) -> {
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
assertNotNull("Class Test not found", aClass);
final ArrayList<PsiField> fields = new ArrayList<>();
fields.add(aClass.findFieldByName("myT", false));
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, new ArrayList<>(), new ArrayList<>(), "", "Extracted");
processor.run();
LocalFileSystem.getInstance().refresh(false);
FileDocumentManager.getInstance().saveAllDocuments();
});
}
use of com.intellij.refactoring.extractclass.ExtractClassProcessor in project intellij-community by JetBrains.
the class ExtractEnumTest method doTest.
private void doTest(final String conflicts, final boolean generateAccessors, final RefactoringTestUtil.MemberDescriptor... memberDescriptors) throws Exception {
doTest((rootDir, rootAfter) -> {
final PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
assertNotNull("Class Test not found", aClass);
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<>(), "", 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());
}
}
if (conflicts != null) {
fail("Conflicts were not detected: " + conflicts);
}
});
}
use of com.intellij.refactoring.extractclass.ExtractClassProcessor in project intellij-community by JetBrains.
the class ExtractClassTest method doTest.
private static void doTest(final PsiClass aClass, final ArrayList<PsiMethod> methods, final ArrayList<PsiField> fields, final String conflicts, boolean generateGettersSetters, boolean inner) {
try {
ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, methods, new ArrayList<>(), StringUtil.getPackageName(aClass.getQualifiedName()), null, "Extracted", null, generateGettersSetters, Collections.<MemberInfo>emptyList());
processor.setExtractInnerClass(inner);
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());
}
}
if (conflicts != null) {
fail("Conflicts were not detected: " + conflicts);
}
}
use of com.intellij.refactoring.extractclass.ExtractClassProcessor in project intellij-community by JetBrains.
the class ExtractClassTest method doTestInnerClass.
private void doTestInnerClass() throws Exception {
doTest((rootDir, rootAfter) -> {
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
assertNotNull("Class Test not found", aClass);
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();
});
}
Aggregations