Search in sources :

Example 96 with HashSet

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

the class PsiClassImplUtil method isMethodEquivalentTo.

public static boolean isMethodEquivalentTo(@NotNull PsiMethod method1, PsiElement another) {
    if (method1 == another)
        return true;
    if (!(another instanceof PsiMethod))
        return false;
    PsiMethod method2 = (PsiMethod) another;
    if (!another.isValid())
        return false;
    if (!method1.getName().equals(method2.getName()))
        return false;
    PsiClass aClass1 = method1.getContainingClass();
    PsiClass aClass2 = method2.getContainingClass();
    PsiManager manager = method1.getManager();
    if (!(aClass1 != null && aClass2 != null && manager.areElementsEquivalent(aClass1, aClass2)))
        return false;
    PsiParameter[] parameters1 = method1.getParameterList().getParameters();
    PsiParameter[] parameters2 = method2.getParameterList().getParameters();
    if (parameters1.length != parameters2.length)
        return false;
    for (int i = 0; i < parameters1.length; i++) {
        PsiParameter parameter1 = parameters1[i];
        PsiParameter parameter2 = parameters2[i];
        PsiType type1 = parameter1.getType();
        PsiType type2 = parameter2.getType();
        if (!compareParamTypes(manager, type1, type2, new HashSet<>()))
            return false;
    }
    return true;
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Example 97 with HashSet

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

the class AbstractRunConfigurationTypeUsagesCollector method getProjectUsages.

@NotNull
@Override
public final Set<UsageDescriptor> getProjectUsages(@NotNull final Project project) {
    final Set<String> runConfigurationTypes = new HashSet<>();
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            if (project.isDisposed())
                return;
            final RunManager runManager = RunManager.getInstance(project);
            for (RunnerAndConfigurationSettings settings : runManager.getAllSettings()) {
                RunConfiguration runConfiguration = settings.getConfiguration();
                if (runConfiguration != null && isApplicable(runManager, settings)) {
                    final ConfigurationFactory configurationFactory = runConfiguration.getFactory();
                    final ConfigurationType configurationType = configurationFactory.getType();
                    final StringBuilder keyBuilder = new StringBuilder();
                    keyBuilder.append(configurationType.getId());
                    if (configurationType.getConfigurationFactories().length > 1) {
                        keyBuilder.append(".").append(configurationFactory.getName());
                    }
                    runConfigurationTypes.add(keyBuilder.toString());
                }
            }
        }
    });
    return ContainerUtil.map2Set(runConfigurationTypes, runConfigurationType -> new UsageDescriptor(runConfigurationType, 1));
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) RunManager(com.intellij.execution.RunManager) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 98 with HashSet

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

the class ModuleRunConfigurationManager method readExternal.

public void readExternal(@NotNull final Element element) {
    LOG.debug("readExternal(" + myModule + ")");
    myUnloadedElements = null;
    final Set<String> existing = new HashSet<>();
    for (final Element child : element.getChildren()) {
        final RunnerAndConfigurationSettings configuration = myManager.loadConfiguration(child, true);
        if (configuration == null && Comparing.strEqual(element.getName(), RunManagerImpl.CONFIGURATION)) {
            if (myUnloadedElements == null)
                myUnloadedElements = new ArrayList<>(2);
            myUnloadedElements.add(element);
        }
        if (configuration != null) {
            existing.add(configuration.getUniqueID());
        }
    }
    for (final RunConfiguration configuration : myManager.getAllConfigurationsList()) {
        if (!usesMyModule(configuration)) {
            RunnerAndConfigurationSettings settings = myManager.getSettings(configuration);
            if (settings != null) {
                existing.add(settings.getUniqueID());
            }
        }
    }
    myManager.removeNotExistingSharedConfigurations(existing);
    // IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read
    myManager.setOrdered(false);
    myManager.getSortedConfigurations();
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) Element(org.jdom.Element) ArrayList(java.util.ArrayList) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) HashSet(com.intellij.util.containers.HashSet)

Example 99 with HashSet

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

the class GlobalInspectionContextImpl method cleanup.

