Bug 572234 - [AutoRefactor immigration #65/151] [cleanup & saveaction] valueOf() rather than instantiation
Summary: [AutoRefactor immigration #65/151] [cleanup & saveaction] valueOf() rather th...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.19   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.20 M1   Edit
Assignee: Fabrice Tiercelin CLA
QA Contact: Lars Vogel CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-23 16:50 EDT by Fabrice Tiercelin CLA
Modified: 2021-04-06 06:24 EDT (History)
1 user (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 2021-03-23 16:50:59 EDT
Replace unnecessary primitive wrappers instance creations by using static factory methods ("valueOf()"):
 - It dramatically improves the space performance.

Given:
        Byte by = new Byte((byte) 4);
        Boolean bo = new Boolean(true);
        Character c = new Character('c');
        Double d = new Double(1);
        Float f1 = new Float(1f);
        Float f2 = new Float(1d);
        Long l = new Long(1);
        Short s = new Short((short) 1);
        Integer i = new Integer(1);
        new Byte("0").byteValue();
        byte by2 = new Byte((byte) 0);

When:
Clean up the code enabling "valueOf() rather than instantiation"

Then:
        Byte by = Byte.valueOf((byte) 4);
        Boolean bo = Boolean.valueOf(true);
        Character c = Character.valueOf('c');
        Double d = Double.valueOf(1);
        Float f1 = Float.valueOf(1f);
        Float f2 = Float.valueOf((float) 1d);
        Long l = Long.valueOf(1);
        Short s = Short.valueOf((short) 1);
        Integer i = Integer.valueOf(1);
        Byte.valueOf("0").byteValue();
        byte by2 = (byte) 0;

This feature is a part of the AutoRefactor plugin immigration into Eclipse
+--------------------------------------------------------------------+-----+
| Rule in AutoRefactor                                               |     |
+--------------------------------------------------------------------+-----+
| Add brackets to control statement                                  | OK  |
| All in one method rather than loop                                 | OK  |
| Arrays.fill() rather than loop                                     | OK  |
| Assign rather than control workflow then assign anyway             | OK  |
| Atomic object rather than mono index array                         | OK  |
| AutoBoxing rather than explicit method                             | OK  |
| Brackets rather than array instantiation                           | OK  |
| Break rather than passive loops                                    | OK  |
| Collapse if statements                                             | OK  |
| Comparison to 0 rather than 1 or -1                                | OK  |
| Inited collection rather than new collection and Collection.add... | OK  |
| Diamond operator                                                   | OK  |
| Double negation                                                    | OK  |
| End of method rather than return                                   | OK  |
| Equals nullable                                                    | OK  |
| Equals on constant rather than on variable                         | OK  |
| Extract common code in if else statement                           | OK  |
| if-elseif                                                          | OK  |
| If rather than while and falls through                             | OK  |
| Improve lambda expressions                                         | OK  |
| Inited map rather than new map and Map.putAll()                    | OK  |
| instanceof rather than isInstance()                                | OK  |
| Java 7 hash rather than Eclipse Java 6 hash                        | OK  |
| Lambda expression rather than comparator                           | OK  |
| Lazy logical rather than eager                                     | OK  |
| Literal rather than boolean constant                               | OK  |
| Local variable rather than field                                   | OK  |
| Make inner class static if it doesn't use top level class members  | OK  |
| Method on map rather than method on keyset                         | OK  |
| Merge conditional statements                                       | OK  |
| Moves increment or decrement outside an expression when possible   | OK  |
| Multi-catch                                                        | OK  |
| No assignment in if condition                                      | OK  |
| Number suffix in uppercase                                         | OK  |
| Objects equals rather than equals and null check                   | OK  |
| One code that falls through rather than redundant blocks           | OK  |
| One condition rather than unreachable block                        | OK  |
| Operand factorization                                              | OK  |
| Parsing rather than valueOf()                                      | OK  |
| Precompiles the regular expressions                                | OK  |
| Primitive comparison rather than wrapper comparison                | OK  |
| Push negation down                                                 | OK  |
| Reduce indentation                                                 | OK  |
| Remove overridden assignment                                       | OK  |
| Remove semi-colons                                                 | OK  |
| Remove super() call in constructor                                 | OK  |
| Remove unnecessary casts                                           | OK  |
| Remove unneeded this expressions                                   | OK  |
| Remove useless lone continue at the end of a loop                  | OK  |
| Remove useless modifiers                                           | OK  |
| Replace String concatenation by StringBuilder when possible        | OK  |
| Serialize rather than boxing and serialize                         | OK  |
| Simple name rather than qualified name                             | OK  |
| String rather than new string                                      | OK  |
| String.join() rather than loop                                     | OK  |
| substring() with one parameter rather than two                     | OK  |
| Switch                                                             | OK  |
| Ternary operator rather than duplicate conditions                  | OK  |
| Unboxing rather than explicit method                               | OK  |
| Use try-with-resource                                              | OK  |
| XOR rather than duplicate conditions                               | OK  |
| Decimal compare rather than equality                               | ... |
| If rather than two switch cases                                    | ... |
| valueOf() rather than instantiation                                | ... |
| Add underscore for each thousand in number literals when it is...  | ko  |
| Aggregate constructor rather than GWT method                       | ko  |
| Android ViewHolder                                                 | ko  |
| Android WakeLock                                                   | ko  |
| Annotation                                                         | ko  |
| ArrayDeque rather than Stack                                       | ko  |
| ArrayList rather than LinkedList                                   | ko  |
| ArrayList rather than Vector                                       | ko  |
| AssertJ                                                            | ko  |
| Assign rather than ternary filter then assign anyway               | 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  |
| Byte primitive rather than wrapper                                 | ko  |
| Char primitive rather than wrapper                                 | ko  |
| Collection.addAll() rather than list creation                      | 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 rather than equals                                      | ko  |
| Declaration outside loop rather than inside                        | ko  |
| Do/while rather than duplicate code                                | ko  |
| Do/while rather than while                                         | ko  |
| Double primitive rather than wrapper                               | ko  |
| Else rather than opposite condition                                | ko  |
| Empty test rather than size                                        | ko  |
| EnumMap rather than HashMap for enum keys                          | ko  |
| EnumSet rather than HashSet for enum types                         | 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  |
| Implicit default constructor rather than written one               | ko  |
| Inline code rather than peremptory condition                       | ko  |
| Int primitive rather than wrapper                                  | ko  |
| JUnit asserts                                                      | ko  |
| Jupiter asserts                                                    | ko  |
| Log parameters rather than log message                             | ko  |
| Long primitive rather than wrapper                                 | ko  |
| Map.entrySet() rather than Map.keySet() and value search           | ko  |
| Move common inner if statement from then/else clauses around ou... | ko  |
| Named method rather than log level parameter                       | ko  |
| No loop iteration rather than empty check                          | ko  |
| One if rather than duplicate blocks that fall through              | ko  |
| One try rather than two                                            | ko  |
| Opposite comparison rather than negative expression                | ko  |
| Opposite condition rather than duplicate condition                 | ko  |
| OR condition rather than redundant clauses                         | ko  |
| Refactors a true or a false assertion with respectively an AND     | ko  |
| Redundant boolean                                                  | ko  |
| Redundant truth                                                    | ko  |
| Remove empty if                                                    | ko  |
| Remove empty lines                                                 | ko  |
| Remove fields default values                                       | ko  |
| Remove parenthesis                                                 | ko  |
| Remove unchecked exceptions from throws clause                     | ko  |
| Remove unnecessary local before return                             | ko  |
| Remove useless block                                               | ko  |
| Remove useless empty check before a for loop                       | ko  |
| Remove empty statements                                            | ko  |
| Replace for loop with Collections.disjoint(Collection, Collection) | ko  |
| Set rather than List                                               | ko  |
| Set rather than Map                                                | ko  |
| Short primitive rather than wrapper                                | 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 concatenation                                               | ko  |
| String.valueOf() rather than concatenation                         | ko  |
| StringBuilder method call rather than reassignment                 | ko  |
| StringBuilder rather than StringBuffer                             | ko  |
| Super call rather than useless overriding                          | ko  |
| TestNG asserts                                                     | ko  |
| Truncating appending rather than sub-characters                    | ko  |
| Update set rather than testing first                               | ko  |
| Use java.nio.* classes instead of java.io.* classes                | ko  |
| Use String.contains()                                              | ko  |
| Variable inside if rather than above                               | ko  |
| While condition rather than inner if                               | ko  |
+--------------------------------------------------------------------+-----+
Comment 1 Eclipse Genie CLA 2021-03-23 17:00:33 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/178284
Comment 2 Noopur Gupta CLA 2021-03-24 02:15:58 EDT
Is this planned for 4.20? If so, it should be added to the JDT UI root planning bug 571724 along with any other new clean up options planned for 4.20.
Comment 3 Fabrice Tiercelin CLA 2021-03-24 04:37:18 EDT
(In reply to Noopur Gupta from comment #2)
> Is this planned for 4.20? If so, it should be added to the JDT UI root
> planning bug 571724 along with any other new clean up options planned for
> 4.20.

I don't want to put pressure on the reviewer but yes! it would be great to merge it for 4.20 .

So I simply add a comment in Bug 571724, that's it?
Comment 4 Noopur Gupta CLA 2021-03-24 05:10:27 EDT
(In reply to Fabrice Tiercelin from comment #3)
> (In reply to Noopur Gupta from comment #2)
> > Is this planned for 4.20? If so, it should be added to the JDT UI root
> > planning bug 571724 along with any other new clean up options planned for
> > 4.20.
> 
> I don't want to put pressure on the reviewer but yes! it would be great to
> merge it for 4.20 .

The planning bug is to have a vision of things that could be included in 4.20. 

> So I simply add a comment in Bug 571724, that's it?

If there are only 1-2 new clean up options that you plan to add in 4.20 then just adding a comment about them in the planning bug is fine. 

But if there are more clean ups being planned then you can create a top-level bug for new clean up options in 4.20 and list the individual features in that. Then, we can just include this top-level bug in the plan.
Comment 6 Eclipse Genie CLA 2021-04-06 06:23:26 EDT
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/178899
Comment 8 Fabrice Tiercelin CLA 2021-04-06 06:24:59 EDT
Verified for 4.20M1 using I20210405-1800 build