Annotation Interface DefaultFor


@Documented @Retention(RUNTIME) @Target(ANNOTATION_TYPE) public @interface DefaultFor
A meta-annotation applied to the declaration of a type qualifier. It specifies that the given annotation should be the default for:
  • all uses at a particular location,
  • all uses of a particular type, and
  • all uses of a particular kind of type.

The default applies to every match for any of this annotation's conditions.

See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Returns regular expressions matching names of variables, to whose types the annotation should be applied as a default.
    Returns exceptions to regular expression rules.
    Returns TypeKinds of types for which an annotation should be implicitly added.
    Class<?>[]
    Returns Classes for which an annotation should be applied.
    Returns the locations to which the annotation should be applied.
  • Element Details

    • value

      Returns the locations to which the annotation should be applied.
      Returns:
      the locations to which the annotation should be applied
      Default:
      {}
    • typeKinds

      TypeKind[] typeKinds
      Returns TypeKinds of types for which an annotation should be implicitly added.
      Returns:
      TypeKinds of types for which an annotation should be implicitly added
      Default:
      {}
    • types

      Class<?>[] types
      Returns Classes for which an annotation should be applied. For example, if @MyAnno is meta-annotated with @DefaultFor(classes=String.class), then every occurrence of String is actually @MyAnno String.

      Only the given types, not their subtypes, receive the default. For instance, if the types element contains only Iterable, then the default does not apply to a variable or expression of type Collection which is a subtype of Iterable.

      Returns:
      Classes for which an annotation should be applied
      Default:
      {}
    • names

      String[] names
      Returns regular expressions matching names of variables, to whose types the annotation should be applied as a default. If a regular expression matches the name of a method, the annotation is applied as a default to the return type.

      The regular expression must match the entire variable or method name. For example, to match any name that contains "foo", use ".*foo.*".

      The default does not apply if the name matches any of the regexes in namesExceptions().

      This affects formal parameter types only if one of the following is true:

      • The method's source code is available; that is, the method is type-checked along with client calls.
      • When the method was compiled in a previous run of javac, either the processor was run or the -g command-line option was provided.
      Returns:
      regular expressions matching variables to whose type an annotation should be applied
      Default:
      {}
    • namesExceptions

      String[] namesExceptions
      Returns exceptions to regular expression rules.
      Returns:
      exceptions to regular expression rules
      See Also:
      Default:
      {}