use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidColorAnnotator method annotateXml.
private static void annotateXml(PsiElement element, AnnotationHolder holder, String value) {
if (value.startsWith("#")) {
final PsiFile file = element.getContainingFile();
if (file != null && AndroidResourceUtil.isInResourceSubdirectory(file, null)) {
if (element instanceof XmlTag) {
Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setGutterIconRenderer(new MyRenderer(element, null));
} else {
assert element instanceof XmlAttributeValue;
Color color = ResourceHelper.parseColor(value);
if (color != null) {
Annotation annotation = holder.createInfoAnnotation(element, null);
annotation.setGutterIconRenderer(new MyRenderer(element, null));
}
}
}
} else if (value.startsWith(COLOR_RESOURCE_PREFIX)) {
annotateResourceReference(ResourceType.COLOR, holder, element, value.substring(COLOR_RESOURCE_PREFIX.length()), false);
} else if (value.startsWith(ANDROID_COLOR_RESOURCE_PREFIX)) {
annotateResourceReference(ResourceType.COLOR, holder, element, value.substring(ANDROID_COLOR_RESOURCE_PREFIX.length()), true);
} else if (value.startsWith(DRAWABLE_PREFIX)) {
annotateResourceReference(ResourceType.DRAWABLE, holder, element, value.substring(DRAWABLE_PREFIX.length()), false);
} else if (value.startsWith(ANDROID_DRAWABLE_PREFIX)) {
annotateResourceReference(ResourceType.DRAWABLE, holder, element, value.substring(ANDROID_DRAWABLE_PREFIX.length()), true);
} else if (value.startsWith(MIPMAP_PREFIX)) {
annotateResourceReference(ResourceType.MIPMAP, holder, element, value.substring(MIPMAP_PREFIX.length()), false);
}
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class IssueIdDocumentationProvider method generateDoc.
@Nullable
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
// Check whether the element is attribute value
if (!(element instanceof XmlAttributeValue)) {
return null;
}
final PsiFile file = element.getContainingFile();
if (!(file instanceof XmlFile)) {
return null;
}
// Check whether the current XML file is lint.xml file
final DomFileElement<LintDomElement> fileElement = DomManager.getDomManager(element.getProject()).getFileElement((XmlFile) file, LintDomElement.class);
if (fileElement == null) {
return null;
}
final Issue issue = IssueIdConverter.getIdSet().get(((XmlAttributeValue) element).getValue());
if (issue == null) {
return null;
}
return issue.getExplanation(TextFormat.HTML);
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidInlineUtil method getInlinableStyleDataFromContext.
@Nullable
static MyStyleData getInlinableStyleDataFromContext(@Nullable PsiElement context) {
if (context instanceof LazyValueResourceElementWrapper) {
context = ((LazyValueResourceElementWrapper) context).computeElement();
}
if (context == null || !context.getManager().isInProject(context)) {
return null;
}
final XmlAttributeValue attrValue = PsiTreeUtil.getParentOfType(context, XmlAttributeValue.class, false);
final XmlTag tag = attrValue != null ? PsiTreeUtil.getParentOfType(attrValue, XmlTag.class) : null;
if (tag == null) {
return null;
}
final MyStyleData data = getInlinableStyleData(tag);
return data != null && PsiEquivalenceUtil.areElementsEquivalent(data.myReferredElement, attrValue) ? data : null;
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class ResourceManager method findIdDeclarations.
// searches only declarations such as "@+id/..."
@NotNull
public List<XmlAttributeValue> findIdDeclarations(@NotNull final String id) {
if (!isResourcePublic(ResourceType.ID.getName(), id)) {
return Collections.emptyList();
}
final List<XmlAttributeValue> declarations = new ArrayList<XmlAttributeValue>();
final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(AndroidIdIndex.INDEX_ID, "+" + id, GlobalSearchScope.allScope(myProject));
final Set<VirtualFile> fileSet = new HashSet<VirtualFile>(files);
final PsiManager psiManager = PsiManager.getInstance(myProject);
for (VirtualFile subdir : getResourceSubdirsToSearchIds()) {
for (VirtualFile file : subdir.getChildren()) {
if (fileSet.contains(file)) {
final PsiFile psiFile = psiManager.findFile(file);
if (psiFile instanceof XmlFile) {
psiFile.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlAttributeValue(XmlAttributeValue attributeValue) {
if (AndroidResourceUtil.isIdDeclaration(attributeValue)) {
final String idInAttr = AndroidResourceUtil.getResourceNameByReferenceText(attributeValue.getValue());
if (id.equals(idInAttr)) {
declarations.add(attributeValue);
}
}
}
});
}
}
}
}
return declarations;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class JavaFindUsagesHelper method getElementNames.
@NotNull
public static Set<String> getElementNames(@NotNull final PsiElement element) {
if (element instanceof PsiDirectory) {
// normalize a directory to a corresponding package
PsiPackage aPackage = ReadAction.compute(() -> JavaDirectoryService.getInstance().getPackage((PsiDirectory) element));
return aPackage == null ? Collections.emptySet() : getElementNames(aPackage);
}
final Set<String> result = new HashSet<>();
ApplicationManager.getApplication().runReadAction(() -> {
if (element instanceof PsiPackage) {
ContainerUtil.addIfNotNull(result, ((PsiPackage) element).getQualifiedName());
} else if (element instanceof PsiClass) {
final String qname = ((PsiClass) element).getQualifiedName();
if (qname != null) {
result.add(qname);
PsiClass topLevelClass = PsiUtil.getTopLevelClass(element);
if (topLevelClass != null && !(topLevelClass instanceof PsiSyntheticClass)) {
String topName = topLevelClass.getQualifiedName();
assert topName != null : "topLevelClass : " + topLevelClass + "; element: " + element + " (" + qname + ") top level file: " + InjectedLanguageManager.getInstance(element.getProject()).getTopLevelFile(element);
if (qname.length() > topName.length()) {
result.add(topName + qname.substring(topName.length()).replace('.', '$'));
}
}
}
} else if (element instanceof PsiMethod) {
ContainerUtil.addIfNotNull(result, ((PsiMethod) element).getName());
} else if (element instanceof PsiVariable) {
ContainerUtil.addIfNotNull(result, ((PsiVariable) element).getName());
} else if (element instanceof PsiMetaOwner) {
final PsiMetaData metaData = ((PsiMetaOwner) element).getMetaData();
if (metaData != null) {
ContainerUtil.addIfNotNull(result, metaData.getName());
}
} else if (element instanceof PsiNamedElement) {
ContainerUtil.addIfNotNull(result, ((PsiNamedElement) element).getName());
} else if (element instanceof XmlAttributeValue) {
ContainerUtil.addIfNotNull(result, ((XmlAttributeValue) element).getValue());
} else {
LOG.error("Unknown element type: " + element);
}
});
return result;
}
Aggregations