Package host.anzo.commons.processors
Class ExtendedEnumProcessor
java.lang.Object
javax.annotation.processing.AbstractProcessor
host.anzo.commons.processors.CommonProcessor
host.anzo.commons.processors.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> cacheListfield, initialized withjava.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
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.
- A
cacheKeys is not used or is empty:
- A
private static final java.util.Map<String, EnumType> cacheMapfield (mapping enum constant names). - Overloaded
public static EnumType getValueOf(String name)methods for name lookup.
CommonProcessor.- See Also:
-
Field Summary
Fields inherited from class host.anzo.commons.processors.CommonProcessor
maker, messager, names, treesFields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanprocess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Processes annotations for a processing round.Methods inherited from class host.anzo.commons.processors.CommonProcessor
capitalize, createQualifiedName, fieldExists, findFieldType, getBoxedType, getSupportedSourceVersion, init, log, logError, logWarn, methodExists, methodExistsMethods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, isInitialized
-
Constructor Details
-
ExtendedEnumProcessor
public ExtendedEnumProcessor()
-
-
Method Details
-
process
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:
processin interfaceProcessor- Specified by:
processin classAbstractProcessor- Parameters:
annotations- The annotation types requested to be processed.roundEnv- Environment for information about the current and prior round.- Returns:
falsealways, as this processor does not claim the annotations.
-