com.intellij.xml.XmlElementDescriptor Java Examples

The following examples show how to use com.intellij.xml.XmlElementDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RTErrorFilter.java    From react-templates-plugin with MIT License 6 votes vote down vote up
@Override
    public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement error) {
        final Project project = error.getProject();
        final Language language = error.getLanguage();
//        if ("CSS".equals(language.getID()) && PsiTreeUtil.getParentOfType(error, XmlAttribute.class) != null &&
//                AngularIndexUtil.hasAngularJS(project)) {
//            final PsiFile file = error.getContainingFile();
//
//            PsiErrorElement nextError = error;
//            while (nextError != null) {
//                if (hasAngularInjectionAt(project, file, nextError.getTextOffset())) return false;
//                nextError = PsiTreeUtil.getNextSiblingOfType(nextError, PsiErrorElement.class);
//            }
//        }
        if (HTMLLanguage.INSTANCE.is(language) && error.getErrorDescription().endsWith("not closed")) {
            System.out.println(error.getErrorDescription());
            final PsiElement parent = error.getParent();
            final XmlElementDescriptor descriptor = parent instanceof XmlTag ? ((XmlTag) parent).getDescriptor() : null;
            return !(descriptor instanceof RTRequireTagDescriptor);
        }
        return true;
    }
 
Example #2
Source File: ViewHelperUtil.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Nullable
public static XmlElementDescriptor xmlElementDescriptorForCurrentTag(@NotNull Project project, @NotNull XmlTag tag) {
    String tagName = tag.getName();

    // Fluid ViewHelpers are always prefixed
    if (tag.getNamespacePrefix().isEmpty()) {
        return null;
    }

    boolean tagDefinedByNamespace = XmlUtil.isTagDefinedByNamespace(tag);
    if (tagDefinedByNamespace) {
        // return null;
    }

    ViewHelper viewHelperInContext = findViewHelperInContext(project, tag, tagName);
    if (viewHelperInContext == null) {
        return null;
    }

    return new ViewHelperXmlElementDescriptor(tagName, tag, viewHelperInContext);
}
 
Example #3
Source File: RTErrorFilter.java    From react-templates-plugin with MIT License 6 votes vote down vote up
@Override
    public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement error) {
        final Project project = error.getProject();
        final Language language = error.getLanguage();
//        if ("CSS".equals(language.getID()) && PsiTreeUtil.getParentOfType(error, XmlAttribute.class) != null &&
//                AngularIndexUtil.hasAngularJS(project)) {
//            final PsiFile file = error.getContainingFile();
//
//            PsiErrorElement nextError = error;
//            while (nextError != null) {
//                if (hasAngularInjectionAt(project, file, nextError.getTextOffset())) return false;
//                nextError = PsiTreeUtil.getNextSiblingOfType(nextError, PsiErrorElement.class);
//            }
//        }
        if (HTMLLanguage.INSTANCE.is(language) && error.getErrorDescription().endsWith("not closed")) {
            System.out.println(error.getErrorDescription());
            final PsiElement parent = error.getParent();
            final XmlElementDescriptor descriptor = parent instanceof XmlTag ? ((XmlTag) parent).getDescriptor() : null;
            return !(descriptor instanceof RTRequireTagDescriptor);
        }
        return true;
    }
 
Example #4
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Nullable
public static MuleElementType getMuleElementTypeFromXmlElement(XmlTag xmlTag) {
    final XmlElementDescriptor descriptor = xmlTag.getDescriptor();
    if (descriptor instanceof XmlElementDescriptorImpl) {
        final XmlElementDescriptorImpl xmlElementDescriptor = (XmlElementDescriptorImpl) descriptor;
        final TypeDescriptor schemaType = xmlElementDescriptor.getType();
        if (schemaType instanceof ComplexTypeDescriptor) {
            final XmlTag complexTypeTag = schemaType.getDeclaration();
            final MuleElementType typeReference = MuleSchemaUtils.getElementTypeFromComplexType(complexTypeTag);
            if (typeReference != null) {
                return typeReference;
            }
        }
    } else {
        //This is to handle unknown elements
        if (!(xmlTag.getName().equals("description")) && isContainer(xmlTag.getParentTag())) {
            return (isKnownMS(xmlTag)) ? MuleElementType.MESSAGE_SOURCE : MuleElementType.MESSAGE_PROCESSOR;
        }
    }
    return null;
}
 
Example #5
Source File: XmlDescriptorUtil.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public static XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    final XmlDocument document = PsiTreeUtil.getParentOfType(contextTag, XmlDocument.class);
    if (document == null) {
        return null;
    }
    final XmlNSDescriptor nsDescriptor = document.getDefaultNSDescriptor(childTag.getNamespace(), true);
    if (nsDescriptor instanceof XmlNSDescriptorEx) {
        XmlElementDescriptor descriptor = ((XmlNSDescriptorEx) nsDescriptor).getElementDescriptor(childTag.getLocalName(), childTag.getNamespace());
        return descriptor != null ? wrapInDelegating(descriptor) : null;
    }
    return null;
}
 
