@@ -496,7 +496,6 @@ object MoleculeBoilerplate {
496
496
val (thisIn, nextIn) = if (maxIn == 0 || in == maxIn) (" P" + (out + in + 1 ), " P" + (out + in + 2 )) else (s " ${ns}_In_ ${i + 1 }_0 " , s " ${ns}_In_ ${i + 1 }_1 " )
497
497
val types = InTypes mkString " , "
498
498
s """
499
- |
500
499
|/********* Input molecules awaiting $i input $s *******************************/
501
500
|
502
501
|trait ${ns}_In_ ${i}_0[ $types] extends $ns with In_ ${i}_0[ ${ns}_In_ ${i}_0, ${ns}_In_ ${i}_1, $thisIn, $nextIn, $types] {
@@ -533,7 +532,7 @@ object MoleculeBoilerplate {
533
532
}
534
533
}
535
534
536
- def namespaceBody (d : Definition , namespace : Namespace ) = {
535
+ def namespaceBodies (d : Definition , namespace : Namespace ) : ( String , Seq [( Int , String )] ) = {
537
536
val inArity = d.in
538
537
val outArity = d.out
539
538
val Ns = namespace.ns
@@ -592,38 +591,57 @@ object MoleculeBoilerplate {
592
591
593
592
val nsArities = d.nss.map(ns => ns.ns -> ns.attrs.size).toMap
594
593
595
- val nsTraits = (for {
596
- in <- 0 to inArity
597
- out <- 0 to outArity
598
- } yield nsTrait(namespace, in, out, inArity, outArity, nsArities)).mkString(" \n " )
599
-
600
594
val extraImports0 = attrs.collect {
601
595
case Val (_, _, _, tpe, _, _, _) if tpe.take(4 ) == " java" => tpe
602
596
}.distinct
603
597
val extraImports = if (extraImports0.isEmpty) " " else extraImports0.mkString(s " \n import " , " \n import " , " " )
604
598
605
- s """ /*
606
- |* AUTO-GENERATED CODE - DON'T CHANGE!
607
- |*
608
- |* Manual changes to this file will likely break molecules!
609
- |* Instead, change the molecule definition file(s) and recompile your project with `sbt compile`.
610
- |*/
611
- |package ${d.pkg}.dsl. ${firstLow(d.domain)}
612
- |import molecule.dsl.schemaDSL._
613
- |import molecule.dsl._ $extraImports
614
- |
615
- |
616
- |object $Ns extends ${Ns }_0 with FirstNS {
617
- | def apply(e: Long): ${Ns }_0 = ???
618
- |}
619
- |
620
- |trait $Ns {
621
- | $attrClasses
622
- |
623
- | $attrClassesOpt
624
- |}
625
- |
626
- | $nsTraits""" .stripMargin
599
+ val nsTraitsOut = (0 to outArity).map(nsTrait(namespace, 0 , _, inArity, outArity, nsArities)).mkString(" \n " )
600
+ val outFile : String =
601
+ s """ /*
602
+ |* AUTO-GENERATED CODE - DON'T CHANGE!
603
+ |*
604
+ |* Manual changes to this file will likely break molecules!
605
+ |* Instead, change the molecule definition file(s) and recompile your project with `sbt compile`.
606
+ |*/
607
+ |package ${d.pkg}.dsl. ${firstLow(d.domain)}
608
+ |import molecule.dsl.schemaDSL._
609
+ |import molecule.dsl._ $extraImports
610
+ |
611
+ |
612
+ |object $Ns extends ${Ns }_0 with FirstNS {
613
+ | def apply(e: Long): ${Ns }_0 = ???
614
+ |}
615
+ |
616
+ |trait $Ns {
617
+ | $attrClasses
618
+ |
619
+ | $attrClassesOpt
620
+ |}
621
+ |
622
+ | $nsTraitsOut""" .stripMargin
623
+
624
+ val nsTraitsIn : Seq [(Int , String )] = if (inArity == 0 ) Nil else (1 to inArity).map(in =>
625
+ (in, (0 to outArity).map(nsTrait(namespace, in, _, inArity, outArity, nsArities)).mkString(" \n " ))
626
+ )
627
+ val inFiles : Seq [(Int , String )] = nsTraitsIn.map { case (in, inTraits) =>
628
+ val inFile : String =
629
+ s """ /*
630
+ |* AUTO-GENERATED CODE - DON'T CHANGE!
631
+ |*
632
+ |* Manual changes to this file will likely break molecules!
633
+ |* Instead, change the molecule definition file(s) and recompile your project with `sbt compile`.
634
+ |*/
635
+ |package ${d.pkg}.dsl. ${firstLow(d.domain)}
636
+ |import molecule.dsl.schemaDSL._
637
+ |import molecule.dsl._ $extraImports
638
+ |
639
+ | $inTraits""" .stripMargin
640
+
641
+ (in, inFile)
642
+ }
643
+
644
+ (outFile, inFiles)
627
645
}
628
646
629
647
def generate (srcManaged : File , domainDirs : Seq [String ], allIndexed : Boolean = true ): Seq [File ] = {
@@ -642,11 +660,17 @@ object MoleculeBoilerplate {
642
660
IO .write(schemaFile, schemaBody(d))
643
661
644
662
// Write namespace files
645
- val namespaceFiles = d.nss.map { ns =>
646
- val nsFile : File = d.pkg.split('.' ).toList.foldLeft(srcManaged)((dir, pkg) => dir / pkg) / " dsl" / firstLow(d.domain) / s " ${ns.ns}.scala "
647
- val nsBody = namespaceBody(d, ns)
648
- IO .write(nsFile, nsBody)
649
- nsFile
663
+ val namespaceFiles = d.nss.flatMap { ns =>
664
+ val (outBody, inBodies) = namespaceBodies(d, ns)
665
+ val outFile : File = d.pkg.split('.' ).toList.foldLeft(srcManaged)((dir, pkg) => dir / pkg) / " dsl" / firstLow(d.domain) / s " ${ns.ns}.scala "
666
+ IO .write(outFile, outBody)
667
+
668
+ val inFiles = inBodies.map { case (i, inBody) =>
669
+ val inFile : File = d.pkg.split('.' ).toList.foldLeft(srcManaged)((dir, pkg) => dir / pkg) / " dsl" / firstLow(d.domain) / s " ${ns.ns}_in $i.scala "
670
+ IO .write(inFile, inBody)
671
+ inFile
672
+ }
673
+ outFile +: inFiles
650
674
}
651
675
652
676
schemaFile +: namespaceFiles
0 commit comments