@@ -116,8 +116,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
116
116
* | +- Export
117
117
* | +- Definition --+- ClassDef
118
118
* | | +- TypeDef
119
- * | | +- DefDef
120
- * | | +- ValDef
119
+ * | | +- ValOrDefDef -+- DefDef
120
+ * | | +- ValDef
121
121
* | |
122
122
* | +- Term --------+- Ref -+- Ident -+- Wildcard
123
123
* | | +- Select
@@ -532,10 +532,33 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
532
532
end extension
533
533
end ClassDefMethods
534
534
535
+ // ValOrDefDef
536
+
537
+ /** Tree representing a value or method definition in the source code.
538
+ * This includes `def`, `val`, `lazy val`, `var`, `object` and parameter definitions.
539
+ */
540
+ type ValOrDefDef <: Definition
541
+
542
+ /** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `ValOrDefDef` */
543
+ given ValOrDefDefTypeTest : TypeTest [Tree , ValOrDefDef ]
544
+
545
+ /** Makes extension methods on `ValOrDefDef` available without any imports */
546
+ given ValOrDefDefMethods : ValOrDefDefMethods
547
+
548
+ /** Extension methods of `ValOrDefDef` */
549
+ trait ValOrDefDefMethods :
550
+ extension (self : ValOrDefDef )
551
+ /** The type tree of this `val` or `def` definition */
552
+ def tpt : TypeTree
553
+ /** The right-hand side of this `val` or `def` definition */
554
+ def rhs : Option [Term ]
555
+ end extension
556
+ end ValOrDefDefMethods
557
+
535
558
// DefDef
536
559
537
560
/** Tree representing a method definition in the source code */
538
- type DefDef <: Definition
561
+ type DefDef <: ValOrDefDef
539
562
540
563
/** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `DefDef` */
541
564
given DefDefTypeTest : TypeTest [Tree , DefDef ]
@@ -611,8 +634,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
611
634
612
635
// ValDef
613
636
614
- /** Tree representing a value definition in the source code This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */
615
- type ValDef <: Definition
637
+ /** Tree representing a value definition in the source code. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */
638
+ type ValDef <: ValOrDefDef
616
639
617
640
/** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `ValDef` */
618
641
given ValDefTypeTest : TypeTest [Tree , ValDef ]
0 commit comments