Search in sources :

Example 11 with InvalidPropertyException

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

the class PropertyProcessor method write.

@SuppressWarnings("StatementWithEmptyBody")
@Override
public PropertyKind write(AnnotationBackedDescriptor descriptor, XmlElementValueProvider valueProvider, PrimitiveAmfOutputStream out, BaseWriter writer, boolean isStyle, @Nullable Context parentContext) throws InvalidPropertyException {
    final String type = descriptor.getType();
    if (isStyle) {
        int flags = 0;
        if (isEffect()) {
            flags |= StyleFlags.EFFECT;
            out.write(flags);
            out.write(Amf3Types.OBJECT);
            return COMPLEX_STYLE;
        } else {
            out.write(flags);
        }
    } else if (isEffect()) {
        out.write(Amf3Types.OBJECT);
        return COMPLEX;
    }
    if (writeIfPrimitive(valueProvider, type, out, descriptor, isStyle, false)) {
    } else if (type.equals(JSCommonTypeNames.ARRAY_CLASS_NAME)) {
        if (!descriptor.isRichTextContent() && valueProvider instanceof XmlAttributeValueProvider && isInlineArray(valueProvider.getTrimmed())) {
            writeInlineArray(valueProvider);
        } else {
            out.write(Amf3Types.ARRAY);
            return ARRAY;
        }
    } else if (descriptor.getArrayType() != null) {
        if (valueProvider.getElement() instanceof XmlTag) {
            final XmlTag propertyTag = (XmlTag) valueProvider.getElement();
            final XmlTag[] subTags = propertyTag.getSubTags();
            if (subTags.length == 1) {
                final XmlTag contentTag = subTags[0];
                final XmlElementDescriptor contentTagDescriptor = contentTag.getDescriptor();
                if (contentTagDescriptor instanceof ClassBackedElementDescriptor && CodeContext.AS3_VEC_VECTOR_QUALIFIED_NAME.equals(contentTagDescriptor.getQualifiedName())) {
                    if (!mxmlWriter.processMxmlVector(contentTag, parentContext, false)) {
                        throw new InvalidPropertyException(contentTag, "invalid.vector.value");
                    }
                    return isStyle ? PRIMITIVE_STYLE : PRIMITIVE;
                }
            }
        }
        writer.vectorHeader(descriptor.getArrayType());
        return VECTOR;
    } else if (type.equals(JSCommonTypeNames.OBJECT_CLASS_NAME) || type.equals(JSCommonTypeNames.ANY_TYPE)) {
        final PropertyKind propertyKind = writeUntypedPropertyValue(out, valueProvider, descriptor, isStyle, parentContext);
        if (propertyKind != null) {
            return propertyKind;
        }
    } else if (type.equals(FlexCommonTypeNames.IFACTORY)) {
        writeClassFactory(valueProvider);
    } else {
        out.write(Amf3Types.OBJECT);
        return isStyle ? COMPLEX_STYLE : COMPLEX;
    }
    return isStyle ? PRIMITIVE_STYLE : PRIMITIVE;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) PropertyKind(com.intellij.flex.uiDesigner.mxml.PropertyProcessor.PropertyKind) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 12 with InvalidPropertyException

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

the class StateWriter method checkStateSpecificPropertyValue.

public boolean checkStateSpecificPropertyValue(MxmlWriter mxmlWriter, PropertyProcessor propertyProcessor, XmlElementValueProvider valueProvider, AnnotationBackedDescriptor descriptor, @NotNull Context context) {
    PsiReference[] references = valueProvider.getElement().getReferences();
    if (references.length < 2) {
        return false;
    }
    List<State> states = null;
    for (int i = references.length - 1; i > -1; i--) {
        PsiReference psiReference = references[i];
        if (psiReference instanceof StateReference) {
            // resolve is expensive for StateReference, so, we use string key (states name) instead of object key (states tag)
            states = nameToState.get(psiReference.getCanonicalText());
            break;
        }
    }
    if (states == null) {
        return false;
    }
    final List<State> filteredStates;
    if (context instanceof DynamicObjectContext) {
        final ArrayList<State> includeInStates = ((DynamicObjectContext) context).includeInStates;
        filteredStates = new ArrayList<>(states.size());
        for (State state : states) {
            if (includeInStates.contains(state)) {
                filteredStates.add(state);
            } else {
                MxmlWriter.LOG.warn("Skip " + valueProvider.getElement().getText() + " from " + state.name + " " + "due to element parent object included only in " + includeInStates);
            }
        }
        if (filteredStates.isEmpty()) {
            return true;
        }
    } else {
        filteredStates = states;
    }
    ValueWriter valueWriter = null;
    try {
        valueWriter = propertyProcessor.process(valueProvider.getElement(), valueProvider, descriptor, context);
    } catch (InvalidPropertyException ignored) {
    }
    if (valueWriter == null) {
        // binding is not yet supported for state specific
        return true;
    }
    final PrimitiveAmfOutputStream out = writer.getOut();
    SetPropertyOrStyle override = new SetPropertyOrStyle(writer.getBlockOut().startRange());
    writer.classOrPropertyName(propertyProcessor.isStyle() ? "com.intellij.flex.uiDesigner.flex.states.SetStyle" : "com.intellij.flex.uiDesigner.flex.states.SetProperty");
    writer.property(NAME).stringReference(propertyProcessor.getName());
    writer.property(VALUE);
    PropertyKind propertyKind;
    try {
        propertyKind = valueWriter.write(descriptor, valueProvider, out, writer, false, context);
    } catch (InvalidPropertyException ignored) {
        // todo handle invalidProperty for state
        throw new UnsupportedOperationException("");
    }
    if (propertyKind.isComplex()) {
        mxmlWriter.processPropertyTagValue(descriptor, (XmlTag) valueProvider.getElement(), context, propertyKind);
    }
    override.targetId = context.getOrAllocateId();
    if (pendingFirstSetProperty == null && context instanceof NullContext) {
        pendingFirstSetProperty = override;
    }
    writer.getBlockOut().endRange(override.dataRange);
    for (State state : filteredStates) {
        state.overrides.add(override);
    }
    return true;
}
Also used : StateReference(com.intellij.javascript.flex.FlexReferenceContributor.StateReference) PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream) PsiReference(com.intellij.psi.PsiReference) PropertyKind(com.intellij.flex.uiDesigner.mxml.PropertyProcessor.PropertyKind) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException)

Example 13 with InvalidPropertyException

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

the class LocalCssWriter method writeClassReference.

@Override
protected void writeClassReference(JSClass jsClass, FlexStyleIndexInfo info, CssString cssString) throws InvalidPropertyException {
    final int projectComponentFactoryId;
    if (info != null && info.getAttributeName().equals("skinClass")) {
        projectComponentFactoryId = InjectionUtil.getProjectComponentFactoryId(jsClass, projectComponentReferenceCounter);
    } else if (InjectionUtil.isProjectComponent(jsClass)) {
        throw new InvalidPropertyException(cssString, "class.reference.in.css.support.only.skin.class", jsClass.getQualifiedName());
    } else {
        projectComponentFactoryId = -1;
    }
    if (projectComponentFactoryId == -1) {
        super.writeClassReference(jsClass, info, cssString);
    } else {
        propertyOut.write(AmfExtendedTypes.DOCUMENT_FACTORY_REFERENCE);
        propertyOut.writeUInt29(projectComponentFactoryId);
    }
}
Also used : InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException)

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