diff options
author | Kato Kazuyoshi <kato.kazuyoshi@gmail.com> | 2011-08-06 12:48:48 +0000 |
---|---|---|
committer | Kato Kazuyoshi <kato.kazuyoshi@gmail.com> | 2011-08-06 12:48:48 +0000 |
commit | 8709b52eef9a0c0b2600664e38e01af3423e93f6 (patch) | |
tree | c434800649fd185e421eb84079709b65d4bc9c62 | |
parent | 92f32deabb13c9fe530314c998f557ab8d9feed5 (diff) | |
download | scala-8709b52eef9a0c0b2600664e38e01af3423e93f6.tar.gz scala-8709b52eef9a0c0b2600664e38e01af3423e93f6.tar.bz2 scala-8709b52eef9a0c0b2600664e38e01af3423e93f6.zip |
Some "synthetic" code don't have RangePosition.
-rwxr-xr-x | src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala | 123 | ||||
-rw-r--r-- | test/scaladoc/resources/SI_4287.scala | 6 | ||||
-rw-r--r-- | test/scaladoc/scala/html/HtmlFactoryTest.scala | 11 |
3 files changed, 76 insertions, 64 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala b/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala index dd519feed0..988f2e0ba9 100755 --- a/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala @@ -3,7 +3,7 @@ package doc package model import scala.collection._ -import util.{RangePosition, SourceFile} +import util.{RangePosition, OffsetPosition, SourceFile} /** The goal of this trait is , using makeTree, * to browse a tree to @@ -24,78 +24,73 @@ trait TreeFactory { thisTreeFactory: ModelFactory with TreeFactory => var expr = new StringBuilder var refs = new immutable.TreeMap[Int, (Entity, Int)] // start, (Entity to be linked to , end) - val pos: Position = rhs.pos - - if (pos.isInstanceOf[RangePosition]) { - - 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 { - - /** Finds the Entity on which we will later create a link on, - * stores it in tree.refs with its position - */ - def makeLink(rhs: Tree){ - var start = pos.startOrPoint - firstIndex - val end = pos.endOrPoint - firstIndex - if(start != end) { - var asym = rhs.symbol - if (asym.isClass) makeTemplate(asym) match{ - case docTmpl: DocTemplateImpl => - refs += ((start, (docTmpl,end))) - case _ => - } - else if (asym.isTerm && asym.owner.isClass){ - if (asym.isSetter) asym = asym.getter(asym.owner) - makeTemplate(asym.owner) match { + rhs.pos match { + case pos: RangePosition => { + 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 { + + /** Finds the Entity on which we will later create a link on, + * stores it in tree.refs with its position + */ + def makeLink(rhs: Tree){ + var start = pos.startOrPoint - firstIndex + val end = pos.endOrPoint - firstIndex + if(start != end) { + var asym = rhs.symbol + if (asym.isClass) makeTemplate(asym) match{ case docTmpl: DocTemplateImpl => - val mbrs: List[MemberImpl] = makeMember(asym,docTmpl) - mbrs foreach {mbr => - refs += ((start, (mbr,end))) - } + refs += ((start, (docTmpl,end))) case _ => } + else if (asym.isTerm && asym.owner.isClass){ + if (asym.isSetter) asym = asym.getter(asym.owner) + makeTemplate(asym.owner) match { + case docTmpl: DocTemplateImpl => + val mbrs: List[MemberImpl] = makeMember(asym,docTmpl) + mbrs foreach { mbr => refs += ((start, (mbr,end))) } + case _ => + } + } } } - } - /** - * Goes through the tree and makes links when a Select occurs, - * The case of New(_) is ignored because the object we want to create a link on - * will be reached with recursivity and we don't want a link on the "new" string - * If a link is not created, its case is probably not defined in here - */ - override def traverse(tree: Tree) = tree match { - case Select(qualifier, name) => - qualifier match { - case New(_) => - case _ => makeLink(tree) - } + /** + * Goes through the tree and makes links when a Select occurs, + * The case of New(_) is ignored because the object we want to create a link on + * will be reached with recursivity and we don't want a link on the "new" string + * If a link is not created, its case is probably not defined in here + */ + override def traverse(tree: Tree) = tree match { + case Select(qualifier, name) => + qualifier match { + case New(_) => + case _ => makeLink(tree) + } traverse(qualifier) - case Ident(_) => makeLink(tree) - case _ => - super.traverse(tree) + case Ident(_) => makeLink(tree) + case _ => + super.traverse(tree) + } } - } - - traverser.traverse(rhs) - - Some(new TreeEntity { - val expression = expr.toString - val refEntity = refs - }) + traverser.traverse(rhs) + Some(new TreeEntity { + val expression = expr.toString + val refEntity = refs + }) + } + case pos: OffsetPosition => + Some(new TreeEntity { + val expression = rhs.toString + val refEntity = new immutable.TreeMap[Int, (Entity, Int)] + }) + case _ => None } - - // 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 - } - } diff --git a/test/scaladoc/resources/SI_4287.scala b/test/scaladoc/resources/SI_4287.scala new file mode 100644 index 0000000000..9846db466d --- /dev/null +++ b/test/scaladoc/resources/SI_4287.scala @@ -0,0 +1,6 @@ +class ClassWithSugar(val x: Int = 123) { +} + +class ClassWithoutSugar { + def this(x: Int = 456) = this() +} diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala index f3973fa7c9..45792056fc 100644 --- a/test/scaladoc/scala/html/HtmlFactoryTest.scala +++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala @@ -353,4 +353,15 @@ object Test extends Properties("HtmlFactory") { case _ => false } } + + property("Default arguments of synthesized constructor") = { + val files = createTemplates("SI_4287.scala") + + files("ClassWithSugar.html") match { + case node: scala.xml.Node => { + node.toString.contains(">123<") + } + case _ => false + } + } } |