Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support java Deprecated on Scala symbols #348

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 additions & 0 deletions src/test/resources/patches/2.12.18.patch
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@
+ public void akka$persistence$testkit$EventStorage$_setter_$DefaultPolicy_$eq (akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll x$1) ;
+ public akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll DefaultPolicy () ;
}
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
@@ -12,8 +12,6 @@
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
/**
* buh!
- *
- * @deprecated
*/
public void javaDeprecatedThingie () { throw new RuntimeException(); }
/**
11 changes: 11 additions & 0 deletions src/test/resources/patches/2.12.19.patch
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@
+ public void akka$persistence$testkit$EventStorage$_setter_$DefaultPolicy_$eq (akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll x$1) ;
+ public akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll DefaultPolicy () ;
}
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
@@ -12,8 +12,6 @@
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
/**
* buh!
- *
- * @deprecated
*/
public void javaDeprecatedThingie () { throw new RuntimeException(); }
/**
11 changes: 11 additions & 0 deletions src/test/resources/patches/2.12.20.patch
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@
+ public void akka$persistence$testkit$EventStorage$_setter_$DefaultPolicy_$eq (akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll x$1) ;
+ public akka.persistence.testkit.ProcessingPolicy.DefaultPolicies<akka.persistence.testkit.JournalOperation>.PassAll DefaultPolicy () ;
}
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
@@ -12,8 +12,6 @@
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
/**
* buh!
- *
- * @deprecated
*/
public void javaDeprecatedThingie () { throw new RuntimeException(); }
/**
11 changes: 11 additions & 0 deletions src/test/resources/patches/2.13.11.patch
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,14 @@
-public interface X extends scala.Serializable, akka.rk.buh.is.it.Y<akka.rk.buh.is.it.A> {
+public interface X extends java.io.Serializable, akka.rk.buh.is.it.Y<akka.rk.buh.is.it.A> {
}
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
@@ -12,8 +12,6 @@
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
/**
* buh!
- *
- * @deprecated
*/
public void javaDeprecatedThingie () { throw new RuntimeException(); }
/**
11 changes: 11 additions & 0 deletions src/test/resources/patches/2.13.12.patch
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,14 @@
-public interface X extends scala.Serializable, akka.rk.buh.is.it.Y<akka.rk.buh.is.it.A> {
+public interface X extends java.io.Serializable, akka.rk.buh.is.it.Y<akka.rk.buh.is.it.A> {
}
--- target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
+++ target/expected_output/basic/akka/rk/buh/is/it/DontTouchThis.java
@@ -12,8 +12,6 @@
public void alreadyDeprecatedInComment () { throw new RuntimeException(); }
/**
* buh!
- *
- * @deprecated
*/
public void javaDeprecatedThingie () { throw new RuntimeException(); }
/**
2 changes: 1 addition & 1 deletion src/test/scala/com/typesafe/genjavadoc/BasicSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BasicSpec extends CompilerSpec {
if (new java.io.File(patchFile).exists) { // we have a patch to apply to expected output for this scala version
"rm -rf target/expected_output".! // cleanup from previous runs
"cp -r src/test/resources/expected_output target/".! // copy expected output to a place which is going to be patched
s"patch -p0 -i $patchFile".! // path expected output
s"patch -p0 --no-backup-if-mismatch -i $patchFile".! // path expected output
"target/expected_output/basic"
} else {
"src/test/resources/expected_output/basic"
Expand Down
Loading