Search in sources :

Example 1 with PrimitiveAmfOutputStream

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

the class PropertyProcessor method writeInlineArray.

private void writeInlineArray(XmlElementValueProvider valueProvider) {
    final PrimitiveAmfOutputStream out = writer.getOut();
    out.write(Amf3Types.ARRAY);
    final int lengthPosition = out.allocateShort();
    int validChildrenCount = 0;
    final StringBuilder builder = StringBuilderSpinAllocator.alloc();
    final String value = valueProvider.getTrimmed();
    try {
        char quoteChar = '\'';
        boolean inQuotes = false;
        for (int index = 1, length = value.length(); index < length; index++) {
            char c = value.charAt(index);
            switch(c) {
                case '[':
                    if (inQuotes) {
                        builder.append(c);
                    }
                    break;
                case '"':
                case '\'':
                    if (inQuotes) {
                        if (quoteChar == c) {
                            inQuotes = false;
                        } else {
                            builder.append(c);
                        }
                    } else {
                        inQuotes = true;
                        quoteChar = c;
                    }
                    break;
                case ',':
                case ']':
                    if (inQuotes) {
                        builder.append(c);
                    } else {
                        int beginIndex = 0;
                        int endIndex = builder.length();
                        while (beginIndex < endIndex && builder.charAt(beginIndex) <= ' ') {
                            beginIndex++;
                        }
                        while (beginIndex < endIndex && builder.charAt(endIndex - 1) <= ' ') {
                            endIndex--;
                        }
                        if (endIndex == 0) {
                            writer.stringReference(XmlElementValueProvider.EMPTY);
                        } else {
                            out.write(Amf3Types.STRING);
                            out.writeAmfUtf(builder, false, beginIndex, endIndex);
                        }
                        validChildrenCount++;
                        builder.setLength(0);
                    }
                    break;
                default:
                    builder.append(c);
            }
        }
    } finally {
        StringBuilderSpinAllocator.dispose(builder);
    }
    out.putShort(validChildrenCount, lengthPosition);
}
Also used : PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream)

Example 2 with PrimitiveAmfOutputStream

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

the class StateWriter method writeDeferredInstance.

void writeDeferredInstance(DynamicObjectContext instance) {
    PrimitiveAmfOutputStream out = writer.getOut();
    if (instance.isWritten()) {
        writeDeferredInstanceKind(AmfExtendedTypes.OBJECT_REFERENCE, instance);
        out.writeUInt29(instance.id);
    } else {
        // IDEA-72004
        if (instance.overrideUserCount > 0) {
            instance.getOrAllocateId();
        }
        if (instance.id == -1) {
            writeDeferredInstanceKind(ObjectMetadata.NEVER_REFERRED, instance);
        } else {
            writeDeferredInstanceKind(ObjectMetadata.REFERRED, instance);
            instance.markAsWritten();
        }
        out.writeUInt29(BlockDataOutputStream.getDataRangeOwnLength(instance.getDataRange()) + 2);
        out.writeShort(instance.getReferredObjectsCount());
        writer.getBlockOut().append(instance.getDataRange());
        if (instance.id != -1) {
            out.writeUInt29(instance.id);
        }
    }
}
Also used : PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream)

Example 3 with PrimitiveAmfOutputStream

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

the class ExpressionBinding method writeFunction.

private static void writeFunction(JSFunction function, BaseWriter writer, @Nullable ValueReferenceResolver valueReferenceResolver, boolean isBinding, @Nullable JSCallExpression expression, @Nullable JSReferenceExpression methodExpression) throws InvalidPropertyException {
    final PrimitiveAmfOutputStream out = writer.getOut();
    JSExpression[] arguments;
    final int rollbackPosition;
    final int start;
    if (function.isConstructor()) {
        assert expression != null;
        arguments = expression.getArguments();
        final JSClass jsClass = (JSClass) function.getParent();
        // text="{new String('newString')}"
        writer.newInstance(jsClass.getQualifiedName(), arguments.length, true);
        rollbackPosition = out.allocateShort();
        start = out.size();
    } else {
        out.write(ExpressionMessageTypes.CALL);
        rollbackPosition = out.allocateShort();
        start = out.size();
        // text="{resourceManager.getString('core', 'viewSource')}"
        if (methodExpression != null) {
            JSReferenceExpression qualifier = (JSReferenceExpression) methodExpression.getQualifier();
            while (qualifier != null) {
                writer.classOrPropertyName(qualifier.getReferencedName());
                qualifier = (JSReferenceExpression) qualifier.getQualifier();
            }
        }
        out.write(0);
        writer.classOrPropertyName(function.getName());
        if (function.isGetProperty()) {
            out.write(isBinding ? -2 : -1);
            return;
        } else {
            assert expression != null;
            arguments = expression.getArguments();
            out.write(arguments.length);
        }
    }
    for (JSExpression argument : arguments) {
        writeExpression(argument, out, writer, valueReferenceResolver);
    }
    out.putShort(out.size() - start, rollbackPosition);
}
Also used : PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 4 with PrimitiveAmfOutputStream

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

