Search in sources :

Example 16 with HashMap

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

the class CoverageSuiteChooserDialog method initTree.

private void initTree() {
    myRootNode.removeAllChildren();
    final HashMap<CoverageRunner, Map<String, List<CoverageSuite>>> grouped = new HashMap<>();
    groupSuites(grouped, myCoverageManager.getSuites(), myEngine);
    final CoverageSuitesBundle currentSuite = myCoverageManager.getCurrentSuitesBundle();
    final List<CoverageRunner> runners = new ArrayList<>(grouped.keySet());
    Collections.sort(runners, (o1, o2) -> o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName()));
    for (CoverageRunner runner : runners) {
        final DefaultMutableTreeNode runnerNode = new DefaultMutableTreeNode(getCoverageRunnerTitle(runner));
        final Map<String, List<CoverageSuite>> providers = grouped.get(runner);
        final DefaultMutableTreeNode remoteNode = new DefaultMutableTreeNode("Remote");
        if (providers.size() == 1) {
            final String providersKey = providers.keySet().iterator().next();
            DefaultMutableTreeNode suitesNode = runnerNode;
            if (!Comparing.strEqual(providersKey, DefaultCoverageFileProvider.class.getName())) {
                suitesNode = remoteNode;
                runnerNode.add(remoteNode);
            }
            final List<CoverageSuite> suites = providers.get(providersKey);
            Collections.sort(suites, (o1, o2) -> o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName()));
            for (CoverageSuite suite : suites) {
                final CheckedTreeNode treeNode = new CheckedTreeNode(suite);
                treeNode.setChecked(currentSuite != null && currentSuite.contains(suite) ? Boolean.TRUE : Boolean.FALSE);
                suitesNode.add(treeNode);
            }
        } else {
            final DefaultMutableTreeNode localNode = new DefaultMutableTreeNode(LOCAL);
            runnerNode.add(localNode);
            runnerNode.add(remoteNode);
            for (String aClass : providers.keySet()) {
                DefaultMutableTreeNode node = Comparing.strEqual(aClass, DefaultCoverageFileProvider.class.getName()) ? localNode : remoteNode;
                for (CoverageSuite suite : providers.get(aClass)) {
                    final CheckedTreeNode treeNode = new CheckedTreeNode(suite);
                    treeNode.setChecked(currentSuite != null && currentSuite.contains(suite) ? Boolean.TRUE : Boolean.FALSE);
                    node.add(treeNode);
                }
            }
        }
        myRootNode.add(runnerNode);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) HashMap(com.intellij.util.containers.HashMap) List(java.util.List) HashMap(com.intellij.util.containers.HashMap)

Example 17 with HashMap

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

the class RTagOperation method createOn.

