Package javassist.bytecode

Examples of javassist.bytecode.ConstPool


    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

    {
        ClassPool pool = ClassPool.getDefault();
        CtClass cc = pool.get(clazz.getCanonicalName());
        for (CtMethod method : cc.getDeclaredMethods()) {
            ClassFile ccFile = cc.getClassFile();
            ConstPool constpool = ccFile.getConstPool();
            AnnotationsAttribute attr;
            attr = filterExistingAnnotations(add, method);
            addNewAnnotations(add, method, constpool, pool, attr);
        }
        cc.setName(cc.getName() + "$ClassModifier$" + COUNTER.increment());
View Full Code Here

        CtClass ctClass = POOL.makeClass(AbstractFelixCommandsService.class.getName() + suffix);
        try {
            if (!ctClass.isFrozen()) {
                ClassFile ccFile = ctClass.getClassFile();
                ccFile.setVersionToJava5();
                ConstPool constPool = ccFile.getConstPool();

                // set superclass
                CtClass abstractCtClass = POOL.getCtClass(AbstractFelixCommandsService.class.getName());
                ctClass.setSuperclass(abstractCtClass);
View Full Code Here

   
    sb.append("return f;");
    sb.append("}");
    mnew = CtNewMethod.make(sb.toString(), mainClass);

    ConstPool cp = mnew.getMethodInfo().getConstPool();
    AnnotationsAttribute attr = new AnnotationsAttribute(cp,
        AnnotationsAttribute.visibleTag);

    javassist.bytecode.annotation.Annotation producesAnnotation = new javassist.bytecode.annotation.Annotation(
        "javax.enterprise.inject.Produces", cp);
View Full Code Here

      else
      {
        seiClass.setSuperclass(requestResponseSuperClass) ;
      }

      ConstPool constantPool = seiClass.getClassFile().getConstPool();

      final String superClassName = seiClass.getSuperclass().getName().replace('.', '/') ;
      final String interfaceName = Provider.class.getName().replace('.', '/') ;
      final String typeName = SOAPMessage.class.getName().replace('.', '/') ;
      final String signature = 'L' + superClassName + ';' + 'L' + interfaceName + "<L" + typeName + ";>;" ;
View Full Code Here

            newClass.defrost();

            ClassFile newClassFile = newClass.getClassFile();

            //we'll be adding new constants to the class file (for generics and annotations)
            ConstPool constPool = newClassFile.getConstPool();

            //copy the annotations on the class
            AnnotationsAttribute annotations = (AnnotationsAttribute) originalClassFile
                .getAttribute(AnnotationsAttribute.visibleTag);
            AnnotationsAttribute newAnnotations = copyAnnotations(annotations, constPool);
View Full Code Here

  /**
   * Add the EnhancedClassFile annotation.
   */
  private void markAsEnhanced(CtClass aCtClazz) {
    ClassFile classFile = aCtClazz.getClassFile();
    ConstPool constPool = classFile.getConstPool();

    AnnotationsAttribute annoAttr = (AnnotationsAttribute) classFile
            .getAttribute(AnnotationsAttribute.visibleTag);

    // Create annotation attribute if it does not exist
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.