diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JdtSourceLookUpProvider.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JdtSourceLookUpProvider.java index f0c8795c..22099b46 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JdtSourceLookUpProvider.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JdtSourceLookUpProvider.java @@ -72,8 +72,8 @@ import com.microsoft.java.debug.core.Configuration; import com.microsoft.java.debug.core.DebugException; import com.microsoft.java.debug.core.DebugSettings; -import com.microsoft.java.debug.core.JavaBreakpointLocation; import com.microsoft.java.debug.core.DebugSettings.Switch; +import com.microsoft.java.debug.core.JavaBreakpointLocation; import com.microsoft.java.debug.core.adapter.AdapterUtils; import com.microsoft.java.debug.core.adapter.Constants; import com.microsoft.java.debug.core.adapter.IDebugAdapterContext; @@ -248,7 +248,7 @@ private BreakpointLocation[] getInlineBreakpointLocations(final CompilationUnit public boolean visit(LambdaExpression node) { int lambdaStart = node.getStartPosition(); int startLine = astUnit.getLineNumber(lambdaStart); - if (startLine == sourceLine) { + if (findNearestRelatedLineToLambda(node) == sourceLine) { int startColumn = astUnit.getColumnNumber(lambdaStart); int lambdaEnd = lambdaStart + node.getLength(); int endLine = astUnit.getLineNumber(lambdaEnd); @@ -258,6 +258,21 @@ public boolean visit(LambdaExpression node) { } return super.visit(node); } + + private int findNearestRelatedLineToLambda(LambdaExpression lambda) { + ASTNode node = lambda; + while (node != null) { + int line = astUnit.getLineNumber(node.getStartPosition()); + if(line == sourceLine) { + return line; + } else if (line < sourceLine) { + // the lambda doesn't belong to current line at all + break; + } + node = node.getParent(); + } + return -1; + } }); return locations.toArray(BreakpointLocation[]::new);