Skip to content

Commit f50b519

Browse files
committed
Improve inline breakpoint discovery when expression is multiline. Fix #521
1 parent b0c70e3 commit f50b519

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JdtSourceLookUpProvider.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
import com.microsoft.java.debug.core.Configuration;
7373
import com.microsoft.java.debug.core.DebugException;
7474
import com.microsoft.java.debug.core.DebugSettings;
75-
import com.microsoft.java.debug.core.JavaBreakpointLocation;
7675
import com.microsoft.java.debug.core.DebugSettings.Switch;
76+
import com.microsoft.java.debug.core.JavaBreakpointLocation;
7777
import com.microsoft.java.debug.core.adapter.AdapterUtils;
7878
import com.microsoft.java.debug.core.adapter.Constants;
7979
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
@@ -248,7 +248,7 @@ private BreakpointLocation[] getInlineBreakpointLocations(final CompilationUnit
248248
public boolean visit(LambdaExpression node) {
249249
int lambdaStart = node.getStartPosition();
250250
int startLine = astUnit.getLineNumber(lambdaStart);
251-
if (startLine == sourceLine) {
251+
if (findNearestRelatedLineToLambda(node) == sourceLine) {
252252
int startColumn = astUnit.getColumnNumber(lambdaStart);
253253
int lambdaEnd = lambdaStart + node.getLength();
254254
int endLine = astUnit.getLineNumber(lambdaEnd);
@@ -258,6 +258,21 @@ public boolean visit(LambdaExpression node) {
258258
}
259259
return super.visit(node);
260260
}
261+
262+
private int findNearestRelatedLineToLambda(LambdaExpression lambda) {
263+
ASTNode node = lambda;
264+
while (node != null) {
265+
int line = astUnit.getLineNumber(node.getStartPosition());
266+
if(line == sourceLine) {
267+
return line;
268+
} else if (line < sourceLine) {
269+
// the lambda doesn't belong to current line at all
270+
break;
271+
}
272+
node = node.getParent();
273+
}
274+
return -1;
275+
}
261276
});
262277

263278
return locations.toArray(BreakpointLocation[]::new);

0 commit comments

Comments
 (0)