Search in sources :

Example 1 with HashMap

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

the class RenameAliasedUsagesUtil method filterAliasedRefs.

public static Collection<PsiReference> filterAliasedRefs(Collection<PsiReference> refs, PsiElement element) {
    Map<GroovyFile, String> aliases = new HashMap<>();
    ArrayList<PsiReference> result = new ArrayList<>();
    for (PsiReference ref : refs) {
        final PsiElement e = ref.getElement();
        if (e == null)
            continue;
        if (skipReference(element, aliases, e))
            continue;
        result.add(ref);
    }
    return result;
}
Also used : HashMap(com.intellij.util.containers.hash.HashMap) ArrayList(java.util.ArrayList) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 2 with HashMap

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

the class SchemaDefinitionsSearch method execute.

@Override
public boolean execute(@NotNull final PsiElement queryParameters, @NotNull final Processor<PsiElement> consumer) {
    if (queryParameters instanceof XmlTagImpl) {
        final XmlTagImpl xml = (XmlTagImpl) queryParameters;
        if (ReadAction.compute(() -> isTypeElement(xml))) {
            final Collection<SchemaTypeInfo> infos = ApplicationManager.getApplication().runReadAction(new Computable<Collection<SchemaTypeInfo>>() {

                @Override
                public Collection<SchemaTypeInfo> compute() {
                    return gatherInheritors(xml);
                }
            });
            if (infos != null && !infos.isEmpty()) {
                final XmlFile file = XmlUtil.getContainingFile(xml);
                final Project project = file.getProject();
                final Module module = ModuleUtilCore.findModuleForPsiElement(queryParameters);
                //if (module == null) return false;
                final VirtualFile vf = file.getVirtualFile();
                String thisNs = ApplicationManager.getApplication().runReadAction(new Computable<String>() {

                    @Override
                    public String compute() {
                        return XmlNamespaceIndex.getNamespace(vf, project, file);
                    }
                });
                thisNs = thisNs == null ? getDefaultNs(file) : thisNs;
                // so thisNs can be null
                if (thisNs == null)
                    return false;
                final ArrayList<SchemaTypeInfo> infosLst = new ArrayList<>(infos);
                Collections.sort(infosLst);
                final Map<String, Set<XmlFile>> nsMap = new HashMap<>();
                for (final SchemaTypeInfo info : infosLst) {
                    Set<XmlFile> targetFiles = nsMap.get(info.getNamespaceUri());
                    if (targetFiles == null) {
                        targetFiles = new HashSet<>();
                        if (Comparing.equal(info.getNamespaceUri(), thisNs)) {
                            targetFiles.add(file);
                        }
                        final Collection<XmlFile> files = ApplicationManager.getApplication().runReadAction(new Computable<Collection<XmlFile>>() {

                            @Override
                            public Collection<XmlFile> compute() {
                                return XmlUtil.findNSFilesByURI(info.getNamespaceUri(), project, module);
                            }
                        });
                        if (files != null) {
                            targetFiles.addAll(files);
                        }
                        nsMap.put(info.getNamespaceUri(), targetFiles);
                    }
                    if (!targetFiles.isEmpty()) {
                        for (final XmlFile targetFile : targetFiles) {
                            ApplicationManager.getApplication().runReadAction(() -> {
                                final String prefixByURI = XmlUtil.findNamespacePrefixByURI(targetFile, info.getNamespaceUri());
                                if (prefixByURI == null)
                                    return;
                                final PsiElementProcessor processor = new PsiElementProcessor() {

                                    @Override
                                    public boolean execute(@NotNull PsiElement element) {
                                        if (element instanceof XmlTagImpl) {
                                            if (isCertainTypeElement((XmlTagImpl) element, info.getTagName(), prefixByURI) || isElementWithEmbeddedType((XmlTagImpl) element, info.getTagName(), prefixByURI)) {
                                                consumer.process(element);
                                                return false;
                                            }
                                        }
                                        return true;
                                    }
                                };
                                XmlUtil.processXmlElements(targetFile, processor, true);
                            });
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlTagImpl(com.intellij.psi.impl.source.xml.XmlTagImpl) HashSet(com.intellij.util.containers.hash.HashSet) XmlFile(com.intellij.psi.xml.XmlFile) HashMap(com.intellij.util.containers.hash.HashMap) NotNull(org.jetbrains.annotations.NotNull) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) Project(com.intellij.openapi.project.Project) SchemaTypeInfo(com.intellij.xml.index.SchemaTypeInfo) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 3 with HashMap

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

the class DeleteFromFavoritesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    Project project = e.getProject();
    FavoritesViewTreeBuilder builder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(dataContext);
    if (project == null || builder == null) {
        return;
    }
    Set<Object> selection = builder.getSelectedElements();
    if (selection.isEmpty()) {
        return;
    }
    FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
    String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
    FavoritesListProvider provider = favoritesManager.getListProvider(listName);
    if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.REMOVE, project, selection)) {
        provider.handle(CommonActionsPanel.Buttons.REMOVE, project, selection, builder.getTree());
        return;
    }
    FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
    final DnDAwareTree tree = FavoritesTreeViewPanel.FAVORITES_TREE_KEY.getData(dataContext);
    assert roots != null && tree != null;
    Map<String, List<AbstractTreeNode>> toRemove = new HashMap<>();
    for (FavoritesTreeNodeDescriptor root : roots) {
        final AbstractTreeNode node = root.getElement();
        if (node instanceof FavoritesListNode) {
            favoritesManager.removeFavoritesList((String) node.getValue());
        } else {
            final FavoritesListNode listNode = FavoritesTreeUtil.extractParentList(root);
            LOG.assertTrue(listNode != null);
            final String name = listNode.getName();
            if (!toRemove.containsKey(name)) {
                toRemove.put(name, new ArrayList<>());
            }
            toRemove.get(name).add(node);
        }
    }
    for (String name : toRemove.keySet()) {
        favoritesManager.removeRoot(name, toRemove.get(name));
    }
}
Also used : HashMap(com.intellij.util.containers.hash.HashMap) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ArrayList(java.util.ArrayList) List(java.util.List) DnDAwareTree(com.intellij.ide.dnd.aware.DnDAwareTree)

Example 4 with HashMap

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

the class ExternalDiffToolUtil method executeMerge.

public static void executeMerge(@Nullable Project project, @NotNull ExternalDiffSettings settings, @NotNull ThreesideMergeRequest request) throws IOException, ExecutionException {
    boolean success = false;
    OutputFile outputFile = null;
    List<InputFile> inputFiles = new ArrayList<>();
    try {
        DiffContent outputContent = request.getOutputContent();
        List<? extends DiffContent> contents = request.getContents();
        List<String> titles = request.getContentTitles();
        String windowTitle = request.getTitle();
        assert contents.size() == 3;
        assert titles.size() == contents.size();
        for (int i = 0; i < contents.size(); i++) {
            DiffContent content = contents.get(i);
            FileNameInfo fileName = FileNameInfo.create(contents, titles, windowTitle, i);
            inputFiles.add(createFile(content, fileName));
        }
        outputFile = createOutputFile(outputContent, FileNameInfo.createMergeResult(outputContent, windowTitle));
        Map<String, String> patterns = new HashMap<>();
        patterns.put("%1", inputFiles.get(0).getPath());
        patterns.put("%2", inputFiles.get(2).getPath());
        patterns.put("%3", inputFiles.get(1).getPath());
        patterns.put("%4", outputFile.getPath());
        final Process process = execute(settings.getMergeExePath(), settings.getMergeParameters(), patterns);
        if (settings.isMergeTrustExitCode()) {
            final Ref<Boolean> resultRef = new Ref<>();
            ProgressManager.getInstance().run(new Task.Modal(project, "Waiting for External Tool", true) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    final Semaphore semaphore = new Semaphore(0);
                    final Thread waiter = new Thread("external process waiter") {

                        @Override
                        public void run() {
                            try {
                                resultRef.set(process.waitFor() == 0);
                            } catch (InterruptedException ignore) {
                            } finally {
                                semaphore.release();
                            }
                        }
                    };
                    waiter.start();
                    try {
                        while (true) {
                            indicator.checkCanceled();
                            if (semaphore.tryAcquire(200, TimeUnit.MILLISECONDS))
                                break;
                        }
                    } catch (InterruptedException ignore) {
                    } finally {
                        waiter.interrupt();
                    }
                }
            });
            success = resultRef.get() == Boolean.TRUE;
        } else {
            ProgressManager.getInstance().run(new Task.Modal(project, "Launching External Tool", false) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    indicator.setIndeterminate(true);
                    TimeoutUtil.sleep(1000);
                }
            });
            success = Messages.showYesNoDialog(project, "Press \"Mark as Resolved\" when you finish resolving conflicts in the external tool", "Merge In External Tool", "Mark as Resolved", "Revert", null) == Messages.YES;
        }
        if (success)
            outputFile.apply();
    } finally {
        request.applyResult(success ? MergeResult.RESOLVED : MergeResult.CANCEL);
        if (outputFile != null)
            outputFile.cleanup();
        for (InputFile file : inputFiles) {
            file.cleanup();
        }
    }
}
Also used : Task(com.intellij.openapi.progress.Task) HashMap(com.intellij.util.containers.hash.HashMap) ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 5 with HashMap

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

