-->

如何消除歧义链接到scaladoc的方法呢?(How to disambiguate links t

2019-08-17 14:20发布

我记录Scala的类重载方法 。 我怎样才能在scaladoc评论提到他们时,区分它们? 举例来说,如果我有

/**
 * The most important method is [[Doc.foo]].
 */
object Doc {
  def foo[A]: A = throw new UnsupportedOperationException;
  def foo[A,B >: A](x: A): B = x;
}

并运行sbt doc我得到

Doc.scala:1:警告:该链接的目标 “Doc.foo” 是不明确的。 几个(可能过载)成员适合目标:

  • 方法foo[A,B>:A](x:A):B在对象文件[选择]
  • 方法foo[A]:Nothing在对象文档

使用foo[A,B >: A]等的链接不起作用。

Answer 1:

下面,似乎这样的伎俩在斯卡拉2.10。

/**
 * The most important method is [[Doc.foo[A]:A*]].
 */

下面是一些提示scaladoc给我:

[warn] Quick crash course on using Scaladoc links
[warn] ==========================================
[warn] Disambiguating terms and types: Prefix terms with '$' and types with '!' in case both names are in use:
[warn]  - [[scala.collection.immutable.List!.apply class List's apply method]] and
[warn]  - [[scala.collection.immutable.List$.apply object List's apply method]]
[warn] Disambiguating overloaded members: If a term is overloaded, you can indicate the first part of its signature followed by *:
[warn]  - [[[scala.collection.immutable.List$.fill[A](Int)(⇒A):List[A]* Fill with a single parameter]]]
[warn]  - [[[scala.collection.immutable.List$.fill[A](Int,Int)(⇒A):List[List[A]]* Fill with a two parameters]]]
[warn] Notes: 
[warn]  - you can use any number of matching square brackets to avoid interference with the signature
[warn]  - you can use \. to escape dots in prefixes (don't forget to use * at the end to match the signature!)
[warn]  - you can use \# to escape hashes, otherwise they will be considered as delimiters, like dots.


Answer 2:

我发现了复杂的签名的解决方案(显然是独特的解决方案),通过研究scaladoc的文档。

  • 不要在签名使用空间
  • 使用参数名称
  • 对于参数类型以及返回类型,前缀的所有点用一个反斜杠\
  • 使用星*在签字结束
  • 使用完整的签名(因为不明确的签名向你求婚)。 这一步是可选的,您可以更早停止签名,只要你完成它*

例:

package org.my.stuff

class ReturnType

object Foo {
  class Bar {
    def lara(s: String): String = ???
    def lara(s: Foo.Bar): ReturnType= ???
  }
}

/** [[org.my.stuff.Foo$.Bar.lara(s:org\.my\.stuff\.Foo\.Bar):org\.my\.stuff\.ReturnType* The link to the right lara method]]
  */
object DocumentFooBarBingComplex {
}


Answer 3:

我仍然惊讶于它是多么的困难得到这个工作和scaladoc本身缺少文档。 我决定寻找Scala代码基地本身的一些有用的例子希望。 我发现最好的是在https://github.com/scala/scala/blob/2.12.x/​​test/scaladoc/resources/links.scala 。 但愿这是为别人谁碰到这个来用。



文章来源: How to disambiguate links to methods in scaladoc?