Skip to content

Commit

Permalink
Improve inline breakpoint discovery when expression is multiline. Fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
gayanper committed Dec 5, 2023
1 parent b0c70e3 commit f50b519
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f50b519

Please sign in to comment.