Search in sources :

Example 36 with THashMap

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

the class GradleResourceCompilerConfigurationGenerator method generateBuildConfiguration.

public void generateBuildConfiguration(@NotNull final CompileContext context) {
    if (shouldBeBuiltByExternalSystem(myProject))
        return;
    if (!hasGradleModules(context))
        return;
    final BuildManager buildManager = BuildManager.getInstance();
    final File projectSystemDir = buildManager.getProjectSystemDirectory(myProject);
    if (projectSystemDir == null)
        return;
    final File gradleConfigFile = new File(projectSystemDir, GradleProjectConfiguration.CONFIGURATION_FILE_RELATIVE_PATH);
    final Map<String, GradleModuleResourceConfiguration> affectedGradleModuleConfigurations = generateAffectedGradleModulesConfiguration(context);
    if (affectedGradleModuleConfigurations.isEmpty())
        return;
    boolean configurationUpdateRequired = context.isRebuild() || !gradleConfigFile.exists();
    final Map<String, Integer> affectedConfigurationHash = new THashMap<>();
    for (Map.Entry<String, GradleModuleResourceConfiguration> entry : affectedGradleModuleConfigurations.entrySet()) {
        Integer moduleLastConfigurationHash = myModulesConfigurationHash.get(entry.getKey());
        int moduleCurrentConfigurationHash = entry.getValue().computeConfigurationHash();
        if (moduleLastConfigurationHash == null || moduleLastConfigurationHash.intValue() != moduleCurrentConfigurationHash) {
            configurationUpdateRequired = true;
        }
        affectedConfigurationHash.put(entry.getKey(), moduleCurrentConfigurationHash);
    }
    final GradleProjectConfiguration projectConfig = loadLastConfiguration(gradleConfigFile);
    // update with newly generated configuration
    projectConfig.moduleConfigurations.putAll(affectedGradleModuleConfigurations);
    final Element element = new Element("gradle-project-configuration");
    XmlSerializer.serializeInto(projectConfig, element);
    final boolean finalConfigurationUpdateRequired = configurationUpdateRequired;
    buildManager.runCommand(() -> {
        if (finalConfigurationUpdateRequired) {
            buildManager.clearState(myProject);
        }
        FileUtil.createIfDoesntExist(gradleConfigFile);
        try {
            JdomKt.write(element, gradleConfigFile.toPath());
            myModulesConfigurationHash.putAll(affectedConfigurationHash);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : Element(org.jdom.Element) IOException(java.io.IOException) THashMap(gnu.trove.THashMap) BuildManager(com.intellij.compiler.server.BuildManager) File(java.io.File) THashMap(gnu.trove.THashMap) Map(java.util.Map) FactoryMap(com.intellij.util.containers.FactoryMap)

Example 37 with THashMap

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

the class ExternalProjectSerializer method configureKryo.

private void configureKryo() {
    myKryo.setAutoReset(true);
    myKryo.setRegistrationRequired(true);
    Log.set(Log.LEVEL_WARN);
    myKryo.register(ArrayList.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new ArrayList();
        }
    });
    myKryo.register(HashMap.class, new MapSerializer() {

        @Override
        protected Map create(Kryo kryo, Input input, Class<Map> type) {
            return new HashMap();
        }
    });
    myKryo.register(HashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new HashSet();
        }
    });
    myKryo.register(File.class, new FileSerializer());
    myKryo.register(DefaultExternalProject.class, new FieldSerializer<DefaultExternalProject>(myKryo, DefaultExternalProject.class) {

        @Override
        protected DefaultExternalProject create(Kryo kryo, Input input, Class<DefaultExternalProject> type) {
            return new DefaultExternalProject();
        }
    });
    myKryo.register(DefaultExternalTask.class, new FieldSerializer<DefaultExternalTask>(myKryo, DefaultExternalTask.class) {

        @Override
        protected DefaultExternalTask create(Kryo kryo, Input input, Class<DefaultExternalTask> type) {
            return new DefaultExternalTask();
        }
    });
    myKryo.register(DefaultExternalPlugin.class, new FieldSerializer<DefaultExternalPlugin>(myKryo, DefaultExternalPlugin.class) {

        @Override
        protected DefaultExternalPlugin create(Kryo kryo, Input input, Class<DefaultExternalPlugin> type) {
            return new DefaultExternalPlugin();
        }
    });
    myKryo.register(DefaultExternalSourceSet.class, new FieldSerializer<DefaultExternalSourceSet>(myKryo, DefaultExternalSourceSet.class) {

        @Override
        protected DefaultExternalSourceSet create(Kryo kryo, Input input, Class<DefaultExternalSourceSet> type) {
            return new DefaultExternalSourceSet();
        }
    });
    myKryo.register(DefaultExternalSourceDirectorySet.class, new FieldSerializer<DefaultExternalSourceDirectorySet>(myKryo, DefaultExternalSourceDirectorySet.class) {

        @Override
        protected DefaultExternalSourceDirectorySet create(Kryo kryo, Input input, Class<DefaultExternalSourceDirectorySet> type) {
            return new DefaultExternalSourceDirectorySet();
        }
    });
    myKryo.register(DefaultExternalFilter.class, new FieldSerializer<DefaultExternalFilter>(myKryo, DefaultExternalFilter.class) {

        @Override
        protected DefaultExternalFilter create(Kryo kryo, Input input, Class<DefaultExternalFilter> type) {
            return new DefaultExternalFilter();
        }
    });
    myKryo.register(ExternalSystemSourceType.class, new DefaultSerializers.EnumSerializer(ExternalSystemSourceType.class));
    myKryo.register(DefaultExternalProjectDependency.class, new FieldSerializer<DefaultExternalProjectDependency>(myKryo, DefaultExternalProjectDependency.class) {

        @Override
        protected DefaultExternalProjectDependency create(Kryo kryo, Input input, Class<DefaultExternalProjectDependency> type) {
            return new DefaultExternalProjectDependency();
        }
    });
    myKryo.register(DefaultFileCollectionDependency.class, new FieldSerializer<DefaultFileCollectionDependency>(myKryo, DefaultFileCollectionDependency.class) {

        @Override
        protected DefaultFileCollectionDependency create(Kryo kryo, Input input, Class<DefaultFileCollectionDependency> type) {
            return new DefaultFileCollectionDependency();
        }
    });
    myKryo.register(DefaultExternalLibraryDependency.class, new FieldSerializer<DefaultExternalLibraryDependency>(myKryo, DefaultExternalLibraryDependency.class) {

        @Override
        protected DefaultExternalLibraryDependency create(Kryo kryo, Input input, Class<DefaultExternalLibraryDependency> type) {
            return new DefaultExternalLibraryDependency();
        }
    });
    myKryo.register(DefaultUnresolvedExternalDependency.class, new FieldSerializer<DefaultUnresolvedExternalDependency>(myKryo, DefaultUnresolvedExternalDependency.class) {

        @Override
        protected DefaultUnresolvedExternalDependency create(Kryo kryo, Input input, Class<DefaultUnresolvedExternalDependency> type) {
            return new DefaultUnresolvedExternalDependency();
        }
    });
    myKryo.register(DefaultExternalDependencyId.class, new FieldSerializer<DefaultExternalDependencyId>(myKryo, DefaultExternalDependencyId.class) {

        @Override
        protected DefaultExternalDependencyId create(Kryo kryo, Input input, Class<DefaultExternalDependencyId> type) {
            return new DefaultExternalDependencyId();
        }
    });
    myKryo.register(LinkedHashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new LinkedHashSet();
        }
    });
    myKryo.register(HashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new HashSet();
        }
    });
    myKryo.register(THashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new THashSet();
        }
    });
    myKryo.register(Set.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new HashSet();
        }
    });
    myKryo.register(THashMap.class, new MapSerializer() {

        @Override
        protected Map create(Kryo kryo, Input input, Class<Map> type) {
            return new THashMap();
        }
    });
}
Also used : THashMap(gnu.trove.THashMap) DefaultExternalDependencyId(org.jetbrains.plugins.gradle.DefaultExternalDependencyId) Input(com.esotericsoftware.kryo.io.Input) MapSerializer(com.esotericsoftware.kryo.serializers.MapSerializer) THashSet(gnu.trove.THashSet) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) ExternalSystemSourceType(com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType) THashMap(gnu.trove.THashMap) DefaultSerializers(com.esotericsoftware.kryo.serializers.DefaultSerializers) CollectionSerializer(com.esotericsoftware.kryo.serializers.CollectionSerializer) Kryo(com.esotericsoftware.kryo.Kryo)

