Skip to content

Commit af339b3

Browse files
committed
Use more conditions on symbols
1 parent d492a1f commit af339b3

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ trait StandardDefinitions extends scala.tasty.reflect.StandardDefinitions {
1111

1212
val definitions: DefinitionsApi = new DefinitionsApi {
1313

14+
// TODO return Symbols instead of Definitions
15+
1416
def RootPackage: PackageDef = packageDefFromSym(defn.RootPackage)
17+
def RootClass: Symbol = defn.RootClass
18+
19+
def EmptyPackageClass: Symbol = defn.EmptyPackageClass
1520

16-
def ScalaPackage: PackageDef = packageDefFromSym(defn.ScalaPackageVal)
21+
def ScalaPackage: Symbol = defn.ScalaPackageVal
22+
def ScalaPackageClass: Symbol = defn.ScalaPackageClass
1723

1824
def AnyClass: ClassDef = classDef(defn.AnyClass)
1925
def AnyValClass: ClassDef = classDef(defn.AnyValClass)
@@ -44,7 +50,7 @@ trait StandardDefinitions extends scala.tasty.reflect.StandardDefinitions {
4450
def Array_length: DefDef = defDefFromSym(defn.Array_length.asTerm)
4551
def Array_update: DefDef = defDefFromSym(defn.Array_update.asTerm)
4652

47-
def RepeatedParamClass: ClassDef = classDef(defn.RepeatedParamClass)
53+
def RepeatedParamClass: Symbol = defn.RepeatedParamClass
4854

4955
def OptionClass: TypeDef = classDef(defn.OptionClass)
5056
def NoneModule: ValDef = valDefFromSym(defn.NoneClass.companionModule.asTerm)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with TastyCoreImpl {
77
def SymbolDeco(symbol: Symbol): SymbolAPI = new SymbolAPI {
88
def isEmpty(implicit ctx: Context): Boolean = symbol eq NoSymbol
99
def isClass(implicit ctx: Context): Boolean = symbol.isClass
10+
def flags(implicit ctx: Context): FlagSet = new FlagSet(symbol.flags)
1011
def name(implicit ctx: Context): String = symbol.name.toString
1112
def fullName(implicit ctx: Context): String = symbol.fullName.toString
1213
def localContext(implicit ctx: Context): Context = ctx.withOwner(symbol)

library/src/scala/tasty/reflect/StandardDefinitions.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@ trait StandardDefinitions extends TastyCore {
1616
/** The module symbol of root package `_root_`. */
1717
def RootPackage: PackageDef
1818

19+
/** The class symbol of root package `_root_`. */
20+
def RootClass: Symbol
21+
22+
/** The class symbol of empty package `_root_._empty_`. */
23+
def EmptyPackageClass: Symbol
24+
1925
/** The module symbol of package `scala`. */
20-
def ScalaPackage: PackageDef
26+
def ScalaPackage: Symbol
27+
28+
/** The class symbol of package `scala`. */
29+
def ScalaPackageClass: Symbol
2130

2231
/** The class symbol of core class `scala.Any`. */
2332
def AnyClass : ClassDef
@@ -97,7 +106,7 @@ trait StandardDefinitions extends TastyCore {
97106
/** A dummy class symbol that is used to indicate repeated parameters
98107
* compiled by the Scala compiler.
99108
*/
100-
def RepeatedParamClass: ClassDef
109+
def RepeatedParamClass: Symbol
101110

102111
/** The class symbol of class `scala.Option`. */
103112
def OptionClass: ClassDef

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ package reflect
55
trait SymbolOps extends TastyCore {
66

77
trait SymbolAPI {
8+
89
def isEmpty(implicit ctx: Context): Boolean
910
def isClass(implicit ctx: Context): Boolean
11+
12+
def flags(implicit ctx: Context): FlagSet
13+
1014
def name(implicit ctx: Context): String
1115
def fullName(implicit ctx: Context): String
16+
1217
def localContext(implicit ctx: Context): Context
18+
1319
def tree(implicit ctx: Context): Option[Definition]
20+
1421
}
1522
implicit def SymbolDeco(symbol: Symbol): SymbolAPI
1623

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
743743
printTypeAndAnnots(tp)
744744
this += " "
745745
printAnnotation(annot)
746-
case Type.SymRef(sym, Type.ThisType(Type.SymRef(PackageDef("runtime", _), NoPrefix()))) if sym.symbol.isClass && (sym.symbol.name == "Null$" || sym.symbol.name == "Nothing$") =>
746+
case Type.SymRef(sym, _) if sym.symbol.isClass && (sym.symbol.fullName == "scala.runtime.Null$" || sym.symbol.fullName == "scala.runtime.Nothing$") =>
747747
// scala.runtime.Null$ and scala.runtime.Nothing$ are not modules, those are their actual names
748748
printType(tpe)
749749
case tpe @ Type.SymRef(sym, _) if sym.symbol.isClass && sym.name.endsWith("$") =>
@@ -1122,7 +1122,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
11221122
def unapply(arg: Tree)(implicit ctx: Context): Option[(String, List[Term])] = arg match {
11231123
case IsTerm(arg @ Term.Apply(fn, args)) =>
11241124
fn.tpe match {
1125-
case Type.SymRef(DefDef(op, _, _, _, _), Type.ThisType(Type.SymRef(sym, _))) if sym.name == "<special-ops>" =>
1125+
case Type.SymRef(DefDef(op, _, _, _, _), Type.ThisType(Type.SymRef(sym2, _))) if sym2.name == "<special-ops>" =>
11261126
Some((op, args))
11271127
case _ => None
11281128
}
@@ -1158,21 +1158,21 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
11581158

11591159
object ScalaPackage {
11601160
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
1161-
case Type.SymRef(PackageDef("scala", _), Type.ThisType(RootPackage())) => true
1161+
case Type.SymRef(sym, _) => sym.symbol == definitions.ScalaPackage
11621162
case _ => false
11631163
}
11641164
}
11651165

11661166
object RootPackage {
11671167
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
1168-
case Type.SymRef(PackageDef("<root>", _), NoPrefix()) => true
1168+
case Type.SymRef(sym, _) => sym.symbol == definitions.RootClass
11691169
case _ => false
11701170
}
11711171
}
11721172

11731173
object EmptyPackage {
11741174
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
1175-
case Type.SymRef(PackageDef("<empty>", _), NoPrefix() | Type.ThisType(RootPackage())) => true
1175+
case Type.SymRef(sym, _) => sym.symbol == definitions.EmptyPackageClass
11761176
case _ => false
11771177
}
11781178
}

0 commit comments

Comments
 (0)