Search in sources :

Example 31 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class RemoveMiddlemanProcessor method findUsages.

public void findUsages(@NotNull List<FixableUsageInfo> usages) {
    for (final MemberInfo memberInfo : myDelegateMethodInfos) {
        if (!memberInfo.isChecked())
            continue;
        final PsiMethod method = (PsiMethod) memberInfo.getMember();
        final String getterName = GenerateMembersUtil.suggestGetterName(field);
        final int[] paramPermutation = DelegationUtils.getParameterPermutation(method);
        final PsiMethod delegatedMethod = DelegationUtils.getDelegatedMethod(method);
        LOG.assertTrue(!DelegationUtils.isAbstract(method));
        processUsagesForMethod(memberInfo.isToAbstract(), method, paramPermutation, getterName, delegatedMethod, usages);
    }
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo)

Example 32 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class MoveMembersDialog method getSelectedMembers.

public PsiMember[] getSelectedMembers() {
    final Collection<MemberInfo> selectedMemberInfos = myTable.getSelectedMemberInfos();
    ArrayList<PsiMember> list = new ArrayList<>();
    for (MemberInfo selectedMemberInfo : selectedMemberInfos) {
        list.add(selectedMemberInfo.getMember());
    }
    return list.toArray(new PsiMember[list.size()]);
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) ArrayList(java.util.ArrayList)

Example 33 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class ExtractMethodObjectProcessor method moveUsedMethodsToInner.

void moveUsedMethodsToInner() {
    if (!myUsages.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            WriteAction.run(() -> {
                for (MethodToMoveUsageInfo usage : myUsages) {
                    final PsiMember member = (PsiMember) usage.getElement();
                    LOG.assertTrue(member != null);
                    myInnerClass.add(member.copy());
                    member.delete();
                }
            });
            return;
        }
        final List<MemberInfo> memberInfos = new ArrayList<>();
        for (MethodToMoveUsageInfo usage : myUsages) {
            memberInfos.add(new MemberInfo((PsiMethod) usage.getElement()));
        }
        final MemberSelectionPanel panel = new MemberSelectionPanel("&Methods to move to the extracted class", memberInfos, null);
        DialogWrapper dlg = new DialogWrapper(myProject, false) {

            {
                init();
                setTitle("Move Methods Used in Extracted Block Only");
            }

            @Override
            protected JComponent createCenterPanel() {
                return panel;
            }
        };
        if (dlg.showAndGet()) {
            WriteAction.run(() -> {
                for (MemberInfoBase<PsiMember> memberInfo : panel.getTable().getSelectedMemberInfos()) {
                    if (memberInfo.isChecked()) {
                        myInnerClass.add(memberInfo.getMember().copy());
                        memberInfo.getMember().delete();
                    }
                }
            });
        }
    }
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) MemberSelectionPanel(com.intellij.refactoring.ui.MemberSelectionPanel) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 34 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class ExtractSuperClassUtil method createExtendingReference.

public static PsiJavaCodeReferenceElement createExtendingReference(final PsiClass superClass, final PsiClass derivedClass, final MemberInfo[] selectedMembers) throws IncorrectOperationException {
    final PsiManager manager = derivedClass.getManager();
    Set<PsiElement> movedElements = new com.intellij.util.containers.HashSet<>();
    for (final MemberInfo info : selectedMembers) {
        movedElements.add(info.getMember());
    }
    final Condition<PsiTypeParameter> filter = parameter -> findTypeParameterInDerived(derivedClass, parameter.getName()) == parameter;
    final PsiTypeParameterList typeParameterList = RefactoringUtil.createTypeParameterListWithUsedTypeParameters(null, filter, PsiUtilCore.toPsiElementArray(movedElements));
    final PsiTypeParameterList originalTypeParameterList = superClass.getTypeParameterList();
    assert originalTypeParameterList != null;
    final PsiTypeParameterList newList = typeParameterList != null ? (PsiTypeParameterList) originalTypeParameterList.replace(typeParameterList) : originalTypeParameterList;
    final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
    Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<>();
    for (final PsiTypeParameter parameter : newList.getTypeParameters()) {
        final PsiTypeParameter parameterInDerived = findTypeParameterInDerived(derivedClass, parameter.getName());
        if (parameterInDerived != null) {
            substitutionMap.put(parameter, factory.createType(parameterInDerived));
        }
    }
    final PsiClassType type = factory.createType(superClass, factory.createSubstitutor(substitutionMap));
    return factory.createReferenceElementByType(type);
}
Also used : TypeConversionUtil(com.intellij.psi.util.TypeConversionUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) NonNls(org.jetbrains.annotations.NonNls) RefactoringEventListener(com.intellij.refactoring.listeners.RefactoringEventListener) HashSet(java.util.HashSet) ModuleUtil(com.intellij.openapi.module.ModuleUtil) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiUtil(com.intellij.psi.util.PsiUtil) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) MultiMap(com.intellij.util.containers.MultiMap) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) PullUpProcessor(com.intellij.refactoring.memberPullUp.PullUpProcessor) Nullable(org.jetbrains.annotations.Nullable) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) MethodSignature(com.intellij.psi.util.MethodSignature) OverrideImplementExploreUtil(com.intellij.codeInsight.generation.OverrideImplementExploreUtil) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) RefactoringUtil(com.intellij.refactoring.util.RefactoringUtil) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) Function(com.intellij.util.Function) com.intellij.psi(com.intellij.psi) Condition(com.intellij.openapi.util.Condition) HashMap(com.intellij.util.containers.HashMap) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) HashSet(java.util.HashSet)

Example 35 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class ExtractSuperclassDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(RefactoringBundle.message("members.to.form.superclass"), myMemberInfos, RefactoringBundle.message("make.abstract"));
    panel.add(memberSelectionPanel, BorderLayout.CENTER);
    final MemberInfoModel<PsiMember, MemberInfo> memberInfoModel = new UsesAndInterfacesDependencyMemberInfoModel<PsiMember, MemberInfo>(mySourceClass, null, false, myContainmentVerifier) {

        @Override
        public Boolean isFixedAbstract(MemberInfo member) {
            return Boolean.TRUE;
        }
    };
    memberInfoModel.memberInfoChanged(new MemberInfoChange<>(myMemberInfos));
    memberSelectionPanel.getTable().setMemberInfoModel(memberInfoModel);
    memberSelectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel);
    panel.add(myDocCommentPanel, BorderLayout.EAST);
    return panel;
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) MemberSelectionPanel(com.intellij.refactoring.ui.MemberSelectionPanel) UsesAndInterfacesDependencyMemberInfoModel(com.intellij.refactoring.util.classMembers.UsesAndInterfacesDependencyMemberInfoModel) PsiMember(com.intellij.psi.PsiMember)

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