Java Code Examples for org.springframework.cglib.core.Constants

The following examples show how to use org.springframework.cglib.core.Constants. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private static void getMethods(Class superclass, Class[] interfaces, List methods, List interfaceMethods, Set forcePublic) {
	ReflectUtils.addAllMethods(superclass, methods);
	List target = (interfaceMethods != null) ? interfaceMethods : methods;
	if (interfaces != null) {
		for (int i = 0; i < interfaces.length; i++) {
			if (interfaces[i] != Factory.class) {
				ReflectUtils.addAllMethods(interfaces[i], target);
			}
		}
	}
	if (interfaceMethods != null) {
		if (forcePublic != null) {
			forcePublic.addAll(MethodWrapper.createSet(interfaceMethods));
		}
		methods.addAll(interfaceMethods);
	}
	CollectionUtils.filter(methods, new RejectModifierPredicate(Constants.ACC_STATIC));
	CollectionUtils.filter(methods, new VisibilityPredicate(superclass, true));
	CollectionUtils.filter(methods, new DuplicatesPredicate());
	CollectionUtils.filter(methods, new RejectModifierPredicate(Constants.ACC_FINAL));
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitGetCallback(ClassEmitter ce, int[] keys) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACK, null);
	e.load_this();
	e.invoke_static_this(BIND_CALLBACKS);
	e.load_this();
	e.load_arg(0);
	e.process_switch(keys, new ProcessSwitchCallback() {
		public void processCase(int key, Label end) {
			e.getfield(getCallbackField(key));
			e.goTo(end);
		}

		public void processDefault() {
			e.pop(); // stack height
			e.aconst_null();
		}
	});
	e.return_value();
	e.end_method();
}
 
Example #3
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitSetCallback(ClassEmitter ce, int[] keys) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACK, null);
	e.load_arg(0);
	e.process_switch(keys, new ProcessSwitchCallback() {
		public void processCase(int key, Label end) {
			e.load_this();
			e.load_arg(1);
			e.checkcast(callbackTypes[key]);
			e.putfield(getCallbackField(key));
			e.goTo(end);
		}

		public void processDefault() {
			// TODO: error?
		}
	});
	e.return_value();
	e.end_method();
}
 
Example #4
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitGetCallbacks(ClassEmitter ce) {
	CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACKS, null);
	e.load_this();
	e.invoke_static_this(BIND_CALLBACKS);
	e.load_this();
	e.push(callbackTypes.length);
	e.newarray(CALLBACK);
	for (int i = 0; i < callbackTypes.length; i++) {
		e.dup();
		e.push(i);
		e.load_this();
		e.getfield(getCallbackField(i));
		e.aastore();
	}
	e.return_value();
	e.end_method();
}
 
Example #5
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 6 votes vote down vote up
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);
			break;
		default:
			e.throw_exception(ILLEGAL_STATE_EXCEPTION, "More than one callback object required");
	}
	emitCommonNewInstance(e);
}
 
Example #6
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private static void getMethods(Class superclass, Class[] interfaces, List methods, List interfaceMethods, Set forcePublic) {
	ReflectUtils.addAllMethods(superclass, methods);
	List target = (interfaceMethods != null) ? interfaceMethods : methods;
	if (interfaces != null) {
		for (int i = 0; i < interfaces.length; i++) {
			if (interfaces[i] != Factory.class) {
				ReflectUtils.addAllMethods(interfaces[i], target);
			}
		}
	}
	if (interfaceMethods != null) {
		if (forcePublic != null) {
			forcePublic.addAll(MethodWrapper.createSet(interfaceMethods));
		}
		methods.addAll(interfaceMethods);
	}
	CollectionUtils.filter(methods, new RejectModifierPredicate(Constants.ACC_STATIC));
	CollectionUtils.filter(methods, new VisibilityPredicate(superclass, true));
	CollectionUtils.filter(methods, new DuplicatesPredicate());
	CollectionUtils.filter(methods, new RejectModifierPredicate(Constants.ACC_FINAL));
}
 
Example #7
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitGetCallback(ClassEmitter ce, int[] keys) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACK, null);
	e.load_this();
	e.invoke_static_this(BIND_CALLBACKS);
	e.load_this();
	e.load_arg(0);
	e.process_switch(keys, new ProcessSwitchCallback() {
		public void processCase(int key, Label end) {
			e.getfield(getCallbackField(key));
			e.goTo(end);
		}

		public void processDefault() {
			e.pop(); // stack height
			e.aconst_null();
		}
	});
	e.return_value();
	e.end_method();
}
 
