Search in sources :

Example 1 with XmlAttributeValueProvider

use of com.intellij.flex.uiDesigner.mxml.XmlAttributeValueProvider 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

XmlAttributeValueProvider (com.intellij.flex.uiDesigner.mxml.XmlAttributeValueProvider)1 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)1 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 Nullable (org.jetbrains.annotations.Nullable)1