Skip to content

Commit 3e374d9

Browse files
committed
Remove redundant Symbol.asXYZ methods
1 parent 99f0f30 commit 3e374d9

File tree

4 files changed

+10
-40
lines changed

4 files changed

+10
-40
lines changed

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,6 @@ trait SymbolOps extends Core { selfSymbolOps: FlagsOps =>
4242
/** The comment for this symbol, if any */
4343
def comment(given ctx: Context): Option[Comment] = internal.Symbol_comment(self)
4444

45-
/** Unsafe cast as to PackageSymbol */
46-
def asPackageDef(given ctx: Context): Symbol =
47-
if self.isPackageDef then self
48-
else throw new Exception("not a PackageDefSymbol")
49-
50-
/** Unsafe cast as to ClassSymbol */
51-
def asClassDef(given ctx: Context): Symbol =
52-
if self.isClassDef then self
53-
else throw new Exception("not a class Symbol")
54-
55-
/** Unsafe cast as to DefSymbol */
56-
def asDefDef(given ctx: Context): Symbol =
57-
if self.isDefDef then self
58-
else throw new Exception("not a def Symbol")
59-
60-
/** Unsafe cast as to ValSymbol */
61-
def asValDef(given ctx: Context): Symbol =
62-
if self.isValDef then self
63-
else throw new Exception("not a val Symbol")
64-
65-
/** Unsafe cast as to TypeSymbol */
66-
def asTypeDef(given ctx: Context): Symbol =
67-
if self.isTypeDef then self
68-
else throw new Exception("not a type Symbol")
69-
70-
/** Unsafe cast as to BindSymbol */
71-
def asBindDef(given ctx: Context): Symbol =
72-
if self.isBind then self
73-
else throw new Exception("not a bind Symbol")
74-
7545
/** Tree of this definition */
7646
def tree(given ctx: Context): Tree =
7747
internal.Symbol_tree(self)

tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,46 @@ object TypeToolbox {
3737
inline def caseFields[T]: List[String] = ${caseFieldsImpl('[T])}
3838
private def caseFieldsImpl(tp: Type[_])(given qctx: QuoteContext): Expr[List[String]] = {
3939
import qctx.tasty._
40-
val fields = tp.unseal.symbol.asClassDef.caseFields.map(_.name)
40+
val fields = tp.unseal.symbol.caseFields.map(_.name)
4141
Expr(fields)
4242
}
4343

4444
inline def fieldIn[T](inline mem: String): String = ${fieldInImpl('[T], mem)}
4545
private def fieldInImpl(t: Type[_], mem: String)(given qctx: QuoteContext): Expr[String] = {
4646
import qctx.tasty._
47-
val field = t.unseal.symbol.asClassDef.field(mem)
47+
val field = t.unseal.symbol.field(mem)
4848
Expr(if field.isNoSymbol then "" else field.name)
4949
}
5050

5151
inline def fieldsIn[T]: Seq[String] = ${fieldsInImpl('[T])}
5252
private def fieldsInImpl(t: Type[_])(given qctx: QuoteContext): Expr[Seq[String]] = {
5353
import qctx.tasty._
54-
val fields = t.unseal.symbol.asClassDef.fields
54+
val fields = t.unseal.symbol.fields
5555
Expr(fields.map(_.name).toList)
5656
}
5757

5858
inline def methodIn[T](inline mem: String): Seq[String] = ${methodInImpl('[T], mem)}
5959
private def methodInImpl(t: Type[_], mem: String)(given qctx: QuoteContext): Expr[Seq[String]] = {
6060
import qctx.tasty._
61-
Expr(t.unseal.symbol.asClassDef.classMethod(mem).map(_.name))
61+
Expr(t.unseal.symbol.classMethod(mem).map(_.name))
6262
}
6363

6464
inline def methodsIn[T]: Seq[String] = ${methodsInImpl('[T])}
6565
private def methodsInImpl(t: Type[_])(given qctx: QuoteContext): Expr[Seq[String]] = {
6666
import qctx.tasty._
67-
Expr(t.unseal.symbol.asClassDef.classMethods.map(_.name))
67+
Expr(t.unseal.symbol.classMethods.map(_.name))
6868
}
6969

7070
inline def method[T](inline mem: String): Seq[String] = ${methodImpl('[T], mem)}
7171
private def methodImpl(t: Type[_], mem: String)(given qctx: QuoteContext): Expr[Seq[String]] = {
7272
import qctx.tasty._
73-
Expr(t.unseal.symbol.asClassDef.method(mem).map(_.name))
73+
Expr(t.unseal.symbol.method(mem).map(_.name))
7474
}
7575

7676
inline def methods[T]: Seq[String] = ${methodsImpl('[T])}
7777
private def methodsImpl(t: Type[_])(given qctx: QuoteContext): Expr[Seq[String]] = {
7878
import qctx.tasty._
79-
Expr(t.unseal.symbol.asClassDef.methods.map(_.name))
79+
Expr(t.unseal.symbol.methods.map(_.name))
8080
}
8181

8282
inline def typeTag[T](x: T): String = ${typeTagImpl('[T])}
@@ -89,7 +89,7 @@ object TypeToolbox {
8989
inline def companion[T1, T2]: Boolean = ${companionImpl('[T1], '[T2])}
9090
private def companionImpl(t1: Type[_], t2: Type[_])(given qctx: QuoteContext): Expr[Boolean] = {
9191
import qctx.tasty._
92-
val res = t1.unseal.symbol.asClassDef.companionModule == t2.unseal.symbol
92+
val res = t1.unseal.symbol.companionModule == t2.unseal.symbol
9393
Expr(res)
9494
}
9595

0 commit comments

Comments
 (0)