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 java.util.List<EnumType> cacheList field, initialized with java.util.List.of(values())
  • A public static EnumType getValue(int ordinal) method to retrieve an enum constant by its ordinal
  • A public static java.util.List<EnumType> getValues() method that returns the cached list
If the cacheKeys attribute of @ExtendedEnum is used:
  • For each specified key (field name):
    • A private static final java.util.Map<FieldType, EnumType> cacheMapBy<FieldName> field.
    • A static initializer block to populate this map.
    • A public static EnumType getValueOf<FieldName>(FieldType key) method.
If cacheKeys is not used or is empty:
  • A private static final java.util.Map<String, EnumType> cacheMap field (mapping enum constant names).
  • Overloaded public static EnumType getValueOf(String name) 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.