Package javassist.bytecode

Examples of javassist.bytecode.ConstPool


    private javassist.bytecode.annotation.Annotation toJavassistAnnotation(final Annotation source)
    {

        final Class<? extends Annotation> annotationType = source.annotationType();

        final ConstPool constPool = getConstPool();

        final javassist.bytecode.annotation.Annotation copy = new javassist.bytecode.annotation.Annotation(
                annotationType.getName(), constPool);

        final Method[] methods = annotationType.getDeclaredMethods();
View Full Code Here


    }
  }

  private void addFieldHandlerField(ClassFile classfile)
      throws CannotCompileException {
    ConstPool cp = classfile.getConstPool();
    FieldInfo finfo = new FieldInfo(cp, HANDLER_FIELD_NAME,
                                    HANDLER_FIELD_DESCRIPTOR);
    finfo.setAccessFlags(AccessFlag.PRIVATE | AccessFlag.TRANSIENT);
    classfile.addField(finfo);
  }
View Full Code Here

    classfile.addField(finfo);
  }

  private void addGetFieldHandlerMethod(ClassFile classfile)
      throws CannotCompileException {
    ConstPool cp = classfile.getConstPool();
    int this_class_index = cp.getThisClassInfo();
    MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME,
                                      GETFIELDHANDLER_METHOD_DESCRIPTOR);
    /* local variable | this | */
    Bytecode code = new Bytecode(cp, 2, 1);
    // aload_0 // load this
    code.addAload(0);
    // getfield // get field "$JAVASSIST_CALLBACK" defined already
    code.addOpcode(Opcode.GETFIELD);
    int field_index = cp.addFieldrefInfo(this_class_index,
                                         HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
    code.addIndex(field_index);
    // areturn // return the value of the field
    code.addOpcode(Opcode.ARETURN);
    minfo.setCodeAttribute(code.toCodeAttribute());
View Full Code Here

    classfile.addMethod(minfo);
  }

  private void addSetFieldHandlerMethod(ClassFile classfile)
      throws CannotCompileException {
    ConstPool cp = classfile.getConstPool();
    int this_class_index = cp.getThisClassInfo();
    MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME,
                                      SETFIELDHANDLER_METHOD_DESCRIPTOR);
    /* local variables | this | callback | */
    Bytecode code = new Bytecode(cp, 3, 3);
    // aload_0 // load this
    code.addAload(0);
    // aload_1 // load callback
    code.addAload(1);
    // putfield // put field "$JAVASSIST_CALLBACK" defined already
    code.addOpcode(Opcode.PUTFIELD);
    int field_index = cp.addFieldrefInfo(this_class_index,
                                         HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
    code.addIndex(field_index);
    // return
    code.addOpcode(Opcode.RETURN);
    minfo.setCodeAttribute(code.toCodeAttribute());
View Full Code Here

    }
  }

  private void addReadMethod(ClassFile classfile, FieldInfo finfo)
      throws CannotCompileException {
    ConstPool cp = classfile.getConstPool();
    int this_class_index = cp.getThisClassInfo();
    String desc = "()" + finfo.getDescriptor();
    MethodInfo minfo = new MethodInfo(cp, EACH_READ_METHOD_PREFIX
                                          + finfo.getName(), desc);
    /* local variables | target obj | each oldvalue | */
    Bytecode code = new Bytecode(cp, 5, 3);
    // aload_0
    code.addAload(0);
    // getfield // get each field
    code.addOpcode(Opcode.GETFIELD);
    int base_field_index = cp.addFieldrefInfo(this_class_index, finfo
        .getName(), finfo.getDescriptor());
    code.addIndex(base_field_index);
    // aload_0
    code.addAload(0);
    // invokeinterface // invoke Enabled.getInterceptFieldCallback()
    int enabled_class_index = cp.addClassInfo(FIELD_HANDLED_TYPE_NAME);
    code.addInvokeinterface(enabled_class_index,
                            GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
                            1);
    // ifnonnull
    code.addOpcode(Opcode.IFNONNULL);
View Full Code Here

    classfile.addMethod(minfo);
  }

  private void addWriteMethod(ClassFile classfile, FieldInfo finfo)
      throws CannotCompileException {
    ConstPool cp = classfile.getConstPool();
    int this_class_index = cp.getThisClassInfo();
    String desc = "(" + finfo.getDescriptor() + ")V";
    MethodInfo minfo = new MethodInfo(cp, EACH_WRITE_METHOD_PREFIX
                                          + finfo.getName(), desc);
    /* local variables | target obj | each oldvalue | */
    Bytecode code = new Bytecode(cp, 6, 3);
    // aload_0
    code.addAload(0);
    // invokeinterface // enabled.getInterceptFieldCallback()
    int enabled_class_index = cp.addClassInfo(FIELD_HANDLED_TYPE_NAME);
    code.addInvokeinterface(enabled_class_index,
                            GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
                            1);
    // ifnonnull (label1)
    code.addOpcode(Opcode.IFNONNULL);
    code.addIndex(9);
    // aload_0
    code.addAload(0);
    // *load_1
    addTypeDependDataLoad(code, finfo.getDescriptor(), 1);
    // putfield
    code.addOpcode(Opcode.PUTFIELD);
    int base_field_index = cp.addFieldrefInfo(this_class_index, finfo
        .getName(), finfo.getDescriptor());
    code.addIndex(base_field_index);
    code.growStack(-Descriptor.dataSize(finfo.getDescriptor()));
    // return ;
    code.addOpcode(Opcode.RETURN);
View Full Code Here

      }
    }
  }

  private int transformInvokevirtualsIntoGetfields(ClassFile classfile, CodeIterator iter, int pos) {
    ConstPool cp = classfile.getConstPool();
    int c = iter.byteAt(pos);
    if (c != Opcode.GETFIELD) {
      return pos;
    }
    int index = iter.u16bitAt(pos + 1);
    String fieldName = cp.getFieldrefName(index);
    String className = cp.getFieldrefClassName(index);
    if ( !filter.handleReadAccess( className, fieldName ) ) {
      return pos;
    }
    String desc = "()" + cp.getFieldrefType( index );
    int read_method_index = cp.addMethodrefInfo(
        cp.getThisClassInfo(),
        EACH_READ_METHOD_PREFIX + fieldName,
        desc
    );
    iter.writeByte(Opcode.INVOKEVIRTUAL, pos);
    iter.write16bit(read_method_index, pos + 1);
View Full Code Here

  }

  private int transformInvokevirtualsIntoPutfields(
      ClassFile classfile,
      CodeIterator iter, int pos) {
    ConstPool cp = classfile.getConstPool();
    int c = iter.byteAt(pos);
    if (c != Opcode.PUTFIELD) {
      return pos;
    }
    int index = iter.u16bitAt(pos + 1);
    String fieldName = cp.getFieldrefName(index);
    String className = cp.getFieldrefClassName(index);
    if ( !filter.handleWriteAccess( className, fieldName ) ) {
      return pos;
    }
    String desc = "(" + cp.getFieldrefType( index ) + ")V";
    int write_method_index = cp.addMethodrefInfo(
        cp.getThisClassInfo(),
        EACH_WRITE_METHOD_PREFIX + fieldName,
        desc
    );
    iter.writeByte(Opcode.INVOKEVIRTUAL, pos);
    iter.write16bit(write_method_index, pos + 1);
View Full Code Here

    return pos;
  }

  private static void addInvokeFieldHandlerMethod(ClassFile classfile,
                                                  Bytecode code, String typeName, boolean isReadMethod) {
    ConstPool cp = classfile.getConstPool();
    // invokeinterface
    int callback_type_index = cp.addClassInfo(FIELD_HANDLER_TYPE_NAME);
    if ((typeName.charAt(0) == 'L')
        && (typeName.charAt(typeName.length() - 1) == ';')
        || (typeName.charAt(0) == '[')) {
      // reference type
      int indexOfL = typeName.indexOf('L');
View Full Code Here

      throw new RuntimeException( e.getMessage(), e );
    }
  }

  private void addFieldHandlerField(ClassFile classfile) throws CannotCompileException {
    final ConstPool constPool = classfile.getConstPool();
    final FieldInfo fieldInfo = new FieldInfo( constPool, HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR );
    fieldInfo.setAccessFlags( AccessFlag.PRIVATE | AccessFlag.TRANSIENT );
    classfile.addField( fieldInfo );
  }
View Full Code Here

TOP

Related Classes of javassist.bytecode.ConstPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.