|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -39,8 +39,8 @@ public abstract class TypeUtils {
@@ -39,8 +39,8 @@ public abstract class TypeUtils {
|
|
|
|
|
/** |
|
|
|
|
* Check if the right-hand side type may be assigned to the left-hand side |
|
|
|
|
* type following the Java generics rules. |
|
|
|
|
* @param lhsType the target type |
|
|
|
|
* @param rhsType the value type that should be assigned to the target type |
|
|
|
|
* @param lhsType the target type (left-hand side (LHS) type) |
|
|
|
|
* @param rhsType the value type (right-hand side (RHS) type) that should be assigned to the target type |
|
|
|
|
* @return true if rhs is assignable to lhs |
|
|
|
|
*/ |
|
|
|
|
public static boolean isAssignable(Type lhsType, Type rhsType) { |
|
|
|
@ -133,35 +133,17 @@ public abstract class TypeUtils {
@@ -133,35 +133,17 @@ public abstract class TypeUtils {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean isAssignable(WildcardType lhsType, Type rhsType) { |
|
|
|
|
Type[] lUpperBounds = lhsType.getUpperBounds(); |
|
|
|
|
Type[] lUpperBounds = getUpperBounds(lhsType); |
|
|
|
|
|
|
|
|
|
// supply the implicit upper bound if none are specified
|
|
|
|
|
if (lUpperBounds.length == 0) { |
|
|
|
|
lUpperBounds = new Type[] { Object.class }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Type[] lLowerBounds = lhsType.getLowerBounds(); |
|
|
|
|
|
|
|
|
|
// supply the implicit lower bound if none are specified
|
|
|
|
|
if (lLowerBounds.length == 0) { |
|
|
|
|
lLowerBounds = new Type[] { null }; |
|
|
|
|
} |
|
|
|
|
Type[] lLowerBounds = getLowerBounds(lhsType); |
|
|
|
|
|
|
|
|
|
if (rhsType instanceof WildcardType rhsWcType) { |
|
|
|
|
// both the upper and lower bounds of the right-hand side must be
|
|
|
|
|
// completely enclosed in the upper and lower bounds of the left-
|
|
|
|
|
// hand side.
|
|
|
|
|
Type[] rUpperBounds = rhsWcType.getUpperBounds(); |
|
|
|
|
|
|
|
|
|
if (rUpperBounds.length == 0) { |
|
|
|
|
rUpperBounds = new Type[] { Object.class }; |
|
|
|
|
} |
|
|
|
|
Type[] rUpperBounds = getUpperBounds(rhsWcType); |
|
|
|
|
|
|
|
|
|
Type[] rLowerBounds = rhsWcType.getLowerBounds(); |
|
|
|
|
|
|
|
|
|
if (rLowerBounds.length == 0) { |
|
|
|
|
rLowerBounds = new Type[] { null }; |
|
|
|
|
} |
|
|
|
|
Type[] rLowerBounds = getLowerBounds(rhsWcType); |
|
|
|
|
|
|
|
|
|
for (Type lBound : lUpperBounds) { |
|
|
|
|
for (Type rBound : rUpperBounds) { |
|
|
|
@ -208,6 +190,26 @@ public abstract class TypeUtils {
@@ -208,6 +190,26 @@ public abstract class TypeUtils {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Type[] getLowerBounds(WildcardType wildcardType) { |
|
|
|
|
Type[] lowerBounds = wildcardType.getLowerBounds(); |
|
|
|
|
|
|
|
|
|
// supply the implicit lower bound if none are specified
|
|
|
|
|
if (lowerBounds.length == 0) { |
|
|
|
|
lowerBounds = new Type[] { null }; |
|
|
|
|
} |
|
|
|
|
return lowerBounds; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Type[] getUpperBounds(WildcardType wildcardType) { |
|
|
|
|
Type[] upperBounds = wildcardType.getUpperBounds(); |
|
|
|
|
|
|
|
|
|
// supply the implicit upper bound if none are specified
|
|
|
|
|
if (upperBounds.length == 0) { |
|
|
|
|
upperBounds = new Type[] { Object.class }; |
|
|
|
|
} |
|
|
|
|
return upperBounds; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean isAssignableBound(@Nullable Type lhsType, @Nullable Type rhsType) { |
|
|
|
|
if (rhsType == null) { |
|
|
|
|
return true; |
|
|
|
|