use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class PullUpTest method doTest.
private void doTest(final boolean checkMembersMovedCount, String conflictMessage, RefactoringTestUtil.MemberDescriptor... membersToFind) {
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);
assertNotNull(sourceClass);
PsiClass targetClass = sourceClass.getSuperClass();
assertNotNull(targetClass);
if (!targetClass.isWritable()) {
final PsiClass[] interfaces = sourceClass.getInterfaces();
assertEquals(1, interfaces.length);
assertTrue(interfaces[0].isWritable());
targetClass = interfaces[0];
}
final MemberInfo[] infos = RefactoringTestUtil.findMembers(sourceClass, membersToFind);
final int[] 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, psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(infos), psiMethod)));
final PullUpProcessor helper = new PullUpProcessor(sourceClass, targetClass, infos, new DocCommentPolicy(DocCommentPolicy.ASIS));
helper.run();
UIUtil.dispatchAllInvocationEvents();
JavaRefactoringListenerManager.getInstance(getProject()).removeMoveMembersListener(listener);
if (conflictMessage != null && conflictsMap.isEmpty()) {
fail("Conflict was not detected");
}
if (conflictMessage == null && !conflictsMap.isEmpty()) {
fail(conflictsMap.values().iterator().next());
}
if (conflictMessage != null && !IGNORE_CONFLICTS.equals(conflictMessage)) {
TreeSet<String> conflicts = new TreeSet<>(conflictsMap.values());
assertEquals(conflictMessage, conflicts.iterator().next());
return;
}
if (checkMembersMovedCount) {
assertEquals(countMoved[0], membersToFind.length);
}
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class PushDownMultifileTest method doTest.
private void doTest(final boolean fail, final String sourceClassName, final String targetClassName) throws Exception {
try {
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 PsiMethod[] methods = srcClass.getMethods();
assertTrue("No methods found", methods.length > 0);
final MemberInfo memberInfo = new MemberInfo(methods[0]);
memberInfo.setChecked(true);
new PushDownProcessor<>(srcClass, Collections.singletonList(memberInfo), new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
//LocalFileSystem.getInstance().refresh(false);
//FileDocumentManager.getInstance().saveAllDocuments();
});
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
if (fail) {
return;
} else {
throw e;
}
}
if (fail) {
fail("Conflict was not detected");
}
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class PushDownMultifileTest method testUsagesInXml.
public void testUsagesInXml() throws Exception {
try {
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 PsiField[] fields = srcClass.getFields();
assertTrue("No methods found", fields.length > 0);
final MemberInfo memberInfo = new MemberInfo(fields[0]);
memberInfo.setChecked(true);
new PushDownProcessor<>(srcClass, Collections.singletonList(memberInfo), new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
//LocalFileSystem.getInstance().refresh(false);
//FileDocumentManager.getInstance().saveAllDocuments();
});
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
assertEquals(e.getMessage(), "Class <b><code>b.B</code></b> is package-private and will not be accessible from file <b><code>A.form</code></b>.");
return;
}
fail("Conflict was not detected");
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class ExtractSuperclassHandler method doRefactoring.
// invoked inside Command and Atomic action
private static void doRefactoring(final Project project, final PsiClass subclass, final ExtractSuperclassDialog dialog) {
final String superclassName = dialog.getExtractedSuperName();
final PsiDirectory targetDirectory = dialog.getTargetDirectory();
final MemberInfo[] selectedMemberInfos = ArrayUtil.toObjectArray(dialog.getSelectedMemberInfos(), MemberInfo.class);
final DocCommentPolicy javaDocPolicy = new DocCommentPolicy(dialog.getDocCommentPolicy());
LocalHistoryAction a = LocalHistory.getInstance().startAction(getCommandName(subclass, superclassName));
try {
final PsiClass superclass;
try {
superclass = ExtractSuperClassUtil.extractSuperClass(project, targetDirectory, superclassName, subclass, selectedMemberInfos, javaDocPolicy);
} finally {
a.finish();
}
// ask whether to search references to subclass and turn them into refs to superclass if possible
ExtractClassUtil.suggestToTurnRefsToSuper(project, superclass, subclass);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class PullAsAbstractUpFix method pullUp.
private static void pullUp(PsiMethod method, PsiClass containingClass, PsiClass baseClass) {
if (!FileModificationService.getInstance().prepareFileForWrite(baseClass.getContainingFile()))
return;
final MemberInfo memberInfo = new MemberInfo(method);
memberInfo.setChecked(true);
memberInfo.setToAbstract(true);
new PullUpProcessor(containingClass, baseClass, new MemberInfo[] { memberInfo }, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
}
Aggregations