private void cleanup(@NotNull final AnalysisScope scope, @NotNull InspectionProfile profile, @Nullable final Runnable postRunnable, @Nullable final String commandName) {
    setCurrentScope(scope);
    final int fileCount = scope.getFileCount();
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    final SearchScope searchScope = ReadAction.compute(scope::toSearchScope);
    final TextRange range;
    if (searchScope instanceof LocalSearchScope) {
        final PsiElement[] elements = ((LocalSearchScope) searchScope).getScope();
        range = elements.length == 1 ? ReadAction.compute(elements[0]::getTextRange) : null;
    } else {
        range = null;
    }
    final Iterable<Tools> inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> {
        assert tools != null;
        return tools.getTool().getTool() instanceof CleanupLocalInspectionTool;
    });
    boolean includeDoNotShow = includeDoNotShow(profile);
    final RefManagerImpl refManager = (RefManagerImpl) getRefManager();
    refManager.inspectionReadActionStarted();
    List<ProblemDescriptor> descriptors = new ArrayList<>();
    Set<PsiFile> files = new HashSet<>();
    try {
        scope.accept(new PsiElementVisitor() {

            private int myCount;

            @Override
            public void visitFile(PsiFile file) {
                if (progressIndicator != null) {
                    progressIndicator.setFraction((double) ++myCount / fileCount);
                }
                if (isBinary(file))
                    return;
                final List<LocalInspectionToolWrapper> lTools = new ArrayList<>();
                for (final Tools tools : inspectionTools) {
                    final InspectionToolWrapper tool = tools.getEnabledTool(file, includeDoNotShow);
                    if (tool instanceof LocalInspectionToolWrapper) {
                        lTools.add((LocalInspectionToolWrapper) tool);
                        tool.initialize(GlobalInspectionContextImpl.this);
                    }
                }
                if (!lTools.isEmpty()) {
                    try {
                        final LocalInspectionsPass pass = new LocalInspectionsPass(file, PsiDocumentManager.getInstance(getProject()).getDocument(file), range != null ? range.getStartOffset() : 0, range != null ? range.getEndOffset() : file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true, HighlightInfoProcessor.getEmpty());
                        Runnable runnable = () -> pass.doInspectInBatch(GlobalInspectionContextImpl.this, InspectionManager.getInstance(getProject()), lTools);
                        ApplicationManager.getApplication().runReadAction(runnable);
                        final Set<ProblemDescriptor> localDescriptors = new TreeSet<>(CommonProblemDescriptor.DESCRIPTOR_COMPARATOR);
                        for (LocalInspectionToolWrapper tool : lTools) {
                            InspectionToolPresentation toolPresentation = getPresentation(tool);
                            for (CommonProblemDescriptor descriptor : toolPresentation.getProblemDescriptors()) {
                                if (descriptor instanceof ProblemDescriptor) {
                                    localDescriptors.add((ProblemDescriptor) descriptor);
                                }
                            }
                        }
                        if (searchScope instanceof LocalSearchScope) {
                            for (Iterator<ProblemDescriptor> iterator = localDescriptors.iterator(); iterator.hasNext(); ) {
                                final ProblemDescriptor descriptor = iterator.next();
                                final TextRange infoRange = descriptor instanceof ProblemDescriptorBase ? ((ProblemDescriptorBase) descriptor).getTextRange() : null;
                                if (infoRange != null && !((LocalSearchScope) searchScope).containsRange(file, infoRange)) {
                                    iterator.remove();
                                }
                            }
                        }
                        if (!localDescriptors.isEmpty()) {
                            descriptors.addAll(localDescriptors);
                            files.add(file);
                        }
                    } finally {
                        myPresentationMap.clear();
                    }
                }
            }
        });
    } finally {
        refManager.inspectionReadActionFinished();
    }
    if (files.isEmpty()) {
        GuiUtils.invokeLaterIfNeeded(() -> {
            if (commandName != null) {
                NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message", scope.getFileCount(), scope.getDisplayName()), MessageType.INFO).notify(getProject());
            }
            if (postRunnable != null) {
                postRunnable.run();
            }
        }, ModalityState.defaultModalityState());
        return;
    }
    Runnable runnable = () -> {
        if (!FileModificationService.getInstance().preparePsiElementsForWrite(files))
            return;
        CleanupInspectionIntention.applyFixesNoSort(getProject(), "Code Cleanup", descriptors, null);
        if (postRunnable != null) {
            postRunnable.run();
        }
    };
    TransactionGuard.submitTransaction(getProject(), runnable);
}
Also used : DefaultInspectionToolPresentation(com.intellij.codeInspection.ui.DefaultInspectionToolPresentation) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) LocalInspectionsPass(com.intellij.codeInsight.daemon.impl.LocalInspectionsPass) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope)

Example 100 with HashSet

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

the class InspectionRVContentProviderImpl method appendDescriptor.

@Override
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context, @NotNull final InspectionToolWrapper toolWrapper, @NotNull final RefEntityContainer container, @NotNull final InspectionTreeNode pNode, final boolean canPackageRepeat) {
    final RefEntity refElement = container.getRefEntity();
    InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
    final CommonProblemDescriptor[] problems = ((RefEntityContainer<CommonProblemDescriptor>) container).getDescriptors();
    if (problems != null) {
        final RefElementNode elemNode = addNodeToParent(container, presentation, pNode);
        for (CommonProblemDescriptor problem : problems) {
            assert problem != null;
            elemNode.insertByOrder(ReadAction.compute(() -> new ProblemDescriptionNode(refElement, problem, toolWrapper, presentation)), true);
            elemNode.setProblem(elemNode.getChildCount() == 1 ? problems[0] : null);
        }
    } else {
        if (canPackageRepeat && pNode instanceof InspectionPackageNode) {
            final Set<RefEntity> currentElements = presentation.getContent().get(((InspectionPackageNode) pNode).getPackageName());
            if (currentElements != null) {
                final Set<RefEntity> currentEntities = new HashSet<>(currentElements);
                if (RefUtil.contains(refElement, currentEntities))
                    return;
            }
        }
        addNodeToParent(container, presentation, pNode);
    }
}
Also used : CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) 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