Annotation Type Pattern


  • @Retention(CLASS)
    @Target({METHOD,FIELD,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE})
    public @interface Pattern
    Specifies that an element of the program represents a string that must completely match given regular expression. Code editors may use this annotation to report errors if the literals that assigned to the annotated variables, passed as arguments to the annotated parameters, or returned from the annotated methods, do not match the supplied pattern.

    This annotation also could be used as a meta-annotation, to define other annotations for convenience. E.g. the following annotation could be defined to annotate the strings that represent UUIDs:

     @Pattern("[\\dA-Fa-f]{8}-[\\dA-Fa-f]{4}-[\\dA-Fa-f]{4}-[\\dA-Fa-f]{4}-[\\dA-Fa-f]{12}")
     @interface UUID {}
     

    Note that using the derived annotation as meta-annotation is not supported. Meta-annotation works only one level deep.

    See Also:
    RegExp
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String value
      A regular expression that matches all the valid string literals that assigned to the annotated variables, passed as arguments to the annotated parameters, or returned from the annotated methods.
    • Element Detail

      • value

        @NonNls
        java.lang.String value
        A regular expression that matches all the valid string literals that assigned to the annotated variables, passed as arguments to the annotated parameters, or returned from the annotated methods.