Skip to content

Commit

Permalink
Optimize lambda search
Browse files Browse the repository at this point in the history
Only search for lambda when the breakpoing is an inline breakpoint.
Add support for any column position within lambda expression.
  • Loading branch information
gayanper committed Jul 25, 2022
1 parent 5ce0cd3 commit 6eef4e8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public boolean visit(LambdaExpression node) {
if (column > -1) {
int startPosition = node.getStartPosition();

int columnNumber = this.compilationUnit.getColumnNumber(startPosition);
int startColumn = this.compilationUnit.getColumnNumber(startPosition);
int endColumn = this.compilationUnit.getColumnNumber(startPosition + node.getLength());
int lineNumber = this.compilationUnit.getLineNumber(startPosition);

if (column == columnNumber && lineNumber == line) {
if (column >= startColumn && startColumn <= endColumn && lineNumber == line) {
this.lambdaMethodBinding = node.resolveMethodBinding();
this.found = true;
this.lambdaExpression = node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,43 +156,46 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th
String[] fqns = new String[lines.length];
if (astUnit != null) {
for (int i = 0; i < lines.length; i++) {
// if we have a column, try to find the lambda expression at that column
LambdaExpressionLocator lambdaExpressionLocator = new LambdaExpressionLocator(astUnit, lines[i],
columns[i]);
astUnit.accept(lambdaExpressionLocator);
if (lambdaExpressionLocator.isFound()) {
fqns[i] = lambdaExpressionLocator.getFullyQualifiedTypeName().concat("#")
.concat(lambdaExpressionLocator.getMethodName())
.concat("#").concat(lambdaExpressionLocator.getMethodSignature());
} else {
// TODO
// The ValidBreakpointLocationLocator will verify if the current line is a valid
// location or not.
// If so, it will return the fully qualified name of the class type that
// contains the current line.
// Otherwise, it will try to find a valid location from the next lines and
// return it's fully qualified name.
// In current stage, we don't support to move the invalid breakpoint down to the
// next valid location, and just
// mark it as "unverified".
// In future, we could consider supporting to update the breakpoint to a valid
// location.
BreakpointLocationLocator locator = new BreakpointLocationLocator(astUnit, lines[i], true,
true);
astUnit.accept(locator);
// When the final valid line location is same as the original line, that
// represents it's a valid breakpoint.
// Add location type check to avoid breakpoint on method/field which will never
// be hit in current implementation.
if (lines[i] == locator.getLineLocation()
&& locator.getLocationType() == BreakpointLocationLocator.LOCATION_LINE) {
fqns[i] = locator.getFullyQualifiedTypeName();
} else if (locator.getLocationType() == BreakpointLocationLocator.LOCATION_METHOD) {
fqns[i] = locator.getFullyQualifiedTypeName().concat("#")
.concat(locator.getMethodName())
.concat("#").concat(locator.getMethodSignature());
if (columns[i] > -1) {
// if we have a column, try to find the lambda expression at that column
LambdaExpressionLocator lambdaExpressionLocator = new LambdaExpressionLocator(astUnit, lines[i],
columns[i]);
astUnit.accept(lambdaExpressionLocator);
if (lambdaExpressionLocator.isFound()) {
fqns[i] = lambdaExpressionLocator.getFullyQualifiedTypeName().concat("#")
.concat(lambdaExpressionLocator.getMethodName())
.concat("#").concat(lambdaExpressionLocator.getMethodSignature());
continue;
}
}

// TODO
// The ValidBreakpointLocationLocator will verify if the current line is a valid
// location or not.
// If so, it will return the fully qualified name of the class type that
// contains the current line.
// Otherwise, it will try to find a valid location from the next lines and
// return it's fully qualified name.
// In current stage, we don't support to move the invalid breakpoint down to the
// next valid location, and just
// mark it as "unverified".
// In future, we could consider supporting to update the breakpoint to a valid
// location.
BreakpointLocationLocator locator = new BreakpointLocationLocator(astUnit, lines[i], true,
true);
astUnit.accept(locator);
// When the final valid line location is same as the original line, that
// represents it's a valid breakpoint.
// Add location type check to avoid breakpoint on method/field which will never
// be hit in current implementation.
if (lines[i] == locator.getLineLocation()
&& locator.getLocationType() == BreakpointLocationLocator.LOCATION_LINE) {
fqns[i] = locator.getFullyQualifiedTypeName();
} else if (locator.getLocationType() == BreakpointLocationLocator.LOCATION_METHOD) {
fqns[i] = locator.getFullyQualifiedTypeName().concat("#")
.concat(locator.getMethodName())
.concat("#").concat(locator.getMethodSignature());
}
}
}
return fqns;
Expand Down

0 comments on commit 6eef4e8

Please sign in to comment.