use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class EmitUtils method member_switch_helper.
private static void member_switch_helper(final CodeEmitter e, List members, final ObjectSwitchCallback callback, boolean useName) {
try {
final Map cache = new HashMap();
final ParameterTyper cached = new ParameterTyper() {
public Type[] getParameterTypes(MethodInfo member) {
Type[] types = (Type[]) cache.get(member);
if (types == null) {
cache.put(member, types = member.getSignature().getArgumentTypes());
}
return types;
}
};
final Label def = e.make_label();
final Label end = e.make_label();
if (useName) {
e.swap();
final Map buckets = CollectionUtils.bucket(members, new Transformer() {
public Object transform(Object value) {
return ((MethodInfo) value).getSignature().getName();
}
});
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_size(e, (List) buckets.get(key), callback, cached, def, end);
}
public void processDefault() throws Exception {
e.goTo(def);
}
});
} else {
member_helper_size(e, members, callback, cached, def, end);
}
e.mark(def);
e.pop();
callback.processDefault();
e.mark(end);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new CodeGenerationException(ex);
}
}
use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class SimpleVerifier method merge.
public Value merge(final Value v, final Value w) {
if (!v.equals(w)) {
Type t = ((BasicValue) v).getType();
Type u = ((BasicValue) w).getType();
if (t != null && (t.getSort() == Type.OBJECT || t.getSort() == Type.ARRAY)) {
if (u != null && (u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY)) {
if ("Lnull;".equals(t.getDescriptor())) {
return w;
}
if ("Lnull;".equals(u.getDescriptor())) {
return v;
}
if (isAssignableFrom(t, u)) {
return v;
}
if (isAssignableFrom(u, t)) {
return w;
}
// interfaces
do {
if (t == null || isInterface(t)) {
return BasicValue.REFERENCE_VALUE;
}
t = getSuperClass(t);
if (isAssignableFrom(t, u)) {
return newValue(t);
}
} while (true);
}
}
return BasicValue.UNINITIALIZED_VALUE;
}
return v;
}
use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class CheckClassAdapter method verify.
/**
* Checks a given class
*
* @param cr a {@code ClassReader} that contains bytecode for the
* analysis.
* @param dump true if bytecode should be printed out not only when errors
* are found.
* @param pw write where results going to be printed
*/
public static void verify(final ClassReader cr, final boolean dump, final PrintWriter pw) {
ClassNode cn = new ClassNode();
cr.accept(new CheckClassAdapter(cn), ClassReader.SKIP_DEBUG);
Type syperType = cn.superName == null ? null : Type.getObjectType(cn.superName);
List methods = cn.methods;
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = (MethodNode) methods.get(i);
Analyzer a = new Analyzer(new SimpleVerifier(Type.getObjectType(cn.name), syperType, false));
try {
a.analyze(cn.name, method);
if (!dump) {
continue;
}
} catch (Exception e) {
e.printStackTrace(pw);
}
Frame[] frames = a.getFrames();
TraceMethodVisitor mv = new TraceMethodVisitor();
pw.println(method.name + method.desc);
for (int j = 0; j < method.instructions.size(); ++j) {
method.instructions.get(j).accept(mv);
StringBuilder s = new StringBuilder();
Frame f = frames[j];
if (f == null) {
s.append('?');
} else {
for (int k = 0; k < f.getLocals(); ++k) {
s.append(getShortName(f.getLocal(k).toString())).append(' ');
}
s.append(" : ");
for (int k = 0; k < f.getStackSize(); ++k) {
s.append(getShortName(f.getStack(k).toString())).append(' ');
}
}
while (s.length() < method.maxStack + method.maxLocals + 1) {
s.append(' ');
}
pw.print(Integer.toString(j + 100000).substring(1));
// mv.text.get(j));
pw.print(" " + s + " : " + mv.buf);
}
for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv);
pw.print(" " + mv.buf);
}
pw.println();
}
pw.flush();
}
use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class ParallelSorterEmitter method generateSwap.
private void generateSwap(final Object[] arrays) {
CodeEmitter e = begin_method(Constants.ACC_PUBLIC, SWAP, null);
for (int i = 0; i < arrays.length; i++) {
Type type = Type.getType(arrays[i].getClass());
Type component = TypeUtils.getComponentType(type);
Local T = e.make_local(type);
e.load_this();
e.getfield(getFieldName(i));
e.store_local(T);
e.load_local(T);
e.load_arg(0);
e.load_local(T);
e.load_arg(1);
e.array_load(component);
e.load_local(T);
e.load_arg(1);
e.load_local(T);
e.load_arg(0);
e.array_load(component);
e.array_store(component);
e.array_store(component);
}
e.return_value();
e.end_method();
}
Aggregations