@@ -14,11 +14,21 @@ trait MacroAnnotation extends StaticAnnotation:
14
14
* It returns a non-empty list containing the modified version of the annotated definition.
15
15
* The new tree for the definition must use the original symbol.
16
16
* New definitions can be added to the list before or after the transformed definitions, this order
17
- * will be retained.
18
- *
19
- * All definitions in the result must have the same owner. The owner can be recovered from `tree.symbol.owner`.
20
- *
21
- * The result cannot add new `class`, `object` or `type` definition. This limitation will be relaxed in the future.
17
+ * will be retained. New definitions will not be visible from outside the macro expansion.
18
+ *
19
+ * Restrictions:
20
+ * - All definitions in the result must have the same owner. The owner can be recovered from `Symbol.spliceOwner`.
21
+ * - Special case: an annotated top-level `def`, `val`, `var`, `lazy val` can return a `class`/`object`
22
+ definition that is owned by the package or package object.
23
+ * - Can not return a `type`.
24
+ * - Annotated top-level `class`/`object` can not return top-level `def`, `val`, `var`, `lazy val`.
25
+ * - Can not see new definition in user written code.
26
+ *
27
+ * Good practices:
28
+ * - Make your new definitions private if you can.
29
+ * - New definitions added as class members should use a fresh name (`Symbol.freshName`) to avoid collisions.
30
+ * - New top-level definitions should use a fresh name (`Symbol.freshName`) that includes the name of the annotated
31
+ * member as a prefix to avoid collisions definitions added in other files.
22
32
*
23
33
* IMPORTANT: When developing and testing a macro annotation, you must enable `-Xcheck-macros` and `-Ycheck:all`.
24
34
*
@@ -184,5 +194,7 @@ trait MacroAnnotation extends StaticAnnotation:
184
194
*
185
195
* @param Quotes Implicit instance of Quotes used for tree reflection
186
196
* @param tree Tree that will be transformed
197
+ *
198
+ * @syntax markdown
187
199
*/
188
200
def transform (using Quotes )(tree : quotes.reflect.Definition ): List [quotes.reflect.Definition ]
0 commit comments