Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 549899

Summary: [AutoRefactor immigration #7,#8/116] [cleanup & saveaction] Use Autoboxing and Unboxing
Product: [Eclipse Project] JDT Reporter: Fabrice Tiercelin <fabrice.tiercelin>
Component: UIAssignee: Fabrice Tiercelin <fabrice.tiercelin>
Status: VERIFIED FIXED QA Contact: Jeff Johnston <jjohnstn>
Severity: normal    
Priority: P3 CC: akiezun, carsten.hammer, jjohnstn, Lars.Vogel, pyvesdev, stephan.herrmann
Version: 4.13   
Target Milestone: 4.13 M3   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/147304
https://git.eclipse.org/r/147306
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=f35cbbf702eca4e4cbbc3c34eda461b9e697e9e5
https://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=863d20260ca7b47334a0565c8adc89c4cc71a6b3
Whiteboard:
Bug Depends on:    
Bug Blocks: 550060, 552534, 559058    

Description Fabrice Tiercelin CLA 2019-08-08 16:07:16 EDT
Add the feature to use Autoboxing and Unboxing if the JVM is >= 1.5 as follows:

Given
Integer i = Integer.valueOf(42);
char c = cObject.charValue();

When
Clean up the code enabling "Use Autoboxing" and "Use Unboxing"

Then
Integer i = 42;
char c = cObject;

PS: Is it possible to make ASTRewrite.createCopyTarget(ASTNode) generic like that:

public <T extends ASTNode> T createCopyTarget(T node)


This feature is a part of the AutoRefactor plugin immigration in Eclipse
+--------------------------------------------------------------------+-----+
| Rule in AutoRefactor                                               |     |
+--------------------------------------------------------------------+-----+
| Add brackets to control statement                                  | OK  |
| Diamond operator                                                   | OK  |
| Remove unnecessary casts                                           | OK  |
| Remove unneeded this expressions                                   | OK  |
| Remove useless modifiers                                           | OK  |
| Simple name rather than qualified name                             | OK  |
| AutoBoxing rather than explicit method                             | ... |
| Unboxing rather than explicit method                               | ... |
| 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  |
| Improve lambda expressions                                         | 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 semi-colons                                                 | 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-08 16:11:53 EDT
New Gerrit change created: https://git.eclipse.org/r/147304
Comment 2 Eclipse Genie CLA 2019-08-08 16:29:07 EDT
New Gerrit change created: https://git.eclipse.org/r/147306
Comment 3 Fabrice Tiercelin CLA 2019-08-08 16:36:38 EDT
I need to replace the shortcut &u by &b and to add a null check in ASTNodes.isMethod()
Comment 4 Fabrice Tiercelin CLA 2019-08-09 01:16:31 EDT
Those two things are fixed. There were also 4 missing files in the commit due to a wrong handling. It's amended.
Comment 7 Jeff Johnston CLA 2019-08-13 17:24:41 EDT
Released for 4.13M3
Comment 8 Lars Vogel CLA 2019-08-13 18:30:09 EDT
Thanks, Fabrice. 

Feel free to run the new cleanup on projects in eclipse.platform.ui or other eclipes.platform.* repos and update Gerrits for the code improvements.
Comment 9 Pierre-Yves Bigourdan CLA 2019-08-14 10:05:14 EDT
Thanks for this, maybe an N&N would be useful? :)
Comment 10 Pierre-Yves Bigourdan CLA 2019-08-14 10:08:20 EDT
(In reply to Pierre-Yves B. from comment #9)
> Thanks for this, maybe an N&N would be useful? :)

Ignore me, I had missed the second patch which does exactly that!
Comment 11 Fabrice Tiercelin CLA 2020-04-07 12:58:38 EDT
Verified for 4.16M1 using build I20200407-0120
Comment 12 Stephan Herrmann CLA 2020-05-09 07:50:19 EDT
Does this feature also handle the deprecated constructors of boxing types?

See bug 513076
Comment 13 Fabrice Tiercelin CLA 2020-05-09 08:14:05 EDT
Unfortunately not :( It's handled by the other AutoRefactor cleanup:
Primitive wrapper creation (KO)

...which has not been migrated in Eclipse yet.
Comment 14 Carsten Hammer CLA 2021-01-14 11:44:54 EST
Can we close Bug 128883 now?
Comment 15 Fabrice Tiercelin CLA 2021-01-14 12:57:04 EST
*** Bug 128883 has been marked as a duplicate of this bug. ***