@@ -332,28 +332,17 @@ object Trees {
332
332
def namedType : NamedType = tpe.asInstanceOf [NamedType ]
333
333
}
334
334
335
- /** Tree defines a new symbol and carries modifiers.
336
- * The position of a MemberDef contains only the defined identifier or pattern.
337
- * The envelope of a MemberDef contains the whole definition and has its point
338
- * on the opening keyword (or the next token after that if keyword is missing).
339
- */
340
- abstract class MemberDef [- T >: Untyped ](implicit @ constructorOnly src : SourceFile ) extends NameTree [T ] with DefTree [T ] {
341
- type ThisTree [- T >: Untyped ] <: MemberDef [T ]
342
-
343
- def rawComment : Option [Comment ] = getAttachment(DocComment )
344
-
345
- def setComment (comment : Option [Comment ]): this .type = {
346
- comment.map(putAttachment(DocComment , _))
347
- this
348
- }
335
+ abstract class NamedDefTree [- T >: Untyped ](implicit @ constructorOnly src : SourceFile ) extends NameTree [T ] with DefTree [T ] {
336
+ type ThisTree [- T >: Untyped ] <: NamedDefTree [T ]
349
337
350
338
/** The position of the name defined by this definition.
351
339
* This is a point position if the definition is synthetic, or a range position
352
340
* if the definition comes from source.
353
341
* It might also be that the definition does not have a position (for instance when synthesized by
354
342
* a calling chain from `viewExists`), in that case the return position is NoSpan.
343
+ * Overridden in Bind
355
344
*/
356
- def nameSpan : Span =
345
+ def nameSpan : Span =
357
346
if (span.exists) {
358
347
val point = span.point
359
348
if (rawMods.is(Synthetic ) || name.toTermName == nme.ERROR ) Span (point)
@@ -378,6 +367,22 @@ object Trees {
378
367
else span
379
368
}
380
369
370
+ /** Tree defines a new symbol and carries modifiers.
371
+ * The position of a MemberDef contains only the defined identifier or pattern.
372
+ * The envelope of a MemberDef contains the whole definition and has its point
373
+ * on the opening keyword (or the next token after that if keyword is missing).
374
+ */
375
+ abstract class MemberDef [- T >: Untyped ](implicit @ constructorOnly src : SourceFile ) extends NamedDefTree [T ] {
376
+ type ThisTree [- T >: Untyped ] <: MemberDef [T ]
377
+
378
+ def rawComment : Option [Comment ] = getAttachment(DocComment )
379
+
380
+ def setComment (comment : Option [Comment ]): this .type = {
381
+ comment.map(putAttachment(DocComment , _))
382
+ this
383
+ }
384
+ }
385
+
381
386
/** A ValDef or DefDef tree */
382
387
abstract class ValOrDefDef [- T >: Untyped ](implicit @ constructorOnly src : SourceFile ) extends MemberDef [T ] with WithLazyField [Tree [T ]] {
383
388
type ThisTree [- T >: Untyped ] <: ValOrDefDef [T ]
@@ -704,10 +709,13 @@ object Trees {
704
709
705
710
/** name @ body */
706
711
case class Bind [- T >: Untyped ] private [ast] (name : Name , body : Tree [T ])(implicit @ constructorOnly src : SourceFile )
707
- extends NameTree [ T ] with DefTree [T ] with PatternTree [T ] {
712
+ extends NamedDefTree [T ] with PatternTree [T ] {
708
713
type ThisTree [- T >: Untyped ] = Bind [T ]
709
714
override def isType : Boolean = name.isTypeName
710
715
override def isTerm : Boolean = name.isTermName
716
+
717
+ override def nameSpan : Span =
718
+ if span.exists then Span (span.start, span.start + name.toString.length) else span
711
719
}
712
720
713
721
/** tree_1 | ... | tree_n */
@@ -940,6 +948,7 @@ object Trees {
940
948
type NameTree = Trees .NameTree [T ]
941
949
type RefTree = Trees .RefTree [T ]
942
950
type DefTree = Trees .DefTree [T ]
951
+ type NamedDefTree = Trees .NamedDefTree [T ]
943
952
type MemberDef = Trees .MemberDef [T ]
944
953
type ValOrDefDef = Trees .ValOrDefDef [T ]
945
954
type LazyTree = Trees .LazyTree [T ]
0 commit comments