66
77import java .awt .Dimension ;
88import java .awt .EventQueue ;
9- import java .awt .event .ActionEvent ;
10- import java .awt .event .ActionListener ;
119import java .awt .event .ComponentAdapter ;
1210import java .awt .event .ComponentEvent ;
1311import java .util .ArrayList ;
@@ -72,12 +70,7 @@ class Rename {
7270 JRootPane rootPane = window .getRootPane ();
7371 window .setTitle ("Rename" );
7472 window .setDefaultCloseOperation (WindowConstants .HIDE_ON_CLOSE );
75- Toolkit .registerWindowCloseKeys (rootPane , new ActionListener () {
76- @ Override
77- public void actionPerformed (ActionEvent e ) {
78- window .setVisible (false );
79- }
80- });
73+ Toolkit .registerWindowCloseKeys (rootPane , e -> window .setVisible (false ));
8174 Toolkit .setIcon (window );
8275
8376 window .setModal (true );
@@ -89,8 +82,6 @@ public void componentHidden(ComponentEvent e) {
8982 ps = null ;
9083 }
9184 });
92- //window.setSize(Toolkit.zoom(250, 130));
93- //window.setLayout(new BoxLayout(window.getContentPane(), BoxLayout.Y_AXIS));
9485 Box windowBox = Box .createVerticalBox ();
9586 Toolkit .setBorder (windowBox );
9687 final int GAP = Toolkit .zoom (5 );
@@ -126,8 +117,7 @@ public void componentHidden(ComponentEvent e) {
126117 renameButton .addActionListener (e -> {
127118 final String newName = textField .getText ().trim ();
128119 if (!newName .isEmpty ()) {
129- if (newName .length () >= 1 &&
130- newName .chars ().limit (1 ).allMatch (Character ::isJavaIdentifierStart ) &&
120+ if (newName .chars ().limit (1 ).allMatch (Character ::isJavaIdentifierStart ) &&
131121 newName .chars ().skip (1 ).allMatch (Character ::isJavaIdentifierPart )) {
132122 rename (ps , binding , newName );
133123 window .setVisible (false );
@@ -140,11 +130,7 @@ public void componentHidden(ComponentEvent e) {
140130 });
141131 rootPane .setDefaultButton (renameButton );
142132
143- //JPanel panelBottom = new JPanel();
144- //panelBottom.setLayout(new BoxLayout(panelBottom, BoxLayout.X_AXIS));
145133 Box buttonBox = Box .createHorizontalBox ();
146- //Toolkit.setBorder(panelBottom, 5, 5, 5, 5);
147-
148134 buttonBox .add (Box .createHorizontalGlue ());
149135 buttonBox .add (showUsageButton );
150136 if (!Platform .isMacOS ()) {
@@ -253,8 +239,8 @@ void rename(PreprocSketch ps, IBinding binding, String newName) {
253239
254240 showUsage .hide ();
255241
256- List <SimpleName > occurrences = new ArrayList <>();
257- occurrences . addAll (findAllOccurrences (root , binding .getKey ()));
242+ List <SimpleName > occurrences =
243+ new ArrayList <> (findAllOccurrences (root , binding .getKey ()));
258244
259245 // Renaming class should rename all constructors
260246 if (binding .getKind () == IBinding .TYPE ) {
@@ -276,29 +262,28 @@ void rename(PreprocSketch ps, IBinding binding, String newName) {
276262
277263 editor .startCompoundEdit ();
278264
279- mappedNodes .entrySet (). forEach (entry -> {
280- int tabIndex = entry . getKey () ;
265+ mappedNodes .forEach (( key , nodes ) -> {
266+ int tabIndex = key ;
281267 SketchCode sketchCode = sketch .getCode (tabIndex );
282268
283269 SyntaxDocument document = (SyntaxDocument ) sketchCode .getDocument ();
284270
285- List <SketchInterval > nodes = entry .getValue ();
286271 nodes .stream ()
287- // Replace from the end so all unprocess offsets stay valid
288- .sorted (Comparator .comparing ((SketchInterval si ) -> si .startTabOffset ).reversed ())
289- .forEach (si -> {
290- // Make sure offsets are in bounds
291- int documentLength = document .getLength ();
292- if (si .startTabOffset >= 0 && si .startTabOffset <= documentLength &&
293- si .stopTabOffset >= 0 && si .stopTabOffset <= documentLength ) {
294- // Replace the code
295- int length = si .stopTabOffset - si .startTabOffset ;
296- try {
297- document .remove (si .startTabOffset , length );
298- document .insertString (si .startTabOffset , newName , null );
299- } catch (BadLocationException e ) { /* Whatever */ }
300- }
301- });
272+ // Replace from the end so all unprocessed offsets stay valid
273+ .sorted (Comparator .comparing ((SketchInterval si ) -> si .startTabOffset ).reversed ())
274+ .forEach (si -> {
275+ // Make sure offsets are in bounds
276+ int documentLength = document .getLength ();
277+ if (si .startTabOffset >= 0 && si .startTabOffset <= documentLength &&
278+ si .stopTabOffset >= 0 && si .stopTabOffset <= documentLength ) {
279+ // Replace the code
280+ int length = si .stopTabOffset - si .startTabOffset ;
281+ try {
282+ document .remove (si .startTabOffset , length );
283+ document .insertString (si .startTabOffset , newName , null );
284+ } catch (BadLocationException e ) { /* Whatever */ }
285+ }
286+ });
302287
303288 try {
304289 sketchCode .setProgram (document .getText (0 , document .getLength ()));
0 commit comments