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

Method toGenericType

output/java_guava/1.4.18/TypeToken.java:1087–1109  ·  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

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