| 1 | /* |
| 2 | * Copyright 2000-2021 JetBrains s.r.o. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.jetbrains.annotations; |
| 17 | |
| 18 | import java.lang.annotation.*; |
| 19 | |
| 20 | /** |
| 21 | * Set of annotations which can be used to specify status of API Element. |
| 22 | * |
| 23 | * @since 18.0.0 |
| 24 | */ |
| 25 | public final class ApiStatus { |
| 26 | |
| 27 | /** |
| 28 | * Prohibited default constructor. |
| 29 | */ |
| 30 | private ApiStatus() { |
| 31 | throw new AssertionError("ApiStatus should not be instantiated"); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * <p>Indicates that a public API of the annotated element (class, method or field) is not in stable state yet. It may be renamed, changed or |
| 36 | * even removed in a future version. This annotation refers to API status only, it doesn't mean that the implementation has |
| 37 | * an 'experimental' quality.</p> |
| 38 | * |
| 39 | * <p>It's safe to use an element marked with this annotation if the usage is located in the same sources codebase as the declaration. However, |
| 40 | * if the declaration belongs to an external library such usages may lead to problems when the library will be updated to another version.</p> |
| 41 | * |
| 42 | * <p>If a package is marked with this annotation, all its containing classes are considered experimental. |
| 43 | * Subpackages of this package are not affected and should be marked independently.</p> |
| 44 | * |
| 45 | * <p>If a type is marked with this annotation, all its members are considered experimental, but its inheritors are not.</p> |
| 46 | * |
| 47 | * <p>If a method is marked with this annotation, overriding methods are not considered experimental.</p> |
| 48 | */ |
| 49 | @Documented |
| 50 | @Retention(RetentionPolicy.CLASS) |
| 51 | @Target({ |
| 52 | ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE |
| 53 | }) |
| 54 | public @interface Experimental {} |
| 55 | |
| 56 | /** |
| 57 | * Indicates that the annotated element (class, method, field, etc) must not be considered as a public API. It's made visible to allow |
| 58 | * usages in other packages of the declaring library, but it must not be used outside of that library. Such elements |
| 59 | * may be renamed, changed or removed in future versions. |
| 60 | * |
| 61 | * <p>If a package is marked with this annotation, all its containing classes are considered internal. |
| 62 | * Subpackages of this package are not affected and should be marked independently.</p> |
| 63 | * |
| 64 | * <p>If a type is marked with this annotation, all its members are considered internal, but its inheritors are not.</p> |
| 65 | * |
| 66 | * <p>If a method is marked with this annotation, overriding methods are not considered internal.</p> |
| 67 | */ |
| 68 | @Documented |
| 69 | @Retention(RetentionPolicy.CLASS) |
| 70 | @Target({ |
| 71 | ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE |
| 72 | }) |
| 73 | public @interface Internal {} |
| 74 | |
| 75 | /** |
| 76 | * <p>Indicates that a public API of the annotated element (class, method or field) is subject to deprecation in a future version. |
| 77 | * It's a weaker variant of {@link Deprecated} annotation. |
| 78 | * The annotated API is not supposed to be used in the new code because a better API exists, |
| 79 | * but it's permitted to postpone the migration of the existing code, therefore the usage is not considered a warning. |
| 80 | * </p> |
| 81 | */ |
| 82 | @Documented |
| 83 | @Retention(RetentionPolicy.CLASS) |
| 84 | @Target({ |
| 85 | ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE |
| 86 | }) |
| 87 | public @interface Obsolete { |
| 88 | /** |
| 89 | * Specifies in which version the API became obsolete. |
| 90 | */ |
| 91 | String since() default ""; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * <p>Indicates that a public API of the annotated element (class, method or field) is subject to removal in a future version. |
| 96 | * It's a stronger variant of {@link Deprecated} annotation.</p> |
| 97 | * |
| 98 | * <p>Since many tools aren't aware of this annotation it should be used as an addition to {@code @Deprecated} annotation |
| 99 | * or {@code @deprecated} Javadoc tag only.</p> |
| 100 | */ |
| 101 | @Documented |
| 102 | @Retention(RetentionPolicy.CLASS) |
| 103 | @Target({ |
| 104 | ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE |
| 105 | }) |
| 106 | public @interface ScheduledForRemoval { |
| 107 | /** |
| 108 | * Specifies in which version the API will be removed. |
| 109 | */ |
| 110 | String inVersion() default ""; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * <p>Indicates that the annotated element firstly appeared in the specified version of the library, so the code using that element |
| 115 | * won't be compatible with older versions of the library. This information may be used by IDEs and static analysis tools. |
| 116 | * This annotation can be used instead of '@since' Javadoc tag if it's needed to keep that information in *.class files or if you need |
| 117 | * to generate them automatically.</p> |
| 118 | */ |
| 119 | @Documented |
| 120 | @Retention(RetentionPolicy.CLASS) |
| 121 | @Target({ |
| 122 | ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE |
| 123 | }) |
| 124 | public @interface AvailableSince { |
| 125 | /** |
| 126 | * Specifies a version where the annotation API firstly appeared. |
| 127 | */ |
| 128 | String value(); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * <p>Indicates that the annotated API class, interface or method <strong>must not be extended, implemented or overridden</strong>.</p> |
| 133 | * |
| 134 | * <p>API class, interface or method may not be marked {@code final} because it is extended by classes of the declaring library |
| 135 | * but it is not supposed to be extended outside the library. Instances of classes and interfaces marked with this annotation |
| 136 | * may be cast to an internal implementing class in the library code, leading to {@code ClassCastException} |
| 137 | * if a different implementation is provided by a client.</p> |
| 138 | * |
| 139 | * <p>New abstract methods may be added to such classes and interfaces in new versions of the library breaking compatibility |
| 140 | * with a client's implementations.</p> |
| 141 | */ |
| 142 | @Documented |
| 143 | @Retention(RetentionPolicy.CLASS) |
| 144 | @Target({ |
| 145 | ElementType.TYPE, ElementType.METHOD |
| 146 | }) |
| 147 | public @interface NonExtendable { } |
| 148 | |
| 149 | /** |
| 150 | * <p>Indicates that the annotated method is part of SPI (Service Provider Interface), which is intended to be |
| 151 | * <strong>only implemented or overridden</strong> but not called by clients of the declaring library. |
| 152 | * If a class or interface is marked with this annotation it means that all its methods can be only overridden.</p> |
| 153 | * |
| 154 | * <p>Although there is a standard mechanism of {@code protected} methods, it is not applicable to interface's methods. |
| 155 | * Also, API method may be made {@code public} to allow calls only from different parts of the declaring library but not outside it.</p> |
| 156 | * |
| 157 | * <p>Signatures of such methods may be changed in new versions of the library in the following steps. Firstly, a method with new signature |
| 158 | * is added to the library delegating to the old method by default. Secondly, all clients implement the new method and remove |
| 159 | * implementations of the old one. This leads to compatibility breakage with code that calls the methods directly.</p> |
| 160 | */ |
| 161 | @Documented |
| 162 | @Retention(RetentionPolicy.CLASS) |
| 163 | @Target({ |
| 164 | ElementType.TYPE, ElementType.METHOD |
| 165 | }) |
| 166 | public @interface OverrideOnly { } |
| 167 | } |