the class PropertyProcessor method processFxComponent.

boolean processFxComponent(XmlTag tag, boolean allowNullableIdOrClassName) {
    String className = getAttributeValue(tag, "className");
    if (className != null && writeFxComponentReferenceIfProcessed(className)) {
        return true;
    }
    final MxmlObjectReference objectReference = processFxDeclarationId(tag, className, allowNullableIdOrClassName);
    if (objectReference == null && !allowNullableIdOrClassName) {
        return false;
    }
    final int objectReferenceId = objectReference == null ? writer.allocateAbsoluteStaticObjectId() : objectReference.id;
    final int sizePosition = writer.componentFactory(objectReferenceId);
    final XmlTag[] subTags = tag.getSubTags();
    final int objectTableSize;
    final PrimitiveAmfOutputStream out = writer.getOut();
    if (subTags.length == 1) {
        out.write(Amf3Types.OBJECT);
        Context context = writer.createInnerComponentContext(objectReference, objectReferenceId);
        mxmlWriter.processPropertyTagValue(null, tag, context, COMPLEX);
        objectTableSize = context.getScope().referenceCounter;
    } else {
        // as object without any properties
        writer.objectHeader("Object");
        writer.endObject();
        if (subTags.length > 1) {
            LOG.warn("Skip fx:component, only one root tag is allowed: " + tag.getText());
        }
        objectTableSize = 0;
    }
    out.putShort(out.size() - (sizePosition + 2), sizePosition);
    out.putShort(objectTableSize, sizePosition + 2);
    return true;
}
Also used : CodeContext(com.intellij.javascript.flex.mxml.schema.CodeContext) PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream)

Example 5 with PrimitiveAmfOutputStream

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

the class StateWriter method write.

public void write() {
    final PrimitiveAmfOutputStream out = writer.getOut();
    out.write(states.size());
    if (states.isEmpty()) {
        return;
    }
    for (State state : states) {
        writer.property(NAME).string(state.name);
        if (!state.overrides.isEmpty()) {
            writer.property(OVERRIDES).arrayHeader(state.overrides.size());
            for (OverrideBase override : state.overrides) {
                override.write(writer, this);
            }
        }
        // object State footer
        writer.endObject();
    }
    reset();
}
Also used : PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream)

Aggregations

PrimitiveAmfOutputStream (com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream)7 DocumentInfo (com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)1 InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)1 ByteArrayOutputStreamEx (com.intellij.flex.uiDesigner.io.ByteArrayOutputStreamEx)1 StringRegistry (com.intellij.flex.uiDesigner.io.StringRegistry)1 MxmlUtil (com.intellij.flex.uiDesigner.mxml.MxmlUtil)1 PrimitiveWriter (com.intellij.flex.uiDesigner.mxml.PrimitiveWriter)1 PropertyKind (com.intellij.flex.uiDesigner.mxml.PropertyProcessor.PropertyKind)1 XmlAttributeValueProvider (com.intellij.flex.uiDesigner.mxml.XmlAttributeValueProvider)1 XmlElementValueProvider (com.intellij.flex.uiDesigner.mxml.XmlElementValueProvider)1 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)1 FlexAnnotationNames (com.intellij.javascript.flex.FlexAnnotationNames)1 FlexPredefinedTagNames (com.intellij.javascript.flex.FlexPredefinedTagNames)1 FlexReferenceContributor (com.intellij.javascript.flex.FlexReferenceContributor)1 StateReference (com.intellij.javascript.flex.FlexReferenceContributor.StateReference)1 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)1 CodeContext (com.intellij.javascript.flex.mxml.schema.CodeContext)1 JavaScriptSupportLoader (com.intellij.lang.javascript.JavaScriptSupportLoader)1 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)1 JSCommonTypeNames (com.intellij.lang.javascript.psi.JSCommonTypeNames)1