@@ -467,9 +467,33 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
467
467
* otherwise the can be `Term` containing the `New` applied to the parameters of the extended class.
468
468
* @param body List of members of the class. The members must align with the members of `cls`.
469
469
*/
470
+ // TODO add selfOpt: Option[ValDef]?
470
471
@ experimental def apply (cls : Symbol , parents : List [Tree /* Term | TypeTree */ ], body : List [Statement ]): ClassDef
471
472
def copy (original : Tree )(name : String , constr : DefDef , parents : List [Tree /* Term | TypeTree */ ], selfOpt : Option [ValDef ], body : List [Statement ]): ClassDef
472
473
def unapply (cdef : ClassDef ): (String , DefDef , List [Tree /* Term | TypeTree */ ], Option [ValDef ], List [Statement ])
474
+
475
+
476
+ /** Create the ValDef and ClassDef of a module.
477
+ *
478
+ * Equivalent to
479
+ * ```
480
+ * def module(module: Symbol, parents: List[Tree], body: List[Statement]): (ValDef, ClassDef) =
481
+ * val modCls = module.moduleClass
482
+ * val modClassDef = ClassDef(modCls, parents, body)
483
+ * val modValDef = ValDef(module, Some(Apply(Select(New(TypeIdent(modCls)), cls.primaryConstructor), Nil)))
484
+ * List(modValDef, modClassDef)
485
+ * ```
486
+ *
487
+ * @param module the module symbol (of the module lazy val)
488
+ * @param parents parents of the module class
489
+ * @param body body of the module class
490
+ * @return The module lazy val definition and module class definition.
491
+ * These should be added one after the other (in that order) in the body of a class or statements of a block.
492
+ *
493
+ * @syntax markdown
494
+ */
495
+ // TODO add selfOpt: Option[ValDef]?
496
+ @ experimental def module (module : Symbol , parents : List [Tree /* Term | TypeTree */ ], body : List [Statement ]): (ValDef , ClassDef )
473
497
}
474
498
475
499
/** Makes extension methods on `ClassDef` available without any imports */
@@ -3660,14 +3684,11 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
3660
3684
* val runSym = cls.declaredMethod("run").head
3661
3685
*
3662
3686
* val runDef = DefDef(runSym, _ => Some('{ println("run") }.asTerm))
3663
- * val clsDef = ClassDef(cls, parents, body = List(runDef))
3664
- * val newCls = Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), Nil)
3665
- * val modVal = ValDef(mod, Some(newCls))
3666
- * val modDef = List(modVal, clsDef)
3687
+ * val modDef = ClassDef.module(mod, parents, body = List(runDef))
3667
3688
*
3668
3689
* val callRun = Apply(Select(Ref(mod), runSym), Nil)
3669
3690
*
3670
- * Block(modDef, callRun)
3691
+ * Block(modDef.toList , callRun)
3671
3692
* ```
3672
3693
* constructs the equivalent to
3673
3694
* ```scala
0 commit comments