@@ -2,7 +2,16 @@ package scala.quoted
2
2
3
3
import scala .reflect .TypeTest
4
4
5
- /** Current Quotes in scope */
5
+ /** Current Quotes in scope
6
+ *
7
+ * Usage:
8
+ * ```scala
9
+ * def myExpr[T](using Quotes): Expr[T] = {
10
+ * import quotes.relect._
11
+ * ...
12
+ * }
13
+ * ```
14
+ */
6
15
inline def quotes (using q : Quotes ): q.type = q
7
16
8
17
/** Quotation context provided by a macro expansion or in the scope of `scala.quoted.staging.run`.
@@ -223,8 +232,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
223
232
val Tree : TreeModule
224
233
225
234
/** Methods of the module object `val Tree` */
226
- trait TreeModule { this : Tree .type =>
227
- }
235
+ trait TreeModule { this : Tree .type => }
228
236
229
237
/** Makes extension methods on `Tree` available without any imports */
230
238
given TreeMethods : TreeMethods
@@ -260,7 +268,21 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
260
268
261
269
}
262
270
263
- /** Tree representing a pacakage clause in the source code */
271
+ /** Tree representing a pacakage clause in the source code
272
+ *
273
+ * ```scala
274
+ * package foo {
275
+ * // package stats
276
+ * }
277
+ * ```
278
+ *
279
+ * or
280
+ *
281
+ * ```scala
282
+ * package foo.bar
283
+ * // package stats
284
+ * ```
285
+ */
264
286
type PackageClause <: Tree
265
287
266
288
/** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `PackageClause` */
@@ -271,8 +293,11 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
271
293
272
294
/** Methods of the module object `val PackageClause` */
273
295
trait PackageClauseModule { this : PackageClause .type =>
296
+ /** Create a package clause `package pid { stats }` */
274
297
def apply (pid : Ref , stats : List [Tree ]): PackageClause
298
+ /** Copy a package clause `package pid { stats }` */
275
299
def copy (original : Tree )(pid : Ref , stats : List [Tree ]): PackageClause
300
+ /** Matches a package clause `package pid { stats }` and extracts the `pid` and `stats` */
276
301
def unapply (tree : PackageClause ): (Ref , List [Tree ])
277
302
}
278
303
@@ -282,12 +307,17 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
282
307
/** Extension methods of `PackageClause` */
283
308
trait PackageClauseMethods :
284
309
extension (self : PackageClause )
310
+ /** Tree containing the package name */
285
311
def pid : Ref
312
+ /** Definitions, imports or exports within the package */
286
313
def stats : List [Tree ]
287
314
end extension
288
315
end PackageClauseMethods
289
316
290
- /** Tree representing an import in the source code */
317
+ /** Tree representing an import in the source code.
318
+ *
319
+ * See also documentation on `Selector`.
320
+ */
291
321
type Import <: Statement
292
322
293
323
/** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is an `Import` */
@@ -298,8 +328,11 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
298
328
299
329
/** Methods of the module object `val Import` */
300
330
trait ImportModule { this : Import .type =>
331
+ /** Create an `Import` with the given qualifier and selectors */
301
332
def apply (expr : Term , selectors : List [Selector ]): Import
333
+ /** Copy an `Import` with the given qualifier and selectors */
302
334
def copy (original : Tree )(expr : Term , selectors : List [Selector ]): Import
335
+ /** Matches an `Import` and extracts the qualifier and selectors */
303
336
def unapply (tree : Import ): (Term , List [Selector ])
304
337
}
305
338
@@ -309,7 +342,12 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
309
342
/** Extension methods of `Import` */
310
343
trait ImportMethods :
311
344
extension (self : Import )
345
+ /** Qualifier of the import */
312
346
def expr : Term
347
+ /** List selectors of the import
348
+ *
349
+ * See documentation on `Selector`
350
+ */
313
351
def selectors : List [Selector ]
314
352
end extension
315
353
end ImportMethods
@@ -327,6 +365,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
327
365
328
366
/** Methods of the module object `val Export` */
329
367
trait ExportModule { this : Export .type =>
368
+ /** Matches an `Export` and extracts the qualifier and selectors */
330
369
def unapply (tree : Export ): (Term , List [Selector ])
331
370
}
332
371
@@ -336,7 +375,12 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
336
375
/** Extension methods of `Export` */
337
376
trait ExportMethods :
338
377
extension (self : Export )
378
+ /** Qualifier of the export */
339
379
def expr : Term
380
+ /** List selectors of the export
381
+ *
382
+ * See documentation on `Selector`
383
+ */
340
384
def selectors : List [Selector ]
341
385
end extension
342
386
end ExportMethods
@@ -367,6 +411,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
367
411
/** Extension methods of `Definition` */
368
412
trait DefinitionMethods :
369
413
extension (self : Definition )
414
+ /** Name of the definition */
370
415
def name : String
371
416
end extension
372
417
end DefinitionMethods
@@ -395,10 +440,31 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
395
440
/** Extension methods of `ClassDef` */
396
441
trait ClassDefMethods :
397
442
extension (self : ClassDef )
443
+ /** The primary constructor of this class */
398
444
def constructor : DefDef
445
+ /** List of extended parent classes or traits.
446
+ * The first parent is always a class.
447
+ */
399
448
def parents : List [Tree /* Term | TypeTree */ ]
400
- def derived : List [TypeTree ]
449
+ /** List of derived type classes */
450
+ def derived : List [TypeTree ] // TODO remove? It seems these don't exist after desugaring
451
+ /** Self-type of the class
452
+ *
453
+ * ```scala
454
+ * class C { self: T =>
455
+ * ...
456
+ * }
457
+ * ```
458
+ */
401
459
def self : Option [ValDef ]
460
+ /** Statements within the class
461
+ *
462
+ * ```scala
463
+ * class C {
464
+ * ... // statemets
465
+ * }
466
+ * ```
467
+ */
402
468
def body : List [Statement ]
403
469
end extension
404
470
end ClassDefMethods
@@ -452,7 +518,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
452
518
/** List of term parameter clauses */
453
519
def termParamss : List [TermParamClause ]
454
520
455
- /** The tree of the return type of the method */
521
+ /** The tree of the return type of this `def` definition */
456
522
def returnTpt : TypeTree
457
523
458
524
/** The tree of the implementation of the method.
@@ -496,7 +562,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
496
562
/** Extension methods of `ValDef` */
497
563
trait ValDefMethods :
498
564
extension (self : ValDef )
565
+ /** The type tree of this `val` definition */
499
566
def tpt : TypeTree
567
+ /** The right-hand side of this `val` definition */
500
568
def rhs : Option [Term ]
501
569
end extension
502
570
end ValDefMethods
@@ -515,8 +583,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
515
583
/** Methods of the module object `val TypeDef` */
516
584
trait TypeDefModule { this : TypeDef .type =>
517
585
def apply (symbol : Symbol ): TypeDef
518
- def copy (original : Tree )(name : String , rhs : Tree /* TypeTree | TypeBoundsTree */ ): TypeDef
519
- def unapply (tdef : TypeDef ): (String , Tree /* TypeTree | TypeBoundsTree */ /* TypeTree | TypeBoundsTree */ )
586
+ def copy (original : Tree )(name : String , rhs : Tree ): TypeDef
587
+ def unapply (tdef : TypeDef ): (String , Tree )
520
588
}
521
589
522
590
/** Makes extension methods on `TypeDef` available without any imports */
@@ -525,7 +593,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
525
593
/** Extension methods of `TypeDef` */
526
594
trait TypeDefMethods :
527
595
extension (self : TypeDef )
528
- def rhs : Tree /* TypeTree | TypeBoundsTree*/
596
+ /** The type bounds on the right-hand side of this `type` definition */
597
+ def rhs : Tree
529
598
end extension
530
599
end TypeDefMethods
531
600
@@ -666,6 +735,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
666
735
/** Extension methods of `Ident` */
667
736
trait IdentMethods :
668
737
extension (self : Ident )
738
+ /** Name of this `Ident` */
669
739
def name : String
670
740
end extension
671
741
end IdentMethods
@@ -710,8 +780,11 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
710
780
/** Extension methods of `Select` */
711
781
trait SelectMethods :
712
782
extension (self : Select )
783
+ /** Qualifier of the `qualifier.name` */
713
784
def qualifier : Term
785
+ /** Name of this `Select` */
714
786
def name : String
787
+ /** Signature of this method */
715
788
def signature : Option [Signature ]
716
789
end extension
717
790
end SelectMethods
@@ -743,11 +816,12 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
743
816
/** Extension methods of `Literal` */
744
817
trait LiteralMethods :
745
818
extension (self : Literal )
819
+ /** Value of this literal */
746
820
def constant : Constant
747
821
end extension
748
822
end LiteralMethods
749
823
750
- /** Tree representing `this` in the source code */
824
+ /** Tree representing `this` or `C.this` in the source code */
751
825
type This <: Term
752
826
753
827
/** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `This` */
@@ -759,12 +833,12 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
759
833
/** Methods of the module object `val This` */
760
834
trait ThisModule { this : This .type =>
761
835
762
- /** Create a `this[<id: String]> ` */
836
+ /** Create a `C. this` for `C` pointing to `cls ` */
763
837
def apply (cls : Symbol ): This
764
838
765
839
def copy (original : Tree )(qual : Option [String ]): This
766
840
767
- /** Matches `this[<id: Option[String]> ` */
841
+ /** Matches `this` or `qual.this` and returns the name of `qual ` */
768
842
def unapply (x : This ): Some [Option [String ]]
769
843
}
770
844
@@ -774,6 +848,10 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
774
848
/** Extension methods of `This` */
775
849
trait ThisMethods :
776
850
extension (self : This )
851
+ /** Returns `C` if the underlying tree is of the form `C.this`
852
+ *
853
+ * Otherwise, return `None`.
854
+ */
777
855
def id : Option [String ]
778
856
end extension
779
857
end ThisMethods
@@ -795,7 +873,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
795
873
796
874
def copy (original : Tree )(tpt : TypeTree ): New
797
875
798
- /** Matches a `new <tpt: TypeTree>` */
876
+ /** Matches `new <tpt: TypeTree>` */
799
877
def unapply (x : New ): Some [TypeTree ]
800
878
}
801
879
@@ -805,6 +883,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
805
883
/** Extension methods of `New` */
806
884
trait NewMethods :
807
885
extension (self : New )
886
+ /** Returns the type tree of this `new` */
808
887
def tpt : TypeTree
809
888
end extension
810
889
end NewMethods
@@ -836,7 +915,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
836
915
/** Extension methods of `NamedArg` */
837
916
trait NamedArgMethods :
838
917
extension (self : NamedArg )
918
+ /** The name part of `name = arg` */
839
919
def name : String
920
+ /** The argument part of `name = arg` */
840
921
def value : Term
841
922
end extension
842
923
end NamedArgMethods
@@ -868,7 +949,27 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
868
949
/** Extension methods of `Apply` */
869
950
trait ApplyMethods :
870
951
extension (self : Apply )
952
+ /** The `fun` part of an (implicit) application like `fun(args)`
953
+ *
954
+ * It maybe a partially applied method:
955
+ * ```scala
956
+ * def f(x1: Int)(x2: Int) = ...
957
+ * f(1)(2)
958
+ * ```
959
+ * - `fun` is `f(1)` in the `Apply` of `f(1)(2)`
960
+ * - `fun` is `f` in the `Apply` of `f(1)`
961
+ */
871
962
def fun : Term
963
+ /** The arguments (implicitly) passed to the method
964
+ *
965
+ * The `Apply` maybe a partially applied method:
966
+ * ```scala
967
+ * def f(x1: Int)(x2: Int) = ...
968
+ * f(1)(2)
969
+ * ```
970
+ * - `args` is `(2)` in the `Apply` of `f(1)(2)`
971
+ * - `args` is `(1)` in the `Apply` of `f(1)`
972
+ */
872
973
def args : List [Term ]
873
974
end extension
874
975
end ApplyMethods
@@ -900,7 +1001,35 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
900
1001
/** Extension methods of `TypeApply` */
901
1002
trait TypeApplyMethods :
902
1003
extension (self : TypeApply )
1004
+ /** The `fun` part of an (inferred) type application like `fun[Args]`
1005
+ *
1006
+ * It maybe a partially applied method:
1007
+ * ```scala
1008
+ * extension (x: Int) def f[T](y: T) = ...
1009
+ * // represented as
1010
+ * // def f(x: Int)[T](y: T) = ...
1011
+ *
1012
+ * 1.f[Int](2)
1013
+ * // represented as
1014
+ * // f(1)[Int](2)
1015
+ * ```
1016
+ * - `fun` is `f(1)` in the `TypeApply` of `f(1)[Int]`
1017
+ */
903
1018
def fun : Term
1019
+ /** The (inferred) type arguments passed to the method
1020
+ *
1021
+ * The `TypeApply` maybe a partially applied method:
1022
+ * ```scala
1023
+ * extension (x: Int) def f[T](y: T) = ...
1024
+ * // represented as
1025
+ * // def f(x: Int)[T](y: T) = ...
1026
+ *
1027
+ * 1.f[Int](2)
1028
+ * // represented as
1029
+ * // f(1)[Int](2)
1030
+ * ```
1031
+ * - `fun` is `[Int]` in the `TypeApply` of `f(1)[Int]`
1032
+ */
904
1033
def args : List [TypeTree ]
905
1034
end extension
906
1035
end TypeApplyMethods
@@ -2040,11 +2169,11 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
2040
2169
// ///////////////////
2041
2170
2042
2171
/** Import/Export selectors:
2043
- * * SimpleSelector: `.bar` in `import foo.bar`
2044
- * * RenameSelector: `.{bar => baz}` in `export foo.{bar => baz}`
2045
- * * OmitSelector: `.{bar => _}` in `import foo.{bar => _}`
2046
- * * GivenSelector: `.given`/`.{given T}` in `export foo.given`/`import foo.{given T}`
2047
- */
2172
+ * - SimpleSelector: `.bar` in `import foo.bar`
2173
+ * - RenameSelector: `.{bar => baz}` in `export foo.{bar => baz}`
2174
+ * - OmitSelector: `.{bar => _}` in `import foo.{bar => _}`
2175
+ * - GivenSelector: `.given`/`.{given T}` in `export foo.given`/`import foo.{given T}`
2176
+ */
2048
2177
type Selector <: AnyRef
2049
2178
2050
2179
/** Module object of `type Selector` */
0 commit comments