Skip to content

Commit 0105262

Browse files
trancexpressiloveeclipse
authored andcommitted
Bug 558907 - Step over should filter lambda synthetic line
When stepping over the last line of a lambda body, the debugger will hold at a synthetic line that is not visible in the source code. This change ensures such lines are filtered by step over. Change-Id: I15d61b2f4ef5becefb9a5d3558dc12c5664581ee Signed-off-by: Simeon Andreev <[email protected]> Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.debug/+/189240 Tested-by: Andrey Loskutov <[email protected]> Tested-by: JDT Bot <[email protected]> Reviewed-by: Andrey Loskutov <[email protected]>
1 parent f5f784d commit 0105262

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIThread.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,8 +2787,8 @@ public boolean handleEvent(Event event, JDIDebugTarget target,
27872787
fStepResultTimeoutTriggered.set(false);
27882788
}
27892789

2790+
Location stepOverLocation2 = fStepOverLocation;
27902791
if (getStepKind() == StepRequest.STEP_OVER) {
2791-
Location stepOverLocation2 = fStepOverLocation;
27922792
if (stepOverLocation2 != null && fStepOverFrameCount >= 0) {
27932793
int underlyingFrameCount = getUnderlyingFrameCount();
27942794
if (underlyingFrameCount > fStepOverFrameCount) {
@@ -2824,7 +2824,8 @@ public boolean handleEvent(Event event, JDIDebugTarget target,
28242824
// a filtered location, or if we're back where
28252825
// we started on a step into, do another step of the same kind
28262826
if (locationShouldBeFiltered(currentLocation)
2827-
|| shouldDoExtraStepInto(currentLocation)) {
2827+
|| shouldDoExtraStepInto(currentLocation)
2828+
|| (getStepKind() == StepRequest.STEP_OVER && isSyntheticAndNotAvailable(currentLocation, stepOverLocation2))) {
28282829
setRunning(true);
28292830
deleteStepRequest();
28302831
createSecondaryStepRequest();
@@ -2985,6 +2986,22 @@ protected void abort() {
29852986
fStepOverFrameCount = -1;
29862987
}
29872988
}
2989+
2990+
private boolean isSyntheticAndNotAvailable(Location currentLocation, Location previousLocation) {
2991+
if (previousLocation != null) {
2992+
Method method = previousLocation.method();
2993+
if (method != null && method.isSynthetic()) {
2994+
boolean isLambdaMethod = LambdaUtils.isLambdaMethod(method);
2995+
if (isLambdaMethod) {
2996+
int currentLineNumber = currentLocation.lineNumber();
2997+
if (currentLineNumber == -1) {
2998+
return true;
2999+
}
3000+
}
3001+
}
3002+
}
3003+
return false;
3004+
}
29883005
}
29893006

29903007
/**

org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/LambdaUtils.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.internal.debug.core.model;
1515

16-
1716
import java.util.ArrayList;
1817
import java.util.Arrays;
1918
import java.util.Collections;
@@ -31,11 +30,15 @@
3130
import org.eclipse.jdt.internal.debug.core.logicalstructures.JDILambdaVariable;
3231
import org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext;
3332

33+
import com.sun.jdi.Method;
34+
3435
/**
3536
* Utility class for Lambda Expressions and Stack frames Place holder for all Lambda operation encapsulation.
3637
*/
3738
public class LambdaUtils {
3839

40+
private static final String LAMBDA_METHOD_PREFIX = "lambda$"; //$NON-NLS-1$
41+
3942
/**
4043
* Inspects the top stack frame of the context; if that frame is a lambda frame, looks for a variable with the specified name in that frame and
4144
* two frames below that frame.
@@ -121,7 +124,7 @@ public static boolean isLambdaFrame(IStackFrame frame) throws DebugException {
121124
* @since 3.8
122125
*/
123126
public static boolean isLambdaFrame(IJavaStackFrame frame) throws DebugException {
124-
return frame.isSynthetic() && frame.getName().startsWith("lambda$"); //$NON-NLS-1$
127+
return frame.isSynthetic() && frame.getName().startsWith(LAMBDA_METHOD_PREFIX);
125128
}
126129

127130
/**
@@ -136,6 +139,18 @@ public static boolean isLambdaField(IVariable variable) throws DebugException {
136139
return (variable instanceof IJavaFieldVariable) && ((IJavaFieldVariable) variable).getDeclaringType().getName().contains("$Lambda$"); //$NON-NLS-1$
137140
}
138141

142+
/**
143+
* Returns if the method is a lambda method.
144+
*
145+
* @param method
146+
* the method for which to check
147+
* @return <code>True</code> if the method is a lambda method else return <code>False</code>
148+
* @since 3.20
149+
*/
150+
public static boolean isLambdaMethod(Method method) {
151+
return method.name().startsWith(LAMBDA_METHOD_PREFIX);
152+
}
153+
139154
private static boolean isLambdaObjectVariable(IVariable variable) {
140155
return variable instanceof JDILambdaVariable;
141156
}

0 commit comments

Comments
 (0)