Search in sources :

Example 1 with PomTargetPsiElement

use of com.intellij.pom.PomTargetPsiElement in project intellij-community by JetBrains.

the class DomIncludesTest method testNavigationToIncluded.

public void testNavigationToIncluded() throws Throwable {
    final MyElement rootElement = createDomFile("a.xml", "<root xmlns:xi=\"http://www.w3.org/2001/XInclude\">" + "<xi:include href=\"b.xml\" xpointer=\"xpointer(/xxx/*)\"/>" + "<child ref=\"b\"/>" + "</root>");
    final XmlFile includedFile = (XmlFile) createFile("b.xml", "<xxx><child xxx=\"b\"/></xxx>");
    final List<Child> children = rootElement.getChildren();
    final MyElement domTarget = children.get(0);
    final GenericAttributeValue<Child> ref = children.get(1).getRef();
    final MyElement value = ref.getValue();
    assertEquals(domTarget, value);
    myFixture.configureFromTempProjectFile("a.xml");
    final int offset = ref.getXmlAttributeValue().getTextRange().getStartOffset() + 1;
    myFixture.getEditor().getCaretModel().moveToOffset(offset);
    final PsiElement target = GotoDeclarationAction.findTargetElement(getProject(), myFixture.getEditor(), offset);
    PsiElement element = ((DomTarget) ((PomTargetPsiElement) target).getTarget()).getNavigationElement();
    //    assertSame(PomService.convertToPsi(DomTarget.getTarget(domTarget)), target);
    assertSame(includedFile.getDocument().getRootTag().getSubTags()[0].getAttributes()[0].getValueElement(), element);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 2 with PomTargetPsiElement

use of com.intellij.pom.PomTargetPsiElement in project intellij-community by JetBrains.

the class HighlightUsagesHandler method getNameIdentifierRange.

@Nullable
public static TextRange getNameIdentifierRange(PsiFile file, PsiElement element) {
    final InjectedLanguageManager injectedManager = InjectedLanguageManager.getInstance(element.getProject());
    if (element instanceof PomTargetPsiElement) {
        final PomTarget target = ((PomTargetPsiElement) element).getTarget();
        if (target instanceof PsiDeclaredTarget) {
            final PsiDeclaredTarget declaredTarget = (PsiDeclaredTarget) target;
            final TextRange range = declaredTarget.getNameIdentifierRange();
            if (range != null) {
                if (range.getStartOffset() < 0 || range.getLength() <= 0) {
                    return null;
                }
                final PsiElement navElement = declaredTarget.getNavigationElement();
                if (PsiUtilBase.isUnderPsiRoot(file, navElement)) {
                    return injectedManager.injectedToHost(navElement, range.shiftRight(navElement.getTextRange().getStartOffset()));
                }
            }
        }
    }
    if (!PsiUtilBase.isUnderPsiRoot(file, element)) {
        return null;
    }
    PsiElement identifier = IdentifierUtil.getNameIdentifier(element);
    if (identifier != null && PsiUtilBase.isUnderPsiRoot(file, identifier)) {
        return injectedManager.injectedToHost(identifier, identifier.getTextRange());
    }
    return null;
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) PomTarget(com.intellij.pom.PomTarget) TextRange(com.intellij.openapi.util.TextRange) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiDeclaredTarget(com.intellij.pom.PsiDeclaredTarget) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PomTargetPsiElement

use of com.intellij.pom.PomTargetPsiElement in project intellij-community by JetBrains.

the class EditSourceUtil method getDescriptor.

@Nullable
public static Navigatable getDescriptor(@NotNull PsiElement element) {
    PsiElement original = getNavigatableOriginalElement(element);
    if (original != null) {
        element = original;
    } else if (!canNavigate(element)) {
        return null;
    }
    if (element instanceof PomTargetPsiElement) {
        return ((PomTargetPsiElement) element).getTarget();
    }
    final PsiElement navigationElement = element.getNavigationElement();
    if (navigationElement instanceof PomTargetPsiElement) {
        return ((PomTargetPsiElement) navigationElement).getTarget();
    }
    final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset();
    final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navigationElement);
    if (virtualFile == null || !virtualFile.isValid()) {
        return null;
    }
    OpenFileDescriptor desc = new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset);
    desc.setUseCurrentWindow(FileEditorManager.USE_CURRENT_WINDOW.isIn(navigationElement));
    return desc;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PomTargetPsiElement

use of com.intellij.pom.PomTargetPsiElement 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 5 with PomTargetPsiElement

use of com.intellij.pom.PomTargetPsiElement 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)

Aggregations

PomTargetPsiElement (com.intellij.pom.PomTargetPsiElement)13 PsiElement (com.intellij.psi.PsiElement)9 PomTarget (com.intellij.pom.PomTarget)6 PsiReference (com.intellij.psi.PsiReference)4 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 DomElement (com.intellij.util.xml.DomElement)2 DomTarget (com.intellij.util.xml.DomTarget)2 ResourceUrl (com.android.ide.common.resources.ResourceUrl)1 ResourceType (com.android.resources.ResourceType)1 Language (com.intellij.lang.Language)1 AntDomElement (com.intellij.lang.ant.dom.AntDomElement)1 AntDomMacrodefAttribute (com.intellij.lang.ant.dom.AntDomMacrodefAttribute)1 AntDomTarget (com.intellij.lang.ant.dom.AntDomTarget)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1 IProperty (com.intellij.lang.properties.IProperty)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 XmlProperty (com.intellij.lang.properties.xml.XmlProperty)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1