Search in sources :

Example 6 with ClassBackedElementDescriptor

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

the class ResolveExternalInlineStyleSourceAction method find.

public Navigatable find() {
    JSClass classElement = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(parentFqn, scope));
    assert classElement != null;
    XmlTag rootTag = ((XmlFile) classElement.getNavigationElement().getContainingFile()).getRootTag();
    assert rootTag != null && rootTag.getDescriptor() != null && rootTag.getDescriptor() instanceof ClassBackedElementDescriptor;
    return find(rootTag, true);
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlFile(com.intellij.psi.xml.XmlFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlTag(com.intellij.psi.xml.XmlTag)

Example 7 with ClassBackedElementDescriptor

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

the class SelectInDesigner method selectIn.

@Override
public void selectIn(SelectInContext context, boolean requestFocus) {
    UsageTrigger.trigger("FlashUIDesigner.selectIn");
    final PsiElement element = getPsiElement(context);
    if (element == null) {
        return;
    }
    DesignerApplicationManager.getInstance().renderIfNeed((XmlFile) element.getContainingFile(), info -> {
        int componentId = 0;
        if (!(element instanceof XmlFile)) {
            PsiElement effectiveElement = element;
            do {
                if (effectiveElement instanceof XmlTag && ((XmlTag) effectiveElement).getDescriptor() instanceof ClassBackedElementDescriptor) {
                    componentId = info.rangeMarkerIndexOf(effectiveElement);
                    if (componentId != -1) {
                        break;
                    }
                }
                effectiveElement = effectiveElement.getContext();
            } while (effectiveElement != null);
            if (componentId == -1) {
                componentId = 0;
                LogMessageUtil.LOG.warn("Can't find target component");
            }
        }
        Client.getInstance().selectComponent(info.getId(), componentId);
    });
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlFile(com.intellij.psi.xml.XmlFile) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 8 with ClassBackedElementDescriptor

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

the class IncrementalDocumentSynchronizer method incrementalSync.

private boolean incrementalSync(final DocumentInfo info) {
    final XmlElementValueProvider valueProvider = findSupportedTarget();
    if (valueProvider == null) {
        return false;
    }
    XmlTag tag = (XmlTag) valueProvider.getElement().getParent();
    if (!(tag.getDescriptor() instanceof ClassBackedElementDescriptor)) {
        return false;
    }
    int componentId = info.rangeMarkerIndexOf(tag);
    if (componentId == -1) {
        return false;
    }
    final AnnotationBackedDescriptor descriptor = (AnnotationBackedDescriptor) valueProvider.getPsiMetaData();
    assert descriptor != null;
    final String typeName = descriptor.getTypeName();
    final String type = descriptor.getType();
    if (type == null) {
        return !typeName.equals(FlexAnnotationNames.EFFECT);
    } else if (type.equals(JSCommonTypeNames.FUNCTION_CLASS_NAME) || typeName.equals(FlexAnnotationNames.EVENT)) {
        return true;
    }
    final StringRegistry.StringWriter stringWriter = new StringRegistry.StringWriter();
    //noinspection IOResourceOpenedButNotSafelyClosed
    final PrimitiveAmfOutputStream dataOut = new PrimitiveAmfOutputStream(new ByteArrayOutputStreamEx(16));
    PrimitiveWriter writer = new PrimitiveWriter(dataOut, stringWriter);
    boolean needRollbackStringWriter = true;
    try {
        if (descriptor.isAllowsPercentage()) {
            String value = valueProvider.getTrimmed();
            final boolean hasPercent;
            if (value.isEmpty() || ((hasPercent = value.endsWith("%")) && value.length() == 1)) {
                return true;
            }
            final String name;
            if (hasPercent) {
                name = descriptor.getPercentProxy();
                value = value.substring(0, value.length() - 1);
            } else {
                name = descriptor.getName();
            }
            stringWriter.write(name, dataOut);
            dataOut.writeAmfDouble(value);
        } else {
            stringWriter.write(descriptor.getName(), dataOut);
            if (!writer.writeIfApplicable(valueProvider, dataOut, descriptor)) {
                needRollbackStringWriter = false;
                stringWriter.rollback();
                return false;
            }
        }
        needRollbackStringWriter = false;
    } catch (InvalidPropertyException ignored) {
        return true;
    } catch (NumberFormatException ignored) {
        return true;
    } finally {
        if (needRollbackStringWriter) {
            stringWriter.rollback();
        }
    }
    Client.getInstance().updatePropertyOrStyle(info.getId(), componentId, stream -> {
        stringWriter.writeTo(stream);
        stream.write(descriptor.isStyle());
        dataOut.writeTo(stream);
    }).doWhenDone(() -> DesignerApplicationManager.createDocumentRenderedNotificationDoneHandler(true).consume(info));
    return true;
}
Also used : VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) XmlFile(com.intellij.psi.xml.XmlFile) FlexPredefinedTagNames(com.intellij.javascript.flex.FlexPredefinedTagNames) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) MxmlUtil(com.intellij.flex.uiDesigner.mxml.MxmlUtil) FlexAnnotationNames(com.intellij.javascript.flex.FlexAnnotationNames) ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) StylesheetFile(com.intellij.psi.css.StylesheetFile) XmlTag(com.intellij.psi.xml.XmlTag) ByteArrayOutputStreamEx(com.intellij.flex.uiDesigner.io.ByteArrayOutputStreamEx) XmlElementValueProvider(com.intellij.flex.uiDesigner.mxml.XmlElementValueProvider) XmlAttribute(com.intellij.psi.xml.XmlAttribute) DocumentInfo(com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) FlexReferenceContributor(com.intellij.javascript.flex.FlexReferenceContributor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PrimitiveWriter(com.intellij.flex.uiDesigner.mxml.PrimitiveWriter) Nullable(org.jetbrains.annotations.Nullable) Update(com.intellij.util.ui.update.Update) JSCommonTypeNames(com.intellij.lang.javascript.psi.JSCommonTypeNames) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) com.intellij.psi(com.intellij.psi) XmlAttributeValueProvider(com.intellij.flex.uiDesigner.mxml.XmlAttributeValueProvider) ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream) XmlElementValueProvider(com.intellij.flex.uiDesigner.mxml.XmlElementValueProvider) ByteArrayOutputStreamEx(com.intellij.flex.uiDesigner.io.ByteArrayOutputStreamEx) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) PrimitiveWriter(com.intellij.flex.uiDesigner.mxml.PrimitiveWriter) XmlTag(com.intellij.psi.xml.XmlTag)

