use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class SimpleVerifier method isSubTypeOf.
protected boolean isSubTypeOf(final Value value, final Value expected) {
Type expectedType = ((BasicValue) expected).getType();
Type type = ((BasicValue) value).getType();
switch(expectedType.getSort()) {
case Type.INT:
case Type.FLOAT:
case Type.LONG:
case Type.DOUBLE:
return type == expectedType;
case Type.ARRAY:
case Type.OBJECT:
if ("Lnull;".equals(type.getDescriptor())) {
return true;
} else if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
return isAssignableFrom(expectedType, type);
} else {
return false;
}
default:
throw new Error("Internal error");
}
}
use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class EmitUtils method member_helper_type.
private static void member_helper_type(final CodeEmitter e, List members, final ObjectSwitchCallback callback, final ParameterTyper typer, final Label def, final Label end, final BitSet checked) throws Exception {
if (members.size() == 1) {
MethodInfo member = (MethodInfo) members.get(0);
Type[] types = typer.getParameterTypes(member);
// need to check classes that have not already been checked via switches
for (int i = 0; i < types.length; i++) {
if (checked == null || !checked.get(i)) {
e.dup();
e.aaload(i);
e.invoke_virtual(Constants.TYPE_CLASS, GET_NAME);
e.push(TypeUtils.emulateClassGetName(types[i]));
e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
e.if_jump(e.EQ, def);
}
}
e.pop();
callback.processCase(member, end);
} else {
// choose the index that has the best chance of uniquely identifying member
Type[] example = typer.getParameterTypes((MethodInfo) members.get(0));
Map buckets = null;
int index = -1;
for (int i = 0; i < example.length; i++) {
final int j = i;
Map test = CollectionUtils.bucket(members, new Transformer() {
public Object transform(Object value) {
return TypeUtils.emulateClassGetName(typer.getParameterTypes((MethodInfo) value)[j]);
}
});
if (buckets == null || test.size() > buckets.size()) {
buckets = test;
index = i;
}
}
if (buckets == null || buckets.size() == 1) {
// TODO: switch by returnType
// must have two methods with same name, types, and different return types
e.goTo(def);
} else {
checked.set(index);
e.dup();
e.aaload(index);
e.invoke_virtual(Constants.TYPE_CLASS, GET_NAME);
final Map fbuckets = buckets;
String[] names = (String[]) buckets.keySet().toArray(new String[buckets.size()]);
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
public void processCase(Object key, Label dontUseEnd) throws Exception {
member_helper_type(e, (List) fbuckets.get(key), callback, typer, def, end, checked);
}
public void processDefault() throws Exception {
e.goTo(def);
}
});
}
}
}
use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class BeanGenerator method generateClass.
public void generateClass(ClassVisitor v) throws Exception {
int size = props.size();
String[] names = (String[]) props.keySet().toArray(new String[size]);
Type[] types = new Type[size];
for (int i = 0; i < size; i++) {
types[i] = (Type) props.get(names[i]);
}
ClassEmitter ce = new ClassEmitter(v);
ce.begin_class(Constants.V1_2, Constants.ACC_PUBLIC, getClassName(), superclass != null ? Type.getType(superclass) : Constants.TYPE_OBJECT, null, null);
EmitUtils.null_constructor(ce);
EmitUtils.add_properties(ce, names, types);
ce.end_class();
}
use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class CodeEmitter method box.
/**
* 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 }));
}
}
}
use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class EmitUtils method hash_array.
private static void hash_array(final CodeEmitter e, Type type, final int multiplier, final Customizer customizer) {
Label skip = e.make_label();
Label end = e.make_label();
e.dup();
e.ifnull(skip);
EmitUtils.process_array(e, type, new ProcessArrayCallback() {
public void processElement(Type type) {
hash_code(e, type, multiplier, customizer);
}
});
e.goTo(end);
e.mark(skip);
e.pop();
e.mark(end);
}
Aggregations