public static RTagOperation[] createOn(FilePath[] files, String tagName, boolean overrideExisting) {
    Map<CvsEnvironment, List<File>> envToFiles = new HashMap<>();
    for (FilePath file : files) {
        CvsConnectionSettings cvsConnectionSettings = CvsUtil.getCvsConnectionSettings(file);
        if (!envToFiles.containsKey(cvsConnectionSettings))
            envToFiles.put(cvsConnectionSettings, new ArrayList<>());
        envToFiles.get(cvsConnectionSettings).add(file.getIOFile());
    }
    ArrayList<RTagOperation> result = new ArrayList<>();
    for (CvsEnvironment cvsEnvironment : envToFiles.keySet()) {
        RTagOperation rTagOperation = new RTagOperation(cvsEnvironment, tagName, overrideExisting);
        result.add(rTagOperation);
        List<File> iofiles = envToFiles.get(cvsEnvironment);
        for (File file : iofiles) {
            rTagOperation.addFile(file);
        }
    }
    return result.toArray(new RTagOperation[result.size()]);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) HashMap(com.intellij.util.containers.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CvsEnvironment(com.intellij.cvsSupport2.connections.CvsEnvironment) CvsConnectionSettings(com.intellij.cvsSupport2.connections.CvsConnectionSettings) File(java.io.File)

Example 18 with HashMap

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

the class GenerateEqualsHelper method createEquals.

private PsiMethod createEquals() throws IncorrectOperationException {
    @NonNls StringBuilder buffer = new StringBuilder();
    CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(myProject);
    ArrayList<PsiField> equalsFields = new ArrayList<>();
    ContainerUtil.addAll(equalsFields, myEqualsFields);
    Collections.sort(equalsFields, EqualsFieldsComparator.INSTANCE);
    final HashMap<String, Object> contextMap = new HashMap<>();
    final PsiType classType = JavaPsiFacade.getElementFactory(myClass.getProject()).createType(myClass);
    final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(myClass.getProject());
    String[] nameSuggestions = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, classType).names;
    String instanceBaseName = nameSuggestions.length > 0 && nameSuggestions[0].length() < 10 ? nameSuggestions[0] : "that";
    contextMap.put(INSTANCE_NAME, instanceBaseName);
    final PsiType objectType = PsiType.getJavaLangObject(myClass.getManager(), myClass.getResolveScope());
    nameSuggestions = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, null, null, objectType).names;
    final String objectBaseName = nameSuggestions.length > 0 ? nameSuggestions[0] : "object";
    contextMap.put(BASE_PARAM_NAME, objectBaseName);
    final MethodSignature equalsSignature = getEqualsSignature(myProject, myClass.getResolveScope());
    PsiMethod superEquals = MethodSignatureUtil.findMethodBySignature(myClass, equalsSignature, true);
    if (superEquals != null) {
        contextMap.put(SUPER_PARAM_NAME, superEquals.getParameterList().getParameters()[0].getName());
    }
    contextMap.put(SUPER_HAS_EQUALS, superMethodExists(equalsSignature));
    contextMap.put(CHECK_PARAMETER_WITH_INSTANCEOF, myCheckParameterWithInstanceof);
    final String methodText = GenerationUtil.velocityGenerateCode(myClass, equalsFields, myNonNullSet, new HashMap<>(), contextMap, EqualsHashCodeTemplatesManager.getInstance().getDefaultEqualsTemplate().getTemplate(), 0, false, myUseAccessors);
    buffer.append(methodText);
    PsiMethod result;
    try {
        result = myFactory.createMethodFromText(buffer.toString(), myClass);
    } catch (IncorrectOperationException e) {
        return null;
    }
    final PsiParameter[] parameters = result.getParameterList().getParameters();
    if (parameters.length != 1)
        return null;
    final PsiParameter parameter = parameters[0];
    PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, styleSettings.GENERATE_FINAL_PARAMETERS);
    PsiMethod method = (PsiMethod) myCodeStyleManager.reformat(result);
    if (superEquals != null) {
        OverrideImplementUtil.annotateOnOverrideImplement(method, myClass, superEquals);
    }
    method = (PsiMethod) myJavaCodeStyleManager.shortenClassReferences(method);
    return method;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) MethodSignature(com.intellij.psi.util.MethodSignature) HashMap(com.intellij.util.containers.HashMap) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 19 with HashMap

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

the class InheritanceToDelegationProcessor method analyzeConflicts.

private void analyzeConflicts(UsageInfo[] usage, MultiMap<PsiElement, String> conflicts) {
    HashMap<PsiElement, HashSet<PsiElement>> reportedNonDelegatedUsages = new HashMap<>();
    HashMap<PsiClass, HashSet<PsiElement>> reportedUpcasts = new HashMap<>();
    //    HashSet reportedObjectUpcasts = new HashSet();
    //    final String nameJavaLangObject = ConflictsUtil.htmlEmphasize("java.lang.Object");
    final String classDescription = RefactoringUIUtil.getDescription(myClass, false);
    for (UsageInfo aUsage : usage) {
        final PsiElement element = aUsage.getElement();
        if (aUsage instanceof InheritanceToDelegationUsageInfo) {
            InheritanceToDelegationUsageInfo usageInfo = (InheritanceToDelegationUsageInfo) aUsage;
            /*if (usageInfo instanceof ObjectUpcastedUsageInfo) {
         PsiElement container = ConflictsUtil.getContainer(usageInfo.element);
         if (!reportedObjectUpcasts.contains(container)) {
           String message = "An instance of " + classDescription + " is upcasted to "
                   + nameJavaLangObject + " in " + ConflictsUtil.getDescription(container, true) + ".";
           conflicts.add(message);
           reportedObjectUpcasts.add(container);
         }
       } else*/
            if (!myIsDelegateOtherMembers && !usageInfo.getDelegateFieldAccessible().isAccessible()) {
                if (usageInfo instanceof NonDelegatedMemberUsageInfo) {
                    final PsiElement nonDelegatedMember = ((NonDelegatedMemberUsageInfo) usageInfo).nonDelegatedMember;
                    HashSet<PsiElement> reportedContainers = reportedNonDelegatedUsages.get(nonDelegatedMember);
                    if (reportedContainers == null) {
                        reportedContainers = new HashSet<>();
                        reportedNonDelegatedUsages.put(nonDelegatedMember, reportedContainers);
                    }
                    final PsiElement container = ConflictsUtil.getContainer(element);
                    if (!reportedContainers.contains(container)) {
                        String message = RefactoringBundle.message("0.uses.1.of.an.instance.of.a.2", RefactoringUIUtil.getDescription(container, true), RefactoringUIUtil.getDescription(nonDelegatedMember, true), classDescription);
                        conflicts.putValue(container, CommonRefactoringUtil.capitalize(message));
                        reportedContainers.add(container);
                    }
                } else if (usageInfo instanceof UpcastedUsageInfo) {
                    final PsiClass upcastedTo = ((UpcastedUsageInfo) usageInfo).upcastedTo;
                    HashSet<PsiElement> reportedContainers = reportedUpcasts.get(upcastedTo);
                    if (reportedContainers == null) {
                        reportedContainers = new HashSet<>();
                        reportedUpcasts.put(upcastedTo, reportedContainers);
                    }
                    final PsiElement container = ConflictsUtil.getContainer(element);
                    if (!reportedContainers.contains(container)) {
                        String message = RefactoringBundle.message("0.upcasts.an.instance.of.1.to.2", RefactoringUIUtil.getDescription(container, true), classDescription, RefactoringUIUtil.getDescription(upcastedTo, false));
                        conflicts.putValue(container, CommonRefactoringUtil.capitalize(message));
                        reportedContainers.add(container);
                    }
                }
            }
        } else if (aUsage instanceof NoLongerOverridingSubClassMethodUsageInfo) {
            NoLongerOverridingSubClassMethodUsageInfo info = (NoLongerOverridingSubClassMethodUsageInfo) aUsage;
            String message = RefactoringBundle.message("0.will.no.longer.override.1", RefactoringUIUtil.getDescription(info.getSubClassMethod(), true), RefactoringUIUtil.getDescription(info.getOverridenMethod(), true));
            conflicts.putValue(info.getSubClassMethod(), message);
        }
    }
}
Also used : HashMap(com.intellij.util.containers.HashMap) UsageInfo(com.intellij.usageView.UsageInfo)

