Exemplo n.º 1
0
  /**
   * Get the value of an entry in the constant pool as a Java constant. Characters and booleans are
   * represented by CONSTANT_Intgere entries. Character and string values are processed to escape
   * characters outside the basic printable ASCII set.
   *
   * @param d the descriptor, giving the expected type of the constant
   * @param index the index of the value in the constant pool
   * @return a printable string containing the value of the constant.
   */
  String getConstantValue(Descriptor d, int index) {
    try {
      ConstantPool.CPInfo cpInfo = constant_pool.get(index);

      switch (cpInfo.getTag()) {
        case ConstantPool.CONSTANT_Integer:
          {
            ConstantPool.CONSTANT_Integer_info info = (ConstantPool.CONSTANT_Integer_info) cpInfo;
            String t = d.getValue(constant_pool);
            if (t.equals("C")) { // character
              return getConstantCharValue((char) info.value);
            } else if (t.equals("Z")) { // boolean
              return String.valueOf(info.value == 1);
            } else { // other: assume integer
              return String.valueOf(info.value);
            }
          }

        case ConstantPool.CONSTANT_String:
          {
            ConstantPool.CONSTANT_String_info info = (ConstantPool.CONSTANT_String_info) cpInfo;
            return getConstantStringValue(info.getString());
          }

        default:
          return constantWriter.stringValue(cpInfo);
      }
    } catch (ConstantPoolException e) {
      return "#" + index;
    }
  }
Exemplo n.º 2
0
 String getValue(Descriptor d) {
   try {
     return d.getValue(constant_pool);
   } catch (ConstantPoolException e) {
     return report(e);
   }
 }