コード例 #1
0
 public void generate() {
   addInterfaceIfNeeded();
   if (!(inspectNoArgConstr(_ce.methods()))) {
     _context.addNoArgConstructor(_ce);
   }
   MemberRef[] declaredFields = _context.collectDeclaredFields(_ce);
   generateSelf_get(declaredFields);
   generateSelf_set(declaredFields);
 }
コード例 #2
0
 private void generateSelfGetMethodCase(MethodBuilder builder, int labelIdx, MemberRef field) {
   Class wrapper = null;
   if (field.type().isPrimitive()) {
     wrapper = PrimitiveUtil.wrapper(field.type());
   }
   builder.aload(1);
   builder.ldc(field.name());
   builder.invokeVirtual(
       Type.STRING, BloatJ2MEContext.EQUALS_METHODNAME, new Type[] {Type.OBJECT}, Type.BOOLEAN);
   builder.ifeq(labelIdx + 1);
   if (wrapper != null) {
     builder.newRef(wrapper);
     builder.dup();
   }
   builder.aload(0);
   builder.getfield(field);
   if (wrapper != null) {
     builder.invokeSpecial(
         _context.getType(wrapper),
         BloatJ2MEContext.INIT_METHODNAME,
         new Type[] {field.type()},
         Type.VOID);
   }
   builder.areturn();
   builder.label(labelIdx + 1);
 }
コード例 #3
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);
  }
コード例 #4
0
 // TODO: Shouldn't this information be passed in by the calling class?
 // (It should know which classes it instruments anyway.)
 private boolean instrumentedType(Type type) {
   String typeName = _context.normalizeClassName(type.className());
   System.err.println(typeName);
   return !(typeName.startsWith("java.")
       || typeName.startsWith("javax.")
       || typeName.startsWith("sun."));
 }