diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 21a5abcb7ce8..5ea4b8aa21a7 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -1435,6 +1435,11 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def PackageDefSymbol_tree(self: PackageDefSymbol)(implicit ctx: Context): PackageDef = FromSymbol.packageDefFromSym(self) + type TypeSymbol = core.Symbols.TypeSymbol + + def matchTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] = + if (symbol.isType) Some(symbol.asType) else None + type ClassDefSymbol = core.Symbols.ClassSymbol def matchClassDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassDefSymbol] = @@ -1522,6 +1527,11 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def TypeBindSymbol_tree(self: TypeBindSymbol)(implicit ctx: Context): TypeTree_TypeBind = FromSymbol.typeBindFromSym(self) + type TermSymbol = core.Symbols.TermSymbol + + def matchTermSymbol(symbol: Symbol)(implicit ctx: Context): Option[TermSymbol] = + if (symbol.isTerm) Some(symbol.asTerm) else None + type DefDefSymbol = core.Symbols.TermSymbol def matchDefDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefDefSymbol] = diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index 806cc0727299..d1e6fb4709bc 100644 --- a/library/src/scala/tasty/reflect/Core.scala +++ b/library/src/scala/tasty/reflect/Core.scala @@ -101,12 +101,15 @@ package scala.tasty.reflect * +- Constant * * +- Symbol --+- PackageDefSymbol - * +- ClassDefSymbol - * +- TypeDefSymbol - * +- TypeBindSymbol - * +- DefDefSymbol - * +- ValDefSymbol - * +- BindSymbol + * | + * +- TypeSymbol -+- ClassDefSymbol + * | +- TypeDefSymbol + * | +- TypeBindSymbol + * | + * +- TermSymbol -+- DefDefSymbol + * | +- ValDefSymbol + * | +- BindSymbol + * | * +- NoSymbol * * +- Flags @@ -421,23 +424,29 @@ trait Core { /** Symbol of a package definition */ type PackageDefSymbol = kernel.PackageDefSymbol - /** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */ - type ClassDefSymbol = kernel.ClassDefSymbol + /** Symbol representing a type definition. */ + type TypeSymbol = kernel.TypeSymbol - /** Symbol of a type (parameter or member) definition. */ - type TypeDefSymbol = kernel.TypeDefSymbol + /** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */ + type ClassDefSymbol = kernel.ClassDefSymbol - /** Symbol representing a type bind definition. */ - type TypeBindSymbol = kernel.TypeBindSymbol + /** Symbol of a type (parameter or member) definition. */ + type TypeDefSymbol = kernel.TypeDefSymbol - /** Symbol representing a method definition. */ - type DefDefSymbol = kernel.DefDefSymbol + /** Symbol representing a type bind definition. */ + type TypeBindSymbol = kernel.TypeBindSymbol - /** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */ - type ValDefSymbol = kernel.ValDefSymbol + /** Symbol representing a term definition. */ + type TermSymbol = kernel.TermSymbol - /** Symbol representing a bind definition. */ - type BindSymbol = kernel.BindSymbol + /** Symbol representing a method definition. */ + type DefDefSymbol = kernel.DefDefSymbol + + /** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */ + type ValDefSymbol = kernel.ValDefSymbol + + /** Symbol representing a bind definition. */ + type BindSymbol = kernel.BindSymbol /** No symbol available. */ type NoSymbol = kernel.NoSymbol diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 3869b49707bf..38c605ccfc6b 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -100,12 +100,15 @@ package scala.tasty.reflect * +- Constant * * +- Symbol --+- PackageDefSymbol - * +- ClassDefSymbol - * +- TypeDefSymbol - * +- TypeBindSymbol - * +- DefDefSymbol - * +- ValDefSymbol - * +- BindSymbol + * | + * +- TypeSymbol -+- ClassDefSymbol + * | +- TypeDefSymbol + * | +- TypeBindSymbol + * | + * +- TermSymbol -+- DefDefSymbol + * | +- ValDefSymbol + * | +- BindSymbol + * | * +- NoSymbol * * +- Flags @@ -249,7 +252,7 @@ trait Kernel { def DefDef_apply(symbol: DefDefSymbol, rhsFn: List[Type] => List[List[Term]] => Option[Term])(implicit ctx: Context): DefDef def DefDef_copy(original: DefDef)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): DefDef - /** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */ + /** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter definitions. */ type ValDef <: Definition def matchValDef(tree: Tree)(implicit ctx: Context): Option[ValDef] @@ -1173,12 +1176,16 @@ trait Kernel { def PackageDefSymbol_tree(self: PackageDefSymbol)(implicit ctx: Context): PackageDef + type TypeSymbol <: Symbol + + def matchTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] + /** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */ - type ClassDefSymbol <: Symbol + type ClassDefSymbol <: TypeSymbol def matchClassDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassDefSymbol] - /** ClassDef tree of this defintion */ + /** ClassDef tree of this definition */ def ClassDefSymbol_tree(self: ClassDefSymbol)(implicit ctx: Context): ClassDef /** Fields directly declared in the class */ @@ -1214,7 +1221,7 @@ trait Kernel { def ClassDefSymbol_of(fullName: String)(implicit ctx: Context): ClassDefSymbol /** Symbol of a type (parameter or member) definition. */ - type TypeDefSymbol <: Symbol + type TypeDefSymbol <: TypeSymbol def matchTypeDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeDefSymbol] @@ -1224,30 +1231,34 @@ trait Kernel { def TypeDefSymbol_tree(self: TypeDefSymbol)(implicit ctx: Context): TypeDef /** Symbol representing a bind definition. */ - type TypeBindSymbol <: Symbol + type TypeBindSymbol <: TypeSymbol def matchTypeBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeBindSymbol] /** TypeBind pattern of this definition */ def TypeBindSymbol_tree(self: TypeBindSymbol)(implicit ctx: Context): TypeTree_TypeBind + type TermSymbol <: Symbol + + def matchTermSymbol(symbol: Symbol)(implicit ctx: Context): Option[TermSymbol] + /** Symbol representing a method definition. */ - type DefDefSymbol <: Symbol + type DefDefSymbol <: TermSymbol def matchDefDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefDefSymbol] - /** DefDef tree of this defintion */ + /** DefDef tree of this definition */ def DefDefSymbol_tree(self: DefDefSymbol)(implicit ctx: Context): DefDef - /** Signature of this defintion */ + /** Signature of this definition */ def DefDefSymbol_signature(self: DefDefSymbol)(implicit ctx: Context): Signature /** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */ - type ValDefSymbol <: Symbol + type ValDefSymbol <: TermSymbol def matchValDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[ValDefSymbol] - /** ValDef tree of this defintion */ + /** ValDef tree of this definition */ def ValDefSymbol_tree(self: ValDefSymbol)(implicit ctx: Context): ValDef /** The class symbol of the companion module class */ @@ -1256,7 +1267,7 @@ trait Kernel { def ValDefSymbol_companionClass(self: ValDefSymbol)(implicit ctx: Context): Option[ClassDefSymbol] /** Symbol representing a bind definition. */ - type BindSymbol <: Symbol + type BindSymbol <: TermSymbol def matchBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] diff --git a/library/src/scala/tasty/reflect/SymbolOps.scala b/library/src/scala/tasty/reflect/SymbolOps.scala index e98c7ca022f4..5e34d610c4c8 100644 --- a/library/src/scala/tasty/reflect/SymbolOps.scala +++ b/library/src/scala/tasty/reflect/SymbolOps.scala @@ -96,6 +96,13 @@ trait SymbolOps extends Core { kernel.PackageDefSymbol_tree(self) } + // TypeSymbol + + object IsTypeSymbol { + def unapply(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] = + kernel.matchTypeSymbol(symbol) + } + // ClassSymbol object IsClassDefSymbol { @@ -184,6 +191,13 @@ trait SymbolOps extends Core { kernel.TypeBindSymbol_tree(self) } + // TermSymbol + + object IsTermSymbol { + def unapply(symbol: Symbol)(implicit ctx: Context): Option[TermSymbol] = + kernel.matchTermSymbol(symbol) + } + // DefSymbol object IsDefDefSymbol {