Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何消除scaladoc中方法链接的歧义?_Scala_Scala 2.10_Scaladoc_Method Names_Disambiguation - Fatal编程技术网

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

如何消除scaladoc中方法链接的歧义?,scala,scala-2.10,scaladoc,method-names,disambiguation,Scala,Scala 2.10,Scaladoc,Method Names,Disambiguation,我正在用文档记录一个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 docI get scala文件:1:警告:链接目标“

我正在用文档记录一个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
I get

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

  • 对象文档中的方法
    foo[A,B>:A](x:A):B
    [所选]
  • 方法
    foo[A]:对象文档中没有任何内容

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

在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.
通过研究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 {
}

我仍然感到惊讶的是,要让它工作起来有多么困难,而且scaladoc本身缺乏文档。我决定搜索scala代码库本身,希望找到一些有用的示例。我找到的最好的在里面。希望这对遇到此问题的其他人有用。

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

步骤:

  • 你可以找到一个你想在其他地方引用的方法
  • 右键单击方法名称并选择“复制引用”
  • 您可以将其粘贴到文档的[[]中(并在其旁边写上您选择的标签,例如“应用(字符串)”)

  • 使用
    [[Doc.foo()]
    有效吗?我知道,在C#中,当文档中有一个不明确的引用时,当您选择一个没有参数的方法时,您必须使用
    ()
    ,或者拼写参数类型,例如
    foo(string)
    。这里可能类似…@Trustme-I'maDoctor不起作用,抱怨:警告:找不到任何成员链接“Doc.foo()”。如果在这里添加文档,我会很高兴。我发现Bushtoc无法通过导入解析名称,这很糟糕。我拒绝在文档注释中使用完全限定名。显然,只有直接使用scaladoc时才会显示提示。我使用了sbt,但没有显示出来。@Randall Schulz这应该根据这个问题来解决:唉,对于复杂的类型签名,这对我来说并不总是有效的。但对于更简单的,它确实如此。(我没有找到更复杂签名的解决方案。)这个答案对我没有帮助。我试图消除“apply”方法的歧义,这些方法具有相同的类型参数,但参数签名不同。我需要它与Intellij IDEA的“快速文档”(Ctrl-Q)配合使用,以查看方法的scaladoc。“不要在签名中使用空格”——如果有一个隐式参数怎么办?唉,这确实不起作用。您可以尝试在空格前添加\或确保不需要编写隐式参数来消除代码歧义。这在IntelliJ 2019.3.4社区中对我很有效。在阅读你的答案之前,我尝试了很多不同的方法,但都一无所获。非常感谢你。