Search in sources :

Example 21 with HashSet

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

the class OfflineInspectionRVContentProvider method excludeProblem.

private static void excludeProblem(final String externalName, final Map<String, Set<OfflineProblemDescriptor>> content) {
    for (Iterator<String> iter = content.keySet().iterator(); iter.hasNext(); ) {
        final String packageName = iter.next();
        final Set<OfflineProblemDescriptor> excluded = new HashSet<>(content.get(packageName));
        for (Iterator<OfflineProblemDescriptor> it = excluded.iterator(); it.hasNext(); ) {
            final OfflineProblemDescriptor ex = it.next();
            if (Comparing.strEqual(ex.getFQName(), externalName)) {
                it.remove();
            }
        }
        if (excluded.isEmpty()) {
            iter.remove();
        } else {
            content.put(packageName, excluded);
        }
    }
}
Also used : OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) HashSet(com.intellij.util.containers.HashSet)

Example 22 with HashSet

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

the class ScopeTreeViewPanel method getSelectedPsiElements.

@NotNull
private PsiElement[] getSelectedPsiElements() {
    final TreePath[] treePaths = myTree.getSelectionPaths();
    if (treePaths != null) {
        Set<PsiElement> result = new HashSet<>();
        for (TreePath path : treePaths) {
            final Object component = path.getLastPathComponent();
            if (component instanceof PackageDependenciesNode) {
                PackageDependenciesNode node = (PackageDependenciesNode) component;
                final PsiElement psiElement = node.getPsiElement();
                if (psiElement != null && psiElement.isValid()) {
                    result.add(psiElement);
                }
            }
        }
        return PsiUtilCore.toPsiElementArray(result);
    }
    return PsiElement.EMPTY_ARRAY;
}
Also used : TreePath(javax.swing.tree.TreePath) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with HashSet

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

the class SafeDeleteHandler method invoke.

public static void invoke(final Project project, PsiElement[] elements, @Nullable Module module, boolean checkDelegates, @Nullable final Runnable successRunnable) {
    for (PsiElement element : elements) {
        if (!SafeDeleteProcessor.validElement(element)) {
            return;
        }
    }
    final PsiElement[] temptoDelete = PsiTreeUtil.filterAncestors(elements);
    Set<PsiElement> elementsSet = new HashSet<>(Arrays.asList(temptoDelete));
    Set<PsiElement> fullElementsSet = new LinkedHashSet<>();
    if (checkDelegates) {
        for (PsiElement element : temptoDelete) {
            boolean found = false;
            for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) {
                if (delegate.handlesElement(element)) {
                    found = true;
                    Collection<? extends PsiElement> addElements = delegate instanceof SafeDeleteProcessorDelegateBase ? ((SafeDeleteProcessorDelegateBase) delegate).getElementsToSearch(element, module, elementsSet) : delegate.getElementsToSearch(element, elementsSet);
                    if (addElements == null)
                        return;
                    fullElementsSet.addAll(addElements);
                    break;
                }
            }
            if (!found) {
                fullElementsSet.add(element);
            }
        }
    } else {
        ContainerUtil.addAll(fullElementsSet, temptoDelete);
    }
    if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, fullElementsSet, true))
        return;
    final PsiElement[] elementsToDelete = PsiUtilCore.toPsiElementArray(fullElementsSet);
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        RefactoringSettings settings = RefactoringSettings.getInstance();
        SafeDeleteProcessor.createInstance(project, null, elementsToDelete, settings.SAFE_DELETE_SEARCH_IN_COMMENTS, settings.SAFE_DELETE_SEARCH_IN_NON_JAVA, true).run();
        if (successRunnable != null)
            successRunnable.run();
    } else {
        final SafeDeleteDialog.Callback callback = new SafeDeleteDialog.Callback() {

            @Override
            public void run(final SafeDeleteDialog dialog) {
                SafeDeleteProcessor.createInstance(project, () -> {
                    if (successRunnable != null) {
                        successRunnable.run();
                    }
                    dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
                }, elementsToDelete, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true).run();
            }
        };
        SafeDeleteDialog dialog = new SafeDeleteDialog(project, elementsToDelete, callback);
        dialog.show();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RefactoringSettings(com.intellij.refactoring.RefactoringSettings) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 24 with HashSet

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

the class AbstractTreeUi method getChildrenFor.

//todo [kirillk] temporary consistency check
private Object[] getChildrenFor(final Object element) {
    final Ref<Object[]> passOne = new Ref<>();
    try (LockToken ignored = acquireLock()) {
        execute(new TreeRunnable("AbstractTreeUi.getChildrenFor") {

            @Override
            public void perform() {
                passOne.set(getTreeStructure().getChildElements(element));
            }
        });
    } catch (IndexNotReadyException e) {
        warnOnIndexNotReady(e);
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    if (!Registry.is("ide.tree.checkStructure"))
        return passOne.get();
    final Object[] passTwo = getTreeStructure().getChildElements(element);
    final HashSet<Object> two = new HashSet<>(Arrays.asList(passTwo));
    if (passOne.get().length != passTwo.length) {
        LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
    } else {
        for (Object eachInOne : passOne.get()) {
            if (!two.contains(eachInOne)) {
                LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
                break;
            }
        }
    }
    return passOne.get();
}
Also used : LockToken(com.intellij.util.concurrency.LockToken) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Example 25 with HashSet

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

the class SearchResults method updateExcluded.

private void updateExcluded() {
    Set<RangeMarker> invalid = new HashSet<>();
    for (RangeMarker marker : myExcluded) {
        if (!marker.isValid()) {
            invalid.add(marker);
            marker.dispose();
        }
    }
    myExcluded.removeAll(invalid);
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker) HashSet(com.intellij.util.containers.HashSet)

Aggregations

HashSet (com.intellij.util.containers.HashSet)162 NotNull (org.jetbrains.annotations.NotNull)50 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 File (java.io.File)22 PsiElement (com.intellij.psi.PsiElement)20 Module (com.intellij.openapi.module.Module)19 ArrayList (java.util.ArrayList)18 Project (com.intellij.openapi.project.Project)17 THashSet (gnu.trove.THashSet)15 Nullable (org.jetbrains.annotations.Nullable)14 HashMap (com.intellij.util.containers.HashMap)13 IOException (java.io.IOException)13 PsiFile (com.intellij.psi.PsiFile)12 UsageInfo (com.intellij.usageView.UsageInfo)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 MultiMap (com.intellij.util.containers.MultiMap)11 Pair (com.intellij.openapi.util.Pair)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)6 Document (com.intellij.openapi.editor.Document)5