Skip to content

Commit 901d541

Browse files
committed
Introduce DecodedMethod
1 parent 39b44d1 commit 901d541

7 files changed

Lines changed: 69 additions & 45 deletions

File tree

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/IStackTraceProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
package com.microsoft.java.debug.core.adapter;
1313

1414
import com.microsoft.java.debug.core.protocol.Requests;
15+
import com.microsoft.java.debug.core.adapter.stacktrace.DecodedMethod;
1516
import com.sun.jdi.Location;
1617
import com.sun.jdi.Method;
1718
import java.util.Optional;
1819

1920
public interface IStackTraceProvider extends IProvider {
20-
boolean shouldSkipOver(Method method, Requests.StepFilters filters);
21-
boolean shouldSkipOut(Location upperLocation, Method method);
22-
Optional<String> formatMethod(Method method);
21+
boolean skipOver(Method method, Requests.StepFilters filters);
22+
boolean skipOut(Location upperLocation, Method method);
23+
DecodedMethod decode(Method method);
2324
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/StackTraceProvider.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
package com.microsoft.java.debug.core.adapter;
1313

1414
import com.microsoft.java.debug.core.protocol.Requests;
15+
import com.microsoft.java.debug.core.adapter.stacktrace.DecodedMethod;
16+
import com.microsoft.java.debug.core.adapter.stacktrace.JavaMethod;
1517
import com.sun.jdi.Location;
1618
import com.sun.jdi.Method;
1719
import org.apache.commons.lang3.ArrayUtils;
1820
import java.util.Optional;
1921

2022
public class StackTraceProvider implements IStackTraceProvider {
2123
@Override
22-
public boolean shouldSkipOver(Method method, Requests.StepFilters filters) {
24+
public boolean skipOver(Method method, Requests.StepFilters filters) {
2325
if (!isConfigured(filters)) {
2426
return false;
2527
}
@@ -29,14 +31,14 @@ public boolean shouldSkipOver(Method method, Requests.StepFilters filters) {
2931
}
3032

3133
@Override
32-
public boolean shouldSkipOut(Location previousLocation, Method method) {
34+
public boolean skipOut(Location previousLocation, Method method) {
3335
return false;
3436
}
3537

3638

3739
@Override
38-
public Optional<String> formatMethod(Method method) {
39-
return Optional.of(method.name());
40+
public DecodedMethod decode(Method method) {
41+
return new JavaMethod(method);
4042
}
4143

4244
private boolean isConfigured(Requests.StepFilters filters) {

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private void registerBreakpointHandler(IDebugAdapterContext context) {
200200
return;
201201
}
202202
Method method = bpThread.frame(0).location().method();
203-
if (stackTraceProvider.shouldSkipOver(method, context.getStepFilters())) {
203+
if (stackTraceProvider.skipOver(method, context.getStepFilters())) {
204204
debugEvent.shouldResume = true;
205205
return;
206206
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/StackTraceRequestHandler.java

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.microsoft.java.debug.core.adapter.ISourceLookUpProvider;
3030
import com.microsoft.java.debug.core.adapter.IStackTraceProvider;
3131
import com.microsoft.java.debug.core.adapter.formatter.SimpleTypeFormatter;
32+
import com.microsoft.java.debug.core.adapter.stacktrace.DecodedMethod;
3233
import com.microsoft.java.debug.core.adapter.variables.StackFrameReference;
3334
import com.microsoft.java.debug.core.protocol.Messages.Response;
3435
import com.microsoft.java.debug.core.protocol.Requests.Arguments;
@@ -79,10 +80,10 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
7980
StackFrameReference stackframe = new StackFrameReference(thread, i);
8081
int frameId = context.getRecyclableIdPool().addObject(thread.uniqueID(), stackframe);
8182
IStackTraceProvider stackTraceProvider = context.getProvider(IStackTraceProvider.class);
82-
Optional<String> formattedMethod = stackTraceProvider.formatMethod(thread.frame(i).location().method());
83-
84-
if(formattedMethod.isPresent()) {
85-
result.add(convertDebuggerStackFrameToClient(frames[i], frameId, context, formattedMethod.get()));
83+
DecodedMethod decodedMethod = stackTraceProvider.decode(thread.frame(i).location().method());
84+
85+
if(!decodedMethod.isGenerated()) {
86+
result.add(convertDebuggerStackFrameToClient(frames[i], frameId, context, decodedMethod));
8687
}
8788
}
8889
} catch (IncompatibleThreadStateException | IndexOutOfBoundsException | URISyntaxException
@@ -99,25 +100,18 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
99100
return CompletableFuture.completedFuture(response);
100101
}
101102

102-
private Types.StackFrame convertDebuggerStackFrameToClient(StackFrame stackFrame, int frameId, IDebugAdapterContext context,String formattedName)
103+
private Types.StackFrame convertDebuggerStackFrameToClient(StackFrame stackFrame, int frameId, IDebugAdapterContext context, DecodedMethod decodedMethod)
103104
throws URISyntaxException, AbsentInformationException {
104105
Location location = stackFrame.location();
105-
Method method = location.method();
106106
Types.Source clientSource = this.convertDebuggerSourceToClient(location, context);
107-
//String methodName = formatMethodName(method, true, true,formattedName);
107+
String formattedName = decodedMethod.format();
108108
int lineNumber = AdapterUtils.convertLineNumber(location.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1());
109109
// Line number returns -1 if the information is not available; specifically, always returns -1 for native methods.
110-
if (lineNumber < 0) {
111-
if (method.isNative()) {
112-
// For native method, display a tip text "native method" in the Call Stack View.
113-
formattedName += "[native method]";
114-
} else {
115-
// For other unavailable method, such as lambda expression's built-in methods run/accept/apply,
116-
// display "Unknown Source" in the Call Stack View.
117-
clientSource = null;
118-
}
110+
if (lineNumber < 0 && !location.method().isNative()) {
111+
// For other unavailable method, such as lambda expression's built-in methods run/accept/apply,
112+
// display "Unknown Source" in the Call Stack View.
113+
clientSource = null;
119114
}
120-
121115
return new Types.StackFrame(frameId, formattedName, clientSource, lineNumber, context.isClientColumnsStartAt1() ? 1 : 0);
122116
}
123117

@@ -175,21 +169,4 @@ public static Types.Source convertDebuggerSourceToClient(String fullyQualifiedNa
175169
}
176170
}
177171
}
178-
179-
private String formatMethodName(Method method, boolean showContextClass, boolean showParameter,String formattedNameString) {
180-
StringBuilder formattedName = new StringBuilder();
181-
/* if (showContextClass) {
182-
// String fullyQualifiedClassName = method.declaringType().name();
183-
formattedName.append(SimpleTypeFormatter.trimTypeName(formattedNameString));
184-
formattedName.append(".");
185-
}*/
186-
formattedName.append(formattedNameString);
187-
if (showParameter) {
188-
List<String> argumentTypeNames = method.argumentTypeNames().stream().map(SimpleTypeFormatter::trimTypeName).collect(Collectors.toList());
189-
formattedName.append("(");
190-
formattedName.append(String.join(",", argumentTypeNames));
191-
formattedName.append(")");
192-
}
193-
return formattedName.toString();
194-
}
195172
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/StepRequestHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession,
200200
*/
201201
private boolean shouldSkipOver(IStackTraceProvider stackTrace, Location originalLocation, Location currentLocation, Requests.StepFilters stepFilters)
202202
throws IncompatibleThreadStateException {
203-
return !stackTrace.shouldSkipOver(originalLocation.method(), stepFilters)
204-
&& stackTrace.shouldSkipOver(currentLocation.method(), stepFilters);
203+
return !stackTrace.skipOver(originalLocation.method(), stepFilters)
204+
&& stackTrace.skipOver(currentLocation.method(), stepFilters);
205205
}
206206

207207
private boolean shouldSkipOut(IStackTraceProvider stackTrace, int originalStackDepth, int currentStackDepth, Location upperLocation,
@@ -213,7 +213,7 @@ private boolean shouldSkipOut(IStackTraceProvider stackTrace, int originalStackD
213213
if (currentStackDepth <= originalStackDepth) {
214214
return false;
215215
}
216-
return stackTrace.shouldSkipOut(upperLocation, currentLocation.method());
216+
return stackTrace.skipOut(upperLocation, currentLocation.method());
217217
}
218218

219219
/**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.microsoft.java.debug.core.adapter.stacktrace;
2+
3+
public interface DecodedMethod {
4+
String format();
5+
6+
boolean isGenerated();
7+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.microsoft.java.debug.core.adapter.stacktrace;
2+
3+
import java.util.List;
4+
import java.util.stream.Collectors;
5+
6+
import com.microsoft.java.debug.core.adapter.formatter.SimpleTypeFormatter;
7+
import com.sun.jdi.Method;
8+
9+
public class JavaMethod implements DecodedMethod {
10+
private Method method;
11+
12+
public JavaMethod(Method method) {
13+
this.method = method;
14+
}
15+
16+
@Override
17+
public String format() {
18+
StringBuilder formattedName = new StringBuilder();
19+
String fullyQualifiedClassName = method.declaringType().name();
20+
formattedName.append(SimpleTypeFormatter.trimTypeName(fullyQualifiedClassName));
21+
formattedName.append(".");
22+
List<String> argumentTypeNames = method.argumentTypeNames().stream().map(SimpleTypeFormatter::trimTypeName).collect(Collectors.toList());
23+
formattedName.append("(");
24+
formattedName.append(String.join(",", argumentTypeNames));
25+
formattedName.append(")");
26+
if (method.isNative()) {
27+
// For native method, display a tip text "native method" in the Call Stack View.
28+
formattedName.append("[native method]");
29+
}
30+
return formattedName.toString();
31+
}
32+
33+
@Override
34+
public boolean isGenerated() {
35+
return method.isBridge() || method.isSynthetic();
36+
}
37+
}

0 commit comments

Comments
 (0)