Class PluginContractProcessor
- All Implemented Interfaces:
Processor
This processor scans classes marked with @DataversePlugin, discovers all implemented
plugin contracts annotated with @PluginContract, validates the contract graph, and emits:
- a per-plugin descriptor under "META-INF/dataverse/plugins/", and
- a
META-INF/services/...entry for the base plugin contract when safe to do so.
Note: The processor enforces contract rules for all top-level and member interfaces in compiled source files. Runtime validation of contracts in PluginLoader loaded from external JARs or assembled outside normal compilation will catch illegal usage the processor cannot see and validate (like anonymous or method body interfaces).
The descriptor captures the build-time view of:
- the plugin implementation class,
- the plugin's base contract,
- all implemented contract API levels,
- all required provider API levels.
Contract graph rules
The processor enforces a strict contract hierarchy:
- A
base contractis the unique, directly loadable identity of a plugin. Base contracts may not extend other contracts and may not declarerequires. - A
capability contractadds optional functionality. It must declare exactly one base contract inrequires. A capability may optionally extend its required base contract in the Java type hierarchy to provide default implementations for methods declared by the base. A capability may not extend another capability.
Service registration
Service registration generation is intentionally cautious. If any implementation of a given base
contract uses @AutoService, this processor suppresses generated service output for that
entire contract to avoid two processors writing the same META-INF/services/... file.
Errors are reported against the offending source element and then converted into a local
PluginContractProcessor.ProcessorException. This aborts processing of the current implementation only, allowing
the processor to continue and surface additional problems in the same compilation run.
-
Field Summary
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the annotation types directly claimed by this processor.Advertises support for the latest source version understood by the current compiler.voidinit(ProcessingEnvironment processingEnv) Initializes compiler utility helpers from the processing environment.booleanprocess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Main processor entry point for each annotation processing round.Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedOptions, isInitialized
-
Constructor Details
-
PluginContractProcessor
public PluginContractProcessor()
-
-
Method Details
-
init
Initializes compiler utility helpers from the processing environment.- Specified by:
initin interfaceProcessor- Overrides:
initin classAbstractProcessor- Parameters:
processingEnv- the active annotation processing environment
-
getSupportedAnnotationTypes
Returns the annotation types directly claimed by this processor.The processor claims all annotations because it does not only react to explicitly annotated
@DataversePluginclasses. It also performs project-wide validation for plugin contracts, provider contracts, and unannotated plugin implementations discovered in the type model.- Specified by:
getSupportedAnnotationTypesin interfaceProcessor- Overrides:
getSupportedAnnotationTypesin classAbstractProcessor- Returns:
- the supported top-level annotation types
-
getSupportedSourceVersion
Advertises support for the latest source version understood by the current compiler.This is preferred over a hard-coded release because the processor mainly operates on the annotation/type model and should remain usable across newer Java releases automatically.
- Specified by:
getSupportedSourceVersionin interfaceProcessor- Overrides:
getSupportedSourceVersionin classAbstractProcessor- Returns:
- the latest source version supported by the running compiler
-
process
Main processor entry point for each annotation processing round.During normal rounds, this processor performs two tasks:
- it inspects all root types and their hierarchies for project-wide contract validation,
- it processes explicitly annotated
@DataversePluginclasses.
During the final round, all accumulated descriptor and service models are written to the compiler output.
- Specified by:
processin interfaceProcessor- Specified by:
processin classAbstractProcessor- Parameters:
annotations- the annotations requested for this roundroundEnv- the current round environment- Returns:
falseso other processors may continue to participate normally
-