From 6eef4e8dec1b6ea542a5f7fdb0b0ef8baa191b74 Mon Sep 17 00:00:00 2001 From: Gayan Perera Date: Fri, 22 Jul 2022 19:30:56 +0200 Subject: [PATCH] Optimize lambda search Only search for lambda when the breakpoing is an inline breakpoint. Add support for any column position within lambda expression. --- .../java/debug/LambdaExpressionLocator.java | 5 +- .../internal/JdtSourceLookUpProvider.java | 73 ++++++++++--------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/LambdaExpressionLocator.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/LambdaExpressionLocator.java index b60328240..f8a64764a 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/LambdaExpressionLocator.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/LambdaExpressionLocator.java @@ -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; 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 81f9f09f9..1dc1c0e64 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 @@ -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;