Introduce SubclassOptInRequired annotation (see KT-41886)

This commit is contained in:
Mikhail Glukhikh
2022-07-12 13:30:06 +02:00
committed by teamcity
parent bd085495bd
commit 3f96626b40
5 changed files with 48 additions and 0 deletions
@@ -55,3 +55,27 @@ public annotation class RequiresOptIn(
public annotation class OptIn(
vararg val markerClass: KClass<out Annotation>
)
/**
* Forbids creation of subclasses/sub-interfaces from the annotated class/interface without explicit OptIn.
*
* This annotation is devoted to specific case when we want subclassing to be experimental.
* In this case we annotated the base class or interface with [SubclassOptInRequired].
* Without an explicit opt-in we have a compilation error/warning on the subclass/sub-interface after that.
*
* There are three ways to negate this error/warning:
* <ol><li>Annotate subclass or interface with the marker annotation. In this case opt-in is propagated.</li>
* <li>Annotate subclass or interface with [OptIn]. In this case opt-in isn't propagated.</li>
* <li>Annotate subclass or interface with [SubclassOptInRequired]. In this case opt-in is propagated to subclasses/interfaces only.</li>
* </ol>
*
* Note that [SubclassOptInRequired] does not negate an opt-in usage error itself.
*
* @property markerClass an opt-in marker to be required
*/
@Target(CLASS)
@Retention(BINARY)
@SinceKotlin("1.8")
public annotation class SubclassOptInRequired(
val markerClass: KClass<out Annotation>
)