Search in sources :

Example 76 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.

the class AngularJSTagDescriptorsProvider method getDescriptor.

@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
    final Project project = xmlTag.getProject();
    if (!(xmlTag instanceof HtmlTag && AngularIndexUtil.hasAngularJS(project)))
        return null;
    final String tagName = xmlTag.getName();
    final String directiveName = DirectiveUtil.normalizeAttributeName(tagName);
    final XmlNSDescriptor nsDescriptor = xmlTag.getNSDescriptor(xmlTag.getNamespace(), false);
    final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(xmlTag) : null;
    if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
        return null;
    }
    if ((NG_CONTAINER.equals(directiveName) || NG_CONTENT.equals(directiveName) || NG_TEMPLATE.equals(directiveName)) && AngularIndexUtil.hasAngularJS2(project)) {
        return new AngularJSTagDescriptor(directiveName, createDirective(xmlTag, directiveName));
    }
    JSImplicitElement directive = DirectiveUtil.getTagDirective(directiveName, project);
    if (DirectiveUtil.isAngular2Directive(directive) && !directive.getName().equals(tagName)) {
        // we've found directive via normalized name for Angular, it should not work
        directive = null;
    }
    if (directive == null && !tagName.equals(directiveName) && AngularIndexUtil.hasAngularJS2(project)) {
        directive = DirectiveUtil.getTagDirective(tagName, project);
        if (!DirectiveUtil.isAngular2Directive(directive))
            directive = null;
    }
    return directive != null ? new AngularJSTagDescriptor(directiveName, directive) : null;
}
Also used : Project(com.intellij.openapi.project.Project) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) HtmlTag(com.intellij.psi.html.HtmlTag) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement) Nullable(org.jetbrains.annotations.Nullable)

Example 77 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method getClassFromMxmlDescriptor.

@Nullable
private static JSClass getClassFromMxmlDescriptor(@NotNull CssSimpleSelector selector, @NotNull Module module) {
    final XmlElementDescriptor xmlElementDescriptor = getTypeSelectorDescriptor(selector, module);
    if (xmlElementDescriptor == null) {
        return null;
    }
    final PsiElement declaration = xmlElementDescriptor.getDeclaration();
    return declaration instanceof JSClass ? (JSClass) declaration : null;
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) ModuleUtilCore.findModuleForPsiElement(com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 78 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor 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 79 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.

the class ResolveExternalInlineStyleSourceAction method findTargetIfStyleDeclarationOwner.

private Navigatable findTargetIfStyleDeclarationOwner(XmlTag parent) {
    int foundCount = 0;
    Navigatable target = null;
    for (XmlAttribute attribute : parent.getAttributes()) {
        XmlAttributeDescriptor descriptor = attribute.getDescriptor();
        // 8
        if (descriptor instanceof AnnotationBackedDescriptor) {
            String ourValue = properties.get(descriptor.getName());
            if (ourValue != null) {
                if (attribute.getDisplayValue().equals(ourValue)) {
                    foundCount++;
                    if (descriptor.getName().equals(targetStyleName)) {
                        target = (Navigatable) attribute;
                    }
                    if (foundCount == properties.size()) {
                        return target;
                    }
                }
            }
        }
    }
    for (XmlTag tag : parent.getSubTags()) {
        XmlElementDescriptor descriptor = tag.getDescriptor();
        if (descriptor instanceof AnnotationBackedDescriptor && ((PsiPresentableMetaData) descriptor).getTypeName().equals(FlexAnnotationNames.STYLE)) {
            String ourValue = properties.get(descriptor.getName());
            if (ourValue != null) {
                if (tag.getSubTags().length == 0 && tag.getValue().getTrimmedText().equals(ourValue)) {
                    foundCount++;
                    if (descriptor.getName().equals(targetStyleName)) {
                        target = (Navigatable) tag;
                    }
                    if (foundCount == properties.size()) {
                        return target;
                    }
                }
            }
        }
    }
    return null;
}
Also used : PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) Navigatable(com.intellij.pom.Navigatable) XmlTag(com.intellij.psi.xml.XmlTag)

Example 80 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.

the class AngularJSAttributeDescriptorsProvider method getAttributeDescriptors.

@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag xmlTag) {
    if (xmlTag != null) {
        final Map<String, XmlAttributeDescriptor> result = new LinkedHashMap<>();
        final Project project = xmlTag.getProject();
        final XmlElementDescriptor descriptor = xmlTag.getDescriptor();
        final Collection<String> directives = AngularIndexUtil.getAllKeys(AngularDirectivesIndex.KEY, project);
        if (AngularIndexUtil.hasAngularJS2(project)) {
            if (descriptor instanceof HtmlElementDescriptorImpl) {
                final XmlAttributeDescriptor[] descriptors = ((HtmlElementDescriptorImpl) descriptor).getDefaultAttributeDescriptors(xmlTag);
                for (XmlAttributeDescriptor attributeDescriptor : descriptors) {
                    final String name = attributeDescriptor.getName();
                    if (name.startsWith("on")) {
                        addAttributes(project, result, "(" + name.substring(2) + ")", null);
                    }
                }
            }
            for (XmlAttribute attribute : xmlTag.getAttributes()) {
                final String name = attribute.getName();
                if (isAngular2Attribute(name, project) || !directives.contains(name))
                    continue;
                final PsiElement declaration = applicableDirective(project, name, xmlTag, AngularDirectivesIndex.KEY);
                if (isApplicable(declaration)) {
                    for (XmlAttributeDescriptor binding : AngularAttributeDescriptor.getFieldBasedDescriptors((JSImplicitElement) declaration)) {
                        result.put(binding.getName(), binding);
                    }
                }
            }
        }
        final Collection<String> docDirectives = AngularIndexUtil.getAllKeys(AngularDirectivesDocIndex.KEY, project);
        for (String directiveName : docDirectives) {
            PsiElement declaration = applicableDirective(project, directiveName, xmlTag, AngularDirectivesDocIndex.KEY);
            if (isApplicable(declaration)) {
                addAttributes(project, result, directiveName, declaration);
            }
        }
        for (String directiveName : directives) {
            if (!docDirectives.contains(directiveName)) {
                PsiElement declaration = applicableDirective(project, directiveName, xmlTag, AngularDirectivesIndex.KEY);
                if (isApplicable(declaration)) {
                    addAttributes(project, result, directiveName, declaration);
                }
            }
        }
        return result.values().toArray(new XmlAttributeDescriptor[result.size()]);
    }
    return XmlAttributeDescriptor.EMPTY;
}
Also used : Project(com.intellij.openapi.project.Project) HtmlElementDescriptorImpl(com.intellij.psi.impl.source.html.dtd.HtmlElementDescriptorImpl) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)159 XmlTag (com.intellij.psi.xml.XmlTag)88 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)60 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)54 PsiElement (com.intellij.psi.PsiElement)23 XmlFile (com.intellij.psi.xml.XmlFile)23 Nullable (org.jetbrains.annotations.Nullable)23 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)22 PsiFile (com.intellij.psi.PsiFile)11 ArrayList (java.util.ArrayList)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 NotNull (org.jetbrains.annotations.NotNull)10 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)7 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)7 Project (com.intellij.openapi.project.Project)7 HtmlTag (com.intellij.psi.html.HtmlTag)7 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)5 XmlDocument (com.intellij.psi.xml.XmlDocument)5 DElementPattern (org.kohsuke.rngom.digested.DElementPattern)5 InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)4