Introduce DeprecatedSinceKotlin annotation
This annotation will be used in the standard library to prevent the new compiler from reporting deprecation diagnostics in case an older API version is used (where the declaration was not deprecated yet). #KT-23575 Fixed
This commit is contained in:
committed by
Mikhail Zarechenskiy
parent
b2022144e6
commit
0aaf29c045
@@ -37,6 +37,32 @@ public annotation class Deprecated(
|
||||
val level: DeprecationLevel = DeprecationLevel.WARNING
|
||||
)
|
||||
|
||||
/**
|
||||
* Marks the annotated declaration as deprecated. In contrast to [Deprecated], severity of the reported diagnostic is not a constant value,
|
||||
* but differs depending on the API version of the usage (the value of the `-api-version` argument when compiling the module where
|
||||
* the usage is located). If the API version is greater or equal than [hiddenSince], the declaration will not be accessible from the code
|
||||
* (as if it was deprecated with level [DeprecationLevel.HIDDEN]), otherwise if the API version is greater or equal than [errorSince],
|
||||
* the usage will be marked as an error (as with [DeprecationLevel.ERROR]), otherwise if the API version is greater or equal
|
||||
* than [warningSince], the usage will be marked as a warning (as with [DeprecationLevel.WARNING]), otherwise the annotation is ignored.
|
||||
*
|
||||
* @property message the message explaining the deprecation and recommending an alternative API to use.
|
||||
* @property replaceWith if present, specifies a code fragment which should be used as a replacement for
|
||||
* the deprecated API usage.
|
||||
* @property warningSince the version, since which this deprecation should be reported as a warning.
|
||||
* @property errorSince the version, since which this deprecation should be reported as a error.
|
||||
* @property hiddenSince the version, since which the annotated declaration should not be available in code.
|
||||
*/
|
||||
@Target(CLASS, FUNCTION, PROPERTY, ANNOTATION_CLASS, CONSTRUCTOR, PROPERTY_SETTER, PROPERTY_GETTER, TYPEALIAS)
|
||||
@MustBeDocumented
|
||||
@SinceKotlin("1.3")
|
||||
public annotation class DeprecatedSinceKotlin(
|
||||
val message: String,
|
||||
val replaceWith: ReplaceWith = ReplaceWith(""),
|
||||
val warningSince: String = "",
|
||||
val errorSince: String = "",
|
||||
val hiddenSince: String = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* Specifies a code fragment that can be used to replace a deprecated function, property or class. Tools such
|
||||
* as IDEs can automatically apply the replacements specified through this annotation.
|
||||
|
||||
@@ -211,6 +211,7 @@ public abstract class KotlinBuiltIns {
|
||||
public final FqNameUnsafe longRange = rangesFqName("LongRange");
|
||||
|
||||
public final FqName deprecated = fqName("Deprecated");
|
||||
public final FqName deprecatedSinceKotlin = fqName("DeprecatedSinceKotlin");
|
||||
public final FqName deprecationLevel = fqName("DeprecationLevel");
|
||||
public final FqName replaceWith = fqName("ReplaceWith");
|
||||
public final FqName extensionFunctionType = fqName("ExtensionFunctionType");
|
||||
@@ -1116,6 +1117,7 @@ public abstract class KotlinBuiltIns {
|
||||
return classFqNameEquals(descriptor, FQ_NAMES.cloneable);
|
||||
}
|
||||
|
||||
// TODO: support DeprecatedSinceKotlin
|
||||
public static boolean isDeprecated(@NotNull DeclarationDescriptor declarationDescriptor) {
|
||||
if (declarationDescriptor.getOriginal().getAnnotations().hasAnnotation(FQ_NAMES.deprecated)) return true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user