Skip to content

Commit 5155869

Browse files
committed
Bug 486264 - [1.8] Entry breakpoint for lambda expression
Change-Id: I958f033a470598bf0da911c016cbbe8f191fbe47 Signed-off-by: Gayan Perera <[email protected]> Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.debug/+/151461 Tested-by: Sarika Sinha <[email protected]> Reviewed-by: Sarika Sinha <[email protected]>
1 parent d687cd9 commit 5155869

File tree

13 files changed

+625
-22
lines changed

13 files changed

+625
-22
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2000, 2021 IBM Corporation and others.
2+
# Copyright (c) 2000, 2022 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
@@ -18,6 +18,7 @@ vmInstallPage=VM Install Page
1818
vmCapabilitiesPageName=VM Capabilities
1919
AddBreakpoint.label=Toggle &Breakpoint
2020
AddTracepoint.label=Toggle &Tracepoint
21+
AddLambdaEntryBreakpoint.label=Toggle &Lambda Entry Breakpoint
2122

2223
addTypeStepFilterAction.label=&Filter Type
2324
addTypeStepFilterAction.tooltip=Filter the selected type(s)
@@ -236,7 +237,11 @@ CommandDefinition.breakpointproperties.name=Java Breakpoint Properties
236237

237238
ToggleTracepointAction.label=Toggle Tra&cepoint
238239
ToggleTracepointCommand.label=Toggle Tracepoint
239-
ToggleTracepointCommand.description=Creates or removes a tracepoint
240+
ToggleTracepointCommand.description=Creates or removes a tracepoint
241+
242+
ToggleLambdaEntryBreakpointAction.label=Toggle Lambda Entry Breakpoint
243+
ToggleLambdaEntryBreakpointCommand.label=Toggle &Lambda Entry Breakpoint
244+
ToggleLambdaEntryBreakpointCommand.description=Creates or removes a lambda entry breakpoint
240245

