Package javassist

Examples of javassist.CtField$LongInitializer


      CtClass targetClass,
      CtClass fieldType,
      String fieldName,
      String getterName,
      String setterName) {
    final CtField theField = addField( targetClass, fieldType, fieldName, true );
    addGetter( targetClass, theField, getterName );
    addSetter( targetClass, theField, setterName );
  }
View Full Code Here


  }

  private CtField addField(CtClass targetClass, CtClass fieldType, String fieldName, boolean makeTransient) {
    final ConstPool constPool = targetClass.getClassFile().getConstPool();

    final CtField theField;
    try {
      theField = new CtField( fieldType, fieldName, targetClass );
      targetClass.addField( theField );
    }
    catch (CannotCompileException e) {
      throw new EnhancementException(
          String.format(
              "Could not enhance class [%s] to add field [%s]",
              targetClass.getName(),
              fieldName
          ),
          e
      );
    }

    // make that new field (1) private, (2) transient and (3) @Transient
    if ( makeTransient ) {
      theField.setModifiers( theField.getModifiers() | Modifier.TRANSIENT );
    }
    theField.setModifiers( Modifier.setPrivate( theField.getModifiers() ) );

    final AnnotationsAttribute annotationsAttribute = getVisibleAnnotations( theField.getFieldInfo() );
    annotationsAttribute.addAnnotation( new Annotation( Transient.class.getName(), constPool ) );
    return theField;
  }
