Skip to content

Commit 5d67623

Browse files
Method Breakpoint does not recognised when set at end of a method
This PR fixes the issue where breakpoints set at the end of a method did not behave like method breakpoints, ensuring both entry and exit events are consistently shown. Fix: #697
1 parent 3d100ec commit 5d67623

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ToggleBreakpointAdapter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -402,6 +402,9 @@ private static void doToggleMethodBreakpoint(IMethod member, String lambdaMethod
402402
deleteTracepoint(breakpoint, part, monitor);
403403
BreakpointToggleUtils.setUnsetTracepoints(false);
404404
} else {
405+
if (ValidBreakpointLocationLocator.LOCATION_METHOD_CLOSE) {
406+
ValidBreakpointLocationLocator.LOCATION_METHOD_CLOSE = false;
407+
}
405408
deleteBreakpoint(breakpoint, part, monitor);
406409
}
407410
return;
@@ -445,6 +448,11 @@ private static void doToggleMethodBreakpoint(IMethod member, String lambdaMethod
445448
}
446449
BreakpointToggleUtils.setUnsetTracepoints(false);
447450
}
451+
if (ValidBreakpointLocationLocator.LOCATION_METHOD_CLOSE) {
452+
methodBreakpoint.setEntry(false);
453+
methodBreakpoint.setExit(true);
454+
ValidBreakpointLocationLocator.LOCATION_METHOD_CLOSE = false;
455+
}
448456
}
449457

450458
/**
@@ -1806,4 +1814,4 @@ private static ICompilationUnit getCompilationUnit(ITextEditor editor) {
18061814
return JavaCore.createCompilationUnitFrom(file);
18071815
}
18081816

1809-
}
1817+
}

org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ValidBreakpointLocationLocator.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2003, 2023 IBM Corporation and others.
2+
* Copyright (c) 2003, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -128,6 +128,7 @@ public class ValidBreakpointLocationLocator extends ASTVisitor {
128128
public static final int LOCATION_METHOD = 2;
129129
public static final int LOCATION_FIELD = 3;
130130
public static final int LOCATION_LAMBDA_METHOD = 4;
131+
public static boolean LOCATION_METHOD_CLOSE = false;
131132

132133

133134
private final CompilationUnit fCompilationUnit;
@@ -1129,10 +1130,9 @@ public boolean visit(MemberValuePair node) {
11291130
public boolean visit(MethodDeclaration node) {
11301131
if (visit(node, false)) {
11311132
if (fBestMatch) {
1132-
// check if we are on the line which contains the method name
11331133
int nameOffset = node.getName().getStartPosition();
11341134
if (lineNumber(nameOffset) == fLineNumber) {
1135-
if (node.getParent() instanceof AnonymousClassDeclaration){
1135+
if (node.getParent() instanceof AnonymousClassDeclaration) {
11361136
fLocationType = LOCATION_NOT_FOUND;
11371137
fLocationFound = true;
11381138
return false;
@@ -1142,16 +1142,29 @@ public boolean visit(MethodDeclaration node) {
11421142
fLocationFound = true;
11431143
return false;
11441144
}
1145-
}
1146-
// visit only the body
1147-
Block body = node.getBody();
1148-
if (body != null) { // body is null for abstract methods
1149-
body.accept(this);
1145+
1146+
Block body = node.getBody();
1147+
if (body != null) {
1148+
int bodyStart = body.getStartPosition();
1149+
int bodyLength = body.getLength();
1150+
int bodyEnd = bodyStart + bodyLength;
1151+
int closingBraceOffset = bodyEnd - 1;
1152+
1153+
if (lineNumber(closingBraceOffset) == fLineNumber) {
1154+
fMemberOffset = closingBraceOffset;
1155+
LOCATION_METHOD_CLOSE = true;
1156+
fLocationType = LOCATION_METHOD;
1157+
fLocationFound = true;
1158+
return false;
1159+
}
1160+
1161+
body.accept(this);
1162+
}
11501163
}
11511164
}
11521165
return false;
11531166
}
1154-
1167+
11551168
/**
11561169
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
11571170
*/
@@ -1610,4 +1623,4 @@ public boolean visit(WhileStatement node) {
16101623
return visit(node, false);
16111624
}
16121625

1613-
}
1626+
}

0 commit comments

Comments
 (0)