diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/DocDriver.scala | 75 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/ModelExtractor.scala | 39 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/ModelFrames.scala | 38 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/ModelToXML.scala | 27 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/script.js | 60 |
5 files changed, 157 insertions, 82 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/DocDriver.scala b/src/compiler/scala/tools/nsc/doc/DocDriver.scala index 2fc4be7e84..9864b13c2e 100644 --- a/src/compiler/scala/tools/nsc/doc/DocDriver.scala +++ b/src/compiler/scala/tools/nsc/doc/DocDriver.scala @@ -23,44 +23,42 @@ abstract class DocDriver extends ModelFrames with ModelToXML { override def addition(sym: global.Symbol) = { super.addition(sym) sym match { - case sym : global.ClassSymbol => additions += sym.asInstanceOf[Symbol] + case sym : global.ClassSymbol => additions += sym.asInstanceOf[Symbol] case sym : global.ModuleSymbol => additions += sym.asInstanceOf[Symbol] - case sym : global.TypeSymbol => additions += sym.asInstanceOf[Symbol] + case sym : global.TypeSymbol => additions += sym.asInstanceOf[Symbol] case _ => } } - def init : Unit = {} + def init: Unit = {} } - def process(units: Iterator[CompilationUnit]): Unit = { + def process(units: Iterator[CompilationUnit]) { assert(global.definitions != null); - def g(pkg : Package, clazz : ClassOrObject) : Unit = { + def g(pkg: Package, clazz: ClassOrObject) { allClasses(pkg) += clazz; clazz.decls.map(._2).foreach { - case clazz : ClassOrObject => - g(pkg, clazz); - case _ => + case clazz : ClassOrObject => g(pkg, clazz) + case _ => } } - def f(pkg : Package, tree : Tree) : Unit = if (!tree.symbol.hasFlag(symtab.Flags.PRIVATE)) tree match { - case tree : PackageDef => - val pkg1 = new Package(tree.symbol.asInstanceOf[ModuleSymbol]); - tree.stats.foreach(stat => f(pkg1, stat)); - case tree : ClassDef => - assert(pkg != null); - g(pkg, new TopLevelClass(tree.symbol.asInstanceOf[ClassSymbol])); - case tree : ModuleDef => - assert(pkg != null); - g(pkg, new TopLevelObject(tree.symbol.asInstanceOf[ModuleSymbol])); - case _ => + def f(pkg: Package, tree: Tree): Unit = if (!tree.symbol.hasFlag(symtab.Flags.PRIVATE)) tree match { + case tree : PackageDef => + val pkg1 = new Package(tree.symbol.asInstanceOf[ModuleSymbol]); + tree.stats.foreach(stat => f(pkg1, stat)) + case tree : ClassDef => + assert(pkg != null); + g(pkg, new TopLevelClass(tree.symbol.asInstanceOf[ClassSymbol])) + case tree : ModuleDef => + assert(pkg != null); + g(pkg, new TopLevelObject(tree.symbol.asInstanceOf[ModuleSymbol])) + case _ => } - units.foreach(unit => f(null, unit.body)); + units.foreach(unit => f(null, unit.body)) - - for (p <- allClasses; val d <- p._2) { - symbols += d.sym; - for (pp <- d.sym.tpe.parents) subClasses(pp.symbol) += d; + for (p <- allClasses; d <- p._2) { + symbols += d.sym + for (pp <- d.sym.tpe.parents) subClasses(pp.symbol) += d } additions0.init copyResources @@ -69,9 +67,7 @@ abstract class DocDriver extends ModelFrames with ModelToXML { new PackagesContentFrame with Frame { def packages = packages0; } new NavigationFrame with Frame { } new ListClassFrame with Frame { - def classes = { - for (p <- allClasses; d <- p._2) yield d; - } + def classes = for (p <- allClasses; d <- p._2) yield d object organized extends jcl.LinkedHashMap[(List[String],Boolean),List[ClassOrObject]] { override def default(key : (List[String],Boolean)) = Nil; classes.foreach(cls => { @@ -121,23 +117,23 @@ abstract class DocDriver extends ModelFrames with ModelToXML { } for (sym <- additions) sym match { case sym : ClassSymbol => - val add = new TopLevelClass(sym); + val add = new TopLevelClass(sym) new ClassContentFrame with Frame { - def clazz = add; + def clazz = add def title = add.kind + " " + add.name + " in package " + add.sym.owner.fullNameString('.') } - case sym : TypeSymbol => - val add = new TopLevelClass(sym); + case sym :TypeSymbol => + val add = new TopLevelClass(sym) new ClassContentFrame with Frame { - def clazz = add; + def clazz = add def title = add.kind + " " + add.name + " in package " + add.sym.owner.fullNameString('.') } - case sym : ModuleSymbol => - val add = new TopLevelObject(sym); + case sym :ModuleSymbol => + val add = new TopLevelObject(sym) new ClassContentFrame with Frame { - def clazz = add; + def clazz = add def title = add.kind + " " + add.name + " in package " + add.sym.owner.fullNameString('.') } @@ -208,7 +204,7 @@ abstract class DocDriver extends ModelFrames with ModelToXML { } // <code>{Text(string + " - ")}</code>; - override def hasLink0(sym : Symbol) : Boolean = { + override def hasLink0(sym: Symbol): Boolean = { if (sym == NoSymbol) return false; val ret = super.hasLink0(sym) && (additions.contains(sym) || symbols.contains(sym)); if (ret) return true; @@ -224,9 +220,10 @@ abstract class DocDriver extends ModelFrames with ModelToXML { } return false; } - def aref(href : String, label : String)(implicit frame : Frame) = - frame.aref(href, "_self", label); - protected def anchor(entity : Symbol)(implicit frame : Frame) : NodeSeq = + def aref(href: String, label: String)(implicit frame: Frame) = + frame.aref(href, "_self", label) + + protected def anchor(entity: Symbol)(implicit frame: Frame): NodeSeq = <a name={Text(frame.docName(entity))}></a> object symbols extends jcl.LinkedHashSet[Symbol]; diff --git a/src/compiler/scala/tools/nsc/doc/ModelExtractor.scala b/src/compiler/scala/tools/nsc/doc/ModelExtractor.scala index 91ed949eba..44c17e4b74 100644 --- a/src/compiler/scala/tools/nsc/doc/ModelExtractor.scala +++ b/src/compiler/scala/tools/nsc/doc/ModelExtractor.scala @@ -16,14 +16,17 @@ import compat.Platform.{EOL => LINE_SEPARATOR} * @author Sean McDirmid */ trait ModelExtractor { - val global : Global + val global: Global import global._ + def assert(b : Boolean) { if (!b) throw new Error; } - case class Tag(tag : String, option : String, body : String); - case class Comment(body : String, attributes : List[Tag]) { + + case class Tag(tag: String, option: String, body: String) + + case class Comment(body: String, attributes: List[Tag]) { def decodeAttributes = { val map = new jcl.LinkedHashMap[String,List[(String,String)]] { override def default(key : String) = Nil; @@ -34,21 +37,20 @@ trait ModelExtractor { map } } - protected def decode(sym : Symbol) = { + protected def decode(sym: Symbol) = if (sym == definitions.ScalaObjectClass || sym == definitions.ObjectClass) - definitions.AnyRefClass; + definitions.AnyRefClass else sym match { - case sym : ModuleClassSymbol => sym.sourceModule; - case sym => sym; + case sym : ModuleClassSymbol => sym.sourceModule + case sym => sym } - } protected def decodeComment(comment0 : String) : Comment = { - assert(comment0.startsWith("/**")); - assert(comment0.endsWith("*/")); - val comment = comment0.substring("/**".length, comment0.length - "*/".length); - val tok = new java.util.StringTokenizer(comment, LINE_SEPARATOR); - val buf = new StringBuilder; + assert(comment0.startsWith("/**")) + assert(comment0.endsWith("*/")) + val comment = comment0.substring("/**".length, comment0.length - "*/".length) + val tok = new java.util.StringTokenizer(comment, LINE_SEPARATOR) + val buf = new StringBuilder type AttrDescr = (String, String, StringBuilder) val attributes = new collection.mutable.ListBuffer[AttrDescr] var attr: AttrDescr = null @@ -89,14 +91,17 @@ trait ModelExtractor { Some(ModelExtractor.this.decodeComment(comment)); } protected def accessQualified(core: String, qual: String) = core match { - case "public" => ""; // assert(qual == null); ""; - case core => core + (if (qual == null) "" else "[" + qual + "]"); + case "public" => "" // assert(qual == null); ""; + case core => core + (if (qual == null) "" else "[" + qual + "]") } def flagsString = { 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"; + 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, { if (sym.hasFlag(Flags.LOCAL)) "this"; else if (sym.privateWithin != null && sym.privateWithin != NoSymbol) diff --git a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala index a4ece5286f..5e84513075 100644 --- a/src/compiler/scala/tools/nsc/doc/ModelFrames.scala +++ b/src/compiler/scala/tools/nsc/doc/ModelFrames.scala @@ -96,17 +96,19 @@ trait ModelFrames extends ModelExtractor { def urlFor(sym: Symbol): String = sym match { case sym : TypeSymbol if sym == definitions.AnyRefClass => - urlFor0(sym,sym) + FILE_EXTENSION_HTML + urlFor0(sym, sym) + FILE_EXTENSION_HTML case psym : ModuleSymbol if psym.isPackage => - urlFor0(sym,sym) + FILE_EXTENSION_HTML + urlFor0(sym, sym) + FILE_EXTENSION_HTML case sym if !hasLink(sym) => null + case sym if sym.hasFlag(Flags.JAVA) => + null // handled in ModelToXML.link case msym: ModuleSymbol => urlFor0(sym, sym) + FILE_EXTENSION_HTML case csym: ClassSymbol => urlFor0(sym, sym) + FILE_EXTENSION_HTML case _ => - val cnt = urlFor(decode(sym.owner)); + val cnt = urlFor(decode(sym.owner)) if (cnt == null) null else cnt + "#" + docName(sym) } @@ -145,13 +147,11 @@ trait ModelFrames extends ModelExtractor { case msym: ModuleSymbol => if (msym hasFlag Flags.PACKAGE) NAME_SUFFIX_PACKAGE else NAME_SUFFIX_OBJECT - case csym: ClassSymbol => - if (csym.isModuleClass) { - if (csym hasFlag Flags.PACKAGE) NAME_SUFFIX_PACKAGE - else NAME_SUFFIX_OBJECT - } - else "" - case _ => "" + case csym: ClassSymbol if csym.isModuleClass => + if (csym hasFlag Flags.PACKAGE) NAME_SUFFIX_PACKAGE + else NAME_SUFFIX_OBJECT + case _ => + "" }) } } @@ -235,6 +235,7 @@ trait ModelFrames extends ModelExtractor { } def optional(cls: ClassOrObject): NodeSeq = NodeSeq.Empty } + abstract class PackageContentFrame extends Frame { override def path = pkg.fullName('/') + "$content" override def title = "All classes and objects in " + pkg.fullName('.') @@ -250,6 +251,7 @@ trait ModelFrames extends ModelExtractor { </table> })}; } + abstract class ClassContentFrame extends Frame { def clazz: ClassOrObject def body: NodeSeq = @@ -271,14 +273,21 @@ trait ModelFrames extends ModelExtractor { </tr> <tr><td></td></tr> </table>; - private def header0: NodeSeq = + private def header0: NodeSeq = { + val owner = decode(clazz.sym.owner) + val name = + owner.fullNameString('/') + (if (owner.isPackage) "/" + clazz.name else "") <xml:group> <div class="entity"> - {aref(urlFor(decode(clazz.sym.owner)), "_self", decode(clazz.sym.owner).fullNameString('.'))} + {aref(urlFor(owner), "_self", owner.fullNameString('.'))} <br/> <span class="entity">{Text(clazz.kind)} {Text(clazz.name)}</span> </div><hr/> - </xml:group>; + <div style="font-size:smaller; color:gray;"> + [source: <a class={name} href=""><code>{name + ".scala"}</code></a>] + </div><hr/> + </xml:group> + } } def longComment(cmnt: Comment): NodeSeq @@ -355,6 +364,7 @@ trait ModelFrames extends ModelExtractor { copyResource(stylesheetSetting.value, !stylesheetSetting.isDefault) copyResource("script.js", false) } + private val patVal = java.util.regex.Pattern.compile( - "scala\\.(Byte|Boolean|Char|Double|Float|Int|Long|Short)") + "scala\\.(Byte|Boolean|Char|Double|Float|Int|Long|Short)") } diff --git a/src/compiler/scala/tools/nsc/doc/ModelToXML.scala b/src/compiler/scala/tools/nsc/doc/ModelToXML.scala index 00de9d6189..63c8990c56 100644 --- a/src/compiler/scala/tools/nsc/doc/ModelToXML.scala +++ b/src/compiler/scala/tools/nsc/doc/ModelToXML.scala @@ -24,11 +24,17 @@ trait ModelToXML extends ModelExtractor { def aref(href: String, label: String)(implicit frame: Frame): NodeSeq def link(entity: Symbol)(implicit frame: Frame): NodeSeq = { - val url = urlFor(entity); + val url = urlFor(entity) // nothing to do but be verbose. - if (url == null) Text({ - entity.owner.fullNameString('.') + '.' + entity.nameString; - }) else aref(url, entity.nameString); + if (url == null) { + val name = entity.owner.fullNameString('.') + '.' + entity.nameString + if (entity.hasFlag(symtab.Flags.JAVA)) + <a class={name.replace('.', '/')} href="" target="contentFrame">{name}</a> + else + Text(name) + } + else + aref(url, entity.nameString) } def link(tpe: Type)(implicit frame: Frame): NodeSeq = { @@ -103,7 +109,7 @@ trait ModelToXML extends ModelExtractor { } } - def longHeader(entity : Entity)(implicit from : Frame) : NodeSeq = Group({ + def longHeader(entity: Entity)(implicit from: Frame): NodeSeq = Group({ anchor(entity.sym) ++ <dl> <dt> {attrsFor(entity)} @@ -156,14 +162,15 @@ trait ModelToXML extends ModelExtractor { {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); - if (!xs.elements.hasNext) return NodeSeq.Empty; - Group( + def longList(entity: ClassOrObject, category: Category)(implicit from: Frame): NodeSeq = { + val xs = entity.members(category) + if (!xs.elements.hasNext) + NodeSeq.Empty + else Group( <table cellpadding="3" class="member-detail" summary=""> <tr><td class="title">{Text(category.label)} Details</td></tr> </table> - <div>{xs.mkXML("","\n","")(m => longHeader(m))}</div>); + <div>{xs.mkXML("","\n","")(m => longHeader(m))}</div>) } def shortList(entity: ClassOrObject, category: Category)(implicit from: Frame): NodeSeq = { diff --git a/src/compiler/scala/tools/nsc/doc/script.js b/src/compiler/scala/tools/nsc/doc/script.js index 7684ecc9a0..592cf05ac0 100644 --- a/src/compiler/scala/tools/nsc/doc/script.js +++ b/src/compiler/scala/tools/nsc/doc/script.js @@ -82,9 +82,11 @@ function init() { api['java/lang/ThreadLocal'] = java_api_root; api['java/lang/Throwable'] = java_api_root; api['java/lang/Void'] = java_api_root; + api['java/math/BigDecimal'] = java_api_root; api['java/math/BigInteger'] = java_api_root; api['java/math/MathContext'] = java_api_root; + api['java/net/Authenticator'] = java_api_root; api['java/net/BindException'] = java_api_root; api['java/net/HttpURLConnection'] = java_api_root; @@ -105,6 +107,7 @@ function init() { api['java/net/URLConnection'] = java_api_root; api['java/net/URLDecoder'] = java_api_root; api['java/net/URLStreamHandler'] = java_api_root; + api['java/nio/Buffer'] = java_api_root; api['java/nio/ByteBuffer'] = java_api_root; api['java/nio/BufferOverflowException'] = java_api_root; @@ -126,24 +129,43 @@ function init() { api['java/nio/channels/ServerSocketChannel'] = java_api_root; api['java/nio/channels/SocketChannel'] = java_api_root; api['java/nio/charset/CharsetDecoder'] = java_api_root; + api['java/rmi/AccessException'] = java_api_root; api['java/rmi/MarshalledObject'] = java_api_root; api['java/rmi/Naming'] = java_api_root; api['java/rmi/RMISecurityManager'] = java_api_root; api['java/rmi/Remote'] = java_api_root; //interface + api['java/sql/Array'] = java_api_root; //interface + api['java/sql/BatchUpdateException'] = java_api_root; //exception api['java/sql/Blob'] = java_api_root; //interface api['java/sql/CallableStatement'] = java_api_root; //interface + api['java/sql/Clob'] = java_api_root; //interface api['java/sql/Connection'] = java_api_root; //interface + api['java/sql/DataTruncation'] = java_api_root; //exception + api['java/sql/DatabaseMetaData'] = java_api_root; //interface api['java/sql/Date'] = java_api_root; + api['java/sql/Driver'] = java_api_root; //interface api['java/sql/DriverManager'] = java_api_root; + api['java/sql/DriverPropertyInfo'] = java_api_root; + api['java/sql/ParameterMetaData'] = java_api_root; //interface + api['java/sql/PreparedStatement'] = java_api_root; //interface + api['java/sql/Ref'] = java_api_root; //interface api['java/sql/ResultSet'] = java_api_root; //interface api['java/sql/ResultSetMetaData'] = java_api_root; //interface + api['java/sql/SQLData'] = java_api_root; //interface + api['java/sql/SQLInput'] = java_api_root; //interface + api['java/sql/SQLOutput'] = java_api_root; //interface + api['java/sql/SQLException'] = java_api_root; //exception api['java/sql/SQLPermission'] = java_api_root; + api['java/sql/SQLWarning'] = java_api_root; //exception + api['java/sql/SavePoint'] = java_api_root; //interface + api['java/sql/Statement'] = java_api_root; //interface + api['java/sql/Struct'] = java_api_root; //interface api['java/sql/Time'] = java_api_root; api['java/sql/Timestamp'] = java_api_root; api['java/sql/Types'] = java_api_root; - api['java/text/MessageFormat'] = java_api_root; + api['java/text/Annotation'] = java_api_root; api['java/text/AttributedCharacterIterator'] = java_api_root; api['java/text/AttributedString'] = java_api_root; @@ -165,6 +187,13 @@ function init() { api['java/text/ParsePosition'] = java_api_root; api['java/text/SimpleDateFormat'] = java_api_root; api['java/text/StringCharacterIterator'] = java_api_root; + + api['java/util/AbstractCollection'] = java_api_root; + api['java/util/AbstractList'] = java_api_root; + api['java/util/AbstractMap'] = java_api_root; + api['java/util/AbstractSequentialList'] = java_api_root; + api['java/util/AbstractSet'] = java_api_root; + api['java/util/ArrayList'] = java_api_root; api['java/util/Arrays'] = java_api_root; api['java/util/BitSet'] = java_api_root; api['java/util/Calendar'] = java_api_root; @@ -174,23 +203,44 @@ function init() { api['java/util/Currency'] = java_api_root; api['java/util/Date'] = java_api_root; api['java/util/Dictionary'] = java_api_root; + api['java/util/EnumMap'] = java_api_root; + api['java/util/EnumSet'] = java_api_root; + api['java/util/Enumeration'] = java_api_root; //interface + api['java/util/EventListener'] = java_api_root; //interface + api['java/util/EventListenerProxy'] = java_api_root; + api['java/util/EventObject'] = java_api_root; + api['java/util/Formattable'] = java_api_root; //interface api['java/util/Formatter'] = java_api_root; + api['java/util/GregorianCalendar'] = java_api_root; api['java/util/HashMap'] = java_api_root; api['java/util/HashSet'] = java_api_root; - api['java/util/Hashapi'] = java_api_root; + api['java/util/Hashtable'] = java_api_root; + api['java/util/IdentityHashMap'] = java_api_root; api['java/util/IllegalFormatException'] = java_api_root; + api['java/util/Iterator'] = java_api_root; //interface api['java/util/LinkedHashMap'] = java_api_root; api['java/util/LinkedHashSet'] = java_api_root; api['java/util/LinkedList'] = java_api_root; api['java/util/List'] = java_api_root; //interface + api['java/util/ListIterator'] = java_api_root; //interface + api['java/util/ListResourceBundle'] = java_api_root; + api['java/util/Locale'] = java_api_root; api['java/util/Map'] = java_api_root; api['java/util/Observable'] = java_api_root; + api['java/util/Observer'] = java_api_root; //interface api['java/util/PriorityQueue'] = java_api_root; api['java/util/Properties'] = java_api_root; + api['java/util/PropertyPermission'] = java_api_root; + api['java/util/PropertyResourceBundle'] = java_api_root; + api['java/util/Queue'] = java_api_root; //interface api['java/util/Random'] = java_api_root; + api['java/util/RandomAccess'] = java_api_root; //interface api['java/util/ResourceBundle'] = java_api_root; api['java/util/Scanner'] = java_api_root; //(1.5) api['java/util/Set'] = java_api_root; + api['java/util/SimpleTimeZone'] = java_api_root; + api['java/util/SortedMap'] = java_api_root; //interface + api['java/util/SortedSet'] = java_api_root; //infterface api['java/util/Stack'] = java_api_root; api['java/util/StringTokenizer'] = java_api_root; api['java/util/Timer'] = java_api_root; @@ -545,6 +595,12 @@ function init() { src['scala/testing/SUnit'] = lib_src_root; src['scala/testing/UnitTest'] = lib_src_root; // object + src['scala/text/DocBreak'] = lib_src_root; + src['scala/text/DocCons'] = lib_src_root; + src['scala/text/DocGroup'] = lib_src_root; + src['scala/text/DocNest'] = lib_src_root; + src['scala/text/DocNil'] = lib_src_root; + src['scala/text/DocText'] = lib_src_root; src['scala/text/Document'] = lib_src_root; src['scala/util/Fluid'] = lib_src_root; |