Package net.sf.cglib.core

Examples of net.sf.cglib.core.CodeEmitter


/*  779 */     e.return_value();
/*  780 */     e.end_method();
/*      */   }
/*      */
/*      */   private void emitGetCallbacks(ClassEmitter ce) {
/*  784 */     CodeEmitter e = ce.begin_method(1, GET_CALLBACKS, null, null);
/*  785 */     e.load_this();
/*  786 */     e.invoke_static_this(BIND_CALLBACKS);
/*  787 */     e.load_this();
/*  788 */     e.push(this.callbackTypes.length);
/*  789 */     e.newarray(CALLBACK);
/*  790 */     for (int i = 0; i < this.callbackTypes.length; i++) {
/*  791 */       e.dup();
/*  792 */       e.push(i);
/*  793 */       e.load_this();
/*  794 */       e.getfield(getCallbackField(i));
/*  795 */       e.aastore();
/*      */     }
/*  797 */     e.return_value();
/*  798 */     e.end_method();
/*      */   }
View Full Code Here


/*  797 */     e.return_value();
/*  798 */     e.end_method();
/*      */   }
/*      */
/*      */   private void emitNewInstanceCallbacks(ClassEmitter ce) {
/*  802 */     CodeEmitter e = ce.begin_method(1, NEW_INSTANCE, null, null);
/*  803 */     e.load_arg(0);
/*  804 */     e.invoke_static_this(SET_THREAD_CALLBACKS);
/*  805 */     emitCommonNewInstance(e);
/*      */   }
View Full Code Here

/*  814 */     e.return_value();
/*  815 */     e.end_method();
/*      */   }
/*      */
/*      */   private void emitNewInstanceCallback(ClassEmitter ce) {
/*  819 */     CodeEmitter e = ce.begin_method(1, SINGLE_NEW_INSTANCE, null, null);
/*  820 */     switch (this.callbackTypes.length)
/*      */     {
/*      */     case 0:
/*  823 */       break;
/*      */     case 1:
/*  826 */       e.push(1);
/*  827 */       e.newarray(CALLBACK);
/*  828 */       e.dup();
/*  829 */       e.push(0);
/*  830 */       e.load_arg(0);
/*  831 */       e.aastore();
/*  832 */       e.invoke_static_this(SET_THREAD_CALLBACKS);
/*  833 */       break;
/*      */     default:
/*  835 */       e.throw_exception(ILLEGAL_STATE_EXCEPTION, "More than one callback object required");
/*      */     }
/*  837 */     emitCommonNewInstance(e);
/*      */   }
View Full Code Here

