Пример #1
0
  public void set(Object instance, Object value) throws IllegalAccessException {
    Object target;
    if ((vmField.flags & Modifier.STATIC) != 0) {
      target = vmField.class_.staticTable;
    } else if (Class.isInstance(vmField.class_, instance)) {
      target = instance;
    } else {
      throw new IllegalArgumentException();
    }

    if (!matchType(value)) {
      throw new IllegalArgumentException();
    }

    Classes.initialize(vmField.class_);

    switch (vmField.code) {
      case ByteField:
        setPrimitive(target, vmField.code, vmField.offset, (Byte) value);
        break;

      case BooleanField:
        setPrimitive(target, vmField.code, vmField.offset, ((Boolean) value) ? 1 : 0);
        break;

      case CharField:
        setPrimitive(target, vmField.code, vmField.offset, (Character) value);
        break;

      case ShortField:
        setPrimitive(target, vmField.code, vmField.offset, (Short) value);
        break;

      case IntField:
        setPrimitive(target, vmField.code, vmField.offset, (Integer) value);
        break;

      case LongField:
        setPrimitive(target, vmField.code, vmField.offset, (Long) value);
        break;

      case FloatField:
        setPrimitive(target, vmField.code, vmField.offset, Float.floatToRawIntBits((Float) value));
        break;

      case DoubleField:
        setPrimitive(
            target, vmField.code, vmField.offset, Double.doubleToRawLongBits((Double) value));
        break;

      case ObjectField:
        setObject(target, vmField.offset, value);
        break;

      default:
        throw new Error();
    }
  }
Пример #2
0
  private void set(Object instance, long value) throws IllegalAccessException {
    Object target;
    if ((vmField.flags & Modifier.STATIC) != 0) {
      target = vmField.class_.staticTable;
    } else if (Class.isInstance(vmField.class_, instance)) {
      target = instance;
    } else {
      throw new IllegalArgumentException();
    }

    Classes.initialize(vmField.class_);

    switch (vmField.code) {
      case ByteField:
      case BooleanField:
      case CharField:
      case ShortField:
      case IntField:
      case LongField:
      case FloatField:
      case DoubleField:
        setPrimitive(target, vmField.code, vmField.offset, value);
        break;

      default:
        throw new IllegalArgumentException(
            "needed "
                + getType()
                + ", got primitive type when setting "
                + Class.getName(vmField.class_)
                + "."
                + getName());
    }
  }