Search in sources :

Example 11 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class MavenArtifactDownloader method collectArtifactsToDownload.

private Map<MavenId, DownloadData> collectArtifactsToDownload(List<MavenExtraArtifactType> types) {
    Map<MavenId, DownloadData> result = new THashMap<>();
    THashSet<String> dependencyTypesFromSettings = new THashSet<>();
    AccessToken accessToken = ReadAction.start();
    try {
        if (myProject.isDisposed())
            return result;
        dependencyTypesFromSettings.addAll(MavenProjectsManager.getInstance(myProject).getImportingSettings().getDependencyTypesAsSet());
    } finally {
        accessToken.finish();
    }
    for (MavenProject eachProject : myMavenProjects) {
        List<MavenRemoteRepository> repositories = eachProject.getRemoteRepositories();
        for (MavenArtifact eachDependency : eachProject.getDependencies()) {
            if (myArtifacts != null && !myArtifacts.contains(eachDependency))
                continue;
            if (MavenConstants.SCOPE_SYSTEM.equalsIgnoreCase(eachDependency.getScope()))
                continue;
            if (myProjectsTree.findProject(eachDependency.getMavenId()) != null)
                continue;
            String dependencyType = eachDependency.getType();
            if (!dependencyTypesFromSettings.contains(dependencyType) && !eachProject.getDependencyTypesFromImporters(SupportedRequestType.FOR_IMPORT).contains(dependencyType)) {
                continue;
            }
            MavenId id = eachDependency.getMavenId();
            DownloadData data = result.get(id);
            if (data == null) {
                data = new DownloadData();
                result.put(id, data);
            }
            data.repositories.addAll(repositories);
            for (MavenExtraArtifactType eachType : types) {
                Pair<String, String> classifierAndExtension = eachProject.getClassifierAndExtension(eachDependency, eachType);
                String classifier = eachDependency.getFullClassifier(classifierAndExtension.first);
                String extension = classifierAndExtension.second;
                data.classifiersWithExtensions.add(new DownloadElement(classifier, extension, eachType));
            }
        }
    }
    return result;
}
Also used : THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) AccessToken(com.intellij.openapi.application.AccessToken) MavenExtraArtifactType(org.jetbrains.idea.maven.importing.MavenExtraArtifactType)

Example 12 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class MavenProjectsTree method delete.

private void delete(MavenProjectReader projectReader, List<VirtualFile> files, MavenExplicitProfiles explicitProfiles, MavenGeneralSettings generalSettings, MavenProgressIndicator process) {
    if (files.isEmpty())
        return;
    UpdateContext updateContext = new UpdateContext();
    Stack<MavenProject> updateStack = new Stack<>();
    Set<MavenProject> inheritorsToUpdate = new THashSet<>();
    for (VirtualFile each : files) {
        MavenProject mavenProject = findProject(each);
        if (mavenProject == null)
            return;
        inheritorsToUpdate.addAll(findInheritors(mavenProject));
        doDelete(findAggregator(mavenProject), mavenProject, updateContext);
    }
    inheritorsToUpdate.removeAll(updateContext.deletedProjects);
    for (MavenProject each : inheritorsToUpdate) {
        doUpdate(each, null, false, false, false, explicitProfiles, updateContext, updateStack, projectReader, generalSettings, process);
    }
    updateExplicitProfiles();
    updateContext.fireUpdatedIfNecessary();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) Stack(com.intellij.util.containers.Stack)

Example 13 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class InconsistentResourceBundleInspection method checkFile.

@Override
public void checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, @NotNull ProblemsHolder problemsHolder, @NotNull GlobalInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
    Set<ResourceBundle> visitedBundles = globalContext.getUserData(VISITED_BUNDLES_KEY);
    if (!(file instanceof PropertiesFile))
        return;
    final PropertiesFile propertiesFile = (PropertiesFile) file;
    ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
    assert visitedBundles != null;
    if (!visitedBundles.add(resourceBundle))
        return;
    List<PropertiesFile> files = resourceBundle.getPropertiesFiles();
    if (files.size() < 2)
        return;
    BidirectionalMap<PropertiesFile, PropertiesFile> parents = new BidirectionalMap<>();
    for (PropertiesFile f : files) {
        PropertiesFile parent = PropertiesUtil.getParent(f, files);
        if (parent != null) {
            parents.put(f, parent);
        }
    }
    final FactoryMap<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps = new FactoryMap<PropertiesFile, Map<String, String>>() {

        @Nullable
        @Override
        protected Map<String, String> create(PropertiesFile key) {
            return key.getNamesMap();
        }
    };
    Map<PropertiesFile, Set<String>> keysUpToParent = new THashMap<>();
    for (PropertiesFile f : files) {
        Set<String> keys = new THashSet<>(propertiesFilesNamesMaps.get(f).keySet());
        PropertiesFile parent = parents.get(f);
        while (parent != null) {
            keys.addAll(propertiesFilesNamesMaps.get(parent).keySet());
            parent = parents.get(parent);
        }
        keysUpToParent.put(f, keys);
    }
    for (final InconsistentResourceBundleInspectionProvider provider : myInspectionProviders.getValue()) {
        if (isProviderEnabled(provider.getName())) {
            provider.check(parents, files, keysUpToParent, propertiesFilesNamesMaps, manager, globalContext.getRefManager(), problemDescriptionsProcessor);
        }
    }
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) THashSet(gnu.trove.THashSet) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) FactoryMap(com.intellij.util.containers.FactoryMap) THashMap(gnu.trove.THashMap) BidirectionalMap(com.intellij.util.containers.BidirectionalMap) BidirectionalMap(com.intellij.util.containers.BidirectionalMap)

