Search in sources :

Example 1 with TypeVariableSource

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

the class AbstractTypeDescriptionGenericTest method testMethodTypeVariableWithExtensionIsRetained.

@Test
public void testMethodTypeVariableWithExtensionIsRetained() throws Exception {
    TypeDescription.Generic typeDescription = describeType(MemberVariable.class.getDeclaredField(FOO));
    assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(typeDescription.getTypeArguments().size(), is(2));
    assertThat(typeDescription.getTypeArguments().get(0).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(typeDescription.getTypeArguments().get(0).asErasure().represents(Number.class), is(true));
    assertThat(typeDescription.getTypeArguments().get(1).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(typeDescription.getTypeArguments().get(1).asErasure().represents(Integer.class), is(true));
    MethodDescription methodDescription = typeDescription.getDeclaredMethods().filter(named(QUX)).getOnly();
    assertThat(methodDescription.getReturnType().getSort(), is(TypeDefinition.Sort.VARIABLE));
    assertThat(methodDescription.getReturnType().getSymbol(), is("S"));
    assertThat(methodDescription.getReturnType().getTypeVariableSource(), is((TypeVariableSource) methodDescription.asDefined()));
    assertThat(methodDescription.getReturnType().getUpperBounds().size(), is(1));
    assertThat(methodDescription.getReturnType().getUpperBounds().getOnly().getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(methodDescription.getReturnType().getUpperBounds().getOnly().asErasure().represents(Number.class), is(true));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeVariableSource(net.bytebuddy.description.TypeVariableSource) Test(org.junit.Test)

Example 2 with TypeVariableSource

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

the class AbstractTypeDescriptionGenericTest method testNestedInnerType.

@Test
public void testNestedInnerType() throws Exception {
    TypeDescription.Generic foo = describeReturnType(NestedInnerType.InnerType.class.getDeclaredMethod(FOO));
    assertThat(foo.getSort(), is(TypeDefinition.Sort.VARIABLE));
    assertThat(foo.getSymbol(), is(T));
    assertThat(foo.getUpperBounds().size(), is(1));
    assertThat(foo.getUpperBounds().getOnly(), is(TypeDescription.Generic.OBJECT));
    assertThat(foo.getTypeVariableSource(), is((TypeVariableSource) new TypeDescription.ForLoadedType(NestedInnerType.class)));
    TypeDescription.Generic bar = describeReturnType(NestedInnerType.InnerType.class.getDeclaredMethod(BAR));
    assertThat(bar.getSort(), is(TypeDefinition.Sort.VARIABLE));
    assertThat(bar.getSymbol(), is(S));
    assertThat(bar.getUpperBounds().size(), is(1));
    assertThat(bar.getUpperBounds().getOnly(), is(foo));
    assertThat(bar.getTypeVariableSource(), is((TypeVariableSource) new TypeDescription.ForLoadedType(NestedInnerType.InnerType.class)));
    TypeDescription.Generic qux = describeReturnType(NestedInnerType.InnerType.class.getDeclaredMethod(QUX));
    assertThat(qux.getSort(), is(TypeDefinition.Sort.VARIABLE));
    assertThat(qux.getSymbol(), is(U));
    assertThat(qux.getUpperBounds().size(), is(1));
    assertThat(qux.getUpperBounds().getOnly(), is(bar));
    MethodDescription quxMethod = new MethodDescription.ForLoadedMethod(NestedInnerType.InnerType.class.getDeclaredMethod(QUX));
    assertThat(qux.getTypeVariableSource(), is((TypeVariableSource) quxMethod));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeVariableSource(net.bytebuddy.description.TypeVariableSource) Test(org.junit.Test)

Example 3 with TypeVariableSource

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

the class AbstractTypeDescriptionGenericTest method testShadowedMethodTypeVariableIsRetained.

@Test
public void testShadowedMethodTypeVariableIsRetained() throws Exception {
    TypeDescription.Generic typeDescription = describeType(MemberVariable.class.getDeclaredField(FOO));
    assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(typeDescription.getTypeArguments().size(), is(2));
    assertThat(typeDescription.getTypeArguments().get(0).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(typeDescription.getTypeArguments().get(0).asErasure().represents(Number.class), is(true));
    assertThat(typeDescription.getTypeArguments().get(1).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(typeDescription.getTypeArguments().get(1).asErasure().represents(Integer.class), is(true));
    MethodDescription methodDescription = typeDescription.getDeclaredMethods().filter(named(BAR)).getOnly();
    assertThat(methodDescription.getReturnType().getSort(), is(TypeDefinition.Sort.VARIABLE));
    assertThat(methodDescription.getReturnType().getSymbol(), is("T"));
    assertThat(methodDescription.getReturnType().getTypeVariableSource(), is((TypeVariableSource) methodDescription.asDefined()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeVariableSource(net.bytebuddy.description.TypeVariableSource) Test(org.junit.Test)

Example 4 with TypeVariableSource

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

the class AbstractTypeDescriptionGenericTest method testMethodTypeVariableIsRetained.

@Test
public void testMethodTypeVariableIsRetained() throws Exception {
    TypeDescription.Generic typeDescription = describeType(MemberVariable.class.getDeclaredField(FOO));
    assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(typeDescription.getTypeArguments().size(), is(2));
    assertThat(typeDescription.getTypeArguments().get(0).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(typeDescription.getTypeArguments().get(0).asErasure().represents(Number.class), is(true));
    assertThat(typeDescription.getTypeArguments().get(1).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(typeDescription.getTypeArguments().get(1).asErasure().represents(Integer.class), is(true));
    MethodDescription methodDescription = typeDescription.getDeclaredMethods().filter(named(FOO)).getOnly();
    assertThat(methodDescription.getReturnType().getSort(), is(TypeDefinition.Sort.VARIABLE));
    assertThat(methodDescription.getReturnType().getSymbol(), is("S"));
    assertThat(methodDescription.getReturnType().getTypeVariableSource(), is((TypeVariableSource) methodDescription.asDefined()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeVariableSource(net.bytebuddy.description.TypeVariableSource) Test(org.junit.Test)

Aggregations

TypeVariableSource (net.bytebuddy.description.TypeVariableSource)4 MethodDescription (net.bytebuddy.description.method.MethodDescription)4 Test (org.junit.Test)4