use of com.intellij.refactoring.util.classMembers.MemberInfoStorage 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.MemberInfoStorage in project intellij-community by JetBrains.
the class PushDownTest method doTestImplements.
private void doTestImplements(boolean toAbstract, boolean failure) {
configureByFile(BASE_PATH + getTestName(false) + ".java");
PsiClass currentClass = JavaPsiFacade.getInstance(getProject()).findClass("Test", GlobalSearchScope.projectScope(getProject()));
MemberInfoStorage memberInfoStorage = new MemberInfoStorage(currentClass, element -> true);
List<MemberInfo> members = memberInfoStorage.getClassMemberInfos(currentClass);
for (MemberInfo member : members) {
member.setChecked(true);
if (toAbstract) {
member.setToAbstract(toAbstract);
}
}
new PushDownProcessor<MemberInfo, PsiMember, PsiClass>(currentClass, members, new DocCommentPolicy(DocCommentPolicy.ASIS)) {
@Override
protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
if (failure == conflicts.isEmpty()) {
fail(failure ? "Conflict was not detected" : "False conflict was detected");
}
return true;
}
}.run();
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
use of com.intellij.refactoring.util.classMembers.MemberInfoStorage in project intellij-community by JetBrains.
the class InheritanceToDelegationHandler method createBaseClassMemberInfos.
private static List<MemberInfo> createBaseClassMemberInfos(PsiClass baseClass) {
final PsiClass deepestBase = RefactoringHierarchyUtil.getDeepestNonObjectBase(baseClass);
LOG.assertTrue(deepestBase != null);
final MemberInfoStorage memberInfoStorage = new MemberInfoStorage(baseClass, MEMBER_INFO_FILTER);
List<MemberInfo> memberInfoList = new ArrayList<>();
memberInfoList.addAll(memberInfoStorage.getClassMemberInfos(deepestBase));
memberInfoList.addAll(memberInfoStorage.getIntermediateMemberInfosList(deepestBase));
return memberInfoList;
}
use of com.intellij.refactoring.util.classMembers.MemberInfoStorage in project intellij-community by JetBrains.
the class JavaPullUpHandler method invoke.
private void invoke(Project project, DataContext dataContext, PsiClass aClass, PsiElement... selectedMembers) {
final Editor editor = dataContext != null ? CommonDataKeys.EDITOR.getData(dataContext) : null;
if (aClass == null) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("is.not.supported.in.the.current.context", REFACTORING_NAME));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
return;
}
List<PsiClass> bases = RefactoringHierarchyUtil.createBasesList(aClass, false, true);
if (bases.isEmpty()) {
final PsiClass containingClass = aClass.getContainingClass();
if (containingClass != null) {
invoke(project, dataContext, containingClass, aClass);
return;
}
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("class.does.not.have.base.classes.interfaces.in.current.project", aClass.getQualifiedName()));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
return;
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass))
return;
mySubclass = aClass;
MemberInfoStorage memberInfoStorage = new MemberInfoStorage(mySubclass, element -> true);
List<MemberInfo> members = memberInfoStorage.getClassMemberInfos(mySubclass);
for (MemberInfoBase<PsiMember> member : members) {
for (PsiElement aMember : selectedMembers) {
if (PsiTreeUtil.isAncestor(member.getMember(), aMember, false)) {
member.setChecked(true);
break;
}
}
}
new PullUpDialog(project, aClass, bases, memberInfoStorage, this).show();
}
Aggregations