View Full Code Here

  byte[] counterAdaptClass (final InputStream is, final String name)
    throws Exception
  {
    CtClass cc = pool.makeClass(is);
    if (!cc.isInterface()) {
      cc.addField(new CtField(CtClass.intType, "_counter", cc));
    }
    CtMethod[] ms = cc.getDeclaredMethods();
    for (int j = 0; j < ms.length; ++j) {
      CtMethod m = ms[j];
      int modifiers = m.getModifiers();
View Full Code Here

        CtClass ctType = convertClass(type);

        try
        {
            CtField field = new CtField(ctType, name, getCtClass());
            field.setModifiers(Modifier.PRIVATE);

            getCtClass().addField(field);
        }
        catch (CannotCompileException ex)
        {
View Full Code Here

      CtClass base = pool.get("org.jboss.aop.proxy.Proxy");
      CtClass proxy = TransformerCommon.makeClass(pool, classname, base);
      proxy.addInterface(pool.get("org.jboss.aop.instrument.Untransformable"));
      CtClass map = pool.get("java.util.Map");
      CtField methodMap = new CtField(map, "methodMap", proxy);
      methodMap.setModifiers(Modifier.PRIVATE | Modifier.STATIC);
      Instrumentor.addSyntheticAttribute(methodMap);
      proxy.addField(methodMap);
      CtMethod getMethodMap = CtNewMethod.getter("getMethodMap", methodMap);
      getMethodMap.setModifiers(Modifier.PUBLIC);
      Instrumentor.addSyntheticAttribute(getMethodMap);
View Full Code Here

      }

      CtClass template = pool.get("org.jboss.aop.proxy.ClassProxyTemplate");
      CtClass superclass = pool.get(clazz.getName());
     
      CtField mixinField = template.getField("mixins");
      CtField instanceAdvisor = template.getField("instanceAdvisor");
     
      CtClass proxy = TransformerCommon.makeClass(pool, classname, superclass);
     
      mixinField = new CtField(mixinField.getType(), "mixins", proxy);
      mixinField.setModifiers(Modifier.PRIVATE);
      Instrumentor.addSyntheticAttribute(mixinField);
      proxy.addField(mixinField);
      instanceAdvisor = new CtField(instanceAdvisor.getType(), "instanceAdvisor", proxy);
      instanceAdvisor.setModifiers(Modifier.PRIVATE);
      proxy.addField(instanceAdvisor);

      CtMethod writeEx = CtNewMethod.make("   public void writeExternal(java.io.ObjectOutput out)\n" +
                                          "   throws java.io.IOException\n" +
                                          "   {\n" +
                                          "   }", proxy);
      Instrumentor.addSyntheticAttribute(writeEx);
      CtMethod readEx = CtNewMethod.make("   public void readExternal(java.io.ObjectInput in)\n" +
                                         "   throws java.io.IOException, ClassNotFoundException\n" +
                                         "   {\n" +
                                         "   }", proxy);
      Instrumentor.addSyntheticAttribute(readEx);
      CtMethod getInstanceAdvisor = CtNewMethod.make("   public org.jboss.aop.InstanceAdvisor _getInstanceAdvisor()\n" +
                                                     "   {\n" +
                                                     "      return instanceAdvisor;\n" +
                                                     "   }", proxy);
      Instrumentor.addSyntheticAttribute(getInstanceAdvisor);
      CtMethod setInstanceAdvisor = CtNewMethod.make("   public void _setInstanceAdvisor(org.jboss.aop.InstanceAdvisor newAdvisor)\n" +
                                                     "   {\n" +
                                                     "      instanceAdvisor = (org.jboss.aop.ClassInstanceAdvisor) newAdvisor;\n" +
                                                     "   }", proxy);
      Instrumentor.addSyntheticAttribute(setInstanceAdvisor);
      CtMethod dynamicInvoke = CtNewMethod.make("   public org.jboss.aop.joinpoint.InvocationResponse _dynamicInvoke(org.jboss.aop.joinpoint.Invocation invocation)\n" +
                                                "   throws Throwable\n" +
                                                "   {\n" +
                                                "      ((org.jboss.aop.joinpoint.InvocationBase) invocation).setInstanceResolver(instanceAdvisor.getMetaData());\n" +
                                                "      org.jboss.aop.advice.Interceptor[] aspects = instanceAdvisor.getInterceptors();\n" +
                                                "      return new org.jboss.aop.joinpoint.InvocationResponse(invocation.invokeNext(aspects));\n" +
                                                "   }", proxy);
      Instrumentor.addSyntheticAttribute(dynamicInvoke);
      CtMethod setMixins = CtNewMethod.make("   public void setMixins(org.jboss.aop.proxy.ProxyMixin[] mixins)\n" +
                                            "   {\n" +
                                            "      this.mixins = mixins;\n" +
                                            "   }", proxy);
      Instrumentor.addSyntheticAttribute(setMixins);
      CtMethod writeReplace = CtNewMethod.make("   public Object writeReplace() throws java.io.ObjectStreamException\n" +
                                               "   {\n" +
                                               "      return new org.jboss.aop.proxy.MarshalledClassProxy(this.getClass().getSuperclass(), mixins, instanceAdvisor);\n" +
                                               "   }", proxy);
      Instrumentor.addSyntheticAttribute(writeReplace);

      proxy.addMethod(writeEx);
      proxy.addMethod(readEx);
      proxy.addMethod(getInstanceAdvisor);
      proxy.addMethod(setInstanceAdvisor);
      proxy.addMethod(dynamicInvoke);
      proxy.addMethod(setMixins);
      if (!interceptWriteReplace)
         proxy.addMethod(writeReplace);

      /*
      CtMethod writeEx = template.getDeclaredMethod("writeExternal");
      CtMethod readEx = template.getDeclaredMethod("readExternal");
      CtMethod getInstanceAdvisor = template.getDeclaredMethod("_getInstanceAdvisor");
      CtMethod setInstanceAdvisor = template.getDeclaredMethod("_setInstanceAdvisor");
      CtMethod dynamicInvoke = template.getDeclaredMethod("_dynamicInvoke");
      CtMethod setMixins = template.getDeclaredMethod("setMixins");
      CtMethod writeReplace = template.getDeclaredMethod("writeReplace");




      proxy.addMethod(CtNewMethod.copy(writeEx, proxy, null));
      proxy.addMethod(CtNewMethod.copy(readEx, proxy, null));
      proxy.addMethod(CtNewMethod.copy(getInstanceAdvisor, proxy, null));
      proxy.addMethod(CtNewMethod.copy(setInstanceAdvisor, proxy, null));
      proxy.addMethod(CtNewMethod.copy(dynamicInvoke, proxy, null));
      proxy.addMethod(CtNewMethod.copy(setMixins, proxy, null));
      proxy.addMethod(CtNewMethod.copy(writeReplace, proxy, null));
      */


      proxy.addInterface(pool.get("org.jboss.aop.proxy.ClassProxy"));
      proxy.addInterface(pool.get("java.io.Externalizable"));
      proxy.addInterface(pool.get("org.jboss.aop.instrument.Untransformable"));
      proxy.addInterface(pool.get("org.jboss.aop.proxy.MethodMapped"));

      CtClass map = pool.get("java.util.Map");
      CtField methodMap = new CtField(map, "methodMap", proxy);
      methodMap.setModifiers(Modifier.PRIVATE | Modifier.STATIC);
      proxy.addField(methodMap);
      CtMethod getMethodMap = CtNewMethod.getter("getMethodMap", methodMap);
      getMethodMap.setModifiers(Modifier.PUBLIC);
      proxy.addMethod(getMethodMap);

View Full Code Here

   private void addJoinpoint(String miname, MethodTransformation trans)throws CannotCompileException, NotFoundException
   {
      CtClass joinpoint = createJoinpointClass(miname, trans);
      CtClass genadvisor = ((GeneratedAdvisorInstrumentor)trans.getInstrumentor()).getGenadvisor();
      CtField field = new CtField(
            joinpoint,
            getJoinPointFieldName(trans),
            genadvisor);
      field.setModifiers(Modifier.PUBLIC);
      genadvisor.addField(field);
   }
View Full Code Here

      return addFieldFromTemplate(template, name, null);
   }
  
   private CtField addFieldFromTemplate(CtClass template, String name, CtClass type) throws Exception
   {
      CtField templateField = template.getField(name);
      CtClass fieldType = (type == null) ? templateField.getType() : type;
      CtField field = new CtField(fieldType, name, proxy);
      field.setModifiers(templateField.getModifiers());
      Instrumentor.addSyntheticAttribute(field);
      proxy.addField(field);
      return field;
   }
View Full Code Here

      else
      {
         initializer = mixin.getConstruction();
      }
      CtClass type = forName(mixinClass.getName());
      CtField field = new CtField(type, mixinFieldName(mixinClass), clazz);
      int modifiers = Modifier.PRIVATE;
      if (mixin.isTransient()) modifiers = modifiers | Modifier.TRANSIENT;
      field.setModifiers(modifiers);
      addSyntheticAttribute(field);
      clazz.addField(field, CtField.Initializer.byExpr(initializer));
      HashSet<Long> addedMethods = new HashSet<Long>();

      String[] interfaces = mixin.getInterfaces();
View Full Code Here

   protected CtField addStaticField(CtClass clazz, String name, String typeName,
                                  CtField.Initializer initializer)
           throws CannotCompileException, NotFoundException
   {
      CtClass type = forName(typeName);
      CtField field = new CtField(type, name, clazz);
      field.setModifiers(Modifier.PRIVATE | Modifier.STATIC);
      Instrumentor.addSyntheticAttribute(field);
      clazz.addField(field, initializer);

      return field;
   }
View Full Code Here

TOP

Related Classes of javassist.CtField$LongInitializer

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.