如何消除scaladoc中方法的链接歧义?

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)

  • 我发现ScalDoc无法通过导入解析名称令人憎恶.我拒绝在文档注释中使用完全限定名称. (14认同)
  • 唉,对于复杂类型的签名,这并没有一直对我有用.但是对于更简单的,它确实如此.(我找不到更复杂签名的解决方案.) (2认同)

Mik*_*yer 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 {
}
Run Code Online (Sandbox Code Playgroud)


ste*_*bot 8

我仍然感到惊讶的是,使用这种方法有困难并且缺乏scaladoc本身的文档.我决定搜索scala代码库本身,希望有一些有用的例子.我找到的最好的是https://github.com/scala/scala/blob/2.12.x/​​test/scaladoc/resources/links.scala.希望这对遇到此问题的其他人有用.


Luk*_*ski 8

我发现非常有用的IntelliJ是右键单击要放入 [[ ]] 的方法并选择“复制参考”。

脚步:

  1. 您在其他地方找到了想要引用的方法。

在此处输入图片说明

  1. 右键单击方法名称并选择“复制引用”。

在此处输入图片说明

  1. 您将其粘贴到文档中的 [[ ]] 中(并在其旁边写下您选择的标签,例如“apply(String)”)。

在此处输入图片说明

  1. 瞧。

在此处输入图片说明