summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-30 22:47:00 +0000
committerPaul Phillips <paulp@improving.org>2011-03-30 22:47:00 +0000
commit518cc3af73729574ba3364f53adf1ff66a356513 (patch)
treea21215973ea6297d40cf1ef9fc2d3ec8805a39fc /src/compiler
parent96965c4459c318afd97b4024f8509a5c4988a3d0 (diff)
downloadscala-518cc3af73729574ba3364f53adf1ff66a356513.tar.gz
scala-518cc3af73729574ba3364f53adf1ff66a356513.tar.bz2
scala-518cc3af73729574ba3364f53adf1ff66a356513.zip
Warn about unqualified names in scaladoc links ...
Warn about unqualified names in scaladoc links because they don't work. I think it would be better to just make them work, but the way things are structured it looks involved. Closes #3696, no review.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala24
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala4
2 files changed, 17 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala b/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala
index 02fadb94fd..e332b28c67 100644
--- a/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala
@@ -21,7 +21,7 @@ import util.{NoPosition, Position}
trait CommentFactory { thisFactory: ModelFactory with CommentFactory =>
val global: Global
- import global.reporter
+ import global.{ reporter, definitions }
protected val commentCache = mutable.HashMap.empty[(global.Symbol, TemplateImpl), Comment]
@@ -674,7 +674,7 @@ trait CommentFactory { thisFactory: ModelFactory with CommentFactory =>
}
def link(): Inline = {
- val SchemeUri = new Regex("""([^:]+:.*)""")
+ val SchemeUri = """([^:]+:.*)""".r
jump("[[")
readUntil { check("]]") || check(" ") }
val target = getRead()
@@ -685,18 +685,20 @@ trait CommentFactory { thisFactory: ModelFactory with CommentFactory =>
})
else None
jump("]]")
+
(target, title) match {
- case (SchemeUri(uri), Some(title)) =>
- Link(uri, title)
- case (SchemeUri(uri), None) =>
- Link(uri, Text(uri))
- case (qualName, None) =>
- entityLink(qualName)
- case (qualName, Some(text)) =>
- reportError(pos, "entity link to " + qualName + " cannot have a custom title'" + text + "'")
+ case (SchemeUri(uri), optTitle) =>
+ Link(uri, optTitle getOrElse Text(uri))
+ case (qualName, optTitle) =>
+ optTitle foreach (text => reportError(pos, "entity link to " + qualName + " cannot have a custom title'" + text + "'"))
+ // XXX rather than warning here we should allow unqualified names
+ // to refer to members of the same package. The "package exists"
+ // exclusion is because [[scala]] is used in some scaladoc.
+ if (!qualName.contains(".") && !definitions.packageExists(qualName))
+ reportError(pos, "entity link to " + qualName + " should be a fully qualified name")
+
entityLink(qualName)
}
-
}
/* UTILITY */
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index 8166b36c31..8977989e21 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -614,6 +614,10 @@ trait Definitions extends reflect.generic.StandardDefinitions {
case result => result
}
}
+ def packageExists(packageName: String): Boolean = {
+ try getModuleOrClass(newTermName(packageName)).isPackage
+ catch { case _: MissingRequirementError => false }
+ }
/** If you're looking for a class, pass a type name.
* If a module, a term name.