Skip to content

Commit 4e6c615

Browse files
committed
Replace IsXYZSymbol with isXYZ methods
1 parent 2cccb23 commit 4e6c615

File tree

17 files changed

+170
-278
lines changed

17 files changed

+170
-278
lines changed

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,18 +1518,16 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
15181518

15191519
type PackageDefSymbol = core.Symbols.Symbol
15201520

1521-
def matchPackageDefSymbol(symbol: Symbol)(given Context): Option[PackageDefSymbol] =
1522-
if (symbol.is(core.Flags.Package)) Some(symbol) else None
1521+
def isPackageDefSymbol(symbol: Symbol)(given Context): Boolean =
1522+
symbol.is(core.Flags.Package)
15231523

15241524
type TypeSymbol = core.Symbols.TypeSymbol
15251525

1526-
def matchTypeSymbol(symbol: Symbol)(given Context): Option[TypeSymbol] =
1527-
if (symbol.isType) Some(symbol.asType) else None
1526+
def isTypeSymbol(symbol: Symbol)(given Context): Boolean = symbol.isType
15281527

15291528
type ClassDefSymbol = core.Symbols.ClassSymbol
15301529

1531-
def matchClassDefSymbol(symbol: Symbol)(given Context): Option[ClassDefSymbol] =
1532-
if (symbol.isClass) Some(symbol.asClass) else None
1530+
def isClassDefSymbol(symbol: Symbol)(given Context): Boolean = symbol.isClass
15331531

15341532
def ClassDefSymbol_fields(self: Symbol)(given Context): List[Symbol] =
15351533
self.unforcedDecls.filter(isField)
@@ -1591,34 +1589,33 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
15911589

15921590
type TypeDefSymbol = core.Symbols.TypeSymbol
15931591

1594-
def matchTypeDefSymbol(symbol: Symbol)(given Context): Option[TypeDefSymbol] =
1595-
if (symbol.isType) Some(symbol.asType) else None
1592+
def isTypeDefSymbol(symbol: Symbol)(given Context): Boolean =
1593+
symbol.isType && !symbol.is(core.Flags.Case)
15961594

15971595
def TypeDefSymbol_isTypeParam(self: TypeDefSymbol)(given Context): Boolean =
15981596
self.isTypeParam
15991597

16001598
type TypeBindSymbol = core.Symbols.TypeSymbol
16011599

1602-
def matchTypeBindSymbol(symbol: Symbol)(given Context): Option[TypeBindSymbol] =
1603-
if (symbol.isType && symbol.is(core.Flags.Case)) Some(symbol.asType) else None
1600+
def isTypeBindSymbol(symbol: Symbol)(given Context): Boolean =
1601+
symbol.isType && symbol.is(core.Flags.Case)
16041602

16051603
type TermSymbol = core.Symbols.TermSymbol
16061604

1607-
def matchTermSymbol(symbol: Symbol)(given Context): Option[TermSymbol] =
1608-
if (symbol.isTerm) Some(symbol.asTerm) else None
1605+
def isTermSymbol(symbol: Symbol)(given Context): Boolean = symbol.isTerm
16091606

16101607
type DefDefSymbol = core.Symbols.TermSymbol
16111608

1612-
def matchDefDefSymbol(symbol: Symbol)(given Context): Option[DefDefSymbol] =
1613-
if (symbol.isTerm && symbol.is(core.Flags.Method)) Some(symbol.asTerm) else None
1609+
def isDefDefSymbol(symbol: Symbol)(given Context): Boolean =
1610+
symbol.isTerm && symbol.is(core.Flags.Method)
16141611

16151612
def DefDefSymbol_signature(self: DefDefSymbol)(given Context): Signature =
16161613
self.signature
16171614

16181615
type ValDefSymbol = core.Symbols.TermSymbol
16191616

1620-
def matchValDefSymbol(symbol: Symbol)(given Context): Option[ValDefSymbol] =
1621-
if (symbol.isTerm && !symbol.is(core.Flags.Method) && !symbol.is(core.Flags.Case)) Some(symbol.asTerm) else None
1617+
def isValDefSymbol(symbol: Symbol)(given Context): Boolean =
1618+
symbol.isTerm && !symbol.is(core.Flags.Method) && !symbol.is(core.Flags.Case)
16221619

