Skip to content

Commit a8df5ce

Browse files
committed
Support java Deprecated on Scala symbols
1 parent 2023c30 commit a8df5ce

File tree

9 files changed

+75
-5
lines changed

9 files changed

+75
-5
lines changed

src/main/scala/com/typesafe/genjavadoc/AST.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ trait AST { this: TransformCake =>
9696
def fabricateParams: Boolean
9797

9898
case class DeprecationInfo(msg: String, since: String) {
99-
def maybeDot = if (msg.endsWith(".")) " " else ". "
100-
def maybeSinceDot = if (since.endsWith(".")) " " else ". "
101-
def render = s" * @deprecated ${msg}${maybeDot}Since $since${maybeSinceDot}"
99+
def render = {
100+
val rMsg = if (msg.isEmpty) "" else s" ${msg.stripSuffix(".")}."
101+
val rSince = if (since.isEmpty) "" else s" Since ${since.stripSuffix(".")}."
102+
s" * @deprecated$rMsg$rSince"
103+
}
102104

103105
def appendToComment(comment: Seq[String]): Seq[String] = comment.toVector match {
104106
case init :+ " */" =>

src/main/scala/com/typesafe/genjavadoc/BasicTransform.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ trait BasicTransform { this: TransformCake =>
160160
private def deprecationInfo(d: ImplDef): Option[DeprecationInfo] = deprecationInfo(d.symbol)
161161
private def deprecationInfo(symbol: Symbol): Option[DeprecationInfo] =
162162
if (symbol.isDeprecated) {
163-
val deprec = symbol.getAnnotation(definitions.DeprecatedAttr).get
164-
Some(DeprecationInfo(deprec.stringArg(0).getOrElse(""), deprec.stringArg(1).getOrElse("")))
163+
// symbol either has `DeprecatedAttr` or `JavaDeprecatedAttr`
164+
val deprec = symbol.getAnnotation(definitions.DeprecatedAttr)
165+
Some(DeprecationInfo(deprec.flatMap(_.stringArg(0)).getOrElse(""), deprec.flatMap(_.stringArg(1)).getOrElse("")))
165166
} else None
166167

167168
}

src/test/resources/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public class DontTouchThis {
1010
* @deprecated This is already deprecated. Since now.
1111
*/
1212
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
13+
/**
14+
* buh!
15+
*
16+
* @deprecated
17+
*/
18+
public void javaDeprecatedThingie () { throw new RuntimeException(); }
1319
/**
1420
* Some methods are forever.
1521
*

src/test/resources/input/basic/test.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ private[it] class DontTouchThis {
275275
*/
276276
@deprecated("This will be ignored", since = "ever")
277277
def alreadyDeprecatedInComment = ()
278+
279+
/**
280+
* buh!
281+
*/
282+
@Deprecated
283+
def javaDeprecatedThingie = ()
278284
}
279285

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

src/test/resources/patches/2.12.18.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,14 @@
6969
+ public void akka$persistence$testkit$EventStorage$_setter_$DefaultPolicy_$eq (akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll x$1) ;
7070
+ public akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll DefaultPolicy () ;
7171
}
72+
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
73+
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
74+
@@ -12,8 +12,6 @@
75+
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
76+
/**
77+
* buh!
78+
- *
79+
- * @deprecated
80+
*/
81+
public void javaDeprecatedThingie () { throw new RuntimeException(); }
82+
/**

src/test/resources/patches/2.12.19.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,14 @@
6969
+ public void akka$persistence$testkit$EventStorage$_setter_$DefaultPolicy_$eq (akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll x$1) ;
7070
+ public akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll DefaultPolicy () ;
7171
}
72+
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
73+
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
74+
@@ -12,8 +12,6 @@
75+
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
76+
/**
77+
* buh!
78+
- *
79+
- * @deprecated
80+
*/
81+
public void javaDeprecatedThingie () { throw new RuntimeException(); }
82+
/**

src/test/resources/patches/2.12.20.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,14 @@
6969
+ public void akka$persistence$testkit$EventStorage$_setter_$DefaultPolicy_$eq (akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll x$1) ;
7070
+ public akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll DefaultPolicy () ;
7171
}
72+
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
73+
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
74+
@@ -12,8 +12,6 @@
75+
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
76+
/**
77+
* buh!
78+
- *
79+
- * @deprecated
80+
*/
81+
public void javaDeprecatedThingie () { throw new RuntimeException(); }
82+
/**

src/test/resources/patches/2.13.11.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,14 @@
259259
-public interface X extends scala.Serializable, akka.rk.buh.is.it.Y<akka.rk.buh.is.it.A> {
260260
+public interface X extends java.io.Serializable, akka.rk.buh.is.it.Y<akka.rk.buh.is.it.A> {
261261
}
262+
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
263+
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
264+
@@ -12,8 +12,6 @@
265+
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
266+
/**
267+
* buh!
268+
- *
269+
- * @deprecated
270+
*/
271+
public void javaDeprecatedThingie () { throw new RuntimeException(); }
272+
/**

src/test/resources/patches/2.13.12.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,14 @@
259259
-public interface X extends scala.Serializable, akka.rk.buh.is.it.Y<akka.rk.buh.is.it.A> {
260260
+public interface X extends java.io.Serializable, akka.rk.buh.is.it.Y<akka.rk.buh.is.it.A> {
261261
}
262+
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
263+
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
264+
@@ -12,8 +12,6 @@
265+
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
266+
/**
267+
* buh!
268+
- *
269+
- * @deprecated
270+
*/
271+
public void javaDeprecatedThingie () { throw new RuntimeException(); }
272+
/**

0 commit comments

Comments
 (0)