Example 38 with THashMap

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

the class PsiSearchHelperImpl method processRequests.

@Override
public boolean processRequests(@NotNull SearchRequestCollector collector, @NotNull Processor<PsiReference> processor) {
    final Map<SearchRequestCollector, Processor<PsiReference>> collectors = ContainerUtil.newHashMap();
    collectors.put(collector, processor);
    ProgressIndicator progress = getOrCreateIndicator();
    appendCollectorsFromQueryRequests(collectors);
    boolean result;
    do {
        MultiMap<Set<IdIndexEntry>, RequestWithProcessor> globals = new MultiMap<>();
        final List<Computable<Boolean>> customs = ContainerUtil.newArrayList();
        final Set<RequestWithProcessor> locals = ContainerUtil.newLinkedHashSet();
        Map<RequestWithProcessor, Processor<PsiElement>> localProcessors = new THashMap<>();
        distributePrimitives(collectors, locals, globals, customs, localProcessors, progress);
        result = processGlobalRequestsOptimized(globals, progress, localProcessors);
        if (result) {
            for (RequestWithProcessor local : locals) {
                result = processSingleRequest(local.request, local.refProcessor);
                if (!result)
                    break;
            }
            if (result) {
                for (Computable<Boolean> custom : customs) {
                    result = custom.compute();
                    if (!result)
                        break;
                }
            }
            if (!result)
                break;
        }
    } while (appendCollectorsFromQueryRequests(collectors));
    return result;
}
Also used : ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) Processor(com.intellij.util.Processor) THashSet(gnu.trove.THashSet) MultiMap(com.intellij.util.containers.MultiMap) THashMap(gnu.trove.THashMap) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 39 with THashMap

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

