Interface MetadataGenerator


public interface MetadataGenerator

Represents a generator, that produces resources during compilation phase. User must implement this interface and bind this implementation to a method that would read resources at runtime.

Here is the full workflow:

  • Compiler finds a method that is marked with the MetadataProvider annotation. This method must be declared as native, otherwise compiler should throw an exception.
  • Compiler instantiates the MetadataGenerator instance with the no-arg constructor If no such constructor exists, compiler throws exception.
  • Compiler runs the generateMetadata(MetadataGeneratorContext, MethodReference) method ands gets the produced resource.
  • Compiler generates implementation of the method marked with MetadataProvider, that will return the generated resource in run time.

Therefore, the type of the value, returned by the generateMetadata(MetadataGeneratorContext, MethodReference) method must match the returning type of the appropriate method, marked with MetadataProvider.

The valid resource types are the following:

  • Valid interfaces, extending the Resource annotation. Read the description of this interface for detailed description about valid resources interfaces.
  • ResourceArray of valid resources.
  • ResourceMap of valid resources.
  • The null value.

All other types are not considered to be resources and therefore are not accepted.

Author:
Alexey Andreev
See Also:
ClassScopedMetadataGenerator
  • Method Details

    • generateMetadata

      Resource generateMetadata(MetadataGeneratorContext context, MethodReference method)

      Generates resources, that will be available at runtime.

      Parameters:
      context - context that contains useful compile-time information.
      method - method which will be used to access the generated resources at run time.
      Returns:
      resource to be attached to method at run time.