Skip to content

Commit 191d401

Browse files
committed
Use consistent names for TASTy Reflect symbols
1 parent 87e9f40 commit 191d401

File tree

26 files changed

+239
-239
lines changed

26 files changed

+239
-239
lines changed

docs/docs/reference/other-new-features/tasty-reflect.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ TASTy Reflect provides the following types:
177177
178178
+- Constant
179179
180-
+- Symbol --+- PackageSymbol
181-
+- ClassSymbol
182-
+- TypeSymbol
183-
+- DefSymbol
184-
+- ValSymbol
185-
+- BindSymbol
180+
+- Symbol --+- PackageDefSymbol
181+
+- ClassDefSymbol
182+
+- TypeDefSymbol
183+
+- DefDefSymbol
184+
+- ValDefSymbol
185+
+- BindDefSymbol
186186
+- NoSymbol
187187
188188
```

library/src/scala/tasty/reflect/Core.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,22 +418,22 @@ trait Core {
418418
type Symbol = kernel.Symbol
419419

420420
/** Symbol of a package definition */
421-
type PackageSymbol = kernel.PackageDefSymbol
421+
type PackageDefSymbol = kernel.PackageDefSymbol
422422

423423
/** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */
424-
type ClassSymbol = kernel.ClassDefSymbol
424+
type ClassDefSymbol = kernel.ClassDefSymbol
425425

426426
/** Symbol of a type (parameter or member) definition. */
427-
type TypeSymbol = kernel.TypeDefSymbol
427+
type TypeDefSymbol = kernel.TypeDefSymbol
428428

429429
/** Symbol representing a method definition. */
430-
type DefSymbol = kernel.DefDefSymbol
430+
type DefDefSymbol = kernel.DefDefSymbol
431431

432432
/** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */
433-
type ValSymbol = kernel.ValDefSymbol
433+
type ValDefSymbol = kernel.ValDefSymbol
434434

435435
/** Symbol representing a bind definition. */
436-
type BindSymbol = kernel.BindSymbol
436+
type BindDefSymbol = kernel.BindSymbol
437437

438438
/** No symbol available. */
439439
type NoSymbol = kernel.NoSymbol

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ trait Printers
335335
}
336336

337337
def visitSymbol(x: Symbol): Buffer = x match {
338-
case IsPackageSymbol(x) => this += "IsPackageSymbol(<" += x.fullName += ">)"
339-
case IsClassSymbol(x) => this += "IsClassSymbol(<" += x.fullName += ">)"
340-
case IsDefSymbol(x) => this += "IsDefSymbol(<" += x.fullName += ">)"
341-
case IsValSymbol(x) => this += "IsValSymbol(<" += x.fullName += ">)"
342-
case IsTypeSymbol(x) => this += "IsTypeSymbol(<" += x.fullName += ">)"
338+
case IsPackageDefSymbol(x) => this += "IsPackageDefSymbol(<" += x.fullName += ">)"
339+
case IsClassDefSymbol(x) => this += "IsClassDefSymbol(<" += x.fullName += ">)"
340+
case IsDefDefSymbol(x) => this += "IsDefDefSymbol(<" += x.fullName += ">)"
341+
case IsValDefSymbol(x) => this += "IsValDefSymbol(<" += x.fullName += ">)"
342+
case IsTypeDefSymbol(x) => this += "IsTypeDefSymbol(<" += x.fullName += ">)"
343343
case NoSymbol() => this += "NoSymbol()"
344344
}
345345

@@ -1225,8 +1225,8 @@ trait Printers
12251225
def printParamDef(arg: ValDef): Unit = {
12261226
val name = arg.name
12271227
arg.symbol.owner match {
1228-
case IsDefSymbol(sym) if sym.name == "<init>" =>
1229-
val ClassDef(_, _, _, _, _, body) = sym.owner.asClass.tree
1228+
case IsDefDefSymbol(sym) if sym.name == "<init>" =>
1229+
val ClassDef(_, _, _, _, _, body) = sym.owner.asClassDef.tree
12301230
body.collectFirst {
12311231
case IsValDef(vdef @ ValDef(`name`, _, _)) if vdef.symbol.flags.is(Flags.ParamAccessor) =>
12321232
if (!vdef.symbol.flags.is(Flags.Local)) {
@@ -1354,10 +1354,10 @@ trait Printers
13541354
printTypeAndAnnots(tp)
13551355
this += " "
13561356
printAnnotation(annot)
1357-
case Type.SymRef(IsClassSymbol(sym), _) if sym.fullName == "scala.runtime.Null$" || sym.fullName == "scala.runtime.Nothing$" =>
1357+
case Type.SymRef(IsClassDefSymbol(sym), _) if sym.fullName == "scala.runtime.Null$" || sym.fullName == "scala.runtime.Nothing$" =>
13581358
// scala.runtime.Null$ and scala.runtime.Nothing$ are not modules, those are their actual names
13591359
printType(tpe)
1360-
case tpe @ Type.SymRef(IsClassSymbol(sym), _) if sym.name.endsWith("$") =>
1360+
case tpe @ Type.SymRef(IsClassDefSymbol(sym), _) if sym.name.endsWith("$") =>
13611361
printType(tpe)
13621362
this += ".type"
13631363
case tpe => printType(tpe)
@@ -1452,7 +1452,7 @@ trait Printers
14521452
if (packagePath != "")
14531453
this += packagePath += "."
14541454
}
1455-
case IsType(prefix @ Type.SymRef(IsClassSymbol(_), _)) =>
1455+
case IsType(prefix @ Type.SymRef(IsClassDefSymbol(_), _)) =>
14561456
printType(prefix)
14571457
this += "#"
14581458
case IsType(prefix) =>
@@ -1717,7 +1717,7 @@ trait Printers
17171717

17181718
def printFullClassName(tp: TypeOrBounds): Unit = {
17191719
def printClassPrefix(prefix: TypeOrBounds): Unit = prefix match {
1720-
case Type.SymRef(IsClassSymbol(sym), prefix2) =>
1720+
case Type.SymRef(IsClassDefSymbol(sym), prefix2) =>
17211721
printClassPrefix(prefix2)
17221722
this += sym.name += "."
17231723
case _ =>
@@ -1756,7 +1756,7 @@ trait Printers
17561756
def unapply(arg: Tree)(implicit ctx: Context): Option[(String, List[Term])] = arg match {
17571757
case IsTerm(arg @ Term.Apply(fn, args)) =>
17581758
fn.tpe match {
1759-
case Type.SymRef(IsDefSymbol(sym), Type.ThisType(Type.SymRef(sym2, _))) if sym2.name == "<special-ops>" =>
1759+
case Type.SymRef(IsDefDefSymbol(sym), Type.ThisType(Type.SymRef(sym2, _))) if sym2.name == "<special-ops>" =>
17601760
Some((sym.tree.name, args))
17611761
case _ => None
17621762
}

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

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,40 @@ trait SymbolOps extends Core {
3434
/** The comment for this symbol, if any */
3535
def comment(implicit ctx: Context): Option[Comment] = kernel.Symbol_comment(self)
3636

37-
/** Unsafe cast as to PackageSymbol. Use IsPackageSymbol to safly check and cast to PackageSymbol */
38-
def asPackage(implicit ctx: Context): PackageSymbol = self match {
39-
case IsPackageSymbol(self) => self
40-
case _ => throw new Exception("not a PackageSymbol")
37+
/** Unsafe cast as to PackageSymbol. Use IsPackageSymbol to safely check and cast to PackageSymbol */
38+
def asPackageDef(implicit ctx: Context): PackageDefSymbol = self match {
39+
case IsPackageDefSymbol(self) => self
40+
case _ => throw new Exception("not a PackageDefSymbol")
4141
}
4242

43-
/** Unsafe cast as to ClassSymbol. Use IsClassSymbol to safly check and cast to ClassSymbol */
44-
def asClass(implicit ctx: Context): ClassSymbol = self match {
45-
case IsClassSymbol(self) => self
46-
case _ => throw new Exception("not a ClassSymbol")
43+
/** Unsafe cast as to ClassSymbol. Use IsClassDefSymbol to safely check and cast to ClassSymbol */
44+
def asClassDef(implicit ctx: Context): ClassDefSymbol = self match {
45+
case IsClassDefSymbol(self) => self
46+
case _ => throw new Exception("not a ClassDefSymbol")
4747
}
4848

49-
/** Unsafe cast as to DefSymbol. Use IsDefSymbol to safly check and cast to DefSymbol */
50-
def asDef(implicit ctx: Context): DefSymbol = self match {
51-
case IsDefSymbol(self) => self
52-
case _ => throw new Exception("not a DefSymbol")
49+
/** Unsafe cast as to DefSymbol. Use IsDefDefSymbol to safely check and cast to DefSymbol */
50+
def asDefDef(implicit ctx: Context): DefDefSymbol = self match {
51+
case IsDefDefSymbol(self) => self
52+
case _ => throw new Exception("not a DefDefSymbol")
5353
}
5454

55-
/** Unsafe cast as to ValSymbol. Use IsValSymbol to safly check and cast to ValSymbol */
56-
def asVal(implicit ctx: Context): ValSymbol = self match {
57-
case IsValSymbol(self) => self
58-
case _ => throw new Exception("not a ValSymbol")
55+
/** Unsafe cast as to ValSymbol. Use IsValDefSymbol to safely check and cast to ValSymbol */
56+
def asValDef(implicit ctx: Context): ValDefSymbol = self match {
57+
case IsValDefSymbol(self) => self
58+
case _ => throw new Exception("not a ValDefSymbol")
5959
}
6060

61-
/** Unsafe cast as to TypeSymbol. Use IsTypeSymbol to safly check and cast to TypeSymbol */
62-
def asType(implicit ctx: Context): TypeSymbol = self match {
63-
case IsTypeSymbol(self) => self
64-
case _ => throw new Exception("not a TypeSymbol")
61+
/** Unsafe cast as to TypeSymbol. Use IsTypeDefSymbol to safely check and cast to TypeSymbol */
62+
def asTypeDef(implicit ctx: Context): TypeDefSymbol = self match {
63+
case IsTypeDefSymbol(self) => self
64+
case _ => throw new Exception("not a TypeDefSymbol")
6565
}
6666

67-
/** Unsafe cast as to BindSymbol. Use IsBindSymbol to safly check and cast to BindSymbol */
68-
def asBind(implicit ctx: Context): BindSymbol = self match {
69-
case IsBindSymbol(self) => self
70-
case _ => throw new Exception("not a BindSymbol")
67+
/** Unsafe cast as to BindSymbol. Use IsBindDefSymbol to safely check and cast to BindSymbol */
68+
def asBindDef(implicit ctx: Context): BindDefSymbol = self match {
69+
case IsBindDefSymbol(self) => self
70+
case _ => throw new Exception("not a BindDefSymbol")
7171
}
7272

7373
/** Annotations attached to this symbol */
@@ -86,30 +86,30 @@ trait SymbolOps extends Core {
8686

8787
// PackageSymbol
8888

89-
object IsPackageSymbol {
90-
def unapply(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] =
89+
object IsPackageDefSymbol {
90+
def unapply(symbol: Symbol)(implicit ctx: Context): Option[PackageDefSymbol] =
9191
kernel.matchPackageDefSymbol(symbol)
9292
}
9393

94-
implicit class PackageSymbolAPI(self: PackageSymbol) {
94+
implicit class PackageDefSymbolAPI(self: PackageDefSymbol) {
9595
def tree(implicit ctx: Context): PackageDef =
9696
kernel.PackageDefSymbol_tree(self)
9797
}
9898

9999
// ClassSymbol
100100

101-
object IsClassSymbol {
102-
def unapply(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] =
101+
object IsClassDefSymbol {
102+
def unapply(symbol: Symbol)(implicit ctx: Context): Option[ClassDefSymbol] =
103103
kernel.matchClassDefSymbol(symbol)
104104
}
105105

106-
object ClassSymbol {
106+
object ClassDefSymbol {
107107
/** The ClassSymbol of a global class definition */
108-
def of(fullName: String)(implicit ctx: Context): ClassSymbol =
108+
def of(fullName: String)(implicit ctx: Context): ClassDefSymbol =
109109
kernel.ClassDefSymbol_of(fullName)
110110
}
111111

112-
implicit class ClassSymbolAPI(self: ClassSymbol) {
112+
implicit class ClassDefSymbolAPI(self: ClassDefSymbol) {
113113
/** ClassDef tree of this defintion */
114114
def tree(implicit ctx: Context): ClassDef =
115115
kernel.ClassDefSymbol_tree(self)
@@ -123,31 +123,31 @@ trait SymbolOps extends Core {
123123
kernel.ClassDefSymbol_field(self)(name)
124124

125125
/** Get non-private named methods defined directly inside the class */
126-
def classMethod(name: String)(implicit ctx: Context): List[DefSymbol] =
126+
def classMethod(name: String)(implicit ctx: Context): List[DefDefSymbol] =
127127
kernel.ClassDefSymbol_classMethod(self)(name)
128128

129129
/** Get all non-private methods defined directly inside the class, exluding constructors */
130-
def classMethods(implicit ctx: Context): List[DefSymbol] =
130+
def classMethods(implicit ctx: Context): List[DefDefSymbol] =
131131
kernel.ClassDefSymbol_classMethods(self)
132132

133133
/** Get named non-private methods declared or inherited */
134-
def method(name: String)(implicit ctx: Context): List[DefSymbol] =
134+
def method(name: String)(implicit ctx: Context): List[DefDefSymbol] =
135135
kernel.ClassDefSymbol_method(self)(name)
136136

137137
/** Get all non-private methods declared or inherited */
138-
def methods(implicit ctx: Context): List[DefSymbol] =
138+
def methods(implicit ctx: Context): List[DefDefSymbol] =
139139
kernel.ClassDefSymbol_methods(self)
140140

141141
/** Fields of a case class type -- only the ones declared in primary constructor */
142-
def caseFields(implicit ctx: Context): List[ValSymbol] =
142+
def caseFields(implicit ctx: Context): List[ValDefSymbol] =
143143
kernel.ClassDefSymbol_caseFields(self)
144144

145145
/** The class symbol of the companion module class */
146-
def companionClass(implicit ctx: Context): Option[ClassSymbol] =
146+
def companionClass(implicit ctx: Context): Option[ClassDefSymbol] =
147147
kernel.ClassDefSymbol_companionClass(self)
148148

149149
/** The symbol of the companion module */
150-
def companionModule(implicit ctx: Context): Option[ValSymbol] =
150+
def companionModule(implicit ctx: Context): Option[ValDefSymbol] =
151151
kernel.ClassDefSymbol_companionModule(self)
152152

153153
/** The symbol of the class of the companion module */
@@ -157,12 +157,12 @@ trait SymbolOps extends Core {
157157

158158
// TypeSymbol
159159

160-
object IsTypeSymbol {
161-
def unapply(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] =
160+
object IsTypeDefSymbol {
161+
def unapply(symbol: Symbol)(implicit ctx: Context): Option[TypeDefSymbol] =
162162
kernel.matchTypeDefSymbol(symbol)
163163
}
164164

165-
implicit class TypeSymbolAPI(self: TypeSymbol) {
165+
implicit class TypeDefSymbolAPI(self: TypeDefSymbol) {
166166
/** TypeDef tree of this definition */
167167
def tree(implicit ctx: Context): TypeDef =
168168
kernel.TypeDefSymbol_tree(self)
@@ -173,12 +173,12 @@ trait SymbolOps extends Core {
173173

174174
// DefSymbol
175175

176-
object IsDefSymbol {
177-
def unapply(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] =
176+
object IsDefDefSymbol {
177+
def unapply(symbol: Symbol)(implicit ctx: Context): Option[DefDefSymbol] =
178178
kernel.matchDefDefSymbol(symbol)
179179
}
180180

181-
implicit class DefSymbolAPI(self: DefSymbol) {
181+
implicit class DefDefSymbolAPI(self: DefDefSymbol) {
182182
/** DefDef tree of this defintion */
183183
def tree(implicit ctx: Context): DefDef =
184184
kernel.DefDefSymbol_tree(self)
@@ -190,32 +190,32 @@ trait SymbolOps extends Core {
190190

191191
// ValSymbol
192192

193-
object IsValSymbol {
194-
def unapply(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] =
193+
object IsValDefSymbol {
194+
def unapply(symbol: Symbol)(implicit ctx: Context): Option[ValDefSymbol] =
195195
kernel.matchValDefSymbol(symbol)
196196
}
197197

198-
implicit class ValSymbolAPI(self: ValSymbol) {
198+
implicit class ValDefSymbolAPI(self: ValDefSymbol) {
199199
/** ValDef tree of this defintion */
200200
def tree(implicit ctx: Context): ValDef =
201201
kernel.ValDefSymbol_tree(self)
202202

203203
/** The class symbol of the companion module class */
204-
def moduleClass(implicit ctx: Context): Option[ClassSymbol] =
204+
def moduleClass(implicit ctx: Context): Option[ClassDefSymbol] =
205205
kernel.ValDefSymbol_moduleClass(self)
206206

207-
def companionClass(implicit ctx: Context): Option[ClassSymbol] =
207+
def companionClass(implicit ctx: Context): Option[ClassDefSymbol] =
208208
kernel.ValDefSymbol_companionClass(self)
209209
}
210210

211211
// BindSymbol
212212

213-
object IsBindSymbol {
214-
def unapply(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] =
213+
object IsBindDefSymbol {
214+
def unapply(symbol: Symbol)(implicit ctx: Context): Option[BindDefSymbol] =
215215
kernel.matchBindSymbol(symbol)
216216
}
217217

218-
implicit class BindSymbolAPI(self: BindSymbol) {
218+
implicit class BindDefSymbolAPI(self: BindDefSymbol) {
219219
/** Bind pattern of this definition */
220220
def tree(implicit ctx: Context): Bind =
221221
kernel.BindSymbol_tree(self)

0 commit comments

Comments
 (0)