Search in sources :

Example 11 with CodeEmitter

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

the class Enhancer method emitConstructors.

private void emitConstructors(ClassEmitter ce, List constructors) {
    boolean seenNull = false;
    for (Iterator it = constructors.iterator(); it.hasNext(); ) {
        MethodInfo constructor = (MethodInfo) it.next();
        if (currentData != null && !"()V".equals(constructor.getSignature().getDescriptor())) {
            continue;
        }
        CodeEmitter e = EmitUtils.begin_method(ce, constructor, Constants.ACC_PUBLIC);
        e.load_this();
        e.dup();
        e.load_args();
        Signature sig = constructor.getSignature();
        seenNull = seenNull || sig.getDescriptor().equals("()V");
        e.super_invoke_constructor(sig);
        if (currentData == null) {
            e.invoke_static_this(BIND_CALLBACKS);
            if (!interceptDuringConstruction) {
                e.load_this();
                e.push(1);
                e.putfield(CONSTRUCTED_FIELD);
            }
        }
        e.return_value();
        e.end_method();
    }
    if (!classOnly && !seenNull && arguments == null)
        throw new IllegalArgumentException("Superclass has no null constructors but no arguments were given");
}
Also used : CodeEmitter(org.springframework.cglib.core.CodeEmitter) Signature(org.springframework.cglib.core.Signature) Iterator(java.util.Iterator) MethodInfo(org.springframework.cglib.core.MethodInfo)

Example 12 with CodeEmitter

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

the class Enhancer method emitNewInstanceCallback.

private void emitNewInstanceCallback(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SINGLE_NEW_INSTANCE, null);
    switch(callbackTypes.length) {
        case 0:
            // TODO: make sure Callback is null
            break;
        case 1:
            // for now just make a new array; TODO: optimize
            e.push(1);
            e.newarray(CALLBACK);
            e.dup();
            e.push(0);
            e.load_arg(0);
            e.aastore();
            e.invoke_static(getThisType(e), SET_THREAD_CALLBACKS, false);
            break;
        default:
            e.throw_exception(ILLEGAL_STATE_EXCEPTION, "More than one callback object required");
    }
    emitCommonNewInstance(e);
}
Also used : CodeEmitter(org.springframework.cglib.core.CodeEmitter)

Example 13 with CodeEmitter

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

the class Enhancer method emitSetThreadCallbacks.

private void emitSetThreadCallbacks(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_STATIC, SET_THREAD_CALLBACKS, null);
    e.getfield(THREAD_CALLBACKS_FIELD);
    e.load_arg(0);
    e.invoke_virtual(THREAD_LOCAL, THREAD_LOCAL_SET);
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.springframework.cglib.core.CodeEmitter)

Aggregations

CodeEmitter (org.springframework.cglib.core.CodeEmitter)13 Label (org.springframework.asm.Label)5 MethodInfo (org.springframework.cglib.core.MethodInfo)4 Type (org.springframework.asm.Type)3 Signature (org.springframework.cglib.core.Signature)3 Iterator (java.util.Iterator)2 ProcessSwitchCallback (org.springframework.cglib.core.ProcessSwitchCallback)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ClassEmitter (org.springframework.cglib.core.ClassEmitter)1 CodeGenerationException (org.springframework.cglib.core.CodeGenerationException)1 Local (org.springframework.cglib.core.Local)1 ObjectSwitchCallback (org.springframework.cglib.core.ObjectSwitchCallback)1