Search in sources :

Example 36 with HashMap

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

the class GenericInlineHandler method initializeInliners.

public static Map<Language, InlineHandler.Inliner> initializeInliners(PsiElement element, InlineHandler.Settings settings, Collection<? extends PsiReference> allReferences) {
    final Map<Language, InlineHandler.Inliner> inliners = new HashMap<>();
    for (PsiReference ref : allReferences) {
        if (ref == null) {
            LOG.error("element: " + element.getClass() + ", allReferences contains null!");
            continue;
        }
        PsiElement refElement = ref.getElement();
        LOG.assertTrue(refElement != null, ref.getClass().getName());
        final Language language = refElement.getLanguage();
        if (inliners.containsKey(language))
            continue;
        final List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(language);
        for (InlineHandler handler : handlers) {
            InlineHandler.Inliner inliner = handler.createInliner(element, settings);
            if (inliner != null) {
                inliners.put(language, inliner);
                break;
            }
        }
    }
    return inliners;
}
Also used : Language(com.intellij.lang.Language) HashMap(com.intellij.util.containers.HashMap) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) InlineHandler(com.intellij.lang.refactoring.InlineHandler)

Example 37 with HashMap

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

the class ColorSettingsUtil method keyToDisplayTextMap.

public static Map<TextAttributesKey, String> keyToDisplayTextMap(final ColorSettingsPage page) {
    final List<AttributesDescriptor> attributeDescriptors = getAllAttributeDescriptors(page);
    final Map<TextAttributesKey, String> displayText = new HashMap<>();
    for (AttributesDescriptor attributeDescriptor : attributeDescriptors) {
        final TextAttributesKey key = attributeDescriptor.getKey();
        displayText.put(key, attributeDescriptor.getDisplayName());
    }
    return displayText;
}
Also used : AttributesDescriptor(com.intellij.openapi.options.colors.AttributesDescriptor) HashMap(com.intellij.util.containers.HashMap) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Example 38 with HashMap

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

the class GlobalInspectionContextImpl method exportResults.

