Annotation Type PreconditionAnnotation
-
@Documented @Retention(RUNTIME) @Target(ANNOTATION_TYPE) public @interface PreconditionAnnotationA meta-annotation that indicates that an annotation R is a precondition annotation, i.e., R is a type-specialized version ofRequiresQualifier. The valuequalifierthat is necessary for a precondition specified withRequiresQualifieris specified here with the valuequalifier.The annotation R that is meta-annotated as
PreconditionAnnotationmust have an element calledvaluethat is an array ofStrings of the same format and with the same meaning as the valueexpressioninRequiresQualifier.The established precondition P has type specified by the
qualifierfield of this annotation. If the annotation R has elements annotated byQualifierArgument, their values are copied to the arguments (elements) of annotation P with the same names. Different element names may be used in R and P, if aQualifierArgumentin R gives the name of the corresponding element in P.For example, the following code declares a precondition annotation for the
MinLenqualifier:
The@PreconditionAnnotation(qualifier = MinLen.class) @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) public @interface RequiresMinLen { String[] value(); @QualifierArgument("value") int targetValue() default 0;valueelement holds the expressions to which the qualifier applies andtargetValueholds the value for thevalueargument ofMinLen.The following code then uses the annotation on a method that requires
fieldto be@MinLen(2)upon entry.@RequiresMinLen(value = "field", targetValue = 2") public char getThirdCharacter() { return field.charAt(2); }- See Also:
RequiresQualifier,QualifierArgument
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.Class<? extends java.lang.annotation.Annotation>qualifierThe qualifier that must be established as a precondition.
-