summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2008-04-05 15:16:36 +0000
committerIulian Dragos <jaguarul@gmail.com>2008-04-05 15:16:36 +0000
commit02975ed50d200f222bc561c335d2aa15b38f65ae (patch)
tree72af4baf7c3d2ec29eb5bc1e565683bf305c58cc
parente5b446654fe016eba7b9d2fe89af191094472bf5 (diff)
downloadscala-02975ed50d200f222bc561c335d2aa15b38f65ae.tar.gz
scala-02975ed50d200f222bc561c335d2aa15b38f65ae.tar.bz2
scala-02975ed50d200f222bc561c335d2aa15b38f65ae.zip
Enhanced @see tag in scaladoc:
- if the text looks like a link, it is turned into a link - if it is a symbol name that can be resolved, it is turned into a link to that symbol - otherwise fall back to old behavior (plain text). Removed two printlns from Definitions (probably debug messages).
-rw-r--r--src/compiler/scala/tools/nsc/doc/ModelFrames.scala1
-rw-r--r--src/compiler/scala/tools/nsc/doc/ModelToXML.scala63
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala2
3 files changed, 57 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
index 3b3a093c2d..f8da165bb9 100644
--- a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
+++ b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
@@ -314,7 +314,6 @@ trait ModelFrames extends ModelExtractor {
</xml:group>
}
}
- def longComment(cmnt: Comment): NodeSeq
val index =
<frameset cols="25%, 75%">
diff --git a/src/compiler/scala/tools/nsc/doc/ModelToXML.scala b/src/compiler/scala/tools/nsc/doc/ModelToXML.scala
index c7895ab25f..bad17af2ee 100644
--- a/src/compiler/scala/tools/nsc/doc/ModelToXML.scala
+++ b/src/compiler/scala/tools/nsc/doc/ModelToXML.scala
@@ -33,7 +33,7 @@ trait ModelToXML extends ModelExtractor {
aref(url, entity.nameString)
}
*/
- def link(entity: Symbol)(implicit frame: Frame): NodeSeq = {
+ def link(entity: Symbol, label: String)(implicit frame: Frame): NodeSeq = {
val url = urlFor(entity)
if (url == null) { // external link (handled by script.js)
val (href, attr) =
@@ -45,9 +45,12 @@ trait ModelToXML extends ModelExtractor {
<a href={Utility.escape(href)} class={attr} target="contentFrame">{name}</a>;
}
else
- aref(url, entity.nameString)
+ aref(url, label)
}
+ def link(entity: Symbol)(implicit frame: Frame): NodeSeq =
+ link(entity, entity.nameString)
+
def link(tpe: Type)(implicit frame: Frame): NodeSeq = {
if (!tpe.typeArgs.isEmpty) {
if (definitions.isFunctionType(tpe)) {
@@ -129,7 +132,7 @@ trait ModelToXML extends ModelExtractor {
}
}
- def longHeader(entity: Entity)(implicit from: Frame): NodeSeq = Group({
+ def longHeader(entity: Entity)(implicit frame: Frame): NodeSeq = Group({
anchor(entity.sym) ++ <dl>
<dt>
{attrsFor(entity)}
@@ -142,7 +145,7 @@ trait ModelToXML extends ModelExtractor {
} ++ {
val cmnt = entity.decodeComment
if (cmnt.isEmpty) NodeSeq.Empty
- else longComment(cmnt.get)
+ else longComment(entity, cmnt.get)
} ++ (entity match {
case entity: ClassOrObject => classBody(entity)
case _ => NodeSeq.Empty
@@ -163,7 +166,7 @@ trait ModelToXML extends ModelExtractor {
}
} ++ <hr/>);
- def longComment(cmnt: Comment): NodeSeq = {
+ def longComment(entity: Entity, cmnt: Comment)(implicit frame: Frame): NodeSeq = {
val attrs = <dl>{
var seq: NodeSeq = NodeSeq.Empty
cmnt.decodeAttributes.foreach{
@@ -173,7 +176,10 @@ trait ModelToXML extends ModelExtractor {
case (option,body) => <dd>{
if (option == null) NodeSeq.Empty;
else decodeOption(tag, option);
- }{parse(body)}</dd>
+ }{ tag match {
+ case "see" => resolveSee(entity.sym, body.trim)
+ case _ => parse(body)
+ }}</dd>
}}
};
seq
@@ -184,6 +190,51 @@ trait ModelToXML extends ModelExtractor {
</xml:group>
}
+ /**
+ * Try to be smart about @see elements. If the body looks like a link, turn it into
+ * a link. If it can be resolved in the symbol table, turn it into a link to the referenced
+ * entity.
+ */
+ private def resolveSee(owner: Symbol, body: String)(implicit frame: Frame): NodeSeq = {
+ /** find a class either in the root package, in the current class or in the current package. */
+ def findClass(clsName: String): Symbol = {
+ try { definitions.getClass(clsName) } catch {
+ case f: FatalError =>
+ try { definitions.getMember(owner, clsName.toTypeName) } catch {
+ case f: FatalError =>
+ definitions.getMember(owner.enclosingPackage, clsName.toTypeName)
+ }
+ }
+ }
+
+ if (body.startsWith("http://")
+ || body.startsWith("https://")
+ || body.startsWith("www")) {
+ // a link
+ body.split(" ") match {
+ case Seq(href, txt, rest @ _*) =>
+ <a href={href}>{txt}{rest}</a>
+ case _ =>
+ <a href={body}>{body}</a>
+ }
+ } else try {
+ // treat it like a class or member reference
+ body.split("#") match {
+ case Seq(clazz, member) =>
+ val clazzSym = if (clazz.length == 0) owner.enclClass else findClass(clazz)
+ link(definitions.getMember(clazzSym, member), body)
+ case Seq(clazz, _*) =>
+ link(findClass(clazz), body)
+ case _ =>
+ parse(body)
+ }
+ } catch {
+ case f: FatalError =>
+ log("Error resolving @see: " + f.toString)
+ parse(body)
+ }
+ }
+
def classBody(entity: ClassOrObject)(implicit from: Frame): NodeSeq =
<xml:group>
{categories.mkXML("","\n","")(c => shortList(entity, c)) : NodeSeq}
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index aa5131a445..3c23a8f481 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -328,8 +328,6 @@ trait Definitions {
if (owner == NoSymbol) return NoSymbol
val result = owner.info.nonPrivateMember(name)
if (result == NoSymbol) {
- Console.println(owner.infosString)
- Console.println(owner.info.decls)
throw new FatalError(owner.toString() + " does not have a member " + name)
}
result