Package net.sf.cglib.core

Examples of net.sf.cglib.core.CodeEmitter$State


/*  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

/*     */   {
/*  53 */     super(v);
/*     */
/*  55 */     begin_class(46, 1, className, FAST_CLASS, null, "<generated>");
/*     */
/*  58 */     CodeEmitter e = begin_method(1, CSTRUCT_CLASS, null, null);
/*  59 */     e.load_this();
/*  60 */     e.load_args();
/*  61 */     e.super_invoke_constructor(CSTRUCT_CLASS);
/*  62 */     e.return_value();
/*  63 */     e.end_method();
/*     */
/*  65 */     VisibilityPredicate vp = new VisibilityPredicate(type, false);
/*  66 */     List methods = ReflectUtils.addAllMethods(type, new ArrayList());
/*  67 */     CollectionUtils.filter(methods, vp);
/*  68 */     CollectionUtils.filter(methods, new DuplicatesPredicate());
/*  69 */     List constructors = new ArrayList(Arrays.asList(type.getDeclaredConstructors()));
/*  70 */     CollectionUtils.filter(constructors, vp);
/*     */
/*  73 */     emitIndexBySignature(methods);
/*     */
/*  76 */     emitIndexByClassArray(methods);
/*     */
/*  79 */     e = begin_method(1, CONSTRUCTOR_GET_INDEX, null, null);
/*  80 */     e.load_args();
/*  81 */     List info = CollectionUtils.transform(constructors, MethodInfoTransformer.getInstance());
/*  82 */     EmitUtils.constructor_switch(e, info, new GetIndexCallback(e, info));
/*  83 */     e.end_method();
/*     */
/*  86 */     e = begin_method(1, INVOKE, INVOCATION_TARGET_EXCEPTION_ARRAY, null);
/*  87 */     e.load_arg(1);
/*  88 */     e.checkcast(Type.getType(type));
/*  89 */     e.load_arg(0);
/*  90 */     invokeSwitchHelper(e, methods, 2);
/*  91 */     e.end_method();
/*     */
/*  94 */     e = begin_method(1, NEW_INSTANCE, INVOCATION_TARGET_EXCEPTION_ARRAY, null);
/*  95 */     e.new_instance(Type.getType(type));
/*  96 */     e.dup();
/*  97 */     e.load_arg(0);
/*  98 */     invokeSwitchHelper(e, constructors, 1);
/*  99 */     e.end_method();
/*     */
/* 102 */     e = begin_method(1, GET_MAX_INDEX, null, null);
/* 103 */     e.push(methods.size() - 1);
/* 104 */     e.return_value();
/* 105 */     e.end_method();
/*     */
/* 107 */     end_class();
/*     */   }
View Full Code Here

/* 107 */     end_class();
/*     */   }
/*     */
/*     */   private void emitIndexBySignature(List methods)
/*     */   {
/* 112 */     CodeEmitter e = begin_method(1, SIGNATURE_GET_INDEX, null, null);
/* 113 */     List signatures = CollectionUtils.transform(methods, new Transformer() {
/*     */       public Object transform(Object obj) {
/* 115 */         return ReflectUtils.getSignature((Method)obj).toString();
/*     */       }
/*     */     });
/* 118 */     e.load_arg(0);
/* 119 */     e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING);
/* 120 */     signatureSwitchHelper(e, signatures);
/* 121 */     e.end_method();
/*     */   }
View Full Code Here

TOP

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

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.