Package net.sf.cglib.core

Examples of net.sf.cglib.core.CodeEmitter


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

/* 121 */     e.end_method();
/*     */   }
/*     */
/*     */   private void emitIndexByClassArray(List methods)
/*     */   {
/* 126 */     CodeEmitter e = begin_method(1, METHOD_GET_INDEX, null, null);
/* 127 */     if (methods.size() > 100)
/*     */     {
/* 129 */       List signatures = CollectionUtils.transform(methods, new Transformer() {
/*     */         public Object transform(Object obj) {
/* 131 */           String s = ReflectUtils.getSignature((Method)obj).toString();
/* 132 */           return s.substring(0, s.lastIndexOf(')') + 1);
/*     */         }
/*     */       });
/* 135 */       e.load_args();
/* 136 */       e.invoke_static(FAST_CLASS, GET_SIGNATURE_WITHOUT_RETURN_TYPE);
/* 137 */       signatureSwitchHelper(e, signatures);
/*     */     } else {
/* 139 */       e.load_args();
/* 140 */       List info = CollectionUtils.transform(methods, MethodInfoTransformer.getInstance());
/* 141 */       EmitUtils.method_switch(e, info, new GetIndexCallback(e, info));
/*     */     }
/* 143 */     e.end_method();
/*     */   }
View Full Code Here

/*     */
/* 222 */       ce.declare_field(26, "eqMethod", Constants.TYPE_STRING, null, null);
/* 223 */       EmitUtils.null_constructor(ce);
/*     */
/* 226 */       MethodInfo proxied = ReflectUtils.getMethodInfo(this.iface.getDeclaredMethods()[0]);
/* 227 */       CodeEmitter e = EmitUtils.begin_method(ce, proxied, 1);
/* 228 */       e.load_this();
/* 229 */       e.super_getfield("target", Constants.TYPE_OBJECT);
/* 230 */       e.checkcast(methodInfo.getClassInfo().getType());
/* 231 */       e.load_args();
/* 232 */       e.invoke(methodInfo);
/* 233 */       e.return_value();
/* 234 */       e.end_method();
/*     */
/* 237 */       e = ce.begin_method(1, NEW_INSTANCE, null, null);
/* 238 */       e.new_instance_this();
/* 239 */       e.dup();
/* 240 */       e.dup2();
/* 241 */       e.invoke_constructor_this();
/* 242 */       e.getfield("eqMethod");
/* 243 */       e.super_putfield("eqMethod", Constants.TYPE_STRING);
/* 244 */       e.load_arg(0);
/* 245 */       e.super_putfield("target", Constants.TYPE_OBJECT);
/* 246 */       e.return_value();
/* 247 */       e.end_method();
/*     */
/* 250 */       e = ce.begin_static();
/* 251 */       e.push(methodInfo.getSignature().toString());
/* 252 */       e.putfield("eqMethod");
/* 253 */       e.return_value();
/* 254 */       e.end_method();
/*     */
/* 256 */       ce.end_class();
/*     */     }
View Full Code Here

