Search in sources :

Example 1 with ObjectSwitchCallback

use of org.springframework.cglib.core.ObjectSwitchCallback in project spring-framework by spring-projects.

the class Enhancer method emitNewInstanceMultiarg.

private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) {
    final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, MULTIARG_NEW_INSTANCE, null);
    final Type thisType = getThisType(e);
    e.load_arg(2);
    e.invoke_static(thisType, SET_THREAD_CALLBACKS, false);
    e.new_instance(thisType);
    e.dup();
    e.load_arg(0);
    EmitUtils.constructor_switch(e, constructors, new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            MethodInfo constructor = (MethodInfo) key;
            Type[] types = constructor.getSignature().getArgumentTypes();
            for (int i = 0; i < types.length; i++) {
                e.load_arg(1);
                e.push(i);
                e.aaload();
                e.unbox(types[i]);
            }
            e.invoke_constructor(thisType, constructor.getSignature());
            e.goTo(end);
        }

        public void processDefault() {
            e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found");
        }
    });
    e.aconst_null();
    e.invoke_static(thisType, SET_THREAD_CALLBACKS, false);
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.springframework.cglib.core.CodeEmitter) Type(org.springframework.asm.Type) Label(org.springframework.asm.Label) MethodInfo(org.springframework.cglib.core.MethodInfo) ObjectSwitchCallback(org.springframework.cglib.core.ObjectSwitchCallback)

Aggregations

Label (org.springframework.asm.Label)1 Type (org.springframework.asm.Type)1 CodeEmitter (org.springframework.cglib.core.CodeEmitter)1 MethodInfo (org.springframework.cglib.core.MethodInfo)1 ObjectSwitchCallback (org.springframework.cglib.core.ObjectSwitchCallback)1