use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class JavaPushDownHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
PsiClass aClass = PsiTreeUtil.getParentOfType(PsiTreeUtil.findCommonParent(elements), PsiClass.class, false);
if (aClass == null)
return;
String qualifiedName = aClass.getQualifiedName();
if (qualifiedName == null)
return;
final Editor editor = dataContext != null ? CommonDataKeys.EDITOR.getData(dataContext) : null;
if (aClass.hasModifierProperty(PsiModifier.FINAL)) {
CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.message("refactoring.cannot.be.performed") + ": Class " + aClass.getName() + " is final", REFACTORING_NAME, HelpID.MEMBERS_PUSH_DOWN);
return;
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass))
return;
MemberInfoStorage memberInfoStorage = new MemberInfoStorage(aClass, element -> !(element instanceof PsiEnumConstant));
List<MemberInfo> members = memberInfoStorage.getClassMemberInfos(aClass);
for (MemberInfoBase<PsiMember> member : members) {
for (PsiElement element : elements) {
if (PsiTreeUtil.isAncestor(member.getMember(), element, false)) {
member.setChecked(true);
break;
}
}
}
PushDownDialog dialog = new PushDownDialog(project, members.toArray(new MemberInfo[members.size()]), aClass);
dialog.show();
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class JavaPullUpHandler method checkConflicts.
@Override
public boolean checkConflicts(final PullUpDialog dialog) {
final List<MemberInfo> infos = dialog.getSelectedMemberInfos();
final MemberInfo[] memberInfos = infos.toArray(new MemberInfo[infos.size()]);
final PsiClass superClass = dialog.getSuperClass();
if (superClass == null || !checkWritable(superClass, memberInfos))
return false;
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> {
final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
if (targetDirectory != null && targetPackage != null) {
conflicts.putAllValues(PullUpConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass, targetPackage, targetDirectory, dialog.getContainmentVerifier()));
}
}), RefactoringBundle.message("detecting.possible.conflicts"), true, myProject))
return false;
if (!conflicts.isEmpty()) {
ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
boolean ok = conflictsDialog.showAndGet();
if (!ok && conflictsDialog.isShowConflicts())
dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
return ok;
}
return true;
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PullUpDialog method updateAbstractState.
private void updateAbstractState() {
boolean hasJavadoc = false;
for (MemberInfo info : myMemberInfos) {
final PsiMember member = info.getMember();
final boolean abstractWhenDisabled = myMemberInfoModel.isAbstractWhenDisabled(info);
info.setToAbstract(abstractWhenDisabled);
if (myMemberInfoModel.isAbstractEnabled(info) || abstractWhenDisabled) {
if (!hasJavadoc && member instanceof PsiDocCommentOwner && ((PsiDocCommentOwner) member).getDocComment() != null) {
hasJavadoc = true;
}
}
}
UIUtil.setEnabled(myJavaDocPanel, hasJavadoc, true);
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PullUpDialog method doAction.
protected void doAction() {
if (!myCallback.checkConflicts(this))
return;
JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC = myJavaDocPanel.getPolicy();
final PsiClass superClass = getSuperClass();
String name = superClass.getQualifiedName();
if (name != null) {
StatisticsManager.getInstance().incUseCount(new StatisticsInfo(PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(), name));
}
List<MemberInfo> infos = getSelectedMemberInfos();
invokeRefactoring(new PullUpProcessor(myClass, superClass, infos.toArray(new MemberInfo[infos.size()]), new DocCommentPolicy(getJavaDocPolicy())));
close(OK_EXIT_CODE);
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PullUpMultifileTest method doTest.
private void doTest(final String... conflicts) throws Exception {
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 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, psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(membersToMove), psiMethod)));
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<>(conflictsMap.values());
final HashSet<String> expected = new HashSet<>(Arrays.asList(conflicts));
assertEquals(expected.size(), values.size());
for (String value : values) {
if (!expected.contains(value)) {
fail("Conflict: " + value + " is unexpectedly reported");
}
}
}
Aggregations