private void exportResults(@NotNull List<File> inspectionsResults, @Nullable String outputPath) {
    @NonNls final String ext = ".xml";
    final Map<Element, Tools> globalTools = new HashMap<>();
    for (Map.Entry<String, Tools> entry : getTools().entrySet()) {
        final Tools sameTools = entry.getValue();
        boolean hasProblems = false;
        String toolName = entry.getKey();
        if (sameTools != null) {
            for (ScopeToolState toolDescr : sameTools.getTools()) {
                InspectionToolWrapper toolWrapper = toolDescr.getTool();
                if (toolWrapper instanceof LocalInspectionToolWrapper) {
                    hasProblems = new File(outputPath, toolName + ext).exists();
                } else {
                    InspectionToolPresentation presentation = getPresentation(toolWrapper);
                    presentation.updateContent();
                    if (presentation.hasReportedProblems()) {
                        final Element root = new Element(InspectionsBundle.message("inspection.problems"));
                        globalTools.put(root, sameTools);
                        LOG.assertTrue(!hasProblems, toolName);
                        break;
                    }
                }
            }
        }
        if (hasProblems) {
            try {
                new File(outputPath).mkdirs();
                final File file = new File(outputPath, toolName + ext);
                inspectionsResults.add(file);
                FileUtil.writeToFile(file, ("</" + InspectionsBundle.message("inspection.problems") + ">").getBytes(CharsetToolkit.UTF8_CHARSET), true);
            } catch (IOException e) {
                LOG.error(e);
            }
        }
    }
    getRefManager().iterate(new RefVisitor() {

        @Override
        public void visitElement(@NotNull final RefEntity refEntity) {
            for (Map.Entry<Element, Tools> entry : globalTools.entrySet()) {
                Tools tools = entry.getValue();
                Element element = entry.getKey();
                for (ScopeToolState state : tools.getTools()) {
                    try {
                        InspectionToolWrapper toolWrapper = state.getTool();
                        InspectionToolPresentation presentation = getPresentation(toolWrapper);
                        presentation.exportResults(element, refEntity, d -> false);
                    } catch (Throwable e) {
                        LOG.error("Problem when exporting: " + refEntity.getExternalName(), e);
                    }
                }
            }
        }
    });
    for (Map.Entry<Element, Tools> entry : globalTools.entrySet()) {
        final String toolName = entry.getValue().getShortName();
        Element element = entry.getKey();
        element.setAttribute(LOCAL_TOOL_ATTRIBUTE, Boolean.toString(false));
        final org.jdom.Document doc = new org.jdom.Document(element);
        PathMacroManager.getInstance(getProject()).collapsePaths(doc.getRootElement());
        try {
            new File(outputPath).mkdirs();
            final File file = new File(outputPath, toolName + ext);
            inspectionsResults.add(file);
            try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), CharsetToolkit.UTF8_CHARSET)) {
                JDOMUtil.writeDocument(doc, writer, "\n");
            }
        } catch (IOException e) {
            LOG.error(e);
        }
    }
}
Also used : DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) com.intellij.openapi.util(com.intellij.openapi.util) UIUtil(com.intellij.util.ui.UIUtil) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) MessageType(com.intellij.openapi.ui.MessageType) ToggleAction(com.intellij.openapi.actionSystem.ToggleAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) Document(com.intellij.openapi.editor.Document) HashSet(com.intellij.util.containers.HashSet) DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) THashSet(gnu.trove.THashSet) TripleFunction(com.intellij.util.TripleFunction) com.intellij.openapi.application(com.intellij.openapi.application) ProjectUtilCore(com.intellij.openapi.project.ProjectUtilCore) ProblemHighlightFilter(com.intellij.codeInsight.daemon.ProblemHighlightFilter) FileIndex(com.intellij.openapi.roots.FileIndex) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) FileModificationService(com.intellij.codeInsight.FileModificationService) com.intellij.openapi.progress(com.intellij.openapi.progress) RefElement(com.intellij.codeInspection.reference.RefElement) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PathMacroManager(com.intellij.openapi.components.PathMacroManager) java.util.concurrent(java.util.concurrent) InspectionResultsView(com.intellij.codeInspection.ui.InspectionResultsView) ProjectUtil(com.intellij.openapi.project.ProjectUtil) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) Stream(java.util.stream.Stream) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) JobLauncherImpl(com.intellij.concurrency.JobLauncherImpl) com.intellij.ui.content(com.intellij.ui.content) java.util(java.util) LocalInspectionsPass(com.intellij.codeInsight.daemon.impl.LocalInspectionsPass) CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) CleanupInspectionIntention(com.intellij.codeInspection.actions.CleanupInspectionIntention) PerformAnalysisInBackgroundOption(com.intellij.analysis.PerformAnalysisInBackgroundOption) JobLauncher(com.intellij.concurrency.JobLauncher) GlobalInspectionContextExtension(com.intellij.codeInspection.lang.GlobalInspectionContextExtension) SensitiveProgressWrapper(com.intellij.concurrency.SensitiveProgressWrapper) NonNls(org.jetbrains.annotations.NonNls) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) SearchScope(com.intellij.psi.search.SearchScope) ContainerUtil(com.intellij.util.containers.ContainerUtil) Constructor(java.lang.reflect.Constructor) ThreadDumper(com.intellij.diagnostic.ThreadDumper) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) CoreProgressManager(com.intellij.openapi.progress.impl.CoreProgressManager) ProblemGroup(com.intellij.lang.annotation.ProblemGroup) NotificationGroup(com.intellij.notification.NotificationGroup) ToolWindowId(com.intellij.openapi.wm.ToolWindowId) Project(com.intellij.openapi.project.Project) OutputStreamWriter(java.io.OutputStreamWriter) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) HighlightInfoProcessor(com.intellij.codeInsight.daemon.impl.HighlightInfoProcessor) AnalysisScope(com.intellij.analysis.AnalysisScope) FileOutputStream(java.io.FileOutputStream) ConcurrencyUtil(com.intellij.util.ConcurrencyUtil) IOException(java.io.IOException) com.intellij.codeInspection(com.intellij.codeInspection) AnalysisUIOptions(com.intellij.analysis.AnalysisUIOptions) GuiUtils(com.intellij.ui.GuiUtils) InspectionTreeState(com.intellij.codeInspection.ui.InspectionTreeState) Disposable(com.intellij.openapi.Disposable) File(java.io.File) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) Element(org.jdom.Element) RefEntity(com.intellij.codeInspection.reference.RefEntity) HashMap(com.intellij.util.containers.HashMap) RefElement(com.intellij.codeInspection.reference.RefElement) Element(org.jdom.Element) Document(com.intellij.openapi.editor.Document) NonNls(org.jetbrains.annotations.NonNls) IOException(java.io.IOException) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) RefEntity(com.intellij.codeInspection.reference.RefEntity) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) HashMap(com.intellij.util.containers.HashMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 39 with HashMap

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

the class TurnRefsToSuperProcessorBase method performVariablesRenaming.

protected void performVariablesRenaming() {
    try {
        //forget about smart pointers
        Map<PsiElement, String> variableRenames = new HashMap<>();
        for (Map.Entry<SmartPsiElementPointer, String> entry : myVariablesRenames.entrySet()) {
            variableRenames.put(entry.getKey().getElement(), entry.getValue());
        }
        for (UsageInfo usage : myVariablesUsages) {
            if (usage instanceof MoveRenameUsageInfo) {
                final MoveRenameUsageInfo renameUsageInfo = ((MoveRenameUsageInfo) usage);
                final String newName = variableRenames.get(renameUsageInfo.getUpToDateReferencedElement());
                final PsiReference reference = renameUsageInfo.getReference();
                if (reference != null) {
                    reference.handleElementRename(newName);
                }
            }
        }
        for (Map.Entry<SmartPsiElementPointer, String> entry : myVariablesRenames.entrySet()) {
            final String newName = entry.getValue();
            if (newName != null) {
                final PsiVariable variable = (PsiVariable) entry.getKey().getElement();
                variable.setName(newName);
            }
        }
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
Also used : HashMap(com.intellij.util.containers.HashMap) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) IncorrectOperationException(com.intellij.util.IncorrectOperationException) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) UsageInfo(com.intellij.usageView.UsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo)

Example 40 with HashMap

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

the class RefactoringUtil method fixJavadocsForParams.

public static void fixJavadocsForParams(PsiMethod method, Set<PsiParameter> newParameters, Condition<Pair<PsiParameter, String>> eqCondition, Condition<String> matchedToOldParam) throws IncorrectOperationException {
    final PsiDocComment docComment = method.getDocComment();
    if (docComment == null)
        return;
    final PsiParameter[] parameters = method.getParameterList().getParameters();
    final PsiDocTag[] paramTags = docComment.findTagsByName("param");
    if (parameters.length > 0 && newParameters.size() < parameters.length && paramTags.length == 0)
        return;
    Map<PsiParameter, PsiDocTag> tagForParam = new HashMap<>();
    for (PsiParameter parameter : parameters) {
        boolean found = false;
        for (PsiDocTag paramTag : paramTags) {
            if (parameter.getName().equals(getNameOfReferencedParameter(paramTag))) {
                tagForParam.put(parameter, paramTag);
                found = true;
                break;
            }
        }
        if (!found) {
            for (PsiDocTag paramTag : paramTags) {
                final String paramName = getNameOfReferencedParameter(paramTag);
                if (eqCondition.value(Pair.create(parameter, paramName))) {
                    tagForParam.put(parameter, paramTag);
                    found = true;
                    break;
                }
            }
        }
        if (!found && !newParameters.contains(parameter)) {
            tagForParam.put(parameter, null);
        }
    }
    List<PsiDocTag> newTags = new ArrayList<>();
    for (PsiDocTag paramTag : paramTags) {
        final String paramName = getNameOfReferencedParameter(paramTag);
        if (!tagForParam.containsValue(paramTag) && !matchedToOldParam.value(paramName)) {
            newTags.add((PsiDocTag) paramTag.copy());
        }
    }
    for (PsiParameter parameter : parameters) {
        if (tagForParam.containsKey(parameter)) {
            final PsiDocTag psiDocTag = tagForParam.get(parameter);
            if (psiDocTag != null) {
                final PsiDocTag copy = (PsiDocTag) psiDocTag.copy();
                final PsiDocTagValue valueElement = copy.getValueElement();
                if (valueElement != null) {
                    valueElement.replace(createParamTag(parameter).getValueElement());
                }
                newTags.add(copy);
            }
        } else {
            newTags.add(createParamTag(parameter));
        }
    }
    PsiElement anchor = paramTags.length > 0 ? paramTags[0].getPrevSibling() : null;
    for (PsiDocTag paramTag : paramTags) {
        paramTag.delete();
    }
    for (PsiDocTag psiDocTag : newTags) {
        anchor = anchor != null && anchor.isValid() ? docComment.addAfter(psiDocTag, anchor) : docComment.add(psiDocTag);
    }
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiDocTag(com.intellij.psi.javadoc.PsiDocTag) HashMap(com.intellij.util.containers.HashMap) THashMap(gnu.trove.THashMap) PsiDocTagValue(com.intellij.psi.javadoc.PsiDocTagValue)

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