/*      */     }
/*  837 */     emitCommonNewInstance(e);
/*      */   }
/*      */
/*      */   private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) {
/*  841 */     CodeEmitter e = ce.begin_method(1, MULTIARG_NEW_INSTANCE, null, null);
/*  842 */     e.load_arg(2);
/*  843 */     e.invoke_static_this(SET_THREAD_CALLBACKS);
/*  844 */     e.new_instance_this();
/*  845 */     e.dup();
/*  846 */     e.load_arg(0);
/*  847 */     EmitUtils.constructor_switch(e, constructors, new ObjectSwitchCallback(e) {
/*      */       public void processCase(Object key, Label end) {
/*  849 */         MethodInfo constructor = (MethodInfo)key;
/*  850 */         Type[] types = constructor.getSignature().getArgumentTypes();
/*  851 */         for (int i = 0; i < types.length; i++) {
/*  852 */           this.val$e.load_arg(1);
/*  853 */           this.val$e.push(i);
/*  854 */           this.val$e.aaload();
/*  855 */           this.val$e.unbox(types[i]);
/*      */         }
/*  857 */         this.val$e.invoke_constructor_this(constructor.getSignature());
/*  858 */         this.val$e.goTo(end);
/*      */       }
/*      */       public void processDefault() {
/*  861 */         this.val$e.throw_exception(Enhancer.ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found");
/*      */       }
/*      */     });
/*  864 */     e.aconst_null();
/*  865 */     e.invoke_static_this(SET_THREAD_CALLBACKS);
/*  866 */     e.return_value();
/*  867 */     e.end_method();
/*      */   }
View Full Code Here

/* 46 */     EmitUtils.null_constructor(this);
/* 47 */     EmitUtils.factory_method(this, NEW_INSTANCE);
/*    */
/* 49 */     declare_field(2, "CGLIB$DELEGATES", Constants.TYPE_OBJECT_ARRAY, null, null);
/*    */
/* 51 */     CodeEmitter e = begin_method(1, CSTRUCT_OBJECT_ARRAY, null, null);
/* 52 */     e.load_this();
/* 53 */     e.super_invoke_constructor();
/* 54 */     e.load_this();
/* 55 */     e.load_arg(0);
/* 56 */     e.putfield("CGLIB$DELEGATES");
/* 57 */     e.return_value();
/* 58 */     e.end_method();
/*    */
/* 60 */     Set unique = new HashSet();
/* 61 */     for (int i = 0; i < classes.length; i++) {
/* 62 */       Method[] methods = getMethods(classes[i]);
/* 63 */       for (int j = 0; j < methods.length; j++) {
/* 64 */         if (unique.add(MethodWrapper.create(methods[j]))) {
/* 65 */           MethodInfo method = ReflectUtils.getMethodInfo(methods[j]);
/* 66 */           e = EmitUtils.begin_method(this, method, 1);
/* 67 */           e.load_this();
/* 68 */           e.getfield("CGLIB$DELEGATES");
/* 69 */           e.aaload(route != null ? route[i] : i);
/* 70 */           e.checkcast(method.getClassInfo().getType());
/* 71 */           e.load_args();
/* 72 */           e.invoke(method);
/* 73 */           e.return_value();
/* 74 */           e.end_method();
/*    */         }
/*    */       }
/*    */     }
/*    */
/* 79 */     end_class();
View Full Code Here

/*  89 */       ClassEmitter ce = new ClassEmitter(v);
/*  90 */       ce.begin_class(46, 1, getClassName(), CONSTRUCTOR_DELEGATE, new Type[] { Type.getType(this.iface) }, "<generated>");
/*     */
/*  96 */       Type declaring = Type.getType(constructor.getDeclaringClass());
/*  97 */       EmitUtils.null_constructor(ce);
/*  98 */       CodeEmitter e = ce.begin_method(1, ReflectUtils.getSignature(newInstance), ReflectUtils.getExceptionTypes(newInstance), null);
/*     */
/* 102 */       e.new_instance(declaring);
/* 103 */       e.dup();
/* 104 */       e.load_args();
/* 105 */       e.invoke_constructor(declaring, ReflectUtils.getSignature(constructor));
/* 106 */       e.return_value();
/* 107 */       e.end_method();
/* 108 */       ce.end_class();
/*     */     }
View Full Code Here

/*    */
/*    */   public void generate(ClassEmitter ce, CallbackGenerator.Context context, List methods) {
/* 44 */     for (Iterator it = methods.iterator(); it.hasNext(); ) {
/* 45 */       MethodInfo method = (MethodInfo)it.next();
/* 46 */       if (!TypeUtils.isProtected(method.getModifiers())) {
/* 47 */         CodeEmitter e = context.beginMethod(ce, method);
/* 48 */         context.emitCallback(e, context.getIndex(method));
/* 49 */         if (this.proxyRef) {
/* 50 */           e.load_this();
/* 51 */           e.invoke_interface(PROXY_REF_DISPATCHER, PROXY_REF_LOAD_OBJECT);
/*    */         } else {
/* 53 */           e.invoke_interface(DISPATCHER, LOAD_OBJECT);
/*    */         }
/* 55 */         e.checkcast(method.getClassInfo().getType());
/* 56 */         e.load_args();
/* 57 */         e.invoke(method);
/* 58 */         e.return_value();
/* 59 */         e.end_method();
/*    */       }
/*    */     }
/*    */   }
View Full Code Here

