Search in sources :

Example 11 with JSAttributeNameValuePair

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

the class FlexFileReferenceHelper method registerFixes.

@NotNull
public List<? extends LocalQuickFix> registerFixes(final FileReference reference) {
    final PsiElement element = reference.getElement();
    if (!(reference instanceof JSFlexFileReference) || !(element instanceof JSAttributeNameValuePair))
        return Collections.emptyList();
    final PsiElement parent = element.getParent();
    if (!(parent instanceof JSAttribute) || !FlexAnnotationNames.EMBED.equals(((JSAttribute) parent).getName())) {
        return Collections.emptyList();
    }
    final String value = ((JSAttributeNameValuePair) element).getSimpleValue();
    if (value.startsWith("/"))
        return Collections.emptyList();
    final Module module = ModuleUtil.findModuleForPsiElement(element);
    if (module == null)
        return Collections.emptyList();
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
    final boolean testSourceRoot = virtualFile != null && rootManager.getFileIndex().isInTestSourceContent(virtualFile);
    for (VirtualFile sourceRoot : rootManager.getSourceRoots(testSourceRoot)) {
        if (sourceRoot.findFileByRelativePath(value) != null) {
            return Collections.singletonList(new AddLeadingSlashFix((JSAttributeNameValuePair) element));
        }
    }
    return Collections.emptyList();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSAttribute(com.intellij.lang.javascript.psi.ecmal4.JSAttribute) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with JSAttributeNameValuePair

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair 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 13 with JSAttributeNameValuePair

use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair 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)

Aggregations

JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)12 JSAttribute (com.intellij.lang.javascript.psi.ecmal4.JSAttribute)7 PsiElement (com.intellij.psi.PsiElement)6 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)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 JSFile (com.intellij.lang.javascript.psi.JSFile)2 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 Ref (com.intellij.openapi.util.Ref)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Nullable (org.jetbrains.annotations.Nullable)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 LocalQuickFixProvider (com.intellij.codeInspection.LocalQuickFixProvider)1 FlexCssPropertyDescriptor (com.intellij.javascript.flex.css.FlexCssPropertyDescriptor)1 AnnotationBackedDescriptorImpl (com.intellij.javascript.flex.mxml.schema.AnnotationBackedDescriptorImpl)1 CodeContext (com.intellij.javascript.flex.mxml.schema.CodeContext)1