Search in sources :

Example 11 with JSAttribute

use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.

the class InjectedPsiVisitor method processEmbedDirective.

private ValueWriter processEmbedDirective(JSAttribute attribute) {
    VirtualFile source = null;
    String mimeType = null;
    String symbol = null;
    for (JSAttributeNameValuePair p : attribute.getValues()) {
        final String name = p.getName();
        if (name == null || name.equals("source")) {
            try {
                source = InjectionUtil.getReferencedFile(p);
            } catch (InvalidPropertyException e) {
                problemsHolder.add(e);
                return InjectedASWriter.IGNORE;
            }
        } else if (name.equals("mimeType")) {
            mimeType = p.getSimpleValue();
        } else if (name.equals("symbol")) {
            symbol = p.getSimpleValue();
        }
    }
    if (source == null) {
        problemsHolder.add(host, FlashUIDesignerBundle.message("embed.source.not.specified", host.getText()));
        return InjectedASWriter.IGNORE;
    }
    if (InjectionUtil.isSwf(source, mimeType)) {
        return new SwfValueWriter(source, symbol);
    } else {
        if (symbol != null) {
            LOG.warn("Attribute symbol is unneeded for " + host.getText());
        }
        if (InjectionUtil.isImage(source, mimeType)) {
            return new ImageValueWriter(source, mimeType);
        } else {
            problemsHolder.add(host, FlashUIDesignerBundle.message("unsupported.embed.asset.type", host.getText()));
            return InjectedASWriter.IGNORE;
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException)

Example 12 with JSAttribute

use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.

the class InjectedPsiVisitor method processResourceDirective.

private ValueWriter processResourceDirective(JSAttribute attribute) {
    String key = null;
    PropertiesFile bundle = null;
    for (JSAttributeNameValuePair p : attribute.getValues()) {
        final String name = p.getName();
        if ("key".equals(name)) {
            key = p.getSimpleValue();
        } else if ("bundle".equals(name)) {
            try {
                // IDEA-74868
                final PsiFileSystemItem referencedPsiFile = InjectionUtil.getReferencedPsiFile(p);
                if (referencedPsiFile instanceof PropertiesFile) {
                    bundle = (PropertiesFile) referencedPsiFile;
                } else {
                    LOG.warn("skip resource directive, referenced file is not properties file " + host.getText());
                }
            } catch (InvalidPropertyException e) {
                invalidPropertyException = e;
                return InjectedASWriter.IGNORE;
            }
        }
    }
    if (key == null || key.isEmpty() || bundle == null) {
        LOG.warn("skip resource directive, one of the required attributes is missed " + host.getText());
        return InjectedASWriter.IGNORE;
    }
    final IProperty property = bundle.findPropertyByKey(key);
    if (property == null) {
        LOG.warn("skip resource directive, key not found " + host.getText());
        return InjectedASWriter.IGNORE;
    }
    return new ResourceDirectiveValueWriter(property.getUnescapedValue());
}
Also used : IProperty(com.intellij.lang.properties.IProperty) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Example 13 with JSAttribute

use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.

the class InjectedPsiVisitor method checkCompilerDirective.

private ValueWriter checkCompilerDirective(JSFile jsFile) {
    PsiElement firstChild = jsFile.getFirstChild();
    if (firstChild instanceof LeafPsiElement && ((LeafPsiElement) firstChild).getElementType() == JSTokenTypes.AT) {
        JSAttribute attribute = (JSAttribute) firstChild.getNextSibling();
        assert attribute != null;
        final String attributeName = attribute.getName();
        if (FlexAnnotationNames.EMBED.equals(attributeName)) {
            return processEmbedDirective(attribute);
        } else if (FlexAnnotationNames.RESOURCE.equals(attributeName)) {
            return processResourceDirective(attribute);
        } else {
            if (!StringUtil.isEmpty(attributeName)) {
                problemsHolder.add(host, FlashUIDesignerBundle.message("unsupported.compiler.directive", host.getText()));
            }
            return InjectedASWriter.IGNORE;
        }
    }
    return null;
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 14 with JSAttribute

use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.

the class FlexAttributeReferenceProvider method getBundleRefsCheckingParent.

private static PsiReference[] getBundleRefsCheckingParent(JSAttributeNameValuePairImpl element) {
    JSAttribute attribute = (JSAttribute) element.getParent();
    @NonNls final String parentName = attribute.getName();
    if (!FlexAnnotationNames.RESOURCE.equals(parentName))
        return PsiReference.EMPTY_ARRAY;
    return FlexPropertiesSupport.getResourceBundleReference(element, ourBundleInfoProvider);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute)

Example 15 with JSAttribute

use of com.intellij.lang.javascript.psi.ecmal4.JSAttribute in project intellij-plugins by JetBrains.

the class FlexCompilationUtils method replaceMacros.

private static String replaceMacros(final String wrapperText, final String outputFileName, final String targetPlayer, @Nullable final JSClass mainClass) {
    final Map<String, String> replacementMap = new THashMap<>();
    replacementMap.put(FlexCommonUtils.SWF_MACRO, outputFileName);
    replacementMap.put(FlexCommonUtils.TITLE_MACRO, outputFileName);
    replacementMap.put(FlexCommonUtils.APPLICATION_MACRO, outputFileName);
    replacementMap.put(FlexCommonUtils.BG_COLOR_MACRO, "#ffffff");
    replacementMap.put(FlexCommonUtils.WIDTH_MACRO, "100%");
    replacementMap.put(FlexCommonUtils.HEIGHT_MACRO, "100%");
    final List<String> versionParts = StringUtil.split(targetPlayer, ".");
    replacementMap.put(FlexCommonUtils.VERSION_MAJOR_MACRO, versionParts.size() >= 1 ? versionParts.get(0) : "0");
    replacementMap.put(FlexCommonUtils.VERSION_MINOR_MACRO, versionParts.size() >= 2 ? versionParts.get(1) : "0");
    replacementMap.put(FlexCommonUtils.VERSION_REVISION_MACRO, versionParts.size() >= 3 ? versionParts.get(2) : "0");
    final Ref<JSAttribute> swfMetadataRef = new Ref<>();
    final PsiFile psiFile = mainClass == null ? null : mainClass.getContainingFile();
    if (psiFile instanceof XmlFile) {
        final XmlTag rootTag = ((XmlFile) psiFile).getRootTag();
        if (rootTag != null) {
            final String ns = rootTag.getPrefixByNamespace(JavaScriptSupportLoader.MXML_URI3) == null ? JavaScriptSupportLoader.MXML_URI : JavaScriptSupportLoader.MXML_URI3;
            for (XmlTag tag : rootTag.findSubTags(FlexPredefinedTagNames.METADATA, ns)) {
                JSResolveUtil.processInjectedFileForTag(tag, new JSResolveUtil.JSInjectedFilesVisitor() {

                    @Override
                    protected void process(final JSFile file) {
                        for (PsiElement elt : file.getChildren()) {
                            if (elt instanceof JSAttributeList) {
                                final JSAttribute swfMetadata = ((JSAttributeList) elt).findAttributeByName("SWF");
                                if (swfMetadataRef.isNull() && swfMetadata != null) {
                                    swfMetadataRef.set(swfMetadata);
                                    return;
                                }
                            }
                        }
                    }
                });
            }
        }
    } else {
        final JSAttributeList attributeList = mainClass == null ? null : mainClass.getAttributeList();
        swfMetadataRef.set(attributeList == null ? null : attributeList.findAttributeByName("SWF"));
    }
    if (!swfMetadataRef.isNull()) {
        final JSAttribute swfMetadata = swfMetadataRef.get();
        final JSAttributeNameValuePair titleAttr = swfMetadata.getValueByName(FlexCommonUtils.TITLE_ATTR);
        ContainerUtil.putIfNotNull(FlexCommonUtils.TITLE_MACRO, titleAttr == null ? null : titleAttr.getSimpleValue(), replacementMap);
        final JSAttributeNameValuePair bgColorAttr = swfMetadata.getValueByName(FlexCommonUtils.BG_COLOR_ATTR);
        ContainerUtil.putIfNotNull(FlexCommonUtils.BG_COLOR_MACRO, bgColorAttr == null ? null : bgColorAttr.getSimpleValue(), replacementMap);
        final JSAttributeNameValuePair widthAttr = swfMetadata.getValueByName(FlexCommonUtils.WIDTH_ATTR);
        ContainerUtil.putIfNotNull(FlexCommonUtils.WIDTH_MACRO, widthAttr == null ? null : widthAttr.getSimpleValue(), replacementMap);
        final JSAttributeNameValuePair heightAttr = swfMetadata.getValueByName(FlexCommonUtils.HEIGHT_ATTR);
        ContainerUtil.putIfNotNull(FlexCommonUtils.HEIGHT_MACRO, heightAttr == null ? null : heightAttr.getSimpleValue(), replacementMap);
    }
    return FlexCommonUtils.replace(wrapperText, replacementMap);
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) XmlFile(com.intellij.psi.xml.XmlFile) JSResolveUtil(com.intellij.lang.javascript.psi.resolve.JSResolveUtil) 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) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

JSAttribute (com.intellij.lang.javascript.psi.ecmal4.JSAttribute)12 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)9 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)3 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)3 NonNls (org.jetbrains.annotations.NonNls)3 NotNull (org.jetbrains.annotations.NotNull)3 InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)2 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)2 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)2 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 JSReferenceSet (com.intellij.lang.javascript.psi.impl.JSReferenceSet)2 Ref (com.intellij.openapi.util.Ref)2 TextRange (com.intellij.openapi.util.TextRange)2 Nullable (org.jetbrains.annotations.Nullable)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)1