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 Details

    • messager

      private Messager 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

      private final Set<TypeMirror> entities
    • entityAnnotations

      private final List<Class<? extends Annotation>> entityAnnotations
  • Constructor Details

    • EntityRequirementProcessor

      public EntityRequirementProcessor()
  • Method Details

    • init

      public void init(ProcessingEnvironment processingEnv)
      Initializes the annotation processor by obtaining the Messager from the processing environment.
      Specified by:
      init in interface Processor
      Overrides:
      init in class AbstractProcessor
      Parameters:
      processingEnv - The processing environment providing access to various utility methods and services.
    • process

      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
      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 interface Processor
      Specified by:
      process in class AbstractProcessor
      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

      private void validate(Element element)
      Validates the requirements on a class annotated with @Entity.
      Parameters:
      element - The annotated element to be validated.
    • isMismatchInGeneratorName

      private boolean isMismatchInGeneratorName(Element field)
      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

      private boolean isIdAnnotatedField(Element field)
      Checks if a field is annotated with Id.
      Parameters:
      field - The field element to be checked.
      Returns:
      True if the field is annotated with @Id, false otherwise.
    • hasNoArgsConstructor

      private boolean hasNoArgsConstructor(TypeElement typeElement)
      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

      private boolean hasRelationAnnotationOnEntityField(TypeElement typeElement)
      Checks if any field of the specified class has an annotation related to entity relationships.
      Parameters:
      typeElement - the TypeElement representing the class to inspect
      Returns:
      true if any field of the class has an annotation related to entity relationships, false otherwise