Skip to content

Commit 0f61b79

Browse files
committed
Use Any.is more broadly
1 parent 08b66b7 commit 0f61b79

File tree

5 files changed

+16
-23
lines changed

5 files changed

+16
-23
lines changed

scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/adapt/AdaptationMatchingRoutine.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ private void captureTypeVarsFromCandidate(Type srcType, OpCandidate candidate,
186186
var existing = map.get(key);
187187
var replacement = assigns.get(key);
188188
// Ignore bounds that are weaker than current bounds.
189-
if (Types.isAssignable(existing, replacement) && !existing.equals(
190-
Any.class) && !(existing instanceof Any))
191-
{
189+
if (Types.isAssignable(existing, replacement) && !Any.is(existing)) {
192190
continue;
193191
}
194192
}

scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/ConvertedOpInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private Type mapAnys(Type opType, OpInfo info) {
170170
info.opType() }, infoMap);
171171
for (var key : reqMap.keySet()) {
172172
var val = reqMap.get(key);
173-
if (val.equals(Any.class) || val instanceof Any) {
173+
if (Any.is(val)) {
174174
reqMap.put(key, infoMap.get(key));
175175
}
176176
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static int checkGenericOutputsAssignability(Type[] froms, Type[] tos,
105105
Type from = froms[i];
106106
Type to = tos[i];
107107

108-
if (to instanceof Any || to.equals(Any.class)) continue;
108+
if (Any.is(to)) continue;
109109

110110
if (from instanceof TypeVariable) {
111111
TypeVarInfo typeVarInfo = typeBounds.get(from);

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ public static Type greatestCommonSuperType(Type[] types,
280280
final boolean wildcardSingleIface)
281281
{
282282

283-
types = Arrays.stream(types).filter(t -> !(t.equals(Any.class) ||
284-
t instanceof Any)).toArray(Type[]::new);
283+
types = Arrays.stream(types).filter(t -> !(Any.is(t))).toArray(Type[]::new);
285284

286285
// return answer quick if the answer is trivial
287286
if (types.length == 0) return null;
@@ -679,7 +678,7 @@ public static boolean typesSatisfyVariables(
679678
private static boolean isApplicableToRawTypes(final Type arg,
680679
final Type param)
681680
{
682-
if (arg instanceof Any || arg.equals(Any.class)) return true;
681+
if (Any.is(arg)) return true;
683682
final List<Class<?>> srcClasses = Types.raws(arg);
684683
final List<Class<?>> destClasses = Types.raws(param);
685684
for (final Class<?> destClass : destClasses) {
@@ -729,7 +728,7 @@ private static boolean isApplicableToParameterizedTypes(final Type arg,
729728
if (destType instanceof TypeVariable<?>) {
730729
final Type srcType = srcTypes[i];
731730
final TypeVariable<?> destTypeVar = (TypeVariable<?>) destType;
732-
if (srcType instanceof Any || srcType.equals(Any.class)) continue;
731+
if (Any.is(srcType)) continue;
733732
if (!isApplicableToTypeParameter(srcType, destTypeVar, typeBounds))
734733
return false;
735734
ignoredIndices.add(i);
@@ -1674,7 +1673,7 @@ private static boolean isAssignable(final Type type, final Type toType,
16741673
return isAssignable(type, (TypeVariable<?>) toType, typeVarAssigns);
16751674
}
16761675

1677-
if (toType instanceof Any) {
1676+
if (Any.is(toType)) {
16781677
return isAssignable(type, (Any) toType, typeVarAssigns);
16791678
}
16801679

@@ -1787,7 +1786,7 @@ private static boolean isAssignable(final Type type,
17871786
return false;
17881787
}
17891788

1790-
if (type instanceof Any) return true;
1789+
if (Any.is(type)) return true;
17911790

17921791
throw new IllegalStateException("found an unhandled type: " + type);
17931792
}
@@ -1941,9 +1940,7 @@ else if (!isAssignable(fromResolved == null ? fromTypeArg
19411940
// parameters of the target type.
19421941
if (fromResolved != null && !fromResolved.equals(toResolved)) {
19431942
// check for anys
1944-
if (fromResolved instanceof Any || toResolved instanceof Any ||
1945-
fromResolved.equals(Any.class) || toResolved.equals(Any.class))
1946-
continue;
1943+
if (Any.is(fromResolved) || Any.is(toResolved)) continue;
19471944
if (fromResolved instanceof ParameterizedType &&
19481945
toResolved instanceof ParameterizedType)
19491946
{
@@ -1961,9 +1958,7 @@ else if (!isAssignable(fromResolved == null ? fromTypeArg
19611958
typeVarAssigns.put((TypeVariable<?>) toTypes[i], fromTypes[i]);
19621959
continue;
19631960
}
1964-
if (!(fromTypes[i] instanceof Any || toTypes[i] instanceof Any ||
1965-
fromTypes[i].equals(Any.class) || toTypes[i].equals(Any.class)))
1966-
return false;
1961+
if (!(Any.is(fromTypes[i]) || Any.is(toTypes[i]))) return false;
19671962
}
19681963
continue;
19691964
}
@@ -2131,7 +2126,7 @@ private static boolean isAssignable(final Type type,
21312126
final GenericArrayType toGenericArrayType,
21322127
final Map<TypeVariable<?>, Type> typeVarAssigns)
21332128
{
2134-
if (type == null || type instanceof Any || type.equals(Any.class)) {
2129+
if (type == null || Any.is(type)) {
21352130
return true;
21362131
}
21372132

@@ -2211,7 +2206,7 @@ private static boolean isAssignable(final Type type,
22112206
final WildcardType toWildcardType,
22122207
final Map<TypeVariable<?>, Type> typeVarAssigns)
22132208
{
2214-
if (type == null || type instanceof Any || type.equals(Any.class)) {
2209+
if (type == null || Any.is(type)) {
22152210
return true;
22162211
}
22172212

@@ -2355,7 +2350,7 @@ private static boolean isAssignable(final Type type,
23552350
return true;
23562351
}
23572352

2358-
if (type instanceof Any || type.equals(Any.class)) {
2353+
if (Any.is(type)) {
23592354
typeVarAssigns.put(toTypeVariable, new Any(toTypeVariable.getBounds()));
23602355
return true;
23612356
}
@@ -3496,7 +3491,7 @@ private static String toString(final Type type, final Set<Type> done) {
34963491
if (type instanceof Class) {
34973492
return classToString((Class<?>) type, done);
34983493
}
3499-
if (type instanceof Any) {
3494+
if (Any.is(type)) {
35003495
return type.toString();
35013496
}
35023497
if (type instanceof ParameterizedType) {

scijava-types/src/main/java/org/scijava/types/inference/GenericAssignability.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ private static void inferTypeVariables(Class<?> type, Type inferFrom,
446446
Type current = typeVarAssigns.putIfAbsent((TypeVariable<?>) inferFrom,
447447
type);
448448
if (current != null) {
449-
if (current instanceof Any) {
449+
if (Any.is(current)) {
450450
typeVarAssigns.put((TypeVariable<?>) inferFrom, type);
451451
}
452452
else if (!Objects.equal(type, current)) {
@@ -491,7 +491,7 @@ private static void inferTypeVariables(ParameterizedType type, Type inferFrom,
491491
if (inferFrom instanceof WildcardType) {
492492
inferFrom = getInferrableBound((WildcardType) inferFrom);
493493
}
494-
if (inferFrom instanceof Any || inferFrom.equals(Any.class)) {
494+
if (Any.is(inferFrom)) {
495495
mapTypeVarsToAny(type, typeMappings);
496496
return;
497497
}

0 commit comments

Comments
 (0)