summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Ureche <vlad.ureche@gmail.com>2012-05-03 02:54:27 +0200
committerPaul Phillips <paulp@improving.org>2012-05-02 18:06:41 -0700
commitb6e989fbf63c9f47acfb54175241b42fdfbfe51b (patch)
treef1af4d441be6c1e903b09eca307b6609bf572ff2
parent00b22ed4a307b3c49a09a03508a28a933aeb1a9f (diff)
downloadscala-b6e989fbf63c9f47acfb54175241b42fdfbfe51b.tar.gz
scala-b6e989fbf63c9f47acfb54175241b42fdfbfe51b.tar.bz2
scala-b6e989fbf63c9f47acfb54175241b42fdfbfe51b.zip
Fixes the backticks in use case signature crash
Suggested by Simon in https://groups.google.com/forum/?hl=en&fromgroups#!topic/scala-internals/z7s1CCRCz74 Now it eliminates backticks and gracefully bails out with an error message when it can't remove the wiki syntax.
-rwxr-xr-xsrc/compiler/scala/tools/nsc/ast/DocComments.scala25
-rw-r--r--test/scaladoc/run/usecase-var-expansion.check4
-rw-r--r--test/scaladoc/run/usecase-var-expansion.scala26
3 files changed, 50 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/DocComments.scala b/src/compiler/scala/tools/nsc/ast/DocComments.scala
index b3ed446563..028c5741c9 100755
--- a/src/compiler/scala/tools/nsc/ast/DocComments.scala
+++ b/src/compiler/scala/tools/nsc/ast/DocComments.scala
@@ -383,7 +383,7 @@ trait DocComments { self: Global =>
}
// !!! todo: inherit from Comment?
- case class DocComment(raw: String, pos: Position = NoPosition) {
+ case class DocComment(raw: String, pos: Position = NoPosition, codePos: Position = NoPosition) {
/** Returns:
* template: the doc comment minus all @define and @usecase sections
@@ -412,7 +412,7 @@ trait DocComments { self: Global =>
val comment = "/** " + raw.substring(commentStart, end) + "*/"
val commentPos = subPos(commentStart, end)
- UseCase(DocComment(comment, commentPos), code, codePos)
+ UseCase(DocComment(comment, commentPos, codePos), code, codePos)
}
private def subPos(start: Int, end: Int) =
@@ -461,7 +461,18 @@ trait DocComments { self: Global =>
findIn(classes ::: List(pkgs.head, definitions.RootClass))
}
- def getType(str: String): Type = {
+ def getType(_str: String, variable: String): Type = {
+ /*
+ * work around the backticks issue suggested by Simon in
+ * https://groups.google.com/forum/?hl=en&fromgroups#!topic/scala-internals/z7s1CCRCz74
+ * ideally, we'd have a removeWikiSyntax method in the CommentFactory to completely eliminate the wiki markup
+ */
+ val str =
+ if (_str.length >= 2 && _str.startsWith("`") && _str.endsWith("`"))
+ _str.substring(1, _str.length - 2)
+ else
+ _str
+
def getParts(start: Int): List[String] = {
val end = skipIdent(str, start)
if (end == start) List()
@@ -471,7 +482,11 @@ trait DocComments { self: Global =>
}
}
val parts = getParts(0)
- assert(parts.nonEmpty, "parts is empty '" + str + "' in site " + site)
+ if (parts.isEmpty) {
+ reporter.error(comment.codePos, "Incorrect variable expansion for " + variable + " in use case. Does the " +
+ "variable expand to wiki syntax when documenting " + site + "?")
+ return ErrorType
+ }
val partnames = (parts.init map newTermName) :+ newTypeName(parts.last)
val (start, rest) = parts match {
case "this" :: _ => (site.thisType, partnames.tail)
@@ -490,7 +505,7 @@ trait DocComments { self: Global =>
for (alias <- aliases) yield
lookupVariable(alias.name.toString.substring(1), site) match {
case Some(repl) =>
- val tpe = getType(repl.trim)
+ val tpe = getType(repl.trim, alias.name.toString)
if (tpe != NoType) tpe
else {
val alias1 = alias.cloneSymbol(definitions.RootClass, alias.rawflags, newTypeName(repl))
diff --git a/test/scaladoc/run/usecase-var-expansion.check b/test/scaladoc/run/usecase-var-expansion.check
new file mode 100644
index 0000000000..3faa4735c0
--- /dev/null
+++ b/test/scaladoc/run/usecase-var-expansion.check
@@ -0,0 +1,4 @@
+newSource:8: error: Incorrect variable expansion for $Coll in use case. Does the variable expand to wiki syntax when documenting class Test2?
+ * @usecase def foo: $Coll[T]
+ ^
+Done.
diff --git a/test/scaladoc/run/usecase-var-expansion.scala b/test/scaladoc/run/usecase-var-expansion.scala
new file mode 100644
index 0000000000..e86ea4a835
--- /dev/null
+++ b/test/scaladoc/run/usecase-var-expansion.scala
@@ -0,0 +1,26 @@
+import scala.tools.nsc.doc.model._
+import scala.tools.partest.ScaladocModelTest
+import language._
+
+object Test extends ScaladocModelTest {
+
+ override def code = """
+ /**
+ * @define Coll `Test`
+ */
+ class Test[T] {
+ /**
+ * member $Coll
+ * @usecase def foo: $Coll[T]
+ * usecase $Coll
+ */
+ def foo(implicit err: String): Test[T] = sys.error(err)
+ }
+
+ /** @define Coll {{{some `really` < !! >> invalid $$$ thing}}} */
+ class Test2[T] extends Test[Int]
+ """
+
+ def scaladocSettings = ""
+ def testModel(root: Package) = ()
+}