@@ -3797,6 +3797,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
3797
3797
def classSymbol (fullName : String ): Symbol
3798
3798
3799
3799
/** Generates a new class symbol for a class with a public parameterless constructor.
3800
+ * For more settings, look to the other newClass methods.
3800
3801
*
3801
3802
* Example usage:
3802
3803
* ```
@@ -3841,13 +3842,41 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
3841
3842
3842
3843
/** Generates a new class symbol for a class with a public single term clause constructor.
3843
3844
*
3844
- * @param owner The owner of the class
3845
- * @param name The name of the class
3846
- * @param parents Function returning the parent classes of the class. The first parent must not be a trait.
3847
- * Takes the constructed class symbol as an argument. Calling `cls.typeRef.asType` as part of this function will lead to cyclic reference errors.
3848
- * @param clsFlags extra flags with which the class symbol should be constructed.
3849
- * @param clsPrivateWithin the symbol within which this new class symbol should be private. May be noSymbol.
3850
- * @param conParams constructor parameter pairs of names and types.
3845
+ * Example usage:
3846
+ * ```
3847
+ * val name = nameExpr.valueOrAbort
3848
+ * def decls(cls: Symbol): List[Symbol] =
3849
+ * List(Symbol.newMethod(cls, "foo", MethodType(Nil)(_ => Nil, _ => TypeRepr.of[Unit])))
3850
+ * val parents = List(TypeTree.of[Object])
3851
+ * val cls = Symbol.newClass(
3852
+ * Symbol.spliceOwner,
3853
+ * name,
3854
+ * parents = _ => parents.map(_.tpe),
3855
+ * decls,
3856
+ * selfType = None,
3857
+ * clsFlags = Flags.EmptyFlags,
3858
+ * Symbol.noSymbol,
3859
+ * List(("idx", TypeRepr.of[Int]), ("str", TypeRepr.of[String]))
3860
+ * )
3861
+ *
3862
+ * val fooSym = cls.declaredMethod("foo").head
3863
+ * val idxSym = cls.fieldMember("idx")
3864
+ * val strSym = cls.fieldMember("str")
3865
+ * val fooDef = DefDef(fooSym, argss =>
3866
+ * Some('{println(s"Foo method call with (${${Ref(idxSym).asExpr}}, ${${Ref(strSym).asExpr}})")}.asTerm)
3867
+ * )
3868
+ * val clsDef = ClassDef(cls, parents, body = List(fooDef))
3869
+ * val newCls = Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), List(idxExpr.asTerm, strExpr.asTerm))
3870
+ *
3871
+ * Block(List(clsDef), Apply(Select(newCls, cls.methodMember("foo")(0)), Nil)).asExprOf[Unit]
3872
+ * ```
3873
+ * @param owner The owner of the class
3874
+ * @param name The name of the class
3875
+ * @param parents Function returning the parent classes of the class. The first parent must not be a trait.
3876
+ * Takes the constructed class symbol as an argument. Calling `cls.typeRef.asType` as part of this function will lead to cyclic reference errors.
3877
+ * @param clsFlags extra flags with which the class symbol should be constructed.
3878
+ * @param clsPrivateWithin the symbol within which this new class symbol should be private. May be noSymbol.
3879
+ * @param conParams constructor parameter pairs of names and types.
3851
3880
*
3852
3881
* Parameters assigned by the constructor can be obtained via `classSymbol.memberField`.
3853
3882
* This symbol starts without an accompanying definition.
@@ -3878,7 +3907,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
3878
3907
* val conMethodType =
3879
3908
* (classType: TypeRepr) => PolyType(List("T"))(_ => List(TypeBounds.empty), polyType =>
3880
3909
* MethodType(List("param"))((_: MethodType) => List(polyType.param(0)), (_: MethodType) =>
3881
- * classType
3910
+ * AppliedType( classType, List(polyType.param(0)))
3882
3911
* )
3883
3912
* )
3884
3913
* val cls = Symbol.newClass(
@@ -3940,7 +3969,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
3940
3969
* @param clsPrivateWithin the symbol within which this new class symbol should be private. May be noSymbol
3941
3970
* @param clsAnnotations annotations of the class
3942
3971
* @param conMethodType Function returning MethodOrPoly type representing the type of the constructor.
3943
- * Takes the result type as parameter which must be returned from the innermost MethodOrPoly.
3972
+ * Takes the result type as parameter which must be returned from the innermost MethodOrPoly and have type parameters applied if those are used .
3944
3973
* PolyType may only represent the first clause of the constructor.
3945
3974
* @param conFlags extra flags with which the constructor symbol should be constructed. Can be `Synthetic` | `Method` | `Private` | `Protected` | `PrivateLocal` | `Local`
3946
3975
* @param conPrivateWithin the symbol within which the constructor for this new class symbol should be private. May be noSymbol.
0 commit comments