241246
AddBookmark.label=Add Boo&kmark...
242247
AddBookmark.tooltip=Add Bookmark...

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<?eclipse version="3.0"?>
33
<!--
4-
Copyright (c) 2005, 2021 IBM Corporation and others.
4+
Copyright (c) 2005, 2022 IBM Corporation and others.
55
66
This program and the accompanying materials
77
are made available under the terms of the Eclipse Public License 2.0
@@ -159,6 +159,16 @@
159159
menubarPath="org.eclipse.ui.run/lineBreakpointBeforeGroup"
160160
id="org.eclipse.jdt.debug.ui.actions.ToggleTracepoint">
161161
</action>
162+
<action
163+
definitionId="org.eclipse.jdt.debug.ui.commands.ToggleLambdaEntryBreakpoint"
164+
label="%ToggleLambdaEntryBreakpointAction.label"
165+
icon="icons/full/obj16/brkp_obj.png"
166+
disabledIcon="icons/full/obj16/brkpd_obj.png"
167+
helpContextId="toggle_tracepoint_action_context"
168+
class="org.eclipse.jdt.internal.debug.ui.actions.RetargetToggleLambdaEntryBreakpointAction"
169+
menubarPath="org.eclipse.ui.run/lineBreakpointBeforeGroup"
170+
id="org.eclipse.jdt.debug.ui.actions.ToggleLambdaEntryBreakpoint">
171+
</action>
162172
<action
163173
definitionId="org.eclipse.jdt.debug.ui.commands.AddClassPrepareBreakpoint"
164174
label="%classPrepareAction.label"
@@ -1005,6 +1015,15 @@
10051015
label="%AddTracepoint.label"
10061016
menubarPath="debug">
10071017
</action>
1018+
<action
1019+
class="org.eclipse.jdt.internal.debug.ui.actions.RulerToggleLambdaEntryBreakpointActionDelegate"
1020+
helpContextId="manage_breakpoint_action_context"
1021+
icon="icons/full/obj16/brkp_obj.png"
1022+
id="org.eclipse.jdt.debug.ui.actions.RulerToggleLambdaEntryBreakpointAction"
1023+
definitionId="org.eclipse.jdt.debug.ui.commands.ToggleLambdaEntryBreakpoint"
1024+
label="%AddLambdaEntryBreakpoint.label"
1025+
menubarPath="debug">
1026+
</action>
10081027
<action
10091028
label="%EnableBreakpoint.label"
10101029
helpContextId="enable_disable_breakpoint_action_context"
@@ -1049,6 +1068,15 @@
10491068
label="%AddTracepoint.label"
10501069
menubarPath="debug">
10511070
</action>
1071+
<action
1072+
class="org.eclipse.jdt.internal.debug.ui.actions.RulerToggleLambdaEntryBreakpointActionDelegate"
1073+
helpContextId="manage_breakpoint_action_context"
1074+
icon="icons/full/obj16/brkp_obj.png"
1075+
id="org.eclipse.jdt.debug.ui.actions.RulerToggleLambdaEntryBreakpointAction"
1076+
definitionId="org.eclipse.jdt.debug.ui.commands.ToggleLambdaEntryBreakpoint"
1077+
label="%AddLambdaEntryBreakpoint.label"
1078+
menubarPath="debug">
1079+
</action>
10521080
<action
10531081
label="%EnableBreakpoint.label"
10541082
helpContextId="enable_disable_breakpoint_action_context"
@@ -2687,6 +2715,12 @@ M4 = Platform-specific fourth key
26872715
categoryId="org.eclipse.debug.ui.category.run"
26882716
id="org.eclipse.jdt.debug.ui.commands.ToggleTracepoint">
26892717
</command>
2718+
<command
2719+
name="%ToggleLambdaEntryBreakpointCommand.label"
2720+
description="%ToggleLambdaEntryBreakpointCommand.description"
2721+
categoryId="org.eclipse.debug.ui.category.run"
2722+
id="org.eclipse.jdt.debug.ui.commands.ToggleLambdaEntryBreakpoint">
2723+
</command>
26902724
<command
26912725
name="%ActionDefinition.addException.name"
26922726
description="%ActionDefinition.addException.description"

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/BreakpointMarkerUpdater.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2015 IBM Corporation and others.
2+
* Copyright (c) 2006, 2021 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
@@ -25,6 +25,7 @@
2525
import org.eclipse.jdt.core.dom.CompilationUnit;
2626
import org.eclipse.jdt.core.manipulation.SharedASTProviderCore;
2727
import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
28+
import org.eclipse.jdt.debug.core.IJavaMethodBreakpoint;
2829
import org.eclipse.jdt.debug.core.IJavaPatternBreakpoint;
2930
import org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint;
3031
import org.eclipse.jdt.debug.core.IJavaWatchpoint;
@@ -67,6 +68,7 @@
6768
*
6869
* @since 3.3
6970
*/
71+
@SuppressWarnings("deprecation")
7072
public class BreakpointMarkerUpdater implements IMarkerUpdater {
7173

7274
public BreakpointMarkerUpdater() {}
@@ -113,7 +115,22 @@ public boolean updateMarker(IMarker marker, IDocument document, Position positio
113115
return false;
114116
}
115117
try {
116-
ValidBreakpointLocationLocator loc = new ValidBreakpointLocationLocator(unit, document.getLineOfOffset(position.getOffset())+1, true, true);
118+
ValidBreakpointLocationLocator loc;
119+
if (breakpoint instanceof IJavaMethodBreakpoint && ((IJavaMethodBreakpoint) breakpoint).isEntry()) {
120+
IMarker m = breakpoint.getMarker();
121+
if (m != null) {
122+
int charStart = m.getAttribute(IMarker.CHAR_START, -1);
123+
int charEnd = m.getAttribute(IMarker.CHAR_END, -1);
124+
int length = charEnd - charStart + 1;
125+
loc = new ValidBreakpointLocationLocator(unit, document.getLineOfOffset(position.getOffset())
126+
+ 1, true, true, position.getOffset(), length);
127+
128+
} else {
129+
loc = new ValidBreakpointLocationLocator(unit, document.getLineOfOffset(position.getOffset()) + 1, true, true);
130+
}
131+
} else {
132+
loc = new ValidBreakpointLocationLocator(unit, document.getLineOfOffset(position.getOffset()) + 1, true, true);
133+
}
117134
unit.accept(loc);
118135
if(loc.getLocationType() == ValidBreakpointLocationLocator.LOCATION_NOT_FOUND) {
119136
return false;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2021 IBM Corporation and others.
2+
* Copyright (c) 2000, 2022 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
@@ -168,6 +168,8 @@ public class ActionMessages extends NLS {
168168

169169
public static String TracepointToggleAction_Unavailable;
170170

171+
public static String LambdaEntryBreakpointToggleAction_Unavailable;
172+
171173
public static String Override_Dependencies_title;
172174
public static String Override_Dependencies_button;
173175
public static String Override_Dependencies_button1;

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2000, 2021 IBM Corporation and others.
2+
# Copyright (c) 2000, 2022 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
@@ -149,6 +149,7 @@ OpenTypeAction_2=Unable to display the selected type.
149149
EditClasspathEntryAction_0=Ed&it...
150150
ProjectSelectionDialog_0=Choose &project(s) to add:
151151
TracepointToggleAction_Unavailable=The operation is unavailable on the current selection.
152+
LambdaEntryBreakpointToggleAction_Unavailable=The operation is unavailable on the current selection.
152153
Override_Dependencies_title=Override Dependencies
153154
Override_Dependencies_button=&Override
154155
Override_Dependencies_button1=&Override Dependencies...

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

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

2727
private static boolean isTracepoint = false;
28+
private static boolean isLambdaEntryBreakpoint = false;
2829

2930

3031
public static void setUnsetTracepoints(boolean tracePoint) {
@@ -35,6 +36,14 @@ public static boolean isToggleTracepoints() {
3536
return isTracepoint;
3637
}
3738

39+
public static void setUnsetLambdaEntryBreakpoint(boolean lambdaEntryBreakpoint) {
40+
isLambdaEntryBreakpoint = lambdaEntryBreakpoint;
41+
}
42+
43+
public static boolean isToggleLambdaEntryBreakpoint() {
44+
return isLambdaEntryBreakpoint;
45+
}
46+
3847
/**
3948
* Convenience method for printing messages to the status line
4049
*
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*******************************************************************************
2+
* Copyright (c) 20227 IBM Corporation and others.
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.actions.breakpoints.RetargetToggleBreakpointAction;
18+
import org.eclipse.jface.viewers.ISelection;
19+
import org.eclipse.ui.IWorkbenchPart;
20+
21+
/**
22+
* Global retargettable toggle Line Entry action.
23+
*
24+
* @since 3.12
25+
*
26+
*/
27+
public class RetargetToggleLambdaEntryBreakpointAction extends RetargetToggleBreakpointAction {
28+
29+
@Override
30+
protected void performAction(Object target, ISelection selection, IWorkbenchPart part) throws CoreException {
31+
BreakpointToggleUtils.setUnsetLambdaEntryBreakpoint(true);
32+
super.performAction(target, selection, part);
33+
}
34+
35+
@Override
36+
protected boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part) {
37+
return super.canPerformAction(target, selection, part);
38+
}
39+
40+
@Override
41+
protected String getOperationUnavailableMessage() {
42+
return ActionMessages.LambdaEntryBreakpointToggleAction_Unavailable;
43+
}
44+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 IBM Corporation and others.
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.jface.action.Action;
19+
import org.eclipse.jface.action.IAction;
20+
import org.eclipse.jface.text.BadLocationException;
21+
import org.eclipse.jface.text.IDocument;
22+
import org.eclipse.jface.text.IRegion;
23+
import org.eclipse.jface.text.ITextSelection;
24+
import org.eclipse.jface.text.TextSelection;
25+
import org.eclipse.jface.text.source.IVerticalRulerInfo;
26+
import org.eclipse.jface.viewers.ISelection;
27+
import org.eclipse.jface.viewers.ISelectionProvider;
28+
import org.eclipse.swt.widgets.Event;
29+
import org.eclipse.ui.IActionDelegate2;
30+
import org.eclipse.ui.IEditorPart;
31+
import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
32+
import org.eclipse.ui.texteditor.IDocumentProvider;
33+
import org.eclipse.ui.texteditor.ITextEditor;
34+
35+
public class RulerToggleLambdaEntryBreakpointActionDelegate extends AbstractRulerActionDelegate implements IActionDelegate2 {
36+
37+
private IEditorPart currentEditor;
38+
private IAction dummyAction;
39+
40+
@Override
41+
protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) {
42+
dummyAction = new Action() {
43+
// empty implementation to make compiler happy
44+
};
45+
return dummyAction;
46+
}
47+
48+
@Override
49+
public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) {
50+
currentEditor = targetEditor;
51+
}
52+
53+
@Override
54+
public void init(IAction action) {
55+
}
56+
57+
@Override
58+
public void dispose() {
59+
currentEditor = null;
60+
dummyAction = null;
61+
super.dispose();
62+
}
63+
64+
@Override
65+
public void runWithEvent(IAction action, Event event) {
66+
if (!(currentEditor instanceof ITextEditor)) {
67+
return;
68+
}
69+
IVerticalRulerInfo rulerInfo = currentEditor.getAdapter(IVerticalRulerInfo.class);
70+
if (rulerInfo == null) {
71+
return;
72+
}
73+
int lineOfLastMouseButtonActivity = rulerInfo.getLineOfLastMouseButtonActivity();
74+
if (lineOfLastMouseButtonActivity < 0) {
75+
return;
76+
}
77+
IDocument document = getDocument((ITextEditor) currentEditor);
78+
if (document == null) {
79+
return;
80+
}
81+
ToggleBreakpointAdapter toggle = new ToggleBreakpointAdapter();
82+
try {
83+
ITextSelection selection = getTextSelection(currentEditor, document, lineOfLastMouseButtonActivity);
84+
if (toggle.canToggleLineBreakpoints(currentEditor, selection)) {
85+
BreakpointToggleUtils.setUnsetLambdaEntryBreakpoint(true);
86+
toggle.toggleBreakpoints(currentEditor, selection);
87+
}
88+
} catch (BadLocationException | CoreException e) {
89+
DebugUIPlugin.log(e);
90+
}
91+
}
92+
93+
private static IDocument getDocument(ITextEditor editor) {
94+
IDocumentProvider provider = editor.getDocumentProvider();
95+
if (provider != null) {
96+
return provider.getDocument(editor.getEditorInput());
97+
}
98+
IDocument doc = editor.getAdapter(IDocument.class);
99+
if (doc != null) {
100+
return doc;
101+
}
102+
return null;
103+
}
104+
105+
private static ITextSelection getTextSelection(IEditorPart editor, IDocument document, int line) throws BadLocationException {
106+
IRegion region = document.getLineInformation(line);
107+
ITextSelection textSelection = new TextSelection(document, region.getOffset(), 0);
108+
ISelectionProvider provider = editor.getSite().getSelectionProvider();
109+
if (provider != null) {
110+
ISelection selection = provider.getSelection();
111+
if (selection instanceof ITextSelection && ((ITextSelection) selection).getStartLine() <= line
112+
&& ((ITextSelection) selection).getEndLine() >= line) {
113+
textSelection = (ITextSelection) selection;
114+
}
115+
}
116+
return textSelection;
117+
}
118+
}

0 commit comments

Comments
 (0)