Skip to content

Commit 1ca6384

Browse files
committed
Use Symbol in SymRef in TASTy reflect
1 parent ff2162d commit 1ca6384

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ import dotty.tools.dotc.core.Symbols._
55
trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with TastyCoreImpl {
66

77
def SymbolDeco(symbol: Symbol): SymbolAPI = new SymbolAPI {
8+
89
def isEmpty(implicit ctx: Context): Boolean = symbol eq NoSymbol
910
def isClass(implicit ctx: Context): Boolean = symbol.isClass
11+
1012
def flags(implicit ctx: Context): FlagSet = new FlagSet(symbol.flags)
13+
1114
def name(implicit ctx: Context): String = symbol.name.toString
1215
def fullName(implicit ctx: Context): String = symbol.fullName.toString
16+
1317
def localContext(implicit ctx: Context): Context = ctx.withOwner(symbol)
18+
1419
def tree(implicit ctx: Context): Option[Definition] =
1520
if (isEmpty) None else Some(FromSymbol.definitionFromSym(symbol))
21+
1622
}
1723

1824
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with Tasty
5151
}
5252

5353
object SymRef extends SymRefExtractor {
54-
def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Definition, TypeOrBounds /* Type | NoPrefix */)] = x match {
54+
def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] = x match {
5555
case tp: Types.NamedType =>
5656
tp.designator match {
57-
case sym: Symbol => Some((definitionFromSym(sym), tp.prefix))
57+
case sym: Symbol => Some((sym, tp.prefix))
5858
case _ => None
5959
}
6060
case _ => None

library/src/scala/tasty/reflect/TypeOrBoundsOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ trait TypeOrBoundsOps extends TastyCore {
4949

5050
val SymRef: SymRefExtractor
5151
abstract class SymRefExtractor {
52-
def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Definition, TypeOrBounds /* Type | NoPrefix */)]
52+
def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)]
5353
}
5454

5555
val TermRef: TermRefExtractor

