Skip to content

Commit c3216f8

Browse files
Method Breakpoint does not recognised when set at end of a method (#700)
This PR fixes the issue where breakpoints set at method closing braces did not created exit method breakpoints Fix: #697
1 parent 3d100ec commit c3216f8

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

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

Lines changed: 11 additions & 3 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
/**
@@ -1548,7 +1556,7 @@ private void toggleFieldOrMethodBreakpoints(IWorkbenchPart part, ISelection sele
15481556
lambdaEntryBP = true;
15491557
BreakpointToggleUtils.setUnsetLambdaEntryBreakpoint(false);
15501558
} else {
1551-
loc = new ValidBreakpointLocationLocator(unit, ts.getStartLine() + 1, true, true, ts.getOffset(), ts.getLength());
1559+
loc = new ValidBreakpointLocationLocator(unit, ts.getStartLine() + 1, true, true, ts.getOffset(), ts.getLength(), true);
15521560
}
15531561
unit.accept(loc);
15541562

@@ -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: 48 additions & 5 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;
@@ -148,6 +149,7 @@ public class ValidBreakpointLocationLocator extends ASTVisitor {
148149
private List<String> fLabels;
149150
private final int fInputOffset;
150151
private final int fInputLength;
152+
private boolean fThroughToggle;
151153

152154
/**
153155
* @param compilationUnit
@@ -192,6 +194,33 @@ public ValidBreakpointLocationLocator(CompilationUnit compilationUnit, int lineN
192194
fInputLength = end;
193195
}
194196

197+
/**
198+
* @param compilationUnit
199+
* the JDOM CompilationUnit of the source code.
200+
* @param lineNumber
201+
* the line number in the source code where to put the breakpoint.
202+
* @param bindingsResolved
203+
* indicates whether bindings are resolved in the compilation unit.
204+
* @param bestMatch
205+
* if <code>true</code> look for the best match, otherwise look only for a valid line.
206+
* @param offset
207+
* selection offset on which breakpoints should be toggled.
208+
* @param end
209+
* selection end on which breakpoints should be toggled.
210+
* @param throughToggle
211+
* if <code>true</code>, indicates the breakpoint is being toggled directly from editor ruler by user.
212+
*/
213+
public ValidBreakpointLocationLocator(CompilationUnit compilationUnit, int lineNumber, boolean bindingsResolved, boolean bestMatch, int offset, int end, boolean throughToggle) {
214+
fCompilationUnit = compilationUnit;
215+
fLineNumber = lineNumber;
216+
fBindingsResolved = bindingsResolved;
217+
fBestMatch = bestMatch;
218+
fLocationFound = false;
219+
fInputOffset = offset;
220+
fInputLength = end;
221+
fThroughToggle = throughToggle;
222+
}
223+
195224
/**
196225
* Returns whether binding information would be helpful in validating a
197226
* breakpoint location. If this locator makes a pass of the tree and
@@ -1128,11 +1157,12 @@ public boolean visit(MemberValuePair node) {
11281157
@Override
11291158
public boolean visit(MethodDeclaration node) {
11301159
if (visit(node, false)) {
1160+
Block body = node.getBody();
11311161
if (fBestMatch) {
11321162
// check if we are on the line which contains the method name
11331163
int nameOffset = node.getName().getStartPosition();
11341164
if (lineNumber(nameOffset) == fLineNumber) {
1135-
if (node.getParent() instanceof AnonymousClassDeclaration){
1165+
if (node.getParent() instanceof AnonymousClassDeclaration) {
11361166
fLocationType = LOCATION_NOT_FOUND;
11371167
fLocationFound = true;
11381168
return false;
@@ -1142,9 +1172,23 @@ public boolean visit(MethodDeclaration node) {
11421172
fLocationFound = true;
11431173
return false;
11441174
}
1175+
1176+
if (body != null && fThroughToggle) {
1177+
int bodyStart = body.getStartPosition();
1178+
int bodyLength = body.getLength();
1179+
int bodyEnd = bodyStart + bodyLength;
1180+
int closingBraceOffset = bodyEnd - 1;
1181+
if (lineNumber(closingBraceOffset) == fLineNumber) {
1182+
fMemberOffset = closingBraceOffset;
1183+
LOCATION_METHOD_CLOSE = true;
1184+
fLocationType = LOCATION_METHOD;
1185+
fLocationFound = true;
1186+
return false;
1187+
}
1188+
body.accept(this);
1189+
}
11451190
}
11461191
// visit only the body
1147-
Block body = node.getBody();
11481192
if (body != null) { // body is null for abstract methods
11491193
body.accept(this);
11501194
}
@@ -1609,5 +1653,4 @@ public boolean visit(VariableDeclarationStatement node) {
16091653
public boolean visit(WhileStatement node) {
16101654
return visit(node, false);
16111655
}
1612-
1613-
}
1656+
}

0 commit comments

Comments
 (0)