the class JpsRunConfigurationSerializer method loadRunConfigurations.

public static void loadRunConfigurations(@NotNull JpsProject project, @Nullable Element runManagerTag) {
    Map<String, JpsRunConfigurationPropertiesSerializer<?>> serializers = new HashMap<>();
    for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
        for (JpsRunConfigurationPropertiesSerializer<?> serializer : extension.getRunConfigurationPropertiesSerializers()) {
            serializers.put(serializer.getTypeId(), serializer);
        }
    }
    for (Element configurationTag : JDOMUtil.getChildren(runManagerTag, "configuration")) {
        if (Boolean.parseBoolean(configurationTag.getAttributeValue("default"))) {
            continue;
        }
        String typeId = configurationTag.getAttributeValue("type");
        JpsRunConfigurationPropertiesSerializer<?> serializer = serializers.get(typeId);
        String name = configurationTag.getAttributeValue("name");
        if (serializer != null) {
            loadRunConfiguration(name, configurationTag, serializer, project);
        } else if (typeId != null) {
            project.addRunConfiguration(name, new JpsUnknownRunConfigurationType(typeId), JpsElementFactory.getInstance().createDummyElement());
        } else {
            LOG.info("Run configuration '" + name + "' wasn't loaded because 'type' attribute is missing");
        }
    }
}
Also used : HashMap(com.intellij.util.containers.hash.HashMap) JpsElement(org.jetbrains.jps.model.JpsElement) Element(org.jdom.Element) JpsModelSerializerExtension(org.jetbrains.jps.model.serialization.JpsModelSerializerExtension)

Aggregations

HashMap (com.intellij.util.containers.hash.HashMap)11 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)3 PsiElement (com.intellij.psi.PsiElement)3 DataContext (com.intellij.openapi.actionSystem.DataContext)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 FileModificationService (com.intellij.codeInsight.FileModificationService)1 DiffContent (com.intellij.diff.contents.DiffContent)1 MessageDiffRequest (com.intellij.diff.requests.MessageDiffRequest)1 AllIcons (com.intellij.icons.AllIcons)1 DataManager (com.intellij.ide.DataManager)1 DnDAwareTree (com.intellij.ide.dnd.aware.DnDAwareTree)1 GotoFileCellRenderer (com.intellij.ide.util.gotoByName.GotoFileCellRenderer)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 com.intellij.lang.properties (com.intellij.lang.properties)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 PlatformDataKeys (com.intellij.openapi.actionSystem.PlatformDataKeys)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Logger (com.intellij.openapi.diagnostic.Logger)1