-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for lambda breakpoints (#427)
* Add support for lambda breakpoints The support for method header breakpoints was extended to support lambda breakpoints using the vscode inline breakpoint feature. * Optimize lambda search Only search for lambda when the breakpoing is an inline breakpoint. Add support for any column position within lambda expression. * Improve for multi line and multi lambdas * Improve lambda breakpoints - Only support for expressions. - The inline breakpoint should be before the expression start. * Remove the unnecessary nodeType check Co-authored-by: Jinbo Wang <[email protected]>
- Loading branch information
1 parent
8c0e87d
commit fe77989
Showing
10 changed files
with
231 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...oft.java.debug.plugin/src/main/java/com/microsoft/java/debug/LambdaExpressionLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Microsoft Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Gayan Perera ([email protected]) - initial API and implementation | ||
*******************************************************************************/ | ||
package com.microsoft.java.debug; | ||
|
||
import org.eclipse.jdt.core.dom.ASTNode; | ||
import org.eclipse.jdt.core.dom.ASTVisitor; | ||
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; | ||
import org.eclipse.jdt.core.dom.CompilationUnit; | ||
import org.eclipse.jdt.core.dom.IMethodBinding; | ||
import org.eclipse.jdt.core.dom.LambdaExpression; | ||
|
||
public class LambdaExpressionLocator extends ASTVisitor { | ||
private CompilationUnit compilationUnit; | ||
private int line; | ||
private int column; | ||
private boolean found; | ||
|
||
private IMethodBinding lambdaMethodBinding; | ||
private LambdaExpression lambdaExpression; | ||
|
||
public LambdaExpressionLocator(CompilationUnit compilationUnit, int line, int column) { | ||
this.compilationUnit = compilationUnit; | ||
this.line = line; | ||
this.column = column; | ||
} | ||
|
||
@Override | ||
public boolean visit(LambdaExpression node) { | ||
// we only support inline breakpoints which are added before the expression part of the | ||
// lambda. And we don't support lambda blocks since they can be debugged using line | ||
// breakpoints. | ||
if (column > -1) { | ||
int startPosition = node.getStartPosition(); | ||
int endPosition = node.getBody().getStartPosition(); | ||
int offset = this.compilationUnit.getPosition(line, column); | ||
// lambda on same line: | ||
// list.stream().map(i -> i + 1); | ||
// | ||
// lambda on multiple lines: | ||
// list.stream().map(user | ||
// -> user.isSystem() ? new SystemUser(user) : new EndUser(user)); | ||
|
||
if (offset >= startPosition && offset <= endPosition) { | ||
this.lambdaMethodBinding = node.resolveMethodBinding(); | ||
this.found = true; | ||
this.lambdaExpression = node; | ||
return false; | ||
} | ||
} | ||
return super.visit(node); | ||
} | ||
|
||
/** | ||
* Returns <code>true</code> if a lambda is found at given location. | ||
*/ | ||
public boolean isFound() { | ||
return found; | ||
} | ||
|
||
/** | ||
* Returns the signature of lambda method otherwise return null. | ||
*/ | ||
public String getMethodSignature() { | ||
if (!this.found) { | ||
return null; | ||
} | ||
return BreakpointLocationLocator.toSignature(this.lambdaMethodBinding, getMethodName()); | ||
} | ||
|
||
/** | ||
* Returns the name of lambda method otherwise return null. | ||
*/ | ||
public String getMethodName() { | ||
if (!this.found) { | ||
return null; | ||
} | ||
String key = this.lambdaMethodBinding.getKey(); | ||
return key.substring(key.indexOf('.') + 1, key.indexOf('(')); | ||
} | ||
|
||
/** | ||
* Returns the name of the type which the lambda method is found. | ||
*/ | ||
public String getFullyQualifiedTypeName() { | ||
if (this.found) { | ||
ASTNode parent = lambdaExpression.getParent(); | ||
while (parent != null) { | ||
if (parent instanceof AbstractTypeDeclaration) { | ||
AbstractTypeDeclaration declaration = (AbstractTypeDeclaration) parent; | ||
return declaration.resolveBinding().getBinaryName(); | ||
} | ||
parent = parent.getParent(); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.