Example #8
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitSetCallback(ClassEmitter ce, int[] keys) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACK, null);
	e.load_arg(0);
	e.process_switch(keys, new ProcessSwitchCallback() {
		public void processCase(int key, Label end) {
			e.load_this();
			e.load_arg(1);
			e.checkcast(callbackTypes[key]);
			e.putfield(getCallbackField(key));
			e.goTo(end);
		}

		public void processDefault() {
			// TODO: error?
		}
	});
	e.return_value();
	e.end_method();
}
 
Example #9
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitGetCallbacks(ClassEmitter ce) {
	CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACKS, null);
	e.load_this();
	e.invoke_static_this(BIND_CALLBACKS);
	e.load_this();
	e.push(callbackTypes.length);
	e.newarray(CALLBACK);
	for (int i = 0; i < callbackTypes.length; i++) {
		e.dup();
		e.push(i);
		e.load_this();
		e.getfield(getCallbackField(i));
		e.aastore();
	}
	e.return_value();
	e.end_method();
}
 
Example #10
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 6 votes vote down vote up
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);
			break;
		default:
			e.throw_exception(ILLEGAL_STATE_EXCEPTION, "More than one callback object required");
	}
	emitCommonNewInstance(e);
}
 
Example #11
Source Project: spring-analysis-note   Author: Vip-Augus   File: ConfigurationClassEnhancer.java    License: MIT License 5 votes vote down vote up
@Override
protected ClassGenerator transform(ClassGenerator cg) throws Exception {
	ClassEmitterTransformer transformer = new ClassEmitterTransformer() {
		@Override
		public void end_class() {
			declare_field(Constants.ACC_PUBLIC, BEAN_FACTORY_FIELD, Type.getType(BeanFactory.class), null);
			super.end_class();
		}
	};
	return new TransformingClassGenerator(cg, transformer);
}
 
Example #12
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 5 votes vote down vote up
protected Object nextInstance(Object instance) {
	EnhancerFactoryData data = (EnhancerFactoryData) instance;

	if (classOnly) {
		return data.generatedClass;
	}

	Class[] argumentTypes = this.argumentTypes;
	Object[] arguments = this.arguments;
	if (argumentTypes == null) {
		argumentTypes = Constants.EMPTY_CLASS_ARRAY;
		arguments = null;
	}
	return data.newInstance(argumentTypes, arguments, callbacks);
}
 
Example #13
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 5 votes vote down vote up
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");
}
 
Example #14
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitSetCallbacks(ClassEmitter ce) {
	CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACKS, null);
	e.load_this();
	e.load_arg(0);
	for (int i = 0; i < callbackTypes.length; i++) {
		e.dup2();
		e.aaload(i);
		e.checkcast(callbackTypes[i]);
		e.putfield(getCallbackField(i));
	}
	e.return_value();
	e.end_method();
}
 
Example #15
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitNewInstanceCallbacks(ClassEmitter ce) {
	CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, NEW_INSTANCE, null);
	Type thisType = getThisType(e);
	e.load_arg(0);
	e.invoke_static(thisType, SET_THREAD_CALLBACKS);
	emitCommonNewInstance(e);
}
 
Example #16
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 5 votes vote down vote up
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);
	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);
	e.return_value();
	e.end_method();
}
 
Example #17
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 5 votes vote down vote up
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();
}
 
Example #18
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitSetStaticCallbacks(ClassEmitter ce) {
	CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_STATIC,
			SET_STATIC_CALLBACKS,
			null);
	e.load_arg(0);
	e.putfield(STATIC_CALLBACKS_FIELD);
	e.return_value();
	e.end_method();
}
 
Example #19
Source Project: java-technology-stack   Author: codeEngraver   File: ConfigurationClassEnhancer.java    License: MIT License 5 votes vote down vote up
@Override
protected ClassGenerator transform(ClassGenerator cg) throws Exception {
	ClassEmitterTransformer transformer = new ClassEmitterTransformer() {
		@Override
		public void end_class() {
			declare_field(Constants.ACC_PUBLIC, BEAN_FACTORY_FIELD, Type.getType(BeanFactory.class), null);
			super.end_class();
		}
	};
	return new TransformingClassGenerator(cg, transformer);
}
 
