Search in sources :

Example 36 with XmlNSDescriptor

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

the class AngularJSTagDescriptor method getElementDescriptor.

@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    XmlTag parent = contextTag.getParentTag();
    if (parent == null)
        return null;
    final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true);
    return descriptor == null ? null : descriptor.getElementDescriptor(childTag);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 37 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor in project android by JetBrains.

the class AndroidXmlTagDescriptor method getElementDescriptor.

@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    final XmlElementDescriptor descriptor = myParentDescriptor.getElementDescriptor(childTag, contextTag);
    if (descriptor != null) {
        return descriptor;
    }
    final XmlNSDescriptor nsDescriptor = getNSDescriptor();
    return nsDescriptor != null ? new AndroidAnyTagDescriptor(nsDescriptor) : null;
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 38 with XmlNSDescriptor

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

the class FlexHighlightingTest method testAfterRename.

@JSTestOptions({ JSTestOption.WithFlexFacet, JSTestOption.WithGumboSdk })
@SuppressWarnings({ "ConstantConditions" })
public void testAfterRename() throws Exception {
    configureByFile(getBasePath() + "/afterRename.xml");
    XmlNSDescriptor nsDescriptor = ((XmlFile) getFile()).getDocument().getRootTagNSDescriptor();
    assertTrue(nsDescriptor.toString(), nsDescriptor instanceof XmlNSDescriptorImpl);
    doDoTest(true, true);
    new RenameProcessor(getProject(), getFile(), "afterRename.mxml", false, false).run();
    assertEquals("afterRename.mxml", getFile().getName());
    assertFalse(myFile.isValid());
    myFile = myPsiManager.findFile(getFile().getVirtualFile().getParent().findChild("afterRename.mxml"));
    assertTrue(myFile.isValid());
    nsDescriptor = ((XmlFile) getFile()).getDocument().getRootTagNSDescriptor();
    assertTrue(nsDescriptor.toString(), nsDescriptor instanceof FlexMxmlNSDescriptor);
    doDoTest(true, true);
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) XmlFile(com.intellij.psi.xml.XmlFile) FlexMxmlNSDescriptor(com.intellij.javascript.flex.mxml.schema.FlexMxmlNSDescriptor) XmlNSDescriptorImpl(com.intellij.xml.impl.dtd.XmlNSDescriptorImpl)

Example 39 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor 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 40 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.

the class XsltContextProviderBase method fillFromSchema.

private static void fillFromSchema(PsiFile file, ElementNames names) {
    if (!(file instanceof XmlFile))
        return;
    final XmlFile f = (XmlFile) file;
    final XmlDocument d = f.getDocument();
    if (d == null)
        return;
    final XmlTag rootTag = d.getRootTag();
    if (rootTag == null)
        return;
    //noinspection unchecked
    names.dependencies.add(new NSDeclTracker(rootTag));
    try {
        final Map<String, String> namespaceDeclarations = rootTag.getLocalNamespaceDeclarations();
        final Collection<String> prefixes = namespaceDeclarations.keySet();
        final XmlElementFactory ef = XmlElementFactory.getInstance(file.getProject());
        int noSchemaNamespaces = 0;
        for (String prefix : prefixes) {
            final String namespace = namespaceDeclarations.get(prefix);
            if (isIgnoredNamespace(prefix, namespace))
                continue;
            final XmlTag tag = ef.createTagFromText("<dummy-tag xmlns='" + namespace + "' />", XMLLanguage.INSTANCE);
            final XmlDocument document = PsiTreeUtil.getParentOfType(tag, XmlDocument.class);
            final XmlNSDescriptor rootDescriptor = tag.getNSDescriptor(tag.getNamespace(), true);
            if (rootDescriptor == null || (rootDescriptor instanceof XmlNSDescriptorImpl && ((XmlNSDescriptorImpl) rootDescriptor).getTag() == null) || !rootDescriptor.getDeclaration().isPhysical()) {
                final QName any = QNameUtil.createAnyLocalName(namespace);
                names.elementNames.add(any);
                names.attributeNames.add(any);
                noSchemaNamespaces++;
                continue;
            }
            //noinspection unchecked
            names.dependencies.add(rootDescriptor.getDescriptorFile());
            //noinspection unchecked
            final Set<XmlElementDescriptor> history = new THashSet<>(150);
            final XmlElementDescriptor[] e = rootDescriptor.getRootElementsDescriptors(document);
            try {
                for (XmlElementDescriptor descriptor : e) {
                    processElementDescriptors(descriptor, tag, names, history, 0);
                }
            } catch (StopProcessingException e1) {
                Logger.getInstance(XsltContextProviderBase.class).error("Maximum recursion depth reached. Missing equals()/hashCode() implementation?", StringUtil.join(history, descriptor -> descriptor.getClass().getName() + "[" + descriptor.getQualifiedName() + "]", ", "));
            }
        }
        names.validateNames = names.elementNames.size() > noSchemaNamespaces;
    //            final QName any = QNameUtil.createAnyLocalName("");
    //            names.elementNames.add(any);
    //            names.attributeNames.add(any);
    } catch (IncorrectOperationException e) {
        Logger.getInstance(XsltContextProvider.class.getName()).error(e);
    }
}
Also used : NSDeclTracker(org.intellij.lang.xpath.xslt.util.NSDeclTracker) QName(javax.xml.namespace.QName) THashSet(gnu.trove.THashSet) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Aggregations

XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)87 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)60 XmlTag (com.intellij.psi.xml.XmlTag)52 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)32 XmlFile (com.intellij.psi.xml.XmlFile)21 Nullable (org.jetbrains.annotations.Nullable)11 XmlDocument (com.intellij.psi.xml.XmlDocument)10 PsiElement (com.intellij.psi.PsiElement)5 XmlAttribute (com.intellij.psi.xml.XmlAttribute)5 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)5 XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)5 CachedValue (com.intellij.psi.util.CachedValue)3 NotNull (org.jetbrains.annotations.NotNull)3 FlexMxmlNSDescriptor (com.intellij.javascript.flex.mxml.schema.FlexMxmlNSDescriptor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 HtmlTag (com.intellij.psi.html.HtmlTag)2 PsiMetaData (com.intellij.psi.meta.PsiMetaData)2 PsiElementProcessor (com.intellij.psi.search.PsiElementProcessor)2 XmlElementDescriptorImpl (com.intellij.xml.impl.schema.XmlElementDescriptorImpl)2