Skip to content

Commit f1ee05e

Browse files
subyssurendran666iloveeclipse
authored andcommitted
Menus for Toggling Trigger Breakpoint and Hit count based breakpoint
This feature enables toggle trigger and hit breakpoints in editor ruler Fixes: #652
1 parent c490b9c commit f1ee05e

File tree

6 files changed

+451
-7
lines changed

6 files changed

+451
-7
lines changed

org.eclipse.jdt.debug.ui/plugin.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,9 @@ OpenFromClipboardAction.name = Open from Clipboard
345345
VariablesView.name = Variables
346346

347347
CompareObjects.label=Compare
348-
CompareObjects.tooltip=Compare selected objects
348+
CompareObjects.tooltip=Compare selected objects
349+
350+
ToggleTriggerpointAction.label=Toggle Triggerpoint
351+
ToggleTriggerpointCommand.description=Creates or removes a triggerpoint
352+
ToggleHitpointAction.label=Toggle Hit Breakpoint
353+
ToggleHitpointCommand.description=Creates or removes a hitcount

org.eclipse.jdt.debug.ui/plugin.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,20 @@
10561056
menubarPath="debug"
10571057
id="org.eclipse.jdt.debug.ui.actions.EnableDisableBreakpointRulerActionDelegate">
10581058
</action>
1059+
<action
1060+
class="org.eclipse.jdt.internal.debug.ui.actions.RulerToggleHitBreakpointActionDelegate"
1061+
icon="icons/full/obj16/brkp_obj.png"
1062+
id="org.eclipse.jdt.debug.ui.actions.HitBreakpointRulerActionDelegate"
1063+
label="%ToggleHitpointAction.label"
1064+
menubarPath="debug">
1065+
</action>
1066+
<action
1067+
class="org.eclipse.jdt.internal.debug.ui.actions.RulerToggleTriggerBreakpointActionDelegate"
1068+
icon="icons/full/obj16/brkp_obj.png"
1069+
id="org.eclipse.jdt.debug.ui.actions.TriggerBreakpointRulerActionDelegate"
1070+
label="%ToggleTriggerpointAction.label"
1071+
menubarPath="debug">
1072+
</action>
10591073
<action
10601074
class="org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate"
10611075
helpContextId="manage_breakpoint_action_context"
@@ -1102,6 +1116,20 @@
11021116
label="%AddLambdaEntryBreakpoint.label"
11031117
menubarPath="debug">
11041118
</action>
1119+
<action
1120+
class="org.eclipse.jdt.internal.debug.ui.actions.RulerToggleHitBreakpointActionDelegate"
1121+
icon="icons/full/obj16/brkp_obj.png"
1122+
id="org.eclipse.jdt.debug.ui.actions.HitBreakpointRulerActionDelegate"
1123+
label="%ToggleHitpointAction.label"
1124+
menubarPath="debug">
1125+
</action>
1126+
<action
1127+
class="org.eclipse.jdt.internal.debug.ui.actions.RulerToggleTriggerBreakpointActionDelegate"
1128+
icon="icons/full/obj16/brkp_obj.png"
1129+
id="org.eclipse.jdt.debug.ui.actions.TriggerBreakpointRulerActionDelegate"
1130+
label="%ToggleTriggerpointAction.label"
1131+
menubarPath="debug">
1132+
</action>
11051133
<action
11061134
label="%EnableBreakpoint.label"
11071135
helpContextId="enable_disable_breakpoint_action_context"

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2022 IBM Corporation and others.
2+
* Copyright (c) 2016, 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
@@ -26,6 +26,10 @@ public class BreakpointToggleUtils {
2626

2727
private static boolean isTracepoint = false;
2828
private static boolean isLambdaEntryBreakpoint = false;
29+
private static boolean isTriggerpoint = false;
30+
private static boolean isHitPoint = false;
31+
32+
private static int hitCount = 0;
2933

3034

3135
public static void setUnsetTracepoints(boolean tracePoint) {
@@ -36,6 +40,16 @@ public static boolean isToggleTracepoints() {
3640
return isTracepoint;
3741
}
3842

43+
public static void setTriggerpoints(boolean triggerPoint) {
44+
isTriggerpoint = triggerPoint;
45+
46+
}
47+
48+
public static boolean isTriggerpoints() {
49+
return isTriggerpoint;
50+
51+
}
52+
3953
public static void setUnsetLambdaEntryBreakpoint(boolean lambdaEntryBreakpoint) {
4054
isLambdaEntryBreakpoint = lambdaEntryBreakpoint;
4155
}
@@ -44,6 +58,32 @@ public static boolean isToggleLambdaEntryBreakpoint() {
4458
return isLambdaEntryBreakpoint;
4559
}
4660

61+
public static void setHitpoints(boolean hitcount) {
62+
isHitPoint = hitcount;
63+
64+
if (!hitcount) {
65+
66+
setHitCount(0);
67+
68+
}
69+
70+
}
71+
72+
public static boolean isHitpoint() {
73+
return isHitPoint;
74+
75+
}
76+
77+
public static void setHitCount(int hit) {
78+
hitCount = hit;
79+
80+
}
81+
82+
public static int getHitCount() {
83+
return hitCount;
84+
85+
}
86+
4787
/**
4888
* Convenience method for printing messages to the status line
4989
*
@@ -69,3 +109,4 @@ public void run() {
69109
}
70110

71111
}
112+
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.jdt.internal.debug.ui.actions;
15+
16+
import org.eclipse.core.runtime.CoreException;
17+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
18+
import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
19+
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
20+
import org.eclipse.jface.action.Action;
21+
import org.eclipse.jface.action.IAction;
22+
import org.eclipse.jface.dialogs.IInputValidator;
23+
import org.eclipse.jface.dialogs.InputDialog;
24+
import org.eclipse.jface.text.BadLocationException;
25+
import org.eclipse.jface.text.IDocument;
26+
import org.eclipse.jface.text.IRegion;
27+
import org.eclipse.jface.text.ITextSelection;
28+
import org.eclipse.jface.text.TextSelection;
29+
import org.eclipse.jface.text.source.IVerticalRulerInfo;
30+
import org.eclipse.jface.viewers.ISelection;
31+
import org.eclipse.jface.viewers.ISelectionProvider;
32+
import org.eclipse.jface.window.Window;
33+
import org.eclipse.swt.widgets.Event;
34+
import org.eclipse.swt.widgets.Shell;
35+
import org.eclipse.ui.IActionDelegate2;
36+
import org.eclipse.ui.IEditorPart;
37+
import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
38+
import org.eclipse.ui.texteditor.IDocumentProvider;
39+
import org.eclipse.ui.texteditor.ITextEditor;
40+
41+
public class RulerToggleHitBreakpointActionDelegate extends AbstractRulerActionDelegate implements IActionDelegate2 {
42+
43+
private IEditorPart currentEditor;
44+
private IAction dummyAction;
45+
46+
@Override
47+
protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) {
48+
dummyAction = new Action() {
49+
};
50+
return dummyAction;
51+
}
52+
53+
@Override
54+
public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) {
55+
currentEditor = targetEditor;
56+
}
57+
58+
@Override
59+
public void init(IAction action) {
60+
}
61+
62+
@Override
63+
public void dispose() {
64+
currentEditor = null;
65+
dummyAction = null;
66+
super.dispose();
67+
}
68+
69+
@Override
70+
public void runWithEvent(IAction action, Event event) {
71+
if (!(currentEditor instanceof ITextEditor)) {
72+
return;
73+
}
74+
IVerticalRulerInfo rulerInfo = currentEditor.getAdapter(IVerticalRulerInfo.class);
75+
if (rulerInfo == null) {
76+
return;
77+
}
78+
int lineOfLastMouseButtonActivity = rulerInfo.getLineOfLastMouseButtonActivity();
79+
if (lineOfLastMouseButtonActivity < 0) {
80+
return;
81+
}
82+
IDocument document = getDocument((ITextEditor) currentEditor);
83+
if (document == null) {
84+
return;
85+
}
86+
ToggleBreakpointAdapter toggle = new ToggleBreakpointAdapter();
87+
try {
88+
ITextSelection selection = getTextSelection(currentEditor, document, lineOfLastMouseButtonActivity);
89+
if (toggle.canToggleLineBreakpoints(currentEditor, selection)) {
90+
IJavaLineBreakpoint jlp = ToggleBreakpointAdapter.findExistingBreakpoint((ITextEditor) currentEditor, selection);
91+
if (jlp == null) {
92+
hitCountDialog();
93+
94+
if (BreakpointToggleUtils.getHitCount() < 2) {
95+
96+
return;
97+
98+
}
99+
}
100+
BreakpointToggleUtils.setHitpoints(true);
101+
toggle.toggleBreakpoints(currentEditor, selection);
102+
}
103+
} catch (BadLocationException | CoreException e) {
104+
DebugUIPlugin.log(e);
105+
}
106+
}
107+
108+
private static IDocument getDocument(ITextEditor editor) {
109+
IDocumentProvider provider = editor.getDocumentProvider();
110+
if (provider != null) {
111+
return provider.getDocument(editor.getEditorInput());
112+
}
113+
IDocument doc = editor.getAdapter(IDocument.class);
114+
if (doc != null) {
115+
return doc;
116+
}
117+
return null;
118+
}
119+
120+
private static ITextSelection getTextSelection(IEditorPart editor, IDocument document, int line) throws BadLocationException {
121+
IRegion region = document.getLineInformation(line);
122+
ITextSelection textSelection = new TextSelection(document, region.getOffset(), 0);
123+
ISelectionProvider provider = editor.getSite().getSelectionProvider();
124+
if (provider != null) {
125+
ISelection selection = provider.getSelection();
126+
if (selection instanceof ITextSelection && ((ITextSelection) selection).getStartLine() <= line
127+
&& ((ITextSelection) selection).getEndLine() >= line) {
128+
textSelection = (ITextSelection) selection;
129+
}
130+
}
131+
return textSelection;
132+
}
133+
134+
private void hitCountDialog() {
135+
String title = ActionMessages.BreakpointHitCountAction_Set_Breakpoint_Hit_Count_2;
136+
String message = ActionMessages.BreakpointHitCountAction__Enter_the_new_hit_count_for_the_breakpoint__3;
137+
IInputValidator validator = new IInputValidator() {
138+
int hitCount = -1;
139+
140+
@Override
141+
public String isValid(String value) {
142+
try {
143+
hitCount = Integer.parseInt(value.trim());
144+
} catch (NumberFormatException nfe) {
145+
hitCount = -1;
146+
}
147+
if (hitCount < 1) {
148+
return ActionMessages.BreakpointHitCountAction_Value_must_be_positive_integer;
149+
}
150+
// no error
151+
return null;
152+
}
153+
};
154+
155+
Shell activeShell = JDIDebugUIPlugin.getActiveWorkbenchShell();
156+
InputDialog input = new InputDialog(activeShell, title, message, "", validator); //$NON-NLS-1$
157+
if (input.open() == Window.CANCEL) {
158+
return;
159+
}
160+
String hit = input.getValue();
161+
if (hit != null && !hit.isEmpty()) {
162+
BreakpointToggleUtils.setHitCount(Integer.parseInt(hit));
163+
}
164+
}
165+
}

0 commit comments

Comments
 (0)