Search in sources :

Example 6 with PomTargetPsiElement

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

the class AntResolveTest method doTaskTest.

private void doTaskTest() throws Exception {
    PsiReference ref = configure();
    PsiElement target = ref.resolve();
    assertTrue(target instanceof PomTargetPsiElement && ((PomTargetPsiElement) target).getTarget().canNavigateToSource());
}
Also used : PsiReference(com.intellij.psi.PsiReference) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PomTargetPsiElement

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

the class AntResolveTest method doPropertyTest.

private void doPropertyTest() throws Exception {
    PsiReference ref = configure();
    PsiElement target = ref.resolve();
    assertTrue((target instanceof PomTargetPsiElement && ((PomTargetPsiElement) target).getTarget().canNavigateToSource()) || (target instanceof XmlTag && ("project".equalsIgnoreCase(((XmlTag) target).getName()) || "buildnumber".equalsIgnoreCase(((XmlTag) target).getName()))));
}
Also used : PsiReference(com.intellij.psi.PsiReference) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 8 with PomTargetPsiElement

use of com.intellij.pom.PomTargetPsiElement in project android by JetBrains.

the class AndroidXmlDocumentationProvider method generateDoc.

@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
    if (element instanceof ProvidedDocumentationPsiElement) {
        return ((ProvidedDocumentationPsiElement) element).getDocumentation();
    }
    if (element instanceof LazyValueResourceElementWrapper) {
        LazyValueResourceElementWrapper wrapper = (LazyValueResourceElementWrapper) element;
        ValueResourceInfo resourceInfo = wrapper.getResourceInfo();
        ResourceType type = resourceInfo.getType();
        String name = resourceInfo.getName();
        Module module = ModuleUtilCore.findModuleForPsiElement(element);
        if (module == null) {
            return null;
        }
        AndroidFacet facet = AndroidFacet.getInstance(element);
        if (facet == null) {
            return null;
        }
        ResourceUrl url;
        ResourceUrl originalUrl = originalElement != null ? ResourceUrl.parse(originalElement.getText()) : null;
        if (originalUrl != null && name.equals(originalUrl.name)) {
            url = originalUrl;
        } else {
            boolean isFramework = false;
            if (originalUrl != null) {
                isFramework = originalUrl.framework;
            } else {
                // Figure out if this resource is a framework file.
                // We really should store that info in the ValueResourceInfo instances themselves.
                // For now, attempt to figure it out
                SystemResourceManager systemResourceManager = facet.getSystemResourceManager();
                VirtualFile containingFile = resourceInfo.getContainingFile();
                if (systemResourceManager != null) {
                    VirtualFile parent = containingFile.getParent();
                    if (parent != null) {
                        VirtualFile resDir = parent.getParent();
                        if (resDir != null) {
                            isFramework = systemResourceManager.isResourceDir(resDir);
                        }
                    }
                }
            }
            url = ResourceUrl.create(type, name, isFramework, false);
        }
        return generateDoc(element, url);
    } else if (element instanceof MyResourceElement) {
        return getResourceDocumentation(element, ((MyResourceElement) element).myResource);
    } else if (element instanceof XmlAttributeValue) {
        return getResourceDocumentation(element, ((XmlAttributeValue) element).getValue());
    }
    if (originalElement instanceof XmlToken) {
        XmlToken token = (XmlToken) originalElement;
        if (token.getTokenType() == XML_ATTRIBUTE_VALUE_START_DELIMITER) {
            PsiElement next = token.getNextSibling();
            if (next instanceof XmlToken) {
                token = (XmlToken) next;
            }
        } else if (token.getTokenType() == XML_ATTRIBUTE_VALUE_END_DELIMITER) {
            PsiElement prev = token.getPrevSibling();
            if (prev instanceof XmlToken) {
                token = (XmlToken) prev;
            }
        }
        if (token.getTokenType() == XML_ATTRIBUTE_VALUE_TOKEN) {
            String documentation = getResourceDocumentation(originalElement, token.getText());
            if (documentation != null) {
                return documentation;
            }
        } else if (token.getTokenType() == XML_DATA_CHARACTERS) {
            String text = token.getText().trim();
            String documentation = getResourceDocumentation(originalElement, text);
            if (documentation != null) {
                return documentation;
            }
        }
    }
    if (element instanceof PomTargetPsiElement && originalElement != null) {
        final PomTarget target = ((PomTargetPsiElement) element).getTarget();
        if (target instanceof DomAttributeChildDescription) {
            synchronized (ANDROID_ATTRIBUTE_DOCUMENTATION_CACHE_KEY) {
                return generateDocForXmlAttribute((DomAttributeChildDescription) target, originalElement);
            }
        }
    }
    if (element instanceof MyDocElement) {
        return ((MyDocElement) element).myDocumentation;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceType(com.android.resources.ResourceType) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) DomAttributeChildDescription(com.intellij.util.xml.reflect.DomAttributeChildDescription) XmlToken(com.intellij.psi.xml.XmlToken) PomTarget(com.intellij.pom.PomTarget) LazyValueResourceElementWrapper(org.jetbrains.android.dom.wrappers.LazyValueResourceElementWrapper) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) Module(com.intellij.openapi.module.Module) ResourceUrl(com.android.ide.common.resources.ResourceUrl) SystemResourceManager(org.jetbrains.android.resourceManagers.SystemResourceManager) FakePsiElement(com.intellij.psi.impl.FakePsiElement) PsiElement(com.intellij.psi.PsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) ValueResourceInfo(org.jetbrains.android.resourceManagers.ValueResourceInfo)

Example 9 with PomTargetPsiElement

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

the class RenameAliasingPomTargetProcessor method prepareRenaming.

@Override
public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames) {
    PomTarget target = null;
    if (element instanceof PomTargetPsiElement) {
        target = ((PomTargetPsiElement) element).getTarget();
    } else if (element instanceof PomTarget) {
        target = (PomTarget) element;
    }
    if (target != null) {
        for (AliasingPsiTargetMapper mapper : Extensions.getExtensions(AliasingPsiTargetMapper.EP_NAME)) {
            for (AliasingPsiTarget psiTarget : mapper.getTargets(target)) {
                PsiElement psiElement = PomService.convertToPsi(psiTarget);
                String name = psiTarget.getNameAlias(newName);
                String definedName = allRenames.put(psiElement, name);
                if (definedName != null) {
                    LOG.assertTrue(definedName.equals(name), "target: " + psiTarget + "; " + "defined name: " + definedName + "; " + "name: " + name + "; " + "mapper: " + mapper);
                } else {
                    prepareRenaming(psiElement, name, allRenames);
                }
            }
        }
    }
}
Also used : PomTarget(com.intellij.pom.PomTarget) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) AliasingPsiTarget(com.intellij.psi.targets.AliasingPsiTarget) AliasingPsiTargetMapper(com.intellij.psi.targets.AliasingPsiTargetMapper) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 10 with PomTargetPsiElement

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

the class AntResolveTest method doTargetTest.

private void doTargetTest() throws Exception {
    PsiReference ref = configure();
    PsiElement target = ref.resolve();
    assertTrue(target instanceof PomTargetPsiElement && ((PomTargetPsiElement) target).getTarget().canNavigateToSource());
}
Also used : PsiReference(com.intellij.psi.PsiReference) 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