private static TypedConstant coerceConstant(TypedConstant constant, Type type) {
    Type constantType = constant.getType();

    if (constantType.equals(type)) {
      return constant;
    }

    switch (type.getBasicType()) {
      case Type.BT_BOOLEAN:
        {
          return CstBoolean.make(((CstInteger) constant).getValue());
        }
      case Type.BT_BYTE:
        {
          return CstByte.make(((CstInteger) constant).getValue());
        }
      case Type.BT_CHAR:
        {
          return CstChar.make(((CstInteger) constant).getValue());
        }
      case Type.BT_SHORT:
        {
          return CstShort.make(((CstInteger) constant).getValue());
        }
      default:
        {
          throw new UnsupportedOperationException("can't coerce " + constant + " to " + type);
        }
    }
  }
Helper for {@link #processFields}, which translates constants into more specific types if
necessary.

@param constant {@code non-null;} the constant in question
@param type {@code non-null;} the desired type
android/android_framework/dex-maker/src/main/java/com/android/dx/dex/cf/CfTranslator.java