Class ExtendedEnumProcessor

All Implemented Interfaces:
Processor

@AutoService(javax.annotation.processing.Processor.class) @SupportedAnnotationTypes("host.anzo.commons.annotations.processors.ExtendedEnum") public class ExtendedEnumProcessor extends CommonProcessor
An annotation processor that enhances enums annotated with @ExtendedEnum.

This processor automatically adds the following members to the annotated enum:

  • A private static final List<EnumType> cacheList field, initialized with List.of(values())
  • A public static EnumType getValue(int ordinal) method to retrieve an enum constant by its ordinal
  • A public static List<EnumType> getValues() method that returns the cached list
  • A private static final Map<String, EnumType> cacheMap field with case-insensitive name mapping
  • Overloaded public static EnumType getValueOf(String) methods for name lookup
This avoids repeated array allocation and provides convenient access methods. It relies on the Javac AST manipulation utilities provided by CommonProcessor.
See Also:
  • Constructor Details

    • ExtendedEnumProcessor

      public ExtendedEnumProcessor()
  • Method Details

    • process

      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
      Processes annotations for a processing round.

      It finds all enums annotated with @ExtendedEnum, verifies processor initialization, and then modifies the AST of each found enum to add the caching field and utility methods.

      Specified by:
      process in interface Processor
      Specified by:
      process in class AbstractProcessor
      Parameters:
      annotations - The annotation types requested to be processed.
      roundEnv - Environment for information about the current and prior round.
      Returns:
      false always, as this processor does not claim the annotations. This allows other processors to potentially process the same annotations, though typically only one processor modifies a given element's structure.