Example #20
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 5 votes vote down vote up
protected Object nextInstance(Object instance) {
	EnhancerFactoryData data = (EnhancerFactoryData) instance;

	if (classOnly) {
		return data.generatedClass;
	}

	Class[] argumentTypes = this.argumentTypes;
	Object[] arguments = this.arguments;
	if (argumentTypes == null) {
		argumentTypes = Constants.EMPTY_CLASS_ARRAY;
		arguments = null;
	}
	return data.newInstance(argumentTypes, arguments, callbacks);
}
 
Example #21
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 5 votes vote down vote up
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");
}
 
Example #22
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitSetCallbacks(ClassEmitter ce) {
	CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACKS, null);
	e.load_this();
	e.load_arg(0);
	for (int i = 0; i < callbackTypes.length; i++) {
		e.dup2();
		e.aaload(i);
		e.checkcast(callbackTypes[i]);
		e.putfield(getCallbackField(i));
	}
	e.return_value();
	e.end_method();
}
 
Example #23
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitNewInstanceCallbacks(ClassEmitter ce) {
	CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, NEW_INSTANCE, null);
	Type thisType = getThisType(e);
	e.load_arg(0);
	e.invoke_static(thisType, SET_THREAD_CALLBACKS);
	emitCommonNewInstance(e);
}
 
Example #24
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 5 votes vote down vote up
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);
	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);
	e.return_value();
	e.end_method();
}
 
Example #25
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 5 votes vote down vote up
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();
}
 
Example #26
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitSetStaticCallbacks(ClassEmitter ce) {
	CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_STATIC,
			SET_STATIC_CALLBACKS,
			null);
	e.load_arg(0);
	e.putfield(STATIC_CALLBACKS_FIELD);
	e.return_value();
	e.end_method();
}
 
Example #27
Source Project: lams   Author: lamsfoundation   File: ConfigurationClassEnhancer.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected ClassGenerator transform(ClassGenerator cg) throws Exception {
	ClassEmitterTransformer transformer = new ClassEmitterTransformer() {
		@Override
		public void end_class() {
			declare_field(Constants.ACC_PUBLIC, BEAN_FACTORY_FIELD, Type.getType(BeanFactory.class), null);
			super.end_class();
		}
	};
	return new TransformingClassGenerator(cg, transformer);
}
 
Example #28
Source Project: spring4-understanding   Author: langtianya   File: ConfigurationClassEnhancer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ClassGenerator transform(ClassGenerator cg) throws Exception {
	ClassEmitterTransformer transformer = new ClassEmitterTransformer() {
		@Override
		public void end_class() {
			declare_field(Constants.ACC_PUBLIC, BEAN_FACTORY_FIELD, Type.getType(BeanFactory.class), null);
			super.end_class();
		}
	};
	return new TransformingClassGenerator(cg, transformer);
}
 
