Search in sources :

Example 51 with THashMap

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

the class XmlLanguageInjector method getXmlAnnotatedElementsValue.

private Trinity<Long, Pattern, Collection<String>> getXmlAnnotatedElementsValue() {
    Trinity<Long, Pattern, Collection<String>> index = myXmlIndex;
    if (index == null || myConfiguration.getModificationCount() != index.first.longValue()) {
        final Map<ElementPattern<?>, BaseInjection> map = new THashMap<>();
        for (BaseInjection injection : myConfiguration.getInjections(XmlLanguageInjectionSupport.XML_SUPPORT_ID)) {
            for (InjectionPlace place : injection.getInjectionPlaces()) {
                if (!place.isEnabled() || place.getElementPattern() == null)
                    continue;
                map.put(place.getElementPattern(), injection);
            }
        }
        final Collection<String> stringSet = PatternValuesIndex.buildStringIndex(map.keySet());
        index = Trinity.create(myConfiguration.getModificationCount(), buildPattern(stringSet), stringSet);
        myXmlIndex = index;
    }
    return index;
}
Also used : ElementPattern(com.intellij.patterns.ElementPattern) Pattern(java.util.regex.Pattern) THashMap(gnu.trove.THashMap) ElementPattern(com.intellij.patterns.ElementPattern) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 52 with THashMap

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

the class AppEngineSdkUtil method computeWhiteList.

public static Map<String, Set<String>> computeWhiteList(final File toolsApiJarFile) {
    try {
        final THashMap<String, Set<String>> map = new THashMap<>();
        final ClassLoader loader = UrlClassLoader.build().urls(toolsApiJarFile.toURI().toURL()).parent(AppEngineSdkUtil.class.getClassLoader()).get();
        final Class<?> whiteListClass = Class.forName("com.google.apphosting.runtime.security.WhiteList", true, loader);
        final Set<String> classes = (Set<String>) whiteListClass.getMethod("getWhiteList").invoke(null);
        for (String qualifiedName : classes) {
            final String packageName = StringUtil.getPackageName(qualifiedName);
            Set<String> classNames = map.get(packageName);
            if (classNames == null) {
                classNames = new THashSet<>();
                map.put(packageName, classNames);
            }
            classNames.add(StringUtil.getShortName(qualifiedName));
        }
        return map;
    } catch (UnsupportedClassVersionError e) {
        LOG.warn(e);
        return Collections.emptyMap();
    } catch (Exception e) {
        LOG.error(e);
        return Collections.emptyMap();
    }
}
Also used : Set(java.util.Set) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) UrlClassLoader(com.intellij.util.lang.UrlClassLoader)

Example 53 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 54 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 55 with THashMap

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

the class SwcCatalogXmlUtil method getTimestampFromCatalogXml.

public static long getTimestampFromCatalogXml(@NotNull final PsiElement psiElement) {
    final Long cachedTimestamp = psiElement.getUserData(TIMESTAMP_IN_CATALOG_XML);
    if (cachedTimestamp != null) {
        return cachedTimestamp;
    }
    if (!(psiElement instanceof JSQualifiedNamedElement)) {
        return -1;
    }
    final String qName = ((JSQualifiedNamedElement) psiElement).getQualifiedName();
    if (StringUtil.isEmpty(qName)) {
        return -1;
    }
    final PsiFile psiFile = psiElement.getContainingFile();
    if (JavaScriptIndex.ECMASCRIPT_JS2.equals(psiFile.getName()))
        return Integer.MIN_VALUE;
    final VirtualFile swfFile = psiFile.getVirtualFile();
    final VirtualFile dir = swfFile != null && "swf".equalsIgnoreCase(swfFile.getExtension()) ? swfFile.getParent() : null;
    final VirtualFile catalogFile = dir == null ? null : dir.findChild("catalog.xml");
    if (catalogFile == null) {
        return -1;
    }
    Pair<Long, THashMap<String, TObjectLongHashMap<String>>> modStampAndSwfNameToQnameWithTimestampMap = catalogFile.getUserData(MOD_STAMP_AND_SWF_NAME_TO_QNAME_WITH_TIMESTAMP_MAP);
    if (modStampAndSwfNameToQnameWithTimestampMap == null || modStampAndSwfNameToQnameWithTimestampMap.first != catalogFile.getModificationStamp()) {
        final THashMap<String, TObjectLongHashMap<String>> swfNameToQnameWithTimestampMap = parseTimestampsFromCatalogXml(catalogFile);
        modStampAndSwfNameToQnameWithTimestampMap = Pair.create(catalogFile.getModificationStamp(), swfNameToQnameWithTimestampMap);
        catalogFile.putUserData(MOD_STAMP_AND_SWF_NAME_TO_QNAME_WITH_TIMESTAMP_MAP, modStampAndSwfNameToQnameWithTimestampMap);
    }
    final TObjectLongHashMap<String> qnameWithTimestampMap = modStampAndSwfNameToQnameWithTimestampMap.second.get(swfFile.getName());
    final long timestamp = qnameWithTimestampMap == null ? -1 : qnameWithTimestampMap.get(qName);
    psiElement.putUserData(TIMESTAMP_IN_CATALOG_XML, timestamp);
    return timestamp;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) THashMap(gnu.trove.THashMap) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiFile(com.intellij.psi.PsiFile)

Aggregations

THashMap (gnu.trove.THashMap)129 NotNull (org.jetbrains.annotations.NotNull)33 THashSet (gnu.trove.THashSet)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 Element (org.jdom.Element)18 PsiElement (com.intellij.psi.PsiElement)16 IOException (java.io.IOException)16 File (java.io.File)15 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 Map (java.util.Map)7 java.util (java.util)6 ArrayList (java.util.ArrayList)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)5 Document (com.intellij.openapi.editor.Document)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5