117117import org .eclipse .jface .viewers .IStructuredSelection ;
118118import org .eclipse .jface .viewers .StructuredSelection ;
119119import org .eclipse .swt .SWT ;
120- import org .eclipse .swt .events .ControlAdapter ;
121- import org .eclipse .swt .events .ControlEvent ;
122120import org .eclipse .swt .events .MouseAdapter ;
123121import org .eclipse .swt .events .MouseEvent ;
124122import 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 ;
126125import org .eclipse .swt .widgets .Button ;
126+ import org .eclipse .swt .widgets .Composite ;
127127import org .eclipse .swt .widgets .Display ;
128128import org .eclipse .swt .widgets .Event ;
129129import 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}
0 commit comments