use of com.intellij.psi.meta.PsiPresentableMetaData in project intellij-community by JetBrains.
the class PsiElement2UsageTargetAdapter method update.
private void update(PsiElement element) {
if (element != null && element.isValid()) {
final ItemPresentation presentation = ((NavigationItem) element).getPresentation();
myIconOpen = presentation == null ? null : ComputableIcon.create(presentation, true);
myIconClosed = presentation == null ? null : ComputableIcon.create(presentation, false);
myPresentableText = presentation == null ? UsageViewUtil.createNodeText(element) : presentation.getPresentableText();
if (myIconOpen == null || myIconClosed == null) {
if (element instanceof PsiMetaOwner) {
final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) element;
final PsiMetaData metaData = psiMetaOwner.getMetaData();
if (metaData instanceof PsiPresentableMetaData) {
final PsiPresentableMetaData psiPresentableMetaData = (PsiPresentableMetaData) metaData;
if (myIconOpen == null)
myIconOpen = ComputableIcon.create(psiPresentableMetaData);
if (myIconClosed == null)
myIconClosed = ComputableIcon.create(psiPresentableMetaData);
}
} else if (element instanceof PsiFile) {
final PsiFile psiFile = (PsiFile) element;
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null) {
myIconOpen = ComputableIcon.create(virtualFile);
myIconClosed = ComputableIcon.create(virtualFile);
}
}
}
}
}
use of com.intellij.psi.meta.PsiPresentableMetaData in project android by JetBrains.
the class AndroidLayoutXmlTagNameProvider method addTagNameVariants.
@Override
public void addTagNameVariants(List<LookupElement> elements, @NotNull XmlTag tag, String prefix) {
final PsiFile file = tag.getContainingFile();
if (!(file instanceof XmlFile && LayoutDomFileDescription.isLayoutFile((XmlFile) file))) {
// Only use this provider for Android layout files
return;
}
XmlExtension xmlExtension = XmlExtension.getExtension(file);
List<XmlElementDescriptor> variants = TagNameVariantCollector.getTagDescriptors(tag, NAMESPACES, null);
// Find the framework widgets that have a support library alternative
Set<String> supportAlternatives = Sets.newHashSet();
for (XmlElementDescriptor descriptor : variants) {
String qualifiedName = descriptor.getName(tag);
if (qualifiedName.startsWith(ANDROID_SUPPORT_PKG_PREFIX)) {
supportAlternatives.add(AndroidUtils.getUnqualifiedName(qualifiedName));
}
}
final Set<String> addedNames = Sets.newHashSet();
for (XmlElementDescriptor descriptor : variants) {
String qualifiedName = descriptor.getName(tag);
if (!addedNames.add(qualifiedName)) {
continue;
}
final String simpleName = AndroidUtils.getUnqualifiedName(qualifiedName);
// Creating LookupElementBuilder with PsiElement gives an ability to show documentation during completion time
PsiElement declaration = descriptor.getDeclaration();
LookupElementBuilder lookupElement = declaration == null ? LookupElementBuilder.create(qualifiedName) : LookupElementBuilder.create(declaration, qualifiedName);
final boolean isDeprecated = isDeclarationDeprecated(declaration);
if (isDeprecated) {
lookupElement = lookupElement.withStrikeoutness(true);
}
if (simpleName != null) {
lookupElement = lookupElement.withLookupString(simpleName);
}
// This statement preserves them in autocompletion.
if (descriptor instanceof PsiPresentableMetaData) {
lookupElement = lookupElement.withIcon(((PsiPresentableMetaData) descriptor).getIcon());
}
// Using insert handler is required for, e.g. automatic insertion of required fields in Android layout XMLs
if (xmlExtension.useXmlTagInsertHandler()) {
lookupElement = lookupElement.withInsertHandler(XmlTagInsertHandler.INSTANCE);
}
// Deprecated tag names are supposed to be shown below non-deprecated tags
int priority = isDeprecated ? 10 : 100;
if (simpleName == null) {
if (supportAlternatives.contains(qualifiedName)) {
// This component has a support library alternative so lower the priority so the support component is shown at the top.
priority -= 1;
} else {
// The component doesn't have an alternative in the support library so push it to the top.
priority += 10;
}
}
elements.add(PrioritizedLookupElement.withPriority(lookupElement, priority));
}
}
use of com.intellij.psi.meta.PsiPresentableMetaData in project intellij-plugins by JetBrains.
the class ResolveExternalInlineStyleSourceAction method findTargetIfStyleDeclarationOwner.
private Navigatable findTargetIfStyleDeclarationOwner(XmlTag parent) {
int foundCount = 0;
Navigatable target = null;
for (XmlAttribute attribute : parent.getAttributes()) {
XmlAttributeDescriptor descriptor = attribute.getDescriptor();
// 8
if (descriptor instanceof AnnotationBackedDescriptor) {
String ourValue = properties.get(descriptor.getName());
if (ourValue != null) {
if (attribute.getDisplayValue().equals(ourValue)) {
foundCount++;
if (descriptor.getName().equals(targetStyleName)) {
target = (Navigatable) attribute;
}
if (foundCount == properties.size()) {
return target;
}
}
}
}
}
for (XmlTag tag : parent.getSubTags()) {
XmlElementDescriptor descriptor = tag.getDescriptor();
if (descriptor instanceof AnnotationBackedDescriptor && ((PsiPresentableMetaData) descriptor).getTypeName().equals(FlexAnnotationNames.STYLE)) {
String ourValue = properties.get(descriptor.getName());
if (ourValue != null) {
if (tag.getSubTags().length == 0 && tag.getValue().getTrimmedText().equals(ourValue)) {
foundCount++;
if (descriptor.getName().equals(targetStyleName)) {
target = (Navigatable) tag;
}
if (foundCount == properties.size()) {
return target;
}
}
}
}
}
return null;
}
use of com.intellij.psi.meta.PsiPresentableMetaData in project intellij-community by JetBrains.
the class DefinitionReference method getVariants.
@Override
@NotNull
public Object[] getVariants() {
final RngGrammar scope = getScope();
if (scope == null) {
return ResolveResult.EMPTY_ARRAY;
}
final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(scope);
if (map == null || map.size() == 0)
return ArrayUtil.EMPTY_OBJECT_ARRAY;
return ContainerUtil.mapNotNull(map.values(), defines -> {
final Define define = defines.iterator().next();
if (defines.size() == 0) {
return null;
} else {
final PsiElement element = define.getPsiElement();
if (element != null) {
final PsiPresentableMetaData data = (PsiPresentableMetaData) ((PsiMetaOwner) element).getMetaData();
if (data != null) {
return LookupValueFactory.createLookupValue(data.getName(), data.getIcon());
} else {
return define.getName();
}
} else {
return define.getName();
}
}
}).toArray();
}
use of com.intellij.psi.meta.PsiPresentableMetaData in project intellij-community by JetBrains.
the class DefaultXmlTagNameProvider method addTagNameVariants.
@Override
public void addTagNameVariants(List<LookupElement> elements, @NotNull XmlTag tag, String prefix) {
final List<String> namespaces;
if (prefix.isEmpty()) {
namespaces = new ArrayList<>(Arrays.asList(tag.knownNamespaces()));
// empty namespace
namespaces.add(XmlUtil.EMPTY_URI);
} else {
namespaces = new ArrayList<>(Collections.singletonList(tag.getNamespace()));
}
PsiFile psiFile = tag.getContainingFile();
XmlExtension xmlExtension = XmlExtension.getExtension(psiFile);
List<String> nsInfo = new ArrayList<>();
List<XmlElementDescriptor> variants = TagNameVariantCollector.getTagDescriptors(tag, namespaces, nsInfo);
if (variants.isEmpty() && psiFile instanceof XmlFile && ((XmlFile) psiFile).getRootTag() == tag) {
getRootTagsVariants(tag, elements);
return;
}
final Set<String> visited = new HashSet<>();
for (int i = 0; i < variants.size(); i++) {
XmlElementDescriptor descriptor = variants.get(i);
String qname = descriptor.getName(tag);
if (!visited.add(qname))
continue;
if (!prefix.isEmpty() && qname.startsWith(prefix + ":")) {
qname = qname.substring(prefix.length() + 1);
}
PsiElement declaration = descriptor.getDeclaration();
if (declaration != null && !declaration.isValid()) {
LOG.error(descriptor + " contains invalid declaration: " + declaration);
}
LookupElementBuilder lookupElement = declaration == null ? LookupElementBuilder.create(qname) : LookupElementBuilder.create(declaration, qname);
final int separator = qname.indexOf(':');
if (separator > 0) {
lookupElement = lookupElement.withLookupString(qname.substring(separator + 1));
}
String ns = nsInfo.get(i);
if (StringUtil.isNotEmpty(ns)) {
lookupElement = lookupElement.withTypeText(ns, true);
}
if (descriptor instanceof PsiPresentableMetaData) {
lookupElement = lookupElement.withIcon(((PsiPresentableMetaData) descriptor).getIcon());
}
if (xmlExtension.useXmlTagInsertHandler()) {
lookupElement = lookupElement.withInsertHandler(XmlTagInsertHandler.INSTANCE);
}
lookupElement = lookupElement.withCaseSensitivity(!(descriptor instanceof HtmlElementDescriptorImpl));
elements.add(PrioritizedLookupElement.withPriority(lookupElement, separator > 0 ? 0 : 1));
}
}
Aggregations