the class StdArrangementExtendableSettings method getExtendedSectionRules.

@Override
public List<ArrangementSectionRule> getExtendedSectionRules() {
    synchronized (myExtendedSectionRules) {
        if (myExtendedSectionRules.isEmpty()) {
            final Map<String, StdArrangementRuleAliasToken> tokenIdToDefinition = new THashMap<>(myRulesAliases.size());
            for (StdArrangementRuleAliasToken alias : myRulesAliases) {
                final String id = alias.getId();
                tokenIdToDefinition.put(id, alias);
            }
            final List<ArrangementSectionRule> sections = getSections();
            for (ArrangementSectionRule section : sections) {
                final List<StdArrangementMatchRule> extendedRules = new ArrayList<>();
                for (StdArrangementMatchRule rule : section.getMatchRules()) {
                    appendExpandedRules(rule, extendedRules, tokenIdToDefinition);
                }
                myExtendedSectionRules.add(ArrangementSectionRule.create(section.getStartComment(), section.getEndComment(), extendedRules));
            }
        }
    }
    return myExtendedSectionRules;
}
Also used : THashMap(gnu.trove.THashMap) ArrangementSectionRule(com.intellij.psi.codeStyle.arrangement.match.ArrangementSectionRule) StdArrangementMatchRule(com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule)

Example 40 with THashMap

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

the class DirectoryEntry method collectDifferencesWith.

