summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2011-02-23 15:41:47 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2011-02-23 15:41:47 +0000
commited971ecabae07e60621ea8b4138eda7585ad3537 (patch)
tree01e577c3be85c184f4e0a1ed974e71c0b71bfc68 /src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala
parent82909349e3a65f864da7f6bea4de2ddd584ae884 (diff)
downloadscala-ed971ecabae07e60621ea8b4138eda7585ad3537.tar.gz
scala-ed971ecabae07e60621ea8b4138eda7585ad3537.tar.bz2
scala-ed971ecabae07e60621ea8b4138eda7585ad3537.zip
[scaladoc] Changed TreeFactory so that it doesn...
[scaladoc] Changed TreeFactory so that it doesn't consume exceptions. Required fixes to makeAnnotation and makeTree which were throwing exceptions as a matter of fact. Also code refactoring around annotations and trees. Closes #4284. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala')
-rwxr-xr-xsrc/compiler/scala/tools/nsc/doc/model/TreeFactory.scala46
1 files changed, 19 insertions, 27 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala b/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala
index 5ed0aa740e..dd519feed0 100755
--- a/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala
@@ -3,6 +3,7 @@ package doc
package model
import scala.collection._
+import util.{RangePosition, SourceFile}
/** The goal of this trait is , using makeTree,
* to browse a tree to
@@ -18,22 +19,21 @@ trait TreeFactory { thisTreeFactory: ModelFactory with TreeFactory =>
val global: Global
import global._
- def makeTree(rhs: Tree): TreeEntity = {
+ def makeTree(rhs: Tree): Option[TreeEntity] = {
- var expr: String = null
+ var expr = new StringBuilder
var refs = new immutable.TreeMap[Int, (Entity, Int)] // start, (Entity to be linked to , end)
- try {
+ val pos: Position = rhs.pos
- val firstIndex = rhs.pos.startOrPoint
+ if (pos.isInstanceOf[RangePosition]) {
- /** Gets the full string of the right hand side of a parameter, without links */
- for (i <- firstIndex until rhs.pos.endOrPoint)
- expr += rhs.pos.source.content.apply(i)
- rhs match {
- case Block(r,s) => expr += "}"
- case _ =>
- }
+ val source: SourceFile = pos.source
+ val firstIndex = pos.startOrPoint
+ val lastIndex = pos.endOrPoint
+
+ assert(firstIndex < lastIndex, "Invalid position indices for tree " + rhs + " (" + firstIndex + ", " + lastIndex + ")")
+ expr.appendAll(source.content, firstIndex, lastIndex - firstIndex)
val traverser = new Traverser {
@@ -41,8 +41,8 @@ trait TreeFactory { thisTreeFactory: ModelFactory with TreeFactory =>
* stores it in tree.refs with its position
*/
def makeLink(rhs: Tree){
- var start = rhs.pos.point - firstIndex
- val end = rhs.pos.endOrPoint - firstIndex
+ var start = pos.startOrPoint - firstIndex
+ val end = pos.endOrPoint - firstIndex
if(start != end) {
var asym = rhs.symbol
if (asym.isClass) makeTemplate(asym) match{
@@ -85,24 +85,16 @@ trait TreeFactory { thisTreeFactory: ModelFactory with TreeFactory =>
traverser.traverse(rhs)
- assert(expr != null, "No expression constructed for rhs=" + rhs.toString)
- new TreeEntity {
- val expression = expr
+ Some(new TreeEntity {
+ val expression = expr.toString
val refEntity = refs
- }
+ })
}
- catch {
- case e: Throwable =>
- //println("Bad tree: " + rhs)
- // TODO: This exception should be rethrown and no dummy tree entity should be created.
- new TreeEntity {
- val expression = "?"
- val refEntity = new immutable.TreeMap[Int, (Entity, Int)]
- }
- //throw e
- }
+ // If there is no position for the tree it means it has been obtained through unpickling and cannot be
+ // printed as a tree.
+ else None
}