use of org.objectweb.asm.ClassVisitor in project Hystrix by Netflix.
the class MethodProvider method unbride.
/**
* Finds generic method for the given bridge method.
*
* @param bridgeMethod the bridge method
* @param aClass the type where the bridge method is declared
* @return generic method
* @throws IOException
* @throws NoSuchMethodException
* @throws ClassNotFoundException
*/
public Method unbride(final Method bridgeMethod, Class<?> aClass) throws IOException, NoSuchMethodException, ClassNotFoundException {
if (bridgeMethod.isBridge() && bridgeMethod.isSynthetic()) {
if (cache.containsKey(bridgeMethod)) {
return cache.get(bridgeMethod);
}
ClassReader classReader = new ClassReader(aClass.getName());
final MethodSignature methodSignature = new MethodSignature();
classReader.accept(new ClassVisitor(ASM5) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
boolean bridge = (access & ACC_BRIDGE) != 0 && (access & ACC_SYNTHETIC) != 0;
if (bridge && bridgeMethod.getName().equals(name) && getParameterCount(desc) == bridgeMethod.getParameterTypes().length) {
return new MethodFinder(methodSignature);
}
return super.visitMethod(access, name, desc, signature, exceptions);
}
}, 0);
Method method = aClass.getDeclaredMethod(methodSignature.name, methodSignature.getParameterTypes());
cache.put(bridgeMethod, method);
return method;
} else {
return bridgeMethod;
}
}
use of org.objectweb.asm.ClassVisitor in project jacoco by jacoco.
the class ProbeInserterTest method setup.
@Before
public void setup() {
actual = new MethodRecorder();
actualVisitor = actual.getVisitor();
expected = new MethodRecorder();
expectedVisitor = expected.getVisitor();
arrayStrategy = new IProbeArrayStrategy() {
public int storeInstance(MethodVisitor mv, boolean clinit, int variable) {
mv.visitLdcInsn(clinit ? "clinit" : "init");
return 5;
}
public void addMembers(ClassVisitor delegate, int probeCount) {
}
};
}
use of org.objectweb.asm.ClassVisitor in project jacoco by jacoco.
the class FramesTest method calculateFrames.
private byte[] calculateFrames(byte[] source) {
source = BytecodeVersion.downgradeIfNeeded(BytecodeVersion.get(source), source);
ClassReader rc = new ClassReader(source);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
// Adjust Version to 1.6 to enable frames:
rc.accept(new ClassVisitor(InstrSupport.ASM_API_VERSION, cw) {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(Opcodes.V1_6, access, name, signature, superName, interfaces);
}
}, 0);
return cw.toByteArray();
}
use of org.objectweb.asm.ClassVisitor in project J2ME-Loader by nikita36078.
the class AndroidProducer method instrument.
private static byte[] instrument(String name, final InputStream classInputStream, boolean isMidlet) throws IOException {
ClassReader cr = new ClassReader(classInputStream);
ClassWriter cw = new ClassWriter(0);
ClassVisitor cv = new AndroidClassVisitor(cw, isMidlet, classesHierarchy, fieldTranslations, methodTranslations);
cr.accept(cv, 0);
return cw.toByteArray();
}
use of org.objectweb.asm.ClassVisitor in project openj9 by eclipse.
the class ASMTransformer method inject_call_to_timerMethod.
public static synchronized byte[] inject_call_to_timerMethod(Class classToTransform) {
try {
ClassReader reader = new ClassReader(classToTransform.getCanonicalName());
ClassWriter cw = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES);
ClassVisitor visitor = new MyClassVisitor(cw, classToTransform.getCanonicalName());
reader.accept(visitor, ClassReader.EXPAND_FRAMES);
return cw.toByteArray();
} catch (IOException e) {
return null;
}
}
Aggregations