summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Ureche <vlad.ureche@gmail.com>2012-10-09 20:42:20 +0200
committerVlad Ureche <vlad.ureche@gmail.com>2012-10-11 17:47:50 +0200
commit950687520907199e756680baed898c4d75cee1e8 (patch)
tree600957e28a1dda804f7536a682ee21dc096487b8
parentc6df7ddd0657ace307eaf6d6bf436cbb24e93df4 (diff)
downloadscala-950687520907199e756680baed898c4d75cee1e8.tar.gz
scala-950687520907199e756680baed898c4d75cee1e8.tar.bz2
scala-950687520907199e756680baed898c4d75cee1e8.zip
SI-6495 Scaladoc will pick up group from owner
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala29
-rw-r--r--test/scaladoc/run/groups.scala94
2 files changed, 71 insertions, 52 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
index 48624ec28f..3b1f0587a1 100644
--- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
@@ -31,6 +31,12 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
import definitions.{ ObjectClass, NothingClass, AnyClass, AnyValClass, AnyRefClass }
import rootMirror.{ RootPackage, RootClass, EmptyPackage }
+ // Defaults for member grouping, that may be overridden by the template
+ val defaultGroup = "Ungrouped"
+ val defaultGroupName = "Ungrouped"
+ val defaultGroupDesc = None
+ val defaultGroupPriority = 1000
+
def templatesCount = docTemplatesCache.count(_._2.isDocTemplate) - droppedPackages.size
private var _modelFinished = false
@@ -121,7 +127,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
}
if (inTpl != null) thisFactory.comment(sym, thisTpl, inTpl) else None
}
- def group = if (comment.isDefined) comment.get.group.getOrElse("No Group") else "No Group"
+ def group = if (comment.isDefined) comment.get.group.getOrElse(defaultGroup) else defaultGroup
override def inTemplate = inTpl
override def toRoot: List[MemberImpl] = this :: inTpl.toRoot
def inDefinitionTemplates = this match {
@@ -493,16 +499,21 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
if (entity != default) return entity
}
// query linearization
- for (tpl <- linearizationTemplates.collect{ case dtpl: DocTemplateImpl if dtpl!=this => dtpl}) {
- val entity = tpl.groupSearch(extractor, default)
- if (entity != default) return entity
- }
- default
+ if (!sym.isPackage)
+ for (tpl <- linearizationTemplates.collect{ case dtpl: DocTemplateImpl if dtpl!=this => dtpl}) {
+ val entity = tpl.groupSearch(extractor, default)
+ if (entity != default) return entity
+ }
+ // query inTpl, going up the ownerChain
+ if (inTpl != null)
+ inTpl.groupSearch(extractor, default)
+ else
+ default
}
- def groupDescription(group: String): Option[Body] = groupSearch(_.groupDesc.get(group), None)
- def groupPriority(group: String): Int = groupSearch(_.groupPrio.get(group) match { case Some(prio) => prio; case _ => 0 }, 0)
- def groupName(group: String): String = groupSearch(_.groupNames.get(group) match { case Some(name) => name; case _ => group }, group)
+ def groupDescription(group: String): Option[Body] = groupSearch(_.groupDesc.get(group), if (group == defaultGroup) defaultGroupDesc else None)
+ def groupPriority(group: String): Int = groupSearch(_.groupPrio.get(group) match { case Some(prio) => prio; case _ => 0 }, if (group == defaultGroup) defaultGroupPriority else 0)
+ def groupName(group: String): String = groupSearch(_.groupNames.get(group) match { case Some(name) => name; case _ => group }, if (group == defaultGroup) defaultGroupName else group)
}
abstract class PackageImpl(sym: Symbol, inTpl: PackageImpl) extends DocTemplateImpl(sym, inTpl) with Package {
diff --git a/test/scaladoc/run/groups.scala b/test/scaladoc/run/groups.scala
index 05324c2ec9..c9e4a8679b 100644
--- a/test/scaladoc/run/groups.scala
+++ b/test/scaladoc/run/groups.scala
@@ -4,49 +4,54 @@ import scala.tools.partest.ScaladocModelTest
object Test extends ScaladocModelTest {
override def code = """
- package test.scaladoc.groups {
-
- /**
- * The trait A
- * @groupdesc A Group A is the group that contains functions starting with f
- * For example:
- * {{{
- * this is an example
- * }}}
- * @groupdesc B Group B is the group that contains functions starting with b
- * @groupname B Group B has a nice new name and a high priority
- * @groupprio B -10
- * @group Traits
- * @note This is a note
- */
- trait A {
- /** foo description
- * @group A */
- def foo = 1
-
- /** bar description
- * @group B */
- def bar = 2
- }
-
- /** The trait B
- * @group Traits
- * @groupdesc C Group C is introduced by B
- */
- trait B {
- /** baz descriptopn
- * @group C */
- def baz = 3
- }
-
- /** The class C which inherits from both A and B
- * @group Classes
- * @groupdesc B Look ma, I'm overriding group descriptions!!!
- * @groupname B And names
- */
- class C extends A with B {
- /** Oh noes, I lost my group -- or did I?!? */
- override def baz = 4
+ package test.scaladoc {
+
+ /** @groupname Z From owner chain */
+ package object `groups`
+
+ package groups {
+ /**
+ * The trait A
+ * @groupdesc A Group A is the group that contains functions starting with f
+ * For example:
+ * {{{
+ * this is an example
+ * }}}
+ * @groupdesc B Group B is the group that contains functions starting with b
+ * @groupname B Group B has a nice new name and a high priority
+ * @groupprio B -10
+ * @group Traits
+ * @note This is a note
+ */
+ trait A {
+ /** foo description
+ * @group A */
+ def foo = 1
+
+ /** bar description
+ * @group B */
+ def bar = 2
+ }
+
+ /** The trait B
+ * @group Traits
+ * @groupdesc C Group C is introduced by B
+ */
+ trait B {
+ /** baz descriptopn
+ * @group C */
+ def baz = 3
+ }
+
+ /** The class C which inherits from both A and B
+ * @group Classes
+ * @groupdesc B Look ma, I'm overriding group descriptions!!!
+ * @groupname B And names
+ */
+ class C extends A with B {
+ /** Oh noes, I lost my group -- or did I?!? */
+ override def baz = 4
+ }
}
}
"""
@@ -101,10 +106,12 @@ object Test extends ScaladocModelTest {
checkGroupDesc(A, "B", "Group B is the group that contains functions starting with b")
checkGroupName(A, "B", "Group B has a nice new name and a high priority")
checkGroupPrio(A, "B", -10)
+ checkGroupName(A, "Z", "From owner chain")
checkGroupDesc(B, "C", "Group C is introduced by B")
checkGroupName(B, "C", "C")
checkGroupPrio(B, "C", 0)
+ checkGroupName(B, "Z", "From owner chain")
checkGroupDesc(C, "A", "Group A is the group that contains functions starting with f")
checkGroupName(C, "A", "A")
@@ -115,5 +122,6 @@ object Test extends ScaladocModelTest {
checkGroupDesc(C, "C", "Group C is introduced by B")
checkGroupName(C, "C", "C")
checkGroupPrio(C, "C", 0)
+ checkGroupName(C, "Z", "From owner chain")
}
} \ No newline at end of file