Example 9 with ClassBackedElementDescriptor

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

the class ResolveExternalInlineStyleSourceAction method find.

private Navigatable find(XmlTag parent, boolean firstLevel) {
    for (XmlTag xmlTag : parent.getSubTags()) {
        String localName = xmlTag.getLocalName();
        if (firstLevel && ignoredRootTags.contains(localName)) {
            continue;
        }
        XmlElementDescriptor xmlTagDescriptor = xmlTag.getDescriptor();
        if (xmlTagDescriptor instanceof ClassBackedElementDescriptor) {
            Navigatable result;
            if (xmlTagDescriptor.getQualifiedName().equals(elementFqn)) {
                result = findTargetIfStyleDeclarationOwner(xmlTag);
                if (result != null) {
                    return result;
                }
            }
            result = find(xmlTag, false);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) Navigatable(com.intellij.pom.Navigatable)

Example 10 with ClassBackedElementDescriptor

use of com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor 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)

Aggregations

ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)14 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)8 XmlTag (com.intellij.psi.xml.XmlTag)6 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)5 Nullable (org.jetbrains.annotations.Nullable)5 InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)4 PsiElement (com.intellij.psi.PsiElement)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 XmlFile (com.intellij.psi.xml.XmlFile)3 PropertyKind (com.intellij.flex.uiDesigner.mxml.PropertyProcessor.PropertyKind)2 XmlAttributeValueProvider (com.intellij.flex.uiDesigner.mxml.XmlAttributeValueProvider)2 XmlAttribute (com.intellij.psi.xml.XmlAttribute)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 DocumentInfo (com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)1 ByteArrayOutputStreamEx (com.intellij.flex.uiDesigner.io.ByteArrayOutputStreamEx)1 PrimitiveAmfOutputStream (com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream)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