Package javassist.bytecode

Examples of javassist.bytecode.FieldInfo


  }

  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


  private void addReadWriteMethods(ClassFile classfile)
      throws CannotCompileException {
    List fields = classfile.getFields();
    for (Iterator field_iter = fields.iterator(); field_iter.hasNext();) {
      FieldInfo finfo = (FieldInfo) field_iter.next();
      if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0
          && (!finfo.getName().equals(HANDLER_FIELD_NAME))) {
        // case of non-static field
        if (filter.handleRead(finfo.getDescriptor(), finfo
            .getName())) {
          addReadMethod(classfile, finfo);
        }
        if (filter.handleWrite(finfo.getDescriptor(), finfo
            .getName())) {
          addWriteMethod(classfile, finfo);
        }
      }
    }
View Full Code Here

*/
public class JavassistUtils
{
   public static void addFieldAnnotation(CtField field, javassist.bytecode.annotation.Annotation annotation)
   {
      FieldInfo fieldInfo = field.getFieldInfo();
      AnnotationsAttribute attribute = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag);
      if (attribute == null)
         attribute = new AnnotationsAttribute(fieldInfo.getConstPool(), AnnotationsAttribute.visibleTag);
      attribute.addAnnotation(annotation);
      fieldInfo.addAttribute(attribute);
   }
View Full Code Here

      return new Annotation(annotation, constPool);
   }

   public static void addSignature(CtField field, String signature)
   {
      FieldInfo fieldInfo = field.getFieldInfo();
      ConstPool constPool = fieldInfo.getConstPool();
      SignatureAttribute signatureAttribute = new SignatureAttribute(constPool, signature);
      fieldInfo.addAttribute(signatureAttribute);
   }
View Full Code Here

        //we can then re-initalize them with this same info

        try {
            if (file.getName().equals(ResteasyExtension.FILTER_DISPATCHER)) {
                FieldInfo field = new FieldInfo(file.getConstPool(), FIELD_NAME, FILTER_FIELD_TYPE);
                field.setAccessFlags(Modifier.PUBLIC);
                file.addField(field);
                field = new FieldInfo(file.getConstPool(), PARAMETER_FIELD_NAME, SET_TYPE);
                field.setAccessFlags(Modifier.PUBLIC);
                file.addField(field);
                for (final MethodInfo method : (List<MethodInfo>) file.getMethods()) {
                    if (method.getName().equals("init") &&
                            method.getDescriptor().equals("(Ljavax/servlet/FilterConfig;)V")) {
                        final Bytecode b = new Bytecode(file.getConstPool());
                        b.addAload(0);
                        b.addAload(1);
                        b.addPutfield(ResteasyExtension.FILTER_DISPATCHER, FIELD_NAME, FILTER_FIELD_TYPE);
                        b.addAload(1);
                        b.addInvokeinterface("javax/servlet/FilterConfig", "getServletContext", "()Ljavax/servlet/ServletContext;", 1);
                        b.addAload(0);
                        b.addGetfield(ResteasyExtension.FILTER_DISPATCHER, PARAMETER_FIELD_NAME, SET_TYPE);
                        b.addInvokestatic(CONTEXT_PARAMS, "init", INIT_METHOD_DESC);
                        b.addAload(0);
                        b.add(Opcode.SWAP);
                        b.addPutfield(ResteasyExtension.FILTER_DISPATCHER, PARAMETER_FIELD_NAME, SET_TYPE);
                        method.getCodeAttribute().iterator().insert(b.get());
                        method.getCodeAttribute().computeMaxStack();
                    } else if(method.getName().equals("<init>")) {
                        //no idea why this is needed
                        method.getCodeAttribute().setMaxStack(1);
                    }
                }
                return true;
            } else if (file.getName().equals(ResteasyExtension.SERVLET_DISPATCHER)) {
                FieldInfo field = new FieldInfo(file.getConstPool(), FIELD_NAME, SERVLET_FIELD_TYPE);
                field.setAccessFlags(Modifier.PUBLIC);
                file.addField(field);
                field = new FieldInfo(file.getConstPool(), PARAMETER_FIELD_NAME, SET_TYPE);
                field.setAccessFlags(Modifier.PUBLIC);
                file.addField(field);
                for (final MethodInfo method : (List<MethodInfo>) file.getMethods()) {
                    if (method.getName().equals("init") &&
                            method.getDescriptor().equals("(Ljavax/servlet/ServletConfig;)V")) {
                        final Bytecode b = new Bytecode(file.getConstPool());
View Full Code Here

*/
public class JavassistUtils
{
   public static void addFieldAnnotation(CtField field, javassist.bytecode.annotation.Annotation annotation)
   {
      FieldInfo fieldInfo = field.getFieldInfo();
      AnnotationsAttribute attribute = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag);
      if (attribute == null)
         attribute = new AnnotationsAttribute(fieldInfo.getConstPool(), AnnotationsAttribute.visibleTag);
      attribute.addAnnotation(annotation);
      fieldInfo.addAttribute(attribute);
   }
View Full Code Here

      return new Annotation(annotation, constPool);
   }

   public static void addSignature(CtField field, String signature)
   {
      FieldInfo fieldInfo = field.getFieldInfo();
      ConstPool constPool = fieldInfo.getConstPool();
      SignatureAttribute signatureAttribute = new SignatureAttribute(constPool, signature);
      fieldInfo.addAttribute(signatureAttribute);
   }
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

  private void addReadWriteMethods(ClassFile classfile)
      throws CannotCompileException {
    List fields = classfile.getFields();
    for (Iterator field_iter = fields.iterator(); field_iter.hasNext();) {
      FieldInfo finfo = (FieldInfo) field_iter.next();
      if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0
          && (!finfo.getName().equals(HANDLER_FIELD_NAME))) {
        // case of non-static field
        if (filter.handleRead(finfo.getDescriptor(), finfo
            .getName())) {
          addReadMethod(classfile, finfo);
        }
        if (filter.handleWrite(finfo.getDescriptor(), finfo
            .getName())) {
          addWriteMethod(classfile, finfo);
        }
      }
    }
View Full Code Here

            List list = getClassFile2().getFields();
            int n = list.size();
            CtMember allFields = null;
            CtField tail = null;
            for (int i = 0; i < n; ++i) {
                FieldInfo finfo = (FieldInfo)list.get(i);
                CtField newTail = new CtField(finfo, this);
                allFields = CtMember.append(allFields, tail, newTail);
                tail = newTail;
            }
View Full Code Here

TOP

Related Classes of javassist.bytecode.FieldInfo

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.