mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
smart-step-into targets rendering: show method and parameter name for 'closure' step targets.
This commit is contained in:
@@ -25,9 +25,11 @@ import com.intellij.psi.*;
|
||||
import com.intellij.util.containers.OrderedSet;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* User: Alexander Podkhalyuzin
|
||||
@@ -76,11 +78,18 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
|
||||
|
||||
//noinspection unchecked
|
||||
final List<StepTarget> targets = new OrderedSet<StepTarget>();
|
||||
final PsiElementVisitor methodCollector = new JavaRecursiveElementWalkingVisitor() {
|
||||
final PsiElementVisitor methodCollector = new JavaRecursiveElementVisitor() {
|
||||
final Stack<String> myParamNameStack = new Stack<String>();
|
||||
|
||||
@Nullable
|
||||
private String getCurrentParamName() {
|
||||
return myParamNameStack.size() > 0? myParamNameStack.peek() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAnonymousClass(PsiAnonymousClass aClass) {
|
||||
for (PsiMethod psiMethod : aClass.getMethods()) {
|
||||
targets.add(new MethodTarget(psiMethod, true));
|
||||
targets.add(new MethodTarget(psiMethod, getCurrentParamName(), true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,10 +104,30 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
|
||||
public void visitCallExpression(final PsiCallExpression expression) {
|
||||
final PsiMethod psiMethod = expression.resolveMethod();
|
||||
if (psiMethod != null) {
|
||||
targets.add(new MethodTarget(psiMethod, false));
|
||||
targets.add(new MethodTarget(psiMethod, null, false));
|
||||
final PsiExpressionList argList = expression.getArgumentList();
|
||||
if (argList != null) {
|
||||
final String methodName = psiMethod.getName();
|
||||
final PsiExpression[] expressions = argList.getExpressions();
|
||||
final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
|
||||
for (int idx = 0; idx < expressions.length; idx++) {
|
||||
final String paramName = (idx < parameters.length && !parameters[idx].isVarArgs())? parameters[idx].getName() : "arg"+(idx+1);
|
||||
myParamNameStack.push(methodName + ": " + paramName);
|
||||
final PsiExpression argExpression = expressions[idx];
|
||||
try {
|
||||
argExpression.accept(this);
|
||||
}
|
||||
finally {
|
||||
myParamNameStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
super.visitCallExpression(expression);
|
||||
}
|
||||
super.visitCallExpression(expression);
|
||||
}
|
||||
|
||||
};
|
||||
element.accept(methodCollector);
|
||||
for (PsiElement sibling = element.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) {
|
||||
@@ -114,13 +143,20 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
|
||||
|
||||
private static class MethodTarget implements StepTarget {
|
||||
private final PsiMethod myMethod;
|
||||
private final String myLabel;
|
||||
private final boolean myNeedBreakpointRequest;
|
||||
|
||||
private MethodTarget(@NotNull PsiMethod method, boolean needBreakpointRequest) {
|
||||
private MethodTarget(@NotNull PsiMethod method, String currentParamName, boolean needBreakpointRequest) {
|
||||
myMethod = method;
|
||||
myLabel = currentParamName == null? null : currentParamName + ".";
|
||||
myNeedBreakpointRequest = needBreakpointRequest;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMethodLabel() {
|
||||
return myLabel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiMethod getMethod() {
|
||||
return myMethod;
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,6 +46,9 @@ public abstract class JvmSmartStepIntoHandler {
|
||||
@NotNull
|
||||
PsiMethod getMethod();
|
||||
|
||||
@Nullable
|
||||
String getMethodLabel();
|
||||
|
||||
boolean needsBreakpointRequest();
|
||||
|
||||
boolean equals(Object another);
|
||||
|
||||
@@ -59,13 +59,15 @@ class PsiMethodListPopupStep implements ListPopupStep<JvmSmartStepIntoHandler.St
|
||||
@NotNull
|
||||
public String getTextFor(JvmSmartStepIntoHandler.StepTarget value) {
|
||||
final PsiMethod method = value.getMethod();
|
||||
return PsiFormatUtil.formatMethod(
|
||||
final String methodLabel = value.getMethodLabel();
|
||||
final String methodRender = PsiFormatUtil.formatMethod(
|
||||
method,
|
||||
PsiSubstitutor.EMPTY,
|
||||
PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
|
||||
PsiFormatUtil.SHOW_TYPE,
|
||||
999
|
||||
);
|
||||
return methodLabel != null? methodLabel + methodRender : methodRender;
|
||||
}
|
||||
|
||||
public ListSeparator getSeparatorAbove(JvmSmartStepIntoHandler.StepTarget value) {
|
||||
|
||||
Reference in New Issue
Block a user