use of com.intellij.refactoring.util.classMembers.MemberInfo 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.MemberInfo in project intellij-community by JetBrains.
the class ExtractClassDialog method canExtractEnum.
private boolean canExtractEnum() {
final List<PsiField> fields = new ArrayList<>();
final List<PsiClass> innerClasses = new ArrayList<>();
final List<PsiMethod> methods = new ArrayList<>();
for (MemberInfo info : memberInfo) {
if (info.isChecked()) {
final PsiMember member = info.getMember();
if (member instanceof PsiField) {
fields.add((PsiField) member);
} else if (member instanceof PsiMethod) {
methods.add((PsiMethod) member);
} else if (member instanceof PsiClass) {
innerClasses.add((PsiClass) member);
}
}
}
return !new BackpointerUsageVisitor(fields, innerClasses, methods, sourceClass).backpointerRequired();
}
use of com.intellij.refactoring.util.classMembers.MemberInfo 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();
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PullUpProcessor method performRefactoring.
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
moveMembersToBase();
moveFieldInitializations();
for (UsageInfo usage : usages) {
PsiElement element = usage.getElement();
if (element == null)
continue;
PullUpHelper<MemberInfo> processor = getProcessor(element);
if (processor == null)
continue;
processor.updateUsage(element);
}
ApplicationManager.getApplication().invokeLater(() -> processMethodsDuplicates(), ModalityState.NON_MODAL, myProject.getDisposed());
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PullUpProcessor method moveMembersToBase.
public void moveMembersToBase() throws IncorrectOperationException {
myMovedMembers = ContainerUtil.newHashSet();
myMembersAfterMove = ContainerUtil.newHashSet();
// build aux sets
for (MemberInfo info : myMembersToMove) {
myMovedMembers.add(info.getMember());
}
final PsiSubstitutor substitutor = upDownSuperClassSubstitutor();
for (MemberInfo info : myMembersToMove) {
PullUpHelper<MemberInfo> processor = getProcessor(info);
LOG.assertTrue(processor != null, info.getMember());
if (!(info.getMember() instanceof PsiClass) || info.getOverrides() == null) {
processor.setCorrectVisibility(info);
processor.encodeContextInfo(info);
}
processor.move(info, substitutor);
}
for (PsiMember member : myMembersAfterMove) {
PullUpHelper<MemberInfo> processor = getProcessor(member);
LOG.assertTrue(processor != null, member);
processor.postProcessMember(member);
final JavaRefactoringListenerManager listenerManager = JavaRefactoringListenerManager.getInstance(myProject);
((JavaRefactoringListenerManagerImpl) listenerManager).fireMemberMoved(mySourceClass, member);
}
}
Aggregations