@@ -135,8 +135,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
135
135
* | +- Export
136
136
* | +- Definition --+- ClassDef
137
137
* | | +- TypeDef
138
- * | | +- DefDef
139
- * | | +- ValDef
138
+ * | | +- ValOrDefDef -+- DefDef
139
+ * | | +- ValDef
140
140
* | |
141
141
* | +- Term --------+- Ref -+- Ident -+- Wildcard
142
142
* | | +- Select
@@ -551,10 +551,33 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
551
551
end extension
552
552
end ClassDefMethods
553
553
554
+ // ValOrDefDef
555
+
556
+ /** Tree representing a value or method definition in the source code.
557
+ * This includes `def`, `val`, `lazy val`, `var`, `object` and parameter definitions.
558
+ */
559
+ type ValOrDefDef <: Definition
560
+
561
+ /** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `ValOrDefDef` */
562
+ given ValOrDefDefTypeTest : TypeTest [Tree , ValOrDefDef ]
563
+
564
+ /** Makes extension methods on `ValOrDefDef` available without any imports */
565
+ given ValOrDefDefMethods : ValOrDefDefMethods
566
+
567
+ /** Extension methods of `ValOrDefDef` */
568
+ trait ValOrDefDefMethods :
569
+ extension (self : ValOrDefDef )
570
+ /** The type tree of this `val` or `def` definition */
571
+ def tpt : TypeTree
572
+ /** The right-hand side of this `val` or `def` definition */
573
+ def rhs : Option [Term ]
574
+ end extension
575
+ end ValOrDefDefMethods
576
+
554
577
// DefDef
555
578
556
579
/** Tree representing a method definition in the source code */
557
- type DefDef <: Definition
580
+ type DefDef <: ValOrDefDef
558
581
559
582
/** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `DefDef` */
560
583
given DefDefTypeTest : TypeTest [Tree , DefDef ]
@@ -630,8 +653,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
630
653
631
654
// ValDef
632
655
633
- /** Tree representing a value definition in the source code This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */
634
- type ValDef <: Definition
656
+ /** Tree representing a value definition in the source code. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */
657
+ type ValDef <: ValOrDefDef
635
658
636
659
/** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `ValDef` */
637
660
given ValDefTypeTest : TypeTest [Tree , ValDef ]
0 commit comments