java.lang.Object
org.apache.commons.jexl3.internal.introspection.ClassMisc

public class ClassMisc extends Object
Miscellaneous introspection methods.

The main algorithm is computing the actual ordered complete set of classes and interfaces that a given class extends or implements. This set order is based on the super-class then (recursive interface) declaration order, attempting to reflect the (hopefully intended) abstraction order (from strong to weak).

  • Constructor Details

    • ClassMisc

      private ClassMisc()
      Lets not instantiate it.
  • Method Details

    • addSuperClasses

      private static void addSuperClasses(Set<Class<?>> superSet, Class<?> baseClass)
      Collect super classes and interfaces in super-order.

      This orders from stronger to weaker abstraction in the sense that Integer is a stronger abstraction than Number.

      Parameters:
      superSet - the set of super classes to collect into
      baseClass - the root class.
    • addSuperInterfaces

      private static void addSuperInterfaces(Set<Class<?>> superSet, Class<?> clazz)
      Recursively add super-interfaces in super-order.

      On the premise that a class also tends to enumerate interface in the order of weaker abstraction and that interfaces follow the same convention (strong implements weak).

      Parameters:
      superSet - the set of super classes to fill
      clazz - the root class.
    • getCommonSuperClass

      public static Class<?> getCommonSuperClass(Class<?> baseClass, Class<?> other)
      Gets the closest common super-class of two classes.

      When building an array, this helps strong-typing the result.

      Parameters:
      baseClass - the class to serve as base
      other - the other class
      Returns:
      Object.class if nothing in common, the closest common class or interface otherwise
    • getSuperClasses

      public static Set<Class<?>> getSuperClasses(Class<?> baseClass, Class<?>... otherClasses)
      Build the set of super classes and interfaces common to a collection of classes.

      The returned set is ordered and puts classes in order of super-class appearance then interfaces of each super-class.

      Parameters:
      baseClass - the class to serve as base
      otherClasses - the (optional) other classes
      Returns:
      an empty set if nothing in common, the set of common classes and interfaces that does not contain the baseClass nor Object class