Example #6
Source File: RTRequireTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@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);
}
 
Example #7
Source File: RTTagDescriptorsProvider.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Nullable
    @Override
    public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
//        System.out.println("getDescriptor " + xmlTag);
        if (!(xmlTag instanceof HtmlTag && RTProjectComponent.isEnabled(xmlTag.getProject()))) {
            return null;
        }
        final String directiveName = DirectiveUtil.normalizeAttributeName(xmlTag.getName());
        if (directiveName.equals(RT_REQUIRE)) {
            return new RTRequireTagDescriptor(RT_REQUIRE, xmlTag);
        }
        if (directiveName.equals(RT_IMPORT)) {
            return new RTImportTagDescriptor(RT_IMPORT, xmlTag);
        }

        if (xmlTag.getContainingFile() instanceof XmlFile) {
            List<String> tags = RTHtmlExtension.loadImportedTags((XmlFile) xmlTag.getContainingFile(), xmlTag);
            for (String tag : tags) {
                if (Strings.areEqual(tag, directiveName)) {
                    return new RTClassTagDescriptor(directiveName, xmlTag);
                }
            }
        }
        // TODO: support required tags
        //return new AnyXmlElementDescriptor()
        return null;
    }
 
Example #8
Source File: RTImportTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@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);
}
 
Example #9
Source File: RTClassTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@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);
}
 
Example #10
Source File: ISMLTagDescriptorsProvider.java    From intellij-demandware with MIT License 5 votes vote down vote up
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag tag) {
    if (!(tag instanceof HtmlTag)) {
        return null;
    }

    final XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(tag.getNamespace(), false);
    final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(tag) : null;
    if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
        return null;
    }

    return new ISMLTagDescriptor(tag.getName(), tag);
}
 
Example #11
Source File: ISMLTagDescriptor.java    From intellij-demandware with MIT License 5 votes vote down vote up
@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);
}
 
Example #12
Source File: RTRequireTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@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);
}
 
Example #13
Source File: RTTagDescriptorsProvider.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Nullable
    @Override
    public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
//        System.out.println("getDescriptor " + xmlTag);
        if (!(xmlTag instanceof HtmlTag && RTProjectComponent.isEnabled(xmlTag.getProject()))) {
            return null;
        }
        final String directiveName = DirectiveUtil.normalizeAttributeName(xmlTag.getName());
        if (directiveName.equals(RT_REQUIRE)) {
            return new RTRequireTagDescriptor(RT_REQUIRE, xmlTag);
        }
        if (directiveName.equals(RT_IMPORT)) {
            return new RTImportTagDescriptor(RT_IMPORT, xmlTag);
        }

        if (xmlTag.getContainingFile() instanceof XmlFile) {
            List<String> tags = RTHtmlExtension.loadImportedTags((XmlFile) xmlTag.getContainingFile(), xmlTag);
            for (String tag : tags) {
                if (Strings.areEqual(tag, directiveName)) {
                    return new RTClassTagDescriptor(directiveName, xmlTag);
                }
            }
        }
        // TODO: support required tags
        //return new AnyXmlElementDescriptor()
        return null;
    }
 
Example #14
Source File: RTImportTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@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);
}
 
Example #15
Source File: RTClassTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@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);
}
 
Example #16
Source File: FlowRenameHandler.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private boolean shouldBeRenamedInplace(Project project, PsiElement[] elements) {
    boolean inProject = PsiManager.getInstance(project).isInProject(elements[0]);
    if(inProject && elements[0] instanceof XmlTag) {
        XmlElementDescriptor descriptor = ((XmlTag)elements[0]).getDescriptor();
        return descriptor instanceof AnyXmlElementDescriptor;
    } else {
        return !inProject;
    }
}
 
Example #17
Source File: FluidTagNameProvider.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag tag) {
    if (tag == null) {
        return null;
    }

    return ViewHelperUtil.xmlElementDescriptorForCurrentTag(tag.getProject(), tag);
}
 
Example #18
Source File: MuleElementInsertHandler.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
protected boolean isNamespaceBound(PsiElement psiElement) {
    PsiElement parent = psiElement.getParent();
    if (!(parent instanceof XmlTag)) return false;
    final XmlTag tag = (XmlTag) parent;
    final XmlElementDescriptor tagDescriptor = tag.getDescriptor();
    final String tagNamespace = tag.getNamespace();
    return tagDescriptor != null && !(tagDescriptor instanceof AnyXmlElementDescriptor) && namespace.equals(tagNamespace);
}
 
