Annotation Type TargetLocations


  • @Documented
    @Retention(RUNTIME)
    @Target(ANNOTATION_TYPE)
    public @interface TargetLocations
    A meta-annotation that restricts the type-use locations where a type qualifier may be applied. When written together with @Target({ElementType.TYPE_USE}), the given type qualifier may be applied only at locations listed in the @TargetLocations(...) meta-annotation. @Target({ElementType.TYPE_USE}) together with no @TargetLocations(...) means that the qualifier can be applied to any type use. @TargetLocations({}) means that the qualifier should not be used in source code. The same goal can be achieved by writing @Target({}), which is enforced by javac itself. @TargetLocations({...}) is enforced by the checker. The resulting errors from the checker can either be suppressed using @SuppressWarnings("type.invalid.annotations.on.location") or can be ignored by providing the -AignoreTargetLocations option.

    This enables a type system designer to permit a qualifier to be applied only in certain locations. For example, some type systems' top and bottom qualifier (such as RegexBottom) should only be written on an explicit wildcard upper or lower bound. This meta-annotation is a declarative, coarse-grained approach to enable that. For finer-grained control, override visit* methods that visit trees in BaseTypeVisitor.

    @TargetLocations are used for all appearances of qualifiers regardless of whether they are provided explicitly or implicitly (inferred or computed). Therefore, only use type-use locations LOWER_BOUND/UPPER_BOUND instead of the IMPLICIT_XX/EXPLICIT_XX alternatives.

    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      TypeUseLocation[] value
      Type uses at which the qualifier is permitted to be applied in source code.
    • Element Detail

      • value

        TypeUseLocation[] value
        Type uses at which the qualifier is permitted to be applied in source code.
        Returns:
        type-use locations declared in this meta-annotation