Skip to content

Commit

Permalink
Don't fail for deprecated lazy vals, fixes lightbend#85.
Browse files Browse the repository at this point in the history
This somewhat fixes lightbend#85 so that genjavadoc does at least not fail. However,
like in the case for deprecated lazy vals with preexisting scaladoc, the
preexisting comment might be lost under some Scala versions.

The reason seems to be that starting from Scala 2.12 positions are reported
in a way that puts the original position on the private `$lzycompute` method
instead of on the accessor. To fix that additional considerations are necessary
to somehow reconcile position information from the lzycompute with the actual
accessor so that existing and generated scaladoc can be merged.
  • Loading branch information
jrudolph committed Sep 18, 2017
1 parent 0ae0a53 commit d898589
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
19 changes: 16 additions & 3 deletions plugin/src/main/scala/com/typesafe/genjavadoc/AST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,22 @@ trait AST { this: TransformCake ⇒
def maybeSinceDot = if (since.endsWith(".")) " " else ". "
def render = s" * @deprecated ${msg}${maybeDot}Since $since${maybeSinceDot}"

def appendToComment(comment: Seq[String]): Seq[String] = comment match {
case Nil => List("/**", render, "*/")
case c => c.dropRight(1) ++ List(" *", render, "*/")
def fullComment = List("/**", render, "*/")

def appendToComment(comment: Seq[String]): Seq[String] = {
comment match {
case Nil => fullComment
case c :: Nil if c.trim.startsWith("//") =>
// sometimes `comment` is just a single line of `// not preceding`. In that case, we just keep that comment line
// and add the deprecation as the complete thing
c +: fullComment
case cs =>
if (!cs.lastOption.exists(_.trim == "*/"))
(cs :+ "// cannot join comments, what happened here? Report at https://github.com/typesafehub/genjavadoc.") ++
fullComment
else
cs.dropRight(1) ++ List(" *", render, "*/")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ public class DeprecatedNoComment {
* @deprecated This is replaced by theShinyNewMethod. Since now.
*/
public void oldMethod () { throw new RuntimeException(); }
private void oldLazyVal$lzycompute () { throw new RuntimeException(); }
/**
* @deprecated This is replaced by theShinyNewLazyVal. Since now.
*/
public void oldLazyVal () { throw new RuntimeException(); }
}
3 changes: 3 additions & 0 deletions plugin/src/test/resources/input/basic/test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ private[it] class DontTouchThis {
class DeprecatedNoComment {
@deprecated("This is replaced by theShinyNewMethod", since = "now")
def oldMethod = ()

@deprecated("This is replaced by theShinyNewLazyVal", since = "now")
lazy val oldLazyVal= ()
}


Expand Down

0 comments on commit d898589

Please sign in to comment.