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());
}
}
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);
}
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]);
}
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]);
}
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();
}
Aggregations