From 29487a16f08b232aa6bc88e314ff4c0247bdd5d6 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 23 Oct 2013 23:26:39 +0200 Subject: [PATCH] smart-step-into targets rendering: show method and parameter name for 'closure' step targets. --- .../actions/JavaSmartStepIntoHandler.java | 46 +++++++++++++++++-- .../actions/JvmSmartStepIntoHandler.java | 4 ++ .../actions/PsiMethodListPopupStep.java | 4 +- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/JavaSmartStepIntoHandler.java b/java/debugger/impl/src/com/intellij/debugger/actions/JavaSmartStepIntoHandler.java index 04fb88a90cb1..4adedd69a776 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/JavaSmartStepIntoHandler.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/JavaSmartStepIntoHandler.java @@ -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 targets = new OrderedSet(); - final PsiElementVisitor methodCollector = new JavaRecursiveElementWalkingVisitor() { + final PsiElementVisitor methodCollector = new JavaRecursiveElementVisitor() { + final Stack myParamNameStack = new Stack(); + + @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; diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/JvmSmartStepIntoHandler.java b/java/debugger/impl/src/com/intellij/debugger/actions/JvmSmartStepIntoHandler.java index 013cdf8645b9..b91893b09fbb 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/JvmSmartStepIntoHandler.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/JvmSmartStepIntoHandler.java @@ -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); diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/PsiMethodListPopupStep.java b/java/debugger/impl/src/com/intellij/debugger/actions/PsiMethodListPopupStep.java index eeefcd439993..c7c880a09c2a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/PsiMethodListPopupStep.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/PsiMethodListPopupStep.java @@ -59,13 +59,15 @@ class PsiMethodListPopupStep implements ListPopupStep