/** * @param rhs * @param lhs * @return <code>true</code> iff an expression of type 'rhs' can be assigned to a variable of type 'lhs'. * Type arguments of generic / raw / parameterized types are <b>not</b> considered. */ public static boolean canAssignTo(TType rhs, TType lhs) { if (rhs.isHierarchyType() && lhs.isHierarchyType()) { HierarchyType rhsGeneric= (HierarchyType) rhs.getTypeDeclaration(); HierarchyType lhsGeneric= (HierarchyType) lhs.getTypeDeclaration(); return lhs.isJavaLangObject() || rhsGeneric.equals(lhsGeneric) || rhsGeneric.isSubType(lhsGeneric); } else if (rhs.isTypeVariable()) { if (rhs.canAssignTo(lhs)) return true; TType[] bounds= ((TypeVariable) rhs).getBounds(); for (int i= 0; i < bounds.length; i++) { if (canAssignTo(bounds[i], lhs)) return true; } return lhs.isJavaLangObject(); } else { return rhs.canAssignTo(lhs); } }
/** * @param rhs * @param lhs * @return <code>true</code> iff an expression of type 'rhs' can be assigned to a variable of type 'lhs'. * Type arguments of generic / raw / parameterized types are <b>not</b> considered. */ public static boolean canAssignTo(TType rhs, TType lhs) { if (rhs.isHierarchyType() && lhs.isHierarchyType()) { HierarchyType rhsGeneric= (HierarchyType) rhs.getTypeDeclaration(); HierarchyType lhsGeneric= (HierarchyType) lhs.getTypeDeclaration(); return lhs.isJavaLangObject() || rhsGeneric.equals(lhsGeneric) || rhsGeneric.isSubType(lhsGeneric); } else if (rhs.isTypeVariable()) { if (rhs.canAssignTo(lhs)) return true; TType[] bounds= ((TypeVariable) rhs).getBounds(); for (int i= 0; i < bounds.length; i++) { if (canAssignTo(bounds[i], lhs)) return true; } return lhs.isJavaLangObject(); } else { return rhs.canAssignTo(lhs); } }
/** * @param rhs * @param lhs * @return <code>true</code> iff an expression of type 'rhs' can be assigned to a variable of type 'lhs'. * Type arguments of generic / raw / parameterized types are <b>not</b> considered. */ public static boolean canAssignTo(TType rhs, TType lhs) { if (rhs.isHierarchyType() && lhs.isHierarchyType()) { HierarchyType rhsGeneric= (HierarchyType) rhs.getTypeDeclaration(); HierarchyType lhsGeneric= (HierarchyType) lhs.getTypeDeclaration(); return lhs.isJavaLangObject() || rhsGeneric.equals(lhsGeneric) || rhsGeneric.isSubType(lhsGeneric); } else if (rhs.isTypeVariable()) { if (rhs.canAssignTo(lhs)) return true; TType[] bounds= ((TypeVariable) rhs).getBounds(); for (int i= 0; i < bounds.length; i++) { if (canAssignTo(bounds[i], lhs)) return true; } return lhs.isJavaLangObject(); } else { return rhs.canAssignTo(lhs); } }