Search in sources :

Example 36 with TypeDescription

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

the class TargetMethodAnnotationDrivenBinderTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    when(assignmentBinding.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
    when(assigner.assign(any(TypeDescription.Generic.class), any(TypeDescription.Generic.class), any(Assigner.Typing.class))).thenReturn(assignmentBinding);
    when(methodInvoker.invoke(any(MethodDescription.class))).thenReturn(methodInvocation);
    when(methodInvocation.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
    when(assignmentBinding.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
    TypeDescription declaringType = mock(TypeDescription.class);
    when(declaringType.getInternalName()).thenReturn(FOO);
    when(declaringType.isInterface()).thenReturn(false);
    when(targetMethod.getInternalName()).thenReturn(BAR);
    when(targetMethod.isStatic()).thenReturn(true);
    when(targetMethod.getDeclaringType()).thenReturn(declaringType);
    when(targetMethod.getDescriptor()).thenReturn(BAZ);
    when(firstParameter.getDeclaringMethod()).thenReturn(targetMethod);
    when(firstParameter.getIndex()).thenReturn(0);
    when(secondParameter.getDeclaringMethod()).thenReturn(targetMethod);
    when(secondParameter.getIndex()).thenReturn(1);
    when(targetMethod.getParameters()).thenReturn((ParameterList) new ParameterList.Explicit<ParameterDescription>(firstParameter, secondParameter));
    when(firstPseudoAnnotation.getAnnotationType()).thenReturn(new TypeDescription.ForLoadedType(FirstPseudoAnnotation.class));
    when(firstPseudoAnnotation.prepare(FirstPseudoAnnotation.class)).thenReturn(firstPseudoAnnotation);
    when(secondPseudoAnnotation.getAnnotationType()).thenReturn(new TypeDescription.ForLoadedType(SecondPseudoAnnotation.class));
    when(secondPseudoAnnotation.prepare(SecondPseudoAnnotation.class)).thenReturn(secondPseudoAnnotation);
    when(sourceTypeDescription.getStackSize()).thenReturn(StackSize.ZERO);
    when(targetTypeDescription.getStackSize()).thenReturn(StackSize.ZERO);
    when(sourceMethod.getReturnType()).thenReturn(sourceTypeDescription);
    when(targetMethod.getReturnType()).thenReturn(targetTypeDescription);
    when(terminationHandler.resolve(assigner, typing, sourceMethod, targetMethod)).thenReturn(termination);
    when(termination.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
    when(implementationTarget.getInstrumentedType()).thenReturn(instrumentedType);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) MethodVisitor(org.objectweb.asm.MethodVisitor) Before(org.junit.Before)

Example 37 with TypeDescription

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

the class MethodBindingBuilderTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    when(methodDescription.getParameters()).thenReturn((ParameterList) methodParameterList);
    when(methodDescription.isStatic()).thenReturn(false);
    TypeDescription declaringType = mock(TypeDescription.class);
    when(methodDescription.getDeclaringType()).thenReturn(declaringType);
    when(declaringType.getInternalName()).thenReturn(FOO);
    when(declaringType.isInterface()).thenReturn(false);
    when(methodDescription.getInternalName()).thenReturn(BAR);
    when(methodDescription.getDescriptor()).thenReturn(BAZ);
    when(methodDescription.getStackSize()).thenReturn(0);
    when(methodDescription.getReturnType()).thenReturn(returnType);
    when(returnType.getStackSize()).thenReturn(StackSize.ZERO);
    when(legalStackManipulation.isValid()).thenReturn(true);
    when(illegalStackManipulation.isValid()).thenReturn(false);
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Before(org.junit.Before)

Example 38 with TypeDescription

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

the class AllArgumentsBinderTest method testNonArrayTypeBinding.

@Test(expected = IllegalStateException.class)
public void testNonArrayTypeBinding() throws Exception {
    when(target.getIndex()).thenReturn(0);
    TypeDescription.Generic targetType = mock(TypeDescription.Generic.class);
    TypeDescription rawTargetType = mock(TypeDescription.class);
    when(targetType.asErasure()).thenReturn(rawTargetType);
    when(targetType.isArray()).thenReturn(false);
    when(target.getType()).thenReturn(targetType);
    AllArguments.Binder.INSTANCE.bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC);
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 39 with TypeDescription

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

the class FieldProxyBinderTest method testIllegalType.

@Test(expected = IllegalStateException.class)
public void testIllegalType() throws Exception {
    doReturn(Foo.class).when(annotation).declaringType();
    when(annotation.value()).thenReturn(FOO);
    TypeDescription targetType = mock(TypeDescription.class);
    TypeDescription.Generic genericTargetType = mock(TypeDescription.Generic.class);
    when(genericTargetType.asErasure()).thenReturn(targetType);
    when(target.getType()).thenReturn(genericTargetType);
    when(instrumentedType.isAssignableTo(new TypeDescription.ForLoadedType(Foo.class))).thenReturn(true);
    new FieldProxy.Binder(getterMethod, setterMethod).bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC);
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 40 with TypeDescription

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

the class MorphBinderTest method testObjectProperties.

@Test
@SuppressWarnings("unchecked")
public void testObjectProperties() throws Exception {
    ObjectPropertyAssertion.of(Morph.Binder.class).apply();
    ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.class).apply();
    ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.MethodCall.class).apply();
    ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.MethodCall.Appender.class).refine(new ObjectPropertyAssertion.Refinement<Implementation.Target>() {

        @Override
        public void apply(Implementation.Target mock) {
            when(mock.getInstrumentedType()).thenReturn(mock(TypeDescription.class));
        }
    }).apply();
    ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.StaticFieldConstructor.class).apply();
    ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.InstanceFieldConstructor.class).apply();
    ObjectPropertyAssertion.of(Morph.Binder.RedirectionProxy.InstanceFieldConstructor.Appender.class).refine(new ObjectPropertyAssertion.Refinement<Implementation.Target>() {

        @Override
        public void apply(Implementation.Target mock) {
            TypeDescription typeDescription = mock(TypeDescription.class);
            FieldList<?> fieldList = mock(FieldList.class);
            FieldList<?> filteredFieldList = mock(FieldList.class);
            when(fieldList.filter(named(Morph.Binder.RedirectionProxy.FIELD_NAME))).thenReturn((FieldList) filteredFieldList);
            when(filteredFieldList.getOnly()).thenReturn(mock(FieldDescription.class));
            when(typeDescription.getDeclaredFields()).thenReturn((FieldList) fieldList);
            when(mock.getInstrumentedType()).thenReturn(typeDescription);
        }
    }).apply();
    ObjectPropertyAssertion.of(Morph.Binder.DefaultMethodLocator.Implicit.class).apply();
    ObjectPropertyAssertion.of(Morph.Binder.DefaultMethodLocator.Explicit.class).apply();
}
Also used : Implementation(net.bytebuddy.implementation.Implementation) FieldDescription(net.bytebuddy.description.field.FieldDescription) MethodDelegationBinder(net.bytebuddy.implementation.bind.MethodDelegationBinder) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Aggregations

TypeDescription (net.bytebuddy.description.type.TypeDescription)178 Test (org.junit.Test)155 MethodDescription (net.bytebuddy.description.method.MethodDescription)75 ByteBuddy (net.bytebuddy.ByteBuddy)25 DynamicType (net.bytebuddy.dynamic.DynamicType)25 StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)17 ClassFileLocator (net.bytebuddy.dynamic.ClassFileLocator)10 AnnotationList (net.bytebuddy.description.annotation.AnnotationList)9 AbstractTypeDescriptionTest (net.bytebuddy.description.type.AbstractTypeDescriptionTest)9 Map (java.util.Map)8 MethodList (net.bytebuddy.description.method.MethodList)8 Field (java.lang.reflect.Field)7 List (java.util.List)5 FieldDescription (net.bytebuddy.description.field.FieldDescription)5 LoadedTypeInitializer (net.bytebuddy.implementation.LoadedTypeInitializer)5 Serializable (java.io.Serializable)4 URLClassLoader (java.net.URLClassLoader)4 TypeList (net.bytebuddy.description.type.TypeList)4 Before (org.junit.Before)4 MethodVisitor (org.objectweb.asm.MethodVisitor)4