Class ClassBuilding


  • public final class ClassBuilding
    extends java.lang.Object
    Entry-point for building enhanced classes and 'fast-class' invocation.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ClassBuilding()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static BytecodeGen.EnhancerBuilder buildEnhancerBuilder​(java.lang.Class<?> hostClass)
      Builder of enhancers that provide method interception via bytecode generation.
      static java.util.function.Function<java.lang.String,​java.util.function.BiFunction<java.lang.Object,​java.lang.Object[],​java.lang.Object>> buildFastClass​(java.lang.Class<?> hostClass)
      Builds a 'fast-class' invoker that uses bytecode generation in place of reflection.
      private static boolean canAccess​(java.lang.reflect.Executable member, boolean samePackage)
      Can we access this member from a subclass which may be in the same package?
      static boolean canEnhance​(java.lang.reflect.Executable member)
      Returns true if the given member can be enhanced using bytecode.
      static boolean canFastInvoke​(java.lang.reflect.Executable member)
      Returns true if the given member can be fast-invoked.
      private static java.lang.reflect.Method[] getOverridableObjectMethods()
      Cache common overridable Object methods.
      private static boolean isPublic​(java.lang.Class<?> clazz)  
      private static boolean mergeInterface​(java.util.List<java.lang.Class<?>> interfaces, java.lang.Class<?> candidate)
      Attempts to merge the interface with the current flattened hierarchy.
      private static java.lang.Object mergeMethods​(java.lang.Object existing, java.lang.Object added)
      Add the new method to an existing partition or create a new one.
      private static java.lang.String packageName​(java.lang.String className)
      Extract the package name from a class name.
      private static void partitionMethod​(java.lang.reflect.Method method, java.util.Map<java.lang.String,​java.lang.Object> partitions)
      Methods are partitioned by name and parameter count.
      private static void pushInterfaces​(java.util.Deque<java.lang.Class<?>[]> interfaceStack, java.lang.Class<?>[] interfaces)
      Pushes the interface declaration onto the stack if it's not empty.
      static java.lang.String signature​(java.lang.reflect.Constructor<?> constructor)
      Minimum signature needed to disambiguate constructors from the same host class.
      static java.lang.String signature​(java.lang.reflect.Method method)
      Minimum signature needed to disambiguate methods from the same host class.
      private static java.lang.String signature​(java.lang.String name, java.lang.Class<?>[] parameterTypes)
      Appends a semicolon-separated list of parameter types to the given name.
      private static void visitFastConstructors​(java.lang.Class<?> hostClass, java.util.function.Consumer<java.lang.reflect.Constructor<?>> visitor)
      Visit all constructors for the host class that can be fast-invoked.
      private static void visitFastMethods​(java.lang.Class<?> hostClass, java.util.function.Consumer<java.lang.reflect.Method> visitor)
      Visit all methods declared by the host class that can be fast-invoked.
      (package private) static <T extends java.lang.reflect.Executable>
      void
      visitMembers​(T[] members, boolean samePackage, java.util.function.Consumer<T> visitor)
      Visit all subclass accessible members in the given array.
      private static void visitMethodHierarchy​(java.lang.Class<?> hostClass, java.util.function.Consumer<java.lang.reflect.Method> visitor)
      Visit the method hierarchy for the host class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • OVERRIDABLE_OBJECT_METHODS

        private static final java.lang.reflect.Method[] OVERRIDABLE_OBJECT_METHODS
    • Constructor Detail

      • ClassBuilding

        private ClassBuilding()
    • Method Detail

      • signature

        public static java.lang.String signature​(java.lang.reflect.Constructor<?> constructor)
        Minimum signature needed to disambiguate constructors from the same host class.
      • signature

        public static java.lang.String signature​(java.lang.reflect.Method method)
        Minimum signature needed to disambiguate methods from the same host class.
      • signature

        private static java.lang.String signature​(java.lang.String name,
                                                  java.lang.Class<?>[] parameterTypes)
        Appends a semicolon-separated list of parameter types to the given name.
      • canEnhance

        public static boolean canEnhance​(java.lang.reflect.Executable member)
        Returns true if the given member can be enhanced using bytecode.
      • buildEnhancerBuilder

        public static BytecodeGen.EnhancerBuilder buildEnhancerBuilder​(java.lang.Class<?> hostClass)
        Builder of enhancers that provide method interception via bytecode generation.
      • partitionMethod

        private static void partitionMethod​(java.lang.reflect.Method method,
                                            java.util.Map<java.lang.String,​java.lang.Object> partitions)
        Methods are partitioned by name and parameter count. This helps focus the search for bridge delegates that involve type-erasure of generic parameter types, since the parameter count will be the same for the bridge method and its delegate.
      • mergeMethods

        private static java.lang.Object mergeMethods​(java.lang.Object existing,
                                                     java.lang.Object added)
        Add the new method to an existing partition or create a new one.
      • visitMethodHierarchy

        private static void visitMethodHierarchy​(java.lang.Class<?> hostClass,
                                                 java.util.function.Consumer<java.lang.reflect.Method> visitor)
        Visit the method hierarchy for the host class.
      • pushInterfaces

        private static void pushInterfaces​(java.util.Deque<java.lang.Class<?>[]> interfaceStack,
                                           java.lang.Class<?>[] interfaces)
        Pushes the interface declaration onto the stack if it's not empty.
      • mergeInterface

        private static boolean mergeInterface​(java.util.List<java.lang.Class<?>> interfaces,
                                              java.lang.Class<?> candidate)
        Attempts to merge the interface with the current flattened hierarchy.
      • packageName

        private static java.lang.String packageName​(java.lang.String className)
        Extract the package name from a class name.
      • getOverridableObjectMethods

        private static java.lang.reflect.Method[] getOverridableObjectMethods()
        Cache common overridable Object methods.
      • canFastInvoke

        public static boolean canFastInvoke​(java.lang.reflect.Executable member)
        Returns true if the given member can be fast-invoked.
      • isPublic

        private static boolean isPublic​(java.lang.Class<?> clazz)
      • buildFastClass

        public static java.util.function.Function<java.lang.String,​java.util.function.BiFunction<java.lang.Object,​java.lang.Object[],​java.lang.Object>> buildFastClass​(java.lang.Class<?> hostClass)
        Builds a 'fast-class' invoker that uses bytecode generation in place of reflection.
      • visitFastConstructors

        private static void visitFastConstructors​(java.lang.Class<?> hostClass,
                                                  java.util.function.Consumer<java.lang.reflect.Constructor<?>> visitor)
        Visit all constructors for the host class that can be fast-invoked.
      • visitFastMethods

        private static void visitFastMethods​(java.lang.Class<?> hostClass,
                                             java.util.function.Consumer<java.lang.reflect.Method> visitor)
        Visit all methods declared by the host class that can be fast-invoked.
      • visitMembers

        static <T extends java.lang.reflect.Executable> void visitMembers​(T[] members,
                                                                          boolean samePackage,
                                                                          java.util.function.Consumer<T> visitor)
        Visit all subclass accessible members in the given array.
      • canAccess

        private static boolean canAccess​(java.lang.reflect.Executable member,
                                         boolean samePackage)
        Can we access this member from a subclass which may be in the same package?