Search in sources :

Example 61 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class AbstractTypeDescriptionGenericTest method testMixedTypeVariables.

@Test
public void testMixedTypeVariables() throws Exception {
    MethodDescription methodDescription = describeInterfaceType(MixedTypeVariables.Inner.class, 0).getDeclaredMethods().getOnly();
    assertThat(methodDescription.getParameters().getOnly().getType().getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(methodDescription.getParameters().getOnly().getType().asRawType().represents(MixedTypeVariables.SampleType.class), is(true));
    assertThat(methodDescription.getParameters().getOnly().getType().getTypeArguments().get(0), is(methodDescription.getTypeVariables().getOnly()));
    assertThat(methodDescription.getParameters().getOnly().getType().getTypeArguments().get(1).represents(Void.class), is(true));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) Test(org.junit.Test)

Example 62 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class TypeConstantAdjustmentTest method testInstrumentationLegacyClassOtherType.

@Test
public void testInstrumentationLegacyClassOtherType() 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(FOO);
    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(FOO);
    verifyNoMoreInteractions(this.methodVisitor);
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) MethodList(net.bytebuddy.description.method.MethodList) ClassVisitor(org.objectweb.asm.ClassVisitor) TypePool(net.bytebuddy.pool.TypePool) FieldList(net.bytebuddy.description.field.FieldList) MethodVisitor(org.objectweb.asm.MethodVisitor) Test(org.junit.Test)

Example 63 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class TypeConstantAdjustmentTest method testInstrumentationLegacyClassFileObjectType.

@Test
public void testInstrumentationLegacyClassFileObjectType() 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).getClassName());
    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);
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) MethodList(net.bytebuddy.description.method.MethodList) ClassVisitor(org.objectweb.asm.ClassVisitor) FieldList(net.bytebuddy.description.field.FieldList) MethodVisitor(org.objectweb.asm.MethodVisitor) TypeDescription(net.bytebuddy.description.type.TypeDescription) TypePool(net.bytebuddy.pool.TypePool) Test(org.junit.Test)

Example 64 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class AdviceTest method testAdviceNativeMethodIsSkipped.

@Test
public void testAdviceNativeMethodIsSkipped() throws Exception {
    Advice.Dispatcher.Resolved.ForMethodEnter methodEnter = mock(Advice.Dispatcher.Resolved.ForMethodEnter.class);
    Advice.Dispatcher.Resolved.ForMethodExit methodExit = mock(Advice.Dispatcher.Resolved.ForMethodExit.class);
    MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
    when(methodDescription.isNative()).thenReturn(true);
    MethodVisitor methodVisitor = mock(MethodVisitor.class);
    assertThat(new Advice(methodEnter, methodExit).wrap(mock(TypeDescription.class), methodDescription, methodVisitor, mock(Implementation.Context.class), mock(TypePool.class), IGNORED, IGNORED), sameInstance(methodVisitor));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) Implementation(net.bytebuddy.implementation.Implementation) MethodVisitor(org.objectweb.asm.MethodVisitor) Test(org.junit.Test)

Example 65 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class InstrumentedTypeDefaultTest method testTypeVariableOutOfScopeIsErased.

@Test
public void testTypeVariableOutOfScopeIsErased() throws Exception {
    TypeDescription typeDescription = new InstrumentedType.Default("foo", Opcodes.ACC_PUBLIC, new TypeDescription.Generic.OfNonGenericType.ForLoadedType(AbstractOuter.ExtendedInner.class), Collections.<TypeVariableToken>emptyList(), Collections.<TypeDescription.Generic>emptyList(), Collections.<FieldDescription.Token>emptyList(), Collections.singletonList(new MethodDescription.Token("foo", Opcodes.ACC_BRIDGE, TypeDescription.Generic.VOID, Collections.<TypeDescription.Generic>emptyList())), Collections.<AnnotationDescription>emptyList(), TypeInitializer.None.INSTANCE, LoadedTypeInitializer.NoOp.INSTANCE, TypeDescription.UNDEFINED, MethodDescription.UNDEFINED, TypeDescription.UNDEFINED, Collections.<TypeDescription>emptyList(), false, false, false);
    MethodDescription methodDescription = typeDescription.getSuperClass().getSuperClass().getDeclaredMethods().filter(named(FOO)).getOnly();
    assertThat(methodDescription.getReturnType(), is(TypeDescription.Generic.OBJECT));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) FieldDescription(net.bytebuddy.description.field.FieldDescription) Test(org.junit.Test)

Aggregations

MethodDescription (net.bytebuddy.description.method.MethodDescription)105 Test (org.junit.Test)102 TypeDescription (net.bytebuddy.description.type.TypeDescription)62 MethodVisitor (org.objectweb.asm.MethodVisitor)15 StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)12 MethodList (net.bytebuddy.description.method.MethodList)9 Implementation (net.bytebuddy.implementation.Implementation)8 AbstractImplementationTargetTest (net.bytebuddy.implementation.AbstractImplementationTargetTest)6 Serializable (java.io.Serializable)4 TypeVariableSource (net.bytebuddy.description.TypeVariableSource)4 FieldList (net.bytebuddy.description.field.FieldList)4 TypePool (net.bytebuddy.pool.TypePool)4 ClassVisitor (org.objectweb.asm.ClassVisitor)4 ByteBuddy (net.bytebuddy.ByteBuddy)3 DynamicType (net.bytebuddy.dynamic.DynamicType)3 AnnotationDescription (net.bytebuddy.description.annotation.AnnotationDescription)2 LoadedTypeInitializer (net.bytebuddy.implementation.LoadedTypeInitializer)2 ByteCodeAppender (net.bytebuddy.implementation.bytecode.ByteCodeAppender)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1