Search in sources :

Example 6 with HashSet

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

the class InspectionViewPsiTreeChangeAdapter method processEventFileOrDir.

private void processEventFileOrDir(@NotNull PsiTreeChangeEvent event, boolean eagerEvaluateFiles) {
    final PsiFile file = event.getFile();
    if (file != null) {
        VirtualFile vFile = file.getVirtualFile();
        if (vFile == null)
            return;
        invalidateFiles(vFile);
    } else {
        final PsiElement child = event.getChild();
        if (child instanceof PsiFileSystemItem) {
            final VirtualFile childFile = ((PsiFileSystemItem) child).getVirtualFile();
            if (childFile != null) {
                if (eagerEvaluateFiles) {
                    Set<VirtualFile> files = new HashSet<>();
                    VfsUtilCore.iterateChildrenRecursively(childFile, VirtualFileFilter.ALL, files::add);
                    invalidateFiles(files.toArray(new VirtualFile[files.size()]));
                } else {
                    invalidateFiles(childFile);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.hash.HashSet)

Example 7 with HashSet

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

the class HighlightUtil method checkIntersectionInTypeCast.

/**
   * 15.16 Cast Expressions
   * ( ReferenceType {AdditionalBound} ) expression, where AdditionalBound: & InterfaceType then all must be true
   *  • ReferenceType must denote a class or interface type.
   *  • The erasures of all the listed types must be pairwise different.
   *  • No two listed types may be subtypes of different parameterization of the same generic interface.
   */
@Nullable
static HighlightInfo checkIntersectionInTypeCast(@NotNull PsiTypeCastExpression expression, @NotNull LanguageLevel languageLevel, @NotNull PsiFile file) {
    PsiTypeElement castTypeElement = expression.getCastType();
    if (castTypeElement != null && isIntersection(castTypeElement, castTypeElement.getType())) {
        HighlightInfo info = checkFeature(expression, Feature.INTERSECTION_CASTS, languageLevel, file);
        if (info != null)
            return info;
        final PsiTypeElement[] conjuncts = PsiTreeUtil.getChildrenOfType(castTypeElement, PsiTypeElement.class);
        if (conjuncts != null) {
            final Set<PsiType> erasures = new HashSet<>(conjuncts.length);
            erasures.add(TypeConversionUtil.erasure(conjuncts[0].getType()));
            final List<PsiTypeElement> conjList = new ArrayList<>(Arrays.asList(conjuncts));
            for (int i = 1; i < conjuncts.length; i++) {
                final PsiTypeElement conjunct = conjuncts[i];
                final PsiType conjType = conjunct.getType();
                if (conjType instanceof PsiClassType) {
                    final PsiClass aClass = ((PsiClassType) conjType).resolve();
                    if (aClass != null && !aClass.isInterface()) {
                        final HighlightInfo errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(conjunct).descriptionAndTooltip(JavaErrorMessages.message("interface.expected")).create();
                        QuickFixAction.registerQuickFixAction(errorResult, new FlipIntersectionSidesFix(aClass.getName(), conjList, conjunct, castTypeElement), null);
                        return errorResult;
                    }
                } else {
                    return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(conjunct).descriptionAndTooltip("Unexpected type: class is expected").create();
                }
                if (!erasures.add(TypeConversionUtil.erasure(conjType))) {
                    final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(conjunct).descriptionAndTooltip("Repeated interface").create();
                    QuickFixAction.registerQuickFixAction(highlightInfo, new DeleteRepeatedInterfaceFix(conjunct, conjList), null);
                    return highlightInfo;
                }
            }
            final List<PsiType> typeList = ContainerUtil.map(conjList, PsiTypeElement::getType);
            final Ref<String> differentArgumentsMessage = new Ref<>();
            final PsiClass sameGenericParameterization = InferenceSession.findParameterizationOfTheSameGenericClass(typeList, pair -> {
                if (!TypesDistinctProver.provablyDistinct(pair.first, pair.second)) {
                    return true;
                }
                differentArgumentsMessage.set(pair.first.getPresentableText() + " and " + pair.second.getPresentableText());
                return false;
            });
            if (sameGenericParameterization != null) {
                final String message = formatClass(sameGenericParameterization) + " cannot be inherited with different arguments: " + differentArgumentsMessage.get();
                return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
            }
        }
    }
    return null;
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) Ref(com.intellij.openapi.util.Ref) HashSet(com.intellij.util.containers.hash.HashSet)

Example 8 with HashSet

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

the class IdeSettingsStatisticsUtils method getUsages.

public static Set<UsageDescriptor> getUsages(@NotNull IdeSettingsDescriptor descriptor, @NotNull Object componentInstance) {
    Set<UsageDescriptor> descriptors = new HashSet<>();
    String providerName = descriptor.myProviderName;
    List<String> propertyNames = descriptor.getPropertyNames();
    if (providerName != null && propertyNames.size() > 0) {
        for (String propertyName : propertyNames) {
            Object propertyValue = getPropertyValue(componentInstance, propertyName);
            if (propertyValue != null) {
                descriptors.add(new UsageDescriptor(getUsageDescriptorKey(providerName, propertyName, propertyValue.toString()), 1));
            }
        }
    }
    return descriptors;
}
Also used : UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) HashSet(com.intellij.util.containers.hash.HashSet)

Example 9 with HashSet

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

the class InstalledPluginsTableModel method warnAboutMissedDependencies.

private void warnAboutMissedDependencies(final Boolean newVal, final IdeaPluginDescriptor... ideaPluginDescriptors) {
    final Set<PluginId> deps = new HashSet<>();
    final List<IdeaPluginDescriptor> descriptorsToCheckDependencies = new ArrayList<>();
    if (newVal) {
        Collections.addAll(descriptorsToCheckDependencies, ideaPluginDescriptors);
    } else {
        descriptorsToCheckDependencies.addAll(getAllPlugins());
        descriptorsToCheckDependencies.removeAll(Arrays.asList(ideaPluginDescriptors));
        for (Iterator<IdeaPluginDescriptor> iterator = descriptorsToCheckDependencies.iterator(); iterator.hasNext(); ) {
            IdeaPluginDescriptor descriptor = iterator.next();
            final Boolean enabled = myEnabled.get(descriptor.getPluginId());
            if (enabled == null || !enabled.booleanValue()) {
                iterator.remove();
            }
        }
    }
    for (final IdeaPluginDescriptor ideaPluginDescriptor : descriptorsToCheckDependencies) {
        PluginManagerCore.checkDependants(ideaPluginDescriptor, pluginId -> PluginManager.getPlugin(pluginId), pluginId -> {
            Boolean enabled = myEnabled.get(pluginId);
            if (enabled == null) {
                return false;
            }
            if (newVal && !enabled.booleanValue()) {
                deps.add(pluginId);
            }
            if (!newVal) {
                if (ideaPluginDescriptor instanceof IdeaPluginDescriptorImpl && ((IdeaPluginDescriptorImpl) ideaPluginDescriptor).isDeleted()) {
                    return true;
                }
                final PluginId pluginDescriptorId = ideaPluginDescriptor.getPluginId();
                for (IdeaPluginDescriptor descriptor : ideaPluginDescriptors) {
                    if (pluginId.equals(descriptor.getPluginId())) {
                        deps.add(pluginDescriptorId);
                        break;
                    }
                }
            }
            return true;
        });
    }
    if (!deps.isEmpty()) {
        final String listOfSelectedPlugins = StringUtil.join(ideaPluginDescriptors, pluginDescriptor -> pluginDescriptor.getName(), ", ");
        final Set<IdeaPluginDescriptor> pluginDependencies = new HashSet<>();
        final String listOfDependencies = StringUtil.join(deps, pluginId -> {
            final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(pluginId);
            assert pluginDescriptor != null;
            pluginDependencies.add(pluginDescriptor);
            return pluginDescriptor.getName();
        }, "<br>");
        final String message = !newVal ? "<html>The following plugins <br>" + listOfDependencies + "<br>are enabled and depend" + (deps.size() == 1 ? "s" : "") + " on selected plugins. " + "<br>Would you like to disable them too?</html>" : "<html>The following plugins on which " + listOfSelectedPlugins + " depend" + (ideaPluginDescriptors.length == 1 ? "s" : "") + " are disabled:<br>" + listOfDependencies + "<br>Would you like to enable them?</html>";
        if (Messages.showOkCancelDialog(message, newVal ? "Enable Dependant Plugins" : "Disable Plugins with Dependency on this", Messages.getQuestionIcon()) == Messages.OK) {
            for (PluginId pluginId : deps) {
                myEnabled.put(pluginId, newVal);
            }
            updatePluginDependencies();
            hideNotApplicablePlugins(newVal, pluginDependencies.toArray(new IdeaPluginDescriptor[pluginDependencies.size()]));
        }
    }
}
Also used : PluginId(com.intellij.openapi.extensions.PluginId) HashSet(com.intellij.util.containers.hash.HashSet)

Example 10 with HashSet

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

the class RemoteAgentReflectiveProxyFactory method createAgentClassLoader.

@Override
protected ClassLoader createAgentClassLoader(URL[] agentLibraryUrls) throws Exception {
    Set<URL> urls = new HashSet<>();
    urls.addAll(Arrays.asList(agentLibraryUrls));
    return myClassLoaderCache == null ? new URLClassLoader(urls.toArray(new URL[urls.size()]), null) : myClassLoaderCache.getOrCreateClassLoader(urls);
}
Also used : URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) HashSet(com.intellij.util.containers.hash.HashSet)

Aggregations

HashSet (com.intellij.util.containers.hash.HashSet)27 Project (com.intellij.openapi.project.Project)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)5 PsiElement (com.intellij.psi.PsiElement)4 XmlFile (com.intellij.psi.xml.XmlFile)4 Set (java.util.Set)4 Ref (com.intellij.openapi.util.Ref)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)2 ExcludeEntryDescription (com.intellij.openapi.compiler.options.ExcludeEntryDescription)2 Module (com.intellij.openapi.module.Module)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 PsiClass (com.intellij.psi.PsiClass)2 PsiFile (com.intellij.psi.PsiFile)2 XmlTag (com.intellij.psi.xml.XmlTag)2 Function (com.intellij.util.Function)2 Processor (com.intellij.util.Processor)2 SmartList (com.intellij.util.SmartList)2