Search in sources :

Example 36 with MemberInfo

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;
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) MemberInfoStorage(com.intellij.refactoring.util.classMembers.MemberInfoStorage)

Example 37 with MemberInfo

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();
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo)

Example 38 with MemberInfo

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();
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) MemberInfoStorage(com.intellij.refactoring.util.classMembers.MemberInfoStorage) Editor(com.intellij.openapi.editor.Editor)

Example 39 with MemberInfo

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());
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) UsageInfo(com.intellij.usageView.UsageInfo)

Example 40 with MemberInfo

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);
    }
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) JavaRefactoringListenerManagerImpl(com.intellij.refactoring.listeners.impl.JavaRefactoringListenerManagerImpl) JavaRefactoringListenerManager(com.intellij.refactoring.listeners.JavaRefactoringListenerManager)

Aggregations

MemberInfo (com.intellij.refactoring.util.classMembers.MemberInfo)45 DocCommentPolicy (com.intellij.refactoring.util.DocCommentPolicy)12 PsiMethod (com.intellij.psi.PsiMethod)6 MultiMap (com.intellij.util.containers.MultiMap)6 ArrayList (java.util.ArrayList)6 Project (com.intellij.openapi.project.Project)5 com.intellij.psi (com.intellij.psi)5 MemberSelectionPanel (com.intellij.refactoring.ui.MemberSelectionPanel)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)5 HashSet (java.util.HashSet)5 Editor (com.intellij.openapi.editor.Editor)4 PsiClass (com.intellij.psi.PsiClass)4 PullUpProcessor (com.intellij.refactoring.memberPullUp.PullUpProcessor)4 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)3 PsiMember (com.intellij.psi.PsiMember)3 MemberSelectionTable (com.intellij.refactoring.ui.MemberSelectionTable)3 MemberInfoStorage (com.intellij.refactoring.util.classMembers.MemberInfoStorage)3 UsageInfo (com.intellij.usageView.UsageInfo)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3