@@ -332,28 +332,17 @@ object Trees {
332332 def namedType : NamedType = tpe.asInstanceOf [NamedType ]
333333 }
334334
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 ]
349337
350338 /** The position of the name defined by this definition.
351339 * This is a point position if the definition is synthetic, or a range position
352340 * if the definition comes from source.
353341 * It might also be that the definition does not have a position (for instance when synthesized by
354342 * a calling chain from `viewExists`), in that case the return position is NoSpan.
343+ * Overridden in Bind
355344 */
356- def nameSpan : Span =
345+ def nameSpan : Span =
357346 if (span.exists) {
358347 val point = span.point
359348 if (rawMods.is(Synthetic ) || name.toTermName == nme.ERROR ) Span (point)
@@ -378,6 +367,22 @@ object Trees {
378367 else span
379368 }
380369
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+
381386 /** A ValDef or DefDef tree */
382387 abstract class ValOrDefDef [- T >: Untyped ](implicit @ constructorOnly src : SourceFile ) extends MemberDef [T ] with WithLazyField [Tree [T ]] {
383388 type ThisTree [- T >: Untyped ] <: ValOrDefDef [T ]
@@ -704,10 +709,13 @@ object Trees {
704709
705710 /** name @ body */
706711 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 ] {
708713 type ThisTree [- T >: Untyped ] = Bind [T ]
709714 override def isType : Boolean = name.isTypeName
710715 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
711719 }
712720
713721 /** tree_1 | ... | tree_n */
@@ -940,6 +948,7 @@ object Trees {
940948 type NameTree = Trees .NameTree [T ]
941949 type RefTree = Trees .RefTree [T ]
942950 type DefTree = Trees .DefTree [T ]
951+ type NamedDefTree = Trees .NamedDefTree [T ]
943952 type MemberDef = Trees .MemberDef [T ]
944953 type ValOrDefDef = Trees .ValOrDefDef [T ]
945954 type LazyTree = Trees .LazyTree [T ]
0 commit comments