Class TypeUtils


  • public final class TypeUtils
    extends java.lang.Object
    Utility class to provide common functionality for types.
    • Constructor Detail

      • TypeUtils

        private TypeUtils()
    • Method Detail

      • isAssignableFrom

        public static boolean isAssignableFrom​(ClassInformationRepository repo,
                                               org.objectweb.asm.Type t,
                                               org.objectweb.asm.Type u)
        Checks to see if one type is assignable from another type. This method should be similar to Class.isAssignableFrom(java.lang.Class) (with some caveats, explained in next paragraph), but uses a ClassInformationRepository object rather than requiring classes to be loaded up in to the JVM.

        Note that this code tries to mimic what ASM's original SimpleVerifier does to find out if two types are equal. The main difference between SimpleVerifier's code and Class.isAssignableFrom(java.lang.Class) is that SimpleVerifier will treat any interface instance as if it were an Object instance. That means that, for example, an Object is assignable to a Comparable (Comparable = Object) in the eyes of ASM's SimpleVerifier. Why this is the case has never been explained.

        Parameters:
        repo - repository to use for deriving class details
        t - type being assigned from
        u - type being assigned to
        Returns:
        true if u is assignable to t (t = u), false otherwise
      • isObjectTypeAssignableFrom

        private static boolean isObjectTypeAssignableFrom​(ClassInformationRepository repo,
                                                          org.objectweb.asm.Type t,
                                                          org.objectweb.asm.Type u)
      • isArrayElementTypeAssignableFrom

        private static boolean isArrayElementTypeAssignableFrom​(ClassInformationRepository repo,
                                                                org.objectweb.asm.Type t,
                                                                org.objectweb.asm.Type u)
      • flattenHierarchy

        private static java.util.LinkedHashSet<java.lang.String> flattenHierarchy​(ClassInformationRepository repo,
                                                                                  java.lang.String type)
      • flattenHierarchy

        private static void flattenHierarchy​(ClassInformationRepository repo,
                                             java.lang.String type,
                                             java.util.LinkedHashSet<java.lang.String> ret)