Search in sources :

Example 1 with LocalCssWriter

use of com.intellij.flex.uiDesigner.css.LocalCssWriter in project intellij-plugins by JetBrains.

the class ModuleInfoUtil method collectApplicationLocalStyle.

@Nullable
private static List<LocalStyleHolder> collectApplicationLocalStyle(final Module module, String flexSdkVersion, final ProblemsHolder problemsHolder, StringWriter stringWriter, ProjectComponentReferenceCounter projectComponentReferenceCounter, final AssetCounter assetCounter) {
    GlobalSearchScope moduleWithDependenciesAndLibrariesScope = module.getModuleWithDependenciesAndLibrariesScope(false);
    final List<JSClass> holders = new ArrayList<>(2);
    if (flexSdkVersion.charAt(0) > '3') {
        JSClass clazz = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.SPARK_APPLICATION, moduleWithDependenciesAndLibrariesScope));
        // it is not legal case, but user can use patched/modified Flex SDK
        if (clazz != null) {
            holders.add(clazz);
        }
    }
    JSClass mxApplicationClass = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.MX_APPLICATION, moduleWithDependenciesAndLibrariesScope));
    // if null, mx.swc is not added to module dependencies
    if (mxApplicationClass != null) {
        holders.add(mxApplicationClass);
    }
    if (holders.isEmpty()) {
        return null;
    }
    final StyleTagWriter styleTagWriter = new StyleTagWriter(new LocalCssWriter(stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter));
    final List<LocalStyleHolder> result = new ArrayList<>();
    final Processor<JSClass> processor = jsClass -> {
        PsiFile psiFile = jsClass.getNavigationElement().getContainingFile();
        if (!(psiFile instanceof XmlFile)) {
            return true;
        }
        XmlTag rootTag = ((XmlFile) psiFile).getRootTag();
        if (rootTag == null) {
            return true;
        }
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        problemsHolder.setCurrentFile(virtualFile);
        try {
            for (final XmlTag subTag : rootTag.getSubTags()) {
                if (subTag.getNamespace().equals(JavaScriptSupportLoader.MXML_URI3) && subTag.getLocalName().equals(FlexPredefinedTagNames.STYLE)) {
                    try {
                        LocalStyleHolder localStyleHolder = styleTagWriter.write(subTag, module, virtualFile);
                        if (localStyleHolder != null) {
                            result.add(localStyleHolder);
                        }
                    } catch (InvalidPropertyException e) {
                        problemsHolder.add(e);
                    }
                }
            }
        } finally {
            problemsHolder.setCurrentFile(null);
        }
        return true;
    };
    final GlobalSearchScope moduleScope = module.getModuleScope(false);
    for (JSClass holder : holders) {
        JSClassSearch.searchClassInheritors(holder, true, moduleScope).forEach(processor);
    }
    return result;
}
Also used : StringWriter(com.intellij.flex.uiDesigner.io.StringRegistry.StringWriter) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) Application(com.intellij.openapi.application.Application) JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) XmlFile(com.intellij.psi.xml.XmlFile) FlexPredefinedTagNames(com.intellij.javascript.flex.FlexPredefinedTagNames) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) FlexCommonTypeNames(com.intellij.javascript.flex.mxml.FlexCommonTypeNames) ActionScriptClassResolver(com.intellij.javascript.flex.resolve.ActionScriptClassResolver) JSClassSearch(com.intellij.lang.javascript.search.JSClassSearch) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) AccessToken(com.intellij.openapi.application.AccessToken) MxmlUtil(com.intellij.flex.uiDesigner.mxml.MxmlUtil) Semaphore(com.intellij.util.concurrency.Semaphore) LocalCssWriter(com.intellij.flex.uiDesigner.css.LocalCssWriter) Project(com.intellij.openapi.project.Project) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Module(com.intellij.openapi.module.Module) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) StylesheetFile(com.intellij.psi.css.StylesheetFile) XmlTag(com.intellij.psi.xml.XmlTag) DumbService(com.intellij.openapi.project.DumbService) XmlAttribute(com.intellij.psi.xml.XmlAttribute) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Library(com.intellij.flex.uiDesigner.libraries.Library) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) Collections(java.util.Collections) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalCssWriter(com.intellij.flex.uiDesigner.css.LocalCssWriter) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LocalCssWriter (com.intellij.flex.uiDesigner.css.LocalCssWriter)1 StringWriter (com.intellij.flex.uiDesigner.io.StringRegistry.StringWriter)1 Library (com.intellij.flex.uiDesigner.libraries.Library)1 MxmlUtil (com.intellij.flex.uiDesigner.mxml.MxmlUtil)1 ProjectComponentReferenceCounter (com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter)1 FlexPredefinedTagNames (com.intellij.javascript.flex.FlexPredefinedTagNames)1 FlexCommonTypeNames (com.intellij.javascript.flex.mxml.FlexCommonTypeNames)1 ActionScriptClassResolver (com.intellij.javascript.flex.resolve.ActionScriptClassResolver)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1 JavaScriptSupportLoader (com.intellij.lang.javascript.JavaScriptSupportLoader)1 FlexBuildConfigurationManager (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 JSClassSearch (com.intellij.lang.javascript.search.JSClassSearch)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Application (com.intellij.openapi.application.Application)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Module (com.intellij.openapi.module.Module)1 DumbService (com.intellij.openapi.project.DumbService)1 Project (com.intellij.openapi.project.Project)1