use of com.intellij.refactoring.extractSuperclass.ExtractSuperClassProcessor in project intellij-community by JetBrains.
the class ExtractSuperClassTest method doTest.
private void doTest(MemberInfo[] members, @NonNls String newClassName, String targetPackageName, VirtualFile rootDir, PsiClass psiClass, String[] conflicts) throws IOException {
PsiDirectory targetDirectory;
if (targetPackageName == null) {
targetDirectory = psiClass.getContainingFile().getContainingDirectory();
} else {
final PsiPackage aPackage = myJavaFacade.findPackage(targetPackageName);
assertNotNull(aPackage);
targetDirectory = aPackage.getDirectories()[0];
}
ExtractSuperClassProcessor processor = new ExtractSuperClassProcessor(myProject, targetDirectory, newClassName, psiClass, members, false, new DocCommentPolicy<>(DocCommentPolicy.ASIS));
final PsiPackage targetPackage;
if (targetDirectory != null) {
targetPackage = JavaDirectoryService.getInstance().getPackage(targetDirectory);
} else {
targetPackage = null;
}
final PsiClass superClass = psiClass.getExtendsListTypes().length > 0 ? psiClass.getSuperClass() : null;
final MultiMap<PsiElement, String> conflictsMap = 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<>(Arrays.asList(conflicts));
final HashSet<String> actualConflicts = new HashSet<>(conflictsMap.values());
assertEquals(expectedConflicts.size(), actualConflicts.size());
for (String actualConflict : actualConflicts) {
if (!expectedConflicts.contains(actualConflict)) {
fail("Unexpected conflict: " + actualConflict);
}
}
} else if (!conflictsMap.isEmpty()) {
fail("Unexpected conflicts!!!");
}
processor.run();
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
FileDocumentManager.getInstance().saveAllDocuments();
String rootAfter = getRoot() + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
Aggregations