diff options
author | Paul Phillips <paulp@improving.org> | 2011-03-30 22:47:00 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-03-30 22:47:00 +0000 |
commit | 518cc3af73729574ba3364f53adf1ff66a356513 (patch) | |
tree | a21215973ea6297d40cf1ef9fc2d3ec8805a39fc | |
parent | 96965c4459c318afd97b4024f8509a5c4988a3d0 (diff) | |
download | scala-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.
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/model/comment/CommentFactory.scala | 24 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Definitions.scala | 4 | ||||
-rw-r--r-- | src/library/scala/util/logging/Logged.scala | 2 |
3 files changed, 18 insertions, 12 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. diff --git a/src/library/scala/util/logging/Logged.scala b/src/library/scala/util/logging/Logged.scala index e07c14da6b..01757e1bfa 100644 --- a/src/library/scala/util/logging/Logged.scala +++ b/src/library/scala/util/logging/Logged.scala @@ -18,7 +18,7 @@ package scala.util.logging // The user of the library instantiates: val x = new MyClass() with ConsoleLogger }}} - * and the logging is sent to the [[ConsoleLogger]] object. + * and the logging is sent to the [[scala.util.logging.ConsoleLogger]] object. */ trait Logged { /** This method should log the message given as argument somewhere |