Search in sources :

Example 1 with DomTarget

use of com.intellij.util.xml.DomTarget 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 DomTarget

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

the class AntResolveTest method testPropertyInMacrodefParam.

public void testPropertyInMacrodefParam() throws Exception {
    PsiReference ref = configure();
    final PsiElement result = ref.resolve();
    assertTrue(result instanceof PomTargetPsiElement);
    final PsiElement naviElem = ((DomTarget) ((PomTargetPsiElement) result).getTarget()).getNavigationElement();
    final DomElement domElement = DomUtil.getDomElement(naviElem);
    assertNotNull(domElement);
    assertNotNull(domElement.getParentOfType(AntDomMacrodefAttribute.class, false));
}
Also used : DomElement(com.intellij.util.xml.DomElement) AntDomMacrodefAttribute(com.intellij.lang.ant.dom.AntDomMacrodefAttribute) PsiReference(com.intellij.psi.PsiReference) DomTarget(com.intellij.util.xml.DomTarget) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 3 with DomTarget

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

the class AntDomPropertyDefiningElement method getNavigationElement.

public final PsiElement getNavigationElement(String propertyName) {
    for (GenericAttributeValue<String> value : getPropertyDefiningAttributes()) {
        if (!propertyName.equals(value.getStringValue())) {
            continue;
        }
        final DomTarget domTarget = DomTarget.getTarget(this, value);
        return domTarget != null ? PomService.convertToPsi(domTarget) : null;
    }
    for (String propName : getImplicitPropertyNames()) {
        if (propertyName.equals(propName)) {
            final DomTarget domTarget = DomTarget.getTarget(this);
            if (domTarget != null) {
                return PomService.convertToPsi(domTarget);
            }
            final XmlElement xmlElement = getXmlElement();
            return xmlElement != null ? xmlElement.getNavigationElement() : null;
        }
    }
    return null;
}
Also used : DomTarget(com.intellij.util.xml.DomTarget) XmlElement(com.intellij.psi.xml.XmlElement)

Example 4 with DomTarget

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

the class AntDomProperty method getNavigationElement.

public PsiElement getNavigationElement(final String propertyName) {
    DomTarget domTarget = DomTarget.getTarget(this);
    if (domTarget == null) {
        final GenericAttributeValue<String> environment = getEnvironment();
        if (environment.getRawText() != null) {
            domTarget = DomTarget.getTarget(this, environment);
        }
        if (domTarget == null) {
            final GenericAttributeValue<String> resource = getResource();
            if (resource.getRawText() != null) {
                domTarget = DomTarget.getTarget(this, resource);
            }
        }
    }
    if (domTarget != null) {
        final PsiElement psi = PomService.convertToPsi(domTarget);
        if (psi != null) {
            return psi;
        }
    }
    final PsiFileSystemItem psiFile = getFile().getValue();
    if (psiFile != null) {
        final String prefix = getPropertyPrefixValue();
        String _propertyName = propertyName;
        if (prefix != null) {
            if (!propertyName.startsWith(prefix)) {
                return null;
            }
            _propertyName = propertyName.substring(prefix.length());
        }
        final PropertiesFile pf = toPropertiesFile(psiFile);
        if (pf != null) {
            final IProperty property = pf.findPropertyByKey(_propertyName);
            return property != null ? property.getPsiElement() : null;
        }
    }
    return null;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) DomTarget(com.intellij.util.xml.DomTarget) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiElement(com.intellij.psi.PsiElement)

Aggregations

DomTarget (com.intellij.util.xml.DomTarget)4 PomTargetPsiElement (com.intellij.pom.PomTargetPsiElement)2 PsiElement (com.intellij.psi.PsiElement)2 XmlElement (com.intellij.psi.xml.XmlElement)2 DomElement (com.intellij.util.xml.DomElement)2 AntDomElement (com.intellij.lang.ant.dom.AntDomElement)1 AntDomMacrodefAttribute (com.intellij.lang.ant.dom.AntDomMacrodefAttribute)1 AntDomTarget (com.intellij.lang.ant.dom.AntDomTarget)1 IProperty (com.intellij.lang.properties.IProperty)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 PomTarget (com.intellij.pom.PomTarget)1 PsiFile (com.intellij.psi.PsiFile)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1 PsiReference (com.intellij.psi.PsiReference)1 DomChildrenDescription (com.intellij.util.xml.reflect.DomChildrenDescription)1 Type (java.lang.reflect.Type)1 Nullable (org.jetbrains.annotations.Nullable)1