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