Skip to content

Commit fe8107b

Browse files
Treiblesschorlectrueden
authored andcommitted
Add getExactSuperType and parameterizeRaw methods
1 parent ce0d2b1 commit fe8107b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/main/java/org/scijava/util/Types.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,19 @@ public static Class<?> erase(final Type type)
12301230
return GenericTypeReflector.erase(type);
12311231
}
12321232

1233+
/**
1234+
* See {@link GenericTypeReflector#getExactSuperType(Type, Class)}
1235+
*
1236+
* @param type
1237+
* @param searchClass
1238+
* @return
1239+
*/
1240+
public static Type getExactSuperType(final Type type,
1241+
final Class<?> searchClass)
1242+
{
1243+
return GenericTypeReflector.getExactSuperType(type, searchClass);
1244+
}
1245+
12331246
/**
12341247
* See {@link TypeUtils#unrollVariables(Map, Type, boolean)}
12351248
*
@@ -1244,6 +1257,23 @@ public static Type unrollVariables(Map<TypeVariable<?>, Type> typeArguments,
12441257
return TypeUtils.unrollVariables(typeArguments, type, followTypeVars);
12451258
}
12461259

1260+
/**
1261+
* Tries to parameterize the given raw type with its type parameters. If
1262+
* type is not raw, it will be returned. Otherwise, a parameterized type
1263+
* containing the type variables of the specified is returned.
1264+
*
1265+
* @param rawType
1266+
* the raw type to parameterize
1267+
* @return either the input of not raw, or a parameterized type
1268+
*/
1269+
public static Type parameterizeRaw(Class<?> rawType) {
1270+
TypeVariable<?>[] typeParams = rawType.getTypeParameters();
1271+
if (typeParams.length == 0) {
1272+
return rawType;
1273+
}
1274+
return Types.parameterize(rawType, typeParams);
1275+
}
1276+
12471277
// -- Helper methods --
12481278

12491279
private static IllegalArgumentException iae(final String... s) {

0 commit comments

Comments
 (0)