Search in sources :

Example 26 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class BuildIcons method main.

public static void main(String[] args) throws Exception {
    File root = new File("/Users/max/IDEA/out/classes/production/");
    final MultiMap<Couple<Integer>, String> dimToPath = new MultiMap<>();
    walk(root, dimToPath, root);
    ArrayList<Couple<Integer>> keys = new ArrayList<>(dimToPath.keySet());
    Collections.sort(keys, (o1, o2) -> {
        int d0 = dimToPath.get(o2).size() - dimToPath.get(o1).size();
        if (d0 != 0)
            return d0;
        int d1 = o1.first - o2.first;
        if (d1 != 0) {
            return d1;
        }
        return o1.second - o2.second;
    });
    int total = 0;
    for (Couple<Integer> key : keys) {
        Collection<String> paths = dimToPath.get(key);
        System.out.println("------------------------   " + key.first + "x" + key.second + "  (total " + paths.size() + " icons) --------------------------------");
        for (String path : paths) {
            System.out.println(path);
            total++;
        }
        System.out.println("");
    }
    System.out.println("Total icons: " + total);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) Couple(com.intellij.openapi.util.Couple) File(java.io.File)

Example 27 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class InputValidator method isOK.

public boolean isOK(IntroduceVariableSettings settings) {
    String name = settings.getEnteredName();
    final PsiElement anchor;
    final boolean replaceAllOccurrences = settings.isReplaceAllOccurrences();
    if (replaceAllOccurrences) {
        anchor = myAnchorStatementIfAll;
    } else {
        anchor = myAnchorStatement;
    }
    final PsiElement scope = anchor.getParent();
    if (scope == null)
        return true;
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final HashSet<PsiVariable> reportedVariables = new HashSet<>();
    JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor visitor = new JavaUnresolvableLocalCollisionDetector.CollidingVariableVisitor() {

        public void visitCollidingElement(PsiVariable collidingVariable) {
            if (!reportedVariables.contains(collidingVariable)) {
                reportedVariables.add(collidingVariable);
                String message = RefactoringBundle.message("introduced.variable.will.conflict.with.0", RefactoringUIUtil.getDescription(collidingVariable, true));
                conflicts.putValue(collidingVariable, message);
            }
        }
    };
    JavaUnresolvableLocalCollisionDetector.visitLocalsCollisions(anchor, name, scope, anchor, visitor);
    if (replaceAllOccurrences) {
        final PsiExpression[] occurences = myOccurenceManager.getOccurrences();
        for (PsiExpression occurence : occurences) {
            IntroduceVariableBase.checkInLoopCondition(occurence, conflicts);
        }
    } else {
        IntroduceVariableBase.checkInLoopCondition(myOccurenceManager.getMainOccurence(), conflicts);
    }
    if (conflicts.size() > 0) {
        return myIntroduceVariableBase.reportConflicts(conflicts, myProject, settings);
    } else {
        return true;
    }
}
Also used : JavaUnresolvableLocalCollisionDetector(com.intellij.refactoring.rename.JavaUnresolvableLocalCollisionDetector) PsiVariable(com.intellij.psi.PsiVariable) PsiExpression(com.intellij.psi.PsiExpression) MultiMap(com.intellij.util.containers.MultiMap) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet)

Example 28 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class IntroduceParameterProcessor method preprocessUsages.

protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    UsageInfo[] usagesIn = refUsages.get();
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    AnySameNameVariables anySameNameVariables = new AnySameNameVariables();
    myMethodToReplaceIn.accept(anySameNameVariables);
    final Pair<PsiElement, String> conflictPair = anySameNameVariables.getConflict();
    if (conflictPair != null) {
        conflicts.putValue(conflictPair.first, conflictPair.second);
    }
    if (!myGenerateDelegate) {
        detectAccessibilityConflicts(usagesIn, conflicts);
    }
    if (myParameterInitializer != null && !myMethodToReplaceIn.hasModifierProperty(PsiModifier.PRIVATE)) {
        final AnySupers anySupers = new AnySupers();
        myParameterInitializer.accept(anySupers);
        if (anySupers.isResult()) {
            for (UsageInfo usageInfo : usagesIn) {
                if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
                    if (!PsiTreeUtil.isAncestor(myMethodToReplaceIn.getContainingClass(), usageInfo.getElement(), false)) {
                        String message = RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class", CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER));
                        conflicts.putValue(myParameterInitializer, message);
                        break;
                    }
                }
            }
        }
    }
    for (IntroduceParameterMethodUsagesProcessor processor : IntroduceParameterMethodUsagesProcessor.EP_NAME.getExtensions()) {
        processor.findConflicts(this, refUsages.get(), conflicts);
    }
    myHasConflicts = !conflicts.isEmpty();
    return showConflicts(conflicts, usagesIn);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) UsageInfo(com.intellij.usageView.UsageInfo) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)

