|
29 | 29 | * #L%
|
30 | 30 | */
|
31 | 31 |
|
32 |
| -package org.scijava.util; |
33 |
| - |
34 |
| -import java.io.File; |
35 |
| - |
36 | 32 | // Portions of this class were adapted from the
|
37 | 33 | // org.apache.commons.lang3.reflect.TypeUtils and
|
38 | 34 | // org.apache.commons.lang3.Validate classes of
|
|
46 | 42 | //
|
47 | 43 | // See NOTICE.txt for further details on third-party licenses.
|
48 | 44 |
|
| 45 | +package org.scijava.util; |
| 46 | + |
| 47 | +import java.io.File; |
49 | 48 | import java.io.Serializable;
|
50 | 49 | import java.lang.reflect.Array;
|
51 | 50 | import java.lang.reflect.Field;
|
|
70 | 69 | import java.util.Objects;
|
71 | 70 | import java.util.Set;
|
72 | 71 |
|
73 |
| -import org.scijava.util.FileUtils; |
74 |
| - |
75 | 72 | /**
|
76 | 73 | * Utility class for working with generic types, fields and methods.
|
77 | 74 | * <p>
|
|
86 | 83 | * </ul>
|
87 | 84 | *
|
88 | 85 | * @author Curtis Rueden
|
| 86 | + * @author Gabe Selzer |
89 | 87 | */
|
90 | 88 | public final class Types {
|
91 | 89 |
|
@@ -791,22 +789,22 @@ public static <T> T enumValue(final String name, final Class<T> dest) {
|
791 | 789 | public static ParameterizedType parameterize(final Class<?> rawType,
|
792 | 790 | final Type... typeArgs)
|
793 | 791 | {
|
794 |
| - return parameterize(rawType, rawType.getDeclaringClass(), typeArgs); |
| 792 | + return parameterizeWithOwner(null, rawType, typeArgs); |
795 | 793 | }
|
796 | 794 |
|
797 | 795 | /**
|
798 | 796 | * Creates a new {@link ParameterizedType} of the given class together with
|
799 | 797 | * the specified type arguments.
|
800 | 798 | *
|
801 |
| - * @param rawType The class of the {@link ParameterizedType}. |
802 | 799 | * @param ownerType The owner type of the parameterized class.
|
| 800 | + * @param rawType The class of the {@link ParameterizedType}. |
803 | 801 | * @param typeArgs The type arguments to use in parameterizing it.
|
804 | 802 | * @return The newly created {@link ParameterizedType}.
|
805 | 803 | */
|
806 |
| - public static ParameterizedType parameterize(final Class<?> rawType, |
807 |
| - final Type ownerType, final Type... typeArgs) |
| 804 | + public static ParameterizedType parameterizeWithOwner(final Type ownerType, |
| 805 | + final Class<?> rawType, final Type... typeArgs) |
808 | 806 | {
|
809 |
| - return new TypeUtils.ParameterizedTypeImpl(rawType, ownerType, typeArgs); |
| 807 | + return TypeUtils.parameterizeWithOwner(ownerType, rawType, typeArgs); |
810 | 808 | }
|
811 | 809 |
|
812 | 810 | /**
|
@@ -1416,7 +1414,7 @@ private static boolean isAssignable(final Type type,
|
1416 | 1414 | // parameters must either be absent from the subject type, within
|
1417 | 1415 | // the bounds of the wildcard type, or be an exact match to the
|
1418 | 1416 | // parameters of the target type.
|
1419 |
| - if (fromTypeArg != null && !toTypeArg.equals(fromTypeArg) && |
| 1417 | + if (fromTypeArg != null && !fromTypeArg.equals(toTypeArg) && |
1420 | 1418 | !(toTypeArg instanceof WildcardType && isAssignable(fromTypeArg,
|
1421 | 1419 | toTypeArg, typeVarAssigns)))
|
1422 | 1420 | {
|
@@ -3206,7 +3204,7 @@ else if (isMissingTypeParameters(clazz)) {
|
3206 | 3204 | Arrays.fill(arguments, UNBOUND_WILDCARD);
|
3207 | 3205 | final Type owner = clazz.getDeclaringClass() == null ? null
|
3208 | 3206 | : addWildcardParameters(clazz.getDeclaringClass());
|
3209 |
| - return parameterize(clazz, owner, arguments); |
| 3207 | + return parameterizeWithOwner(owner, clazz, arguments); |
3210 | 3208 | }
|
3211 | 3209 | else {
|
3212 | 3210 | return clazz;
|
@@ -3584,9 +3582,9 @@ public static Type capture(final Type type) {
|
3584 | 3582 | for (final CaptureTypeImpl captured : toInit) {
|
3585 | 3583 | captured.init(varMap);
|
3586 | 3584 | }
|
3587 |
| - final Type ownerType = (pType.getOwnerType() == null) ? null : capture( |
| 3585 | + final Type ownerType = pType.getOwnerType() == null ? null : capture( |
3588 | 3586 | pType.getOwnerType());
|
3589 |
| - return parameterize(clazz, ownerType, capturedArguments); |
| 3587 | + return parameterizeWithOwner(ownerType, clazz, capturedArguments); |
3590 | 3588 | }
|
3591 | 3589 | return type;
|
3592 | 3590 | }
|
@@ -3764,9 +3762,10 @@ else if (type instanceof TypeVariable) {
|
3764 | 3762 | }
|
3765 | 3763 | else if (type instanceof ParameterizedType) {
|
3766 | 3764 | final ParameterizedType pType = (ParameterizedType) type;
|
3767 |
| - return parameterize((Class<?>) pType.getRawType(), pType |
3768 |
| - .getOwnerType() == null ? pType.getOwnerType() : map(pType |
3769 |
| - .getOwnerType()), map(pType.getActualTypeArguments())); |
| 3765 | + final Type ownerType = pType.getOwnerType() == null ? // |
| 3766 | + pType.getOwnerType() : map(pType.getOwnerType()); |
| 3767 | + return parameterizeWithOwner(ownerType, (Class<?>) pType.getRawType(), |
| 3768 | + map(pType.getActualTypeArguments())); |
3770 | 3769 | }
|
3771 | 3770 | else if (type instanceof WildcardType) {
|
3772 | 3771 | final WildcardType wType = (WildcardType) type;
|
|
0 commit comments