Example 14 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class DuplicateStringLiteralInspection method getCandidateFiles.

@NotNull
private Set<PsiFile> getCandidateFiles(String stringToFind, Project project) {
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
    final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(project);
    final List<String> words = StringUtil.getWordsInStringLongestFirst(stringToFind);
    if (words.isEmpty())
        return Collections.emptySet();
    Set<PsiFile> resultFiles = null;
    for (String word : words) {
        if (word.length() < MIN_STRING_LENGTH) {
            continue;
        }
        ProgressManager.checkCanceled();
        final Set<PsiFile> files = new THashSet<>();
        Processor<PsiFile> processor = Processors.cancelableCollectProcessor(files);
        searchHelper.processAllFilesWithWordInLiterals(word, scope, processor);
        if (resultFiles == null) {
            resultFiles = files;
        } else {
            resultFiles.retainAll(files);
        }
        if (resultFiles.isEmpty())
            return Collections.emptySet();
    }
    return resultFiles != null ? resultFiles : Collections.emptySet();
}
Also used : PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class XmlNSDescriptorImpl method doBuildDeclarationMap.

// Read-only calculation
private CachedValue<Map<String, XmlElementDescriptor>> doBuildDeclarationMap() {
    return CachedValuesManager.getManager(myElement.getProject()).createCachedValue(() -> {
        final List<XmlElementDecl> result = new ArrayList<>();
        myElement.processElements(new FilterElementProcessor(new ClassFilter(XmlElementDecl.class), result), getDeclaration());
        final Map<String, XmlElementDescriptor> ret = new LinkedHashMap<>((int) (result.size() * 1.5));
        Set<PsiFile> dependencies = new THashSet<>(1);
        dependencies.add(myDescriptorFile);
        for (final XmlElementDecl xmlElementDecl : result) {
            final String name = xmlElementDecl.getName();
            if (name != null) {
                if (!ret.containsKey(name)) {
                    ret.put(name, new XmlElementDescriptorImpl(xmlElementDecl));
                    // if element descriptor was produced from entity reference use proper dependency
                    PsiElement dependingElement = xmlElementDecl.getUserData(XmlElement.DEPENDING_ELEMENT);
                    if (dependingElement != null) {
                        PsiFile dependingElementContainingFile = dependingElement.getContainingFile();
                        if (dependingElementContainingFile != null)
                            dependencies.add(dependingElementContainingFile);
                    }
                }
            }
        }
        return new CachedValueProvider.Result<>(ret, dependencies.toArray());
    }, false);
}
Also used : THashSet(gnu.trove.THashSet) FilterElementProcessor(com.intellij.psi.scope.processor.FilterElementProcessor) ClassFilter(com.intellij.psi.filters.ClassFilter) PsiFile(com.intellij.psi.PsiFile) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

THashSet (gnu.trove.THashSet)239 NotNull (org.jetbrains.annotations.NotNull)65 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 Project (com.intellij.openapi.project.Project)35 File (java.io.File)35 THashMap (gnu.trove.THashMap)31 Nullable (org.jetbrains.annotations.Nullable)31 Module (com.intellij.openapi.module.Module)29 IOException (java.io.IOException)24 PsiElement (com.intellij.psi.PsiElement)21 PsiFile (com.intellij.psi.PsiFile)18 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 java.util (java.util)16 Element (org.jdom.Element)14 Pair (com.intellij.openapi.util.Pair)13 Logger (com.intellij.openapi.diagnostic.Logger)12 ContainerUtil (com.intellij.util.containers.ContainerUtil)12 Document (com.intellij.openapi.editor.Document)11 Library (com.intellij.openapi.roots.libraries.Library)11 StringUtil (com.intellij.openapi.util.text.StringUtil)10