Example 20 with HashMap

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

the class InlineMethodProcessor method getInaccessible.

/**
   * Given a set of referencedElements, returns a map from containers (in a sense of ConflictsUtil.getContainer)
   * to subsets of referencedElemens that are not accessible from that container
   *
   * @param referencedElements
   * @param usages
   * @param elementToInline
   */
private static Map<PsiMember, Set<PsiMember>> getInaccessible(HashSet<PsiMember> referencedElements, UsageInfo[] usages, PsiElement elementToInline) {
    final Map<PsiMember, Set<PsiMember>> result = new HashMap<>();
    final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(elementToInline.getProject()).getResolveHelper();
    for (UsageInfo usage : usages) {
        final PsiElement usageElement = usage.getElement();
        if (usageElement == null)
            continue;
        final PsiElement container = ConflictsUtil.getContainer(usageElement);
        // usage in import statement
        if (!(container instanceof PsiMember))
            continue;
        PsiMember memberContainer = (PsiMember) container;
        Set<PsiMember> inaccessibleReferenced = result.get(memberContainer);
        if (inaccessibleReferenced == null) {
            inaccessibleReferenced = new HashSet<>();
            result.put(memberContainer, inaccessibleReferenced);
            for (PsiMember member : referencedElements) {
                if (PsiTreeUtil.isAncestor(elementToInline, member, false))
                    continue;
                if (elementToInline instanceof PsiClass && InheritanceUtil.isInheritorOrSelf((PsiClass) elementToInline, member.getContainingClass(), true))
                    continue;
                PsiElement resolveScope = usageElement instanceof PsiReferenceExpression ? ((PsiReferenceExpression) usageElement).advancedResolve(false).getCurrentFileResolveScope() : null;
                if (!resolveHelper.isAccessible(member, member.getModifierList(), usageElement, null, resolveScope)) {
                    inaccessibleReferenced.add(member);
                }
            }
        }
    }
    return result;
}
Also used : HashMap(com.intellij.util.containers.HashMap) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

HashMap (com.intellij.util.containers.HashMap)118 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 File (java.io.File)22 Nullable (org.jetbrains.annotations.Nullable)18 Map (java.util.Map)17 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)15 ArrayList (java.util.ArrayList)14 PsiElement (com.intellij.psi.PsiElement)11 HashSet (com.intellij.util.containers.HashSet)10 List (java.util.List)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 IOException (java.io.IOException)8 Pair (com.intellij.openapi.util.Pair)6 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)6 SearchScope (com.intellij.psi.search.SearchScope)6 Logger (com.intellij.openapi.diagnostic.Logger)5 PsiFile (com.intellij.psi.PsiFile)5 UsageInfo (com.intellij.usageView.UsageInfo)5