Search in sources :

Example 1 with MxmlBackedElementDescriptor

use of com.intellij.javascript.flex.mxml.schema.MxmlBackedElementDescriptor in project intellij-plugins by JetBrains.

the class MxmlWriter method processDefaultProperty.

// descriptor will be null if child is XmlText
@Nullable
private PropertyKind processDefaultProperty(XmlTag parentTag, XmlElementValueProvider valueProvider, @Nullable ClassBackedElementDescriptor descriptor, int childrenLength, @NotNull Context context) {
    final ClassBackedElementDescriptor parentDescriptor = (ClassBackedElementDescriptor) parentTag.getDescriptor();
    assert parentDescriptor != null;
    final AnnotationBackedDescriptor defaultDescriptor = parentDescriptor.getDefaultPropertyDescriptor();
    final boolean isXmlText = descriptor == null;
    if (defaultDescriptor == null) {
        final String className = parentDescriptor.getQualifiedName();
        final JSClass jsClass;
        if (parentDescriptor instanceof MxmlBackedElementDescriptor) {
            jsClass = (JSClass) ActionScriptClassResolver.findClassByQNameStatic(className, parentTag);
        } else {
            jsClass = (JSClass) parentDescriptor.getDeclaration();
        }
        final boolean isDirectContainerImpl = className.equals(FlexCommonTypeNames.ICONTAINER);
        if (isDirectContainerImpl || ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.ICONTAINER)) {
            if (isXmlText) {
                addProblem(parentTag, "initializer.cannot.be.represented.in.text", parentTag.getLocalName());
                return null;
            }
            if (!isDirectContainerImpl && isHaloNavigator(className, jsClass) && !ActionScriptClassResolver.isParentClass((JSClass) descriptor.getDeclaration(), FlexCommonTypeNames.INAVIGATOR_CONTENT)) {
                addProblem(parentTag, "children.must.be", parentTag.getLocalName(), FlexCommonTypeNames.INAVIGATOR_CONTENT);
                return null;
            }
            writer.classOrPropertyName("0");
            out.write(AmfExtendedTypes.MX_CONTAINER_CHILDREN);
            return PropertyKind.ARRAY;
        } else {
            // http://youtrack.jetbrains.net/issue/IDEA-66565
            addProblem(parentTag, "default.property.not.found", parentTag.getLocalName());
        }
    } else {
        // xmlText as default property with injection, see BindingToDeferredInstanceFromBytesBase
        if (isXmlText && writeXmlTextAsDefaultPropertyInjectedValue(parentTag, valueProvider, defaultDescriptor, context)) {
            return null;
        }
        if (defaultDescriptor.getType().equals(JSCommonTypeNames.ARRAY_CLASS_NAME) && defaultDescriptor.getArrayType() != null) {
            final String elementType = defaultDescriptor.getArrayType();
            context.setChildrenType(elementType);
            final boolean isString = elementType.equals(JSCommonTypeNames.STRING_CLASS_NAME);
            if (isString) {
                if (descriptor != null && !descriptor.getQualifiedName().equals(JSCommonTypeNames.STRING_CLASS_NAME)) {
                    addProblem(parentTag, "children.must.be", parentTag.getLocalName(), elementType);
                    return null;
                }
            } else {
                if (isXmlText) {
                    addProblem(parentTag, "initializer.cannot.be.represented.in.text", parentTag.getLocalName());
                    return PropertyKind.IGNORE;
                }
            }
        }
        writer.classOrPropertyName(defaultDescriptor.getName());
        if (defaultDescriptor.isDeferredInstance()) {
            writer.newInstance("com.intellij.flex.uiDesigner.flex.DeferredInstanceFromArray", 1, false).typeMarker(Amf3Types.ARRAY);
            return PropertyKind.ARRAY;
        } else {
            final String type = defaultDescriptor.getType();
            if (type.equals(JSCommonTypeNames.STRING_CLASS_NAME) || (isXmlText && childrenLength == 1 && (type.equals(JSCommonTypeNames.OBJECT_CLASS_NAME) || type.equals(JSCommonTypeNames.ANY_TYPE)))) {
                writeSubstitutedString(valueProvider.getSubstituted());
            } else if (defaultDescriptor.contentIsArrayable()) {
                out.write(type.equals(JSCommonTypeNames.ARRAY_CLASS_NAME) ? Amf3Types.ARRAY : AmfExtendedTypes.ARRAY_IF_LENGTH_GREATER_THAN_1);
                return PropertyKind.ARRAY;
            } else if (defaultDescriptor.getArrayType() != null) /* Vector */
            {
                if (isXmlText) {
                    LOG.warn("skip " + valueProvider.getElement() + " due to IDEA-73478");
                    return null;
                }
                writer.vectorHeader(defaultDescriptor.getArrayType());
                return PropertyKind.VECTOR;
            } else if (type.equals(JSCommonTypeNames.NUMBER_CLASS_NAME)) {
                out.writeAmfDouble(valueProvider.getTrimmed());
            } else if (type.equals(JSCommonTypeNames.BOOLEAN_CLASS_NAME)) {
                out.writeAmfBoolean(valueProvider.getTrimmed());
            } else {
                out.write(Amf3Types.OBJECT);
                return PropertyKind.COMPLEX;
            }
        }
    }
    return PropertyKind.PRIMITIVE;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) MxmlBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.MxmlBackedElementDescriptor) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)1 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)1 MxmlBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.MxmlBackedElementDescriptor)1 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 Nullable (org.jetbrains.annotations.Nullable)1