Skip to content

Commit ce0d2b1

Browse files
Treiblesschorlectrueden
authored andcommitted
Add second version of unroll
This version allows to specify if type vars should be followed.
1 parent 4573fb8 commit ce0d2b1

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

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

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

1233+
/**
1234+
* See {@link TypeUtils#unrollVariables(Map, Type, boolean)}
1235+
*
1236+
* @param typeArguments
1237+
* @param type
1238+
* @param followTypeVars
1239+
* @return
1240+
*/
1241+
public static Type unrollVariables(Map<TypeVariable<?>, Type> typeArguments,
1242+
final Type type, boolean followTypeVars)
1243+
{
1244+
return TypeUtils.unrollVariables(typeArguments, type, followTypeVars);
1245+
}
1246+
12331247
// -- Helper methods --
12341248

12351249
private static IllegalArgumentException iae(final String... s) {
@@ -2804,13 +2818,36 @@ public static Type getArrayComponentType(final Type type) {
28042818
*/
28052819
public static Type unrollVariables(Map<TypeVariable<?>, Type> typeArguments,
28062820
final Type type)
2821+
{
2822+
return unrollVariables(typeArguments, type, true);
2823+
}
2824+
2825+
/**
2826+
* Get a type representing {@code type} with variable assignments
2827+
* "unrolled."
2828+
*
2829+
* @param typeArguments as from
2830+
* {@link TypeUtils#getTypeArguments(Type, Class)}
2831+
* @param type the type to unroll variable assignments for
2832+
* @param followTypeVars whether a {@link TypeVariable} should be recursively followed
2833+
* if it maps to another {@link TypeVariable}, or if it should be just replaced
2834+
* by the mapping
2835+
* @return Type
2836+
* @since 3.2
2837+
*/
2838+
public static Type unrollVariables(Map<TypeVariable<?>, Type> typeArguments,
2839+
final Type type, boolean followTypeVars)
28072840
{
28082841
if (typeArguments == null) {
28092842
typeArguments = Collections.<TypeVariable<?>, Type> emptyMap();
28102843
}
28112844
if (containsTypeVariables(type)) {
28122845
if (type instanceof TypeVariable) {
2813-
return unrollVariables(typeArguments, typeArguments.get(type));
2846+
if (followTypeVars) {
2847+
return unrollVariables(typeArguments, typeArguments.get(type));
2848+
} else {
2849+
return typeArguments.get(type);
2850+
}
28142851
}
28152852
if (type instanceof ParameterizedType) {
28162853
final ParameterizedType p = (ParameterizedType) type;

0 commit comments

Comments
 (0)