/*     */
/* 106 */       EmitUtils.null_constructor(ce);
/*     */
/* 109 */       emitProxy(ce, method);
/*     */
/* 112 */       CodeEmitter e = ce.begin_method(1, NEW_INSTANCE, null, null);
/* 113 */       e.new_instance_this();
/* 114 */       e.dup();
/* 115 */       e.invoke_constructor_this();
/* 116 */       e.return_value();
/* 117 */       e.end_method();
/*     */
/* 120 */       e = ce.begin_method(1, ADD_DELEGATE, null, null);
/* 121 */       e.load_this();
/* 122 */       e.load_arg(0);
/* 123 */       e.checkcast(Type.getType(this.iface));
/* 124 */       e.invoke_virtual_this(ADD_HELPER);
/* 125 */       e.return_value();
/* 126 */       e.end_method();
/*     */
/* 128 */       ce.end_class();
/*     */     }
View Full Code Here

/*  81 */       sigMap.put(method.getSignature().toString(), methodProxyField);
/*  82 */       ce.declare_field(26, methodField, METHOD, null, null);
/*  83 */       ce.declare_field(26, methodProxyField, METHOD_PROXY, null, null);
/*  84 */       ce.declare_field(26, "CGLIB$emptyArgs", Constants.TYPE_OBJECT_ARRAY, null, null);
/*     */
/*  88 */       CodeEmitter e = ce.begin_method(16, impl, method.getExceptionTypes(), null);
/*     */
/*  92 */       if (TypeUtils.isAbstract(method.getModifiers())) {
/*  93 */         e.throw_exception(ABSTRACT_METHOD_ERROR, method.toString() + " is abstract");
/*     */       } else {
/*  95 */         e.load_this();
/*  96 */         e.load_args();
/*  97 */         e.super_invoke(method.getSignature());
/*     */       }
/*  99 */       e.return_value();
/* 100 */       e.end_method();
/*     */
/* 103 */       e = context.beginMethod(ce, method);
/* 104 */       Label nullInterceptor = e.make_label();
/* 105 */       context.emitCallback(e, context.getIndex(method));
/* 106 */       e.dup();
/* 107 */       e.ifnull(nullInterceptor);
/*     */
/* 109 */       e.load_this();
/* 110 */       e.getfield(methodField);
/*     */
/* 112 */       if (method.getSignature().getArgumentTypes().length == 0)
/* 113 */         e.getfield("CGLIB$emptyArgs");
/*     */       else {
/* 115 */         e.create_arg_array();
/*     */       }
/*     */
/* 118 */       e.getfield(methodProxyField);
/* 119 */       e.invoke_interface(METHOD_INTERCEPTOR, INTERCEPT);
/* 120 */       e.unbox_or_zero(method.getSignature().getReturnType());
/* 121 */       e.return_value();
/*     */
/* 123 */       e.mark(nullInterceptor);
/* 124 */       e.load_this();
/* 125 */       e.load_args();
/* 126 */       e.super_invoke(method.getSignature());
/* 127 */       e.return_value();
/* 128 */       e.end_method();
/*     */     }
/* 130 */     generateFindProxy(ce, sigMap);
/*     */   }
View Full Code Here

/* 169 */       e.putfield(getMethodProxyField(impl));
/*     */     }
/*     */   }
/*     */
/*     */   public void generateFindProxy(ClassEmitter ce, Map sigMap) {
/* 174 */     CodeEmitter e = ce.begin_method(9, FIND_PROXY, null, null);
/*     */
/* 178 */     e.load_arg(0);
/* 179 */     e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING);
/* 180 */     ObjectSwitchCallback callback = new ObjectSwitchCallback(e, sigMap) {
/*     */       public void processCase(Object key, Label end) {
/* 182 */         this.val$e.getfield((String)this.val$sigMap.get(key));
/* 183 */         this.val$e.return_value();
/*     */       }
/*     */       public void processDefault() {
/* 186 */         this.val$e.aconst_null();
/* 187 */         this.val$e.return_value();
/*     */       }
/*     */     };
/* 190 */     EmitUtils.string_switch(e, (String[])sigMap.keySet().toArray(new String[0]), 1, callback);
/*     */
/* 194 */     e.end_method();
/*     */   }
View Full Code Here

TOP

Related Classes of net.sf.cglib.core.CodeEmitter

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.