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