Search in sources :

Example 6 with InvalidPropertyException

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

the class ExpressionBinding method resolveReferenceExpression.

@NotNull
private static PsiElement resolveReferenceExpression(JSReferenceExpression expression, boolean qualificatorSupported) throws InvalidPropertyException {
    if (!qualificatorSupported) {
        checkQualifier(expression);
    }
    final AccessToken token = ReadAction.start();
    final PsiElement element;
    try {
        element = expression.resolve();
    } finally {
        token.finish();
    }
    if (element == null) {
        throw new InvalidPropertyException(expression, "unresolved.variable.or.type", expression.getReferencedName());
    }
    return element;
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with InvalidPropertyException

use of com.intellij.flex.uiDesigner.InvalidPropertyException 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 8 with InvalidPropertyException

use of com.intellij.flex.uiDesigner.InvalidPropertyException 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 9 with InvalidPropertyException

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

the class MxmlWriter method write.

@Nullable
public Pair<ProjectComponentReferenceCounter, List<RangeMarker>> write(XmlFile psiFile) throws IOException {
    document = MxmlUtil.getDocumentAndWaitIfNotCommitted(psiFile);
    final AccessToken token = ReadAction.start();
    try {
        VirtualFile virtualFile = psiFile.getVirtualFile();
        LOG.assertTrue(virtualFile != null);
        problemsHolder.setCurrentFile(virtualFile);
        XmlTag tag = psiFile.getRootTag();
        XmlElementDescriptor untypedDescriptor = tag == null ? null : tag.getDescriptor();
        final ClassBackedElementDescriptor descriptor;
        if (untypedDescriptor instanceof ClassBackedElementDescriptor) {
            descriptor = (ClassBackedElementDescriptor) untypedDescriptor;
        } else {
            return null;
        }
        final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
        try {
            PsiElement declaration = descriptor.getDeclaration();
            if (declaration == null) {
                return null;
            }
            effectiveClassInfo = MxmlUtil.computeEffectiveClass(tag, declaration, projectComponentReferenceCounter, true);
        } catch (InvalidPropertyException e) {
            problemsHolder.add(e);
            return null;
        }
        if (effectiveClassInfo.first == -1) {
            out.write(Amf3Types.OBJECT);
            writer.mxmlObjectHeader(effectiveClassInfo.second == null ? descriptor.getQualifiedName() : effectiveClassInfo.second);
        } else {
            writer.documentReference(effectiveClassInfo.first);
            out.allocateClearShort();
        }
        processElements(tag, null, false, -1, out.size() - 2, true, effectiveClassInfo.third);
        writer.endObject();
        if (stateWriter != null) {
            stateWriter.write();
            hasStates = false;
        } else {
            out.write(0);
        }
        injectedASWriter.write();
        writer.writeMessageHeader(projectComponentReferenceCounter);
        return Pair.create(projectComponentReferenceCounter, rangeMarkers);
    } finally {
        token.finish();
        problemsHolder.setCurrentFile(null);
        writer.resetAfterMessage();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Condition(com.intellij.openapi.util.Condition) ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) AccessToken(com.intellij.openapi.application.AccessToken) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with InvalidPropertyException

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

the class MxmlWriter method processTagChildren.

boolean processTagChildren(final XmlTag tag, @NotNull final Context context, @Nullable final Context parentContext, final boolean propertiesExpected, @Nullable PropertyKind propertyKind) {
    int lengthPosition = propertyKind != null && propertyKind.isList() ? out.allocateShort() : 0;
    int explicitContentOccurred = -1;
    int validAndStaticChildrenCount = 0;
    final XmlTagChild[] children = tag.getValue().getChildren();
    // if we process property tag value - if we cannot set value due to invalid content, so, we don't write property,
    // otherwise if there is no content, we write explicit null
    boolean invalidValue = false;
    for (XmlTagChild child : children) {
        if (child instanceof XmlTag) {
            XmlTag childTag = (XmlTag) child;
            XmlElementDescriptor descriptor = childTag.getDescriptor();
            if (descriptor == null) {
                LOG.warn("Descriptor is null, skip " + child);
                invalidValue = true;
                continue;
            }
            assert descriptor != null;
            if (descriptor instanceof ClassBackedElementDescriptor) {
                final ClassBackedElementDescriptor classBackedDescriptor = (ClassBackedElementDescriptor) descriptor;
                if (classBackedDescriptor.isPredefined()) {
                    if (MxmlUtil.isObjectLanguageTag(tag)) {
                        // IDEA-73482
                        processPropertyTag(childTag, new AnyXmlAttributeDescriptorWrapper(descriptor), context);
                    } else if (descriptor.getQualifiedName().equals(FlexPredefinedTagNames.DECLARATIONS)) {
                        injectedASWriter.readDeclarations(this, childTag);
                    }
                    continue;
                } else if (MxmlUtil.isAbstract(classBackedDescriptor)) {
                    addProblem(child, "abstract.class", classBackedDescriptor.getQualifiedName());
                    continue;
                }
                if (explicitContentOccurred == 1) {
                    LOG.warn("Default content already processed, skip " + child);
                    continue;
                }
                if (propertiesExpected && explicitContentOccurred == -1) {
                    explicitContentOccurred = 0;
                    final PropertyKind defaultPropertyKind = processDefaultProperty(tag, valueProviderFactory.create(childTag), classBackedDescriptor, children.length, context);
                    if (defaultPropertyKind == null) {
                        continue;
                    } else if (defaultPropertyKind.isList()) {
                        lengthPosition = out.allocateShort();
                        propertyKind = defaultPropertyKind;
                    } else if (defaultPropertyKind == PropertyKind.PRIMITIVE) {
                        validAndStaticChildrenCount++;
                        continue;
                    }
                }
                if (processClassBackedSubTag(childTag, classBackedDescriptor, context, propertyKind != null && propertyKind.isList())) {
                    validAndStaticChildrenCount++;
                }
            } else if (propertiesExpected && descriptor instanceof AnnotationBackedDescriptor) {
                AnnotationBackedDescriptor annotationBackedDescriptor = (AnnotationBackedDescriptor) descriptor;
                // skip invalid, contiguous child elements already processed and explicit content (i.e. AnnotationBackedDescriptor, property childTag) was occurred
                if (explicitContentOccurred == 0) {
                    explicitContentOccurred = 1;
                    if (propertyKind != null && propertyKind.isList()) {
                        endList(validAndStaticChildrenCount, lengthPosition);
                    }
                }
                if (childTag.getNamespace().equals(MxmlJSClass.MXML_URI4) && childTag.getLocalName().equals(FlexStateElementNames.STATES)) {
                    if (childTag.getSubTags().length != 0) {
                        hasStates = true;
                        assert parentContext == null;
                        if (stateWriter == null) {
                            stateWriter = new StateWriter(writer);
                        }
                        stateWriter.readDeclaration(childTag);
                    }
                } else {
                    processPropertyTag(childTag, annotationBackedDescriptor, context);
                }
            }
        } else if (child instanceof XmlText && !MxmlUtil.containsOnlyWhitespace(child)) {
            if (explicitContentOccurred == 1) {
                LOG.warn("Default content already processed, skip '" + child.getText().trim() + "'");
                continue;
            }
            if (context.getChildrenType() != null && !context.getChildrenType().equals(JSCommonTypeNames.STRING_CLASS_NAME)) {
                LOG.warn("Illegal child type, skip '" + child.getText().trim() + "'");
                continue;
            }
            if (propertiesExpected && explicitContentOccurred == -1) {
                explicitContentOccurred = 0;
                final XmlElementValueProvider valueProvider = valueProviderFactory.create((XmlText) child);
                final PropertyKind defaultPropertyKind = processDefaultProperty(tag, valueProvider, null, children.length, context);
                if (defaultPropertyKind == PropertyKind.IGNORE) {
                    explicitContentOccurred = -1;
                    continue;
                } else if (defaultPropertyKind == null) {
                    continue;
                } else if (defaultPropertyKind.isList()) {
                    lengthPosition = out.allocateShort();
                    propertyKind = defaultPropertyKind;
                } else if (defaultPropertyKind == PropertyKind.PRIMITIVE) {
                    validAndStaticChildrenCount++;
                    continue;
                } else {
                    final ValueWriter valueWriter;
                    try {
                        valueWriter = propertyProcessor.processXmlTextAsDefaultPropertyWithComplexType(valueProvider, tag, context);
                    } catch (InvalidPropertyException e) {
                        // we don't need any out rollback - nothing is written yet
                        problemsHolder.add(e);
                        continue;
                    }
                    if (valueWriter == null) {
                        throw new IllegalArgumentException("unexpected default property kind " + defaultPropertyKind);
                    } else if (valueWriter == InjectedASWriter.IGNORE) {
                        continue;
                    }
                }
            } else if (propertyKind == PropertyKind.VECTOR) {
                LOG.warn("skip " + child + " due to IDEA-73478");
                // IDEA-73478, XmlText allowed only for fx:Array, but not for fx:Vector (even with type String)
                break;
            }
            if (propertyKind != null && propertyKind == PropertyKind.COMPLEX) {
                invalidValue = true;
                LOG.warn("Text is not expected" + child);
            } else {
                writer.string(((XmlText) child).getValue());
                validAndStaticChildrenCount++;
            }
        }
    }
    if (propertyKind != null && propertyKind.isList()) {
        endList(validAndStaticChildrenCount, lengthPosition);
    } else if (!propertiesExpected && validAndStaticChildrenCount == 0) {
        if (invalidValue) {
            return false;
        }
        // PropertyAsTagWithCommentedValueAsTag, replace Amf3Types.OBJECT to Amf3Types.NULL
        out.putByte(Amf3Types.NULL, out.size() - 1);
    }
    return true;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) PropertyKind(com.intellij.flex.uiDesigner.mxml.PropertyProcessor.PropertyKind) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Aggregations

InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)13 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)5 PsiElement (com.intellij.psi.PsiElement)5 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)4 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)4 PropertyKind (com.intellij.flex.uiDesigner.mxml.PropertyProcessor.PropertyKind)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)2 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)2 AccessToken (com.intellij.openapi.application.AccessToken)2 Condition (com.intellij.openapi.util.Condition)2 PrimitiveAmfOutputStream (com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream)1 StateReference (com.intellij.javascript.flex.FlexReferenceContributor.StateReference)1 IProperty (com.intellij.lang.properties.IProperty)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 Module (com.intellij.openapi.module.Module)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 Trinity (com.intellij.openapi.util.Trinity)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1 PsiReference (com.intellij.psi.PsiReference)1