Example 29 with MultiMap

use of com.intellij.util.containers.MultiMap 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;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog)

Example 30 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class PullUpConflictsUtil method checkConflicts.

public static MultiMap<PsiElement, String> checkConflicts(final MemberInfoBase<? extends PsiMember>[] infos, @NotNull final PsiClass subclass, @Nullable PsiClass superClass, @NotNull final PsiPackage targetPackage, @NotNull PsiDirectory targetDirectory, final InterfaceContainmentVerifier interfaceContainmentVerifier, boolean movedMembers2Super) {
    final Set<PsiMember> movedMembers = new HashSet<>();
    final Set<PsiMethod> abstractMethods = new HashSet<>();
    final boolean isInterfaceTarget;
    final PsiElement targetRepresentativeElement;
    if (superClass != null) {
        isInterfaceTarget = superClass.isInterface();
        targetRepresentativeElement = superClass;
    } else {
        isInterfaceTarget = false;
        targetRepresentativeElement = targetDirectory;
    }
    for (MemberInfoBase<? extends PsiMember> info : infos) {
        PsiMember member = info.getMember();
        if (member instanceof PsiMethod) {
            if (!info.isToAbstract()) {
                movedMembers.add(member);
            } else {
                abstractMethods.add((PsiMethod) member);
            }
        } else {
            movedMembers.add(member);
        }
    }
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final Set<PsiMethod> abstrMethods = new HashSet<>(abstractMethods);
    if (superClass != null) {
        for (PsiMethod method : subclass.getMethods()) {
            if (!movedMembers.contains(method) && !method.hasModifierProperty(PsiModifier.PRIVATE)) {
                if (method.findSuperMethods(superClass).length > 0) {
                    abstrMethods.add(method);
                }
            }
        }
        if (newAbstractMethodInSuper(infos)) {
            final PsiAnnotation annotation = AnnotationUtil.findAnnotation(superClass, CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE);
            if (annotation != null) {
                conflicts.putValue(annotation, RefactoringBundle.message("functional.interface.broken"));
            } else {
                final PsiFunctionalExpression functionalExpression = FunctionalExpressionSearch.search(superClass).findFirst();
                if (functionalExpression != null) {
                    conflicts.putValue(functionalExpression, RefactoringBundle.message("functional.interface.broken"));
                }
            }
        }
    }
    RefactoringConflictsUtil.analyzeAccessibilityConflicts(movedMembers, superClass, conflicts, VisibilityUtil.ESCALATE_VISIBILITY, targetRepresentativeElement, abstrMethods);
    if (superClass != null) {
        if (movedMembers2Super) {
            checkSuperclassMembers(superClass, infos, conflicts);
            if (isInterfaceTarget) {
                checkInterfaceTarget(infos, conflicts);
            }
        } else {
            final String qualifiedName = superClass.getQualifiedName();
            assert qualifiedName != null;
            if (superClass.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
                if (!Comparing.strEqual(StringUtil.getPackageName(qualifiedName), targetPackage.getQualifiedName())) {
                    conflicts.putValue(superClass, RefactoringUIUtil.getDescription(superClass, true) + " won't be accessible from " + RefactoringUIUtil.getDescription(targetPackage, true));
                }
            }
        }
    }
    // check if moved methods use other members in the classes between Subclass and Superclass
    List<PsiElement> checkModuleConflictsList = new ArrayList<>();
    for (PsiMember member : movedMembers) {
        if (member instanceof PsiMethod || member instanceof PsiClass && !(member instanceof PsiCompiledElement)) {
            ClassMemberReferencesVisitor visitor = movedMembers2Super ? new ConflictingUsagesOfSubClassMembers(member, movedMembers, abstractMethods, subclass, superClass, superClass != null ? null : targetPackage, conflicts, interfaceContainmentVerifier) : new ConflictingUsagesOfSuperClassMembers(member, subclass, targetPackage, movedMembers, conflicts);
            member.accept(visitor);
        }
        ContainerUtil.addIfNotNull(checkModuleConflictsList, member);
    }
    for (final PsiMethod method : abstractMethods) {
        ContainerUtil.addIfNotNull(checkModuleConflictsList, method.getParameterList());
        ContainerUtil.addIfNotNull(checkModuleConflictsList, method.getReturnTypeElement());
        ContainerUtil.addIfNotNull(checkModuleConflictsList, method.getTypeParameterList());
    }
    RefactoringConflictsUtil.analyzeModuleConflicts(subclass.getProject(), checkModuleConflictsList, UsageInfo.EMPTY_ARRAY, targetDirectory, conflicts);
    final PsiFile psiFile = PsiTreeUtil.getParentOfType(subclass, PsiClassOwner.class);
    final boolean toDifferentPackage = !Comparing.strEqual(targetPackage.getQualifiedName(), psiFile != null ? ((PsiClassOwner) psiFile).getPackageName() : null);
    for (final PsiMethod abstractMethod : abstractMethods) {
        abstractMethod.accept(new ClassMemberReferencesVisitor(subclass) {

            @Override
            protected void visitClassMemberReferenceElement(PsiMember classMember, PsiJavaCodeReferenceElement classMemberReference) {
                if (classMember != null && willBeMoved(classMember, movedMembers)) {
                    boolean isAccessible = false;
                    if (classMember.hasModifierProperty(PsiModifier.PRIVATE)) {
                        isAccessible = true;
                    } else if (classMember.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) && toDifferentPackage) {
                        isAccessible = true;
                    }
                    if (isAccessible) {
                        String message = RefactoringUIUtil.getDescription(abstractMethod, false) + " uses " + RefactoringUIUtil.getDescription(classMember, true) + " which won't be accessible from the subclass.";
                        message = CommonRefactoringUtil.capitalize(message);
                        conflicts.putValue(classMember, message);
                    }
                }
            }
        });
        if (abstractMethod.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) && toDifferentPackage) {
            if (!isInterfaceTarget) {
                String message = "Can't make " + RefactoringUIUtil.getDescription(abstractMethod, false) + " abstract as it won't be accessible from the subclass.";
                message = CommonRefactoringUtil.capitalize(message);
                conflicts.putValue(abstractMethod, message);
            }
        }
    }
    return conflicts;
}
Also used : ArrayList(java.util.ArrayList) MultiMap(com.intellij.util.containers.MultiMap) ClassMemberReferencesVisitor(com.intellij.refactoring.util.classMembers.ClassMemberReferencesVisitor) HashSet(java.util.HashSet)

Aggregations

MultiMap (com.intellij.util.containers.MultiMap)141 NotNull (org.jetbrains.annotations.NotNull)38 UsageInfo (com.intellij.usageView.UsageInfo)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 Project (com.intellij.openapi.project.Project)19 PsiElement (com.intellij.psi.PsiElement)18 Collection (java.util.Collection)17 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)16 Nullable (org.jetbrains.annotations.Nullable)16 Map (java.util.Map)15 Module (com.intellij.openapi.module.Module)11 File (java.io.File)11 ArrayList (java.util.ArrayList)11 ContainerUtil (com.intellij.util.containers.ContainerUtil)10 HashSet (com.intellij.util.containers.HashSet)10 THashSet (gnu.trove.THashSet)9 java.util (java.util)9 Pair (com.intellij.openapi.util.Pair)8 com.intellij.psi (com.intellij.psi)8 HashSet (java.util.HashSet)8