use of org.powermock.api.mockito.repackaged.cglib.core.MethodInfo in project powermock by powermock.
the class Enhancer method emitMethods.
private void emitMethods(final ClassEmitter ce, List methods, List actualMethods) {
CallbackGenerator[] generators = CallbackInfo.getGenerators(callbackTypes);
Map groups = new HashMap();
final Map indexes = new HashMap();
final Map originalModifiers = new HashMap();
final Map positions = CollectionUtils.getIndexMap(methods);
Iterator it1 = methods.iterator();
Iterator it2 = (actualMethods != null) ? actualMethods.iterator() : null;
while (it1.hasNext()) {
MethodInfo method = (MethodInfo) it1.next();
Method actualMethod = (it2 != null) ? (Method) it2.next() : null;
int index = filter.accept(actualMethod, actualMethods);
if (index >= callbackTypes.length) {
throw new IllegalArgumentException("Callback filter returned an index that is too large: " + index);
}
originalModifiers.put(method, new Integer((actualMethod != null) ? actualMethod.getModifiers() : method.getModifiers()));
indexes.put(method, new Integer(index));
List group = (List) groups.get(generators[index]);
if (group == null) {
groups.put(generators[index], group = new ArrayList(methods.size()));
}
group.add(method);
}
Set seenGen = new HashSet();
CodeEmitter se = ce.getStaticHook();
se.new_instance(THREAD_LOCAL);
se.dup();
se.invoke_constructor(THREAD_LOCAL, CSTRUCT_NULL);
se.putfield(THREAD_CALLBACKS_FIELD);
final Object[] state = new Object[1];
CallbackGenerator.Context context = new CallbackGenerator.Context() {
public ClassLoader getClassLoader() {
return Enhancer.this.getClassLoader();
}
public int getOriginalModifiers(MethodInfo method) {
return ((Integer) originalModifiers.get(method)).intValue();
}
public int getIndex(MethodInfo method) {
return ((Integer) indexes.get(method)).intValue();
}
public void emitCallback(CodeEmitter e, int index) {
emitCurrentCallback(e, index);
}
public Signature getImplSignature(MethodInfo method) {
return rename(method.getSignature(), ((Integer) positions.get(method)).intValue());
}
public CodeEmitter beginMethod(ClassEmitter ce, MethodInfo method) {
CodeEmitter e = EmitUtils.begin_method(ce, method);
if (!interceptDuringConstruction && !TypeUtils.isAbstract(method.getModifiers())) {
Label constructed = e.make_label();
e.load_this();
e.getfield(CONSTRUCTED_FIELD);
e.if_jump(e.NE, constructed);
e.load_this();
e.load_args();
e.super_invoke();
e.return_value();
e.mark(constructed);
}
return e;
}
};
for (int i = 0; i < callbackTypes.length; i++) {
CallbackGenerator gen = generators[i];
if (!seenGen.contains(gen)) {
seenGen.add(gen);
final List fmethods = (List) groups.get(gen);
if (fmethods != null) {
try {
gen.generate(ce, context, fmethods);
gen.generateStatic(se, context, fmethods);
} catch (RuntimeException x) {
throw x;
} catch (Exception x) {
throw new CodeGenerationException(x);
}
}
}
}
se.return_value();
se.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.MethodInfo in project powermock by powermock.
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();
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);
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");
}
use of org.powermock.api.mockito.repackaged.cglib.core.MethodInfo in project powermock by powermock.
the class NoOpGenerator method generate.
public void generate(ClassEmitter ce, Context context, List methods) {
for (Iterator it = methods.iterator(); it.hasNext(); ) {
MethodInfo method = (MethodInfo) it.next();
if (TypeUtils.isProtected(context.getOriginalModifiers(method)) && TypeUtils.isPublic(method.getModifiers())) {
CodeEmitter e = EmitUtils.begin_method(ce, method);
e.load_this();
e.load_args();
e.super_invoke();
e.return_value();
e.end_method();
}
}
}
use of org.powermock.api.mockito.repackaged.cglib.core.MethodInfo in project powermock by powermock.
the class BulkBeanEmitter method generateGet.
private void generateGet(final Class target, final Method[] getters) {
CodeEmitter e = begin_method(Constants.ACC_PUBLIC, GET_PROPERTY_VALUES, null);
if (getters.length >= 0) {
e.load_arg(0);
e.checkcast(Type.getType(target));
Local bean = e.make_local();
e.store_local(bean);
for (int i = 0; i < getters.length; i++) {
if (getters[i] != null) {
MethodInfo getter = ReflectUtils.getMethodInfo(getters[i]);
e.load_arg(1);
e.push(i);
e.load_local(bean);
e.invoke(getter);
e.box(getter.getSignature().getReturnType());
e.aastore();
}
}
}
e.return_value();
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.MethodInfo in project powermock by powermock.
the class DispatcherGenerator method generate.
public void generate(ClassEmitter ce, Context context, List methods) {
for (Iterator it = methods.iterator(); it.hasNext(); ) {
MethodInfo method = (MethodInfo) it.next();
if (!TypeUtils.isProtected(method.getModifiers())) {
CodeEmitter e = context.beginMethod(ce, method);
context.emitCallback(e, context.getIndex(method));
if (proxyRef) {
e.load_this();
e.invoke_interface(PROXY_REF_DISPATCHER, PROXY_REF_LOAD_OBJECT);
} else {
e.invoke_interface(DISPATCHER, LOAD_OBJECT);
}
e.checkcast(method.getClassInfo().getType());
e.load_args();
e.invoke(method);
e.return_value();
e.end_method();
}
}
}
Aggregations