src/share/classes/com/sun/tools/apt/mirror/declaration/Constants.java

Print this page




  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 package com.sun.tools.apt.mirror.declaration;
  27 
  28 
  29 import java.util.Collection;
  30 
  31 import com.sun.mirror.declaration.*;
  32 import com.sun.mirror.type.TypeMirror;
  33 import com.sun.tools.apt.mirror.type.TypeMirrorImpl;
  34 import com.sun.tools.javac.code.Type;
  35 
  36 import static com.sun.tools.javac.code.TypeTags.*;
  37 
  38 
  39 /**
  40  * Utility class for operating on constant expressions.
  41  */

  42 class Constants {
  43 
  44     /**
  45      * Converts a constant in javac's internal representation (in which
  46      * boolean, char, byte, short, and int are each represented by an Integer)
  47      * into standard representation.  Other values (including null) are
  48      * returned unchanged.
  49      */
  50     static Object decodeConstant(Object value, Type type) {
  51         if (value instanceof Integer) {
  52             int i = ((Integer) value).intValue();
  53             switch (type.tag) {
  54             case BOOLEAN:  return Boolean.valueOf(i != 0);
  55             case CHAR:     return Character.valueOf((char) i);
  56             case BYTE:     return Byte.valueOf((byte) i);
  57             case SHORT:    return Short.valueOf((short) i);
  58             }
  59         }
  60         return value;
  61     }




  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 package com.sun.tools.apt.mirror.declaration;
  27 
  28 
  29 import java.util.Collection;
  30 
  31 import com.sun.mirror.declaration.*;
  32 import com.sun.mirror.type.TypeMirror;
  33 import com.sun.tools.apt.mirror.type.TypeMirrorImpl;
  34 import com.sun.tools.javac.code.Type;
  35 
  36 import static com.sun.tools.javac.code.TypeTags.*;
  37 
  38 
  39 /**
  40  * Utility class for operating on constant expressions.
  41  */
  42 @SuppressWarnings("deprecation")
  43 class Constants {
  44 
  45     /**
  46      * Converts a constant in javac's internal representation (in which
  47      * boolean, char, byte, short, and int are each represented by an Integer)
  48      * into standard representation.  Other values (including null) are
  49      * returned unchanged.
  50      */
  51     static Object decodeConstant(Object value, Type type) {
  52         if (value instanceof Integer) {
  53             int i = ((Integer) value).intValue();
  54             switch (type.tag) {
  55             case BOOLEAN:  return Boolean.valueOf(i != 0);
  56             case CHAR:     return Character.valueOf((char) i);
  57             case BYTE:     return Byte.valueOf((byte) i);
  58             case SHORT:    return Short.valueOf((short) i);
  59             }
  60         }
  61         return value;
  62     }