Skip to content

Commit d4c38a7

Browse files
committed
Incorporated review comments
1 parent 51cbc73 commit d4c38a7

File tree

8 files changed

+122
-108
lines changed

8 files changed

+122
-108
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
3333
import org.eclipse.jdt.internal.debug.core.JavaDebugUtils;
3434
import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint;
35+
import org.eclipse.jdt.internal.debug.core.breakpoints.JavaMethodBreakpoint;
3536
import org.eclipse.jdt.internal.debug.core.breakpoints.LambdaLocationLocator;
3637
import org.eclipse.jdt.internal.debug.core.breakpoints.ValidBreakpointLocationLocator;
3738
import org.eclipse.jface.text.BadLocationException;
@@ -121,15 +122,15 @@ public boolean updateMarker(IMarker marker, IDocument document, Position positio
121122
int charEnd = m.getAttribute(IMarker.CHAR_END, -1);
122123
int length = charEnd - charStart + 1;
123124
if (methodBreakpoint.isLambdaBreakpoint()) {
124-
LambdaLocationLocator currentLambda = new LambdaLocationLocator(charStart, charEnd, -10);
125+
LambdaLocationLocator currentLambda = new LambdaLocationLocator(charStart, charEnd, JavaMethodBreakpoint.LAMBDA_ALREADY_CALCULATED);
125126
unit.accept(currentLambda);
126-
if (methodBreakpoint.getLambdaName() != null) {
127-
if (currentLambda.getSelectedLambda() != null
128-
&& !methodBreakpoint.getLambdaName().equals(currentLambda.getSelectedLambda())) {
129-
methodBreakpoint.setLambdaName(currentLambda.getSelectedLambda());
127+
String existingLamda = methodBreakpoint.getLambdaName();
128+
String selectedLambda = currentLambda.getSelectedLambda();
129+
if (existingLamda != null && selectedLambda != null) {
130+
if (existingLamda.equals(selectedLambda)) {
131+
methodBreakpoint.setLambdaName(selectedLambda);
130132
}
131133
}
132-
133134
}
134135
loc = new ValidBreakpointLocationLocator(unit, document.getLineOfOffset(position.getOffset())
135136
+ 1, true, true, position.getOffset(), length);

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

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,25 +1776,7 @@ protected String getMethodBreakpointText(IJavaMethodBreakpoint methodBreakpoint)
17761776
appendThreadFilter(methodBreakpoint, label);
17771777

17781778
if (methodBreakpoint.isLambdaBreakpoint()) {
1779-
appendConditional(methodBreakpoint, label);
1780-
if (methodBreakpoint.getLambdaName() != null) {
1781-
label.append(" - [ " + methodBreakpoint.getLambdaName() + " ]"); //$NON-NLS-1$ //$NON-NLS-2$
1782-
} else {
1783-
if (member != null) {
1784-
label.append(" - "); //$NON-NLS-1$
1785-
label.append(getJavaLabelProvider().getText(member));
1786-
} else {
1787-
String methodSig = methodBreakpoint.getMethodSignature();
1788-
String methodName = methodBreakpoint.getMethodName();
1789-
if (methodSig != null) {
1790-
label.append(" - "); //$NON-NLS-1$
1791-
label.append(Signature.toString(methodSig, methodName, null, false, false));
1792-
} else if (methodName != null) {
1793-
label.append(" - "); //$NON-NLS-1$
1794-
label.append(methodName);
1795-
}
1796-
}
1797-
}
1779+
processInLineLambdaLabel(methodBreakpoint, label, member);
17981780
} else {
17991781
boolean entry = methodBreakpoint.isEntry();
18001782
boolean exit = methodBreakpoint.isExit();
@@ -2219,4 +2201,29 @@ public Color getBackground(Object element) {
22192201
public synchronized boolean requiresUIThread(Object element) {
22202202
return !isInitialized();
22212203
}
2204+
2205+
/**
2206+
* Process custom label for inline lambda breakpoints
2207+
*/
2208+
private void processInLineLambdaLabel(IJavaMethodBreakpoint methodBreakpoint, StringBuilder label, IMember member) throws CoreException {
2209+
appendConditional(methodBreakpoint, label);
2210+
if (methodBreakpoint.getLambdaName() != null) {
2211+
label.append(" - [ " + methodBreakpoint.getLambdaName() + " ]"); //$NON-NLS-1$ //$NON-NLS-2$
2212+
} else {
2213+
if (member != null) {
2214+
label.append(" - "); //$NON-NLS-1$
2215+
label.append(getJavaLabelProvider().getText(member));
2216+
} else {
2217+
String methodSig = methodBreakpoint.getMethodSignature();
2218+
String methodName = methodBreakpoint.getMethodName();
2219+
if (methodSig != null) {
2220+
label.append(" - "); //$NON-NLS-1$
2221+
label.append(Signature.toString(methodSig, methodName, null, false, false));
2222+
} else if (methodName != null) {
2223+
label.append(" - "); //$NON-NLS-1$
2224+
label.append(methodName);
2225+
}
2226+
}
2227+
}
2228+
}
22222229
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,6 @@ Override_Dependencies_button=&Override
155155
Override_Dependencies_button1=&Override Dependencies...
156156
Override_Dependencies_label1=Dependencies derived from the Java Build Path:
157157
Override_Dependencies_label2=Dependencies for launching:
158-
lambdaSelection=Select a lambda
158+
lambdaSelection=Select lambda
159159
lambdaSelect=Select
160160
lambdaClose=Close

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

Lines changed: 52 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@
117117
import org.eclipse.jface.viewers.IStructuredSelection;
118118
import org.eclipse.jface.viewers.StructuredSelection;
119119
import org.eclipse.swt.SWT;
120-
import org.eclipse.swt.events.ControlAdapter;
121-
import org.eclipse.swt.events.ControlEvent;
122120
import org.eclipse.swt.events.MouseAdapter;
123121
import org.eclipse.swt.events.MouseEvent;
124122
import org.eclipse.swt.graphics.Point;
125-
import org.eclipse.swt.graphics.Rectangle;
123+
import org.eclipse.swt.layout.GridData;
124+
import org.eclipse.swt.layout.GridLayout;
126125
import org.eclipse.swt.widgets.Button;
126+
import org.eclipse.swt.widgets.Composite;
127127
import org.eclipse.swt.widgets.Display;
128128
import org.eclipse.swt.widgets.Event;
129129
import org.eclipse.swt.widgets.Shell;
@@ -407,7 +407,7 @@ private static void doToggleMethodBreakpoint(IMethod member, IWorkbenchPart part
407407
private static void doToggleMethodBreakpoint(IMethod member, String lambdaMethodName, String lambdaMethodSignature, LambdaBreakpoint lambdaProperties, IWorkbenchPart part, ISelection finalSelection, IProgressMonitor monitor) throws CoreException {
408408
int lambdaPosition = 0;
409409
if (lambdaProperties != null) {
410-
lambdaPosition = lambdaProperties.getLambdaPosition();
410+
lambdaPosition = lambdaProperties.lambdaPosition();
411411
}
412412

413413
IJavaBreakpoint breakpoint = getMethodBreakpoint(member, lambdaMethodName, lambdaMethodSignature, lambdaPosition);
@@ -464,9 +464,9 @@ private static void doToggleMethodBreakpoint(IMethod member, String lambdaMethod
464464
}
465465
if (lambdaMethodName != null || lambdaMethodSignature != null) {
466466
methodBreakpoint.setLambdaBreakpoint(true);
467-
methodBreakpoint.setInlineLambdas(lambdaPosition);
467+
methodBreakpoint.setInlineLambdaPosition(lambdaPosition);
468468
String lambdaName = lambdaProperties.getLambdaName();
469-
if (lambdaProperties.isInline) {
469+
if (lambdaProperties.isInline()) {
470470
methodBreakpoint.setLambdaName(lambdaName);
471471
} else {
472472
methodBreakpoint.setLambdaName(null);
@@ -1403,11 +1403,12 @@ protected static IJavaBreakpoint getMethodBreakpoint(IMember element, String lam
14031403
if (container instanceof IMethod) {
14041404
if (method instanceof org.eclipse.jdt.internal.core.LambdaMethod) {
14051405
try {
1406-
if (methodBreakpoint.getInlineLambdasPositions() == lambdaPosition
1406+
if (methodBreakpoint.getInlineLambdasPosition() == lambdaPosition
14071407
&& methodBreakpoint.getCharStart() == element.getSourceRange().getOffset()) {
14081408
return methodBreakpoint;
14091409
}
14101410
} catch (CoreException e) {
1411+
JDIDebugUIPlugin.log(e);
14111412
return null;
14121413
}
14131414

@@ -1717,8 +1718,9 @@ private void toggleFieldOrMethodBreakpoints(IWorkbenchPart part, ISelection sele
17171718
return;
17181719
}
17191720
ITextSelection textSelection = new TextSelection(document, selectedLambda.getNodeOffset(), selectedLambda.getNodeLength());
1720-
LambdaBreakpoint lambdaBp = new LambdaBreakpoint(selected == -1 ? selectedLambda.getLambdaMethodName()
1721-
: lambdaExpresions.get(selected).toString(), selected < 0 ? 0 : selected, lambdaExpresions.size() > 1 ? true : false);
1721+
LambdaBreakpoint lambdaBp = new LambdaBreakpoint(lambdaExpresions.get(selected).toString(), selected, lambdaExpresions.size() > 1
1722+
? true
1723+
: false);
17221724
toggleLambdaEntryMethodBreakpoints(part, textSelection, selectedLambda.getLambdaMethodName(), selectedLambda.getfLambdaMethodSignature(), lambdaBp);
17231725
} catch (BadLocationException e) {
17241726
BreakpointToggleUtils.report(ActionMessages.LambdaEntryBreakpointToggleAction_Unavailable, part);
@@ -1730,29 +1732,10 @@ private void toggleFieldOrMethodBreakpoints(IWorkbenchPart part, ISelection sele
17301732
}
17311733
}
17321734

1733-
class LambdaBreakpoint {
1734-
private String lambdaName;
1735-
private int lambdaPosition;
1736-
private boolean isInline;
1737-
1738-
public LambdaBreakpoint(String lambdaName, int lambdaPosition, boolean isInline) {
1739-
this.lambdaName = lambdaName;
1740-
this.lambdaPosition = lambdaPosition;
1741-
this.isInline = isInline;
1742-
}
1743-
1735+
private record LambdaBreakpoint(String lambdaName, int lambdaPosition, boolean isInline) {
17441736
public String getLambdaName() {
17451737
return shortenExpression(lambdaName);
17461738
}
1747-
1748-
public int getLambdaPosition() {
1749-
return lambdaPosition;
1750-
}
1751-
1752-
public boolean isInline() {
1753-
return isInline;
1754-
}
1755-
17561739
}
17571740

17581741
/**
@@ -1973,25 +1956,23 @@ public int selectLambda(List<LambdaExpression> lambdaExps) {
19731956
if (lambdaExps.isEmpty()) {
19741957
return -1;
19751958
}
1959+
19761960
int[] selection = { -1 };
19771961
Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
19781962
Shell popup = new Shell(parentShell, SWT.TOOL | SWT.RESIZE);
19791963
popup.setText(ActionMessages.lambdaSelection);
1980-
popup.setSize(290, 55 * lambdaExps.size());
1981-
popup.setLayout(null);
1982-
Table table = new Table(popup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
1983-
table.setBounds(10, 10, popup.getBounds().width - 20, popup.getBounds().width - 60);
1984-
List<String> itemsName = lambdaExps.stream().map(LambdaExpression::toString).toList();
1985-
itemsName = itemsName.stream().map(item -> item.trim().replaceAll("\\n+$", "")).toList(); //$NON-NLS-1$ //$NON-NLS-2$
1964+
GridLayout popupLayout = new GridLayout(1, false);
1965+
popupLayout.marginWidth = 10;
1966+
popupLayout.marginHeight = 10;
1967+
popupLayout.verticalSpacing = 10;
1968+
popup.setLayout(popupLayout);
19861969

1987-
if (Platform.getOS().equals(Platform.OS_MACOSX)) {
1988-
itemsName = itemsName.stream().map(ToggleBreakpointAdapter::shortenExpression).toList();
1989-
}
1970+
Table table = new Table(popup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
1971+
GridData tableData = new GridData(SWT.FILL, SWT.FILL, true, true);
1972+
table.setLayoutData(tableData);
1973+
List<String> itemsName = toLambdaEntries(lambdaExps);
19901974

19911975
for (String item : itemsName) {
1992-
if (item.charAt(item.length() - 1) == '\n') {
1993-
item = item.substring(0, item.length() - 2).trim();
1994-
}
19951976
new TableItem(table, SWT.NONE).setText(item);
19961977
}
19971978

@@ -2001,37 +1982,35 @@ public void mouseDoubleClick(MouseEvent e) {
20011982
int ind = table.getSelectionIndex();
20021983
if (ind >= 0) {
20031984
selection[0] = ind;
2004-
popup.dispose();
1985+
popup.close();
20051986
}
20061987
}
20071988
});
20081989

2009-
Button selectButton = new Button(popup, SWT.PUSH);
1990+
Composite buttonBar = new Composite(popup, SWT.NONE);
1991+
GridLayout buttonLayout = new GridLayout(2, true);
1992+
buttonLayout.marginWidth = 0;
1993+
buttonLayout.marginHeight = 0;
1994+
buttonLayout.horizontalSpacing = 10;
1995+
buttonBar.setLayout(buttonLayout);
1996+
buttonBar.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
1997+
Button selectButton = new Button(buttonBar, SWT.PUSH);
20101998
selectButton.setText(ActionMessages.lambdaSelect);
2011-
selectButton.setBounds(90, 180, 80, 30);
1999+
selectButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
20122000

20132001
selectButton.addListener(SWT.Selection, e -> {
20142002
int index = table.getSelectionIndex();
20152003
if (index >= 0) {
20162004
selection[0] = index;
2017-
popup.dispose();
2005+
popup.close();
20182006
}
20192007
});
2020-
2021-
Button closeButton = new Button(popup, SWT.PUSH);
2008+
Button closeButton = new Button(buttonBar, SWT.PUSH);
20222009
closeButton.setText(ActionMessages.lambdaClose);
2023-
closeButton.setBounds(170, 180, 80, 30);
2024-
2010+
closeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
20252011
closeButton.addListener(SWT.Selection, e -> popup.close());
2026-
popup.addControlListener(new ControlAdapter() {
2027-
@Override
2028-
public void controlResized(ControlEvent e) {
2029-
Rectangle clientArea = popup.getClientArea();
2030-
table.setBounds(10, 10, clientArea.width - 20, clientArea.height - 60);
2031-
selectButton.setBounds(clientArea.width - 180, clientArea.height - 40, 80, 30);
2032-
closeButton.setBounds(clientArea.width - 90, clientArea.height - 40, 80, 30);
2033-
}
2034-
});
2012+
int tableHeight = Math.min(lambdaExps.size(), 10) * table.getItemHeight() + 80;
2013+
popup.setSize(300, tableHeight);
20352014
Point location = Display.getDefault().getCursorLocation();
20362015
popup.setLocation(location);
20372016
popup.addListener(SWT.Deactivate, e -> popup.close());
@@ -2064,4 +2043,19 @@ public static String shortenExpression(String input) {
20642043
return shortened.toString().trim();
20652044
}
20662045

2046+
private List<String> toLambdaEntries(List<LambdaExpression> lambdaExps) {
2047+
List<String> itemsName = lambdaExps.stream().map(LambdaExpression::toString).toList();
2048+
itemsName = itemsName.stream().map(item -> item.trim().replaceAll("\\n+$", "")).toList(); //$NON-NLS-1$ //$NON-NLS-2$
2049+
if (Platform.getOS().equals(Platform.OS_MACOSX)) { // If an expression is of multiline then we should shorten it to single line.
2050+
itemsName = itemsName.stream().map(ToggleBreakpointAdapter::shortenExpression).toList();
2051+
}
2052+
itemsName = itemsName.stream().map(item -> {
2053+
if (!item.isEmpty() && item.charAt(item.length() - 1) == '\n') {
2054+
int newLength = Math.max(0, item.length() - 2);
2055+
return item.substring(0, newLength).trim();
2056+
}
2057+
return item;
2058+
}).toList();
2059+
return itemsName;
2060+
}
20672061
}

org.eclipse.jdt.debug/model/org/eclipse/jdt/debug/core/IJavaMethodBreakpoint.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public interface IJavaMethodBreakpoint extends IJavaLineBreakpoint {
160160
/**
161161
* Returns whether this breakpoint a lambda entry breakpoint or not.
162162
*
163-
* @return <code>true</code> if this breakpoint of lambda entry breakpoint; <code>false</code> if this breakpoint not lambda entry breakpoint;
163+
* @return <code>true</code> if this breakpoint is a lambda entry breakpoint, <code>false</code> if not.
164164
* @since 3.25
165165
*/
166166
public boolean isLambdaBreakpoint();
@@ -181,17 +181,17 @@ public interface IJavaMethodBreakpoint extends IJavaLineBreakpoint {
181181
* @return the position of lambda in a lambda expression.
182182
* @since 3.25
183183
*/
184-
public int getInlineLambdasPositions();
184+
public int getInlineLambdasPosition();
185185

186186
/**
187187
* Sets the in-line lambda position
188188
*
189189
* @param pos
190-
* lambda position
190+
* lambda position, starts with 0 and cannot be negative
191191
* @throws CoreException
192192
* @since 3.25
193193
*/
194-
public void setInlineLambdas(int pos) throws CoreException;
194+
public void setInlineLambdaPosition(int pos) throws CoreException;
195195

196196
/**
197197
* Sets the local name used by user in the editor for single-lined lambdas

0 commit comments

Comments
 (0)