MCPcopy Create free account
hub / github.com/antlr/codebuff / toGenericType

Method toGenericType

output/java_guava/1.4.19/TypeToken.java:1088–1111  ·  view source on GitHub ↗

Returns the type token representing the generic type declaration of cls. For example: TypeToken.getGenericType(Iterable.class) returns Iterable . If cls isn't parameterized and isn't a generic array, the type token of the class is returned.

(Class<T> cls)

Source from the content-addressed store, hash-verified

1086 */
1087
1088 @VisibleForTesting
1089 static <T> TypeToken<? extends T> toGenericType(Class<T> cls) {
1090 if (cls.isArray()) {
1091 Type arrayOfGenericType = Types.newArrayType(
1092 // If we are passed with int[].class, don't turn it to GenericArrayType
1093 toGenericType(cls.getComponentType()).runtimeType);
1094 @SuppressWarnings("unchecked") // array is covariant
1095 TypeToken<? extends T> result = (TypeToken<? extends T>) of(arrayOfGenericType);
1096 return result;
1097 }
1098 TypeVariable<Class<T>>[] typeParams = cls.getTypeParameters();
1099 Type ownerType =
1100 cls.isMemberClass() && !Modifier.isStatic(cls.getModifiers())
1101 ? toGenericType(cls.getEnclosingClass()).runtimeType
1102 : null;
1103 if ((typeParams.length > 0)
1104 || ((ownerType != null) && ownerType != cls.getEnclosingClass())) {
1105 @SuppressWarnings("unchecked") // Like, it's Iterable<T> for Iterable.class
1106 TypeToken<? extends T> type = (TypeToken<? extends T>) of(Types.newParameterizedTypeWithOwner(ownerType, cls, typeParams));
1107 return type;
1108 } else {
1109 return of(cls);
1110 }
1111 }
1112
1113
1114 private TypeToken<? super T> getSupertypeFromUpperBounds(Class<? super T> supertype, Type[] upperBounds) {

Callers 2

getSupertypeMethod · 0.95

Calls 8

newArrayTypeMethod · 0.95
ofMethod · 0.95
isArrayMethod · 0.45
getComponentTypeMethod · 0.45
getTypeParametersMethod · 0.45
isStaticMethod · 0.45
getModifiersMethod · 0.45

Tested by

no test coverage detected