Class ContextBasedObjectSupplier<A extends java.lang.annotation.Annotation,​T>

  • Type Parameters:
    A - my qualifier annotation type
    T - my value type
    Direct Known Subclasses:
    RendererSupplier, ViewServiceSupplier

    public abstract class ContextBasedObjectSupplier<A extends java.lang.annotation.Annotation,​T>
    extends org.eclipse.e4.core.di.suppliers.ExtendedObjectSupplier
    A partial implementation of an object supplier that computes its results from values in the Eclipse context.
    Since:
    1.22
    • Field Summary

      • Fields inherited from class org.eclipse.e4.core.di.suppliers.ExtendedObjectSupplier

        SERVICE_CONTEXT_KEY, SERVICE_NAME
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ContextBasedObjectSupplier​(java.lang.Class<A> qualifierType, java.lang.Class<T> valueType)
      Initializes me with the type of value that I supply and the qualifier annotation type that I key on.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean checkDependencies​(A qualifier, java.lang.Class<? extends T> requestedType, org.eclipse.e4.core.contexts.IEclipseContext context)
      Check whether the Eclipse context has the dependencies required to compute my result.
      protected abstract java.util.Optional<? extends T> compute​(A qualifier, java.lang.Class<? extends T> requestedType, org.eclipse.e4.core.contexts.IEclipseContext context)
      Compute my value from the Eclipse context.
      java.lang.Object get​(org.eclipse.e4.core.di.suppliers.IObjectDescriptor descriptor, org.eclipse.e4.core.di.suppliers.IRequestor requestor, boolean track, boolean group)  
      • Methods inherited from class java.lang.Object

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

      • ContextBasedObjectSupplier

        protected ContextBasedObjectSupplier​(java.lang.Class<A> qualifierType,
                                             java.lang.Class<T> valueType)
        Initializes me with the type of value that I supply and the qualifier annotation type that I key on.
        Parameters:
        qualifierType - the qualifier annotation type
        valueType - the value type
    • Method Detail

      • get

        public java.lang.Object get​(org.eclipse.e4.core.di.suppliers.IObjectDescriptor descriptor,
                                    org.eclipse.e4.core.di.suppliers.IRequestor requestor,
                                    boolean track,
                                    boolean group)
        Specified by:
        get in class org.eclipse.e4.core.di.suppliers.ExtendedObjectSupplier
      • checkDependencies

        protected boolean checkDependencies​(A qualifier,
                                            java.lang.Class<? extends T> requestedType,
                                            org.eclipse.e4.core.contexts.IEclipseContext context)
        Check whether the Eclipse context has the dependencies required to compute my result. The default implementation just attempts to compute the result, which is useful for simple cases where the computation is not expensive and does not have undesired side-effects if it fails.
        Parameters:
        qualifier - the qualifier annotation, which may have attributes required for the computation
        requestedType - the type requested for injection
        context - the Eclipse context
        Returns:
        true if I can compute a value from this context; false, otherwise
        See Also:
        #compute(Annotation, IEclipseContext)
      • compute

        protected abstract java.util.Optional<? extends T> compute​(A qualifier,
                                                                   java.lang.Class<? extends T> requestedType,
                                                                   org.eclipse.e4.core.contexts.IEclipseContext context)
        Compute my value from the Eclipse context. An empty result indicates that the value does not exist (the IInjector.NOT_A_VALUE special result for the object-supplier protocol). Injection of null values is not supported.
        Parameters:
        qualifier - the qualifier annotation, which may have attributes required for the computation
        requestedType - the type requested for injection
        context - the Eclipse context
        Returns:
        the result of the computation (possibly empty, but not null)