summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-04-25 17:17:03 +0000
committermichelou <michelou@epfl.ch>2007-04-25 17:17:03 +0000
commit04034834f5ae9c68e1e42d8aef151a2ef7f83fdf (patch)
tree674158e3729efc85c428d128795af5608c08bbc9 /src
parent58c64abc66708912ea67a6934fb84f4fa8217e18 (diff)
downloadscala-04034834f5ae9c68e1e42d8aef151a2ef7f83fdf.tar.gz
scala-04034834f5ae9c68e1e42d8aef151a2ef7f83fdf.tar.bz2
scala-04034834f5ae9c68e1e42d8aef151a2ef7f83fdf.zip
generates constant values in API doc
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/doc/ModelExtractor.scala109
-rw-r--r--src/compiler/scala/tools/nsc/doc/ModelFrames.scala2
-rw-r--r--src/compiler/scala/tools/nsc/doc/ModelToXML.scala92
3 files changed, 105 insertions, 98 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/ModelExtractor.scala b/src/compiler/scala/tools/nsc/doc/ModelExtractor.scala
index 9969aa63f5..8e9d66f735 100644
--- a/src/compiler/scala/tools/nsc/doc/ModelExtractor.scala
+++ b/src/compiler/scala/tools/nsc/doc/ModelExtractor.scala
@@ -75,26 +75,26 @@ trait ModelExtractor {
}
- sealed abstract class Entity(val sym : Symbol) {
- private[ModelExtractor] def sym0 = sym;
+ sealed abstract class Entity(val sym: Symbol) {
+ private[ModelExtractor] def sym0 = sym
- override def toString = sym.toString;
- def comment : Option[String] = global.comments.get(sym);
+ override def toString = sym.toString
+ def comment : Option[String] = global.comments.get(sym)
// comments decoded, now what?
- def attributes = sym.attributes;
+ def attributes = sym.attributes
def decodeComment : Option[Comment] = {
val comment0 = this.comment;
if (comment0.isEmpty) return None;
var comment = comment0.get.trim;
Some(ModelExtractor.this.decodeComment(comment));
}
- protected def accessQualified(core : String, qual : String) = core match {
+ protected def accessQualified(core: String, qual: String) = core match {
case "public" => ""; // assert(qual == null); "";
case core => core + (if (qual == null) "" else "[" + qual + "]");
}
def flagsString = {
- import symtab.Flags;
+ import symtab.Flags
val isLocal = sym.hasFlag(Flags.LOCAL);
val x = if (sym.hasFlag(Flags.PRIVATE)) "private" else if (sym.hasFlag(Flags.PROTECTED)) "protected" else "public";
var string = accessQualified(x, {
@@ -121,74 +121,75 @@ trait ModelExtractor {
def kind : String;
def header = {
}
- def typeParams : List[TypeParam] = Nil;
- def params : List[List[Param]] = Nil;
- def resultType : Option[Type] = None;
- def parents : Iterable[Type] = Nil;
- def lo : Option[Type] = sym.info match {
+ def typeParams : List[TypeParam] = Nil
+ def params: List[List[Param]] = Nil
+ def resultType: Option[Type] = None
+ def parents: Iterable[Type] = Nil
+ def lo: Option[Type] = sym.info match {
case TypeBounds(lo,hi) if decode(lo.symbol) != definitions.AllClass => Some(lo);
case _ => None;
}
def hi : Option[Type] = sym.info match {
- case TypeBounds(lo,hi) if decode(hi.symbol) != definitions.AnyClass => Some(hi);
- case _ => None;
+ case TypeBounds(lo,hi) if decode(hi.symbol) != definitions.AnyClass => Some(hi)
+ case _ => None
}
def variance = {
- import symtab.Flags._;
- if (sym.hasFlag(COVARIANT)) "+";
- else if (sym.hasFlag(CONTRAVARIANT)) "-";
- else "";
- }
- def overridden : Iterable[Symbol] = {
- Nil;
+ import symtab.Flags._
+ if (sym hasFlag COVARIANT) "+"
+ else if (sym hasFlag CONTRAVARIANT) "-"
+ else ""
}
+ def overridden: Iterable[Symbol] = Nil
}
- class Param(sym : Symbol) extends Entity(sym) {
- override def resultType = Some(sym.tpe);
+
+ class Param(sym: Symbol) extends Entity(sym) {
+ override def resultType = Some(sym.tpe)
//def kind = if (sym.isPublic) "val" else "";
- def kind = "";
+ def kind = ""
}
- class ConstructorParam(sym : Symbol) extends Param(sym) {
+
+ class ConstructorParam(sym: Symbol) extends Param(sym) {
override protected def accessQualified(core : String, qual : String) = core match {
- case "public" => "val";
- case "protected" => super.accessQualified(core,qual) + " val";
- case "private" if qual == "this" => "";
- case core => super.accessQualified(core, qual);
+ case "public" => "val"
+ case "protected" => super.accessQualified(core,qual) + " val"
+ case "private" if qual == "this" => ""
+ case core => super.accessQualified(core, qual)
}
}
- def Param(sym : Symbol) = new Param(sym);
- class TypeParam(sym : Symbol) extends Entity(sym) {
- def kind = "";
+ def Param(sym: Symbol) = new Param(sym)
+ class TypeParam(sym: Symbol) extends Entity(sym) {
+ def kind = ""
}
- def TypeParam(sym : Symbol) = new TypeParam(sym);
+ def TypeParam(sym: Symbol) = new TypeParam(sym)
trait Clazz extends ClassOrObject {
- private def csym = sym.asInstanceOf[TypeSymbol];
- override def typeParams = csym.typeParams.map(TypeParam);
+ private def csym = sym.asInstanceOf[TypeSymbol]
+ override def typeParams = csym.typeParams.map(TypeParam)
override def params = {
- if (constructorArgs.isEmpty) Nil;
- else constructorArgs.values.toList :: Nil;
+ if (constructorArgs.isEmpty) Nil
+ else constructorArgs.values.toList :: Nil
}
- def isTrait = csym.isTrait;
- override def kind = if (sym.isTrait) "trait" else "class";
+ def isTrait = csym.isTrait
+ override def kind = if (sym.isTrait) "trait" else "class"
}
+
trait Object extends ClassOrObject {
- override def kind = "object";
- }
- case class Package(override val sym : ModuleSymbol) extends Entity(sym) {
- override def kind = "package";
- override def name = fullName('.');
+ override def kind = "object"
}
+ case class Package(override val sym: ModuleSymbol) extends Entity(sym) {
+ override def kind = "package"
+ override def name = fullName('.')
+ }
- trait TopLevel extends ClassOrObject;
- class TopLevelClass (sym : Symbol) extends Entity(sym) with TopLevel with Clazz;
- class TopLevelObject(sym : Symbol) extends Entity(sym) with TopLevel with Object;
+ trait TopLevel extends ClassOrObject
+ class TopLevelClass (sym: Symbol) extends Entity(sym) with TopLevel with Clazz
+ class TopLevelObject(sym: Symbol) extends Entity(sym) with TopLevel with Object
- def compare(pathA : List[ClassOrObject], pathB : List[ClassOrObject]) : Int = {
- var pA = pathA;
- var pB = pathB;
+ def compare(pathA: List[ClassOrObject], pathB: List[ClassOrObject]): Int = {
+ var pA = pathA
+ var pB = pathB
while (true) {
if (pA.isEmpty) return -1;
if (pB.isEmpty) return +1;
@@ -260,10 +261,10 @@ trait ModelExtractor {
o.map(comments.apply);
}
}
- abstract class ValDef(sym : Symbol) extends Member(sym) {
+ abstract class ValDef(sym: Symbol) extends Member(sym) {
override def resultType = Some(resultType0);
- protected def resultType0 : Type;
- override def overridden : Iterable[Symbol] = {
+ protected def resultType0: Type
+ override def overridden: Iterable[Symbol] = {
var ret : jcl.LinkedHashSet[Symbol] = null;
for (parent <- ClassOrObject.this.parents) {
val sym0 = sym.overriddenSymbol(parent.symbol);
@@ -294,7 +295,7 @@ trait ModelExtractor {
}
override def kind = "def"
}
- case class Val(override val sym : TermSymbol) extends ValDef(sym) {
+ case class Val(override val sym: TermSymbol) extends ValDef(sym) {
def resultType0 : Type = sym.tpe;
override def kind = {
import symtab.Flags._;
diff --git a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
index 42421ac07f..682fdf9864 100644
--- a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
+++ b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala
@@ -266,7 +266,7 @@ trait ModelFrames extends ModelExtractor {
<!-- <table><tr></tr></table> -->
</td>
<td align="right" valign="top" style="white-space:nowrap;" rowspan="2">
- <div class="doctitle-larger">{docTitle}</div>
+ <div class="doctitle-larger">{windowTitle}</div>
</td>
</tr>
<tr><td></td></tr>
diff --git a/src/compiler/scala/tools/nsc/doc/ModelToXML.scala b/src/compiler/scala/tools/nsc/doc/ModelToXML.scala
index 6ad9791bc1..00de9d6189 100644
--- a/src/compiler/scala/tools/nsc/doc/ModelToXML.scala
+++ b/src/compiler/scala/tools/nsc/doc/ModelToXML.scala
@@ -31,7 +31,7 @@ trait ModelToXML extends ModelExtractor {
}) else aref(url, entity.nameString);
}
- def link(tpe: Type)(implicit frame : Frame) : NodeSeq = {
+ def link(tpe: Type)(implicit frame: Frame): NodeSeq = {
if (!tpe.typeArgs.isEmpty) {
if (definitions.isFunctionType(tpe)) {
val (args,r) = tpe.typeArgs.splitAt(tpe.typeArgs.length - 1);
@@ -61,15 +61,11 @@ trait ModelToXML extends ModelExtractor {
}
}
- private def printIf[T](what : Option[T], before : String, after : String)(f : T => NodeSeq) : NodeSeq = {
- if (what.isEmpty) return Text("");
- var seq : NodeSeq = Text(before);
- seq = seq ++ f(what.get);
- seq = seq ++ Text(after);
- seq
- }
+ private def printIf[T](what: Option[T], before: String, after: String)(f: T => NodeSeq): NodeSeq =
+ if (what.isEmpty) Text("")
+ else Text(before) ++ f(what.get) ++ Text(after)
- def bodyFor(entity : Entity)(implicit frame : Frame) : NodeSeq = {
+ def bodyFor(entity: Entity)(implicit frame: Frame): NodeSeq = {
var seq = {entity.typeParams.surround("[", "]")(e => {
Text(e.variance) ++ <em>{e.name}</em> ++
{printIf(e.hi, " <: ", "")(link)} ++
@@ -77,22 +73,21 @@ trait ModelToXML extends ModelExtractor {
})} ++ printIf(entity.hi, " <: ", "")(link) ++
printIf(entity.lo, " >: ", "")(link);
{entity.params.foreach(xs => {
- seq = seq ++ xs.mkXML("(", ", ", ")")(arg => {
- var seq : NodeSeq = {
- val str = arg.flagsString.trim;
- if (str.length == 0) NodeSeq.Empty;
- else <code>{Text(str)} </code>;
- }
- seq = seq ++ <em>{arg.name}</em>;
- seq = seq ++ Text(" : ") ++ link(arg.resultType.get);
- seq;
- });
- seq;
+ seq = seq ++ xs.mkXML("(", ", ", ")")(arg =>
+ {
+ val str = arg.flagsString.trim
+ if (str.length == 0) NodeSeq.Empty
+ else <code>{Text(str)} </code>
+ } ++
+ <em>{arg.name}</em> ++
+ Text(" : ") ++ link(arg.resultType.get)
+ );
+ seq
})};
seq ++ {printIf(entity.resultType, " : ", "")(tpe => link(tpe))}
}
- def extendsFor(entity : Entity)(implicit frame : Frame) : NodeSeq = {
+ def extendsFor(entity: Entity)(implicit frame: Frame): NodeSeq = {
if (entity.parents.isEmpty) NodeSeq.Empty;
else <code> extends </code>++
entity.parents.mkXML(Text(""), <code> with </code>, Text(""))(link);
@@ -119,14 +114,14 @@ trait ModelToXML extends ModelExtractor {
<dd>{extendsFor(entity)}</dd>
</dl>;
} ++ {
- val cmnt = entity.decodeComment;
- if (cmnt.isEmpty) NodeSeq.Empty;
- else longComment(cmnt.get);
+ val cmnt = entity.decodeComment
+ if (cmnt.isEmpty) NodeSeq.Empty
+ else longComment(cmnt.get)
} ++ (entity match {
- case entity : ClassOrObject => {classBody(entity)};
- case _ => NodeSeq.Empty;
+ case entity: ClassOrObject => classBody(entity)
+ case _ => NodeSeq.Empty
}) ++ {
- val overridden = entity.overridden;
+ val overridden = entity.overridden
if (!overridden.isEmpty) {
var seq : NodeSeq = Text("Overrides ");
seq = seq ++ overridden.mkXML("",", ", "")(sym => link(decode(sym.owner)) ++ Text(".") ++ link(sym));
@@ -134,9 +129,9 @@ trait ModelToXML extends ModelExtractor {
} else NodeSeq.Empty;
} ++ <hr/>);
- def longComment(cmnt : Comment) : NodeSeq = {
+ def longComment(cmnt: Comment): NodeSeq = {
val attrs = <dl>{
- var seq : NodeSeq = NodeSeq.Empty;
+ var seq: NodeSeq = NodeSeq.Empty
cmnt.decodeAttributes.foreach{
case (tag,xs) =>
seq = seq ++ <dt style="margin:10px 0 0 20px;">
@@ -149,13 +144,17 @@ trait ModelToXML extends ModelExtractor {
};
seq;
}</dl>;
- <span><dl><dd>{parse(cmnt.body)}</dd></dl>{attrs}</span>
+ <xml:group>
+ <dl><dd>{parse(cmnt.body)}</dd></dl>
+ {attrs}
+ </xml:group>
}
- def classBody(entity : ClassOrObject)(implicit from : Frame) : NodeSeq = <span>
- {categories.mkXML("","\n","")(c => shortList(entity, c)) : NodeSeq}
- {categories.mkXML("","\n","")(c => longList(entity, c)) : NodeSeq}
- </span>;
+ def classBody(entity: ClassOrObject)(implicit from: Frame): NodeSeq =
+ <xml:group>
+ {categories.mkXML("","\n","")(c => shortList(entity, c)) : NodeSeq}
+ {categories.mkXML("","\n","")(c => longList(entity, c)) : NodeSeq}
+ </xml:group>;
def longList(entity : ClassOrObject,category : Category)(implicit from : Frame) : NodeSeq = {
val xs = entity.members(category);
@@ -167,13 +166,13 @@ trait ModelToXML extends ModelExtractor {
<div>{xs.mkXML("","\n","")(m => longHeader(m))}</div>);
}
- def shortList(entity: ClassOrObject, category: Category)(implicit from: Frame) : NodeSeq = {
+ def shortList(entity: ClassOrObject, category: Category)(implicit from: Frame): NodeSeq = {
val xs = entity.members(category)
- var seq : NodeSeq = NodeSeq.Empty
+ var seq: NodeSeq = NodeSeq.Empty
if (xs.elements.hasNext) {
// alphabetic
val set = new scala.collection.jcl.TreeSet[entity.Member]()(mA => new Ordered[entity.Member] {
- def compare(mB : entity.Member) : Int = {
+ def compare(mB: entity.Member): Int = {
if (mA eq mB) return 0;
val diff = mA.name compare mB.name;
if (diff != 0) return diff;
@@ -183,7 +182,7 @@ trait ModelToXML extends ModelExtractor {
}
});
set addAll xs;
- seq = seq ++ <table cellpadding="3" class="member" summary="">
+ seq = seq ++ <table cellpadding="3" class="member" summary="">
<tr><td colspan="2" class="title">{Text(category.label + " Summary")}</td></tr>
{set.mkXML("","\n","")(mmbr => shortHeader(mmbr))}
</table>
@@ -220,16 +219,23 @@ trait ModelToXML extends ModelExtractor {
<code>{Text(entity.flagsString)} {Text(entity.kind)}</code>
</td>
<td class="signature">
- <em>{link(decode(entity.sym))}</em>{bodyFor(entity) ++ extendsFor(entity)}
+ <em>{link(decode(entity.sym))}</em>
+ {bodyFor(entity) ++ extendsFor(entity)}
+ {
+ entity.resultType match {
+ case Some(PolyType(_, ConstantType(v))) => Text(" = " + v.escapedStringValue)
+ case _ => NodeSeq.Empty
+ }
+ }
{
- val cmnt = entity.decodeComment;
- if (cmnt.isEmpty) NodeSeq.Empty;
- else <br>{parse(cmnt.get.body)}</br>;
+ val cmnt = entity.decodeComment
+ if (cmnt.isEmpty) NodeSeq.Empty
+ else <div>{parse(cmnt.get.body)}</div>;
}
</td>
</tr>
- def attrsFor(entity : Entity)(implicit from : Frame) : NodeSeq = {
+ def attrsFor(entity: Entity)(implicit from: Frame): NodeSeq = {
def attrFor(attr: AnnotationInfo[Constant]): Node = {
val buf = new StringBuilder
val AnnotationInfo(tpe, args, nvPairs) = attr