Search in sources :

Example 1 with ResourceReferenceType

use of com.android.tools.idea.AndroidPsiUtils.ResourceReferenceType in project android by JetBrains.

the class AndroidDocumentationProvider method generateDoc.

@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
    if (originalElement == null) {
        return null;
    }
    ResourceReferenceType referenceType = AndroidPsiUtils.getResourceReferenceType(originalElement);
    if (referenceType == ResourceReferenceType.NONE) {
        return null;
    }
    Module module = ModuleUtilCore.findModuleForPsiElement(originalElement);
    if (module == null) {
        return null;
    }
    ResourceType type = AndroidPsiUtils.getResourceType(originalElement);
    if (type == null) {
        return null;
    }
    String name = AndroidPsiUtils.getResourceName(originalElement);
    boolean isFrameworkResource = referenceType == ResourceReferenceType.FRAMEWORK;
    return AndroidJavaDocRenderer.render(module, type, name, isFrameworkResource);
}
Also used : ResourceReferenceType(com.android.tools.idea.AndroidPsiUtils.ResourceReferenceType) ResourceType(com.android.resources.ResourceType) Module(com.intellij.openapi.module.Module)

Example 2 with ResourceReferenceType

use of com.android.tools.idea.AndroidPsiUtils.ResourceReferenceType in project android by JetBrains.

the class AndroidColorAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (element instanceof XmlTag) {
        XmlTag tag = (XmlTag) element;
        String tagName = tag.getName();
        if ((ResourceType.COLOR.getName().equals(tagName) || ResourceType.DRAWABLE.getName().equals(tagName) || ResourceType.MIPMAP.getName().equals(tagName))) {
            DomElement domElement = DomManager.getDomManager(element.getProject()).getDomElement(tag);
            if (domElement instanceof ResourceElement || ApplicationManager.getApplication().isUnitTestMode()) {
                String value = tag.getValue().getText().trim();
                annotateXml(element, holder, value);
            }
        } else if (TAG_ITEM.equals(tagName)) {
            XmlTagValue value = tag.getValue();
            String text = value.getText();
            annotateXml(element, holder, text);
        }
    } else if (element instanceof XmlAttributeValue) {
        XmlAttributeValue v = (XmlAttributeValue) element;
        String value = v.getValue();
        if (value == null || value.isEmpty()) {
            return;
        }
        annotateXml(element, holder, value);
    } else if (element instanceof PsiReferenceExpression) {
        ResourceReferenceType referenceType = AndroidPsiUtils.getResourceReferenceType(element);
        if (referenceType != ResourceReferenceType.NONE) {
            // (isResourceReference will return true for both "R.drawable.foo" and the foo literal leaf in the
            // same expression, which would result in both elements getting annotated and the icon showing up
            // in the gutter twice. Instead we only count the outer one.
            ResourceType type = AndroidPsiUtils.getResourceType(element);
            if (type == ResourceType.COLOR || type == ResourceType.DRAWABLE || type == ResourceType.MIPMAP) {
                String name = AndroidPsiUtils.getResourceName(element);
                annotateResourceReference(type, holder, element, name, referenceType == ResourceReferenceType.FRAMEWORK);
            }
        }
    }
}
Also used : ResourceElement(org.jetbrains.android.dom.resources.ResourceElement) DomElement(com.intellij.util.xml.DomElement) XmlTagValue(com.intellij.psi.xml.XmlTagValue) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) ResourceReferenceType(com.android.tools.idea.AndroidPsiUtils.ResourceReferenceType) ResourceType(com.android.resources.ResourceType) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

ResourceType (com.android.resources.ResourceType)2 ResourceReferenceType (com.android.tools.idea.AndroidPsiUtils.ResourceReferenceType)2 Module (com.intellij.openapi.module.Module)1 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlTagValue (com.intellij.psi.xml.XmlTagValue)1 DomElement (com.intellij.util.xml.DomElement)1 ResourceElement (org.jetbrains.android.dom.resources.ResourceElement)1