|
| 1 | +/** |
| 2 | + * Checker Framework qualifiers Copyright 2004-present by the Checker Framework developers |
| 3 | + * |
| 4 | + * <p>MIT License: |
| 5 | + * |
| 6 | + * <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| 7 | + * and associated documentation files (the "Software"), to deal in the Software without restriction, |
| 8 | + * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| 9 | + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| 10 | + * furnished to do so, subject to the following conditions: |
| 11 | + * |
| 12 | + * <p>The above copyright notice and this permission notice shall be included in all copies or |
| 13 | + * substantial portions of the Software. |
| 14 | + * |
| 15 | + * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| 16 | + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 17 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + */ |
| 21 | +package org.checkerframework.framework.qual; |
| 22 | + |
| 23 | +import java.lang.annotation.Annotation; |
| 24 | +import java.lang.annotation.Documented; |
| 25 | +import java.lang.annotation.ElementType; |
| 26 | +import java.lang.annotation.Repeatable; |
| 27 | +import java.lang.annotation.Retention; |
| 28 | +import java.lang.annotation.RetentionPolicy; |
| 29 | +import java.lang.annotation.Target; |
| 30 | + |
| 31 | +/** |
| 32 | + * Applied to a declaration of a package, type, method, variable, etc., specifies that the given |
| 33 | + * annotation should be the default. The default is applied to type uses within the declaration for |
| 34 | + * which no other annotation is explicitly written. (The default is not applied to the "parametric |
| 35 | + * locations": class declarations, type parameter declarations, and type parameter uses.) If |
| 36 | + * multiple {@code DefaultQualifier} annotations are in scope, the innermost one takes precedence. |
| 37 | + * DefaultQualifier takes precedence over {@link DefaultQualifierInHierarchy}. |
| 38 | + * |
| 39 | + * <p>You may write multiple {@code @DefaultQualifier} annotations (for unrelated type systems, or |
| 40 | + * with different {@code locations} fields) at the same location. For example: |
| 41 | + * |
| 42 | + * <pre> |
| 43 | + * @DefaultQualifier(NonNull.class) |
| 44 | + * @DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.IMPLICIT_UPPER_BOUND) |
| 45 | + * @DefaultQualifier(Tainted.class) |
| 46 | + * class MyClass { ... } |
| 47 | + * </pre> |
| 48 | + * |
| 49 | + * <p>This annotation currently has no effect in stub files. |
| 50 | + * |
| 51 | + * @see org.checkerframework.framework.qual.TypeUseLocation |
| 52 | + * @see DefaultQualifierInHierarchy |
| 53 | + * @see DefaultFor |
| 54 | + * @checker_framework.manual #defaults Default qualifier for unannotated types |
| 55 | + */ |
| 56 | +@Documented |
| 57 | +@Retention(RetentionPolicy.RUNTIME) |
| 58 | +@Target({ |
| 59 | + ElementType.PACKAGE, |
| 60 | + ElementType.TYPE, |
| 61 | + ElementType.CONSTRUCTOR, |
| 62 | + ElementType.METHOD, |
| 63 | + ElementType.FIELD, |
| 64 | + ElementType.LOCAL_VARIABLE, |
| 65 | + ElementType.PARAMETER |
| 66 | +}) |
| 67 | +@Repeatable(DefaultQualifier.List.class) |
| 68 | +public @interface DefaultQualifier { |
| 69 | + |
| 70 | + /** |
| 71 | + * The Class for the default annotation. |
| 72 | + * |
| 73 | + * <p>To prevent affecting other type systems, always specify an annotation in your own type |
| 74 | + * hierarchy. (For example, do not set {@link |
| 75 | + * org.checkerframework.common.subtyping.qual.Unqualified} as the default.) |
| 76 | + */ |
| 77 | + Class<? extends Annotation> value(); |
| 78 | + |
| 79 | + /** |
| 80 | + * Returns the locations to which the annotation should be applied. |
| 81 | + * |
| 82 | + * @return the locations to which the annotation should be applied |
| 83 | + */ |
| 84 | + TypeUseLocation[] locations() default {TypeUseLocation.ALL}; |
| 85 | + |
| 86 | + /** |
| 87 | + * A wrapper annotation that makes the {@link DefaultQualifier} annotation repeatable. |
| 88 | + * |
| 89 | + * <p>Programmers generally do not need to write this. It is created by Java when a programmer |
| 90 | + * writes more than one {@link DefaultQualifier} annotation at the same location. |
| 91 | + */ |
| 92 | + @Documented |
| 93 | + @Retention(RetentionPolicy.RUNTIME) |
| 94 | + @Target({ |
| 95 | + ElementType.PACKAGE, |
| 96 | + ElementType.TYPE, |
| 97 | + ElementType.CONSTRUCTOR, |
| 98 | + ElementType.METHOD, |
| 99 | + ElementType.FIELD, |
| 100 | + ElementType.LOCAL_VARIABLE, |
| 101 | + ElementType.PARAMETER |
| 102 | + }) |
| 103 | + public static @interface List { |
| 104 | + /** |
| 105 | + * Return the repeatable annotations. |
| 106 | + * |
| 107 | + * @return the repeatable annotations |
| 108 | + */ |
| 109 | + DefaultQualifier[] value(); |
| 110 | + } |
| 111 | +} |
0 commit comments