Bug 550394 - [AutoRefactor immigration #10/116] [cleanup & saveaction] Lambda expression enhancement
Summary: [AutoRefactor immigration #10/116] [cleanup & saveaction] Lambda expression e...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.13   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.15 M3   Edit
Assignee: Fabrice Tiercelin CLA
QA Contact: Jeff Johnston CLA
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks: 561379 562616
  Show dependency tree
 
Reported: 2019-08-23 14:40 EDT by Fabrice Tiercelin CLA
Modified: 2020-11-21 03:45 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabrice Tiercelin CLA 2019-08-23 14:40:51 EDT
Improve lambda expressions if the JVM is >= 1.8 as follows:

Given
(someString) -> someString.trim().toLowerCase();
someString -> {return someString.trim().toLowerCase();};
someString -> {return someString.trim().toLowerCase() + \"bar\";};
() -> new ArrayList<>();
date -> date.getTime();

When
Clean up the code enabling "Simplify lambda expression and method reference syntax"

Then
someString -> someString.trim().toLowerCase();
someString -> someString.trim().toLowerCase();
someString -> (someString.trim().toLowerCase() + \"bar\");
ArrayList::new;
Date::getTime;


This feature is a part of the AutoRefactor plugin immigration in Eclipse
+--------------------------------------------------------------------+-----+
| Rule in AutoRefactor                                               |     |
+--------------------------------------------------------------------+-----+
| Add brackets to control statement                                  | OK  |
| AutoBoxing rather than explicit method                             | OK  |
| Diamond operator                                                   | OK  |
| Remove semi-colons                                                 | OK  |
| Remove unnecessary casts                                           | OK  |
| Remove unneeded this expressions                                   | OK  |
| Remove useless modifiers                                           | OK  |
| Simple name rather than qualified name                             | OK  |
| Unboxing rather than explicit method                               | OK  |
| Improve lambda expressions                                         | ... |
| Aggregate constructor rather than GWT method                       | ko  |
| All in one method rather than loop                                 | ko  |
| Android ViewHolder                                                 | ko  |
| Android WakeLock                                                   | ko  |
| Annotation                                                         | ko  |
| ArrayDeque rather than Stack                                       | ko  |
| ArrayList rather than LinkedList                                   | ko  |
| ArrayList rather than Vector                                       | ko  |
| Big number                                                         | ko  |
| Boolean                                                            | ko  |
| Boolean constant rather than valueOf()                             | ko  |
| Boolean equals() rather than null check                            | ko  |
| Boolean primitive rather than wrapper                              | ko  |
| Brackets rather than array instantiation                           | ko  |
| Break rather than passive loops                                    | ko  |
| Byte primitive rather than wrapper                                 | ko  |
| Capitalize lower case 'l' -> 'L' for long number literals          | ko  |
| Char primitive rather than wrapper                                 | ko  |
| Collapse if statements                                             | ko  |
| Collection.contains() rather than loop                             | ko  |
| Collection.containsAll() rather than loop                          | ko  |
| Collections APIs rather than Vector pre-Collections APIs           | ko  |
| Comments                                                           | ko  |
| Comparison to 0 rather than 1 or -1                                | ko  |
| Declaration outside loop rather than inside                        | ko  |
| Do/while rather than duplicate code                                | ko  |
| Do/while rather than while                                         | ko  |
| Double compare rather than equality                                | ko  |
| Double primitive rather than wrapper                               | ko  |
| Else rather than opposite condition                                | ko  |
| Empty test rather than size                                        | ko  |
| End of method rather than return                                   | ko  |
| EnumMap rather than HashMap for enum keys                          | ko  |
| EnumSet rather than HashSet for enum types                         | ko  |
| Equals on constant rather than on variable                         | ko  |
| Extract common code in if else statement                           | ko  |
| Float primitive rather than wrapper                                | ko  |
| Generic list rather than raw list                                  | ko  |
| Generic map rather than raw map                                    | ko  |
| HashMap rather than Hashtable                                      | ko  |
| HashMap rather than TreeMap                                        | ko  |
| HashSet rather than TreeSet                                        | ko  |
| HotSpot intrinsiced APIs                                           | ko  |
| If rather than two switch cases                                    | ko  |
| If rather than while and falls through                             | ko  |
| if-elseif                                                          | ko  |
| Implicit default constructor rather than written one               | ko  |
| Inited collection rather than new collection and Collection.add... | ko  |
| Inited map rather than new map and Map.putAll()                    | ko  |
| Inline code rather than peremptory condition                       | ko  |
| Int primitive rather than wrapper                                  | ko  |
| Java 7 hash rather than Eclipse Java 6 hash                        | ko  |
| JUnit asserts                                                      | ko  |
| Lambda expression rather than comparator                           | ko  |
| Lazy logical rather than eager                                     | ko  |
| Literal rather than boolean constant                               | ko  |
| Log parameters rather than log message                             | ko  |
| Long primitive rather than wrapper                                 | ko  |
| Map.entrySet() rather than Map.keySet() and value search           | ko  |
| Merge conditional statements                                       | ko  |
| Method on map rather than method on keyset                         | ko  |
| Move common inner if statement from then/else clauses around ou... | ko  |
| Multi-catch                                                        | ko  |
| Named method rather than log level parameter                       | ko  |
| No assignment in if condition                                      | ko  |
| Objects equals rather than equals and null check                   | ko  |
| One code that falls through rather than redundant blocks           | ko  |
| One condition rather than unreachable block                        | ko  |
| One if rather than duplicate blocks that fall through              | ko  |
| Opposite comparison rather than negative expression                | ko  |
| Opposite condition rather than duplicate condition                 | ko  |
| OR condition rather than redundant clauses                         | ko  |
| Primitive wrapper creation                                         | ko  |
| Push negation down                                                 | ko  |
| Remove empty if                                                    | ko  |
| Remove empty lines                                                 | ko  |
| Remove fields default values                                       | ko  |
| Remove overriden assignment                                        | ko  |
| Remove super() call in constructor                                 | ko  |
| Remove unchecked exceptions from throws clause                     | ko  |
| Remove unnecessary local before return                             | ko  |
| Remove useless block                                               | ko  |
| Remove useless null checks                                         | ko  |
| Removes empty statements                                           | ko  |
| Set rather than List                                               | ko  |
| Set rather than map                                                | ko  |
| Short primitive rather than wrapper                                | ko  |
| Simplify expressions                                               | ko  |
| Single declarations rather than multi declaration                  | ko  |
| Standard method rather than Library method                         | ko  |
| Static constant rather than instance constant                      | ko  |
| String                                                             | ko  |
| String rather than new string                                      | ko  |
| String.valueOf() rather than concatenation                         | ko  |
| StringBuilder                                                      | ko  |
| StringBuilder method call rather than reassignment                 | ko  |
| StringBuilder rather than StringBuffer                             | ko  |
| Super call rather than useless overriding                          | ko  |
| Switch                                                             | ko  |
| Ternary operator rather than duplicate conditions                  | ko  |
| TestNG asserts                                                     | ko  |
| Update set rather than testing first                               | ko  |
| Use String.contains()                                              | ko  |
| Use try-with-resource                                              | ko  |
| Work with null checked expressions first                           | ko  |
| XOR rather than duplicate conditions                               | ko  |
+--------------------------------------------------------------------+-----+
Comment 1 Eclipse Genie CLA 2019-08-23 14:44:49 EDT
New Gerrit change created: https://git.eclipse.org/r/148248
Comment 2 Eclipse Genie CLA 2019-08-23 14:45:32 EDT
New Gerrit change created: https://git.eclipse.org/r/148249
Comment 3 Eclipse Genie CLA 2019-08-29 14:35:09 EDT
New Gerrit change created: https://git.eclipse.org/r/148248
Comment 5 Jeff Johnston CLA 2020-01-22 14:31:54 EST
Released for 4.15M3
Comment 6 Eclipse Genie CLA 2020-01-22 17:03:27 EST
New Gerrit change created: https://git.eclipse.org/r/156382
Comment 8 Jeff Johnston CLA 2020-01-22 17:52:32 EST
Patch had to be reverted as CleanupTest18 got an NPE in the new test case.
Comment 9 Fabrice Tiercelin CLA 2020-01-23 00:39:51 EST
Actually, I didn't say the feature was ready to merge :/ :) I was still working on it. Lars Vogel has told me a wrong case I was working on. So I continue my work.
Comment 10 Eclipse Genie CLA 2020-01-23 00:47:07 EST
New Gerrit change created: https://git.eclipse.org/r/156388
Comment 11 Jeff Johnston CLA 2020-01-23 15:12:07 EST
(In reply to Fabrice Tiercelin from comment #9)
> Actually, I didn't say the feature was ready to merge :/ :) I was still
> working on it. Lars Vogel has told me a wrong case I was working on. So I
> continue my work.

Yes, it was totally my fault.  I somehow thought the tests had been run when I merged it (must have been distracted between multiple patches I was reviewing).  Anyway, I just wanted you to know that you had to resubmit because I had merged/reverted previous patch.
Comment 12 Fabrice Tiercelin CLA 2020-01-25 15:30:55 EST
Jeff,

Here we are, the feature is done. You can review and merge.
Comment 14 Lars Vogel CLA 2020-02-11 16:40:06 EST
Can this be added to the N&N?
Comment 15 Lars Vogel CLA 2020-02-11 16:40:32 EST
Thanks, Fabrice this is one of my favorite cleanups from autorefactor!
Comment 17 Fabrice Tiercelin CLA 2020-11-21 03:45:33 EST
Verified for 4.18M3 using I20201116-1800 build