From 9817494e4628a04b8a9a834cdc9735c4906c5da2 Mon Sep 17 00:00:00 2001 From: Vlad Ureche Date: Thu, 8 Dec 2011 00:03:42 +0100 Subject: [PATCH] Fixed use case signature problems in #5054 The flags attached to symbols depend on the order of access and this affects use cases. For a workaround, flags are copied from the full signature, which is always correct. Closes #5054, will open another bug for the html itself. --- .../tools/nsc/doc/model/ModelFactory.scala | 20 +++--- .../{SI_5054.scala => SI_5054_q1.scala} | 4 +- test/scaladoc/resources/SI_5054_q2.scala | 10 +++ test/scaladoc/resources/SI_5054_q3.scala | 10 +++ test/scaladoc/resources/SI_5054_q4.scala | 10 +++ test/scaladoc/resources/SI_5054_q5.scala | 10 +++ test/scaladoc/resources/SI_5054_q6.scala | 10 +++ .../scaladoc/scala/html/HtmlFactoryTest.scala | 64 +++++++++++++++++-- 8 files changed, 124 insertions(+), 14 deletions(-) rename test/scaladoc/resources/{SI_5054.scala => SI_5054_q1.scala} (87%) create mode 100644 test/scaladoc/resources/SI_5054_q2.scala create mode 100644 test/scaladoc/resources/SI_5054_q3.scala create mode 100644 test/scaladoc/resources/SI_5054_q4.scala create mode 100644 test/scaladoc/resources/SI_5054_q5.scala create mode 100644 test/scaladoc/resources/SI_5054_q6.scala diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala index a3b4dc433773..1fe96ed447ba 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala @@ -119,14 +119,18 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { else Public() } } - def flags = { - val fgs = mutable.ListBuffer.empty[Paragraph] - if (sym.isImplicit) fgs += Paragraph(Text("implicit")) - if (sym.isSealed) fgs += Paragraph(Text("sealed")) - if (!sym.isTrait && (sym hasFlag Flags.ABSTRACT)) fgs += Paragraph(Text("abstract")) - if (!sym.isTrait && (sym hasFlag Flags.DEFERRED)) fgs += Paragraph(Text("abstract")) - if (!sym.isModule && (sym hasFlag Flags.FINAL)) fgs += Paragraph(Text("final")) - fgs.toList + def flags = this match { + // workaround for uninitialized flags in use cases - see SI-5054 + case m: NonTemplateMemberEntity if (m.useCaseOf.isDefined) => + m.useCaseOf.get.flags + case _ => + val fgs = mutable.ListBuffer.empty[Paragraph] + if (sym.isImplicit) fgs += Paragraph(Text("implicit")) + if (sym.isSealed) fgs += Paragraph(Text("sealed")) + if (!sym.isTrait && (sym hasFlag Flags.ABSTRACT)) fgs += Paragraph(Text("abstract")) + if (!sym.isTrait && (sym hasFlag Flags.DEFERRED)) fgs += Paragraph(Text("abstract")) + if (!sym.isModule && (sym hasFlag Flags.FINAL)) fgs += Paragraph(Text("final")) + fgs.toList } def deprecation = if (sym.isDeprecated) diff --git a/test/scaladoc/resources/SI_5054.scala b/test/scaladoc/resources/SI_5054_q1.scala similarity index 87% rename from test/scaladoc/resources/SI_5054.scala rename to test/scaladoc/resources/SI_5054_q1.scala index 17167303e4d1..8efc54bf93de 100644 --- a/test/scaladoc/resources/SI_5054.scala +++ b/test/scaladoc/resources/SI_5054_q1.scala @@ -1,4 +1,4 @@ -class SI_5054 { +class SI_5054_q1 { /** * A simple comment @@ -7,4 +7,4 @@ class SI_5054 { * @usecase def test(): Int */ def test(implicit lost: Int): Int = lost -} \ No newline at end of file +} diff --git a/test/scaladoc/resources/SI_5054_q2.scala b/test/scaladoc/resources/SI_5054_q2.scala new file mode 100644 index 000000000000..6aa3c44bfbeb --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q2.scala @@ -0,0 +1,10 @@ +class SI_5054_q2 { + + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + final def test(implicit lost: Int): Int = lost +} diff --git a/test/scaladoc/resources/SI_5054_q3.scala b/test/scaladoc/resources/SI_5054_q3.scala new file mode 100644 index 000000000000..352ebcabf277 --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q3.scala @@ -0,0 +1,10 @@ +class SI_5054_q3 { + + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + implicit def test(implicit lost: Int): Int = lost +} diff --git a/test/scaladoc/resources/SI_5054_q4.scala b/test/scaladoc/resources/SI_5054_q4.scala new file mode 100644 index 000000000000..8b1127fd345f --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q4.scala @@ -0,0 +1,10 @@ +abstract class SI_5054_q4 { + + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + def test(implicit lost: Int): Int +} diff --git a/test/scaladoc/resources/SI_5054_q5.scala b/test/scaladoc/resources/SI_5054_q5.scala new file mode 100644 index 000000000000..da025b8822bb --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q5.scala @@ -0,0 +1,10 @@ +trait SI_5054_q5 { + + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + def test(implicit lost: Int): Int = lost +} diff --git a/test/scaladoc/resources/SI_5054_q6.scala b/test/scaladoc/resources/SI_5054_q6.scala new file mode 100644 index 000000000000..6c135551fee0 --- /dev/null +++ b/test/scaladoc/resources/SI_5054_q6.scala @@ -0,0 +1,10 @@ +trait SI_5054_q6 { + + /** + * A simple comment + * + * @param lost a lost parameter + * @usecase def test(): Int + */ + def test(implicit lost: Int): Int +} diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala index c8dad4cf4877..84b9295197c3 100644 --- a/test/scaladoc/scala/html/HtmlFactoryTest.scala +++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala @@ -378,11 +378,67 @@ object Test extends Properties("HtmlFactory") { true } - property("Use cases should override their original members - valid until signature is added to html") = { - createTemplate("SI_5054.scala") match { + // A piece of the signature - corresponding to the use case + def signature(no: Int, modifier: String) = (""" +
  • + +

    + + """ + modifier + """ + def + + + test(): Int + +

    +

    [use case] A simple comment +

    +
  • """).replaceAll("\\s+", "") + + property("Use cases should override their original members - TODO: Change when including full signature") = { + createTemplate("SI_5054_q1.scala") match { + case node: scala.xml.Node => + node.toString.replaceAll("\\s+","").contains(signature(1, "")) + case _ => false + } + } + + property("Use cases should keep their flags - final should not be lost") = { + createTemplate("SI_5054_q2.scala") match { + case node: scala.xml.Node => + node.toString.replaceAll("\\s+","").contains(signature(2, "final")) + case _ => false + } + } + + property("Use cases should keep their flags - implicit should not be lost") = { + createTemplate("SI_5054_q3.scala") match { + case node: scala.xml.Node => + node.toString.replaceAll("\\s+","").contains(signature(3, "implicit")) + case _ => false + } + } + + property("Use cases should keep their flags - real abstract should not be lost") = { + createTemplate("SI_5054_q4.scala") match { + case node: scala.xml.Node => + node.toString.replaceAll("\\s+","").contains(signature(4, "abstract")) + case _ => false + } + } + + property("Use cases should keep their flags - traits should not be affected") = { + createTemplate("SI_5054_q5.scala") match { + case node: scala.xml.Node => + node.toString.replaceAll("\\s+","").contains(signature(5, "")) + case _ => false + } + } + + property("Use cases should keep their flags - traits with abstract members should display abstract") = { + createTemplate("SI_5054_q6.scala") match { case node: scala.xml.Node => - node.toString.contains("A simple comment") && - ! node.toString.contains("a lost parameter") + node.toString.replaceAll("\\s+","").contains(signature(6, "abstract")) case _ => false } }