mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
lambda expressions breadcrumbs
This commit is contained in:
@@ -16,9 +16,8 @@
|
||||
package com.intellij.lang.java;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.psi.ElementDescriptionUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.util.RefactoringDescriptionLocation;
|
||||
import com.intellij.usageView.UsageViewShortNameLocation;
|
||||
import com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider;
|
||||
@@ -37,18 +36,45 @@ public class JavaBreadcrumbsInfoProvider extends BreadcrumbsInfoProvider {
|
||||
|
||||
@Override
|
||||
public boolean acceptElement(@NotNull PsiElement e) {
|
||||
return e instanceof PsiMember;
|
||||
return e instanceof PsiMember || e instanceof PsiLambdaExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getElementInfo(@NotNull PsiElement e) {
|
||||
if (e instanceof PsiLambdaExpression) {
|
||||
PsiType type = ((PsiFunctionalExpression)e).getFunctionalInterfaceType();
|
||||
return type == null ? "<lambda>" : "lambda " + PsiNameHelper.getShortClassName(type.getCanonicalText());
|
||||
}
|
||||
return ElementDescriptionUtil.getElementDescription(e, UsageViewShortNameLocation.INSTANCE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getElementTooltip(@NotNull PsiElement e) {
|
||||
if (e instanceof PsiLambdaExpression) return getLambdaDescription((PsiLambdaExpression)e);
|
||||
return ElementDescriptionUtil.getElementDescription(e, RefactoringDescriptionLocation.WITH_PARENT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getLambdaDescription(@NotNull PsiLambdaExpression e) {
|
||||
StringBuilder sb = new StringBuilder("lambda");
|
||||
PsiType functionalInterfaceType = e.getFunctionalInterfaceType();
|
||||
if (functionalInterfaceType != null) {
|
||||
String shortClassName = PsiNameHelper.getShortClassName(functionalInterfaceType.getCanonicalText());
|
||||
sb.append(" ").append(StringUtil.htmlEmphasize(shortClassName));
|
||||
}
|
||||
PsiParameter[] parameters = e.getParameterList().getParameters();
|
||||
if (parameters.length > 0) {
|
||||
sb.append(" (");
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
if (i > 0) sb.append(", ");
|
||||
String str = PsiNameHelper.getShortClassName(parameters[i].getType().getCanonicalText());
|
||||
if (str.isEmpty()) str = StringUtil.notNullize(parameters[i].getName());
|
||||
sb.append(StringUtil.htmlEmphasize(str));
|
||||
}
|
||||
sb.append(")");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user