library/src/scala/tasty/util/ShowExtractors.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,8 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
160160
case Type.ConstantType(value) =>
161161
this += "Type.ConstantType(" += value += ")"
162162
case Type.SymRef(sym, qual) =>
163-
def visitName(sym: Definition): Buffer = sym match {
164-
case ValDef(name, _, _) => this += "ValDef(\"" += name += "\", _, _)"
165-
case DefDef(name, _, _, _, _) => this += "DefDef(\"" += name += "\", _, _, _, _)"
166-
case TypeDef(name, _) => this += "TypeDef(\"" += name += "\", _)"
167-
case ClassDef(name, _, _, _, _) => this += "ClassDef(\"" += name += "\", _, _, _, _)"
168-
case PackageDef(name, _) => this += "PackageDef(\"" += name += "\", _)"
169-
}
170163
this += "Type.SymRef("
171-
visitName(sym)
164+
this += "<" += sym.fullName += ">"
172165
this += ", " += qual += ")"
173166
case Type.TermRef(name, qual) =>
174167
this += "Type.TermRef(\"" += name += "\", " += qual += ")"

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,10 @@ 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, _) if sym.symbol.isClass && (sym.symbol.fullName == "scala.runtime.Null$" || sym.symbol.fullName == "scala.runtime.Nothing$") =>
746+
case Type.SymRef(sym, _) if sym.isClass && (sym.fullName == "scala.runtime.Null$" || sym.fullName == "scala.runtime.Nothing$") =>
747747
// scala.runtime.Null$ and scala.runtime.Nothing$ are not modules, those are their actual names
748748
printType(tpe)
749-
case tpe @ Type.SymRef(sym, _) if sym.symbol.isClass && sym.name.endsWith("$") =>
749+
case tpe @ Type.SymRef(sym, _) if sym.isClass && sym.name.endsWith("$") =>
750750
printType(tpe)
751751
this += ".type"
752752
case tpe => printType(tpe)
@@ -826,7 +826,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
826826
case Type.SymRef(sym, prefix) =>
827827
prefix match {
828828
case Types.EmptyPrefix() =>
829-
case IsType(prefix @ Type.SymRef(sym, _)) if sym.symbol.isClass =>
829+
case IsType(prefix @ Type.SymRef(sym, _)) if sym.isClass =>
830830
printType(prefix)
831831
this += "#"
832832
case IsType(prefix) =>
@@ -958,7 +958,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
958958
val annots = definition.annots.filter {
959959
case Annotation(annot, _) =>
960960
annot.tpe match {
961-
case Type.TypeRef(_, Type.SymRef(sym, _)) if sym.symbol.fullName == "scala.annotation.internal" => false
961+
case Type.TypeRef(_, Type.SymRef(sym, _)) if sym.fullName == "scala.annotation.internal" => false
962962
case Type.TypeRef("forceInline", Types.ScalaPackage()) => false
963963
case _ => true
964964
}
@@ -1055,7 +1055,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
10551055
def printProtectedOrPrivate(definition: Definition): Boolean = {
10561056
var prefixWasPrinted = false
10571057
def printWithin(within: Type) = within match {
1058-
case Type.SymRef(sym @ PackageDef(name, _), _) =>
1058+
case Type.SymRef(sym, _) =>
10591059
this += sym.name
10601060
case _ => printFullClassName(within)
10611061
}
@@ -1083,7 +1083,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
10831083

10841084
def printFullClassName(tp: TypeOrBounds): Unit = {
10851085
def printClassPrefix(prefix: TypeOrBounds): Unit = prefix match {
1086-
case Type.SymRef(sym, prefix2) if sym.symbol.isClass =>
1086+
case Type.SymRef(sym, prefix2) if sym.isClass =>
10871087
printClassPrefix(prefix2)
10881088
this += sym.name += "."
10891089
case _ =>
@@ -1122,8 +1122,11 @@ 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(sym2, _))) if sym2.name == "<special-ops>" =>
1126-
Some((op, args))
1125+
case Type.SymRef(sym, Type.ThisType(Type.SymRef(sym2, _))) if sym2.name == "<special-ops>" =>
1126+
sym.tree match {
1127+
case Some(DefDef(op, _, _, _, _)) => Some((op, args))
1128+
case _ => None
1129+
}
11271130
case _ => None
11281131
}
11291132
case _ => None
@@ -1144,7 +1147,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
11441147

11451148
object JavaLangObject {
11461149
def unapply(tpe: Type)(implicit ctx: Context): Boolean = tpe match {
1147-
case Type.TypeRef("Object", Type.SymRef(sym, _)) if sym.symbol.fullName == "java.lang" => true
1150+
case Type.TypeRef("Object", Type.SymRef(sym, _)) if sym.fullName == "java.lang" => true
11481151
case _ => false
11491152
}
11501153
}
@@ -1158,21 +1161,21 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
11581161

11591162
object ScalaPackage {
11601163
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
1161-
case Type.SymRef(sym, _) => sym.symbol == definitions.ScalaPackage
1164+
case Type.SymRef(sym, _) => sym == definitions.ScalaPackage
11621165
case _ => false
11631166
}
11641167
}
11651168

11661169
object RootPackage {
11671170
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
1168-
case Type.SymRef(sym, _) => sym.symbol == definitions.RootClass
1171+
case Type.SymRef(sym, _) => sym == definitions.RootClass
11691172
case _ => false
11701173
}
11711174
}
11721175

11731176
object EmptyPackage {
11741177
def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Boolean = tpe match {
1175-
case Type.SymRef(sym, _) => sym.symbol == definitions.EmptyPackageClass
1178+
case Type.SymRef(sym, _) => sym == definitions.EmptyPackageClass
11761179
case _ => false
11771180
}
11781181
}

0 commit comments

Comments
 (0)