0

I'm working on an annotation processor and became curious.

Does it make any sense to annotate like this and validate within the annotation processor?

@Retention(value = RUNTIME)
@Target(value = {FIELD, METHOD, PARAMETER})
public @interface BitProperty {

    @Min(1)
    @Max(31)
    int scale() default 31;
}
Hardy
  • 18,659
  • 3
  • 49
  • 65
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184

1 Answers1

1

I am not even sure that this supposed to do? What would your expectation be? When the annotation processor runs you want that validation occurs and annotations with invalid parameter values (eg scale > 31) throw a constraint violation exception which in turn would abort the annotation processing?

The biggest problem here is that an annotation processor does not deal with Annotation instances, but rather with AnnotationMirrow and other classes within the javax.lang.model.element package. Bean Validation and Hibernate Validator are not designed to work with this reflective API. So, not, it won't work.

Hardy
  • 18,659
  • 3
  • 49
  • 65