Search in sources :

Example 1 with ClassBackedElementDescriptor

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

the class CreateFlexSkinIntention method getHostComponentClass.

@Nullable
private JSClass getHostComponentClass() {
    final XmlTag tag = myElement instanceof XmlTag ? ((XmlTag) myElement).getParentTag() : myElement instanceof XmlAttributeValue ? (XmlTag) myElement.getParent().getParent() : null;
    final XmlElementDescriptor descriptor = tag == null ? null : tag.getDescriptor();
    if (descriptor instanceof ClassBackedElementDescriptor) {
        final PsiElement declaration = descriptor.getDeclaration();
        if (declaration instanceof JSClass) {
            return (JSClass) declaration;
        }
    }
    return null;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ClassBackedElementDescriptor

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

the class MxmlWriter method processDeclarations.

void processDeclarations(XmlTag parent) {
    final int lengthPosition = out.allocateShort();
    int validChildrenCount = 0;
    for (XmlTag tag : parent.getSubTags()) {
        ClassBackedElementDescriptor descriptor = (ClassBackedElementDescriptor) tag.getDescriptor();
        assert descriptor != null;
        if (descriptor.isPredefined()) {
            // todo IDEA-72123
            if (descriptor.getName().equals(FlexPredefinedTagNames.MODEL)) {
                if (propertyProcessor.processFxModel(tag)) {
                    validChildrenCount++;
                }
            }
            continue;
        } else if (MxmlUtil.isComponentLanguageTag(tag)) {
            if (propertyProcessor.processFxComponent(tag, false)) {
                validChildrenCount++;
            }
            continue;
        }
        if (processClassBackedSubTag(tag, descriptor, null, true)) {
            validChildrenCount++;
        }
    }
    out.putShort(validChildrenCount, lengthPosition);
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)

Example 3 with ClassBackedElementDescriptor

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

the class PropertyProcessor method processClass.

// see ClassProperty test
private void processClass(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
    JSClass jsClass = valueProvider.getJsClass();
    // IDEA-73537, cannot use only valueProvider.getJsClass()
    if (jsClass == null) {
        String trimmed = valueProvider.getTrimmed();
        XmlElement exceptionElement = valueProvider.getElement();
        if (trimmed.isEmpty() && valueProvider.getElement() instanceof XmlTag) {
            // case 1, fx:Class
            final XmlTag propertyTag = (XmlTag) valueProvider.getElement();
            final XmlTag[] propertyTagSubTags = propertyTag.getSubTags();
            if (propertyTagSubTags.length == 1) {
                final XmlTag contentTag = propertyTagSubTags[0];
                exceptionElement = contentTag;
                final XmlElementDescriptor contentTagDescriptor = contentTag.getDescriptor();
                if (contentTagDescriptor instanceof ClassBackedElementDescriptor && AsCommonTypeNames.CLASS.equals(contentTagDescriptor.getQualifiedName())) {
                    trimmed = contentTag.getValue().getTrimmedText();
                }
            }
        }
        if (trimmed.isEmpty()) {
            throw new InvalidPropertyException(exceptionElement, "invalid.class.value");
        }
        final Module module = ModuleUtilCore.findModuleForPsiElement(valueProvider.getElement());
        if (module != null) {
            jsClass = (JSClass) ActionScriptClassResolver.findClassByQNameStatic(trimmed, module.getModuleWithDependenciesAndLibrariesScope(false));
        }
        if (jsClass == null) {
            throw new InvalidPropertyException(exceptionElement, "unresolved.class", trimmed);
        }
    }
    if (InjectionUtil.isProjectComponent(jsClass)) {
        if (ActionScriptClassResolver.isParentClass(jsClass, "spark.components.View")) {
            int projectComponentFactoryId = getProjectComponentFactoryId(jsClass);
            assert projectComponentFactoryId != -1;
            writer.projectClassReference(projectComponentFactoryId);
        } else {
            throw new InvalidPropertyException(valueProvider.getElement(), "class.reference.support.only.skin.class.or.view", jsClass.getQualifiedName());
        }
    } else {
        writer.classReference(jsClass.getQualifiedName());
    }
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 4 with ClassBackedElementDescriptor

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

the class PropertyProcessor method writeIfFxg.

private boolean writeIfFxg(XmlTag tag, XmlElementDescriptor descriptor, Context parentContext, boolean allowIncludeInExcludeFrom, PrimitiveAmfOutputStream out) {
    if (descriptor instanceof ClassBackedElementDescriptor) {
        PsiElement declaration = descriptor.getDeclaration();
        PsiFile psiFile = declaration.getContainingFile();
        VirtualFile virtualFile = psiFile.getVirtualFile();
        MxmlWriter.LOG.assertTrue(virtualFile != null);
        if (JavaScriptSupportLoader.isFxgFile(virtualFile)) {
            out.write(AmfExtendedTypes.REFERABLE);
            mxmlWriter.processIdAttributeOfFxTag(tag, parentContext, allowIncludeInExcludeFrom);
            out.write(AmfExtendedTypes.SWF);
            out.writeUInt29(EmbedSwfManager.getInstance().add(virtualFile, EmbedSwfManager.FXG_MARKER, writer.getAssetCounter()));
            return true;
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 5 with ClassBackedElementDescriptor

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

the class IncrementalDocumentSynchronizer method findSupportedTarget.

@Nullable
private XmlElementValueProvider findSupportedTarget() {
    PsiElement element = event.getParent();
    // if we change attribute value via line marker, so, event.getParent() will be XmlAttribute instead of XmlAttributeValue
    while (!(element instanceof XmlAttribute)) {
        element = element.getParent();
        if (element instanceof XmlTag) {
            XmlTag tag = (XmlTag) element;
            XmlElementDescriptor descriptor = tag.getDescriptor();
            if (descriptor instanceof ClassBackedElementDescriptor) {
                ClassBackedElementDescriptor classBackedElementDescriptor = (ClassBackedElementDescriptor) descriptor;
                if (classBackedElementDescriptor.isPredefined()) {
                    isStyleDataChanged = descriptor.getQualifiedName().equals(FlexPredefinedTagNames.STYLE);
                    isSkippedXml = isStyleDataChanged || (!MxmlUtil.isObjectLanguageTag(tag) && !descriptor.getQualifiedName().equals(FlexPredefinedTagNames.DECLARATIONS));
                }
            }
            return null;
        } else if (element instanceof PsiFile || element == null) {
            return null;
        }
    }
    XmlAttribute attribute = (XmlAttribute) element;
    if (JavaScriptSupportLoader.MXML_URI3.equals(attribute.getNamespace()) || attribute.getValueElement() == null) {
        return null;
    }
    XmlAttributeDescriptor xmlDescriptor = attribute.getDescriptor();
    if (!(xmlDescriptor instanceof AnnotationBackedDescriptor)) {
        return null;
    }
    AnnotationBackedDescriptor descriptor = (AnnotationBackedDescriptor) xmlDescriptor;
    if (descriptor.isPredefined() || MxmlUtil.isIdLanguageAttribute(attribute, descriptor)) {
        return null;
    }
    // todo incremental sync for state-specific attributes
    PsiReference[] references = attribute.getReferences();
    if (references.length > 1) {
        for (int i = references.length - 1; i > -1; i--) {
            PsiReference psiReference = references[i];
            if (psiReference instanceof FlexReferenceContributor.StateReference) {
                return null;
            }
        }
    } else {
        String prefix = attribute.getName() + '.';
        for (XmlAttribute anotherAttribute : attribute.getParent().getAttributes()) {
            if (anotherAttribute != attribute && anotherAttribute.getName().startsWith(prefix)) {
                return null;
            }
        }
    }
    XmlAttributeValueProvider valueProvider = new XmlAttributeValueProvider(attribute);
    // skip binding
    PsiLanguageInjectionHost injectedHost = valueProvider.getInjectedHost();
    if (injectedHost != null && InjectedLanguageUtil.hasInjections(injectedHost)) {
        return null;
    }
    return valueProvider;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeValueProvider(com.intellij.flex.uiDesigner.mxml.XmlAttributeValueProvider) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) 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