Class AbstractSubclassFactory<T>

  • Type Parameters:
    T - the superclass type
    Direct Known Subclasses:
    AbstractProxyFactory

    public abstract class AbstractSubclassFactory<T>
    extends AbstractClassFactory<T>
    Class factory for classes that override superclass methods.

    This class extends AbstractClassFactory by adding convenience methods to override methods on the superclass.

    Author:
    Stuart Douglas
    • Field Detail

      • reflectionMetadataSource

        protected final ReflectionMetadataSource reflectionMetadataSource
        The metadata source used to generate the proxy
    • Method Detail

      • overrideMethod

        protected boolean overrideMethod​(Method method,
                                         MethodIdentifier identifier,
                                         MethodBodyCreator creator)
        Creates a new method on the generated class that overrides the given methods, unless a method with the same signature has already been overridden.
        Parameters:
        method - The method to override
        identifier - The identifier of the method to override
        creator - The MethodBodyCreator used to create the method body
        Returns:
        true if the method was successfully overridden, false otherwise
      • overrideMethod

        protected boolean overrideMethod​(org.jboss.classfilewriter.ClassMethod method,
                                         MethodIdentifier identifier,
                                         MethodBodyCreator creator)
        Creates a new method on the generated class that overrides the given methods, unless a method with the same signature has already been overridden.
        Parameters:
        method - The method to override
        identifier - The identifier of the method to override
        creator - The MethodBodyCreator used to create the method body
        Returns:
        false if the method has already been overridden
      • cleanup

        protected void cleanup()
        Cleans up any resources left over from generating the class. Implementors should ensure they call super.cleanup();
        Specified by:
        cleanup in class AbstractClassFactory<T>
      • overrideEquals

        protected boolean overrideEquals()
        Override the equals method using the default MethodBodyCreator.
        Returns:
        true if the method was not already overridden
      • overrideEquals

        protected boolean overrideEquals​(MethodBodyCreator creator)
        Override the equals method using the given MethodBodyCreator.
        Parameters:
        creator - the method body creator to use
        Returns:
        true if the method was not already overridden
      • overrideHashcode

        protected boolean overrideHashcode()
        Override the hashCode method using the default MethodBodyCreator.
        Returns:
        true if the method was not already overridden
      • overrideHashcode

        protected boolean overrideHashcode​(MethodBodyCreator creator)
        Override the hashCode method using the given MethodBodyCreator.
        Parameters:
        creator - the method body creator to use
        Returns:
        true if the method was not already overridden
      • overrideToString

        protected boolean overrideToString()
        Override the toString method using the default MethodBodyCreator
        Returns:
        true if the method was not already overridden
      • overrideToString

        protected boolean overrideToString​(MethodBodyCreator creator)
        Override the toString method using the given MethodBodyCreator.
        Parameters:
        creator - the method body creator to use
        Returns:
        true if the method was not already overridden
      • overrideFinalize

        protected boolean overrideFinalize()
        Override the finalize method using the default MethodBodyCreator.
        Returns:
        true if the method was not already overridden
      • overrideFinalize

        protected boolean overrideFinalize​(MethodBodyCreator creator)
        Override the finalize method using the given MethodBodyCreator.
        Parameters:
        creator - the method body creator to use
        Returns:
        true if the method was not already overridden
      • overrideClone

        protected boolean overrideClone()
        Override the clone method using the default MethodBodyCreator.
        Returns:
        true if the method was not already overridden
      • overrideClone

        protected boolean overrideClone​(MethodBodyCreator creator)
        Override the clone method using the given MethodBodyCreator.
        Parameters:
        creator - the method body creator to use
        Returns:
        true if the method was not already overridden
      • addInterface

        protected boolean addInterface​(Class<?> interfaceClass)
        Adds an interface to the generated subclass, using the default MethodBodyCreator to generate the method bodies.
        Parameters:
        interfaceClass - the interface to add
      • addInterface

        protected boolean addInterface​(MethodBodyCreator override,
                                       Class<?> interfaceClass)
        Adds an interface to the generated subclass, using the given MethodBodyCreator to generate the method bodies
        Parameters:
        override - the method body creator to use
        interfaceClass - the interface to add
        Returns:
        true if the interface was not already overridden
      • createConstructorDelegates

        protected void createConstructorDelegates()
        Adds a constructor for every non-private constructor present on the superclass. The constructor bodies are generated with the default ConstructorBodyCreator
      • createConstructorDelegates

        protected void createConstructorDelegates​(ConstructorBodyCreator creator)
        Adds constructors that delegate the the superclass constructor for all non-private constructors present on the superclass
        Parameters:
        creator - the constructor body creator to use
      • getDefaultMethodOverride

        public MethodBodyCreator getDefaultMethodOverride()
        Returns the default MethodBodyCreator to use when creating overridden methods.
        Returns:
        the default method body creator
      • getDefaultConstructorOverride

        public ConstructorBodyCreator getDefaultConstructorOverride()
        Returns the default ConstructorBodyCreator to use then creating overridden subclasses.
        Returns:
        the default constructor body creator