Search in sources :

Example 1 with DomChildrenDescription

use of com.intellij.util.xml.reflect.DomChildrenDescription in project intellij-community by JetBrains.

the class AntDomDocumentationProvider method getQuickNavigateInfo.

@Nullable
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
    // todo!
    if (element instanceof PomTargetPsiElement) {
        final PomTarget pomTarget = ((PomTargetPsiElement) element).getTarget();
        if (pomTarget instanceof DomTarget) {
            final DomElement domElement = ((DomTarget) pomTarget).getDomElement();
            if (domElement instanceof AntDomTarget) {
                final AntDomTarget antTarget = (AntDomTarget) domElement;
                final String description = antTarget.getDescription().getRawText();
                if (description != null && description.length() > 0) {
                    final String targetName = antTarget.getName().getRawText();
                    final StringBuilder builder = StringBuilderSpinAllocator.alloc();
                    try {
                        builder.append("Target");
                        if (targetName != null) {
                            builder.append(" \"").append(targetName).append("\"");
                        }
                        final XmlElement xmlElement = antTarget.getXmlElement();
                        if (xmlElement != null) {
                            final PsiFile containingFile = xmlElement.getContainingFile();
                            if (containingFile != null) {
                                final String fileName = containingFile.getName();
                                builder.append(" [").append(fileName).append("]");
                            }
                        }
                        return builder.append(" ").append(description).toString();
                    } finally {
                        StringBuilderSpinAllocator.dispose(builder);
                    }
                }
            }
        } else if (pomTarget instanceof DomChildrenDescription) {
            final DomChildrenDescription description = (DomChildrenDescription) pomTarget;
            Type type = null;
            try {
                type = description.getType();
            } catch (UnsupportedOperationException e) {
                LOG.info(e);
            }
            if (type instanceof Class && AntDomElement.class.isAssignableFrom(((Class) type))) {
                final String elemName = description.getName();
                if (elemName != null) {
                    final AntDomElement.Role role = description.getUserData(AntDomElement.ROLE);
                    final StringBuilder builder = StringBuilderSpinAllocator.alloc();
                    try {
                        if (role == AntDomElement.Role.TASK) {
                            builder.append("Task ");
                        } else if (role == AntDomElement.Role.DATA_TYPE) {
                            builder.append("Data structure ");
                        }
                        builder.append(elemName);
                        return builder.toString();
                    } finally {
                        StringBuilderSpinAllocator.dispose(builder);
                    }
                }
            }
        }
    }
    return null;
}
Also used : AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget) DomTarget(com.intellij.util.xml.DomTarget) DomChildrenDescription(com.intellij.util.xml.reflect.DomChildrenDescription) AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget) PomTarget(com.intellij.pom.PomTarget) Type(java.lang.reflect.Type) DomElement(com.intellij.util.xml.DomElement) AntDomElement(com.intellij.lang.ant.dom.AntDomElement) XmlElement(com.intellij.psi.xml.XmlElement) PsiFile(com.intellij.psi.PsiFile) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DomChildrenDescription

use of com.intellij.util.xml.reflect.DomChildrenDescription in project intellij-community by JetBrains.

the class DomStubBuilderVisitor method visitXmlElement.

void visitXmlElement(XmlElement element, ElementStub parent, int index) {
    DomInvocationHandler handler = myManager.getDomHandler(element);
    if (handler == null || handler.getAnnotation(Stubbed.class) == null && !handler.getChildDescription().isStubbed())
        return;
    AbstractDomChildrenDescription description = handler.getChildDescription();
    String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription) description).getXmlName().getNamespaceKey() : "";
    if (element instanceof XmlTag) {
        XmlTag tag = (XmlTag) element;
        String elementClass = null;
        if (handler.getAnnotation(StubbedOccurrence.class) != null) {
            final Type type = description.getType();
            elementClass = ((Class) type).getName();
        }
        ElementStub stub = new ElementStub(parent, StringRef.fromString(tag.getName()), StringRef.fromNullableString(nsKey), index, description instanceof CustomDomChildrenDescription, elementClass == null ? null : StringRef.fromNullableString(elementClass), tag.getSubTags().length == 0 ? tag.getValue().getTrimmedText() : "");
        for (XmlAttribute attribute : tag.getAttributes()) {
            visitXmlElement(attribute, stub, 0);
        }
        Map<String, Integer> indices = new HashMap<>();
        for (final XmlTag subTag : tag.getSubTags()) {
            String name = subTag.getName();
            Integer i = indices.get(name);
            i = i == null ? 0 : i + 1;
            visitXmlElement(subTag, stub, i);
            indices.put(name, i);
        }
    } else if (element instanceof XmlAttribute) {
        new AttributeStub(parent, StringRef.fromString(((XmlAttribute) element).getLocalName()), StringRef.fromNullableString(nsKey), ((XmlAttribute) element).getValue());
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) Stubbed(com.intellij.util.xml.Stubbed) HashMap(java.util.HashMap) DomInvocationHandler(com.intellij.util.xml.impl.DomInvocationHandler) CustomDomChildrenDescription(com.intellij.util.xml.reflect.CustomDomChildrenDescription) DomChildrenDescription(com.intellij.util.xml.reflect.DomChildrenDescription) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) CustomDomChildrenDescription(com.intellij.util.xml.reflect.CustomDomChildrenDescription) Type(java.lang.reflect.Type) AttributeStub(com.intellij.util.xml.stubs.AttributeStub) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) ElementStub(com.intellij.util.xml.stubs.ElementStub) XmlTag(com.intellij.psi.xml.XmlTag) StubbedOccurrence(com.intellij.util.xml.StubbedOccurrence)

Aggregations

DomChildrenDescription (com.intellij.util.xml.reflect.DomChildrenDescription)2 Type (java.lang.reflect.Type)2 AntDomElement (com.intellij.lang.ant.dom.AntDomElement)1 AntDomTarget (com.intellij.lang.ant.dom.AntDomTarget)1 PomTarget (com.intellij.pom.PomTarget)1 PomTargetPsiElement (com.intellij.pom.PomTargetPsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlElement (com.intellij.psi.xml.XmlElement)1 XmlTag (com.intellij.psi.xml.XmlTag)1 DomElement (com.intellij.util.xml.DomElement)1 DomTarget (com.intellij.util.xml.DomTarget)1 Stubbed (com.intellij.util.xml.Stubbed)1 StubbedOccurrence (com.intellij.util.xml.StubbedOccurrence)1 DomInvocationHandler (com.intellij.util.xml.impl.DomInvocationHandler)1 AbstractDomChildrenDescription (com.intellij.util.xml.reflect.AbstractDomChildrenDescription)1 CustomDomChildrenDescription (com.intellij.util.xml.reflect.CustomDomChildrenDescription)1 AttributeStub (com.intellij.util.xml.stubs.AttributeStub)1 ElementStub (com.intellij.util.xml.stubs.ElementStub)1 HashMap (java.util.HashMap)1