我正在使用overloaded methods记录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]
等链接不起作用。
答案 0 :(得分:25)
以下似乎可以解决Scala 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.
答案 1 :(得分:8)
通过研究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 {
}
答案 2 :(得分:8)
我仍然感到惊讶的是,让这项工作变得困难以及缺乏scaladoc本身的文档。我决定搜索scala代码库本身,希望有一些有用的例子。我找到的最好的是https://github.com/scala/scala/blob/2.12.x/test/scaladoc/resources/links.scala。希望这对遇到此问题的其他人有用。
答案 3 :(得分:0)