use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class XmlFindUsagesProvider method getNodeText.
@Override
@NotNull
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
if (element instanceof XmlTag) {
final XmlTag xmlTag = (XmlTag) element;
final PsiMetaData metaData = xmlTag.getMetaData();
final String name = metaData != null ? DescriptiveNameUtil.getMetaDataName(metaData) : xmlTag.getName();
String presentableName = metaData == null ? "<" + name + ">" : name;
return presentableName + " of file " + xmlTag.getContainingFile().getName();
}
if (element instanceof XmlAttributeValue) {
return ((XmlAttributeValue) element).getValue();
}
if (element instanceof PsiNamedElement) {
return ((PsiNamedElement) element).getName();
}
return element.getText();
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class HtmlDocumentationProvider method findDocumentationDescriptor.
private static EntityDescriptor findDocumentationDescriptor(PsiElement element, XmlTag context) {
boolean isTag = true;
PsiElement nameElement = null;
String key = null;
if (element instanceof XmlElementDecl) {
nameElement = ((XmlElementDecl) element).getNameElement();
} else if (element instanceof XmlAttributeDecl) {
nameElement = ((XmlAttributeDecl) element).getNameElement();
isTag = false;
} else if (element instanceof XmlTag) {
final XmlTag xmlTag = ((XmlTag) element);
final PsiMetaData metaData = xmlTag.getMetaData();
key = (metaData != null) ? metaData.getName() : null;
isTag = xmlTag.getLocalName().equals(ELEMENT_ELEMENT_NAME);
} else if (element.getParent() instanceof XmlAttributeValue) {
isTag = false;
key = ((XmlAttribute) element.getParent().getParent()).getName();
} else if (element instanceof XmlAttributeValue) {
isTag = false;
final XmlAttribute xmlAttribute = (XmlAttribute) element.getParent();
key = xmlAttribute.getName();
} else if (element instanceof XmlAttribute) {
final XmlAttribute xmlAttribute = (XmlAttribute) element;
isTag = false;
key = xmlAttribute.getName();
} else if (element instanceof XmlElement) {
nameElement = element;
isTag = !(element.getParent() instanceof XmlAttribute);
} else {
nameElement = element;
if (context != null) {
String text = element.getText();
isTag = text != null && text.startsWith(context.getName());
}
}
if (nameElement != null) {
key = nameElement.getText();
}
key = StringUtil.notNullize(key).toLowerCase(Locale.US);
int dotIndex = key.indexOf('.');
if (dotIndex > 0) {
key = key.substring(0, dotIndex);
}
if (isTag) {
return HtmlDescriptorsTable.getTagDescriptor(key);
} else {
return getDescriptor(key, context);
}
}
use of com.intellij.psi.meta.PsiMetaData 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.PsiMetaData 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;
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class LookupItemUtil method objectToLookupItem.
/**
* @deprecated
* @see LookupElementBuilder
*/
@NotNull
public static LookupElement objectToLookupItem(Object object) {
if (object instanceof LookupElement)
return (LookupElement) object;
if (object instanceof PsiClass) {
return JavaClassNameCompletionContributor.createClassLookupItem((PsiClass) object, true);
}
if (object instanceof PsiMethod) {
return new JavaMethodCallElement((PsiMethod) object);
}
if (object instanceof PsiVariable) {
return new VariableLookupItem((PsiVariable) object);
}
if (object instanceof PsiExpression) {
return new ExpressionLookupItem((PsiExpression) object);
}
if (object instanceof PsiType) {
return PsiTypeLookupItem.createLookupItem((PsiType) object, null);
}
if (object instanceof PsiPackage) {
return new PackageLookupItem((PsiPackage) object);
}
String s = null;
LookupItem item = new LookupItem(object, "");
if (object instanceof PsiElement) {
s = PsiUtilCore.getName((PsiElement) object);
}
TailType tailType = TailType.NONE;
if (object instanceof PsiMetaData) {
s = ((PsiMetaData) object).getName();
} else if (object instanceof String) {
s = (String) object;
} else if (object instanceof Template) {
s = ((Template) object).getKey();
} else if (object instanceof PresentableLookupValue) {
s = ((PresentableLookupValue) object).getPresentation();
}
if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
item.setBold();
}
if (s == null) {
LOG.error("Null string for object: " + object + " of class " + (object != null ? object.getClass() : null));
}
item.setLookupString(s);
item.setTailType(tailType);
return item;
}
Aggregations