From 0b69be68d3100103ebfd636bbc36f9cdcbd6fb28 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Fri, 19 Aug 2016 15:28:39 +0200 Subject: Add phase to deal with constructors --- dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala | 1 + .../dottydoc/core/AlternateConstructorsPhase.scala | 34 ++++ .../dotty/tools/dottydoc/core/DocASTPhase.scala | 4 +- .../tools/dottydoc/core/MiniPhaseTransform.scala | 19 +- .../src/dotty/tools/dottydoc/model/entities.scala | 9 +- .../src/dotty/tools/dottydoc/model/factories.scala | 21 +- .../src/dotty/tools/dottydoc/model/internal.scala | 3 + dottydoc/src/dotty/tools/dottydoc/model/json.scala | 8 +- dottydoc/test/BaseTest.scala | 24 +-- dottydoc/test/ConstructorTest.scala | 211 +++++++++++++++++++++ dottydoc/test/PackageStructure.scala | 20 +- dottydoc/test/SimpleComments.scala | 6 +- dottydoc/test/WhitelistedStdLib.scala | 12 +- 13 files changed, 318 insertions(+), 54 deletions(-) create mode 100644 dottydoc/src/dotty/tools/dottydoc/core/AlternateConstructorsPhase.scala create mode 100644 dottydoc/test/ConstructorTest.scala diff --git a/dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala b/dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala index 61de1cfd8..2d4c7abcf 100644 --- a/dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala +++ b/dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala @@ -35,6 +35,7 @@ class DocCompiler extends Compiler { new LinkParamListTypes, new LinkImplicitlyAddedTypes, new LinkSuperTypes, + new AlternateConstructors, new SortMembers)) ) } diff --git a/dottydoc/src/dotty/tools/dottydoc/core/AlternateConstructorsPhase.scala b/dottydoc/src/dotty/tools/dottydoc/core/AlternateConstructorsPhase.scala new file mode 100644 index 000000000..53c96fc87 --- /dev/null +++ b/dottydoc/src/dotty/tools/dottydoc/core/AlternateConstructorsPhase.scala @@ -0,0 +1,34 @@ +package dotty.tools +package dottydoc +package core + +import dotc.core.Contexts.Context + +import transform.DocMiniPhase +import model._ +import model.internal._ + +/** This DocMiniPhase adds the alternate constructors, currently defined as + * methods with the name ``, to the Entity#constructors list + */ +class AlternateConstructors extends DocMiniPhase { + def partitionMembers(ent: Entity with Constructors with Members): (List[List[ParamList]], List[Entity]) = { + val (constructors, members) = ent.members.partition(x => x.name == "") + + val paramLists: List[List[ParamList]] = constructors.collect { + case df: Def => df.paramLists + } + + (ent.constructors ++ paramLists, members) + } + + override def transformClass(implicit ctx: Context) = { case cls: ClassImpl => + val (constructors, members) = partitionMembers(cls) + cls.copy(members = members, constructors = constructors) + } + + override def transformCaseClass(implicit ctx: Context) = { case cc: CaseClassImpl => + val (constructors, members) = partitionMembers(cc) + cc.copy(members = members, constructors = constructors) + } +} diff --git a/dottydoc/src/dotty/tools/dottydoc/core/DocASTPhase.scala b/dottydoc/src/dotty/tools/dottydoc/core/DocASTPhase.scala index 013010971..7744752ce 100644 --- a/dottydoc/src/dotty/tools/dottydoc/core/DocASTPhase.scala +++ b/dottydoc/src/dotty/tools/dottydoc/core/DocASTPhase.scala @@ -97,7 +97,7 @@ class DocASTPhase extends Phase { val name = n.decode.toString val newPath = prev :+ name //TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well - TraitImpl(name, collectMembers(rhs), flags(t), newPath, typeParams(t.symbol), superTypes(t)) + TraitImpl(name, collectMembers(rhs), flags(t), newPath, typeParams(t.symbol), traitParameters(t.symbol), superTypes(t)) /** objects, on the format "Object$" so drop the last letter */ case o @ TypeDef(n, rhs) if o.symbol.is(Flags.Module) => @@ -110,7 +110,7 @@ class DocASTPhase extends Phase { val name = n.decode.toString val newPath = prev :+ name //TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well - (name, collectMembers(rhs), flags(c), newPath, typeParams(c.symbol), superTypes(c), None) match { + (name, collectMembers(rhs), flags(c), newPath, typeParams(c.symbol), constructors(c.symbol), superTypes(c), None) match { case x if c.symbol.is(Flags.CaseClass) => CaseClassImpl.tupled(x) case x => ClassImpl.tupled(x) } diff --git a/dottydoc/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala b/dottydoc/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala index 7bdb2bf4e..2690ac7b7 100644 --- a/dottydoc/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala +++ b/dottydoc/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala @@ -88,15 +88,16 @@ object transform { newPackage } - case c: Class => transformEntity(c, _.classTransformation) { newClass => + case c: Class => transformEntity(c, _.classTransformation) { cls => ClassImpl( - newClass.name, - newClass.members.map(traverse), - newClass.modifiers, - newClass.path, - newClass.typeParams, - newClass.superTypes, - newClass.comment + cls.name, + cls.members.map(traverse), + cls.modifiers, + cls.path, + cls.typeParams, + cls.constructors, + cls.superTypes, + cls.comment ) } case cc: CaseClass => transformEntity(cc, _.caseClassTransformation) { cc => @@ -106,6 +107,7 @@ object transform { cc.modifiers, cc.path, cc.typeParams, + cc.constructors, cc.superTypes, cc.comment ) @@ -117,6 +119,7 @@ object transform { trt.modifiers, trt.path, trt.typeParams, + trt.traitParams, trt.superTypes, trt.comment ) diff --git a/dottydoc/src/dotty/tools/dottydoc/model/entities.scala b/dottydoc/src/dotty/tools/dottydoc/model/entities.scala index 4d3a33b33..76792070c 100644 --- a/dottydoc/src/dotty/tools/dottydoc/model/entities.scala +++ b/dottydoc/src/dotty/tools/dottydoc/model/entities.scala @@ -57,6 +57,10 @@ trait ParamList { def isImplicit: Boolean } +trait Constructors { + def constructors: List[List[ParamList]] +} + trait ImplicitlyAddedEntity extends Entity { def implicitlyAddedFrom: Option[Reference] } @@ -67,15 +71,16 @@ trait Package extends Entity with Members { def children: List[Entity with Members] } -trait Class extends Entity with Modifiers with TypeParams with SuperTypes with Members { +trait Class extends Entity with Modifiers with TypeParams with Constructors with SuperTypes with Members { val kind = "class" } -trait CaseClass extends Entity with Modifiers with TypeParams with SuperTypes with Members { +trait CaseClass extends Entity with Modifiers with TypeParams with Constructors with SuperTypes with Members { override val kind = "case class" } trait Trait extends Entity with Modifiers with TypeParams with SuperTypes with Members { + def traitParams: List[ParamList] override val kind = "trait" } diff --git a/dottydoc/src/dotty/tools/dottydoc/model/factories.scala b/dottydoc/src/dotty/tools/dottydoc/model/factories.scala index b5cf15148..b19b836ee 100644 --- a/dottydoc/src/dotty/tools/dottydoc/model/factories.scala +++ b/dottydoc/src/dotty/tools/dottydoc/model/factories.scala @@ -6,19 +6,17 @@ import references._ import dotty.tools.dotc import dotc.core.Types._ import dotc.core.TypeApplications._ -import dotc.core.Flags import dotc.core.Contexts.Context -import dotc.core.Symbols.Symbol +import dotc.core.Symbols.{ Symbol, ClassSymbol } import dotty.tools.dotc.core.SymDenotations._ import dotty.tools.dotc.core.Names.TypeName -import dotc.core.{ Flags => DottyFlags } import dotc.ast.Trees._ object factories { import dotty.tools.dotc.ast.tpd._ import dotty.tools.dottydoc.model.internal.ParamListImpl - import DottyFlags._ + import dotc.core.Flags._ type TypeTree = dotty.tools.dotc.ast.Trees.Tree[Type] @@ -118,11 +116,11 @@ object factories { pt.paramNames.map(_.show.split("\\$").last) case ClassInfo(_, _, _, decls, _) => decls.iterator - .filter(_.flags is Flags.TypeParam) + .filter(_.flags is TypeParam) .map { tp => val prefix = - if (tp.flags is Flags.Covariant) "+" - else if (tp.flags is Flags.Contravariant) "-" + if (tp.flags is Covariant) "+" + else if (tp.flags is Contravariant) "-" else "" prefix + tp.name.show.split("\\$").last } @@ -131,6 +129,15 @@ object factories { Nil } + def constructors(sym: Symbol)(implicit ctx: Context): List[List[ParamList]] = sym match { + case sym: ClassSymbol => + paramLists(sym.primaryConstructor.info) :: Nil + case _ => Nil + } + + def traitParameters(sym: Symbol)(implicit ctx: Context): List[ParamList] = + constructors(sym).head + def paramLists(tpe: Type)(implicit ctx: Context): List[ParamList] = tpe match { case pt: PolyType => paramLists(pt.resultType) diff --git a/dottydoc/src/dotty/tools/dottydoc/model/internal.scala b/dottydoc/src/dotty/tools/dottydoc/model/internal.scala index 63e97743d..6afb1ec9b 100644 --- a/dottydoc/src/dotty/tools/dottydoc/model/internal.scala +++ b/dottydoc/src/dotty/tools/dottydoc/model/internal.scala @@ -26,6 +26,7 @@ object internal { modifiers: List[String], path: List[String], typeParams: List[String] = Nil, + constructors: List[List[ParamList]] = Nil, superTypes: List[MaterializableLink] = Nil, var comment: Option[Comment] = None ) extends Class with Impl @@ -36,6 +37,7 @@ object internal { modifiers: List[String], path: List[String], typeParams: List[String] = Nil, + constructors: List[List[ParamList]] = Nil, superTypes: List[MaterializableLink] = Nil, var comment: Option[Comment] = None ) extends CaseClass with Impl @@ -46,6 +48,7 @@ object internal { modifiers: List[String], path: List[String], typeParams: List[String] = Nil, + traitParams: List[ParamList] = Nil, superTypes: List[MaterializableLink] = Nil, var comment: Option[Comment] = None ) extends Trait with Impl diff --git a/dottydoc/src/dotty/tools/dottydoc/model/json.scala b/dottydoc/src/dotty/tools/dottydoc/model/json.scala index 9bf37295c..145728f8a 100644 --- a/dottydoc/src/dotty/tools/dottydoc/model/json.scala +++ b/dottydoc/src/dotty/tools/dottydoc/model/json.scala @@ -34,7 +34,7 @@ object json { def json: String = { val (secondTitle, secondValue, kind) = link match { case ul: UnsetLink => ("query".json, ul.query.json, "UnsetLink".json) - case ml: MaterializedLink => ("target", ml.target.json, "MaterializedLink".json) + case ml: MaterializedLink => ("target".json, ml.target.json, "MaterializedLink".json) case nl: NoLink => ("target".json, nl.target.json, "NoLink".json) } s"""{"title":${link.title.json},$secondTitle:${secondValue},"kind":$kind}""" @@ -70,11 +70,11 @@ object json { case ent: Package => s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"package"}""" case ent: Class => - s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"class"}""" + s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"constructors":${ent.constructors.map(xs => xs.map(_.json).mkString("[",",","]")).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"class"}""" case ent: CaseClass => - s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"case class"}""" + s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"constructors":${ent.constructors.map(xs => xs.map(_.json).mkString("[",",","]")).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"case class"}""" case ent: Trait => - s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"trait"}""" + s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"traitParams":${ent.traitParams.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"trait"}""" case ent: Object => s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"object"}""" case ent: Def => diff --git a/dottydoc/test/BaseTest.scala b/dottydoc/test/BaseTest.scala index 7f077d27b..2233d03c8 100644 --- a/dottydoc/test/BaseTest.scala +++ b/dottydoc/test/BaseTest.scala @@ -7,6 +7,7 @@ import dotc.util.SourceFile import dotc.core.Phases.Phase import dotc.typer.FrontEnd import dottydoc.core.DocASTPhase +import model.Package trait DottyTest { dotty.tools.dotc.parsing.Scanners // initialize keywords @@ -21,34 +22,33 @@ trait DottyTest { ctx } - private def compilerWithChecker(assertion: DocASTPhase => Unit) = new DocCompiler { - private[this] val docPhase = new DocASTPhase - - override def phases = - List(new FrontEnd) :: - List(docPhase) :: + private def compilerWithChecker(assertion: Map[String, Package] => Unit) = new DocCompiler { + private[this] val assertionPhase: List[List[Phase]] = List(new Phase { def phaseName = "assertionPhase" - override def run(implicit ctx: Context): Unit = assertion(docPhase) - }) :: - Nil + override def run(implicit ctx: Context): Unit = + assertion(ctx.docbase.packages[Package].toMap) + }) :: Nil + + override def phases = + super.phases ++ assertionPhase } - def checkSource(source: String)(assertion: DocASTPhase => Unit): Unit = { + def checkSource(source: String)(assertion: Map[String, Package] => Unit): Unit = { val c = compilerWithChecker(assertion) c.rootContext(ctx) val run = c.newRun run.compile(source) } - def checkFiles(sources: List[String])(assertion: DocASTPhase => Unit): Unit = { + def checkFiles(sources: List[String])(assertion: Map[String, Package] => Unit): Unit = { val c = compilerWithChecker(assertion) c.rootContext(ctx) val run = c.newRun run.compile(sources) } - def checkSources(sourceFiles: List[SourceFile])(assertion: DocASTPhase => Unit): Unit = { + def checkSources(sourceFiles: List[SourceFile])(assertion: Map[String, Package] => Unit): Unit = { val c = compilerWithChecker(assertion) c.rootContext(ctx) val run = c.newRun diff --git a/dottydoc/test/ConstructorTest.scala b/dottydoc/test/ConstructorTest.scala new file mode 100644 index 000000000..8aa883022 --- /dev/null +++ b/dottydoc/test/ConstructorTest.scala @@ -0,0 +1,211 @@ +package dotty.tools +package dottydoc + +import org.junit.Test +import org.junit.Assert._ + +import dotc.util.SourceFile +import model._ +import model.internal._ +import model.references._ + +class Constructors extends DottyTest { + @Test def singleClassConstructor = { + val source = new SourceFile ( + "Class.scala", + """ + |package scala + | + |class Class(val str: String) + """.stripMargin + ) + + checkSources(source :: Nil) { packages => + packages("scala") match { + case PackageImpl(_, List(cls: Class), _, _) => + cls.constructors.headOption match { + case Some(ParamListImpl(NamedReference("str", _, false, false) :: Nil, false) :: Nil) => + // success! + case _ => assert(false, s"Incorrect constructor found: ${cls.constructors}") + } + } + } + } + + @Test def constructorPlusImplicitArgList = { + val source = new SourceFile ( + "Class.scala", + """ + |package scala + | + |class Class(val str1: String)(implicit str2: String) + """.stripMargin + ) + + checkSources(source :: Nil) { packages => + packages("scala") match { + case PackageImpl(_, List(cls: Class), _, _) => + cls.constructors match { + case ( + ParamListImpl(NamedReference("str1", _, false, false) :: Nil, false) :: + ParamListImpl(NamedReference("str2", _, false, false) :: Nil, true) :: Nil + ) :: Nil => + // success! + case _ => assert(false, s"Incorrect constructor found: ${cls.constructors}") + } + } + } + } + + @Test def multipleArgumentListsForConstructor = { + val source = new SourceFile ( + "Class.scala", + """ + |package scala + | + |class Class(val str1: String)(val str2: String)(implicit str3: String) + """.stripMargin + ) + + checkSources(source :: Nil) { packages => + packages("scala") match { + case PackageImpl(_, List(cls: Class), _, _) => + cls.constructors match { + case ( + ParamListImpl(NamedReference("str1", _, false, false) :: Nil, false) :: + ParamListImpl(NamedReference("str2", _, false, false) :: Nil, false) :: + ParamListImpl(NamedReference("str3", _, false, false) :: Nil, true) :: Nil + ) :: Nil => + // success! + case _ => assert(false, s"Incorrect constructor found: ${cls.constructors}") + } + } + } + } + + @Test def multipleConstructors = { + val source = new SourceFile ( + "Class.scala", + """ + |package scala + | + |class Class(val main: String) { + | def this(alt1: Int) = + | this("String") + | + | def this(alt2: List[String]) = + | this(alt2.head) + |} + """.stripMargin + ) + + checkSources(source :: Nil) { packages => + packages("scala") match { + case PackageImpl(_, List(cls: Class), _, _) => + cls.constructors match { + case ( + ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil + ) :: ( + ParamListImpl(NamedReference("alt1", _, false, false) :: Nil, false) :: Nil + ) :: ( + ParamListImpl(NamedReference("alt2", _, false, false) :: Nil, false) :: Nil + ) :: Nil => + // success! + case _ => + assert( + false, + s"""Incorrect constructor found:\n${cls.constructors.mkString("\n")}""" + ) + } + } + } + } + + @Test def multipleConstructorsCC = { + val source = new SourceFile ( + "Class.scala", + """ + |package scala + | + |case class Class(val main: String) { + | def this(alt1: Int) = + | this("String") + | + | def this(alt2: List[String]) = + | this(alt2.head) + |} + """.stripMargin + ) + + checkSources(source :: Nil) { packages => + packages("scala") match { + case PackageImpl(_, List(cls: CaseClass, obj: Object), _, _) => + cls.constructors match { + case ( + ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil + ) :: ( + ParamListImpl(NamedReference("alt1", _, false, false) :: Nil, false) :: Nil + ) :: ( + ParamListImpl(NamedReference("alt2", _, false, false) :: Nil, false) :: Nil + ) :: Nil => + // success! + case _ => + println(obj.members.map(x => x.kind + " " + x.name)) + assert( + false, + s"""Incorrect constructor found:\n${cls.constructors.mkString("\n")}""" + ) + } + } + } + } + + @Test def traitParameters = { + val source = new SourceFile ( + "Trait.scala", + """ + |package scala + | + |trait Trait(val main: String) + """.stripMargin + ) + + checkSources(source :: Nil) { packages => + packages("scala") match { + case PackageImpl(_, List(trt: Trait), _, _) => + trt.traitParams match { + case ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil => + case _ => + assert( + false, + s"""Incorrect constructor found:\n${trt.traitParams.mkString("\n")}""" + ) + } + } + } + } + + @Test def testJson = { + val actualSource = + """ + |package scala + | + |trait Trait(val main: String) + |class Class(val main: String) + |case class CaseClass(main: String) + """.stripMargin + + val source = new SourceFile ("JsonTest.scala", actualSource) + + checkSources(source :: Nil) { packages => + packages("scala") match { + case PackageImpl(_, List(cc: CaseClass, _, cls: Class, trt: Trait), _, _) => + import model.json._ + lazy val incorrectJson = s"The json generated for:\n$actualSource\n\nIs not correct" + assert(cc.json.contains(s""""constructors":[[{"list":[{"title":"main""""), incorrectJson) + assert(cls.json.contains(s""""constructors":[[{"list":[{"title":"main""""), incorrectJson) + assert(trt.json.contains(s""""traitParams":[{"list":[{"title":"main""""), incorrectJson) + } + } + } +} diff --git a/dottydoc/test/PackageStructure.scala b/dottydoc/test/PackageStructure.scala index af6e52184..00caaa2c0 100644 --- a/dottydoc/test/PackageStructure.scala +++ b/dottydoc/test/PackageStructure.scala @@ -10,7 +10,7 @@ import model.internal._ class PackageStructure extends DottyTest { @Test def multipleCompilationUnits = { val source1 = new SourceFile( - "", + "TraitA.scala", """ |package scala | @@ -19,7 +19,7 @@ class PackageStructure extends DottyTest { ) val source2 = new SourceFile( - "", + "TraitB.scala", """ |package scala | @@ -27,8 +27,8 @@ class PackageStructure extends DottyTest { """.stripMargin ) - checkSources(source1 :: source2 :: Nil) { doc => - doc.packages("scala") match { + checkSources(source1 :: source2 :: Nil) { packages => + packages("scala") match { case PackageImpl(_, List(tA, tB), _, _) => assert( tA.name == "A" && tB.name == "B", @@ -42,7 +42,7 @@ class PackageStructure extends DottyTest { @Test def multiplePackages = { val source1 = new SourceFile( - "", + "TraitA.scala", """ |package scala |package collection @@ -51,7 +51,7 @@ class PackageStructure extends DottyTest { """.stripMargin) val source2 = new SourceFile( - "", + "TraitB.scala", """ |package scala |package collection @@ -59,8 +59,8 @@ class PackageStructure extends DottyTest { |trait B """.stripMargin) - checkSources(source1 :: source2 :: Nil) { doc => - doc.packages("scala") match { + checkSources(source1 :: source2 :: Nil) { packages => + packages("scala") match { case PackageImpl( "scala", List(PackageImpl("scala.collection", List(tA, tB), _, _)), @@ -72,10 +72,10 @@ class PackageStructure extends DottyTest { ) case _ => - fail(s"""Incorrect package structure for 'scala' package: ${doc.packages("scala")}""") + fail(s"""Incorrect package structure for 'scala' package: ${packages("scala")}""") } - doc.packages("scala.collection") match { + packages("scala.collection") match { case PackageImpl("scala.collection", List(tA, tB), _, _) => assert( tA.name == "A" && tB.name == "B", diff --git a/dottydoc/test/SimpleComments.scala b/dottydoc/test/SimpleComments.scala index ad9b7b1a6..959eb1745 100644 --- a/dottydoc/test/SimpleComments.scala +++ b/dottydoc/test/SimpleComments.scala @@ -15,9 +15,9 @@ class TestSimpleComments extends DottyTest { |trait HelloWorld """.stripMargin - checkSource(source) { doc => - val traitCmt = doc - .packages("scala") + checkSource(source) { packages => + val traitCmt = + packages("scala") .children.find(_.path.mkString(".") == "scala.HelloWorld") .flatMap(_.comment.map(_.body)) .get diff --git a/dottydoc/test/WhitelistedStdLib.scala b/dottydoc/test/WhitelistedStdLib.scala index 0225ba218..48697ea7f 100644 --- a/dottydoc/test/WhitelistedStdLib.scala +++ b/dottydoc/test/WhitelistedStdLib.scala @@ -19,9 +19,9 @@ class TestWhitelistedCollections extends DottyTest { } @Test def arrayHasDocumentation = - checkFiles(files) { doc => - val array = doc - .packages("scala") + checkFiles(files) { packages => + val array = + packages("scala") .children.find(_.path.mkString(".") == "scala.Array") .get @@ -29,9 +29,9 @@ class TestWhitelistedCollections extends DottyTest { } @Test def traitImmutableHasDocumentation = - checkFiles(files) { doc => - val imm = doc - .packages("scala") + checkFiles(files) { packages => + val imm = + packages("scala") .children.find(_.path.mkString(".") == "scala.Immutable") .get -- cgit v1.2.3