Pet*_*lák 29 scala method-names disambiguation scaladoc scala-2.10
我正在使用重载方法记录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;
}
Run Code Online (Sandbox Code Playgroud)
sbt doc
我跑了
Doc.scala:1:警告:链接目标"Doc.foo"不明确.几个(可能是超载的)成员符合目标:
foo[A,B>:A](x:A):B
对象Doc中的方法[已选择]foo[A]:Nothing
对象Doc中的方法
使用foo[A,B >: A]
等链接不起作用.
Bri*_*Hsu 27
以下似乎可以解决Scala 2.10中的问题.
/**
* The most important method is [[Doc.foo[A]:A*]].
*/
Run Code Online (Sandbox Code Playgroud)
这里有一些提示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.
Run Code Online (Sandbox Code Playgroud)
通过研究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 {
}
Run Code Online (Sandbox Code Playgroud)
我仍然感到惊讶的是,使用这种方法有困难并且缺乏scaladoc本身的文档.我决定搜索scala代码库本身,希望有一些有用的例子.我找到的最好的是https://github.com/scala/scala/blob/2.12.x/test/scaladoc/resources/links.scala.希望这对遇到此问题的其他人有用.
我发现非常有用的IntelliJ
是右键单击要放入 [[ ]] 的方法并选择“复制参考”。
脚步: