Class EntityRequirementProcessor
java.lang.Object
javax.annotation.processing.AbstractProcessor
io.github.blyznytsiaorg.bibernate.EntityRequirementProcessor
- All Implemented Interfaces:
Processor
@SupportedAnnotationTypes("io.github.blyznytsiaorg.bibernate.annotation.Entity")
@SupportedSourceVersion(RELEASE_17)
public class EntityRequirementProcessor
extends AbstractProcessor
Annotation processor for validating requirements on classes annotated with the
Entity
annotation.
This processor performs checks such as ensuring the presence of a field annotated with Id
,
the existence of a no-args constructor, and the consistency of generator names between GeneratedValue
and SequenceGenerator
annotations.
Additionally, this processor supports the IgnoreEntity
annotation to exclude specific classes
from the validation process.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
Modifier and TypeFieldDescriptionprivate final Set
<TypeMirror> private final List
<Class<? extends Annotation>> private Messager
The Messager used for reporting diagnostic messages during the annotation processing.Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
hasNoArgsConstructor
(TypeElement typeElement) Checks if a class has a no-args constructor (constructor without parameters).private boolean
hasRelationAnnotationOnEntityField
(TypeElement typeElement) Checks if any field of the specified class has an annotation related to entity relationships.void
init
(ProcessingEnvironment processingEnv) Initializes the annotation processor by obtaining the Messager from the processing environment.private boolean
isIdAnnotatedField
(Element field) Checks if a field is annotated withId
.private boolean
isMismatchInGeneratorName
(Element field) Checks if there is a mismatch in generator names between @GeneratedValue and @SequenceGenerator annotations.boolean
process
(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Processes the annotated elements and performs validation checks on classes annotated with @Entity.private void
Validates the requirements on a class annotated with @Entity.Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, getSupportedSourceVersion, isInitialized
-
Field Details
-
messager
The Messager used for reporting diagnostic messages during the annotation processing. It provides a way for the annotation processor to communicate messages, warnings, and errors back to the user or the development environment. -
entities
-
entityAnnotations
-
-
Constructor Details
-
EntityRequirementProcessor
public EntityRequirementProcessor()
-
-
Method Details
-
init
Initializes the annotation processor by obtaining the Messager from the processing environment.- Specified by:
init
in interfaceProcessor
- Overrides:
init
in classAbstractProcessor
- Parameters:
processingEnv
- The processing environment providing access to various utility methods and services.
-
process
Processes the annotated elements and performs validation checks on classes annotated with @Entity. Supports the @IgnoreEntity annotation to exclude specific classes from validation.- Specified by:
process
in interfaceProcessor
- Specified by:
process
in classAbstractProcessor
- Parameters:
annotations
- The set of annotation types that this processor supports.roundEnv
- The environment for a round of annotation processing.- Returns:
- True if the set of annotations are claimed by this processor, false otherwise.
-
validate
Validates the requirements on a class annotated with @Entity.- Parameters:
element
- The annotated element to be validated.
-
isMismatchInGeneratorName
Checks if there is a mismatch in generator names between @GeneratedValue and @SequenceGenerator annotations.- Parameters:
field
- The field element to be checked for the mismatch.- Returns:
- True if a mismatch in generator names is found, false otherwise.
-
isIdAnnotatedField
Checks if a field is annotated withId
.- Parameters:
field
- The field element to be checked.- Returns:
- True if the field is annotated with @Id, false otherwise.
-
hasNoArgsConstructor
Checks if a class has a no-args constructor (constructor without parameters).- Parameters:
typeElement
- The TypeElement representing the class to be checked.- Returns:
- True if the class has a no-args constructor, false otherwise.
-
hasRelationAnnotationOnEntityField
Checks if any field of the specified class has an annotation related to entity relationships.- Parameters:
typeElement
- theTypeElement
representing the class to inspect- Returns:
true
if any field of the class has an annotation related to entity relationships,false
otherwise
-