Skip to content

Commit 0242add

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 0242add

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

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: 32 additions & 6 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,17 @@ public ValidBreakpointLocationLocator(CompilationUnit compilationUnit, int lineN
192194
fInputLength = end;
193195
}
194196

197+
public ValidBreakpointLocationLocator(CompilationUnit compilationUnit, int lineNumber, boolean bindingsResolved, boolean bestMatch, int offset, int end, boolean throughToggle) {
198+
fCompilationUnit = compilationUnit;
199+
fLineNumber = lineNumber;
200+
fBindingsResolved = bindingsResolved;
201+
fBestMatch = bestMatch;
202+
fLocationFound = false;
203+
fInputOffset = offset;
204+
fInputLength = end;
205+
fThroughToggle = throughToggle;
206+
}
207+
195208
/**
196209
* Returns whether binding information would be helpful in validating a
197210
* breakpoint location. If this locator makes a pass of the tree and
@@ -1128,11 +1141,12 @@ public boolean visit(MemberValuePair node) {
11281141
@Override
11291142
public boolean visit(MethodDeclaration node) {
11301143
if (visit(node, false)) {
1144+
Block body = node.getBody();
11311145
if (fBestMatch) {
11321146
// check if we are on the line which contains the method name
11331147
int nameOffset = node.getName().getStartPosition();
11341148
if (lineNumber(nameOffset) == fLineNumber) {
1135-
if (node.getParent() instanceof AnonymousClassDeclaration){
1149+
if (node.getParent() instanceof AnonymousClassDeclaration) {
11361150
fLocationType = LOCATION_NOT_FOUND;
11371151
fLocationFound = true;
11381152
return false;
@@ -1142,9 +1156,22 @@ public boolean visit(MethodDeclaration node) {
11421156
fLocationFound = true;
11431157
return false;
11441158
}
1159+
1160+
if (body != null && fThroughToggle) {
1161+
int bodyStart = body.getStartPosition();
1162+
int bodyLength = body.getLength();
1163+
int bodyEnd = bodyStart + bodyLength;
1164+
int closingBraceOffset = bodyEnd - 1;
1165+
if (lineNumber(closingBraceOffset) == fLineNumber) {
1166+
fMemberOffset = closingBraceOffset;
1167+
LOCATION_METHOD_CLOSE = true;
1168+
fLocationType = LOCATION_METHOD;
1169+
fLocationFound = true;
1170+
return false;
1171+
}
1172+
body.accept(this);
1173+
}
11451174
}
1146-
// visit only the body
1147-
Block body = node.getBody();
11481175
if (body != null) { // body is null for abstract methods
11491176
body.accept(this);
11501177
}
@@ -1609,5 +1636,4 @@ public boolean visit(VariableDeclarationStatement node) {
16091636
public boolean visit(WhileStatement node) {
16101637
return visit(node, false);
16111638
}
1612-
1613-
}
1639+
}

0 commit comments

Comments
 (0)