Skip to content

Commit 28231bf

Browse files
committed
Add maybeOwner to TASTy reflect
1 parent 1d64af5 commit 28231bf

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
15901590
type Symbol = core.Symbols.Symbol
15911591

15921592
def Symbol_owner(self: Symbol)(given Context): Symbol = self.owner
1593+
def Symbol_maybeOwner(self: Symbol)(given Context): Symbol = self.maybeOwner
15931594

15941595
def Symbol_flags(self: Symbol)(given Context): Flags = self.flags
15951596

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,9 +1164,12 @@ trait CompilerInterface {
11641164
*/
11651165
type Symbol <: AnyRef
11661166

1167-
/** Owner of this symbol. The owner is the symbol in which this symbol is defined. */
1167+
/** Owner of this symbol. The owner is the symbol in which this symbol is defined. Throws if this symbol does not have an owner. */
11681168
def Symbol_owner(self: Symbol)(given ctx: Context): Symbol
11691169

1170+
/** Owner of this symbol. The owner is the symbol in which this symbol is defined. Returns `NoSymbol` if this symbol does not have an owner. */
1171+
def Symbol_maybeOwner(self: Symbol)(given ctx: Context): Symbol
1172+
11701173
/** Flags of this symbol */
11711174
def Symbol_flags(self: Symbol)(given ctx: Context): Flags
11721175

library/src/scala/tasty/reflect/SourceCodePrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
12281228

12291229
def printAnnotation(annot: Term)(given elideThis: Option[Symbol]): Buffer = {
12301230
val Annotation(ref, args) = annot
1231-
if (annot.symbol.exists && annot.symbol.owner.fullName == "scala.internal.quoted.showName") this
1231+
if (annot.symbol.maybeOwner.fullName == "scala.internal.quoted.showName") this
12321232
else {
12331233
this += "@"
12341234
printTypeTree(ref)

library/src/scala/tasty/reflect/SymbolOps.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ trait SymbolOps extends Core { selfSymbolOps: FlagsOps =>
1616

1717
given symbolOps: extension (self: Symbol) {
1818

19-
/** Owner of this symbol. The owner is the symbol in which this symbol is defined */
19+
/** Owner of this symbol. The owner is the symbol in which this symbol is defined. Throws if this symbol does not have an owner. */
2020
def owner(given ctx: Context): Symbol = internal.Symbol_owner(self)
2121

22+
/** Owner of this symbol. The owner is the symbol in which this symbol is defined. Returns `NoSymbol` if this symbol does not have an owner. */
23+
def maybeOwner(given ctx: Context): Symbol = internal.Symbol_maybeOwner(self)
24+
2225
/** Flags of this symbol */
2326
def flags(given ctx: Context): Flags = internal.Symbol_flags(self)
2427

0 commit comments

Comments
 (0)