@@ -1578,6 +1578,39 @@ object SymDenotations {
1578
1578
if (is(Private ))
1579
1579
copySymDenotation(name = expandedName, initFlags = this .flags &~ Private )
1580
1580
else this
1581
+
1582
+ /** If this is a sealed class, its known children in the order of textual occurrence
1583
+ */
1584
+ def children (using Context ): List [Symbol ] =
1585
+
1586
+ def completeChildrenIn (owner : Symbol )(using Context ) =
1587
+ // Possible children are: classes extending Scala classes and
1588
+ // Scala or Java enum values that are defined in owner.
1589
+ // If owner is a package, we complete only
1590
+ // children that are defined in the same file as their parents.
1591
+ def maybeChild (sym : Symbol ) =
1592
+ (sym.isClass && ! this .is(JavaDefined ) || sym.originDenotation.is(EnumVal ))
1593
+ && ! owner.is(Package )
1594
+ || sym.originDenotation.infoOrCompleter.match
1595
+ case _ : SymbolLoaders .SecondCompleter => sym.associatedFile == this .symbol.associatedFile
1596
+ case _ => false
1597
+
1598
+ if owner.isClass then
1599
+ for c <- owner.info.decls.toList if maybeChild(c) do
1600
+ c.ensureCompleted()
1601
+ end completeChildrenIn
1602
+
1603
+ if is(Sealed ) then
1604
+ if ! is(ChildrenQueried ) then
1605
+ // Make sure all visible children are completed, so that
1606
+ // they show up in Child annotations. A possible child is visible if it
1607
+ // is defined in the same scope as `cls` or in the companion object of `cls`.
1608
+ completeChildrenIn(owner)
1609
+ completeChildrenIn(companionClass)
1610
+ setFlag(ChildrenQueried )
1611
+
1612
+ annotations.collect { case Annotation .Child (child) => child }.reverse
1613
+ end children
1581
1614
}
1582
1615
1583
1616
/** The contents of a class definition during a period
0 commit comments