Skip to content

Commit

Permalink
Support java Deprecated on Scala symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Mar 4, 2024
1 parent 2023c30 commit a802823
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/main/scala/com/typesafe/genjavadoc/AST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ trait AST { this: TransformCake =>
def fabricateParams: Boolean

case class DeprecationInfo(msg: String, since: String) {
def maybeDot = if (msg.endsWith(".")) " " else ". "
def maybeSinceDot = if (since.endsWith(".")) " " else ". "
def render = s" * @deprecated ${msg}${maybeDot}Since $since${maybeSinceDot}"
def render = {
val rMsg = if (msg.isEmpty) "" else s" ${msg.stripSuffix(".")}."
val rSince = if (since.isEmpty) "" else s" Since ${since.stripSuffix(".")}."
s" * @deprecated$rMsg$rSince"
}

def appendToComment(comment: Seq[String]): Seq[String] = comment.toVector match {
case init :+ " */" =>
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/com/typesafe/genjavadoc/BasicTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ trait BasicTransform { this: TransformCake =>
private def deprecationInfo(d: ImplDef): Option[DeprecationInfo] = deprecationInfo(d.symbol)
private def deprecationInfo(symbol: Symbol): Option[DeprecationInfo] =
if (symbol.isDeprecated) {
val deprec = symbol.getAnnotation(definitions.DeprecatedAttr).get
Some(DeprecationInfo(deprec.stringArg(0).getOrElse(""), deprec.stringArg(1).getOrElse("")))
// symbol either has `DeprecatedAttr` or `JavaDeprecatedAttr`
val deprec = symbol.getAnnotation(definitions.DeprecatedAttr)
Some(DeprecationInfo(deprec.flatMap(_.stringArg(0)).getOrElse(""), deprec.flatMap(_.stringArg(1)).getOrElse("")))
} else None

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public class DontTouchThis {
* @deprecated This is already deprecated. Since now.
*/
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
/**
* buh!
*
* @deprecated
*/
public void javaDeprecatedThingie () { throw new RuntimeException(); }
/**
* Some methods are forever.
*
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/input/basic/test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ private[it] class DontTouchThis {
*/
@deprecated("This will be ignored", since = "ever")
def alreadyDeprecatedInComment = ()

/**
* buh!
*/
@Deprecated
def javaDeprecatedThingie = ()
}

@deprecated("Les Scalac Voyages Extraordinaire", since = "now")
Expand Down

0 comments on commit a802823

Please sign in to comment.