Skip to content

Commit

Permalink
improve lambda discovery
Browse files Browse the repository at this point in the history
This will handle lambda blocks and convert inline to line breakpoints if
if line and lambda block first line doesn't match.
  • Loading branch information
gayanper committed Aug 2, 2022
1 parent ec133c3 commit f3a7a1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ private static List<Location> collectLocations(List<ReferenceType> refTypes, int
return locations;
}

private static List<Location> collectLocations(List<ReferenceType> refTypes, String nameAndSignature) {
private static List<Location> collectLocations(List<ReferenceType> refTypes,
String nameAndSignature, int line) {
List<Location> locations = new ArrayList<>();
String[] segments = nameAndSignature.split("#");

Expand All @@ -257,6 +258,7 @@ private static List<Location> collectLocations(List<ReferenceType> refTypes, Str
for (Method method : methods) {
if (!method.isAbstract() && !method.isNative()
&& segments[0].equals(method.name())
&& method.location().lineNumber() == line
&& (segments[1].equals(method.genericSignature()) || segments[1].equals(method.signature()))) {
locations.add(method.location());
break;
Expand All @@ -275,10 +277,12 @@ private List<BreakpointRequest> createBreakpointRequests(ReferenceType refType,

private List<BreakpointRequest> createBreakpointRequests(List<ReferenceType> refTypes, int lineNumber,
int hitCount, boolean includeNestedTypes) {
List<Location> locations;
List<Location> locations = null;
if (this.methodSignature != null) {
locations = collectLocations(refTypes, this.methodSignature);
} else {
locations = collectLocations(refTypes, this.methodSignature, lineNumber);
}

if (locations == null || locations.isEmpty()) {
locations = collectLocations(refTypes, lineNumber, includeNestedTypes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ public LambdaExpressionLocator(CompilationUnit compilationUnit, int line, int co
public boolean visit(LambdaExpression node) {
if (column > -1) {
int startPosition = node.getStartPosition();

int startColumn = this.compilationUnit.getColumnNumber(startPosition);
int endPosition = startPosition + node.getLength();
int endColumn = this.compilationUnit.getColumnNumber(endPosition);
int startLine = this.compilationUnit.getLineNumber(startPosition);
int endLine = this.compilationUnit.getLineNumber(endPosition);
int offset = this.compilationUnit.getPosition(line, column);

// lambda on same line:
// list.stream().map(i -> i + 1);
Expand All @@ -50,9 +46,7 @@ public boolean visit(LambdaExpression node) {
// list.stream().map(user
// -> user.isSystem() ? new SystemUser(user) : new EndUser(user));

if ((startLine == endLine && column >= startColumn && column <= endColumn && line == startLine)
|| (startLine != endLine && line >= startLine && line <= endLine
&& (column >= startColumn || column <= endColumn))) {
if (offset >= startPosition && offset <= endPosition) {
this.lambdaMethodBinding = node.resolveMethodBinding();
this.found = true;
this.lambdaExpression = node;
Expand Down

0 comments on commit f3a7a1e

Please sign in to comment.