下面列出了怎么用com.intellij.psi.ElementDescriptionLocation的API类实例代码及写法,或者点击链接到github查看源代码。
@Nullable
@Override
public String getElementDescription(PsiElement element, ElementDescriptionLocation location) {
if (!(element instanceof BuildElement)) {
return null;
}
if (location instanceof UsageViewLongNameLocation) {
return ((BuildElement) element).getPresentableText();
}
if (location instanceof UsageViewShortNameLocation) {
if (element instanceof PsiNameIdentifierOwner) {
// this is used by rename operations, so needs to be accurate
return ((PsiNameIdentifierOwner) element).getName();
}
if (element instanceof PsiFile) {
return ((PsiFile) element).getName();
}
return ((BuildElement) element).getPresentableText();
}
return null;
}
@Override
@Nullable
public String getElementDescription(@NotNull PsiElement element, @NotNull ElementDescriptionLocation location) {
if (!(element instanceof GLSLDeclarator)) return null;
GLSLDeclarator declarator = (GLSLDeclarator) element;
GLSLDeclaration declaration = declarator.getParentDeclaration();
if (declaration == null) return null;
if (location instanceof UsageViewTypeLocation) {
return declaration.getDeclarationDescription();
}
if (location instanceof UsageViewLongNameLocation) {
return declaration.getDeclarationDescription() + " '" + declarator.getName() + "'";
}
if (location instanceof UsageViewNodeTextLocation) {
return declarator.getName();
}
return null;
// return location.toString();
}
@Nullable
@Override
public String getElementDescription(@NotNull PsiElement element, @NotNull ElementDescriptionLocation location) {
if (!element.getLanguage().is(HaskellLanguage.INSTANCE)) return null;
if (!(element instanceof HaskellNamedElement)) return null;
return ((HaskellNamedElement) element).getName();
}
@Nullable
@Override
@RequiredReadAction
public String getElementDescription(@Nonnull PsiElement element, @Nonnull ElementDescriptionLocation location)
{
if(location == UsageViewShortNameLocation.INSTANCE && element instanceof CSharpNamedElement)
{
return ((CSharpNamedElement) element).getNameWithAt();
}
return null;
}
@Override
@Nullable
public String getElementDescription(@Nonnull PsiElement element, @Nonnull ElementDescriptionLocation location) {
if (element instanceof PomTargetPsiElement) {
return getElementDescription(((PomTargetPsiElement)element).getTarget(), location);
}
return null;
}
@Override
public ElementDescriptionProvider getDefaultProvider() {
return new ElementDescriptionProvider() {
@Override
public String getElementDescription(@Nonnull PsiElement element, @Nonnull ElementDescriptionLocation location) {
if (element instanceof PsiPresentableMetaData) {
return ((PsiPresentableMetaData)element).getTypeName();
}
return null;
}
};
}
@Override
public String getElementDescription(@Nonnull final PsiElement element, @Nonnull final ElementDescriptionLocation location) {
if (location instanceof UsageViewLongNameLocation) {
if (element instanceof PsiDirectory) {
return PsiPackageHelper.getInstance(element.getProject()).getQualifiedName((PsiDirectory)element, true);
}
return "";
}
return null;
}
@Override
public String getElementDescription(@Nonnull final PsiElement element, @Nonnull final ElementDescriptionLocation location) {
if (!(location instanceof UsageViewShortNameLocation)) return null;
if (element instanceof PsiMetaOwner) {
PsiMetaData metaData = ((PsiMetaOwner)element).getMetaData();
if (metaData!=null) return DescriptiveNameUtil.getMetaDataName(metaData);
}
if (element instanceof PsiNamedElement) {
return ((PsiNamedElement)element).getName();
}
return "";
}
@Override
public String getElementDescription(@Nonnull PomTarget element, @Nonnull ElementDescriptionLocation location) {
if (element instanceof PsiElement) return null;
if (location == UsageViewTypeLocation.INSTANCE) {
return getTypeName(element);
}
if (location == UsageViewNodeTextLocation.INSTANCE) {
return getTypeName(element) + " " + StringUtil.notNullize(element instanceof PomNamedTarget ? ((PomNamedTarget)element).getName() : null, "''");
}
if (location instanceof HighlightUsagesDescriptionLocation) {
return getTypeName(element);
}
return null;
}
@Override
public String getElementDescription(@Nonnull final PsiElement element, @Nonnull final ElementDescriptionLocation location) {
if (location instanceof DeleteNameDescriptionLocation) {
if (element instanceof PsiNamedElement) {
return ((PsiNamedElement)element).getName();
}
}
return null;
}
@Nullable
public abstract String getElementDescription(@Nonnull PomTarget element, @Nonnull ElementDescriptionLocation location);
@Override
public String getElementDescription(@Nonnull final PsiElement element, @Nonnull final ElementDescriptionLocation location) {
final String typeString = UsageViewUtil.getType(element);
final String name = DescriptiveNameUtil.getDescriptiveName(element);
return typeString + " " + CommonRefactoringUtil.htmlEmphasize(name);
}