@@ -135,8 +135,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
135135 * | +- Export
136136 * | +- Definition --+- ClassDef
137137 * | | +- TypeDef
138- * | | +- DefDef
139- * | | +- ValDef
138+ * | | +- ValOrDefDef -+- DefDef
139+ * | | +- ValDef
140140 * | |
141141 * | +- Term --------+- Ref -+- Ident -+- Wildcard
142142 * | | +- Select
@@ -551,10 +551,33 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
551551 end extension
552552 end ClassDefMethods
553553
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+
554577 // DefDef
555578
556579 /** Tree representing a method definition in the source code */
557- type DefDef <: Definition
580+ type DefDef <: ValOrDefDef
558581
559582 /** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `DefDef` */
560583 given DefDefTypeTest : TypeTest [Tree , DefDef ]
@@ -630,8 +653,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
630653
631654 // ValDef
632655
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
635658
636659 /** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `ValDef` */
637660 given ValDefTypeTest : TypeTest [Tree , ValDef ]
0 commit comments