use of org.objectweb.asm.MethodVisitor in project robovm by robovm.
the class AnnotationImplPlugin method generateAnnotationTypeMethod.
private void generateAnnotationTypeMethod(Clazz clazz, ClassWriter cw) {
// Class<? extends Annotation> annotationType();
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "annotationType", "()Ljava/lang/Class;", null, null);
mv.visitCode();
mv.visitLdcInsn(Type.getObjectType(clazz.getInternalName()));
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
use of org.objectweb.asm.MethodVisitor in project byte-buddy by raphw.
the class TypeConstantAdjustmentTest method testInstrumentationLegacyClassFileArrayType.
@Test
public void testInstrumentationLegacyClassFileArrayType() throws Exception {
ClassVisitor classVisitor = TypeConstantAdjustment.INSTANCE.wrap(mock(TypeDescription.class), this.classVisitor, mock(Implementation.Context.class), mock(TypePool.class), new FieldList.Empty<FieldDescription.InDefinedShape>(), new MethodList.Empty<MethodDescription>(), IGNORED, IGNORED);
classVisitor.visit(ClassFileVersion.JAVA_V4.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
MethodVisitor methodVisitor = classVisitor.visitMethod(FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
assertThat(methodVisitor, not(this.methodVisitor));
methodVisitor.visitLdcInsn(Type.getType(Object[].class));
verify(this.classVisitor).visit(ClassFileVersion.JAVA_V4.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
verify(this.classVisitor).visitMethod(FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
verifyNoMoreInteractions(this.classVisitor);
verify(this.methodVisitor).visitLdcInsn(Type.getType(Object[].class).getInternalName().replace('/', '.'));
verify(this.methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC, Type.getType(Class.class).getInternalName(), "forName", Type.getType(Class.class.getDeclaredMethod("forName", String.class)).getDescriptor(), false);
verifyNoMoreInteractions(this.methodVisitor);
}
use of org.objectweb.asm.MethodVisitor in project byte-buddy by raphw.
the class RebaseImplementationTargetTest method testNonRebasedMethodIsInvokable.
@Test
public void testNonRebasedMethodIsInvokable() throws Exception {
when(invokableMethod.getDeclaringType()).thenReturn(instrumentedType);
when(invokableMethod.isSpecializableFor(instrumentedType)).thenReturn(true);
when(resolution.isRebased()).thenReturn(false);
when(resolution.getResolvedMethod()).thenReturn(invokableMethod);
Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(rebasedSignatureToken);
assertThat(specialMethodInvocation.isValid(), is(true));
assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) invokableMethod));
assertThat(specialMethodInvocation.getTypeDescription(), is(instrumentedType));
MethodVisitor methodVisitor = mock(MethodVisitor.class);
Implementation.Context implementationContext = mock(Implementation.Context.class);
StackManipulation.Size size = specialMethodInvocation.apply(methodVisitor, implementationContext);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESPECIAL, BAZ, FOO, QUX, false);
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
assertThat(size.getSizeImpact(), is(0));
assertThat(size.getMaximalSize(), is(0));
}
use of org.objectweb.asm.MethodVisitor in project byte-buddy by raphw.
the class RebaseImplementationTargetTest method testSuperTypeMethodIsInvokable.
@Test
public void testSuperTypeMethodIsInvokable() throws Exception {
when(invokableMethod.isSpecializableFor(rawSuperClass)).thenReturn(true);
Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(invokableToken);
assertThat(specialMethodInvocation.isValid(), is(true));
assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) invokableMethod));
assertThat(specialMethodInvocation.getTypeDescription(), is(rawSuperClass));
MethodVisitor methodVisitor = mock(MethodVisitor.class);
Implementation.Context implementationContext = mock(Implementation.Context.class);
StackManipulation.Size size = specialMethodInvocation.apply(methodVisitor, implementationContext);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESPECIAL, BAR, FOO, QUX, false);
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
assertThat(size.getSizeImpact(), is(0));
assertThat(size.getMaximalSize(), is(0));
}
use of org.objectweb.asm.MethodVisitor in project felix by apache.
the class ProxyGenerator method generateConstructor.
/**
* Generates the constructors. The constructor receives a temporal dependency
* and set the {@link ProxyGenerator#DEPENDENCY} field.
* @param cw the class writer
* @param className the generated class name.
*/
private static void generateConstructor(ClassWriter cw, String className) {
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", '(' + DEPENDENCY_DESC + ")V", null, null);
mv.visitCode();
// Load this
mv.visitVarInsn(ALOAD, 0);
// Dup
mv.visitInsn(DUP);
// Call super
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
// Load the argument
mv.visitVarInsn(ALOAD, 1);
// Assign the dependency field
mv.visitFieldInsn(PUTFIELD, className, DEPENDENCY, DEPENDENCY_DESC);
// Return void
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
Aggregations