@Override
public void collectDifferencesWith(Entry right, List<Difference> result) {
    DirectoryEntry e = (DirectoryEntry) right;
    if (!getPath().equals(e.getPath())) {
        result.add(new Difference(false, this, e));
    }
    // most often we have the same children, so try processing it directly
    int commonIndex = 0;
    final int myChildrenSize = myChildren.size();
    final int rightChildrenSize = e.myChildren.size();
    final int minChildrenSize = Math.min(myChildrenSize, rightChildrenSize);
    while (commonIndex < minChildrenSize) {
        Entry childEntry = myChildren.get(commonIndex);
        Entry rightChildEntry = e.myChildren.get(commonIndex);
        if (childEntry.getNameId() == rightChildEntry.getNameId() && childEntry.isDirectory() == rightChildEntry.isDirectory()) {
            childEntry.collectDifferencesWith(rightChildEntry, result);
        } else {
            break;
        }
        ++commonIndex;
    }
    if (commonIndex == myChildrenSize && commonIndex == rightChildrenSize)
        return;
    TIntObjectHashMap<Entry> uniqueNameIdToMyChildEntries = new TIntObjectHashMap<>(myChildrenSize - commonIndex);
    for (int i = commonIndex; i < myChildrenSize; ++i) {
        Entry childEntry = myChildren.get(i);
        uniqueNameIdToMyChildEntries.put(childEntry.getNameId(), childEntry);
    }
    TIntObjectHashMap<Entry> uniqueNameIdToRightChildEntries = new TIntObjectHashMap<>(rightChildrenSize - commonIndex);
    TIntObjectHashMap<Entry> myNameIdToRightChildEntries = new TIntObjectHashMap<>(rightChildrenSize - commonIndex);
    for (int i = commonIndex; i < rightChildrenSize; ++i) {
        Entry rightChildEntry = e.myChildren.get(i);
        int rightChildEntryNameId = rightChildEntry.getNameId();
        Entry myChildEntry = uniqueNameIdToMyChildEntries.get(rightChildEntryNameId);
        if (myChildEntry != null && myChildEntry.isDirectory() == rightChildEntry.isDirectory()) {
            uniqueNameIdToMyChildEntries.remove(rightChildEntryNameId);
            myNameIdToRightChildEntries.put(rightChildEntryNameId, rightChildEntry);
        } else {
            uniqueNameIdToRightChildEntries.put(rightChildEntryNameId, rightChildEntry);
        }
    }
    if (!Paths.isCaseSensitive() && uniqueNameIdToMyChildEntries.size() > 0 && uniqueNameIdToRightChildEntries.size() > 0) {
        THashMap<String, Entry> nameToEntryMap = new THashMap<>(uniqueNameIdToMyChildEntries.size(), CaseInsensitiveStringHashingStrategy.INSTANCE);
        uniqueNameIdToMyChildEntries.forEachValue(myChildEntry -> {
            nameToEntryMap.put(myChildEntry.getName(), myChildEntry);
            return true;
        });
        uniqueNameIdToRightChildEntries.forEachValue(rightChildEntry -> {
            Entry myChildEntry = nameToEntryMap.get(rightChildEntry.getName());
            if (myChildEntry != null && rightChildEntry.isDirectory() == myChildEntry.isDirectory()) {
                myNameIdToRightChildEntries.put(myChildEntry.getNameId(), rightChildEntry);
                uniqueNameIdToMyChildEntries.remove(myChildEntry.getNameId());
                uniqueNameIdToRightChildEntries.remove(rightChildEntry.getNameId());
            }
            return true;
        });
    }
    for (Entry child : e.myChildren) {
        if (uniqueNameIdToRightChildEntries.containsKey(child.getNameId())) {
            child.collectCreatedDifferences(result);
        }
    }
    for (Entry child : myChildren) {
        if (uniqueNameIdToMyChildEntries.containsKey(child.getNameId())) {
            child.collectDeletedDifferences(result);
        } else {
            Entry itsChild = myNameIdToRightChildEntries.get(child.getNameId());
            if (itsChild != null)
                child.collectDifferencesWith(itsChild, result);
        }
    }
}
Also used : THashMap(gnu.trove.THashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) Difference(com.intellij.history.core.revisions.Difference)

Aggregations

THashMap (gnu.trove.THashMap)132 NotNull (org.jetbrains.annotations.NotNull)33 THashSet (gnu.trove.THashSet)27 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Element (org.jdom.Element)18 PsiElement (com.intellij.psi.PsiElement)17 IOException (java.io.IOException)17 File (java.io.File)15 Map (java.util.Map)11 Nullable (org.jetbrains.annotations.Nullable)10 Project (com.intellij.openapi.project.Project)9 List (java.util.List)9 Module (com.intellij.openapi.module.Module)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)7 ArrayList (java.util.ArrayList)7 java.util (java.util)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)5 Document (com.intellij.openapi.editor.Document)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5