Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I document vals in pattern definitions

Tags:

scala

scaladoc

I would like to create ScalaDoc entries to every val and def of my class. The problem is that the vals lie inside a pattern definition, and don't know how to use the /** */ syntax.

Example:

class C(id: String) {
   val (part1, part2) = {
         .....
         (expr1, expr2)
   }
}

How do I document part1 and part2?

I've read before asking this documentation about ScalaDoc.

like image 476
david.perez Avatar asked Oct 20 '22 04:10

david.perez


1 Answers

It should be

  val (
    /** Part one. */
    x,
    /** Part two. */
    y
  ) = (1, 2)

but for a flawed heuristic

/** To prevent doc comments attached to expressions from leaking out of scope
 *  onto the next documentable entity, they are discarded upon passing a right
 *  brace, bracket, or parenthesis.
 */
def discardDocBuffer(): Unit = ()

Under -Xlint you will see

[warn] /home/apm/goofy/src/main/scala/docked.scala:10: discarding unmoored doc comment
[warn]     /** Part two. */
[warn]     ^

Maybe the heuristic could be improved to discard only if no doc is discovered on the enclosing entity.

like image 114
som-snytt Avatar answered Oct 26 '22 22:10

som-snytt