Example #19
Source File: MuleSchemaProvider.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
@NotNull
public Set<String> getAvailableNamespaces(@NotNull XmlFile file, @Nullable String tagName) {
    final Module module = ModuleUtil.findModuleForPsiElement(file);
    Map<String, XmlFile> schemas = getSchemas(module);
    Set<String> namespaces = new HashSet<>();

    try {
        for (XmlFile xsd : schemas.values()) {
            final XmlDocument document = xsd.getDocument();
            if (document != null) {
                final PsiMetaData metaData = document.getMetaData();
                if (metaData instanceof XmlNSDescriptorImpl) {
                    XmlNSDescriptorImpl descriptor = (XmlNSDescriptorImpl) metaData;
                    String defaultNamespace = descriptor.getDefaultNamespace();

                    //Stupid HTTP module XSD weirdo
                    if (xsd.getName().contains("mule-httpn"))
                        defaultNamespace = "http://www.mulesoft.org/schema/mule/http";
                    /////

                    if (StringUtils.isNotEmpty(defaultNamespace)) {
                        if (StringUtils.isNotEmpty(tagName)) {
                            XmlElementDescriptor elementDescriptor = descriptor.getElementDescriptor(tagName, defaultNamespace);
                            if (elementDescriptor != null) {
                                namespaces.add(defaultNamespace);
                            }
                        } else {
                            namespaces.add(defaultNamespace);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        //e.printStackTrace();
    }
    return namespaces;
}
 
Example #20
Source File: FluidTagNameProvider.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, XmlTag context) {
    XmlElementDescriptor descriptor = getDescriptor(context);
    if (descriptor == null) {
        return null;
    }

    return descriptor.getAttributeDescriptor(attributeName, context);
}
 
Example #21
Source File: FluidTagNameProvider.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag context) {
    XmlElementDescriptor descriptor = getDescriptor(context);
    if (descriptor == null) {
        return XmlAttributeDescriptor.EMPTY;
    }

    return descriptor.getAttributesDescriptors(context);
}
 
Example #22
Source File: ISMLTagDescriptor.java    From intellij-demandware with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #23
Source File: XmlDescriptorUtil.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
public static XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return ContainerUtil.map2Array(xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument),
        XmlElementDescriptor.class, descriptor -> wrapInDelegating(descriptor));
}
 
Example #24
Source File: XmlDescriptorUtil.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
@NotNull
public static DelegatingRelaxedHtmlElementDescriptor wrapInDelegating(XmlElementDescriptor descriptor) {
    return descriptor instanceof DelegatingRelaxedHtmlElementDescriptor ? (DelegatingRelaxedHtmlElementDescriptor)descriptor :
        new DelegatingRelaxedHtmlElementDescriptor(descriptor);
}
 
Example #25
Source File: RTRequireTagDescriptor.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #26
Source File: ViewHelperXmlElementDescriptor.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    return XmlDescriptorUtil.getElementsDescriptors(context);
}
 
Example #27
Source File: ViewHelperXmlElementDescriptor.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    return XmlDescriptorUtil.getElementDescriptor(childTag, contextTag);
}
 
Example #28
Source File: RTImportTagDescriptor.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #29
Source File: RTClassTagDescriptor.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #30
Source File: AfxFusionElementDescriptorProvider.java    From intellij-neos with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This code currently only works for fully-qualified Fusion prototypes, having exactly one ":" between namespace and name.
 *
 * NOTE: {@link ResolveEngine#getPrototypeDefinitions(Project, String, String)} only returns a single PsiElement
 *       in the list in case it found a prototype definition (i.e. a line like "prototype(X) < prototype(Y)" when
 *       searching for "X"). We trigger "jump to definition" only in this case.
 *
 *       From the {@link XmlElementDescriptor}, we cannot return more than one "Declaration", because
 *       the {@link TagNameReference}, whose resolve() method calls the descriptor's getDeclaration() method,
 *       is NOT of type {@link PsiPolyVariantReference}.
 *
 *       How is the TagNameReference created/called? The {@link com.intellij.psi.impl.source.xml.XmlTagImpl#getReferences(PsiReferenceService.Hints)} creates
 *       the TagNameReference.
 *
 * IN CASE WE WANT TO RETURN MULTIPLE RESULTS LATER, we could provide our own TagNameReference also implementing
 * PsiPolyVariantReference; by registering an own xml.xmlExtension; and overriding createTagNameReference().
 *
 * Alternatively, we could implement a custom {@link com.intellij.psi.PsiReferenceContributor}, which would be able to add
 * multiple completions. However, this would still mark the Fusion XML tag "red" and as unknown XML element in the system.
 */
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag tag) {
    String key = tag.getName();
    String[] nameParts = tag.getName().split(":");

    if (nameParts.length == 2) {
        List<PsiElement> fusionPrototypes = ResolveEngine.getPrototypeDefinitions(tag.getProject(), nameParts[1], nameParts[0]);

        if (fusionPrototypes.size() == 1) {
            return new AfxXmlTagDescriptor(key, fusionPrototypes);
        }
    }

    return null;
}