Package iu.type

Class TypeFacade<D,T>

java.lang.Object
iu.type.ElementBase
iu.type.TypeFacade<D,T>
Type Parameters:
D - declaring type
T - generic type
All Implemented Interfaces:
IuAnnotatedElement, IuDeclaredElement<D>, IuNamedElement<D>, IuParameterizedElement, IuType<D,T>, ParameterizedFacade

final class TypeFacade<D,T> extends ElementBase implements IuType<D,T>, ParameterizedFacade
Facade implementation of IuType.

Always includes a non-null reference() for which IuTypeReference.referent() == this.

Delegates most lookups to a TypeTemplate, but propagates independent resolution of type parameters based on arguments provided via referrer, which may or may not be the same TypeTemplate this facade delegates to.

  • Field Details

    • template

      final TypeTemplate<D,T> template
      Holds a reference to the template this facade delegates to.
    • parameterizedElement

      final ParameterizedElement parameterizedElement
      Parameterized element mix-in.

      May be used by related components to apply type arguments to managed instances before sealing. Once sealed, the public interface (i.e., IuParameterizedElement.typeParameter(String)) is preferred.

  • Constructor Details

    • TypeFacade

      TypeFacade(TypeTemplate<D,T> template, ElementBase referrer, IuReferenceKind referenceKind)
      Constructor for a non-named, non-indexed reference.
      Parameters:
      template - type template
      referrer - referrer element
      referenceKind - reference kind
    • TypeFacade

      TypeFacade(TypeTemplate<D,T> template, ElementBase referrer, IuReferenceKind referenceKind, String referenceName)
      Constructor for a named reference.
      Parameters:
      template - type template
      referrer - referrer element
      referenceKind - reference kind
      referenceName - reference name
    • TypeFacade

      TypeFacade(TypeTemplate<D,T> template, ElementBase referrer, IuReferenceKind referenceKind, int referenceIndex)
      Constructor for an indexed reference.
      Parameters:
      template - type template
      referrer - referrer element
      referenceKind - reference kind
      referenceIndex - reference index
  • Method Details

    • reference

      public IuTypeReference<T,?> reference()
      Description copied from interface: IuType
      Gets the reference used to obtain this type.
      Specified by:
      reference in interface IuType<D,T>
      Returns:
      type reference
    • typeParameters

      public Map<String,TypeFacade<?,?>> typeParameters()
      Description copied from interface: IuParameterizedElement
      Gets type parameters by name.
      Specified by:
      typeParameters in interface IuParameterizedElement
      Specified by:
      typeParameters in interface ParameterizedFacade
      Returns:
      map of type parameter facades
    • hasAnnotation

      public boolean hasAnnotation(Class<? extends Annotation> annotationType)
      Description copied from interface: IuAnnotatedElement
      Determines if an annotation is present.
      Specified by:
      hasAnnotation in interface IuAnnotatedElement
      Parameters:
      annotationType - annotation type
      Returns:
      true if the annotation is present, else null
    • annotation

      public <A extends Annotation> A annotation(Class<A> annotationType)
      Description copied from interface: IuAnnotatedElement
      Gets an annotation.
      Specified by:
      annotation in interface IuAnnotatedElement
      Type Parameters:
      A - annotation type
      Parameters:
      annotationType - annotation type
      Returns:
      annotation if present, else null
    • annotations

      public Iterable<? extends Annotation> annotations()
      Description copied from interface: IuAnnotatedElement
      Gets all defined annotations.
      Specified by:
      annotations in interface IuAnnotatedElement
      Returns:
      all annotations
    • permitted

      public boolean permitted(Predicate<String> isUserInRole)
      Description copied from interface: IuAnnotatedElement
      Determines if access to this element is permitted in the current context.
      Specified by:
      permitted in interface IuAnnotatedElement
      Parameters:
      isUserInRole - Delegates role-checks to a higher level module.
      Returns:
      true if access is permitted in the current context; else false
    • permitted

      public boolean permitted()
      Description copied from interface: IuAnnotatedElement
      Determines if access to this element is permitted for all users in the current context.
      Specified by:
      permitted in interface IuAnnotatedElement
      Returns:
      true if access is permitted for all users in the current context; else false
    • sub

      public <S> IuType<D,? extends S> sub(Class<S> subclass) throws ClassCastException
      Description copied from interface: IuType
      Gets a type-enforced facade for a specific sub-type of the described type.
      Specified by:
      sub in interface IuType<D,T>
      Type Parameters:
      S - sub-type
      Parameters:
      subclass - subclass of the described type
      Returns:
      this
      Throws:
      ClassCastException - If the type does not erase to a subclass
    • autoboxClass

      public Class<T> autoboxClass()
      Description copied from interface: IuType
      Returns the autobox equivalent
      Specified by:
      autoboxClass in interface IuType<D,T>
      Returns:
      the object version related to a primitive type, or the class passed in as-is if not primitive
    • autoboxDefault

      public T autoboxDefault()
      Description copied from interface: IuType
      Returns the default value for an object or primitive type.
      Specified by:
      autoboxDefault in interface IuType<D,T>
      Returns:
      The default value that would be assigned to a field of described primitive type if declared without an initializer; null if the described time is not primitive.
    • name

      public String name()
      Description copied from interface: IuNamedElement
      Gets the name.
      Specified by:
      name in interface IuNamedElement<D>
      Returns:
      name
    • declaringType

      public IuType<?,D> declaringType()
      Description copied from interface: IuDeclaredElement
      Gets the declaring type.
      Specified by:
      declaringType in interface IuDeclaredElement<D>
      Returns:
      declaring type
    • deref

      public Type deref()
      Description copied from interface: IuType
      Gets the generic type.
      Specified by:
      deref in interface IuType<D,T>
      Returns:
      generic type
    • erase

      public IuType<D,T> erase()
      Description copied from interface: IuType
      Gets the erased facade, which describing the Class representing the erasure of the generic type.

      The IuType.deref() of the erased facade must return a Class.

      Specified by:
      erase in interface IuType<D,T>
      Returns:
      erased type facade
      See Also:
    • erasedClass

      public Class<T> erasedClass()
      Description copied from interface: IuType
      Get the type erasure class.

      Shorthand for IuType.erase().IuType.deref()

      Specified by:
      erasedClass in interface IuType<D,T>
      Returns:
      type erasure class
      See Also:
    • hierarchy

      public Iterable<TypeFacade<?,? super T>> hierarchy()
      Description copied from interface: IuType
      Iterates the type hierarchy, from most specific to least specific.
      1. All Class.getGenericInterfaces()
      2. Class.getGenericSuperclass()
      3. Iterate IuType.hierarchy() until Object is reached

      This type described by this facade is not included. Object is always the last element.

      Specified by:
      hierarchy in interface IuType<D,T>
      Returns:
      inherited and extended types
    • referTo

      public IuType<?,? super T> referTo(Type referentType)
      Description copied from interface: IuType
      Refers to a type in the the described type's hierarchy.

      When the referent type declares type parameters, the resolved generic types associated with those parameters are described by the returned facade.

      Specified by:
      referTo in interface IuType<D,T>
      Parameters:
      referentType - type to refer to
      Returns:
      referent facade
    • enclosedTypes

      public Iterable<? extends IuType<T,?>> enclosedTypes()
      Description copied from interface: IuType
      Gets enclosed types.
      Specified by:
      enclosedTypes in interface IuType<D,T>
      Returns:
      enclosed types
    • constructors

      public Iterable<? extends IuConstructor<T>> constructors()
      Description copied from interface: IuType
      Gets all constructors defined by this type.
      Specified by:
      constructors in interface IuType<D,T>
      Returns:
      constructors
    • fields

      public Iterable<? extends IuField<? super T,?>> fields()
      Description copied from interface: IuType
      Gets all fields defined by this type, followed by all fields defined by all types in this type's hierarchy, in IuType.hierarchy() order.
      Specified by:
      fields in interface IuType<D,T>
      Returns:
      fields declared by this type and its hierarchy, in this followed by IuType.hierarchy() order
    • properties

      public Iterable<? extends IuProperty<? super T,?>> properties()
      Description copied from interface: IuType
      Gets all properties defined by this type, followed by all properties defined by all types in this type's hierarchy, in IuType.hierarchy() order.
      Specified by:
      properties in interface IuType<D,T>
      Returns:
      properties declared by this type and its hierarchy, in this followed by IuType.hierarchy() order
    • methods

      public Iterable<? extends IuMethod<? super T,?>> methods()
      Description copied from interface: IuType
      Gets all methods defined by this type.

      The result iterates all methods declared on all classes in the type erasure's hierarchy with private erasure for duplicately defined methods.

      Specified by:
      methods in interface IuType<D,T>
      Returns:
      methods
    • observe

      public void observe(T instance)
      Description copied from interface: IuType
      Observes a new instance.

      Observing an instance registers it with the implementation module as an available target for type introspection, for example, for resource binding. Implementors of InstanceReference may use IuType.subscribe(InstanceReference) to be notified when new instances are observed.

      Once all InstanceReferences have been notified, all methods annotated by @PostConstruct will be invoked on the instance.

      Observing an instance that is already observed has no effect, nor does observing an instance of a type that has no subscribers. All instances provided via IuExecutable.exec(Object...) are observed automatically. This method is a no-op for those instances, however it is up to implementors to ensure @PostConstruct methods do not result in errors or repeat initialization steps when invoked repeatedly.

      Specified by:
      observe in interface IuType<D,T>
      Parameters:
      instance - to observe
    • destroy

      public void destroy(T instance)
      Description copied from interface: IuType
      Destroys an instance.

      Invokes all @PreDestroy methods on an instance. If the instance was observed, its state will be reverted and no futures actions will be taken on it.

      This method may be invoked to close the lifecycle of instances created via IuExecutable.exec(Object...).

      Destroying an instance that is already destroyed should have no effect, but it is up to implementors to ensure @PreDestroy methods do not result in errors or other side-effects when invoked repeatedly.

      Specified by:
      destroy in interface IuType<D,T>
      Parameters:
      instance - to destroy
    • subscribe

      public Runnable subscribe(InstanceReference<T> instanceReference)
      Description copied from interface: IuType
      Subscribes a new instance reference.
      Specified by:
      subscribe in interface IuType<D,T>
      Parameters:
      instanceReference - will accept all observed instances until unsubscribed.
      Returns:
      thunk for unsubscribing the reference
    • toString

      public String toString()
      Overrides:
      toString in class Object