Search in sources :

Example 46 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 ElementMatchersTest method testAnyMethodDefinedShape.

@Test
public void testAnyMethodDefinedShape() throws Exception {
    Method method = GenericMethodType.class.getDeclaredMethod("foo", Exception.class);
    MethodDescription methodDescription = new TypeDescription.ForLoadedType(GenericMethodType.Inner.class).getInterfaces().getOnly().getDeclaredMethods().filter(named(FOO)).getOnly();
    assertThat(ElementMatchers.anyOf(method).matches(methodDescription), is(true));
    assertThat(ElementMatchers.definedMethod(ElementMatchers.anyOf(methodDescription.asDefined())).matches(methodDescription), is(true));
    assertThat(ElementMatchers.anyOf(methodDescription.asDefined()).matches(methodDescription.asDefined()), is(true));
    assertThat(ElementMatchers.anyOf(methodDescription.asDefined()).matches(methodDescription), is(false));
    assertThat(ElementMatchers.anyOf(methodDescription).matches(methodDescription.asDefined()), is(false));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 47 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 ElementMatchersTest method testIsNative.

@Test
public void testIsNative() throws Exception {
    MethodDescription methodDescription = mock(MethodDescription.class);
    when(methodDescription.getModifiers()).thenReturn(Opcodes.ACC_NATIVE);
    assertThat(ElementMatchers.isNative().matches(methodDescription), is(true));
    assertThat(ElementMatchers.isNative().matches(mock(MethodDescription.class)), is(false));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) Test(org.junit.Test)

Example 48 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 ElementMatchersTest method testNoneOfMethodDefinedShape.

@Test
public void testNoneOfMethodDefinedShape() throws Exception {
    Method method = GenericMethodType.class.getDeclaredMethod("foo", Exception.class);
    MethodDescription methodDescription = new TypeDescription.ForLoadedType(GenericMethodType.Inner.class).getInterfaces().getOnly().getDeclaredMethods().filter(named(FOO)).getOnly();
    assertThat(ElementMatchers.noneOf(method).matches(methodDescription), is(false));
    assertThat(ElementMatchers.definedMethod(ElementMatchers.noneOf(methodDescription.asDefined())).matches(methodDescription), is(false));
    assertThat(ElementMatchers.noneOf(methodDescription.asDefined()).matches(methodDescription.asDefined()), is(false));
    assertThat(ElementMatchers.noneOf(methodDescription.asDefined()).matches(methodDescription), is(true));
    assertThat(ElementMatchers.noneOf(methodDescription).matches(methodDescription.asDefined()), is(true));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 49 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 ElementMatchersTest method testNoneOfConstructorDefinedShape.

@Test
public void testNoneOfConstructorDefinedShape() throws Exception {
    Constructor<?> constructor = GenericConstructorType.class.getDeclaredConstructor(Exception.class);
    MethodDescription methodDescription = new TypeDescription.ForLoadedType(GenericConstructorType.Inner.class).getSuperClass().getDeclaredMethods().filter(isConstructor()).getOnly();
    assertThat(ElementMatchers.noneOf(constructor).matches(methodDescription), is(false));
    assertThat(ElementMatchers.definedMethod(ElementMatchers.noneOf(methodDescription.asDefined())).matches(methodDescription), is(false));
    assertThat(ElementMatchers.noneOf(methodDescription.asDefined()).matches(methodDescription.asDefined()), is(false));
    assertThat(ElementMatchers.noneOf(methodDescription.asDefined()).matches(methodDescription), is(true));
    assertThat(ElementMatchers.noneOf(methodDescription).matches(methodDescription.asDefined()), is(true));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) Test(org.junit.Test)

Example 50 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 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));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Implementation(net.bytebuddy.implementation.Implementation) MethodVisitor(org.objectweb.asm.MethodVisitor) AbstractImplementationTargetTest(net.bytebuddy.implementation.AbstractImplementationTargetTest) 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