-
Notifications
You must be signed in to change notification settings - Fork 188
Add support for lambda breakpoints #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
438078d
Add support for lambda breakpoints
gayanper 9b001d7
Optimize lambda search
gayanper ec133c3
Improve for multi line and multi lambdas
gayanper 6dcb88d
Improve lambda breakpoints
gayanper aec3abe
Remove the unnecessary nodeType check
testforstephen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 (gayanper@gmail.com) - 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.