Search in sources :

Example 91 with WildcardType

use of java.lang.reflect.WildcardType in project mongo-java-driver by mongodb.

the class TypeData method getNestedTypeData.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T> void getNestedTypeData(final TypeData.Builder<T> builder, final Type type) {
    if (type instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType) type;
        TypeData.Builder paramBuilder = TypeData.builder((Class) pType.getRawType());
        for (Type argType : pType.getActualTypeArguments()) {
            getNestedTypeData(paramBuilder, argType);
        }
        builder.addTypeParameter(paramBuilder.build());
    } else if (type instanceof WildcardType) {
        builder.addTypeParameter(TypeData.builder((Class) ((WildcardType) type).getUpperBounds()[0]).build());
    } else if (type instanceof TypeVariable) {
        builder.addTypeParameter(TypeData.builder(Object.class).build());
    } else if (type instanceof Class) {
        builder.addTypeParameter(TypeData.builder((Class) type).build());
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) TypeVariable(java.lang.reflect.TypeVariable)

Example 92 with WildcardType

use of java.lang.reflect.WildcardType in project j2objc by google.

the class WildcardTypeTest method checkUpperBoundedParameter.

private void checkUpperBoundedParameter(Method method) {
    assertLenghtOne(method.getGenericParameterTypes());
    Type genericParameterType = method.getGenericParameterTypes()[0];
    assertInstanceOf(ParameterizedType.class, genericParameterType);
    ParameterizedType parameterizedType = (ParameterizedType) genericParameterType;
    Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
    assertLenghtOne(actualTypeArguments);
    assertInstanceOf(WildcardType.class, actualTypeArguments[0]);
    WildcardType wildcardType = (WildcardType) actualTypeArguments[0];
    assertEquals("? extends T", wildcardType.toString());
    assertEquals("? extends T", wildcardType.getTypeName());
    assertLenghtZero(wildcardType.getLowerBounds());
    Type[] upperBounds = wildcardType.getUpperBounds();
    assertLenghtOne(upperBounds);
    Type upperBound = upperBounds[0];
    assertEquals(getTypeParameter(method), upperBound);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) WildcardType(java.lang.reflect.WildcardType)

Example 93 with WildcardType

use of java.lang.reflect.WildcardType in project guava by hceylan.

the class TypeTokenResolutionTest method testWithGenericLowerBoundInWildcard.

public void testWithGenericLowerBoundInWildcard() throws Exception {
    WildcardType wildcardType = (WildcardType) new WithGenericBound<String>() {
    }.getTargetType("withWildcardLowerBound");
    assertEquals(String.class, wildcardType.getLowerBounds()[0]);
}
Also used : WildcardType(java.lang.reflect.WildcardType)

Example 94 with WildcardType

use of java.lang.reflect.WildcardType in project guava by hceylan.

the class TypeTokenResolutionTest method testWithGenericUpperBoundInWildcard.

public void testWithGenericUpperBoundInWildcard() throws Exception {
    WildcardType wildcardType = (WildcardType) new WithGenericBound<String>() {
    }.getTargetType("withWildcardUpperBound");
    assertEquals(String.class, wildcardType.getUpperBounds()[0]);
}
Also used : WildcardType(java.lang.reflect.WildcardType)

Example 95 with WildcardType

use of java.lang.reflect.WildcardType in project guava by hceylan.

the class TypesTest method testNewWildcardType.

public void testNewWildcardType() throws Exception {
    WildcardType noBoundJvmType = WithWildcardType.getWildcardType("withoutBound");
    WildcardType objectBoundJvmType = WithWildcardType.getWildcardType("withObjectBound");
    WildcardType upperBoundJvmType = WithWildcardType.getWildcardType("withUpperBound");
    WildcardType lowerBoundJvmType = WithWildcardType.getWildcardType("withLowerBound");
    WildcardType objectBound = Types.subtypeOf(Object.class);
    WildcardType upperBound = Types.subtypeOf(int[][].class);
    WildcardType lowerBound = Types.supertypeOf(String[][].class);
    assertEqualWildcardType(noBoundJvmType, objectBound);
    assertEqualWildcardType(objectBoundJvmType, objectBound);
    assertEqualWildcardType(upperBoundJvmType, upperBound);
    assertEqualWildcardType(lowerBoundJvmType, lowerBound);
    new EqualsTester().addEqualityGroup(noBoundJvmType, objectBoundJvmType, objectBound).addEqualityGroup(upperBoundJvmType, upperBound).addEqualityGroup(lowerBoundJvmType, lowerBound).testEquals();
}
Also used : WildcardType(java.lang.reflect.WildcardType) EqualsTester(com.google.common.testing.EqualsTester)

Aggregations

WildcardType (java.lang.reflect.WildcardType)236 ParameterizedType (java.lang.reflect.ParameterizedType)208 Type (java.lang.reflect.Type)180 GenericArrayType (java.lang.reflect.GenericArrayType)160 TypeVariable (java.lang.reflect.TypeVariable)134 Test (org.junit.Test)24 GenericClass (org.evosuite.utils.generic.GenericClass)14 Method (java.lang.reflect.Method)10 WildcardTypeImpl (org.evosuite.utils.generic.WildcardTypeImpl)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)8 Test (org.junit.jupiter.api.Test)8 CaptureType (com.googlecode.gentyref.CaptureType)7 JSONException (com.alibaba.fastjson.JSONException)5 JSONType (com.alibaba.fastjson.annotation.JSONType)5 CatalogType (org.spongepowered.api.CatalogType)4 GenericDeclaration (java.lang.reflect.GenericDeclaration)3 HashSet (java.util.HashSet)3 List (java.util.List)3 MediaType (javax.ws.rs.core.MediaType)3