@@ -69,7 +69,7 @@ abstract class PcCollector[T](
69
69
case _ => rawPath
70
70
def collect (
71
71
parent : Option [Tree ]
72
- )(tree : Tree , pos : SourcePosition , symbol : Option [Symbol ]): T
72
+ )(tree : Tree | EndMarker , pos : SourcePosition , symbol : Option [Symbol ]): T
73
73
74
74
/**
75
75
* @return (adjusted position, should strip backticks)
@@ -423,7 +423,7 @@ abstract class PcCollector[T](
423
423
parent : Option [Tree ]
424
424
): Set [T ] =
425
425
def collect (
426
- tree : Tree ,
426
+ tree : Tree | EndMarker ,
427
427
pos : SourcePosition ,
428
428
symbol : Option [Symbol ] = None
429
429
) =
@@ -461,6 +461,9 @@ abstract class PcCollector[T](
461
461
case df : NamedDefTree
462
462
if df.span.isCorrect && df.nameSpan.isCorrect &&
463
463
filter(df) && ! isGeneratedGiven(df) =>
464
+ def collectEndMarker =
465
+ EndMarker .getPosition(df, pos, sourceText).map:
466
+ collect(EndMarker (df.symbol), _)
464
467
val annots = collectTrees(df.mods.annotations)
465
468
val traverser =
466
469
new PcCollector .DeepFolderWithParent [Set [T ]](
@@ -470,7 +473,7 @@ abstract class PcCollector[T](
470
473
occurrences + collect(
471
474
df,
472
475
pos.withSpan(df.nameSpan)
473
- )
476
+ ) ++ collectEndMarker
474
477
) { case (set, tree) =>
475
478
traverser(set, tree)
476
479
}
@@ -635,3 +638,34 @@ case class ExtensionParamOccurence(
635
638
sym : Symbol ,
636
639
methods : List [untpd.Tree ]
637
640
)
641
+
642
+ case class EndMarker (symbol : Symbol )
643
+
644
+ object EndMarker :
645
+ /**
646
+ * Matches end marker line from start to the name's beginning.
647
+ * E.g.
648
+ * end /* some comment */
649
+ */
650
+ private val endMarkerRegex = """ .*end(/\*.*\*/|\s)+""" .r
651
+ def getPosition (df : NamedDefTree , pos : SourcePosition , sourceText : String )(
652
+ implicit ct : Context
653
+ ): Option [SourcePosition ] =
654
+ val name = df.name.toString()
655
+ val endMarkerLine =
656
+ sourceText.slice(df.span.start, df.span.end).split('\n ' ).last
657
+ val index = endMarkerLine.length() - name.length()
658
+ if index < 0 then None
659
+ else
660
+ val (possiblyEndMarker, possiblyEndMarkerName) =
661
+ endMarkerLine.splitAt(index)
662
+ Option .when(
663
+ possiblyEndMarkerName == name &&
664
+ endMarkerRegex.matches(possiblyEndMarker)
665
+ )(
666
+ pos
667
+ .withStart(df.span.end - name.length())
668
+ .withEnd(df.span.end)
669
+ )
670
+ end getPosition
671
+ end EndMarker
0 commit comments