Esempio n. 1
0
  private static void createProperty(ClassWriter cw, String classType, ASMProperty property)
      throws PageException {
    String name = property.getName();
    Type type = property.getASMType();
    Class clazz = property.getClazz();

    cw.visitField(Opcodes.ACC_PRIVATE, name, type.toString(), null, null).visitEnd();

    int load = loadFor(type);
    // int sizeOf=sizeOf(type);

    // get<PropertyName>():<type>
    Type[] types = new Type[0];
    Method method =
        new Method(
            (clazz == boolean.class ? "get" : "get") + StringUtil.ucFirst(name), type, types);
    GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, method, null, null, cw);

    Label start = new Label();
    adapter.visitLabel(start);

    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.visitFieldInsn(Opcodes.GETFIELD, classType, name, type.toString());
    adapter.returnValue();

    Label end = new Label();
    adapter.visitLabel(end);
    adapter.visitLocalVariable("this", "L" + classType + ";", null, start, end, 0);
    adapter.visitEnd();

    adapter.endMethod();

    // set<PropertyName>(object):void
    types = new Type[] {type};
    method = new Method("set" + StringUtil.ucFirst(name), Types.VOID, types);
    adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, method, null, null, cw);

    start = new Label();
    adapter.visitLabel(start);
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.visitVarInsn(load, 1);
    adapter.visitFieldInsn(Opcodes.PUTFIELD, classType, name, type.toString());

    adapter.visitInsn(Opcodes.RETURN);
    end = new Label();
    adapter.visitLabel(end);
    adapter.visitLocalVariable("this", "L" + classType + ";", null, start, end, 0);
    adapter.visitLocalVariable(name, type.toString(), null, start, end, 1);
    // adapter.visitMaxs(0, 0);//.visitMaxs(sizeOf+1, sizeOf+1);// hansx
    adapter.visitEnd();

    adapter.endMethod();
  }
 public JavaType convertAsmType(org.objectweb.asm.Type asmType) {
   JavaType result;
   switch (asmType.getSort()) {
     case org.objectweb.asm.Type.OBJECT:
       result = getClassSymbol(asmType.getInternalName()).type;
       break;
     case org.objectweb.asm.Type.BYTE:
       result = symbols.byteType;
       break;
     case org.objectweb.asm.Type.CHAR:
       result = symbols.charType;
       break;
     case org.objectweb.asm.Type.SHORT:
       result = symbols.shortType;
       break;
     case org.objectweb.asm.Type.INT:
       result = symbols.intType;
       break;
     case org.objectweb.asm.Type.LONG:
       result = symbols.longType;
       break;
     case org.objectweb.asm.Type.FLOAT:
       result = symbols.floatType;
       break;
     case org.objectweb.asm.Type.DOUBLE:
       result = symbols.doubleType;
       break;
     case org.objectweb.asm.Type.BOOLEAN:
       result = symbols.booleanType;
       break;
     case org.objectweb.asm.Type.ARRAY:
       result = new ArrayJavaType(convertAsmType(asmType.getElementType()), symbols.arrayClass);
       break;
     case org.objectweb.asm.Type.VOID:
       result = symbols.voidType;
       break;
     default:
       throw new IllegalArgumentException(asmType.toString());
   }
   return result;
 }