This repository was archived by the owner on Mar 16, 2026. It is now read-only.
forked from microsoft/java-debug
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLambdaExpressionLocator.java
More file actions
103 lines (93 loc) · 3.55 KB
/
Copy pathLambdaExpressionLocator.java
File metadata and controls
103 lines (93 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*******************************************************************************
* 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) {
if (column > -1) {
int startPosition = node.getStartPosition();
int breakOffset = 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));
// Since the debugger supports BreakpointLocations Request to hint user
// about possible inline breakpoint locations, we will only support
// inline breakpoints added where a lambda expression begins.
if (breakOffset == startPosition) {
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 BindingUtils.toSignature(this.lambdaMethodBinding);
}
/**
* Returns the name of lambda method otherwise return null.
*/
public String getMethodName() {
if (!this.found) {
return null;
}
return BindingUtils.getMethodName(lambdaMethodBinding, true);
}
/**
* 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;
}
}