Search in sources :

Example 81 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 TypePoolDefaultCacheTest method testCache.

@Test
public void testCache() throws Exception {
    TypePool typePool = TypePool.Default.ofClassPath();
    TypeDescription typeDescription = typePool.describe(Void.class.getName()).resolve();
    assertThat(typePool.describe(Void.class.getName()).resolve(), sameInstance(typeDescription));
    typePool.clear();
    assertThat(typePool.describe(Void.class.getName()).resolve(), not(sameInstance(typeDescription)));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 82 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 TypePoolDefaultComponentPoolStrategyTest method testForAnnotationProperty.

@Test
public void testForAnnotationProperty() throws Exception {
    TypePool typePool = mock(TypePool.class);
    TypeDescription typeDescription = mock(TypeDescription.class);
    when(typePool.describe(BAR)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
    when(typeDescription.getDeclaredMethods()).thenReturn(new MethodList.Explicit<MethodDescription.InDefinedShape>(methodDescription));
    when(methodDescription.getActualName()).thenReturn(FOO);
    TypeDescription.Generic returnType = mock(TypeDescription.Generic.class);
    TypeDescription rawReturnType = mock(TypeDescription.class);
    when(returnType.asErasure()).thenReturn(rawReturnType);
    when(methodDescription.getReturnType()).thenReturn(returnType);
    TypeDescription rawComponentType = mock(TypeDescription.class);
    when(rawReturnType.getComponentType()).thenReturn(rawComponentType);
    when(rawComponentType.getName()).thenReturn(QUX);
    assertThat(new TypePool.Default.ComponentTypeLocator.ForAnnotationProperty(typePool, BAR_DESCRIPTOR).bind(FOO).lookup(), is(QUX));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) MethodList(net.bytebuddy.description.method.MethodList) Test(org.junit.Test)

Example 83 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 TypePoolDefaultLazyTypeContainmentTest method testDeclaredInMethodGetTypeIsNotNull.

@Test
public void testDeclaredInMethodGetTypeIsNotNull() throws Exception {
    TypeDescription typeDescription = mock(TypeDescription.class);
    TypePool typePool = mock(TypePool.class);
    when(typePool.describe(FOO)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    assertThat(new TypePool.Default.LazyTypeDescription.TypeContainment.WithinMethod(FOO_INTERNAL, BAR, QUX).getEnclosingType(typePool), is(typeDescription));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 84 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 TypePoolDefaultLazyTypeContainmentTest method testDeclaredInMethodGetMethodIsNull.

@Test
@SuppressWarnings("unchecked")
public void testDeclaredInMethodGetMethodIsNull() throws Exception {
    MethodDescription methodDescription = mock(MethodDescription.class);
    when(methodDescription.getActualName()).thenReturn(BAR);
    when(methodDescription.getDescriptor()).thenReturn(QUX);
    TypeDescription typeDescription = mock(TypeDescription.class);
    TypePool typePool = mock(TypePool.class);
    when(typePool.describe(FOO)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    when(typeDescription.getDeclaredMethods()).thenReturn((MethodList) new MethodList.Explicit<MethodDescription>(methodDescription));
    assertThat(new TypePool.Default.LazyTypeDescription.TypeContainment.WithinMethod(FOO_INTERNAL, BAR, QUX).getEnclosingMethod(typePool), is(methodDescription));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 85 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 TypePoolDefaultLazyTypeContainmentTest method testDeclaredInTypeGetTypeIsNotNull.

@Test
public void testDeclaredInTypeGetTypeIsNotNull() throws Exception {
    TypePool typePool = mock(TypePool.class);
    TypeDescription typeDescription = mock(TypeDescription.class);
    when(typePool.describe(FOO)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    assertThat(new TypePool.Default.LazyTypeDescription.TypeContainment.WithinType(FOO_INTERNAL, false).getEnclosingType(typePool), is(typeDescription));
    assertThat(new TypePool.Default.LazyTypeDescription.TypeContainment.WithinType(FOO_INTERNAL, true).getEnclosingType(typePool), is(typeDescription));
}
Also used : 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