Search in sources :

Example 26 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class AdviceTest method testAdviceAbstractMethodIsSkipped.

@Test
public void testAdviceAbstractMethodIsSkipped() 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.isAbstract()).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 27 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class JavaConstantMethodHandleTest method testAbstractMethodNotSpecial.

@Test(expected = IllegalArgumentException.class)
public void testAbstractMethodNotSpecial() throws Exception {
    MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
    TypeDescription typeDescription = mock(TypeDescription.class);
    when(methodDescription.isAbstract()).thenReturn(true);
    when(methodDescription.isSpecializableFor(typeDescription)).thenReturn(true);
    JavaConstant.MethodHandle.ofSpecial(methodDescription, typeDescription);
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 28 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class TypeProxyCreationTest method testAllLegalNotIgnoreFinalizer.

@Test
public void testAllLegalNotIgnoreFinalizer() throws Exception {
    when(implementationTarget.getInstrumentedType()).thenReturn(foo);
    when(invocationFactory.invoke(eq(implementationTarget), eq(foo), any(MethodDescription.class))).thenReturn(specialMethodInvocation);
    when(specialMethodInvocation.isValid()).thenReturn(true);
    when(specialMethodInvocation.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
    when(methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT)).thenReturn(proxyMethod);
    TypeDescription dynamicType = new TypeProxy(foo, implementationTarget, invocationFactory, false, false).make(BAR, ClassFileVersion.ofThisVm(), methodAccessorFactory).getTypeDescription();
    assertThat(dynamicType.getModifiers(), is(modifiers));
    assertThat(dynamicType.getSuperClass().asErasure(), is(foo));
    assertThat(dynamicType.getInterfaces(), is((TypeList.Generic) new TypeList.Generic.Empty()));
    assertThat(dynamicType.getName(), is(BAR));
    assertThat(dynamicType.getDeclaredMethods().size(), is(2));
    assertThat(dynamicType.isAssignableTo(Serializable.class), is(false));
    verify(methodAccessorFactory, times(fooMethods.size() + 1)).registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT);
    for (MethodDescription methodDescription : fooMethods) {
        verify(invocationFactory).invoke(implementationTarget, foo, methodDescription);
    }
    verify(invocationFactory).invoke(implementationTarget, foo, new MethodDescription.ForLoadedMethod(Object.class.getDeclaredMethod("finalize")));
    verifyNoMoreInteractions(invocationFactory);
    verify(specialMethodInvocation, times(fooMethods.size() + 1)).isValid();
    verifyNoMoreInteractions(specialMethodInvocation);
}
Also used : Serializable(java.io.Serializable) MethodDescription(net.bytebuddy.description.method.MethodDescription) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) MethodVisitor(org.objectweb.asm.MethodVisitor) Test(org.junit.Test)

Example 29 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class TypeProxyCreationTest method testAllIllegal.

@Test
public void testAllIllegal() throws Exception {
    when(implementationTarget.getInstrumentedType()).thenReturn(foo);
    when(invocationFactory.invoke(eq(implementationTarget), eq(foo), any(MethodDescription.class))).thenReturn(specialMethodInvocation);
    TypeDescription dynamicType = new TypeProxy(foo, implementationTarget, invocationFactory, true, false).make(BAR, ClassFileVersion.ofThisVm(), methodAccessorFactory).getTypeDescription();
    assertThat(dynamicType.getModifiers(), is(modifiers));
    assertThat(dynamicType.getSuperClass().asErasure(), is(foo));
    assertThat(dynamicType.getInterfaces(), is((TypeList.Generic) new TypeList.Generic.Empty()));
    assertThat(dynamicType.getName(), is(BAR));
    assertThat(dynamicType.getDeclaredMethods().size(), is(2));
    assertThat(dynamicType.isAssignableTo(Serializable.class), is(false));
    verifyZeroInteractions(methodAccessorFactory);
    for (MethodDescription methodDescription : fooMethods) {
        verify(invocationFactory).invoke(implementationTarget, foo, methodDescription);
    }
    verifyNoMoreInteractions(invocationFactory);
    verify(specialMethodInvocation, times(fooMethods.size())).isValid();
    verifyNoMoreInteractions(specialMethodInvocation);
}
Also used : Serializable(java.io.Serializable) MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 30 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class TypeProxyCreationTest method testAllLegal.

@Test
public void testAllLegal() throws Exception {
    when(implementationTarget.getInstrumentedType()).thenReturn(foo);
    when(invocationFactory.invoke(eq(implementationTarget), eq(foo), any(MethodDescription.class))).thenReturn(specialMethodInvocation);
    when(specialMethodInvocation.isValid()).thenReturn(true);
    when(specialMethodInvocation.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
    when(methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT)).thenReturn(proxyMethod);
    TypeDescription dynamicType = new TypeProxy(foo, implementationTarget, invocationFactory, true, false).make(BAR, ClassFileVersion.ofThisVm(), methodAccessorFactory).getTypeDescription();
    assertThat(dynamicType.getModifiers(), is(modifiers));
    assertThat(dynamicType.getSuperClass().asErasure(), is(foo));
    assertThat(dynamicType.getInterfaces(), is((TypeList.Generic) new TypeList.Generic.Empty()));
    assertThat(dynamicType.getName(), is(BAR));
    assertThat(dynamicType.getDeclaredMethods().size(), is(2));
    assertThat(dynamicType.isAssignableTo(Serializable.class), is(false));
    verify(methodAccessorFactory, times(fooMethods.size())).registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT);
    for (MethodDescription methodDescription : fooMethods) {
        verify(invocationFactory).invoke(implementationTarget, foo, methodDescription);
    }
    verifyNoMoreInteractions(invocationFactory);
    verify(specialMethodInvocation, times(fooMethods.size())).isValid();
    verifyNoMoreInteractions(specialMethodInvocation);
}
Also used : Serializable(java.io.Serializable) MethodDescription(net.bytebuddy.description.method.MethodDescription) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) MethodVisitor(org.objectweb.asm.MethodVisitor) 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