16231620
def ValDefSymbol_moduleClass(self: ValDefSymbol)(given Context): Option[ClassDefSymbol] = {
16241621
val sym = self.moduleClass
@@ -1632,12 +1629,12 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
16321629

16331630
type BindSymbol = core.Symbols.TermSymbol
16341631

1635-
def matchBindSymbol(symbol: Symbol)(given Context): Option[BindSymbol] =
1636-
if (symbol.isTerm && symbol.is(core.Flags.Case)) Some(symbol.asTerm) else None
1632+
def isBindSymbol(symbol: Symbol)(given Context): Boolean =
1633+
symbol.isTerm && symbol.is(core.Flags.Case)
16371634

16381635
type NoSymbol = core.Symbols.NoSymbol.type
16391636

1640-
def matchNoSymbol(symbol: Symbol)(given Context): Boolean = symbol eq core.Symbols.NoSymbol
1637+
def isNoSymbol(symbol: Symbol)(given Context): Boolean = symbol eq core.Symbols.NoSymbol
16411638

16421639
//
16431640
// FLAGS

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,16 +1252,16 @@ trait CompilerInterface {
12521252
/** Symbol of a package definition */
12531253
type PackageDefSymbol <: Symbol
12541254

1255-
def matchPackageDefSymbol(symbol: Symbol)(given ctx: Context): Option[PackageDefSymbol]
1255+
def isPackageDefSymbol(symbol: Symbol)(given ctx: Context): Boolean
12561256

12571257
type TypeSymbol <: Symbol
12581258

1259-
def matchTypeSymbol(symbol: Symbol)(given ctx: Context): Option[TypeSymbol]
1259+
def isTypeSymbol(symbol: Symbol)(given ctx: Context): Boolean
12601260

12611261
/** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */
12621262
type ClassDefSymbol <: TypeSymbol
12631263

1264-
def matchClassDefSymbol(symbol: Symbol)(given ctx: Context): Option[ClassDefSymbol]
1264+
def isClassDefSymbol(symbol: Symbol)(given ctx: Context): Boolean
12651265

12661266
/** Fields directly declared in the class */
12671267
def ClassDefSymbol_fields(self: Symbol)(given ctx: Context): List[Symbol]
@@ -1298,31 +1298,31 @@ trait CompilerInterface {
12981298
/** Symbol of a type (parameter or member) definition. */
12991299
type TypeDefSymbol <: TypeSymbol
13001300

1301-
def matchTypeDefSymbol(symbol: Symbol)(given ctx: Context): Option[TypeDefSymbol]
1301+
def isTypeDefSymbol(symbol: Symbol)(given ctx: Context): Boolean
13021302

13031303
def TypeDefSymbol_isTypeParam(self: TypeDefSymbol)(given ctx: Context): Boolean
13041304

13051305
/** Symbol representing a bind definition. */
13061306
type TypeBindSymbol <: TypeSymbol
13071307

1308-
def matchTypeBindSymbol(symbol: Symbol)(given ctx: Context): Option[TypeBindSymbol]
1308+
def isTypeBindSymbol(symbol: Symbol)(given ctx: Context): Boolean
13091309

13101310
type TermSymbol <: Symbol
13111311

1312-
def matchTermSymbol(symbol: Symbol)(given ctx: Context): Option[TermSymbol]
1312+
def isTermSymbol(symbol: Symbol)(given ctx: Context): Boolean
13131313

13141314
/** Symbol representing a method definition. */
13151315
type DefDefSymbol <: TermSymbol
13161316

1317-
def matchDefDefSymbol(symbol: Symbol)(given ctx: Context): Option[DefDefSymbol]
1317+
def isDefDefSymbol(symbol: Symbol)(given ctx: Context): Boolean
13181318

13191319
/** Signature of this definition */
13201320
def DefDefSymbol_signature(self: DefDefSymbol)(given ctx: Context): Signature
13211321

13221322
/** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */
13231323
type ValDefSymbol <: TermSymbol
13241324

1325-
def matchValDefSymbol(symbol: Symbol)(given ctx: Context): Option[ValDefSymbol]
1325+
def isValDefSymbol(symbol: Symbol)(given ctx: Context): Boolean
13261326

13271327
/** The class symbol of the companion module class */
13281328
def ValDefSymbol_moduleClass(self: ValDefSymbol)(given ctx: Context): Option[ClassDefSymbol]
@@ -1332,12 +1332,12 @@ trait CompilerInterface {
13321332
/** Symbol representing a bind definition. */
13331333
type BindSymbol <: TermSymbol
13341334

1335-
def matchBindSymbol(symbol: Symbol)(given ctx: Context): Option[BindSymbol]
1335+
def isBindSymbol(symbol: Symbol)(given ctx: Context): Boolean
13361336

13371337
/** No symbol available. */
13381338
type NoSymbol <: Symbol
13391339

1340-
def matchNoSymbol(symbol: Symbol)(given ctx: Context): Boolean
1340+
def isNoSymbol(symbol: Symbol)(given ctx: Context): Boolean
13411341

13421342
//
13431343
// FLAGS

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,13 @@ trait Printers
365365
case OmitSelector(id) => this += "OmitSelector(" += id += ")"
366366
}
367367

368-
def visitSymbol(x: Symbol): Buffer = x match {
369-
case IsPackageDefSymbol(x) => this += "IsPackageDefSymbol(<" += x.fullName += ">)"
370-
case IsClassDefSymbol(x) => this += "IsClassDefSymbol(<" += x.fullName += ">)"
371-
case IsDefDefSymbol(x) => this += "IsDefDefSymbol(<" += x.fullName += ">)"
372-
case IsValDefSymbol(x) => this += "IsValDefSymbol(<" += x.fullName += ">)"
373-
case IsTypeDefSymbol(x) => this += "IsTypeDefSymbol(<" += x.fullName += ">)"
374-
case NoSymbol() => this += "NoSymbol()"
375-
}
368+
def visitSymbol(x: Symbol): Buffer =
369+
if x.isPackageDef then this += "IsPackageDefSymbol(<" += x.fullName += ">)"
370+
else if x.isClassDef then this += "IsClassDefSymbol(<" += x.fullName += ">)"
371+
else if x.isDefDef then this += "IsDefDefSymbol(<" += x.fullName += ">)"
372+
else if x.isValDef then this += "IsValDefSymbol(<" += x.fullName += ">)"
373+
else if x.isTypeDef then this += "IsTypeDefSymbol(<" += x.fullName += ">)"
374+
else { assert(x.isNoSymbol); this += "NoSymbol()" }
376375

377376
def +=(x: Boolean): Buffer = { sb.append(x); this }
378377
def +=(x: Byte): Buffer = { sb.append(x); this }
@@ -1272,24 +1271,23 @@ trait Printers
12721271

12731272
def printParamDef(arg: ValDef)(given elideThis: Option[Symbol]): Unit = {
12741273
val name = arg.name
1275-
arg.symbol.owner match {
1276-
case IsDefDefSymbol(sym) if sym.name == "<init>" =>
1277-
val ClassDef(_, _, _, _, _, body) = sym.owner.tree
1278-
body.collectFirst {
1279-
case IsValDef(vdef @ ValDef(`name`, _, _)) if vdef.symbol.flags.is(Flags.ParamAccessor) =>
1280-
if (!vdef.symbol.flags.is(Flags.Local)) {
1281-
var printedPrefix = false
1282-
if (vdef.symbol.flags.is(Flags.Override)) {
1283-
this += "override "
1284-
printedPrefix = true
1285-
}
1286-
printedPrefix |= printProtectedOrPrivate(vdef)
1287-
if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightValDef("var ")
1288-
else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAcessor)) this += highlightValDef("val ")
1274+
val sym = arg.symbol.owner
1275+
if sym.isDefDef && sym.name == "<init>" then
1276+
val ClassDef(_, _, _, _, _, body) = sym.owner.tree
1277+
body.collectFirst {
1278+
case IsValDef(vdef @ ValDef(`name`, _, _)) if vdef.symbol.flags.is(Flags.ParamAccessor) =>
1279+
if (!vdef.symbol.flags.is(Flags.Local)) {
1280+
var printedPrefix = false
1281+
if (vdef.symbol.flags.is(Flags.Override)) {
1282+
this += "override "
1283+
printedPrefix = true
12891284
}
1290-
}
1291-
case _ =>
1292-
}
1285+
printedPrefix |= printProtectedOrPrivate(vdef)
1286+
if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightValDef("var ")
1287+
else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAcessor)) this += highlightValDef("val ")
1288+
}
1289+
}
1290+
end if
12931291

12941292
this += highlightValDef(name) += ": "
12951293
printTypeTree(arg.tpt)
@@ -1421,10 +1419,10 @@ trait Printers
14211419
case Type.IsTypeRef(tpe) if tpe.typeSymbol.fullName == "scala.runtime.Null$" || tpe.typeSymbol.fullName == "scala.runtime.Nothing$" =>
14221420
// scala.runtime.Null$ and scala.runtime.Nothing$ are not modules, those are their actual names
14231421
printType(tpe)
1424-
case Type.IsTermRef(tpe) if tpe.termSymbol.isClass && tpe.termSymbol.name.endsWith("$") =>
1422+
case Type.IsTermRef(tpe) if tpe.termSymbol.isClassDef && tpe.termSymbol.name.endsWith("$") =>
14251423
printType(tpe)
14261424
this += ".type"
1427-
case Type.IsTypeRef(tpe) if tpe.typeSymbol.isClass && tpe.typeSymbol.name.endsWith("$") =>
1425+
case Type.IsTypeRef(tpe) if tpe.typeSymbol.isClassDef && tpe.typeSymbol.name.endsWith("$") =>
14281426
printType(tpe)
14291427
this += ".type"
14301428
case tpe @ Type.TermRef(sym, _) =>
@@ -1528,10 +1526,10 @@ trait Printers
15281526
if (packagePath != "")
15291527
this += packagePath += "."
15301528
}
1531-
case Type.IsTermRef(prefix) if prefix.termSymbol.isClass =>
1529+
case Type.IsTermRef(prefix) if prefix.termSymbol.isClassDef =>
15321530
printType(prefix)
15331531
this += "#"
1534-
case Type.IsTypeRef(prefix) if prefix.typeSymbol.isClass =>
1532+
case Type.IsTypeRef(prefix) if prefix.typeSymbol.isClassDef =>
15351533
printType(prefix)
15361534
this += "#"
15371535
case IsType(Type.ThisType(Type.TermRef(cdef, _))) if elideThis.nonEmpty && cdef == elideThis.get =>

0 commit comments

Comments
 (0)