Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blewitt2016-03-15 23:32:55 +0000
committerJay Arthanareeswaran2016-04-05 15:56:03 +0000
commit6cb38423959485832f6b2b451a0cc3345d452e56 (patch)
tree80758269cf032cf884844dde1eafbd6fdc04231b /org.eclipse.jdt.apt.core
parentab49196ce45436d53b4eaed402b4d09d2547be3c (diff)
downloadeclipse.jdt.core-6cb38423959485832f6b2b451a0cc3345d452e56.tar.gz
eclipse.jdt.core-6cb38423959485832f6b2b451a0cc3345d452e56.tar.xz
eclipse.jdt.core-6cb38423959485832f6b2b451a0cc3345d452e56.zip
Bug 489702 - Replace new PrimitiveWrapper() with .valueOf()
The primitive wrapper classes (Byte, Short, Character, Integer, Long) all have a constructor that takes a String (or primitive) value and return a new instance wrapping that type. They also have a valueOf method which does the same thing, but without creating a new object instance. Replace calls to the constructor and in-line calls where the object creation doesn't escape (for example, new Integer().intValue() or equivalent). Change-Id: I70310f46c085879b6efa28740186426de59c81b5 Signed-off-by: Alex Blewitt <alex.blewitt@gmail.com>
Diffstat (limited to 'org.eclipse.jdt.apt.core')
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AnnotationInvocationHandler.java6
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/Factory.java34
2 files changed, 20 insertions, 20 deletions
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AnnotationInvocationHandler.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AnnotationInvocationHandler.java
index 5533931d54..91ac291655 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AnnotationInvocationHandler.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/AnnotationInvocationHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc.
+ * Copyright (c) 2005, 2016 BEA Systems, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -49,7 +49,7 @@ public class AnnotationInvocationHandler implements InvocationHandler
if( args == null || args.length == 0 )
{
if( methodName.equals("hashCode") ) //$NON-NLS-1$
- return new Integer( _instance.hashCode() );
+ return Integer.valueOf( _instance.hashCode() );
if( methodName.equals("toString") ) //$NON-NLS-1$
return _instance.toString();
if( methodName.equals("annotationType")) //$NON-NLS-1$
@@ -57,7 +57,7 @@ public class AnnotationInvocationHandler implements InvocationHandler
}
else if( args.length == 1 && methodName.equals("equals") ) //$NON-NLS-1$
{
- return new Boolean( _instance.equals( args[0] ) );
+ return Boolean.valueOf(_instance.equals(args[0]));
}
if( args != null && args.length != 0 )
throw new NoSuchMethodException("method " + method.getName() + formatArgs(args) + " does not exists"); //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/Factory.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/Factory.java
index bbdc53b3ea..aeed41ac9e 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/Factory.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/Factory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2015 BEA Systems, Inc. and others
+ * Copyright (c) 2005, 2016 BEA Systems, Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -468,17 +468,17 @@ public class Factory
else
return avoidReflectException ? Boolean.FALSE : value;
case 'c':
- return new Character((char)b); // narrowing.
+ return Character.valueOf((char)b); // narrowing.
case 'd':
return new Double(b); // widening.
case 'f':
return new Float(b); // widening.
case 'i':
- return new Integer(b); // widening.
+ return Integer.valueOf(b); // widening.
case 'l':
- return new Long(b); // widening.
+ return Long.valueOf(b); // widening.
case 's':
- return new Short(b); // widening.
+ return Short.valueOf(b); // widening.
default:
throw new IllegalStateException("unknown type " + expectedTypeChar); //$NON-NLS-1$
}
@@ -492,19 +492,19 @@ public class Factory
{
case 'b':
if(nameLen == 4) // byte
- return new Byte((byte)s); // narrowing.
+ return Byte.valueOf((byte)s); // narrowing.
else
return avoidReflectException ? Boolean.FALSE : value; // completely wrong.
case 'c':
- return new Character((char)s); // narrowing.
+ return Character.valueOf((char)s); // narrowing.
case 'd':
return new Double(s); // widening.
case 'f':
return new Float(s); // widening.
case 'i':
- return new Integer(s); // widening.
+ return Integer.valueOf(s); // widening.
case 'l':
- return new Long(s); // widening.
+ return Long.valueOf(s); // widening.
case 's':
return value; // exact match
default:
@@ -520,7 +520,7 @@ public class Factory
{
case 'b':
if(nameLen == 4) // byte
- return new Byte((byte)c); // narrowing.
+ return Byte.valueOf((byte)c); // narrowing.
else
return avoidReflectException ? Boolean.FALSE : value; // completely wrong.
case 'c':
@@ -530,11 +530,11 @@ public class Factory
case 'f':
return new Float(c); // widening.
case 'i':
- return new Integer(c); // widening.
+ return Integer.valueOf(c); // widening.
case 'l':
- return new Long(c); // widening.
+ return Long.valueOf(c); // widening.
case 's':
- return new Short((short)c); // narrowing.
+ return Short.valueOf((short)c); // narrowing.
default:
throw new IllegalStateException("unknown type " + expectedTypeChar); //$NON-NLS-1$
}
@@ -549,11 +549,11 @@ public class Factory
{
case 'b':
if(nameLen == 4) // byte
- return new Byte((byte)i); // narrowing.
+ return Byte.valueOf((byte)i); // narrowing.
else
return avoidReflectException ? Boolean.FALSE : value; // completely wrong.
case 'c':
- return new Character((char)i); // narrowing
+ return Character.valueOf((char)i); // narrowing
case 'd':
return new Double(i); // widening.
case 'f':
@@ -561,9 +561,9 @@ public class Factory
case 'i':
return value; // exact match
case 'l':
- return new Long(i); // widening.
+ return Long.valueOf(i); // widening.
case 's':
- return new Short((short)i); // narrowing.
+ return Short.valueOf((short)i); // narrowing.
default:
throw new IllegalStateException("unknown type " + expectedTypeChar); //$NON-NLS-1$
}

Back to the top