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);
}
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);
}
}
}
}
Aggregations