private Signature loadMethod(int index) { return new Signature("CGLIB$LOAD_PRIVATE_" + index, Constants.TYPE_OBJECT, Constants.TYPES_EMPTY); }
private static Signature writeMethodSig(String name, String desc) { return new Signature("$cglib_write_" + name, "(" + desc + ")V"); }
private static Signature readMethodSig(String name, String desc) { return new Signature("$cglib_read_" + name, "()" + desc); }
public static Signature parseConstructor(Type[] types) { StringBuffer sb = new StringBuffer(); sb.append("("); for (int i = 0; i < types.length; i++) { sb.append(types[i].getDescriptor()); } sb.append(")"); sb.append("V"); return new Signature(Constants.CONSTRUCTOR_NAME, sb.toString()); }
/** * For internal use by {@link Enhancer} only; see the {@link org.mockito.cglib.reflect.FastMethod} class * for similar functionality. */ public static MethodProxy create(Class c1, Class c2, String desc, String name1, String name2) { MethodProxy proxy = new MethodProxy(); proxy.sig1 = new Signature(name1, desc); proxy.sig2 = new Signature(name2, desc); proxy.createInfo = new CreateInfo(c1, c2); return proxy; }
public static Signature getSignature(Member member) { if (member instanceof Method) { return new Signature(member.getName(), Type.getMethodDescriptor((Method)member)); } else if (member instanceof Constructor) { Type[] types = TypeUtils.getTypes(((Constructor)member).getParameterTypes()); return new Signature(Constants.CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, types)); } else { throw new IllegalArgumentException("Cannot get signature of a field"); } }
public static Signature parseSignature(String s) { int space = s.indexOf(' '); int lparen = s.indexOf('(', space); int rparen = s.indexOf(')', lparen); String returnType = s.substring(0, space); String methodName = s.substring(space + 1, lparen); StringBuffer sb = new StringBuffer(); sb.append('('); for (Iterator it = parseTypes(s, lparen + 1, rparen).iterator(); it.hasNext();) { sb.append(it.next()); } sb.append(')'); sb.append(map(returnType)); return new Signature(methodName, sb.toString()); }
private static Signature readCallbackSig(Type type) { Type remap = remap(type); return new Signature("read" + callbackName(remap), remap, new Type[]{ Constants.TYPE_OBJECT, Constants.TYPE_STRING, remap }); }
private static Signature writeCallbackSig(Type type) { Type remap = remap(type); return new Signature("write" + callbackName(remap), remap, new Type[]{ Constants.TYPE_OBJECT, Constants.TYPE_STRING, remap, remap }); }
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return begin_method(access, new Signature(name, desc), TypeUtils.fromInternalNames(exceptions)); } }
private Signature rename(Signature sig, int index) { return new Signature("CGLIB$" + sig.getName() + "$" + index, sig.getDescriptor()); }
public CodeEmitter getStaticHook() { if (TypeUtils.isInterface(getAccess())) { throw new IllegalStateException("static hook is invalid for this class"); } if (staticHook == null) { staticHookSig = new Signature("CGLIB$STATICHOOK" + getNextHook(), "()V"); staticHook = begin_method(Constants.ACC_STATIC, staticHookSig, null); if (staticInit != null) { staticInit.invoke_static_this(staticHookSig); } } return staticHook; }
public static void add_property(ClassEmitter ce, String name, Type type, String fieldName) { String property = TypeUtils.upperFirst(name); CodeEmitter e; e = ce.begin_method(Constants.ACC_PUBLIC, new Signature("get" + property, type, Constants.TYPES_EMPTY), null); e.load_this(); e.getfield(fieldName); e.return_value(); e.end_method(); e = ce.begin_method(Constants.ACC_PUBLIC, new Signature("set" + property, Type.VOID_TYPE, new Type[]{ type }), null); e.load_this(); e.load_arg(0); e.putfield(fieldName); e.return_value(); e.end_method(); }
public void declare_field(int access, final String name, Type type, Object value) { super.declare_field(access, name, type, value); String property = TypeUtils.upperFirst(callback.getPropertyName(getClassType(), name)); if (property != null) { CodeEmitter e; e = begin_method(Constants.ACC_PUBLIC, new Signature("get" + property, type, Constants.TYPES_EMPTY), null); e.load_this(); e.getfield(name); e.return_value(); e.end_method(); e = begin_method(Constants.ACC_PUBLIC, new Signature("set" + property, Type.VOID_TYPE, new Type[]{ type }), null); e.load_this(); e.load_arg(0); e.putfield(name); e.return_value(); e.end_method(); } } }
/** * If the argument is a primitive class, replaces the primitive value * on the top of the stack with the wrapped (Object) equivalent. For * example, char -> Character. * If the class is Void, a null is pushed onto the stack instead. * @param type the class indicating the current type of the top stack value */ public void box(Type type) { if (TypeUtils.isPrimitive(type)) { if (type == Type.VOID_TYPE) { aconst_null(); } else { Type boxed = TypeUtils.getBoxedType(type); new_instance(boxed); if (type.getSize() == 2) { // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o dup_x2(); dup_x2(); pop(); } else { // p -> po -> opo -> oop -> o dup_x1(); swap(); } invoke_constructor(boxed, new Signature(Constants.CONSTRUCTOR_NAME, Type.VOID_TYPE, new Type[]{ type })); } } }
/** * For internal use by {@link Enhancer} only; see the {@link org.mockito.cglib.reflect.FastMethod} class * for similar functionality. */ public static MethodProxy create(Class c1, Class c2, String desc, String name1, String name2) { MethodProxy proxy = new MethodProxy(); proxy.sig1 = new Signature(name1, desc); proxy.sig2 = new Signature(name2, desc); proxy.createInfo = new CreateInfo(c1, c2); return proxy; }
public static Signature parseConstructor(Type[] types) { StringBuffer sb = new StringBuffer(); sb.append("("); for (int i = 0; i < types.length; i++) { sb.append(types[i].getDescriptor()); } sb.append(")"); sb.append("V"); return new Signature(Constants.CONSTRUCTOR_NAME, sb.toString()); }
private static Signature readCallbackSig(Type type) { Type remap = remap(type); return new Signature("read" + callbackName(remap), remap, new Type[]{ Constants.TYPE_OBJECT, Constants.TYPE_STRING, remap }); }
private static Signature writeCallbackSig(Type type) { Type remap = remap(type); return new Signature("write" + callbackName(remap), remap, new Type[]{ Constants.TYPE_OBJECT, Constants.TYPE_STRING, remap, remap }); }
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return begin_method(access, new Signature(name, desc), TypeUtils.fromInternalNames(exceptions)); } }