Search in sources :

Example 56 with THashMap

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

the class SwcCatalogXmlUtil method parseTimestampsFromCatalogXml.

@SuppressWarnings({ "unchecked" })
private static THashMap<String, TObjectLongHashMap<String>> parseTimestampsFromCatalogXml(@NotNull final VirtualFile catalogFile) {
    //  <swc xmlns="http://www.adobe.com/flash/swccatalog/9">
    //    <libraries>
    //      <library path="library.swf">                                                                    take swf name here
    //        <script name="flash/sampler/StackFrame" mod="1256700285949" signatureChecksum="121164004" >   name attribute is not FQN, take only mod here
    //          <def id="flash.sampler:Sample" />                                                           multiple defs possible
    //          <def id="flash.sampler:clearSamples" />
    //          ...
    final THashMap<String, TObjectLongHashMap<String>> swfNameToQnameWithTimestampMap = new THashMap<>(1);
    try {
        final Element rootElement = JDOMUtil.load(catalogFile.getInputStream());
        if (rootElement != null && "swc".equals(rootElement.getName())) {
            for (final Element librariesElement : rootElement.getChildren("libraries", rootElement.getNamespace())) {
                for (final Element libraryElement : librariesElement.getChildren("library", librariesElement.getNamespace())) {
                    final String swfName = libraryElement.getAttributeValue("path");
                    if (StringUtil.isEmpty(swfName)) {
                        continue;
                    }
                    final TObjectLongHashMap<String> qNameWithTimestampMap = new TObjectLongHashMap<>();
                    swfNameToQnameWithTimestampMap.put(swfName, qNameWithTimestampMap);
                    for (final Element scriptElement : libraryElement.getChildren("script", libraryElement.getNamespace())) {
                        final String mod = scriptElement.getAttributeValue("mod");
                        if (StringUtil.isEmpty(mod)) {
                            continue;
                        }
                        try {
                            final long timestamp = Long.parseLong(mod);
                            for (final Element defElement : scriptElement.getChildren("def", scriptElement.getNamespace())) {
                                final String id = defElement.getAttributeValue("id");
                                if (!StringUtil.isEmpty(id)) {
                                    final String fqn = id.replace(':', '.');
                                    qNameWithTimestampMap.put(fqn, timestamp);
                                }
                            }
                        } catch (NumberFormatException ignored) {
                        /*ignore*/
                        }
                    }
                }
            }
        }
    } catch (JDOMException ignored) {
    /*ignore*/
    } catch (IOException ignored) {
    /*ignore*/
    }
    return swfNameToQnameWithTimestampMap;
}
Also used : TObjectLongHashMap(gnu.trove.TObjectLongHashMap) THashMap(gnu.trove.THashMap) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Example 57 with THashMap

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

the class CompilerConfigGeneratorRt method addFilesIncludedInSwc.

private void addFilesIncludedInSwc(final Element rootElement) {
    final JpsCompilerExcludes excludes = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(myModule.getProject()).getCompilerExcludes();
    final Map<String, String> filePathToPathInSwc = new THashMap<>();
    for (String path : myBC.getCompilerOptions().getFilesToIncludeInSWC()) {
        final File fileOrDir = new File(path);
        if (excludes.isExcluded(fileOrDir))
            continue;
        if (myProjectDescriptor.getIgnoredFileIndex().isIgnored(fileOrDir.getName()))
            continue;
        final String baseRelativePath = StringUtil.notNullize(FlexCommonUtils.getPathRelativeToSourceRoot(myModule, fileOrDir.getPath()), fileOrDir.getName());
        if (fileOrDir.isDirectory()) {
            processFilesRecursively(fileOrDir, file -> {
                if (myProjectDescriptor.getIgnoredFileIndex().isIgnored(file.getName()))
                    return false;
                if (!file.isDirectory() && !FlexCommonUtils.isSourceFile(file.getName()) && !excludes.isExcluded(file)) {
                    final String relativePath = FileUtil.getRelativePath(fileOrDir, file);
                    assert relativePath != null;
                    final String pathInSwc = baseRelativePath.isEmpty() ? relativePath : baseRelativePath + "/" + relativePath;
                    filePathToPathInSwc.put(file.getPath(), pathInSwc);
                }
                return true;
            });
        } else if (fileOrDir.isFile()) {
            filePathToPathInSwc.put(fileOrDir.getPath(), baseRelativePath);
        }
    }
    for (Map.Entry<String, String> entry : filePathToPathInSwc.entrySet()) {
        final String value = FileUtil.toSystemIndependentName(entry.getValue()) + CompilerOptionInfo.LIST_ENTRY_PARTS_SEPARATOR + FileUtil.toSystemIndependentName(entry.getKey());
        addOption(rootElement, CompilerOptionInfo.INCLUDE_FILE_INFO, value);
    }
}
Also used : JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) THashMap(gnu.trove.THashMap) File(java.io.File) THashMap(gnu.trove.THashMap)

Example 58 with THashMap

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

