Skip to content

Commit d3ee45b

Browse files
committed
Remove public TypeVarFromParameterizedTypeInfo
The special case it handles can be encapsulated with an anonymous subclass overriding the TypeVarInfo#allowType(Type, boolean) method within the private Types#isApplicableToTypeParameter method.
1 parent 895dbc6 commit d3ee45b

File tree

2 files changed

+10
-26
lines changed
  • scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/impl
  • scijava-types/src/main/java/org/scijava/types

2 files changed

+10
-26
lines changed

scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/impl/MatchingUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.scijava.types.Any;
4242
import org.scijava.types.Nil;
4343
import org.scijava.types.Types;
44-
import org.scijava.types.Types.TypeVarFromParameterizedTypeInfo;
4544
import org.scijava.types.Types.TypeVarInfo;
4645

4746
public final class MatchingUtils {
@@ -125,8 +124,7 @@ static int checkGenericOutputsAssignability(Type[] froms, Type[] tos,
125124
// has one bound, being to.
126125
if (typeVarInfo == null) {
127126
TypeVariable<?> fromTypeVar = (TypeVariable<?>) from;
128-
TypeVarFromParameterizedTypeInfo fromInfo =
129-
new TypeVarFromParameterizedTypeInfo(fromTypeVar);
127+
TypeVarInfo fromInfo = new TypeVarInfo(fromTypeVar);
130128
fromInfo.fixBounds(to, true);
131129
typeBounds.put(fromTypeVar, fromInfo);
132130
from = to;

scijava-types/src/main/java/org/scijava/types/Types.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,15 @@ private static boolean isApplicableToTypeParameter(final Type arg,
734734
{
735735
// add the type variable to the HashMap if it does not yet exist.
736736
if (!typeBounds.containsKey(param)) {
737-
typeBounds.put(param, new TypeVarFromParameterizedTypeInfo(
738-
param));
737+
typeBounds.put(param, new TypeVarInfo(param) {
738+
@Override
739+
public boolean allowType(Type type, boolean refuseWildcards) {
740+
// NB: Hardcode refuseWildcards to true. Necessary for TypeVariables
741+
// which were contained in ParameterizedTypes. Behavior tested by
742+
// TypesTest#testSatisfiesWildcardsInParameterizedType().
743+
return super.allowType(type, true);
744+
}
745+
});
739746
}
740747
// attempt to restrict the bounds of the type variable to the argument.
741748
// We call the fixBounds method the refuseWildcards flag to be true,
@@ -1312,27 +1319,6 @@ public String toString() {
13121319
}
13131320
}
13141321

1315-
/**
1316-
* Class for {@link TypeVariable} which were contained in
1317-
* {@link ParameterizedType}s. The only difference to {@link TypeVarInfo} is
1318-
* that {@link TypeVarInfo#allowType(Type, boolean)} will be always called
1319-
* with refuseWildcards flag to be true.
1320-
*/
1321-
public static class TypeVarFromParameterizedTypeInfo extends TypeVarInfo {
1322-
1323-
public TypeVarFromParameterizedTypeInfo(TypeVariable<?> var) {
1324-
super(var);
1325-
}
1326-
1327-
/**
1328-
* @param refuseWildcards hardcoded to true
1329-
*/
1330-
@Override
1331-
public boolean allowType(Type type, boolean refuseWildcards) {
1332-
return super.allowType(type, true);
1333-
}
1334-
}
1335-
13361322
// -- BEGIN FORK OF APACHE COMMONS LANG 3.4 CODE --
13371323

13381324
/*

0 commit comments

Comments
 (0)