Clean up type checking code. Patch provided by Konstantin Kolinko.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 9 Apr 2008 22:29:28 +0000 (22:29 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 9 Apr 2008 22:29:28 +0000 (22:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@646571 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/el/lang/ELArithmetic.java
java/org/apache/el/lang/ELSupport.java
java/org/apache/el/parser/AstNegative.java

index cac6283..404a6c5 100644 (file)
@@ -164,8 +164,6 @@ public abstract class ELArithmetic {
                     || obj1 instanceof Double
                     || obj0 instanceof Float
                     || obj1 instanceof Float
-                    || (obj0 != null && (Double.TYPE == obj0.getClass() || Float.TYPE == obj0.getClass()))
-                    || (obj1 != null && (Double.TYPE == obj1.getClass() || Float.TYPE == obj1.getClass()))
                     || (obj0 instanceof String && ELSupport
                             .isStringFloat((String) obj0)) || (obj1 instanceof String && ELSupport
                     .isStringFloat((String) obj1)));
@@ -362,13 +360,12 @@ public abstract class ELArithmetic {
             return coerce(ZERO);
         }
 
-        Class objType = obj.getClass();
-        if (Character.class.equals(objType) || Character.TYPE == objType) {
+        if (obj instanceof Character) {
             return coerce(new Short((short) ((Character) obj).charValue()));
         }
 
         throw new IllegalArgumentException(MessageFactory.get("error.convert",
-                obj, objType, "Number"));
+                obj, obj.getClass(), "Number"));
     }
 
     protected abstract Number coerce(final String str);
index cebbd04..e076afb 100644 (file)
@@ -164,7 +164,7 @@ public class ELSupport {
         if (obj == null || "".equals(obj)) {
             return Boolean.FALSE;
         }
-        if (obj instanceof Boolean || obj.getClass() == Boolean.TYPE) {
+        if (obj instanceof Boolean) {
             return (Boolean) obj;
         }
         if (obj instanceof String) {
@@ -187,7 +187,7 @@ public class ELSupport {
             return new Character((char) ((Number) obj).shortValue());
         }
         Class objType = obj.getClass();
-        if (obj instanceof Character || objType == Character.TYPE) {
+        if (obj instanceof Character) {
             return (Character) obj;
         }
 
@@ -259,14 +259,13 @@ public class ELSupport {
             return coerceToNumber((Number) obj, type);
         }
 
-        Class objType = obj.getClass();
-        if (Character.class.equals(objType) || Character.TYPE == objType) {
+        if (obj instanceof Character) {
             return coerceToNumber(new Short((short) ((Character) obj)
                     .charValue()), type);
         }
 
         throw new IllegalArgumentException(MessageFactory.get("error.convert",
-                obj, objType, type));
+                obj, obj.getClass(), type));
     }
 
     protected final static Number coerceToNumber(final String val,
@@ -402,10 +401,7 @@ public class ELSupport {
         return (obj0 instanceof Double
                 || obj1 instanceof Double
                 || obj0 instanceof Float
-                || obj1 instanceof Float
-                || (obj0 != null && (Double.TYPE == obj0.getClass() || Float.TYPE == obj0
-                        .getClass())) || (obj1 != null && (Double.TYPE == obj1
-                .getClass() || Float.TYPE == obj1.getClass())));
+                || obj1 instanceof Float);
     }
 
     public final static boolean isDoubleStringOp(final Object obj0,
@@ -424,17 +420,7 @@ public class ELSupport {
                 || obj0 instanceof Short
                 || obj1 instanceof Short
                 || obj0 instanceof Byte
-                || obj1 instanceof Byte
-                || (obj0 != null && (Long.TYPE == obj0.getClass()
-                        || Integer.TYPE == obj0.getClass()
-                        || Character.TYPE == obj0.getClass()
-                        || Short.TYPE == obj0.getClass() || Byte.TYPE == obj0
-                        .getClass())) || (obj0 != null && (Long.TYPE == obj0
-                .getClass()
-                || Integer.TYPE == obj0.getClass()
-                || Character.TYPE == obj0.getClass()
-                || Short.TYPE == obj0.getClass() || Byte.TYPE == obj0
-                .getClass())));
+                || obj1 instanceof Byte);
     }
 
     public final static boolean isStringFloat(final String str) {
index ec14826..f58bd9b 100644 (file)
@@ -59,23 +59,22 @@ public final class AstNegative extends SimpleNode {
             }
             return new Long(-Long.parseLong((String) obj));
         }
-        Class type = obj.getClass();
-        if (obj instanceof Long || Long.TYPE == type) {
+        if (obj instanceof Long) {
             return new Long(-((Long) obj).longValue());
         }
-        if (obj instanceof Double || Double.TYPE == type) {
+        if (obj instanceof Double) {
             return new Double(-((Double) obj).doubleValue());
         }
-        if (obj instanceof Integer || Integer.TYPE == type) {
+        if (obj instanceof Integer) {
             return new Integer(-((Integer) obj).intValue());
         }
-        if (obj instanceof Float || Float.TYPE == type) {
+        if (obj instanceof Float) {
             return new Float(-((Float) obj).floatValue());
         }
-        if (obj instanceof Short || Short.TYPE == type) {
+        if (obj instanceof Short) {
             return new Short((short) -((Short) obj).shortValue());
         }
-        if (obj instanceof Byte || Byte.TYPE == type) {
+        if (obj instanceof Byte) {
             return new Byte((byte) -((Byte) obj).byteValue());
         }
         Long num = (Long) coerceToNumber(obj, Long.class);