the class ValidateFlashConfigurationsPrecompileTask method checkSimilarOutputFiles.

private static boolean checkSimilarOutputFiles(final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCsToCompile, final Consumer<Trinity<Module, FlexBuildConfiguration, FlashProjectStructureProblem>> errorConsumer) {
    final Map<String, Pair<Module, FlexBuildConfiguration>> outputPathToModuleAndBC = new THashMap<>();
    for (Pair<Module, FlexBuildConfiguration> moduleAndBC : modulesAndBCsToCompile) {
        final FlexBuildConfiguration bc = moduleAndBC.second;
        final String outputFilePath = bc.getActualOutputFilePath();
        checkOutputPathUnique(outputFilePath, moduleAndBC, outputPathToModuleAndBC, errorConsumer);
    }
    return true;
}
Also used : THashMap(gnu.trove.THashMap) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) Module(com.intellij.openapi.module.Module) Pair(com.intellij.openapi.util.Pair)

Example 59 with THashMap

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

the class ActionScriptSmartCompletionContributor method getEventsMap.

public static Map<String, String> getEventsMap(JSClass clazzToProcess) {
    if (clazzToProcess == null)
        return Collections.emptyMap();
    final Map<String, String> eventsMap = new THashMap<>();
    class EventsDataCollector extends ResolveProcessor implements ActionScriptResolveUtil.MetaDataProcessor {

        public EventsDataCollector() {
            super(null);
            setToProcessHierarchy(true);
            setToProcessMembers(false);
            setTypeContext(true);
            setLocalResolve(true);
        }

        @Override
        public boolean process(@NotNull final JSAttribute jsAttribute) {
            if ("Event".equals(jsAttribute.getName())) {
                final JSAttributeNameValuePair eventAttr = jsAttribute.getValueByName("name");
                JSAttributeNameValuePair typeAttr = jsAttribute.getValueByName("type");
                if (eventAttr != null && typeAttr != null) {
                    final String simpleValue = eventAttr.getSimpleValue();
                    if (simpleValue != null) {
                        eventsMap.put(simpleValue, typeAttr.getSimpleValue());
                    }
                }
            }
            return true;
        }

        @Override
        public boolean handleOtherElement(final PsiElement el, final PsiElement context, final Ref<PsiElement> continuePassElement) {
            return true;
        }

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            if (element instanceof JSClass) {
                ActionScriptResolveUtil.processMetaAttributesForClass(element, this, true);
            }
            return true;
        }
    }
    final EventsDataCollector eventsDataCollector = new EventsDataCollector();
    if (clazzToProcess instanceof XmlBackedJSClassImpl) {
        XmlFile file = (XmlFile) clazzToProcess.getParent().getContainingFile();
        if (file != null && JavaScriptSupportLoader.isFlexMxmFile(file)) {
            final XmlDocument xmlDocument = file.getDocument();
            final XmlTag rootTag = xmlDocument == null ? null : xmlDocument.getRootTag();
            final XmlTag[] tags = rootTag == null ? XmlTag.EMPTY : MxmlJSClass.findLanguageSubTags(rootTag, FlexPredefinedTagNames.METADATA);
            JSResolveUtil.JSInjectedFilesVisitor injectedFilesVisitor = new JSResolveUtil.JSInjectedFilesVisitor() {

                @Override
                protected void process(JSFile file) {
                    for (PsiElement element : file.getChildren()) {
                        if (element instanceof JSAttributeList) {
                            ActionScriptResolveUtil.processAttributeList(eventsDataCollector, null, (JSAttributeList) element, true, true);
                        }
                    }
                }
            };
            for (XmlTag tag : tags) {
                JSResolveUtil.processInjectedFileForTag(tag, injectedFilesVisitor);
            }
        }
    }
    clazzToProcess.processDeclarations(eventsDataCollector, ResolveState.initial(), clazzToProcess, clazzToProcess);
    return eventsMap;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) NotNull(org.jetbrains.annotations.NotNull) ResolveState(com.intellij.psi.ResolveState) Ref(com.intellij.openapi.util.Ref) THashMap(gnu.trove.THashMap) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 60 with THashMap

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

the class ResolveExternalInlineStyleSourceActionTest method testFindComponent.

@JSTestOptions({ JSTestOption.WithCssSupportLoader, JSTestOption.WithJsSupportLoader, JSTestOption.WithGumboSdk, JSTestOption.WithFlexFacet })
public void testFindComponent() throws Exception {
    Map<String, String> styles = new THashMap<>();
    styles.put("left", "10");
    styles.put("right", "10");
    ResolveExternalInlineStyleSourceAction action = new ResolveExternalInlineStyleSourceAction("innerComponentInDeclarations", "spark.components.Button", "left", styles, myModule);
    PsiElement element = (PsiElement) action.find();
    assertNotNull(element);
    assertEquals(1717, element.getTextOffset());
}
Also used : THashMap(gnu.trove.THashMap) PsiElement(com.intellij.psi.PsiElement) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

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