/*      */       }
/*  894 */       group.add(method);
/*      */     }
/*      */
/*  897 */     Set seenGen = new HashSet();
/*  898 */     CodeEmitter se = ce.getStaticHook();
/*  899 */     se.new_instance(THREAD_LOCAL);
/*  900 */     se.dup();
/*  901 */     se.invoke_constructor(THREAD_LOCAL, CSTRUCT_NULL);
/*  902 */     se.putfield("CGLIB$THREAD_CALLBACKS");
/*      */
/*  904 */     Object[] state = new Object[1];
/*  905 */     CallbackGenerator.Context context = new CallbackGenerator.Context(originalModifiers, indexes, positions) {
/*      */       public int getOriginalModifiers(MethodInfo method) {
/*  907 */         return ((Integer)this.val$originalModifiers.get(method)).intValue();
/*      */       }
/*      */       public int getIndex(MethodInfo method) {
/*  910 */         return ((Integer)this.val$indexes.get(method)).intValue();
/*      */       }
/*      */       public void emitCallback(CodeEmitter e, int index) {
/*  913 */         Enhancer.this.emitCurrentCallback(e, index);
/*      */       }
/*      */       public Signature getImplSignature(MethodInfo method) {
/*  916 */         return Enhancer.this.rename(method.getSignature(), ((Integer)this.val$positions.get(method)).intValue());
/*      */       }
/*      */       public CodeEmitter beginMethod(ClassEmitter ce, MethodInfo method) {
/*  919 */         CodeEmitter e = EmitUtils.begin_method(ce, method);
/*  920 */         if ((!Enhancer.this.interceptDuringConstruction) && (!TypeUtils.isAbstract(method.getModifiers())))
/*      */         {
/*  922 */           Label constructed = e.make_label();
/*  923 */           e.load_this();
/*  924 */           e.getfield("CGLIB$CONSTRUCTED");
/*  925 */           e.if_jump(154, constructed);
/*  926 */           e.load_this();
/*  927 */           e.load_args();
/*  928 */           e.super_invoke();
/*  929 */           e.return_value();
/*  930 */           e.mark(constructed);
/*      */         }
/*  932 */         return e;
/*      */       }
/*      */     };
/*  935 */     for (int i = 0; i < this.callbackTypes.length; i++) {
View Full Code Here

/*  952 */     se.return_value();
/*  953 */     se.end_method();
/*      */   }
/*      */
/*      */   private void emitSetThreadCallbacks(ClassEmitter ce) {
/*  957 */     CodeEmitter e = ce.begin_method(9, SET_THREAD_CALLBACKS, null, null);
/*      */
/*  961 */     e.getfield("CGLIB$THREAD_CALLBACKS");
/*  962 */     e.load_arg(0);
/*  963 */     e.invoke_virtual(THREAD_LOCAL, THREAD_LOCAL_SET);
/*  964 */     e.return_value();
/*  965 */     e.end_method();
/*      */   }
View Full Code Here

/*  964 */     e.return_value();
/*  965 */     e.end_method();
/*      */   }
/*      */
/*      */   private void emitSetStaticCallbacks(ClassEmitter ce) {
/*  969 */     CodeEmitter e = ce.begin_method(9, SET_STATIC_CALLBACKS, null, null);
/*      */
/*  973 */     e.load_arg(0);
/*  974 */     e.putfield("CGLIB$STATIC_CALLBACKS");
/*  975 */     e.return_value();
/*  976 */     e.end_method();
/*      */   }
View Full Code Here

/*  989 */     e.getfield(getCallbackField(index));
/*  990 */     e.mark(end);
/*      */   }
/*      */
/*      */   private void emitBindCallbacks(ClassEmitter ce) {
/*  994 */     CodeEmitter e = ce.begin_method(26, BIND_CALLBACKS, null, null);
/*      */
/*  998 */     Local me = e.make_local();
/*  999 */     e.load_arg(0);
/* 1000 */     e.checkcast_this();
/* 1001 */     e.store_local(me);
/*      */
/* 1003 */     Label end = e.make_label();
/* 1004 */     e.load_local(me);
/* 1005 */     e.getfield("CGLIB$BOUND");
/* 1006 */     e.if_jump(154, end);
/* 1007 */     e.load_local(me);
/* 1008 */     e.push(1);
/* 1009 */     e.putfield("CGLIB$BOUND");
/*      */
/* 1011 */     e.getfield("CGLIB$THREAD_CALLBACKS");
/* 1012 */     e.invoke_virtual(THREAD_LOCAL, THREAD_LOCAL_GET);
/* 1013 */     e.dup();
/* 1014 */     Label found_callback = e.make_label();
/* 1015 */     e.ifnonnull(found_callback);
/* 1016 */     e.pop();
/*      */
/* 1018 */     e.getfield("CGLIB$STATIC_CALLBACKS");
/* 1019 */     e.dup();
/* 1020 */     e.ifnonnull(found_callback);
/* 1021 */     e.pop();
/* 1022 */     e.goTo(end);
/*      */
/* 1024 */     e.mark(found_callback);
/* 1025 */     e.checkcast(CALLBACK_ARRAY);
/* 1026 */     e.load_local(me);
/* 1027 */     e.swap();
/* 1028 */     for (int i = this.callbackTypes.length - 1; i >= 0; i--) {
/* 1029 */       if (i != 0) {
/* 1030 */         e.dup2();
/*      */       }
/* 1032 */       e.aaload(i);
/* 1033 */       e.checkcast(this.callbackTypes[i]);
/* 1034 */       e.putfield(getCallbackField(i));
/*      */     }
/*      */
/* 1037 */     e.mark(end);
/* 1038 */     e.return_value();
/* 1039 */     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.