Skip to content

feat(processor): support the ServiceLoader static provider() method #37

Description

@LMLiam

Problem

java.util.ServiceLoader (Java 9+) supports two provider shapes: a public no‑arg constructor, or a public static provider() factory method returning the service type. The processor implicitly assumes the constructor form and offers no way to register a provider that exposes a static provider() method, even though such a class is a valid SPI provider.

Evidence

  • Generation writes the provider's binary name into META-INF/services/<contract> (ServiceSchemeProcessor.kt:156-170) with no awareness of provider methods.
  • Discovery is purely annotation‑driven on the class (ServiceSchemeProcessor.kt:48-63); there is no recognition of a static provider() factory.
  • README only shows the constructor form (README.md:71-92).

Proposed implementation

  • Detect a public static <ContractType> provider() method on annotated providers and treat it as a valid registration (the service‑file entry stays the provider class name; ServiceLoader handles the factory automatically).
  • Combine with provider‑instantiability validation (separate issue): a provider is valid if it has either a public no‑arg constructor or a public static provider() method.
  • Document the factory‑method option in the README.

Acceptance criteria

  • A provider exposing only a public static provider() method is accepted and loadable at runtime via ServiceLoader.
  • Tests cover the provider‑method form (Java + Kotlin @JvmStatic).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:processorAnnotation processor: discovery, validation, META-INF/services generationstatus:readyTriaged and ready for worktype:featureFeature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions