예제 #1
0
  private void generateSelfSetFieldCase(MethodBuilder builder, int labelIdx, MemberRef field) {
    Type fieldType = field.type();

    Class wrapper = PrimitiveUtil.wrapper(fieldType);
    builder.aload(1);
    builder.ldc(field.name());
    builder.invokeVirtual(
        Type.STRING, BloatJ2MEContext.EQUALS_METHODNAME, new Type[] {Type.OBJECT}, Type.BOOLEAN);
    builder.ifeq(labelIdx + 1);
    builder.aload(0);
    builder.aload(2);
    if (wrapper != null) {
      builder.checkcast(wrapper);
      builder.invokeVirtual(
          _context.getType(wrapper),
          PrimitiveUtil.conversionFunctionName(wrapper),
          new Type[0],
          fieldType);
    } else {
      builder.checkcast(fieldType);
    }
    builder.putfield(field);
    builder.returnInstruction();
    builder.label(labelIdx + 1);
  }
예제 #2
0
  protected void generateSelf_set(MemberRef[] fields) {
    MethodBuilder builder =
        new MethodBuilder(
            _context,
            _ce,
            Modifiers.PUBLIC,
            Void.TYPE,
            SELFSET_METHODNAME,
            new Class[] {String.class, Object.class},
            null);

    for (int fieldIdx = 0; fieldIdx < fields.length; fieldIdx++) {
      generateSelfSetFieldCase(builder, fieldIdx, fields[fieldIdx]);
    }

    Type superType = _ce.superclass();
    if (instrumentedType(superType)) {
      builder.aload(0);
      builder.aload(1);
      builder.aload(2);
      builder.invokeSpecial(
          superType, SELFSET_METHODNAME, new Type[] {Type.STRING, Type.OBJECT}, Type.VOID);

    } else {
      builder.ldc(null);
    }

    builder.returnInstruction();
    builder.commit();
  }