forked from scala/scala
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements `apiStatus ` annotation as a generic form of `deprecated` annotation. `apiStatus` takes `category` and `defaultAction` parameters, corresponding to configurable warning's category and action. One of the usage is to trigger compiler error from the library when a method is invoked to display migration message. Another usage would be to denote bincompat status of the API as warning. This is a resend of scala#7790 based on the configurable warnings. Ref scala#8373 / https://twitter.com/not_xuwei_k/status/1240354073297268737
- Loading branch information
Showing
10 changed files
with
180 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Scala (https://www.scala-lang.org) | ||
* | ||
* Copyright EPFL and Lightbend, Inc. | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package scala.annotation | ||
|
||
import scala.annotation.meta._ | ||
|
||
/** | ||
* An annotation to denote the API status. | ||
* | ||
* @param message the advisory to print during compilation | ||
* @param category a string identifying the categorization of the restriction | ||
* @param since a string identifying the first version in which the status is applied | ||
* @param defaultAction the default severity of the restriction when the annotee is referenced | ||
* @since 2.13.2 | ||
* @see [[scala.annotation.apiStatus.Action]] | ||
* @see [[scala.annotation.apiStatus.Category]] | ||
*/ | ||
@getter @setter @beanGetter @beanSetter @companionClass @companionMethod | ||
class apiStatus( | ||
message: String, | ||
category: String, | ||
since: String = "", | ||
defaultAction: String = apiStatus.Action.Warning) extends scala.annotation.StaticAnnotation | ||
|
||
object apiStatus { | ||
object Action { | ||
final val Error = "error" | ||
final val Warning = "warning" | ||
final val WarningSummary = "warning-summary" | ||
final val WarningVerbose = "warning-verbose" | ||
final val Info = "info" | ||
final val InfoSummary = "info-summary" | ||
final val InfoVerbose = "info-verbose" | ||
final val Silent = "silent" | ||
} | ||
|
||
object Category { | ||
final val ForRemoval = "for-removal" | ||
final val InternalOnly = "internal-only" | ||
final val ApiMayChange = "api-may-change" | ||
final val Mistake = "mistake" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
report-deprecated-error.scala:26: error: method <<= is removed; use := syntax instead (foo-lib 1.0) | ||
<<=() | ||
^ | ||
report-deprecated-error.scala:28: warning: should DSL is incubating, and future compatibility is not guaranteed (foo-lib 1.0) | ||
"bar" should { | ||
^ | ||
1 warning | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import scala.annotation.apiStatus | ||
|
||
package foo { | ||
object syntax { | ||
@apiStatus( | ||
"method <<= is removed; use := syntax instead", | ||
category = apiStatus.Category.ForRemoval, | ||
since = "foo-lib 1.0", | ||
defaultAction = apiStatus.Action.Error, | ||
) | ||
def <<=() = ??? | ||
|
||
@apiStatus( | ||
"should DSL is incubating, and future compatibility is not guaranteed", | ||
category = apiStatus.Category.ApiMayChange, | ||
since = "foo-lib 1.0", | ||
) | ||
implicit class ShouldDSL(s: String) { | ||
def should(o: String): Unit = () | ||
} | ||
} | ||
} | ||
|
||
object Test1 { | ||
import foo.syntax._ | ||
<<=() | ||
|
||
"bar" should { | ||
"something" | ||
} | ||
} |