Interface Dependency

All Known Implementing Classes:
AbstractDependency, IndependentDependency, InjectionPointDependency

public interface Dependency
Defines a TypeUsage for Dependency Injection with an Injector.
Since:
Jan-2025
Author:
brian.oliver
  • Method Summary

    Modifier and Type
    Method
    Description
    static <V> Optional<V>
    resolve(Dependency requested, Map<Dependency, V> candidates, build.codemodel.jdk.JDKCodeModel codeModel)
    Looks up the value registered for requested in candidates, keyed by Dependency.
    Obtains the unique signature for the Dependency, consisting of the TypeName and any AnnotationTypeUsages that have been annotated with the Qualifier meta-annotation.
    static String
    signatureOf(build.codemodel.foundation.usage.TypeUsage typeUsage, Stream<? extends build.codemodel.foundation.usage.AnnotationTypeUsage> qualifierAnnotations)
    Computes the canonical signature for a TypeUsage and a set of qualifier AnnotationTypeUsages, consisting of the TypeUsage's TypeUsage.canonicalName() (recursively including any generic parameters) followed by the qualifier annotations, sorted and rendered so that the signature is stable regardless of the order in which the qualifiers were declared.
    build.codemodel.foundation.usage.TypeUsage
    Obtains the TypeUsage for the Dependency.
  • Method Details

    • typeUsage

      build.codemodel.foundation.usage.TypeUsage typeUsage()
      Obtains the TypeUsage for the Dependency.
      Returns:
      the TypeUsage
    • signature

      String signature()
      Obtains the unique signature for the Dependency, consisting of the TypeName and any AnnotationTypeUsages that have been annotated with the Qualifier meta-annotation.
      Returns:
      the Signature for the Dependency
    • signatureOf

      static String signatureOf(build.codemodel.foundation.usage.TypeUsage typeUsage, Stream<? extends build.codemodel.foundation.usage.AnnotationTypeUsage> qualifierAnnotations)
      Computes the canonical signature for a TypeUsage and a set of qualifier AnnotationTypeUsages, consisting of the TypeUsage's TypeUsage.canonicalName() (recursively including any generic parameters) followed by the qualifier annotations, sorted and rendered so that the signature is stable regardless of the order in which the qualifiers were declared.

      Anywhere two things must be recognized as the "same qualified type" (an IndependentDependency and a Provides method it may resolve to, for example) must derive their signature from this method, so the two stay comparable.

      Parameters:
      typeUsage - the TypeUsage
      qualifierAnnotations - the Qualifier AnnotationTypeUsages
      Returns:
      the canonical signature
      Throws:
      DuplicateQualifierException - if more than one AnnotationTypeUsage of the same qualifier annotation type is present, making the signature ambiguous
    • resolve

      static <V> Optional<V> resolve(Dependency requested, Map<Dependency, V> candidates, build.codemodel.jdk.JDKCodeModel codeModel)
      Looks up the value registered for requested in candidates, keyed by Dependency. An exact key match (same signature()) always wins outright. On a miss, candidates is searched for the Dependency whose qualifiers match requested's exactly and whose typeUsage() is compatible - this is what lets a wildcard-bearing request (e.g. Class<? extends Base> or Set<? extends Base>) be satisfied by a registered candidate that doesn't match it exactly (e.g. Class<Impl>), without ever letting a wildcard-fallback candidate override an exact match, and without letting a differently-qualified (or unqualified) candidate silently satisfy a qualified request (e.g. an unqualified JDKVersion must never satisfy a request for @System JDKVersion).
      Type Parameters:
      V - the type of value
      Parameters:
      requested - the requested Dependency
      candidates - the candidates, keyed by Dependency
      codeModel - the JDKCodeModel used to check bound assignability
      Returns:
      the resolved value, or Optional.empty() if no candidate is compatible
      Throws:
      InjectionException - if more than one candidate is wildcard-compatible with requested