Example #29
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 4 votes vote down vote up
public void generateClass(ClassVisitor v) throws Exception {
	Class sc = (superclass == null) ? Object.class : superclass;

	if (TypeUtils.isFinal(sc.getModifiers()))
		throw new IllegalArgumentException("Cannot subclass final class " + sc.getName());
	List constructors = new ArrayList(Arrays.asList(sc.getDeclaredConstructors()));
	filterConstructors(sc, constructors);

	// Order is very important: must add superclass, then
	// its superclass chain, then each interface and
	// its superinterfaces.
	List actualMethods = new ArrayList();
	List interfaceMethods = new ArrayList();
	final Set forcePublic = new HashSet();
	getMethods(sc, interfaces, actualMethods, interfaceMethods, forcePublic);

	List methods = CollectionUtils.transform(actualMethods, new Transformer() {
		public Object transform(Object value) {
			Method method = (Method) value;
			int modifiers = Constants.ACC_FINAL
					| (method.getModifiers()
					& ~Constants.ACC_ABSTRACT
					& ~Constants.ACC_NATIVE
					& ~Constants.ACC_SYNCHRONIZED);
			if (forcePublic.contains(MethodWrapper.create(method))) {
				modifiers = (modifiers & ~Constants.ACC_PROTECTED) | Constants.ACC_PUBLIC;
			}
			return ReflectUtils.getMethodInfo(method, modifiers);
		}
	});

	ClassEmitter e = new ClassEmitter(v);
	if (currentData == null) {
		e.begin_class(Constants.V1_2,
				Constants.ACC_PUBLIC,
				getClassName(),
				Type.getType(sc),
				(useFactory ?
						TypeUtils.add(TypeUtils.getTypes(interfaces), FACTORY) :
						TypeUtils.getTypes(interfaces)),
				Constants.SOURCE_FILE);
	}
	else {
		e.begin_class(Constants.V1_2,
				Constants.ACC_PUBLIC,
				getClassName(),
				null,
				new Type[]{FACTORY},
				Constants.SOURCE_FILE);
	}
	List constructorInfo = CollectionUtils.transform(constructors, MethodInfoTransformer.getInstance());

	e.declare_field(Constants.ACC_PRIVATE, BOUND_FIELD, Type.BOOLEAN_TYPE, null);
	e.declare_field(Constants.ACC_PUBLIC | Constants.ACC_STATIC, FACTORY_DATA_FIELD, OBJECT_TYPE, null);
	if (!interceptDuringConstruction) {
		e.declare_field(Constants.ACC_PRIVATE, CONSTRUCTED_FIELD, Type.BOOLEAN_TYPE, null);
	}
	e.declare_field(Constants.PRIVATE_FINAL_STATIC, THREAD_CALLBACKS_FIELD, THREAD_LOCAL, null);
	e.declare_field(Constants.PRIVATE_FINAL_STATIC, STATIC_CALLBACKS_FIELD, CALLBACK_ARRAY, null);
	if (serialVersionUID != null) {
		e.declare_field(Constants.PRIVATE_FINAL_STATIC, Constants.SUID_FIELD_NAME, Type.LONG_TYPE, serialVersionUID);
	}

	for (int i = 0; i < callbackTypes.length; i++) {
		e.declare_field(Constants.ACC_PRIVATE, getCallbackField(i), callbackTypes[i], null);
	}
	// This is declared private to avoid "public field" pollution
	e.declare_field(Constants.ACC_PRIVATE | Constants.ACC_STATIC, CALLBACK_FILTER_FIELD, OBJECT_TYPE, null);

	if (currentData == null) {
		emitMethods(e, methods, actualMethods);
		emitConstructors(e, constructorInfo);
	}
	else {
		emitDefaultConstructor(e);
	}
	emitSetThreadCallbacks(e);
	emitSetStaticCallbacks(e);
	emitBindCallbacks(e);

	if (useFactory || currentData != null) {
		int[] keys = getCallbackKeys();
		emitNewInstanceCallbacks(e);
		emitNewInstanceCallback(e);
		emitNewInstanceMultiarg(e, constructorInfo);
		emitGetCallback(e, keys);
		emitSetCallback(e, keys);
		emitGetCallbacks(e);
		emitSetCallbacks(e);
	}

	e.end_class();
}
 
Example #30
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 4 votes vote down vote up
private void emitBindCallbacks(ClassEmitter ce) {
	CodeEmitter e = ce.begin_method(Constants.PRIVATE_FINAL_STATIC,
			BIND_CALLBACKS,
			null);
	Local me = e.make_local();
	e.load_arg(0);
	e.checkcast_this();
	e.store_local(me);

	Label end = e.make_label();
	e.load_local(me);
	e.getfield(BOUND_FIELD);
	e.if_jump(CodeEmitter.NE, end);
	e.load_local(me);
	e.push(1);
	e.putfield(BOUND_FIELD);

	e.getfield(THREAD_CALLBACKS_FIELD);
	e.invoke_virtual(THREAD_LOCAL, THREAD_LOCAL_GET);
	e.dup();
	Label found_callback = e.make_label();
	e.ifnonnull(found_callback);
	e.pop();

	e.getfield(STATIC_CALLBACKS_FIELD);
	e.dup();
	e.ifnonnull(found_callback);
	e.pop();
	e.goTo(end);

	e.mark(found_callback);
	e.checkcast(CALLBACK_ARRAY);
	e.load_local(me);
	e.swap();
	for (int i = callbackTypes.length - 1; i >= 0; i--) {
		if (i != 0) {
			e.dup2();
		}
		e.aaload(i);
		e.checkcast(callbackTypes[i]);
		e.putfield(getCallbackField(i));
	}

	e.mark(end);
	e.return_value();
	e.end_method();
}