From 0ca1bdfce73ff399cd60fef9fc34ebf5aaec33d1 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 27 Feb 2019 08:53:14 +0100 Subject: [PATCH 01/17] Create tasty.reflect.Kernel --- .../tools/dotc/tastyreflect/CoreImpl.scala | 126 +---- .../tools/dotc/tastyreflect/KernelImpl.scala | 127 +++++ .../tools/dotc/tastyreflect/TreeOpsImpl.scala | 3 +- .../TypeOrBoundsTreesOpsImpl.scala | 2 +- .../other-new-features/tasty-reflect.md | 2 + .../src/scala/tasty/reflect/CommentOps.scala | 2 +- library/src/scala/tasty/reflect/Core.scala | 206 ++++---- library/src/scala/tasty/reflect/Kernel.scala | 492 ++++++++++++++++++ 8 files changed, 730 insertions(+), 230 deletions(-) create mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala create mode 100644 library/src/scala/tasty/reflect/Kernel.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala index 83220030ac55..8ef74dbd473c 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala @@ -1,132 +1,8 @@ package dotty.tools.dotc package tastyreflect -import dotty.tools.dotc.ast.{tpd, untpd} -import dotty.tools.dotc.core.Constants -import dotty.tools.dotc.core.Types - trait CoreImpl extends scala.tasty.reflect.Core { - type Context = core.Contexts.Context - - type Settings = config.ScalaSettings - - type TermOrTypeTree = tpd.Tree - - type Tree = tpd.Tree - type PackageClause = tpd.PackageDef - type Statement = tpd.Tree - type Import = tpd.Import - type Definition = tpd.Tree - type PackageDef = PackageDefinition - type ClassDef = tpd.TypeDef - type TypeDef = tpd.TypeDef - type DefDef = tpd.DefDef - type ValDef = tpd.ValDef - type Term = tpd.Tree - val Term: TermCoreModuleImpl - trait TermCoreModuleImpl extends TermCoreModule { - type Ref = tpd.RefTree - type Ident = tpd.Ident - type Select = tpd.Select - type Literal = tpd.Literal - type This = tpd.This - type New = tpd.New - type NamedArg = tpd.NamedArg - type Apply = tpd.Apply - type TypeApply = tpd.TypeApply - type Super = tpd.Super - type Typed = tpd.Typed - type Assign = tpd.Assign - type Block = tpd.Block - type Lambda = tpd.Closure - type If = tpd.If - type Match = tpd.Match - type Try = tpd.Try - type Return = tpd.Return - type Repeated = tpd.SeqLiteral - type Inlined = tpd.Inlined - type SelectOuter = tpd.Select - type While = tpd.WhileDo - } - - - type CaseDef = tpd.CaseDef - type TypeCaseDef = tpd.CaseDef - - type Pattern = tpd.Tree - type Value = tpd.Tree - type Bind = tpd.Bind - type Unapply = tpd.UnApply - type Alternatives = tpd.Alternative - type TypeTest = tpd.Typed - - type TypeOrBoundsTree = tpd.Tree - type TypeTree = tpd.Tree - val TypeTree: TypeTreeCoreModuleImpl - trait TypeTreeCoreModuleImpl extends TypeTreeCoreModule { - type Inferred = tpd.TypeTree - type Ident = tpd.Ident - type Select = tpd.Select - type Projection = tpd.Select - type Singleton = tpd.SingletonTypeTree - type Refined = tpd.RefinedTypeTree - type Applied = tpd.AppliedTypeTree - type Annotated = tpd.Annotated - type MatchType = tpd.MatchTypeTree - type ByName = tpd.ByNameTypeTree - type LambdaTypeTree = tpd.LambdaTypeTree - type TypeBind = tpd.Bind - type TypeBlock = tpd.Block - } - type TypeBoundsTree = tpd.TypeBoundsTree - type WildcardType = tpd.TypeTree - - type TypeOrBounds = Types.Type - type NoPrefix = Types.NoPrefix.type - type TypeBounds = Types.TypeBounds - type Type = Types.Type - type ConstantType = Types.ConstantType - type SymRef = Types.NamedType - type TermRef = Types.NamedType - type TypeRef = Types.NamedType - type SuperType = Types.SuperType - type Refinement = Types.RefinedType - type AppliedType = Types.AppliedType - type AnnotatedType = Types.AnnotatedType - type AndType = Types.AndType - type OrType = Types.OrType - type MatchType = Types.MatchType - type ByNameType = Types.ExprType - type ParamRef = Types.ParamRef - type ThisType = Types.ThisType - type RecursiveThis = Types.RecThis - type RecursiveType = Types.RecType - type LambdaType[ParamInfo] = Types.LambdaType { type PInfo = ParamInfo } - type MethodType = Types.MethodType - type PolyType = Types.PolyType - type TypeLambda = Types.TypeLambda - - type ImportSelector = untpd.Tree - - type Id = untpd.Ident - - type Signature = core.Signature - - type Position = util.SourcePosition - - type Comment = core.Comments.Comment - - type Constant = Constants.Constant - - type Symbol = core.Symbols.Symbol - type PackageSymbol = core.Symbols.Symbol - type ClassSymbol = core.Symbols.ClassSymbol - type TypeSymbol = core.Symbols.TypeSymbol - type DefSymbol = core.Symbols.TermSymbol - type BindSymbol = core.Symbols.TermSymbol - type ValSymbol = core.Symbols.TermSymbol - type NoSymbol = core.Symbols.NoSymbol.type + final val kernel: KernelImpl = new KernelImpl - type Flags = core.Flags.FlagSet } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala new file mode 100644 index 000000000000..f2c86ef7f4fa --- /dev/null +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -0,0 +1,127 @@ +package dotty.tools.dotc +package tastyreflect + +import dotty.tools.dotc.ast.{tpd, untpd} +import dotty.tools.dotc.core.Constants +import dotty.tools.dotc.core.Types + +import scala.tasty.reflect.Kernel + +class KernelImpl extends Kernel { + type Context = core.Contexts.Context + + type Settings = config.ScalaSettings + + type TermOrTypeTree = tpd.Tree + + type Tree = tpd.Tree + type PackageClause = tpd.PackageDef + type Statement = tpd.Tree + type Import = tpd.Import + type Definition = tpd.Tree + type PackageDef = PackageDefinition + type ClassDef = tpd.TypeDef + type TypeDef = tpd.TypeDef + type DefDef = tpd.DefDef + type ValDef = tpd.ValDef + type Term = tpd.Tree + type Term_Ref = tpd.RefTree + type Term_Ident = tpd.Ident + type Term_Select = tpd.Select + type Term_Literal = tpd.Literal + type Term_This = tpd.This + type Term_New = tpd.New + type Term_NamedArg = tpd.NamedArg + type Term_Apply = tpd.Apply + type Term_TypeApply = tpd.TypeApply + type Term_Super = tpd.Super + type Term_Typed = tpd.Typed + type Term_Assign = tpd.Assign + type Term_Block = tpd.Block + type Term_Lambda = tpd.Closure + type Term_If = tpd.If + type Term_Match = tpd.Match + type Term_Try = tpd.Try + type Term_Return = tpd.Return + type Term_Repeated = tpd.SeqLiteral + type Term_Inlined = tpd.Inlined + type Term_SelectOuter = tpd.Select + type Term_While = tpd.WhileDo + + type CaseDef = tpd.CaseDef + type TypeCaseDef = tpd.CaseDef + + type Pattern = tpd.Tree + type Value = tpd.Tree + type Bind = tpd.Bind + type Unapply = tpd.UnApply + type Alternatives = tpd.Alternative + type TypeTest = tpd.Typed + + type TypeOrBoundsTree = tpd.Tree + type TypeTree = tpd.Tree + type TypeTree_Inferred = tpd.TypeTree + type TypeTree_Ident = tpd.Ident + type TypeTree_Select = tpd.Select + type TypeTree_Projection = tpd.Select + type TypeTree_Singleton = tpd.SingletonTypeTree + type TypeTree_Refined = tpd.RefinedTypeTree + type TypeTree_Applied = tpd.AppliedTypeTree + type TypeTree_Annotated = tpd.Annotated + type TypeTree_MatchType = tpd.MatchTypeTree + type TypeTree_ByName = tpd.ByNameTypeTree + type TypeTree_LambdaTypeTree = tpd.LambdaTypeTree + type TypeTree_TypeBind = tpd.Bind + type TypeTree_TypeBlock = tpd.Block + + type TypeBoundsTree = tpd.TypeBoundsTree + type WildcardType = tpd.TypeTree + + type TypeOrBounds = Types.Type + type NoPrefix = Types.NoPrefix.type + type TypeBounds = Types.TypeBounds + type Type = Types.Type + type ConstantType = Types.ConstantType + type SymRef = Types.NamedType + type TermRef = Types.NamedType + type TypeRef = Types.NamedType + type SuperType = Types.SuperType + type Refinement = Types.RefinedType + type AppliedType = Types.AppliedType + type AnnotatedType = Types.AnnotatedType + type AndType = Types.AndType + type OrType = Types.OrType + type MatchType = Types.MatchType + type ByNameType = Types.ExprType + type ParamRef = Types.ParamRef + type ThisType = Types.ThisType + type RecursiveThis = Types.RecThis + type RecursiveType = Types.RecType + type LambdaType[ParamInfo] = Types.LambdaType { type PInfo = ParamInfo } + type MethodType = Types.MethodType + type PolyType = Types.PolyType + type TypeLambda = Types.TypeLambda + + type ImportSelector = untpd.Tree + + type Id = untpd.Ident + + type Signature = core.Signature + + type Position = util.SourcePosition + + type Comment = core.Comments.Comment + + type Constant = Constants.Constant + + type Symbol = core.Symbols.Symbol + type PackageSymbol = core.Symbols.Symbol + type ClassSymbol = core.Symbols.ClassSymbol + type TypeSymbol = core.Symbols.TypeSymbol + type DefSymbol = core.Symbols.TermSymbol + type BindSymbol = core.Symbols.TermSymbol + type ValSymbol = core.Symbols.TermSymbol + type NoSymbol = core.Symbols.NoSymbol.type + + type Flags = core.Flags.FlagSet +} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala index 5f86ea0dd0f1..d5c689b89a68 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala @@ -368,7 +368,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with RootPositionImpl with if (termOrTypeTree.isTerm) Some(termOrTypeTree) else None } - object Term extends TermModule with TermCoreModuleImpl { + object Term extends TermModule with TermCoreModule { object IsIdent extends IsIdentModule { def unapply(x: Term)(implicit ctx: Context): Option[Ident] = x match { @@ -377,7 +377,6 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with RootPositionImpl with } } - object Ref extends RefModule { def apply(sym: Symbol)(implicit ctx: Context): Ref = withDefaultPos(ctx => tpd.ref(sym)(ctx).asInstanceOf[tpd.RefTree]) } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala index 7541f6d820be..5dc2725996ce 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala @@ -95,7 +95,7 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } - object TypeTree extends TypeTreeModule with TypeTreeCoreModuleImpl { + object TypeTree extends TypeTreeModule with TypeTreeCoreModule { object IsInferred extends IsInferredModule { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Inferred] = tpt match { diff --git a/docs/docs/reference/other-new-features/tasty-reflect.md b/docs/docs/reference/other-new-features/tasty-reflect.md index a98010a52991..8114a530e0a7 100644 --- a/docs/docs/reference/other-new-features/tasty-reflect.md +++ b/docs/docs/reference/other-new-features/tasty-reflect.md @@ -175,6 +175,8 @@ TASTy Reflect provides the following types: +- Position ++- Comment + +- Constant +- Symbol --+- PackageSymbol diff --git a/library/src/scala/tasty/reflect/CommentOps.scala b/library/src/scala/tasty/reflect/CommentOps.scala index 97480f7160e6..9ba18317e85f 100644 --- a/library/src/scala/tasty/reflect/CommentOps.scala +++ b/library/src/scala/tasty/reflect/CommentOps.scala @@ -14,6 +14,6 @@ trait CommentOps extends Core { def usecases: List[(String, Option[DefDef])] } - implicit def CommentDeco(com: Comment): CommentAPI + implicit def CommentDeco(comment: Comment): CommentAPI } diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index 3da2cea1a533..a1f7541dda31 100644 --- a/library/src/scala/tasty/reflect/Core.scala +++ b/library/src/scala/tasty/reflect/Core.scala @@ -97,6 +97,8 @@ package scala.tasty.reflect * * +- Position * + * +- Comment + * * +- Constant * * +- Symbol --+- PackageSymbol @@ -116,48 +118,50 @@ package scala.tasty.reflect */ trait Core { + val kernel: Kernel + /** Compilation context */ - type Context <: AnyRef + type Context = kernel.Context /** Settings */ - type Settings <: AnyRef + type Settings = kernel.Settings // TODO: When bootstrapped, remove and use `Term | TypeTree` type directly in other files /** Workaround missing `|` types in Scala 2 to represent `Term | TypeTree` */ - type TermOrTypeTree /* Term | TypeTree */ <: AnyRef + type TermOrTypeTree /* Term | TypeTree */ = kernel.TermOrTypeTree /** Tree representing code written in the source */ - type Tree <: AnyRef + type Tree = kernel.Tree /** Tree representing a pacakage clause in the source code */ - type PackageClause <: Tree + type PackageClause = kernel.PackageClause /** Tree representing a statement in the source code */ - type Statement <: Tree + type Statement = kernel.Statement /** Tree representing an import in the source code */ - type Import <: Statement + type Import = kernel.Import /** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef` */ - type Definition <: Statement + type Definition = kernel.Definition /** Tree representing a package definition. This includes definitions in all source files */ - type PackageDef <: Definition + type PackageDef = kernel.PackageDef /** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */ - type ClassDef <: Definition + type ClassDef = kernel.ClassDef /** Tree representing a type (paramter or member) definition in the source code */ - type TypeDef <: Definition + type TypeDef = kernel.TypeDef /** Tree representing a method definition in the source code */ - type DefDef <: Definition + type DefDef = kernel.DefDef /** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */ - type ValDef <: Definition + type ValDef = kernel.ValDef /** Tree representing an expression in the source code */ - type Term <: Statement + type Term = kernel.Term /** Trees representing an expression in the source code */ val Term: TermCoreModule @@ -166,232 +170,232 @@ trait Core { trait TermCoreModule { /** Tree representing a reference to definition */ - type Ref <: Term + type Ref = kernel.Term_Ref /** Tree representing a reference to definition with a given name */ - type Ident <: Ref + type Ident = kernel.Term_Ident /** Tree representing a selection of definition with a given name on a given prefix */ - type Select <: Ref + type Select = kernel.Term_Select /** Tree representing a literal value in the source code */ - type Literal <: Term + type Literal = kernel.Term_Literal /** Tree representing `this` in the source code */ - type This <: Term + type This = kernel.Term_This /** Tree representing `new` in the source code */ - type New <: Term + type New = kernel.Term_New /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ - type NamedArg <: Term + type NamedArg = kernel.Term_NamedArg /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ - type Apply <: Term + type Apply = kernel.Term_Apply /** Tree an application of type arguments */ - type TypeApply <: Term + type TypeApply = kernel.Term_TypeApply /** Tree representing `super` in the source code */ - type Super <: Term + type Super = kernel.Term_Super /** Tree representing a type ascription `x: T` in the source code */ - type Typed <: Term + type Typed = kernel.Term_Typed /** Tree representing an assignment `x = y` in the source code */ - type Assign <: Term + type Assign = kernel.Term_Assign /** Tree representing a block `{ ... }` in the source code */ - type Block <: Term + type Block = kernel.Term_Block /** Tree representing a lambda `(...) => ...` in the source code */ - type Lambda <: Term + type Lambda = kernel.Term_Lambda /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ - type If <: Term + type If = kernel.Term_If /** Tree representing a pattern match `x match { ... }` in the source code */ - type Match <: Term + type Match = kernel.Term_Match /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ - type Try <: Term + type Try = kernel.Term_Try /** Tree representing a `return` in the source code */ - type Return <: Term + type Return = kernel.Term_Return /** Tree representing a variable argument list in the source code */ - type Repeated <: Term + type Repeated = kernel.Term_Repeated /** Tree representing the scope of an inlined tree */ - type Inlined <: Term + type Inlined = kernel.Term_Inlined /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ - type SelectOuter <: Term + type SelectOuter = kernel.Term_SelectOuter /** Tree representing a while loop */ - type While <: Term + type While = kernel.Term_While } /** Branch of a pattern match or catch clause */ - type CaseDef <: AnyRef + type CaseDef = kernel.CaseDef /** Branch of a type pattern match */ - type TypeCaseDef <: AnyRef + type TypeCaseDef = kernel.TypeCaseDef /** Pattern tree of the pattern part of a CaseDef */ - type Pattern <: AnyRef + type Pattern = kernel.Pattern /** Pattern representing a value. This includes `1`, ```x``` and `_` */ - type Value <: Pattern + type Value = kernel.Value /** Pattern representing a `_ @ _` binding. */ - type Bind <: Pattern + type Bind = kernel.Bind /** Pattern representing a `Xyz(...)` unapply. */ - type Unapply <: Pattern + type Unapply = kernel.Unapply /** Pattern representing `X | Y | ...` alternatives. */ - type Alternatives <: Pattern + type Alternatives = kernel.Alternatives /** Pattern representing a `x: Y` type test. */ - type TypeTest <: Pattern + type TypeTest = kernel.TypeTest /** Type tree representing a type or a bounds written in the source */ - type TypeOrBoundsTree <: AnyRef + type TypeOrBoundsTree = kernel.TypeOrBoundsTree /** Type tree representing a type written in the source */ - type TypeTree <: TypeOrBoundsTree + type TypeTree = kernel.TypeTree /** Type trees representing a type written in the source */ val TypeTree: TypeTreeCoreModule /** Type trees representing a type written in the source */ - abstract class TypeTreeCoreModule { + trait TypeTreeCoreModule { /** Type tree representing an inferred type */ - type Inferred <: TypeTree + type Inferred = kernel.TypeTree_Inferred /** Type tree representing a reference to definition with a given name */ - type Ident <: TypeTree + type Ident = kernel.TypeTree_Ident /** Type tree representing a selection of definition with a given name on a given term prefix */ - type Select <: TypeTree + type Select = kernel.TypeTree_Select /** Type tree representing a selection of definition with a given name on a given type prefix */ - type Projection <: TypeTree + type Projection = kernel.TypeTree_Projection /** Type tree representing a singleton type */ - type Singleton <: TypeTree + type Singleton = kernel.TypeTree_Singleton /** Type tree representing a type refinement */ - type Refined <: TypeTree + type Refined = kernel.TypeTree_Refined /** Type tree representing a type application */ - type Applied <: TypeTree + type Applied = kernel.TypeTree_Applied /** Type tree representing an annotated type */ - type Annotated <: TypeTree + type Annotated = kernel.TypeTree_Annotated /** Type tree representing a type match */ - type MatchType <: TypeTree + type MatchType = kernel.TypeTree_MatchType /** Type tree representing a by name parameter */ - type ByName <: TypeTree + type ByName = kernel.TypeTree_ByName /** Type tree representing a lambda abstraction type */ - type LambdaTypeTree <: TypeTree + type LambdaTypeTree = kernel.TypeTree_LambdaTypeTree /** Type tree representing a type binding */ - type TypeBind <: TypeTree + type TypeBind = kernel.TypeTree_TypeBind /** Type tree within a block with aliases `{ type U1 = ... ; T[U1, U2] }` */ - type TypeBlock <: TypeTree + type TypeBlock = kernel.TypeTree_TypeBlock } /** Type tree representing a type bound written in the source */ - type TypeBoundsTree <: TypeOrBoundsTree + type TypeBoundsTree = kernel.TypeBoundsTree /** Type tree representing wildcard type bounds written in the source. * The wildcard type `_` (for example in in `List[_]`) will be a type tree that * represents a type but has `TypeBound`a inside. */ - type WildcardType <: TypeOrBoundsTree + type WildcardType = kernel.WildcardType /** Type or bounds */ - type TypeOrBounds <: AnyRef + type TypeOrBounds = kernel.TypeOrBounds /** NoPrefix for a type selection */ - type NoPrefix <: TypeOrBounds + type NoPrefix = kernel.NoPrefix /** Type bounds */ - type TypeBounds <: TypeOrBounds + type TypeBounds = kernel.TypeBounds /** A type */ - type Type <: TypeOrBounds + type Type = kernel.Type /** A singleton type representing a known constant value */ - type ConstantType <: Type + type ConstantType = kernel.ConstantType /** Type of a reference to a symbol */ - type SymRef <: Type + type SymRef = kernel.SymRef /** Type of a reference to a term */ - type TermRef <: Type + type TermRef = kernel.TermRef /** Type of a reference to a type */ - type TypeRef <: Type + type TypeRef = kernel.TypeRef /** Type of a `super` refernce */ - type SuperType <: Type + type SuperType = kernel.SuperType /** A type with a type refinement `T { type U }` */ - type Refinement <: Type + type Refinement = kernel.Refinement /** A higher kinded type applied to some types `T[U]` */ - type AppliedType <: Type + type AppliedType = kernel.AppliedType /** A type with an anottation `T @foo` */ - type AnnotatedType <: Type + type AnnotatedType = kernel.AnnotatedType /** Intersection type `T & U` */ - type AndType <: Type + type AndType = kernel.AndType /** Union type `T | U` */ - type OrType <: Type + type OrType = kernel.OrType /** Type match `T match { case U => ... }` */ - type MatchType <: Type + type MatchType = kernel.MatchType /** Type of a by by name parameter */ - type ByNameType <: Type + type ByNameType = kernel.ByNameType /** Type of a parameter reference */ - type ParamRef <: Type + type ParamRef = kernel.ParamRef /** Type of `this` */ - type ThisType <: Type + type ThisType = kernel.ThisType /** A type that is recursively defined `this` */ - type RecursiveThis <: Type + type RecursiveThis = kernel.RecursiveThis /** A type that is recursively defined */ - type RecursiveType <: Type + type RecursiveType = kernel.RecursiveType // TODO can we add the bound back without an cake? // TODO is LambdaType really needed? ParamRefExtractor could be split into more precise extractors /** Common abstraction for lambda types (MethodType, PolyType and TypeLambda). */ - type LambdaType[ParamInfo /*<: TypeOrBounds*/] <: Type + type LambdaType[ParamInfo /*<: TypeOrBounds*/] = kernel.LambdaType[ParamInfo] /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ - type MethodType <: LambdaType[Type] + type MethodType = kernel.MethodType /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ - type PolyType <: LambdaType[TypeBounds] + type PolyType = kernel.PolyType /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ - type TypeLambda <: LambdaType[TypeBounds] + type TypeLambda = kernel.TypeLambda /** Import selectors: @@ -399,49 +403,49 @@ trait Core { * * RenameSelector: `.{bar => baz}` in `import foo.{bar => baz}` * * OmitSelector: `.{bar => _}` in `import foo.{bar => _}` */ - type ImportSelector <: AnyRef + type ImportSelector = kernel.ImportSelector /** Untyped identifier */ - type Id <: AnyRef + type Id = kernel.Id /** JVM signature of a method */ - type Signature <: AnyRef + type Signature = kernel.Signature /** Source position */ - type Position <: AnyRef + type Position = kernel.Position /** Comment */ - type Comment <: AnyRef + type Comment = kernel.Comment /** Constant value represented as the constant itself */ - type Constant <: AnyRef + type Constant = kernel.Constant /** Symbol of a definition. * Then can be compared with == to know if the definition is the same. */ - type Symbol <: AnyRef + type Symbol = kernel.Symbol /** Symbol of a package definition */ - type PackageSymbol <: Symbol + type PackageSymbol = kernel.PackageSymbol /** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */ - type ClassSymbol <: Symbol + type ClassSymbol = kernel.ClassSymbol /** Symbol of a type (parameter or member) definition. */ - type TypeSymbol <: Symbol + type TypeSymbol = kernel.TypeSymbol /** Symbol representing a method definition. */ - type DefSymbol <: Symbol + type DefSymbol = kernel.DefSymbol /** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */ - type ValSymbol <: Symbol + type ValSymbol = kernel.ValSymbol /** Symbol representing a bind definition. */ - type BindSymbol <: Symbol + type BindSymbol = kernel.BindSymbol /** No symbol available. */ - type NoSymbol <: Symbol + type NoSymbol = kernel.NoSymbol /** FlagSet of a Symbol */ - type Flags + type Flags = kernel.Flags } diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala new file mode 100644 index 000000000000..81b879bf1c7a --- /dev/null +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -0,0 +1,492 @@ +package scala.tasty.reflect + +/** Tasty reflect abstract types + * + * ```none + * + * +- Tree -+- PackageClause + * +- Import + * +- Statement -+- Definition --+- PackageDef + * | +- ClassDef + * | +- TypeDef + * | +- DefDef + * | +- ValDef + * | + * +- Term --------+- Ref -+- Ident + * | +- Select + * | + * +- Literal + * +- This + * +- New + * +- NamedArg + * +- Apply + * +- TypeApply + * +- Super + * +- Typed + * +- Assign + * +- Block + * +- Lambda + * +- If + * +- Match + * +- Try + * +- Return + * +- Repeated + * +- Inlined + * +- SelectOuter + * +- While + * + * + * +- TypeTree ----+- Inferred + * | +- Ident + * | +- Select + * | +- Project + * | +- Singleton + * +- TypeOrBoundsTree ---+ +- Refined + * | +- Applied + * | +- Annotated + * | +- MatchType + * | +- ByName + * | +- LambdaTypeTree + * | +- TypeBind + * | +- TypeBlock + * | + * +- TypeBoundsTree + * +- WildcardTypeTree + * + * +- CaseDef + * +- TypeCaseDef + * + * +- Pattern --+- Value + * +- Bind + * +- Unapply + * +- Alternatives + * +- TypeTest + * + * + * +- NoPrefix + * +- TypeOrBounds -+- TypeBounds + * | + * +- Type -------+- ConstantType + * +- SymRef + * +- TermRef + * +- TypeRef + * +- SuperType + * +- Refinement + * +- AppliedType + * +- AnnotatedType + * +- AndType + * +- OrType + * +- MatchType + * +- ByNameType + * +- ParamRef + * +- ThisType + * +- RecursiveThis + * +- RecursiveType + * +- LambdaType[ParamInfo <: TypeOrBounds] -+- MethodType + * +- PolyType + * +- TypeLambda + * + * +- ImportSelector -+- SimpleSelector + * +- RenameSelector + * +- OmitSelector + * + * +- Id + * + * +- Signature + * + * +- Position + * + * +- Comment + * + * +- Constant + * + * +- Symbol --+- PackageSymbol + * +- ClassSymbol + * +- TypeSymbol + * +- DefSymbol + * +- ValSymbol + * +- BindSymbol + * +- NoSymbol + * + * +- Flags + * + * Aliases: + * # TermOrTypeTree = Term | TypeTree + * + * ``` + */ +trait Kernel { + + // + // CONTEXT + // + + /** Compilation context */ + type Context <: AnyRef + + // + // Settings + // + + /** Settings */ + type Settings <: AnyRef + + // + // TREES + // + + // TODO: When bootstrapped, remove and use `Term | TypeTree` type directly in other files + /** Workaround missing `|` types in Scala 2 to represent `Term | TypeTree` */ + type TermOrTypeTree /* Term | TypeTree */ <: AnyRef + + /** Tree representing code written in the source */ + type Tree <: AnyRef + + /** Tree representing a pacakage clause in the source code */ + type PackageClause <: Tree + + /** Tree representing a statement in the source code */ + type Statement <: Tree + + /** Tree representing an import in the source code */ + type Import <: Statement + + /** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef` */ + type Definition <: Statement + + /** Tree representing a package definition. This includes definitions in all source files */ + type PackageDef <: Definition + + /** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */ + type ClassDef <: Definition + + /** Tree representing a type (paramter or member) definition in the source code */ + type TypeDef <: Definition + + /** Tree representing a method definition in the source code */ + type DefDef <: Definition + + /** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */ + type ValDef <: Definition + + /** Tree representing an expression in the source code */ + type Term <: Statement + + /** Tree representing a reference to definition */ + type Term_Ref <: Term + + /** Tree representing a reference to definition with a given name */ + type Term_Ident <: Term_Ref + + /** Tree representing a selection of definition with a given name on a given prefix */ + type Term_Select <: Term_Ref + + /** Tree representing a literal value in the source code */ + type Term_Literal <: Term + + /** Tree representing `this` in the source code */ + type Term_This <: Term + + /** Tree representing `new` in the source code */ + type Term_New <: Term + + /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ + type Term_NamedArg <: Term + + /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ + type Term_Apply <: Term + + /** Tree an application of type arguments */ + type Term_TypeApply <: Term + + /** Tree representing `super` in the source code */ + type Term_Super <: Term + + /** Tree representing a type ascription `x: T` in the source code */ + type Term_Typed <: Term + + /** Tree representing an assignment `x = y` in the source code */ + type Term_Assign <: Term + + /** Tree representing a block `{ ... }` in the source code */ + type Term_Block <: Term + + /** Tree representing a lambda `(...) => ...` in the source code */ + type Term_Lambda <: Term + + /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ + type Term_If <: Term + + /** Tree representing a pattern match `x match { ... }` in the source code */ + type Term_Match <: Term + + /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ + type Term_Try <: Term + + /** Tree representing a `return` in the source code */ + type Term_Return <: Term + + /** Tree representing a variable argument list in the source code */ + type Term_Repeated <: Term + + /** Tree representing the scope of an inlined tree */ + type Term_Inlined <: Term + + /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ + type Term_SelectOuter <: Term + + /** Tree representing a while loop */ + type Term_While <: Term + + // + // CASES + // + + /** Branch of a pattern match or catch clause */ + type CaseDef <: AnyRef + + /** Branch of a type pattern match */ + type TypeCaseDef <: AnyRef + + // + // PATTERNS + // + + /** Pattern tree of the pattern part of a CaseDef */ + type Pattern <: AnyRef + + /** Pattern representing a value. This includes `1`, ```x``` and `_` */ + type Value <: Pattern + + /** Pattern representing a `_ @ _` binding. */ + type Bind <: Pattern + + /** Pattern representing a `Xyz(...)` unapply. */ + type Unapply <: Pattern + + /** Pattern representing `X | Y | ...` alternatives. */ + type Alternatives <: Pattern + + /** Pattern representing a `x: Y` type test. */ + type TypeTest <: Pattern + + // + // TYPE TREES + // + + /** Type tree representing a type or a bounds written in the source */ + type TypeOrBoundsTree <: AnyRef + + /** Type tree representing a type written in the source */ + type TypeTree <: TypeOrBoundsTree + + /** Type tree representing an inferred type */ + type TypeTree_Inferred <: TypeTree + + /** Type tree representing a reference to definition with a given name */ + type TypeTree_Ident <: TypeTree + + /** Type tree representing a selection of definition with a given name on a given term prefix */ + type TypeTree_Select <: TypeTree + + /** Type tree representing a selection of definition with a given name on a given type prefix */ + type TypeTree_Projection <: TypeTree + + /** Type tree representing a singleton type */ + type TypeTree_Singleton <: TypeTree + + /** Type tree representing a type refinement */ + type TypeTree_Refined <: TypeTree + + /** Type tree representing a type application */ + type TypeTree_Applied <: TypeTree + + /** Type tree representing an annotated type */ + type TypeTree_Annotated <: TypeTree + + /** Type tree representing a type match */ + type TypeTree_MatchType <: TypeTree + + /** Type tree representing a by name parameter */ + type TypeTree_ByName <: TypeTree + + /** Type tree representing a lambda abstraction type */ + type TypeTree_LambdaTypeTree <: TypeTree + + /** Type tree representing a type binding */ + type TypeTree_TypeBind <: TypeTree + + /** Type tree within a block with aliases `{ type U1 = ... ; T[U1, U2] }` */ + type TypeTree_TypeBlock <: TypeTree + + /** Type tree representing a type bound written in the source */ + type TypeBoundsTree <: TypeOrBoundsTree + + /** Type tree representing wildcard type bounds written in the source. + * The wildcard type `_` (for example in in `List[_]`) will be a type tree that + * represents a type but has `TypeBound`a inside. + */ + type WildcardType <: TypeOrBoundsTree + + // + // TYPES + // + + /** Type or bounds */ + type TypeOrBounds <: AnyRef + + /** NoPrefix for a type selection */ + type NoPrefix <: TypeOrBounds + + /** Type bounds */ + type TypeBounds <: TypeOrBounds + + /** A type */ + type Type <: TypeOrBounds + + /** A singleton type representing a known constant value */ + type ConstantType <: Type + + /** Type of a reference to a symbol */ + type SymRef <: Type + + /** Type of a reference to a term */ + type TermRef <: Type + + /** Type of a reference to a type */ + type TypeRef <: Type + + /** Type of a `super` refernce */ + type SuperType <: Type + + /** A type with a type refinement `T { type U }` */ + type Refinement <: Type + + /** A higher kinded type applied to some types `T[U]` */ + type AppliedType <: Type + + /** A type with an anottation `T @foo` */ + type AnnotatedType <: Type + + /** Intersection type `T & U` */ + type AndType <: Type + + /** Union type `T | U` */ + type OrType <: Type + + /** Type match `T match { case U => ... }` */ + type MatchType <: Type + + /** Type of a by by name parameter */ + type ByNameType <: Type + + /** Type of a parameter reference */ + type ParamRef <: Type + + /** Type of `this` */ + type ThisType <: Type + + /** A type that is recursively defined `this` */ + type RecursiveThis <: Type + + /** A type that is recursively defined */ + type RecursiveType <: Type + + // TODO can we add the bound back without an cake? + // TODO is LambdaType really needed? ParamRefExtractor could be split into more precise extractors + /** Common abstraction for lambda types (MethodType, PolyType and TypeLambda). */ + type LambdaType[ParamInfo /*<: TypeOrBounds*/] <: Type + + /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ + type MethodType <: LambdaType[Type] + + /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ + type PolyType <: LambdaType[TypeBounds] + + /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ + type TypeLambda <: LambdaType[TypeBounds] + + // + // IMPORT SELECTORS + // + + /** Import selectors: + * * SimpleSelector: `.bar` in `import foo.bar` + * * RenameSelector: `.{bar => baz}` in `import foo.{bar => baz}` + * * OmitSelector: `.{bar => _}` in `import foo.{bar => _}` + */ + type ImportSelector <: AnyRef + + // + // IDENTIFIERS + // + + /** Untyped identifier */ + type Id <: AnyRef + + // + // SIGNATURES + // + + /** JVM signature of a method */ + type Signature <: AnyRef + + // + // POSITIONS + // + + /** Source position */ + type Position <: AnyRef + + // + // COMMENTS + // + + /** Comment */ + type Comment <: AnyRef + + // + // CONSTANTS + // + + /** Constant value represented as the constant itself */ + type Constant <: AnyRef + + // + // SYMBOLS + // + + /** Symbol of a definition. + * Then can be compared with == to know if the definition is the same. + */ + type Symbol <: AnyRef + + /** Symbol of a package definition */ + type PackageSymbol <: Symbol + + /** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */ + type ClassSymbol <: Symbol + + /** Symbol of a type (parameter or member) definition. */ + type TypeSymbol <: Symbol + + /** Symbol representing a method definition. */ + type DefSymbol <: Symbol + + /** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */ + type ValSymbol <: Symbol + + /** Symbol representing a bind definition. */ + type BindSymbol <: Symbol + + /** No symbol available. */ + type NoSymbol <: Symbol + + // + // FLAGS + // + + /** FlagSet of a Symbol */ + type Flags + +} From 0603c94698fd614ae9f949b85b8092f976e6ed75 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 27 Feb 2019 09:34:13 +0100 Subject: [PATCH 02/17] Implement extension method in kernel --- .../dotc/tastyreflect/CaseDefOpsImpl.scala | 11 - .../dotc/tastyreflect/ConstantOpsImpl.scala | 4 - .../dotc/tastyreflect/ContextOpsImpl.scala | 6 - .../dotc/tastyreflect/FlagsOpsImpl.scala | 48 -- .../tools/dotc/tastyreflect/IdOpsImpl.scala | 5 - .../tools/dotc/tastyreflect/KernelImpl.scala | 612 +++++++++++++++++- .../dotc/tastyreflect/PatternOpsImpl.scala | 28 +- .../dotc/tastyreflect/PositionOpsImpl.scala | 16 - .../dotc/tastyreflect/QuotedOpsImpl.scala | 45 -- .../dotc/tastyreflect/SignatureOpsImpl.scala | 5 - .../dotc/tastyreflect/SymbolOpsImpl.scala | 93 --- .../tools/dotc/tastyreflect/TreeOpsImpl.scala | 184 ------ .../tastyreflect/TypeOrBoundsOpsImpl.scala | 127 ---- .../TypeOrBoundsTreesOpsImpl.scala | 79 --- .../src/scala/tasty/reflect/CaseDefOps.scala | 16 +- .../src/scala/tasty/reflect/ConstantOps.scala | 5 +- .../src/scala/tasty/reflect/ContextOps.scala | 9 +- .../src/scala/tasty/reflect/FlagsOps.scala | 84 +-- library/src/scala/tasty/reflect/IdOps.scala | 11 +- library/src/scala/tasty/reflect/Kernel.scala | 406 ++++++++++++ .../src/scala/tasty/reflect/PatternOps.scala | 50 +- .../src/scala/tasty/reflect/PositionOps.scala | 31 +- .../src/scala/tasty/reflect/QuotedOps.scala | 24 +- .../scala/tasty/reflect/SignatureOps.scala | 14 +- .../src/scala/tasty/reflect/SymbolOps.scala | 73 ++- library/src/scala/tasty/reflect/TreeOps.scala | 328 +++++----- .../scala/tasty/reflect/TypeOrBoundsOps.scala | 254 +++----- .../tasty/reflect/TypeOrBoundsTreeOps.scala | 161 ++--- 28 files changed, 1506 insertions(+), 1223 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala index 60b566c9fae8..6abc3bf708fb 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala @@ -4,12 +4,6 @@ import dotty.tools.dotc.ast.tpd trait CaseDefOpsImpl extends scala.tasty.reflect.CaseDefOps with CoreImpl with Helpers { - def CaseDefDeco(caseDef: CaseDef): CaseDefAPI = new CaseDefAPI { - def pattern(implicit ctx: Context): Pattern = caseDef.pat - def guard(implicit ctx: Context): Option[Term] = optional(caseDef.guard) - def rhs(implicit ctx: Context): Term = caseDef.body - } - object CaseDef extends CaseDefModule { def apply(pattern: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef = tpd.CaseDef(pattern, guard.getOrElse(tpd.EmptyTree), body) @@ -20,11 +14,6 @@ trait CaseDefOpsImpl extends scala.tasty.reflect.CaseDefOps with CoreImpl with H def unapply(x: CaseDef): Some[(Pattern, Option[Term], Term)] = Some(x.pat, optional(x.guard), x.body) } - def TypeCaseDefDeco(caseDef: TypeCaseDef): TypeCaseDefAPI = new TypeCaseDefAPI { - def pattern(implicit ctx: Context): Pattern = caseDef.pat - def rhs(implicit ctx: Context): Term = caseDef.body - } - object TypeCaseDef extends TypeCaseDefModule { def apply(pattern: TypeTree, body: TypeTree)(implicit ctx: Context): TypeCaseDef = tpd.CaseDef(pattern, tpd.EmptyTree, body) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala index b467f60d04ce..7c2c50a651c9 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala @@ -5,10 +5,6 @@ import dotty.tools.dotc.core.Constants trait ConstantOpsImpl extends scala.tasty.reflect.ConstantOps with CoreImpl { - def ConstantDeco(const: Constant): ConstantAPI = new ConstantAPI { - def value: Any = const.value - } - object Constant extends ConstantModule { object Unit extends UnitModule { diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala index 256389aa4aa6..16e296e183db 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala @@ -4,10 +4,4 @@ trait ContextOpsImpl extends scala.tasty.reflect.ContextOps with CoreImpl { val rootContext: Context - def ContextDeco(ctx: Context): ContextAPI = new ContextAPI { - def owner: Symbol = ctx.owner - - def source: java.nio.file.Path = ctx.compilationUnit.source.file.jpath - } - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala index ce422cd4a376..aaa28cb4ecc2 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala @@ -1,54 +1,6 @@ package dotty.tools.dotc package tastyreflect -import dotty.tools.dotc.core.Decorators._ - -import scala.tasty.reflect - trait FlagsOpsImpl extends scala.tasty.reflect.FlagsOps with CoreImpl { - def FlagsDeco(flagSet: Flags): FlagsAPI = new FlagsAPI { - def is(that: Flags): Boolean = flagSet is that - def |(that: Flags): Flags = flagSet | that - def &(that: Flags): Flags = flagSet & that - } - - object Flags extends FlagsModule { - def Private: Flags = core.Flags.Private - def Protected: Flags = core.Flags.Protected - def Abstract: Flags = core.Flags.Abstract - def Final: Flags = core.Flags.Final - def Sealed: Flags = core.Flags.Sealed - def Case: Flags = core.Flags.Case - def Implicit: Flags = core.Flags.Implicit - def Implied = core.Flags.Implied - def Erased: Flags = core.Flags.Erased - def Lazy: Flags = core.Flags.Lazy - def Override: Flags = core.Flags.Override - def Inline: Flags = core.Flags.Inline - def Macro: Flags = core.Flags.Macro - def Static: Flags = core.Flags.JavaStatic - def JavaDefined: Flags = core.Flags.JavaDefined - def Object: Flags = core.Flags.Module - def Trait: Flags = core.Flags.Trait - def Local: Flags = core.Flags.Local - def Synthetic: Flags = core.Flags.Synthetic - def Artifact: Flags = core.Flags.Artifact - def Mutable: Flags = core.Flags.Mutable - def FieldAccessor: Flags = core.Flags.Accessor - def CaseAcessor: Flags = core.Flags.CaseAccessor - def Covariant: Flags = core.Flags.Covariant - def Contravariant: Flags = core.Flags.Contravariant - def Scala2X: Flags = core.Flags.Scala2x - def DefaultParameterized: Flags = core.Flags.DefaultParameterized - def StableRealizable: Flags = core.Flags.StableRealizable - def Param: Flags = core.Flags.Param - def ParamAccessor: Flags = core.Flags.ParamAccessor - def Enum: Flags = core.Flags.Enum - def ModuleClass: Flags = core.Flags.ModuleClass - def PrivateLocal: Flags = core.Flags.PrivateLocal - def Package: Flags = core.Flags.Package - def ImplClass: Flags = core.Flags.ImplClass - } - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala index 17330bae1a6b..c85a8667020c 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala @@ -4,11 +4,6 @@ import dotty.tools.dotc.core.Decorators._ trait IdOpsImpl extends scala.tasty.reflect.IdOps with CoreImpl { - def IdDeco(id: Id): IdAPI = new IdAPI { - def pos(implicit ctx: Context): Position = id.sourcePos - def name(implicit ctx: Context): String = id.name.toString - } - object Id extends IdModule { def unapply(id: Id): Option[String] = Some(id.name.toString) } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index f2c86ef7f4fa..6f18cb91669f 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -1,120 +1,620 @@ package dotty.tools.dotc package tastyreflect -import dotty.tools.dotc.ast.{tpd, untpd} -import dotty.tools.dotc.core.Constants -import dotty.tools.dotc.core.Types +import dotty.tools.dotc.ast.{Trees, tpd, untpd} +import dotty.tools.dotc.ast.tpd.TreeOps +import dotty.tools.dotc.core.{Constants, NameKinds, Types} +import dotty.tools.dotc.core.Flags._ +import dotty.tools.dotc.core.StdNames.nme +import dotty.tools.dotc.core.quoted.PickledQuotes +import dotty.tools.dotc.core.Symbols._ +import dotty.tools.dotc.core.Decorators._ +import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFromSym} import scala.tasty.reflect.Kernel class KernelImpl extends Kernel { + + // + // CONTEXT + // + type Context = core.Contexts.Context + def Context_owner(self: Context): Symbol = self.owner + + def Context_source(self: Context): java.nio.file.Path = self.compilationUnit.source.file.jpath + + // + // Settings + // + type Settings = config.ScalaSettings + // + // TREES + // + type TermOrTypeTree = tpd.Tree type Tree = tpd.Tree + + def Tree_pos(self: Tree)(implicit ctx: Context): Position = self.sourcePos + def Tree_symbol(self: Tree)(implicit ctx: Context): Symbol = self.symbol + type PackageClause = tpd.PackageDef + + def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Term_Ref = self.pid + def PackageClause_stats(self: PackageClause)(implicit ctx: Context): List[Tree] = self.stats + type Statement = tpd.Tree + type Import = tpd.Import + + def Import_impliedOnly(self: Import): Boolean = self.impliedOnly + def Import_expr(self: Import)(implicit ctx: Context): Tree = self.expr + def Import_selectors(self: Import)(implicit ctx: Context): List[ImportSelector] = self.selectors + type Definition = tpd.Tree + + def Definition_name(self: Definition)(implicit ctx: Context): String = self.symbol.name.toString + type PackageDef = PackageDefinition + + def PackageDef_owner(self: PackageDef)(implicit ctx: Context): PackageDef = packageDefFromSym(self.symbol.owner) + + def PackageDef_members(self: PackageDef)(implicit ctx: Context): List[Statement] = { + if (self.symbol.is(core.Flags.JavaDefined)) Nil // FIXME should also support java packages + else self.symbol.info.decls.iterator.map(definitionFromSym).toList + } + + def PackageDef_symbol(self: PackageDef)(implicit ctx: Context): PackageSymbol = self.symbol + type ClassDef = tpd.TypeDef + + def ClassDef_constructor(self: ClassDef)(implicit ctx: Context): DefDef = ClassDef_rhs(self).constr + def ClassDef_parents(self: ClassDef)(implicit ctx: Context): List[TermOrTypeTree] = ClassDef_rhs(self).parents + def ClassDef_derived(self: ClassDef)(implicit ctx: Context): List[TypeTree] = ClassDef_rhs(self).derived.asInstanceOf[List[TypeTree]] + def ClassDef_self(self: ClassDef)(implicit ctx: Context): Option[ValDef] = optional(ClassDef_rhs(self).self) + def ClassDef_body(self: ClassDef)(implicit ctx: Context): List[Statement] = ClassDef_rhs(self).body + def ClassDef_symbol(self: ClassDef)(implicit ctx: Context): ClassSymbol = self.symbol.asClass + private def ClassDef_rhs(self: ClassDef) = self.rhs.asInstanceOf[tpd.Template] + type TypeDef = tpd.TypeDef + + def TypeDef_rhs(self: TypeDef)(implicit ctx: Context): TypeOrBoundsTree = self.rhs + def TypeDef_symbol(self: TypeDef)(implicit ctx: Context): TypeSymbol = self.symbol.asType + type DefDef = tpd.DefDef + + def DefDef_typeParams(self: DefDef)(implicit ctx: Context): List[TypeDef] = self.tparams + def DefDef_paramss(self: DefDef)(implicit ctx: Context): List[List[ValDef]] = self.vparamss + def DefDef_returnTpt(self: DefDef)(implicit ctx: Context): TypeTree = self.tpt + def DefDef_rhs(self: DefDef)(implicit ctx: Context): Option[Tree] = optional(self.rhs) + def DefDef_symbol(self: DefDef)(implicit ctx: Context): DefSymbol = self.symbol.asTerm + type ValDef = tpd.ValDef + + def ValDef_tpt(self: ValDef)(implicit ctx: Context): TypeTree = self.tpt + def ValDef_rhs(self: ValDef)(implicit ctx: Context): Option[Tree] = optional(self.rhs) + def ValDef_symbol(self: ValDef)(implicit ctx: Context): ValSymbol = self.symbol.asTerm + type Term = tpd.Tree + + def Term_pos(self: Term)(implicit ctx: Context): Position = self.sourcePos + def Term_tpe(self: Term)(implicit ctx: Context): Type = self.tpe + def Term_underlyingArgument(self: Term)(implicit ctx: Context): Term = self.underlyingArgument + def Term_underlying(self: Term)(implicit ctx: Context): Term = self.underlying + type Term_Ref = tpd.RefTree + type Term_Ident = tpd.Ident + + def Term_Ident_name(self: Term_Ident)(implicit ctx: Context): String = self.name.show + type Term_Select = tpd.Select + + def Term_Select_qualifier(self: Term_Select)(implicit ctx: Context): Term = self.qualifier + def Term_Select_name(self: Term_Select)(implicit ctx: Context): String = self.name.toString + def Term_Select_signature(self: Term_Select)(implicit ctx: Context): Option[Signature] = + if (self.symbol.signature == core.Signature.NotAMethod) None + else Some(self.symbol.signature) + type Term_Literal = tpd.Literal + + def Term_Literal_constant(self: Term_Literal)(implicit ctx: Context): Constant = self.const + type Term_This = tpd.This + + def Term_This_id(self: Term_This)(implicit ctx: Context): Option[Id] = optional(self.qual) + type Term_New = tpd.New + + def Term_New_tpt(self: Term_New)(implicit ctx: Context): TypeTree = self.tpt + type Term_NamedArg = tpd.NamedArg + + def Term_NamedArg_name(self: Term_NamedArg)(implicit ctx: Context): String = self.name.toString + def Term_NamedArg_value(self: Term_NamedArg)(implicit ctx: Context): Term = self.arg + type Term_Apply = tpd.Apply + + def Term_Apply_fun(self: Term_Apply)(implicit ctx: Context): Term = self.fun + def Term_Apply_args(self: Term_Apply)(implicit ctx: Context): List[Term] = self.args + type Term_TypeApply = tpd.TypeApply + + def Term_TypeApply_fun(self: Term_TypeApply)(implicit ctx: Context): Term = self.fun + def Term_TypeApply_args(self: Term_TypeApply)(implicit ctx: Context): List[TypeTree] = self.args + type Term_Super = tpd.Super + + def Term_Super_qualifier(self: Term_Super)(implicit ctx: Context): Term = self.qual + def Term_Super_id(self: Term_Super)(implicit ctx: Context): Option[Id] = optional(self.mix) + type Term_Typed = tpd.Typed + + def Term_Typed_expr(self: Term_Typed)(implicit ctx: Context): Term = self.expr + def Term_Typed_tpt(self: Term_Typed)(implicit ctx: Context): TypeTree = self.tpt + type Term_Assign = tpd.Assign + + def Term_Assign_lhs(self: Term_Assign)(implicit ctx: Context): Term = self.lhs + def Term_Assign_rhs(self: Term_Assign)(implicit ctx: Context): Term = self.rhs + type Term_Block = tpd.Block + + def Term_Block_statements(self: Term_Block)(implicit ctx: Context): List[Statement] = self.stats + def Term_Block_expr(self: Term_Block)(implicit ctx: Context): Term = self.expr + + type Term_Inlined = tpd.Inlined + + def Term_Inlined_call(self: Term_Inlined)(implicit ctx: Context): Option[TermOrTypeTree] = optional(self.call) + def Term_Inlined_bindings(self: Term_Inlined)(implicit ctx: Context): List[Definition] = self.bindings + def Term_Inlined_body(self: Term_Inlined)(implicit ctx: Context): Term = self.expansion + type Term_Lambda = tpd.Closure + + def Term_Lambda_meth(self: Term_Lambda)(implicit ctx: Context): Term = self.meth + def Term_Lambda_tptOpt(self: Term_Lambda)(implicit ctx: Context): Option[TypeTree] = optional(self.tpt) + type Term_If = tpd.If + + def Term_If_cond(self: Term_If)(implicit ctx: Context): Term = self.cond + def Term_If_thenp(self: Term_If)(implicit ctx: Context): Term = self.thenp + def Term_If_elsep(self: Term_If)(implicit ctx: Context): Term = self.elsep + type Term_Match = tpd.Match + + def Term_Match_scrutinee(self: Term_Match)(implicit ctx: Context): Term = self.selector + def Term_Match_cases(self: Term_Match)(implicit ctx: Context): List[CaseDef] = self.cases + type Term_Try = tpd.Try + + def Term_Try_body(self: Term_Try)(implicit ctx: Context): Term = self.expr + def Term_Try_cases(self: Term_Try)(implicit ctx: Context): List[CaseDef] = self.cases + def Term_Try_finalizer(self: Term_Try)(implicit ctx: Context): Option[Term] = optional(self.finalizer) + type Term_Return = tpd.Return + + def Term_Return_expr(self: Term_Return)(implicit ctx: Context): Term = self.expr + type Term_Repeated = tpd.SeqLiteral - type Term_Inlined = tpd.Inlined + + def Term_Repeated_elems(self: Term_Repeated)(implicit ctx: Context): List[Term] = self.elems + def Term_Repeated_elemtpt(self: Term_Repeated)(implicit ctx: Context): TypeTree = self.elemtpt + type Term_SelectOuter = tpd.Select + + def Term_SelectOuter_qualifier(self: Term_SelectOuter)(implicit ctx: Context): Term = self.qualifier + def Term_SelectOuter_level(self: Term_SelectOuter)(implicit ctx: Context): Int = { + val NameKinds.OuterSelectName(_, levels) = self.name + levels + } + def Term_SelectOuter_tpe(self: Term_SelectOuter)(implicit ctx: Context): Type = self.tpe.stripTypeVar + type Term_While = tpd.WhileDo + def Term_While_cond(self: Term_While)(implicit ctx: Context): Term = self.cond + def Term_While_body(self: Term_While)(implicit ctx: Context): Term = self.body + + // + // CASES + // + type CaseDef = tpd.CaseDef + + def CaseDef_pattern(self: CaseDef)(implicit ctx: Context): Pattern = self.pat + def CaseDef_guard(self: CaseDef)(implicit ctx: Context): Option[Term] = optional(self.guard) + def CaseDef_rhs(self: CaseDef)(implicit ctx: Context): Term = self.body + type TypeCaseDef = tpd.CaseDef + def TypeCaseDef_pattern(self: TypeCaseDef)(implicit ctx: Context): TypeTree = self.pat + def TypeCaseDef_rhs(self: TypeCaseDef)(implicit ctx: Context): TypeTree = self.body + + // + // PATTERNS + // + type Pattern = tpd.Tree type Value = tpd.Tree + + def Pattern_Value_value(self: Value)(implicit ctx: Context): Term = self + type Bind = tpd.Bind + + def Pattern_Bind_name(self: Bind)(implicit ctx: Context): String = self.name.toString + + def Pattern_Bind_pattern(self: Bind)(implicit ctx: Context): Pattern = self.body + type Unapply = tpd.UnApply + + def Pattern_Unapply_fun(self: Unapply)(implicit ctx: Context): Term = self.fun + def Pattern_Unapply_implicits(self: Unapply)(implicit ctx: Context): List[Term] = self.implicits + def Pattern_Unapply_patterns(self: Unapply)(implicit ctx: Context): List[Pattern] = effectivePatterns(self.patterns) + + private def effectivePatterns(patterns: List[Pattern]): List[Pattern] = patterns match { + case patterns0 :+ Trees.SeqLiteral(elems, _) => patterns0 ::: elems + case _ => patterns + } + type Alternatives = tpd.Alternative + + def Pattern_Alternatives_patterns(self: Alternatives)(implicit ctx: Context): List[Pattern] = self.trees + type TypeTest = tpd.Typed + def Pattern_TypeTest_tpt(self: TypeTest)(implicit ctx: Context): TypeTree = self.tpt + + // + // TYPE TREES + // + type TypeOrBoundsTree = tpd.Tree + + def TypeOrBoundsTree_tpe(self: TypeOrBoundsTree)(implicit ctx: Context): Type = self.tpe.stripTypeVar + type TypeTree = tpd.Tree + + def TypeTree_pos(self: TypeTree)(implicit ctx: Context): Position = self.sourcePos + def TypeTree_symbol(self: TypeTree)(implicit ctx: Context): Symbol = self.symbol + def TypeTree_tpe(self: TypeTree)(implicit ctx: Context): Type = self.tpe.stripTypeVar + type TypeTree_Inferred = tpd.TypeTree + type TypeTree_Ident = tpd.Ident + + def TypeTree_Ident_name(self: TypeTree_Ident)(implicit ctx: Context): String = self.name.toString + type TypeTree_Select = tpd.Select + + def TypeTree_Select_qualifier(self: TypeTree_Select)(implicit ctx: Context): Term = self.qualifier + def TypeTree_Select_name(self: TypeTree_Select)(implicit ctx: Context): String = self.name.toString + type TypeTree_Projection = tpd.Select + + def TypeTree_Projection_qualifier(self: TypeTree_Projection)(implicit ctx: Context): TypeTree = self.qualifier + def TypeTree_Projection_name(self: TypeTree_Projection)(implicit ctx: Context): String = self.name.toString + type TypeTree_Singleton = tpd.SingletonTypeTree + + def TypeTree_Singleton_ref(self: TypeTree_Singleton)(implicit ctx: Context): Term = self.ref + type TypeTree_Refined = tpd.RefinedTypeTree + + def TypeTree_Refined_tpt(self: TypeTree_Refined)(implicit ctx: Context): TypeTree = self.tpt + def TypeTree_Refined_refinements(self: TypeTree_Refined)(implicit ctx: Context): List[Definition] = self.refinements + type TypeTree_Applied = tpd.AppliedTypeTree + + def TypeTree_Applied_tpt(self: TypeTree_Applied)(implicit ctx: Context): TypeTree = self.tpt + def TypeTree_Applied_args(self: TypeTree_Applied)(implicit ctx: Context): List[TypeOrBoundsTree] = self.args + type TypeTree_Annotated = tpd.Annotated + + def TypeTree_Annotated_arg(self: TypeTree_Annotated)(implicit ctx: Context): TypeTree = self.arg + def TypeTree_Annotated_annotation(self: TypeTree_Annotated)(implicit ctx: Context): Term = self.annot + type TypeTree_MatchType = tpd.MatchTypeTree + + def TypeTree_MatchType_bound(self: TypeTree_MatchType)(implicit ctx: Context): Option[TypeTree] = if (self.bound == tpd.EmptyTree) None else Some(self.bound) + def TypeTree_MatchType_selector(self: TypeTree_MatchType)(implicit ctx: Context): TypeTree = self.selector + def TypeTree_MatchType_cases(self: TypeTree_MatchType)(implicit ctx: Context): List[CaseDef] = self.cases + type TypeTree_ByName = tpd.ByNameTypeTree + + def TypeTree_ByName_result(self: TypeTree_ByName)(implicit ctx: Context): TypeTree = self.result + type TypeTree_LambdaTypeTree = tpd.LambdaTypeTree + + def TypeTree_LambdaTypeTree_tparams(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): List[TypeDef] = self.tparams + def TypeTree_LambdaTypeTree_body(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): TypeOrBoundsTree = self.body + type TypeTree_TypeBind = tpd.Bind + + def TypeTree_TypeBind_name(self: TypeTree_TypeBind)(implicit ctx: Context): String = self.name.toString + def TypeTree_TypeBind_body(self: TypeTree_TypeBind)(implicit ctx: Context): TypeOrBoundsTree = self.body + type TypeTree_TypeBlock = tpd.Block + def TypeTree_TypeBlock_aliases(self: TypeTree_TypeBlock)(implicit ctx: Context): List[TypeDef] = self.stats.map { case alias: TypeDef => alias } + def TypeTree_TypeBlock_tpt(self: TypeTree_TypeBlock)(implicit ctx: Context): TypeTree = self.expr + type TypeBoundsTree = tpd.TypeBoundsTree + + def TypeBoundsTree_tpe(self: TypeBoundsTree)(implicit ctx: Context): TypeBounds = self.tpe.asInstanceOf[Types.TypeBounds] + def TypeBoundsTree_low(self: TypeBoundsTree)(implicit ctx: Context): TypeTree = self.lo + def TypeBoundsTree_hi(self: TypeBoundsTree)(implicit ctx: Context): TypeTree = self.hi + type WildcardType = tpd.TypeTree + // + // TYPES + // + type TypeOrBounds = Types.Type + type NoPrefix = Types.NoPrefix.type + type TypeBounds = Types.TypeBounds + + def TypeBounds_low(self: TypeBounds)(implicit ctx: Context): Type = self.lo + def TypeBounds_hi(self: TypeBounds)(implicit ctx: Context): Type = self.hi + type Type = Types.Type + + def `Type_=:=`(self: Type)(that: Type)(implicit ctx: Context): Boolean = self =:= that + + def `Type_<:<`(self: Type)(that: Type)(implicit ctx: Context): Boolean = self <:< that + + /** Widen from singleton type to its underlying non-singleton + * base type by applying one or more `underlying` dereferences, + * Also go from => T to T. + * Identity for all other types. Example: + * + * class Outer { class C ; val x: C } + * def o: Outer + * .widen = o.C + */ + def Type_widen(self: Type)(implicit ctx: Context): Type = self.widen + + def Type_classSymbol(self: Type)(implicit ctx: Context): Option[ClassSymbol] = + if (self.classSymbol.exists) Some(self.classSymbol.asClass) else None + + def Type_typeSymbol(self: Type)(implicit ctx: Context): Symbol = self.typeSymbol + + def Type_isSingleton(self: Type)(implicit ctx: Context): Boolean = self.isSingleton + + def Type_memberType(self: Type)(member: Symbol)(implicit ctx: Context): Type = + member.info.asSeenFrom(self, member.owner) + type ConstantType = Types.ConstantType + + def ConstantType_value(self: ConstantType)(implicit ctx: Context): Any = self.value + type SymRef = Types.NamedType + + def SymRef_qualifier(self: SymRef)(implicit ctx: Context): TypeOrBounds = self.prefix + type TermRef = Types.NamedType + + def TermRef_qualifier(self: TermRef)(implicit ctx: Context): TypeOrBounds = self.prefix + type TypeRef = Types.NamedType + + def TypeRef_name(self: TypeRef)(implicit ctx: Context): String = self.name.toString + def TypeRef_qualifier(self: TypeRef)(implicit ctx: Context): TypeOrBounds = self.prefix + type SuperType = Types.SuperType + + def SuperType_thistpe(self: SuperType)(implicit ctx: Context): Type = self.thistpe + def SuperType_supertpe(self: SuperType)(implicit ctx: Context): Type = self.supertpe + type Refinement = Types.RefinedType + + def Refinement_parent(self: Refinement)(implicit ctx: Context): Type = self.parent + def Refinement_name(self: Refinement)(implicit ctx: Context): String = self.refinedName.toString + def Refinement_info(self: Refinement)(implicit ctx: Context): TypeOrBounds = self.refinedInfo + type AppliedType = Types.AppliedType + + def AppliedType_tycon(self: AppliedType)(implicit ctx: Context): Type = self.tycon + def AppliedType_args(self: AppliedType)(implicit ctx: Context): List[TypeOrBounds] = self.args + type AnnotatedType = Types.AnnotatedType + + def AnnotatedType_underlying(self: AnnotatedType)(implicit ctx: Context): Type = self.underlying.stripTypeVar + def AnnotatedType_annot(self: AnnotatedType)(implicit ctx: Context): Term = self.annot.tree + type AndType = Types.AndType + + def AndType_left(self: AndType)(implicit ctx: Context): Type = self.tp1.stripTypeVar + def AndType_right(self: AndType)(implicit ctx: Context): Type = self.tp2.stripTypeVar + type OrType = Types.OrType + + def OrType_left(self: OrType)(implicit ctx: Context): Type = self.tp1.stripTypeVar + def OrType_right(self: OrType)(implicit ctx: Context): Type = self.tp2.stripTypeVar + type MatchType = Types.MatchType + + def MatchType_bound(self: MatchType)(implicit ctx: Context): Type = self.bound + def MatchType_scrutinee(self: MatchType)(implicit ctx: Context): Type = self.scrutinee + def MatchType_cases(self: MatchType)(implicit ctx: Context): List[Type] = self.cases + type ByNameType = Types.ExprType + + def ByNameType_underlying(self: ByNameType)(implicit ctx: Context): Type = self.resType.stripTypeVar + type ParamRef = Types.ParamRef + + def ParamRef_binder(self: ParamRef)(implicit ctx: Context): LambdaType[TypeOrBounds] = + self.binder.asInstanceOf[LambdaType[TypeOrBounds]] // Cast to tpd + def ParamRef_paramNum(self: ParamRef)(implicit ctx: Context): Int = self.paramNum + type ThisType = Types.ThisType + + def ThisType_underlying(self: ThisType)(implicit ctx: Context): Type = self.underlying + type RecursiveThis = Types.RecThis + + def RecursiveThis_binder(self: RecursiveThis)(implicit ctx: Context): RecursiveType = self.binder + type RecursiveType = Types.RecType + + def RecursiveType_underlying(self: RecursiveType)(implicit ctx: Context): Type = self.underlying.stripTypeVar + type LambdaType[ParamInfo] = Types.LambdaType { type PInfo = ParamInfo } + type MethodType = Types.MethodType + + def MethodType_isErased(self: MethodType): Boolean = self.isErasedMethod + def MethodType_isImplicit(self: MethodType): Boolean = self.isImplicitMethod + def MethodType_paramNames(self: MethodType)(implicit ctx: Context): List[String] = self.paramNames.map(_.toString) + def MethodType_paramTypes(self: MethodType)(implicit ctx: Context): List[Type] = self.paramInfos + def MethodType_resType(self: MethodType)(implicit ctx: Context): Type = self.resType + type PolyType = Types.PolyType + + def PolyType_paramNames(self: PolyType)(implicit ctx: Context): List[String] = self.paramNames.map(_.toString) + def PolyType_paramBounds(self: PolyType)(implicit ctx: Context): List[TypeBounds] = self.paramInfos + def PolyType_resType(self: PolyType)(implicit ctx: Context): Type = self.resType + type TypeLambda = Types.TypeLambda + def TypeLambda_paramNames(self: TypeLambda)(implicit ctx: Context): List[String] = self.paramNames.map(_.toString) + def TypeLambda_paramBounds(self: TypeLambda)(implicit ctx: Context): List[TypeBounds] = self.paramInfos + def TypeLambda_resType(self: TypeLambda)(implicit ctx: Context): Type = self.resType + + // + // IMPORT SELECTORS + // + type ImportSelector = untpd.Tree + // + // IDENTIFIERS + // + type Id = untpd.Ident + def Id_pos(self: Id)(implicit ctx: Context): Position = self.sourcePos + + def Id_name(self: Id)(implicit ctx: Context): String = self.name.toString + + // + // SIGNATURES + // + type Signature = core.Signature + def Signature_paramSigs(self: Signature): List[String] = + self.paramsSig.map(_.toString) + + def Signature_resultSig(self: Signature): String = + self.resSig.toString + + // + // POSITIONS + // + type Position = util.SourcePosition + def Position_start(self: Position): Int = self.start + + def Position_end(self: Position): Int = self.end + + def Position_exists(self: Position): Boolean = self.exists + + def Position_sourceFile(self: Position): java.nio.file.Path = self.source.file.jpath + + def Position_startLine(self: Position): Int = self.startLine + + def Position_endLine(self: Position): Int = self.endLine + + def Position_startColumn(self: Position): Int = self.startColumn + + def Position_endColumn(self: Position): Int = self.endColumn + + def Position_sourceCode(self: Position): String = + new String(self.source.content(), self.start, self.end - self.start) + + // + // COMMENTS + // + type Comment = core.Comments.Comment + // + // CONSTANTS + // + type Constant = Constants.Constant + final def Constant_value(const: Constant): Any = const.value + + // + // SYMBOLS + // + type Symbol = core.Symbols.Symbol + + def Symbol_owner(self: Symbol)(implicit ctx: Context): Symbol = self.owner + + def Symbol_flags(self: Symbol)(implicit ctx: Context): Flags = self.flags + + + def Symbol_privateWithin(self: Symbol)(implicit ctx: Context): Option[Type] = { + val within = self.privateWithin + if (within.exists && !self.is(core.Flags.Protected)) Some(within.typeRef) + else None + } + + def Symbol_protectedWithin(self: Symbol)(implicit ctx: Context): Option[Type] = { + val within = self.privateWithin + if (within.exists && self.is(core.Flags.Protected)) Some(within.typeRef) + else None + } + + def Symbol_name(self: Symbol)(implicit ctx: Context): String = self.name.toString + + def Symbol_fullName(self: Symbol)(implicit ctx: Context): String = self.fullName.toString + + def Symbol_pos(self: Symbol)(implicit ctx: Context): Position = self.sourcePos + + def Symbol_localContext(self: Symbol)(implicit ctx: Context): Context = { + if (self.exists) ctx.withOwner(self) + else ctx + } + + def Symbol_comment(self: Symbol)(implicit ctx: Context): Option[Comment] = { + import dotty.tools.dotc.core.Comments.CommentsContext + val docCtx = ctx.docCtx.getOrElse { + throw new RuntimeException( + "DocCtx could not be found and comments are unavailable. This is a compiler-internal error." + ) + } + docCtx.docstring(self) + } + def Symbol_annots(self: Symbol)(implicit ctx: Context): List[Term] = { + self.annotations.flatMap { + case _: core.Annotations.LazyBodyAnnotation => Nil + case annot => annot.tree :: Nil + } + } + + def Symbol_isDefinedInCurrentRun(self: Symbol)(implicit ctx: Context): Boolean = + self.topLevelClass.asClass.isDefinedInCurrentRun + + def Symbol_isLocalDummy(self: Symbol)(implicit ctx: Context): Boolean = self.isLocalDummy + def Symbol_isRefinementClass(self: Symbol)(implicit ctx: Context): Boolean = self.isRefinementClass + def Symbol_isAliasType(self: Symbol)(implicit ctx: Context): Boolean = self.isAliasType + def Symbol_isAnonymousClass(self: Symbol)(implicit ctx: Context): Boolean = self.isAnonymousClass + def Symbol_isAnonymousFunction(self: Symbol)(implicit ctx: Context): Boolean = self.isAnonymousFunction + def Symbol_isAbstractType(self: Symbol)(implicit ctx: Context): Boolean = self.isAbstractType + def Symbol_isClassConstructor(self: Symbol)(implicit ctx: Context): Boolean = self.isClassConstructor + type PackageSymbol = core.Symbols.Symbol type ClassSymbol = core.Symbols.ClassSymbol type TypeSymbol = core.Symbols.TypeSymbol @@ -123,5 +623,109 @@ class KernelImpl extends Kernel { type ValSymbol = core.Symbols.TermSymbol type NoSymbol = core.Symbols.NoSymbol.type + // + // FLAGS + // + type Flags = core.Flags.FlagSet + + /** Is the given flag set a subset of this flag sets */ + def Flags_is(self: Flags)(that: Flags): Boolean = self.is(that) + + /** Union of the two flag sets */ + def Flags_or(self: Flags)(that: Flags): Flags = self | that + + /** Intersection of the two flag sets */ + def Flags_and(self: Flags)(that: Flags): Flags = self & that + + def Flags_Private: Flags = core.Flags.Private + def Flags_Protected: Flags = core.Flags.Protected + def Flags_Abstract: Flags = core.Flags.Abstract + def Flags_Final: Flags = core.Flags.Final + def Flags_Sealed: Flags = core.Flags.Sealed + def Flags_Case: Flags = core.Flags.Case + def Flags_Implicit: Flags = core.Flags.Implicit + def Flags_Implied: Flags = core.Flags.Implied + def Flags_Erased: Flags = core.Flags.Erased + def Flags_Lazy: Flags = core.Flags.Lazy + def Flags_Override: Flags = core.Flags.Override + def Flags_Inline: Flags = core.Flags.Inline + def Flags_Macro: Flags = core.Flags.Macro + def Flags_Static: Flags = core.Flags.JavaStatic + def Flags_JavaDefined: Flags = core.Flags.JavaDefined + def Flags_Object: Flags = core.Flags.Module + def Flags_Trait: Flags = core.Flags.Trait + def Flags_Local: Flags = core.Flags.Local + def Flags_Synthetic: Flags = core.Flags.Synthetic + def Flags_Artifact: Flags = core.Flags.Artifact + def Flags_Mutable: Flags = core.Flags.Mutable + def Flags_FieldAccessor: Flags = core.Flags.Accessor + def Flags_CaseAcessor: Flags = core.Flags.CaseAccessor + def Flags_Covariant: Flags = core.Flags.Covariant + def Flags_Contravariant: Flags = core.Flags.Contravariant + def Flags_Scala2X: Flags = core.Flags.Scala2x + def Flags_DefaultParameterized: Flags = core.Flags.DefaultParameterized + def Flags_StableRealizable: Flags = core.Flags.StableRealizable + def Flags_Param: Flags = core.Flags.Param + def Flags_ParamAccessor: Flags = core.Flags.ParamAccessor + def Flags_Enum: Flags = core.Flags.Enum + def Flags_ModuleClass: Flags = core.Flags.ModuleClass + def Flags_PrivateLocal: Flags = core.Flags.PrivateLocal + def Flags_Package: Flags = core.Flags.Package + def Flags_ImplClass: Flags = core.Flags.ImplClass + + // + // QUOTED SEAL/UNSEAL + // + + /** View this expression `Expr[_]` as a `Term` */ + def QuotedExpr_unseal(self: scala.quoted.Expr[_])(implicit ctx: Context): Term = + PickledQuotes.quotedExprToTree(self) + + /** View this expression `Type[T]` as a `TypeTree` */ + def QuotedType_unseal(self: scala.quoted.Type[_])(implicit ctx: Context): TypeTree = + PickledQuotes.quotedTypeToTree(self) + + /** Convert `Term` to an `Expr[T]` and check that it conforms to `T` */ + def QuotedExpr_seal[T](self: Term)(tpe: scala.quoted.Type[T])(implicit ctx: Context): scala.quoted.Expr[T] = { + + val expectedType = QuotedType_unseal(tpe).tpe + + def etaExpand(term: Term): Term = term.tpe.widen match { + case mtpe: Types.MethodType if !mtpe.isParamDependent => + val closureResType = mtpe.resType match { + case t: Types.MethodType => t.toFunctionType() + case t => t + } + val closureTpe = Types.MethodType(mtpe.paramNames, mtpe.paramInfos, closureResType) + val closureMethod = ctx.newSymbol(ctx.owner, nme.ANON_FUN, Synthetic | Method, closureTpe) + tpd.Closure(closureMethod, tss => etaExpand(new tpd.TreeOps(term).appliedToArgs(tss.head))) + case _ => term + } + + val expanded = etaExpand(self) + if (expanded.tpe <:< expectedType) { + new scala.quoted.Exprs.TastyTreeExpr(expanded).asInstanceOf[scala.quoted.Expr[T]] + } else { + throw new scala.tasty.TastyTypecheckError( + s"""Term: ${self.show} + |did not conform to type: ${expectedType.show} + |""".stripMargin + ) + } + } + + /** Convert `Type` to an `quoted.Type[T]` */ + def QuotedType_seal(self: Type)(implicit ctx: Context): scala.quoted.Type[_] = { + val dummySpan = ctx.owner.span // FIXME + new scala.quoted.Types.TreeType(tpd.TypeTree(self).withSpan(dummySpan)) + } + + // + // HELPERS + // + + private def optional[T <: Trees.Tree[_]](tree: T): Option[tree.type] = + if (tree.isEmpty) None else Some(tree) + } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala index cd2cd58efde6..ac8dec3c4ce1 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala @@ -7,32 +7,6 @@ import dotty.tools.dotc.core.StdNames.nme trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with RootPositionImpl { - def ValueDeco(value: Value): Pattern.ValueAPI = new Pattern.ValueAPI { - def value(implicit ctx: Context): Term = value - } - def BindDeco(bind: Bind): Pattern.BindAPI = new Pattern.BindAPI { - def name(implicit ctx: Context): String = bind.name.toString - def pattern(implicit ctx: Context): Pattern = bind.body - } - def UnapplyDeco(unapply: Unapply): Pattern.UnapplyAPI = new Pattern.UnapplyAPI { - def fun(implicit ctx: Context): Term = unapply.fun - def implicits(implicit ctx: Context): List[Term] = unapply.implicits - def patterns(implicit ctx: Context): List[Pattern] = effectivePatterns(unapply.patterns) - - private def effectivePatterns(patterns: List[Pattern]): List[Pattern] = patterns match { - case patterns0 :+ Trees.SeqLiteral(elems, _) => patterns0 ::: elems - case _ => patterns - } - } - def AlternativeDeco(alternatives: Alternatives): Pattern.AlternativesAPI = new Pattern.AlternativesAPI { - def patterns(implicit ctx: Context): List[Pattern] = alternatives.trees - } - def TypeTestDeco(typeTest: TypeTest): Pattern.TypeTestAPI = new Pattern.TypeTestAPI { - def tpt(implicit ctx: Context): TypeTree = typeTest.tpt - } - - // ----- Patterns ------------------------------------------------- - def PatternDeco(pattern: Pattern): PatternAPI = new PatternAPI { def pos(implicit ctx: Context): Position = pattern.sourcePos def tpe(implicit ctx: Context): Type = pattern.tpe.stripTypeVar @@ -96,7 +70,7 @@ trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with RootPositionImp withDefaultPos(ctx => tpd.cpy.UnApply(original)(fun, implicits, patterns)(ctx)) def unapply(x: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] = x match { - case IsUnapply(x) => Some((x.fun, x.implicits, UnapplyDeco(x).patterns)) + case IsUnapply(x) => Some((x.fun, x.implicits, UnapplyAPI(x).patterns)) case _ => None } } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala index 26b401dc90e3..970f667d7903 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala @@ -2,20 +2,4 @@ package dotty.tools.dotc.tastyreflect trait PositionOpsImpl extends scala.tasty.reflect.PositionOps with CoreImpl { - def PositionDeco(pos: Position): PositionAPI = new PositionAPI { - def start: Int = pos.start - def end: Int = pos.end - - def exists: Boolean = pos.exists - - def sourceFile: java.nio.file.Path = pos.source.file.jpath - - def startLine: Int = pos.startLine - def endLine: Int = pos.endLine - - def startColumn: Int = pos.startColumn - def endColumn: Int = pos.endColumn - - def sourceCode: String = new String(pos.source.content(), pos.start, pos.end - pos.start) - } } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala index b527e12f44e8..bb91368d5c56 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala @@ -10,49 +10,4 @@ import dotty.tools.dotc.core.Types trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl { - def QuotedExprDeco[T](x: scala.quoted.Expr[T]): QuotedExprAPI = new QuotedExprAPI { - def unseal(implicit ctx: Context): Term = PickledQuotes.quotedExprToTree(x) - } - - def QuotedTypeDeco[T](x: scala.quoted.Type[T]): QuotedTypeAPI = new QuotedTypeAPI { - def unseal(implicit ctx: Context): TypeTree = PickledQuotes.quotedTypeToTree(x) - } - - def TermToQuoteDeco(term: Term): TermToQuotedAPI = new TermToQuotedAPI { - - def seal[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T] = { - - val expectedType = QuotedTypeDeco(implicitly[scala.quoted.Type[T]]).unseal.tpe - - def etaExpand(term: Term): Term = term.tpe.widen match { - case mtpe: Types.MethodType if !mtpe.isParamDependent => - val closureResType = mtpe.resType match { - case t: Types.MethodType => t.toFunctionType() - case t => t - } - val closureTpe = Types.MethodType(mtpe.paramNames, mtpe.paramInfos, closureResType) - val closureMethod = ctx.newSymbol(ctx.owner, nme.ANON_FUN, Synthetic | Method, closureTpe) - tpd.Closure(closureMethod, tss => etaExpand(new tpd.TreeOps(term).appliedToArgs(tss.head))) - case _ => term - } - - val expanded = etaExpand(term) - if (expanded.tpe <:< expectedType) { - new scala.quoted.Exprs.TastyTreeExpr(expanded).asInstanceOf[scala.quoted.Expr[T]] - } else { - throw new scala.tasty.TastyTypecheckError( - s"""Term: ${term.show} - |did not conform to type: ${expectedType.show} - |""".stripMargin - ) - } - } - } - - def TypeToQuoteDeco(tpe: Types.Type): TypeToQuotedAPI = new TypeToQuotedAPI { - def seal(implicit ctx: Context): quoted.Type[_] = { - val dummySpan = ctx.owner.span // FIXME - new scala.quoted.Types.TreeType(tpd.TypeTree(tpe).withSpan(dummySpan)) - } - } } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala index 8eeb857adbcb..f11aeca7d420 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala @@ -8,9 +8,4 @@ trait SignatureOpsImpl extends scala.tasty.reflect.SignatureOps with CoreImpl { } } - def SignatureDeco(sig: Signature): SignatureAPI = new SignatureAPI { - def paramSigs: List[String] = sig.paramsSig.map(_.toString) - def resultSig: String = sig.resSig.toString - } - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala index 58bfb03289eb..e9315528aa02 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala @@ -7,99 +7,6 @@ import dotty.tools.dotc.core.Decorators._ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl { - def SymbolDeco(symbol: Symbol): SymbolAPI = new SymbolAPI { - - def flags(implicit ctx: Context): Flags = symbol.flags - - def privateWithin(implicit ctx: Context): Option[Type] = { - val within = symbol.privateWithin - if (within.exists && !symbol.is(core.Flags.Protected)) Some(within.typeRef) - else None - } - - def protectedWithin(implicit ctx: Context): Option[Type] = { - val within = symbol.privateWithin - if (within.exists && symbol.is(core.Flags.Protected)) Some(within.typeRef) - else None - } - - def name(implicit ctx: Context): String = symbol.name.toString - def fullName(implicit ctx: Context): String = symbol.fullName.toString - - def pos(implicit ctx: Context): Position = symbol.sourcePos - - def comment(implicit ctx: Context): Option[Comment] = { - import dotty.tools.dotc.core.Comments.CommentsContext - val docCtx = ctx.docCtx.getOrElse { - throw new RuntimeException( - "DocCtx could not be found and comments are unavailable. This is a compiler-internal error." - ) - } - docCtx.docstring(symbol) - } - - def owner(implicit ctx: Context): Symbol = symbol.owner - - def isLocalDummy(implicit ctx: Context): Boolean = symbol.isLocalDummy - def isRefinementClass(implicit ctx: Context): Boolean = symbol.isRefinementClass - def isAliasType(implicit ctx: Context): Boolean = symbol.isAliasType - def isAnonymousClass(implicit ctx: Context): Boolean = symbol.isAnonymousClass - def isAnonymousFunction(implicit ctx: Context): Boolean = symbol.isAnonymousFunction - def isAbstractType(implicit ctx: Context): Boolean = symbol.isAbstractType - def isClassConstructor(implicit ctx: Context): Boolean = symbol.isClassConstructor - - def localContext(implicit ctx: Context): Context = { - if (symbol.exists) ctx.withOwner(symbol) - else ctx - } - - def asPackage(implicit ctx: Context): PackageSymbol = symbol match { - case IsPackageSymbol(symbol) => symbol - case _ => throw new Exception("not a PackageSymbol") - } - - def asClass(implicit ctx: Context): ClassSymbol = symbol match { - case IsClassSymbol(symbol) => symbol.asClass - case _ => throw new Exception("not a ClassSymbol") - } - - def asDef(implicit ctx: Context): DefSymbol = symbol match { - case IsDefSymbol(symbol) => symbol.asTerm - case _ => throw new Exception("not a DefSymbol") - } - - def asVal(implicit ctx: Context): ValSymbol = symbol match { - case IsValSymbol(symbol) => symbol - case _ => throw new Exception("not a ValSymbol") - } - - def asBind(implicit ctx: Context): BindSymbol = symbol match { - case IsBindSymbol(symbol) => symbol - case _ => throw new Exception("not a BindSymbol") - } - - def asType(implicit ctx: Context): TypeSymbol = symbol match { - case IsTypeSymbol(symbol) => symbol.asType - case _ => throw new Exception("not a TypeSymbol") - } - - def treeOpt(implicit ctx: Context): Option[Definition] = - if (symbol eq core.Symbols.NoSymbol) None - else Some(FromSymbol.definitionFromSym(symbol)) - - def annots(implicit ctx: Context): List[Term] = { - symbol.annotations.flatMap { - case _: core.Annotations.LazyBodyAnnotation => Nil - case annot => annot.tree :: Nil - } - } - - def isDefinedInCurrentRun(implicit ctx: Context): Boolean = { - symbol.topLevelClass.asClass.isDefinedInCurrentRun - } - - } - object IsPackageSymbol extends IsPackageSymbolModule { def unapply(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] = if (symbol.is(Flags.Package)) Some(symbol) else None diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala index d5c689b89a68..62e359279055 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala @@ -1,7 +1,6 @@ package dotty.tools.dotc.tastyreflect import dotty.tools.dotc.ast.{Trees, tpd, untpd} -import dotty.tools.dotc.core import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.core.Symbols.NoSymbol import dotty.tools.dotc.core._ @@ -9,176 +8,6 @@ import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFr trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with RootPositionImpl with Helpers { - def TreeDeco(tree: Tree): TreeAPI = new TreeAPI { - def pos(implicit ctx: Context): Position = tree.sourcePos - def symbol(implicit ctx: Context): Symbol = tree.symbol - } - - def PackageClauseDeco(pack: PackageClause): PackageClauseAPI = new PackageClauseAPI { - def pid(implicit ctx: Context): Term.Ref = pack.pid - def stats(implicit ctx: Context): List[Tree] = pack.stats - } - - def ImportDeco(imp: Import): ImportAPI = new ImportAPI { - def impliedOnly: Boolean = imp.impliedOnly - def expr(implicit ctx: Context): Tree = imp.expr - def selectors(implicit ctx: Context): List[ImportSelector] = imp.selectors - } - - def DefinitionDeco(definition: Definition): DefinitionAPI = new DefinitionAPI { - def name(implicit ctx: Context): String = definition.symbol.name.toString - } - - def ClassDefDeco(cdef: ClassDef): ClassDefAPI = new ClassDefAPI { - private def rhs = cdef.rhs.asInstanceOf[tpd.Template] - def constructor(implicit ctx: Context): DefDef = rhs.constr - def parents(implicit ctx: Context): List[TermOrTypeTree] = rhs.parents - def derived(implicit ctx: Context): List[TypeTree] = rhs.derived.asInstanceOf[List[TypeTree]] - def self(implicit ctx: Context): Option[tpd.ValDef] = optional(rhs.self) - def body(implicit ctx: Context): List[Statement] = rhs.body - def symbol(implicit ctx: Context): ClassSymbol = cdef.symbol.asClass - } - - def DefDefDeco(ddef: DefDef): DefDefAPI = new DefDefAPI { - def typeParams(implicit ctx: Context): List[TypeDef] = ddef.tparams - def paramss(implicit ctx: Context): List[List[ValDef]] = ddef.vparamss - def returnTpt(implicit ctx: Context): TypeTree = ddef.tpt - def rhs(implicit ctx: Context): Option[Tree] = optional(ddef.rhs) - def symbol(implicit ctx: Context): DefSymbol = ddef.symbol.asTerm - } - - def ValDefDeco(vdef: ValDef): ValDefAPI = new ValDefAPI { - def tpt(implicit ctx: Context): TypeTree = vdef.tpt - def rhs(implicit ctx: Context): Option[Tree] = optional(vdef.rhs) - def symbol(implicit ctx: Context): ValSymbol = vdef.symbol.asTerm - } - def TypeDefDeco(tdef: TypeDef): TypeDefAPI = new TypeDefAPI { - def rhs(implicit ctx: Context): TypeOrBoundsTree = tdef.rhs - def symbol(implicit ctx: Context): TypeSymbol = tdef.symbol.asType - } - - def PackageDefDeco(pdef: PackageDef): PackageDefAPI = new PackageDefAPI { - - def owner(implicit ctx: Context): PackageDefinition = packageDefFromSym(pdef.symbol.owner) - - def members(implicit ctx: Context): List[Statement] = { - if (pdef.symbol.is(core.Flags.JavaDefined)) Nil // FIXME should also support java packages - else pdef.symbol.info.decls.iterator.map(definitionFromSym).toList - } - - def symbol(implicit ctx: Context): PackageSymbol = pdef.symbol - } - - def IdentDeco(x: Term.Ident): Term.IdentAPI = new Term.IdentAPI { - def name(implicit ctx: Context): String = x.name.show - } - - def SelectDeco(x: Term.Select): Term.SelectAPI = new Term.SelectAPI { - def qualifier(implicit ctx: Context): Term = x.qualifier - def name(implicit ctx: Context): String = x.name.toString - def signature(implicit ctx: Context): Option[Signature] = - if (x.symbol.signature == core.Signature.NotAMethod) None - else Some(x.symbol.signature) - } - - def LiteralDeco(x: Term.Literal): Term.LiteralAPI = new Term.LiteralAPI { - def constant(implicit ctx: Context): Constant = x.const - } - - def ThisDeco(x: Term.This): Term.ThisAPI = new Term.ThisAPI { - def id(implicit ctx: Context): Option[Id] = optional(x.qual) - } - - def NewDeco(x: Term.New): Term.NewAPI = new Term.NewAPI { - def tpt(implicit ctx: Context): TypeTree = x.tpt - } - - def NamedArgDeco(x: Term.NamedArg): Term.NamedArgAPI = new Term.NamedArgAPI { - def name(implicit ctx: Context): String = x.name.toString - def value(implicit ctx: Context): Term = x.arg - } - - def ApplyDeco(x: Term.Apply): Term.ApplyAPI = new Term.ApplyAPI { - def fun(implicit ctx: Context): Term = x.fun - def args(implicit ctx: Context): List[Term] = x.args - } - - def TypeApplyDeco(x: Term.TypeApply): Term.TypeApplyAPI = new Term.TypeApplyAPI { - def fun(implicit ctx: Context): Term = x.fun - def args(implicit ctx: Context): List[TypeTree] = x.args - } - - def SuperDeco(x: Term.Super): Term.SuperAPI = new Term.SuperAPI { - def qualifier(implicit ctx: Context): Term = x.qual - def id(implicit ctx: Context): Option[untpd.Ident] = optional(x.mix) - } - - def TypedDeco(x: Term.Typed): Term.TypedAPI = new Term.TypedAPI { - def expr(implicit ctx: Context): Term = x.expr - def tpt(implicit ctx: Context): TypeTree = x.tpt - } - - def AssignDeco(x: Term.Assign): Term.AssignAPI = new Term.AssignAPI { - def lhs(implicit ctx: Context): Term = x.lhs - def rhs(implicit ctx: Context): Term = x.rhs - } - - def BlockDeco(x: Term.Block): Term.BlockAPI = new Term.BlockAPI { - def statements(implicit ctx: Context): List[Statement] = x.stats - def expr(implicit ctx: Context): Term = x.expr - } - - def InlinedDeco(x: Term.Inlined): Term.InlinedAPI = new Term.InlinedAPI { - def call(implicit ctx: Context): Option[Term] = optional(x.call) - def bindings(implicit ctx: Context): List[Definition] = x.bindings - def body(implicit ctx: Context): Term = x.expansion - } - - def LambdaDeco(x: Term.Lambda): Term.LambdaAPI = new Term.LambdaAPI { - def meth(implicit ctx: Context): Term = x.meth - def tptOpt(implicit ctx: Context): Option[TypeTree] = optional(x.tpt) - } - - def IfDeco(x: Term.If): Term.IfAPI = new Term.IfAPI { - def cond(implicit ctx: Context): Term = x.cond - def thenp(implicit ctx: Context): Term = x.thenp - def elsep(implicit ctx: Context): Term = x.elsep - } - - def MatchDeco(x: Term.Match): Term.MatchAPI = new Term.MatchAPI { - def scrutinee(implicit ctx: Context): Term = x.selector - def cases(implicit ctx: Context): List[tpd.CaseDef] = x.cases - } - - def TryDeco(x: Term.Try): Term.TryAPI = new Term.TryAPI { - def body(implicit ctx: Context): Term = x.expr - def cases(implicit ctx: Context): List[CaseDef] = x.cases - def finalizer(implicit ctx: Context): Option[Term] = optional(x.finalizer) - } - - def ReturnDeco(x: Term.Return): Term.ReturnAPI = new Term.ReturnAPI { - def expr(implicit ctx: Context): Term = x.expr - } - - def RepeatedDeco(x: Term.Repeated): Term.RepeatedAPI = new Term.RepeatedAPI { - def elems(implicit ctx: Context): List[Term] = x.elems - def elemtpt(implicit ctx: Context): TypeTree = x.elemtpt - } - - def SelectOuterDeco(x: Term.SelectOuter): Term.SelectOuterAPI = new Term.SelectOuterAPI { - def qualifier(implicit ctx: Context): Term = x.qualifier - def level(implicit ctx: Context): Int = { - val NameKinds.OuterSelectName(_, levels) = x.name - levels - } - def tpe(implicit ctx: Context): Type = x.tpe.stripTypeVar - } - - def WhileDeco(x: Term.While): Term.WhileAPI = new Term.WhileAPI { - def cond(implicit ctx: Context): Term = x.cond - def body(implicit ctx: Context): Term = x.body - } - // ----- Tree ---------------------------------------------------- object IsPackageClause extends IsPackageClauseModule { @@ -353,14 +182,6 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with RootPositionImpl with // ----- Terms ---------------------------------------------------- - def TermDeco(term: Term): TermAPI = new TermAPI { - import tpd._ - def pos(implicit ctx: Context): Position = term.sourcePos - def tpe(implicit ctx: Context): Type = term.tpe - def underlyingArgument(implicit ctx: Context): Term = term.underlyingArgument - def underlying(implicit ctx: Context): Term = term.underlying - } - object IsTerm extends IsTermModule { def unapply(tree: Tree)(implicit ctx: Context): Option[Term] = if (tree.isTerm) Some(tree) else None @@ -486,11 +307,6 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with RootPositionImpl with } } - def NamedArgDeco(x: Term.NamedArg): Term.NamedArgAPI = new Term.NamedArgAPI { - def name(implicit ctx: Context): String = x.name.toString - def value(implicit ctx: Context): Term = x.arg - } - object IsNamedArg extends IsNamedArgModule { def unapply(x: Term)(implicit ctx: Context): Option[NamedArg] = x match { case x: tpd.NamedArg if x.name.isInstanceOf[Names.TermName] => Some(x) // TODO: Now, the name should alwas be a term name diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala index 6dd3e134aa79..a6a0c19fac55 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala @@ -5,128 +5,6 @@ import dotty.tools.dotc.core.Decorators._ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreImpl { - def TypeDeco(tpe: Type): TypeAPI = new TypeAPI { - def =:=(other: Type)(implicit ctx: Context): Boolean = tpe =:= other - def <:<(other: Type)(implicit ctx: Context): Boolean = tpe <:< other - - /** Widen from singleton type to its underlying non-singleton - * base type by applying one or more `underlying` dereferences, - * Also go from => T to T. - * Identity for all other types. Example: - * - * class Outer { class C ; val x: C } - * def o: Outer - * .widen = o.C - */ - def widen(implicit ctx: Context): Type = tpe.widen - - def classSymbol(implicit ctx: Context): Option[ClassSymbol] = - if (tpe.classSymbol.exists) Some(tpe.classSymbol.asClass) else None - - def typeSymbol(implicit ctx: Context): Symbol = tpe.typeSymbol - - def isSingleton(implicit ctx: Context): Boolean = tpe.isSingleton - - def memberType(member: Symbol)(implicit ctx: Context): Type = - member.info.asSeenFrom(tpe, member.owner) - } - - def ConstantTypeDeco(x: ConstantType): Type.ConstantTypeAPI = new Type.ConstantTypeAPI { - def value(implicit ctx: Context): Any = x.value - } - - def SymRefDeco(x: SymRef): Type.SymRefAPI = new Type.SymRefAPI { - def qualifier(implicit ctx: Context): TypeOrBounds = x.prefix - } - - def TermRefDeco(x: TermRef): Type.TermRefAPI = new Type.TermRefAPI { - def qualifier(implicit ctx: Context): TypeOrBounds = x.prefix - } - - def TypeRefDeco(x: TypeRef): Type.TypeRefAPI = new Type.TypeRefAPI { - def name(implicit ctx: Context): String = x.name.toString - def qualifier(implicit ctx: Context): TypeOrBounds = x.prefix - } - - def SuperTypeDeco(x: SuperType): Type.SuperTypeAPI = new Type.SuperTypeAPI { - def thistpe(implicit ctx: Context): Type = x.thistpe - def supertpe(implicit ctx: Context): Type = x.supertpe - } - - def RefinementDeco(x: Refinement): Type.RefinementAPI = new Type.RefinementAPI { - def parent(implicit ctx: Context): Type = x.parent - def name(implicit ctx: Context): String = x.refinedName.toString - def info(implicit ctx: Context): TypeOrBounds = x.refinedInfo - } - - def AppliedTypeDeco(x: AppliedType): Type.AppliedTypeAPI = new Type.AppliedTypeAPI { - def tycon(implicit ctx: Context): Type = x.tycon - def args(implicit ctx: Context): List[TypeOrBounds] = x.args - } - - def AnnotatedTypeDeco(x: AnnotatedType): Type.AnnotatedTypeAPI = new Type.AnnotatedTypeAPI { - def underlying(implicit ctx: Context): Type = x.underlying.stripTypeVar - def annot(implicit ctx: Context): Term = x.annot.tree - } - - def AndTypeDeco(x: AndType): Type.AndTypeAPI = new Type.AndTypeAPI { - def left(implicit ctx: Context): Type = x.tp1.stripTypeVar - def right(implicit ctx: Context): Type = x.tp2.stripTypeVar - } - - def OrTypeDeco(x: OrType): Type.OrTypeAPI = new Type.OrTypeAPI { - def left(implicit ctx: Context): Type = x.tp1 - def right(implicit ctx: Context): Type = x.tp2 - } - - def MatchTypeDeco(x: MatchType): Type.MatchTypeAPI = new Type.MatchTypeAPI { - def bound(implicit ctx: Context): Type = x.bound - def scrutinee(implicit ctx: Context): Type = x.scrutinee - def cases(implicit ctx: Context): List[Type] = x.cases - } - - def ByNameTypeDeco(x: ByNameType): Type.ByNameTypeAPI = new Type.ByNameTypeAPI { - def underlying(implicit ctx: Context): Type = x.resType.stripTypeVar - } - - def ParamRefDeco(x: ParamRef): Type.ParamRefAPI = new Type.ParamRefAPI { - def binder(implicit ctx: Context): LambdaType[TypeOrBounds] = - x.binder.asInstanceOf[LambdaType[TypeOrBounds]] // Cast to tpd - def paramNum(implicit ctx: Context): Int = x.paramNum - } - - def ThisTypeDeco(x: ThisType): Type.ThisTypeAPI = new Type.ThisTypeAPI { - def underlying(implicit ctx: Context): Type = x.underlying - } - - def RecursiveThisDeco(x: RecursiveThis): Type.RecursiveThisAPI = new Type.RecursiveThisAPI { - def binder(implicit ctx: Context): RecursiveType = x.binder - } - - def RecursiveTypeDeco(x: RecursiveType): Type.RecursiveTypeAPI = new Type.RecursiveTypeAPI { - def underlying(implicit ctx: Context): Type = x.underlying.stripTypeVar - } - - def MethodTypeDeco(x: MethodType): Type.MethodTypeAPI = new Type.MethodTypeAPI { - def isErased: Boolean = x.isErasedMethod - def isImplicit: Boolean = x.isImplicitMethod - def paramNames(implicit ctx: Context): List[String] = x.paramNames.map(_.toString) - def paramTypes(implicit ctx: Context): List[Type] = x.paramInfos - def resType(implicit ctx: Context): Type = x.resType - } - - def PolyTypeDeco(x: PolyType): Type.PolyTypeAPI = new Type.PolyTypeAPI { - def paramNames(implicit ctx: Contexts.Context): List[String] = x.paramNames.map(_.toString) - def paramBounds(implicit ctx: Contexts.Context): List[TypeBounds] = x.paramInfos - def resType(implicit ctx: Contexts.Context): Type = x.resType - } - - def TypeLambdaDeco(x: TypeLambda): Type.TypeLambdaAPI = new Type.TypeLambdaAPI { - def paramNames(implicit ctx: Contexts.Context): List[String] = x.paramNames.map(_.toString) - def paramBounds(implicit ctx: Contexts.Context): List[TypeBounds] = x.paramInfos - def resType(implicit ctx: Contexts.Context): Type = x.resType - } - // ===== Types ==================================================== object IsType extends IsTypeModule { @@ -456,11 +334,6 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } - def TypeBoundsDeco(tpe: TypeBounds): TypeBoundsAPI = new TypeBoundsAPI { - def low(implicit ctx: Context): Type = tpe.lo - def hi(implicit ctx: Context): Type = tpe.hi - } - // ----- NoPrefix -------------------------------------------------- object NoPrefix extends NoPrefixModule { diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala index 5dc2725996ce..2e60623d2bc2 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala @@ -8,79 +8,6 @@ import dotty.tools.dotc.core.{Contexts, Types} trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps with RootPositionImpl { - def TypeTreeDeco(tpt: TypeTree): TypeTreeAPI = new TypeTreeAPI { - def pos(implicit ctx: Context): Position = tpt.sourcePos - def symbol(implicit ctx: Context): Symbol = tpt.symbol - def tpe(implicit ctx: Context): Type = tpt.tpe.stripTypeVar - } - - def InferredDeco(x: TypeTree.Inferred): TypeTree.InferredAPI = new TypeTree.InferredAPI { - } - - def TypeIdentDeco(x: TypeTree.Ident): TypeTree.IdentAPI = new TypeTree.IdentAPI { - def name(implicit ctx: Contexts.Context): String = x.name.toString - } - - def TypeSelectDeco(x: TypeTree.Select): TypeTree.SelectAPI = new TypeTree.SelectAPI { - def qualifier(implicit ctx: Contexts.Context): Term = x.qualifier - def name(implicit ctx: Contexts.Context): String = x.name.toString - } - - def ProjectionDeco(x: TypeTree.Projection): TypeTree.ProjectionAPI = new TypeTree.ProjectionAPI { - def qualifier(implicit ctx: Contexts.Context): TypeTree = x.qualifier - def name(implicit ctx: Contexts.Context): String = x.name.toString - } - - def SingletonDeco(x: TypeTree.Singleton): TypeTree.SingletonAPI = new TypeTree.SingletonAPI { - def ref(implicit ctx: Contexts.Context): Term = x.ref - } - - def RefinedDeco(x: TypeTree.Refined): TypeTree.RefinedAPI = new TypeTree.RefinedAPI { - def tpt(implicit ctx: Contexts.Context): TypeTree = x.tpt - def refinements(implicit ctx: Contexts.Context): List[Definition] = x.refinements - } - - def AppliedDeco(x: TypeTree.Applied): TypeTree.AppliedAPI = new TypeTree.AppliedAPI { - def tpt(implicit ctx: Contexts.Context): TypeTree = x.tpt - def args(implicit ctx: Contexts.Context): List[TypeOrBoundsTree] = x.args - } - - def AnnotatedDeco(x: TypeTree.Annotated): TypeTree.AnnotatedAPI = new TypeTree.AnnotatedAPI { - def arg(implicit ctx: Contexts.Context): TypeTree = x.arg - def annotation(implicit ctx: Contexts.Context): Term = x.annot - } - - def MatchTypeTreeDeco(x: TypeTree.MatchType): TypeTree.MatchTypeAPI = new TypeTree.MatchTypeAPI { - def bound(implicit ctx: Contexts.Context): Option[TypeTree] = if (x.bound == tpd.EmptyTree) None else Some(x.bound) - def selector(implicit ctx: Contexts.Context): TypeTree = x.selector - def cases(implicit ctx: Contexts.Context): List[CaseDef] = x.cases - } - - def ByNameDeco(x: TypeTree.ByName): TypeTree.ByNameAPI = new TypeTree.ByNameAPI { - def result(implicit ctx: Contexts.Context): TypeTree = x.result - } - - def LambdaTypeTreeDeco(x: TypeTree.LambdaTypeTree): TypeTree.LambdaTypeTreeAPI = new TypeTree.LambdaTypeTreeAPI { - def tparams(implicit ctx: Contexts.Context): List[TypeDef] = x.tparams - def body(implicit ctx: Contexts.Context): TypeOrBoundsTree = x.body - } - - def TypeBindDeco(x: TypeTree.TypeBind): TypeTree.TypeBindAPI = new TypeTree.TypeBindAPI { - def name(implicit ctx: Contexts.Context): String = x.name.toString - def body(implicit ctx: Contexts.Context): TypeOrBoundsTree = x.body - } - - def TypeBlockDeco(x: TypeTree.TypeBlock): TypeTree.TypeBlockAPI = new TypeTree.TypeBlockAPI { - def aliases(implicit ctx: Contexts.Context): List[TypeDef] = x.stats.map { case alias: TypeDef => alias } - def tpt(implicit ctx: Contexts.Context): TypeTree = x.expr - } - - // ----- TypeOrBoundsTree ------------------------------------------------ - - def TypeOrBoundsTreeDeco(tpt: TypeOrBoundsTree): TypeOrBoundsTreeAPI = new TypeOrBoundsTreeAPI { - def tpe(implicit ctx: Context): Type = tpt.tpe.stripTypeVar - } - // ----- TypeTrees ------------------------------------------------ object IsTypeTree extends IsTypeTreeModule { @@ -344,12 +271,6 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w // ----- TypeBoundsTrees ------------------------------------------------ - def TypeBoundsTreeDeco(bounds: TypeBoundsTree): TypeBoundsTreeAPI = new TypeBoundsTreeAPI { - def tpe(implicit ctx: Context): TypeBounds = bounds.tpe.asInstanceOf[Types.TypeBounds] - def low(implicit ctx: Context): TypeTree = bounds.lo - def hi(implicit ctx: Context): TypeTree = bounds.hi - } - object IsTypeBoundsTree extends IsTypeBoundsTreeModule { def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] = x match { case x: tpd.TypeBoundsTree => Some(x) diff --git a/library/src/scala/tasty/reflect/CaseDefOps.scala b/library/src/scala/tasty/reflect/CaseDefOps.scala index 866179aa8c3f..f7ea1dd4beb2 100644 --- a/library/src/scala/tasty/reflect/CaseDefOps.scala +++ b/library/src/scala/tasty/reflect/CaseDefOps.scala @@ -4,12 +4,11 @@ package reflect /** Tasty reflect case definition */ trait CaseDefOps extends Core { - trait CaseDefAPI { - def pattern(implicit ctx: Context): Pattern - def guard(implicit ctx: Context): Option[Term] - def rhs(implicit ctx: Context): Term + implicit class CaseDefAPI(caseDef: CaseDef) { + def pattern(implicit ctx: Context): Pattern = kernel.CaseDef_pattern(caseDef) + def guard(implicit ctx: Context): Option[Term] = kernel.CaseDef_guard(caseDef) + def rhs(implicit ctx: Context): Term = kernel.CaseDef_rhs(caseDef) } - implicit def CaseDefDeco(caseDef: CaseDef): CaseDefAPI val CaseDef: CaseDefModule abstract class CaseDefModule { @@ -22,11 +21,10 @@ trait CaseDefOps extends Core { } - trait TypeCaseDefAPI { - def pattern(implicit ctx: Context): TypeTree - def rhs(implicit ctx: Context): TypeTree + implicit class TypeCaseDefAPI(caseDef: TypeCaseDef) { + def pattern(implicit ctx: Context): TypeTree = kernel.TypeCaseDef_pattern(caseDef) + def rhs(implicit ctx: Context): TypeTree = kernel.TypeCaseDef_rhs(caseDef) } - implicit def TypeCaseDefDeco(caseDef: TypeCaseDef): TypeCaseDefAPI val TypeCaseDef: TypeCaseDefModule abstract class TypeCaseDefModule { diff --git a/library/src/scala/tasty/reflect/ConstantOps.scala b/library/src/scala/tasty/reflect/ConstantOps.scala index 920a07ad64a8..a71118530e5b 100644 --- a/library/src/scala/tasty/reflect/ConstantOps.scala +++ b/library/src/scala/tasty/reflect/ConstantOps.scala @@ -3,10 +3,9 @@ package reflect trait ConstantOps extends Core { - trait ConstantAPI { - def value: Any + implicit class ConstantAPI(const: Constant) { + def value: Any = kernel.Constant_value(const) } - implicit def ConstantDeco(const: Constant): ConstantAPI /** Module of Constant literals */ val Constant: ConstantModule diff --git a/library/src/scala/tasty/reflect/ContextOps.scala b/library/src/scala/tasty/reflect/ContextOps.scala index 7f2c85715c31..881568b060bd 100644 --- a/library/src/scala/tasty/reflect/ContextOps.scala +++ b/library/src/scala/tasty/reflect/ContextOps.scala @@ -3,14 +3,15 @@ package reflect trait ContextOps extends Core { - trait ContextAPI { - def owner: Symbol + implicit class ContextAPI(self: Context) { + /** Returns the owner of the context */ + def owner: Symbol = kernel.Context_owner(self) /** Returns the source file being compiled. The path is relative to the current working directory. */ - def source: java.nio.file.Path + def source: java.nio.file.Path = kernel.Context_source(self) } - implicit def ContextDeco(ctx: Context): ContextAPI + /** Context of the macro expansion */ implicit def rootContext: Context } diff --git a/library/src/scala/tasty/reflect/FlagsOps.scala b/library/src/scala/tasty/reflect/FlagsOps.scala index 6eff5e459a4f..914ff42f31da 100644 --- a/library/src/scala/tasty/reflect/FlagsOps.scala +++ b/library/src/scala/tasty/reflect/FlagsOps.scala @@ -2,120 +2,122 @@ package scala.tasty.reflect trait FlagsOps extends Core { - trait FlagsAPI { + implicit class FlagsAPI(self: Flags) { + /** Is the given flag set a subset of this flag sets */ - def is(flagSet: Flags): Boolean + def is(that: Flags): Boolean = kernel.Flags_is(self)(that) + /** Union of the two flag sets */ - def |(flagSet: Flags): Flags + def |(that: Flags): Flags = kernel.Flags_or(self)(that) + /** Intersection of the two flag sets */ - def &(flagSet: Flags): Flags + def &(that: Flags): Flags = kernel.Flags_and(self)(that) + } - implicit def FlagsDeco(flagSet: Flags): FlagsAPI - val Flags: FlagsModule - abstract class FlagsModule { + object Flags { /** Is this symbol `private` */ - def Private: Flags + def Private: Flags = kernel.Flags_Private /** Is this symbol `protected` */ - def Protected: Flags + def Protected:Flags = kernel.Flags_Protected /** Is this symbol `abstract` */ - def Abstract: Flags + def Abstract:Flags = kernel.Flags_Abstract /** Is this symbol `final` */ - def Final: Flags + def Final:Flags = kernel.Flags_Final /** Is this symbol `sealed` */ - def Sealed: Flags + def Sealed:Flags = kernel.Flags_Sealed /** Is this symbol `case` */ - def Case: Flags + def Case:Flags = kernel.Flags_Case /** Is this symbol `implicit` */ - def Implicit: Flags + def Implicit:Flags = kernel.Flags_Implicit /** Is this symbol `erased` */ - def Erased: Flags + def Erased:Flags = kernel.Flags_Erased /** Is this symbol `lazy` */ - def Lazy: Flags + def Lazy:Flags = kernel.Flags_Lazy /** Is this symbol `override` */ - def Override: Flags + def Override:Flags = kernel.Flags_Override /** Is this symbol `inline` */ - def Inline: Flags + def Inline:Flags = kernel.Flags_Inline /** Is this symbol markes as a macro. An inline method containing toplevel splices */ - def Macro: Flags + def Macro:Flags = kernel.Flags_Macro /** Is this symbol marked as static. Mapped to static Java member */ - def Static: Flags + def Static:Flags = kernel.Flags_Static /** Is this symbol defined in a Java class */ - def JavaDefined: Flags + def JavaDefined:Flags = kernel.Flags_JavaDefined /** Is this symbol an object or its class (used for a ValDef or a ClassDef extends Modifier respectively) */ - def Object: Flags + def Object:Flags = kernel.Flags_Object /** Is this symbol a trait */ - def Trait: Flags + def Trait:Flags = kernel.Flags_Trait /** Is this symbol local? Used in conjunction with private/private[Type] to mean private[this] extends Modifier proctected[this] */ - def Local: Flags + def Local:Flags = kernel.Flags_Local /** Was this symbol generated by Scala compiler */ - def Synthetic: Flags + def Synthetic:Flags = kernel.Flags_Synthetic /** Is this symbol to be tagged Java Synthetic */ - def Artifact: Flags + def Artifact:Flags = kernel.Flags_Artifact /** Is this symbol a `var` (when used on a ValDef) */ - def Mutable: Flags + def Mutable:Flags = kernel.Flags_Mutable /** Is this symbol a getter or a setter */ - def FieldAccessor: Flags + def FieldAccessor:Flags = kernel.Flags_FieldAccessor /** Is this symbol a getter for case class parameter */ - def CaseAcessor: Flags + def CaseAcessor:Flags = kernel.Flags_CaseAcessor /** Is this symbol a type parameter marked as covariant `+` */ - def Covariant: Flags + def Covariant:Flags = kernel.Flags_Covariant /** Is this symbol a type parameter marked as contravariant `-` */ - def Contravariant: Flags + def Contravariant:Flags = kernel.Flags_Contravariant /** Was this symbol imported from Scala2.x */ - def Scala2X: Flags + def Scala2X:Flags = kernel.Flags_Scala2X /** Is this symbol a method with default parameters */ - def DefaultParameterized: Flags + def DefaultParameterized:Flags = kernel.Flags_DefaultParameterized /** Is this symbol member that is assumed to be stable and realizable */ - def StableRealizable: Flags + def StableRealizable:Flags = kernel.Flags_StableRealizable /** Is this symbol a parameter */ - def Param: Flags + def Param:Flags = kernel.Flags_Param /** Is this symbol a parameter accessor */ - def ParamAccessor: Flags + def ParamAccessor:Flags = kernel.Flags_ParamAccessor /** Is this symbol an enum */ - def Enum: Flags + def Enum:Flags = kernel.Flags_Enum /** Is this symbol a module class */ - def ModuleClass: Flags + def ModuleClass:Flags = kernel.Flags_ModuleClass /** Is this symbol labeled private[this] */ - def PrivateLocal: Flags + def PrivateLocal:Flags = kernel.Flags_PrivateLocal /** Is this symbol a package */ - def Package: Flags + def Package:Flags = kernel.Flags_Package /** Is this symbol an implementation class of a Scala2 trait */ - def ImplClass: Flags + def ImplClass:Flags = kernel.Flags_ImplClass } } diff --git a/library/src/scala/tasty/reflect/IdOps.scala b/library/src/scala/tasty/reflect/IdOps.scala index be4b0c13a547..efbc6e7c0502 100644 --- a/library/src/scala/tasty/reflect/IdOps.scala +++ b/library/src/scala/tasty/reflect/IdOps.scala @@ -3,12 +3,15 @@ package reflect trait IdOps extends Core { - trait IdAPI { + implicit class IdAPI(id: Id) { + /** Position in the source code */ - def pos(implicit ctx: Context): Position - def name(implicit ctx: Context): String + def pos(implicit ctx: Context): Position = kernel.Id_pos(id) + + /** Name of the identifier */ + def name(implicit ctx: Context): String = kernel.Id_name(id) + } - implicit def IdDeco(id: Id): IdAPI val Id: IdModule abstract class IdModule { diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 81b879bf1c7a..188e44f50453 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -124,6 +124,12 @@ trait Kernel { /** Compilation context */ type Context <: AnyRef + /** Returns the owner of the context */ + def Context_owner(self: Context): Symbol + + /** Returns the source file being compiled. The path is relative to the current working directory. */ + def Context_source(self: Context): java.nio.file.Path + // // Settings // @@ -142,102 +148,206 @@ trait Kernel { /** Tree representing code written in the source */ type Tree <: AnyRef + def Tree_pos(self: Tree)(implicit ctx: Context): Position + def Tree_symbol(self: Tree)(implicit ctx: Context): Symbol + /** Tree representing a pacakage clause in the source code */ type PackageClause <: Tree + def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Term_Ref + def PackageClause_stats(self: PackageClause)(implicit ctx: Context): List[Tree] + /** Tree representing a statement in the source code */ type Statement <: Tree /** Tree representing an import in the source code */ type Import <: Statement + def Import_impliedOnly(self: Import): Boolean + def Import_expr(self: Import)(implicit ctx: Context): Term + def Import_selectors(self: Import)(implicit ctx: Context): List[ImportSelector] + /** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef` */ type Definition <: Statement + def Definition_name(self: Definition)(implicit ctx: Context): String + /** Tree representing a package definition. This includes definitions in all source files */ type PackageDef <: Definition + def PackageDef_owner(self: PackageDef)(implicit ctx: Context): PackageDef + def PackageDef_members(self: PackageDef)(implicit ctx: Context): List[Statement] + def PackageDef_symbol(self: PackageDef)(implicit ctx: Context): PackageSymbol + /** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */ type ClassDef <: Definition + def ClassDef_constructor(self: ClassDef)(implicit ctx: Context): DefDef + def ClassDef_parents(self: ClassDef)(implicit ctx: Context): List[TermOrTypeTree] + def ClassDef_derived(self: ClassDef)(implicit ctx: Context): List[TypeTree] + def ClassDef_self(self: ClassDef)(implicit ctx: Context): Option[ValDef] + def ClassDef_body(self: ClassDef)(implicit ctx: Context): List[Statement] + def ClassDef_symbol(self: ClassDef)(implicit ctx: Context): ClassSymbol + /** Tree representing a type (paramter or member) definition in the source code */ type TypeDef <: Definition + def TypeDef_rhs(self: TypeDef)(implicit ctx: Context): TypeOrBoundsTree + def TypeDef_symbol(self: TypeDef)(implicit ctx: Context): TypeSymbol + /** Tree representing a method definition in the source code */ type DefDef <: Definition + def DefDef_typeParams(self: DefDef)(implicit ctx: Context): List[TypeDef] + def DefDef_paramss(self: DefDef)(implicit ctx: Context): List[List[ValDef]] + def DefDef_returnTpt(self: DefDef)(implicit ctx: Context): TypeTree + def DefDef_rhs(self: DefDef)(implicit ctx: Context): Option[Term] + def DefDef_symbol(self: DefDef)(implicit ctx: Context): DefSymbol + /** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */ type ValDef <: Definition + def ValDef_tpt(self: ValDef)(implicit ctx: Context): TypeTree + def ValDef_rhs(self: ValDef)(implicit ctx: Context): Option[Term] + def ValDef_symbol(self: ValDef)(implicit ctx: Context): ValSymbol + /** Tree representing an expression in the source code */ type Term <: Statement + def Term_pos(self: Term)(implicit ctx: Context): Position + def Term_tpe(self: Term)(implicit ctx: Context): Type + def Term_underlyingArgument(self: Term)(implicit ctx: Context): Term + def Term_underlying(self: Term)(implicit ctx: Context): Term + /** Tree representing a reference to definition */ type Term_Ref <: Term /** Tree representing a reference to definition with a given name */ type Term_Ident <: Term_Ref + def Term_Ident_name(self: Term_Ident)(implicit ctx: Context): String + /** Tree representing a selection of definition with a given name on a given prefix */ type Term_Select <: Term_Ref + def Term_Select_qualifier(self: Term_Select)(implicit ctx: Context): Term + def Term_Select_name(self: Term_Select)(implicit ctx: Context): String + def Term_Select_signature(self: Term_Select)(implicit ctx: Context): Option[Signature] + /** Tree representing a literal value in the source code */ type Term_Literal <: Term + def Term_Literal_constant(self: Term_Literal)(implicit ctx: Context): Constant + /** Tree representing `this` in the source code */ type Term_This <: Term + def Term_This_id(self: Term_This)(implicit ctx: Context): Option[Id] + /** Tree representing `new` in the source code */ type Term_New <: Term + def Term_New_tpt(self: Term_New)(implicit ctx: Context): TypeTree + /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ type Term_NamedArg <: Term + def Term_NamedArg_name(self: Term_NamedArg)(implicit ctx: Context): String + def Term_NamedArg_value(self: Term_NamedArg)(implicit ctx: Context): Term + /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ type Term_Apply <: Term + def Term_Apply_fun(self: Term_Apply)(implicit ctx: Context): Term + def Term_Apply_args(self: Term_Apply)(implicit ctx: Context): List[Term] + /** Tree an application of type arguments */ type Term_TypeApply <: Term + def Term_TypeApply_fun(self: Term_TypeApply)(implicit ctx: Context): Term + def Term_TypeApply_args(self: Term_TypeApply)(implicit ctx: Context): List[TypeTree] + /** Tree representing `super` in the source code */ type Term_Super <: Term + def Term_Super_qualifier(self: Term_Super)(implicit ctx: Context): Term + def Term_Super_id(self: Term_Super)(implicit ctx: Context): Option[Id] + /** Tree representing a type ascription `x: T` in the source code */ type Term_Typed <: Term + def Term_Typed_expr(self: Term_Typed)(implicit ctx: Context): Term + def Term_Typed_tpt(self: Term_Typed)(implicit ctx: Context): TypeTree + /** Tree representing an assignment `x = y` in the source code */ type Term_Assign <: Term + def Term_Assign_lhs(self: Term_Assign)(implicit ctx: Context): Term + def Term_Assign_rhs(self: Term_Assign)(implicit ctx: Context): Term + /** Tree representing a block `{ ... }` in the source code */ type Term_Block <: Term + def Term_Block_statements(self: Term_Block)(implicit ctx: Context): List[Statement] + def Term_Block_expr(self: Term_Block)(implicit ctx: Context): Term + /** Tree representing a lambda `(...) => ...` in the source code */ type Term_Lambda <: Term + def Term_Lambda_meth(self: Term_Lambda)(implicit ctx: Context): Term + def Term_Lambda_tptOpt(self: Term_Lambda)(implicit ctx: Context): Option[TypeTree] + /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ type Term_If <: Term + def Term_If_cond(self: Term_If)(implicit ctx: Context): Term + def Term_If_thenp(self: Term_If)(implicit ctx: Context): Term + def Term_If_elsep(self: Term_If)(implicit ctx: Context): Term + /** Tree representing a pattern match `x match { ... }` in the source code */ type Term_Match <: Term + def Term_Match_scrutinee(self: Term_Match)(implicit ctx: Context): Term + def Term_Match_cases(self: Term_Match)(implicit ctx: Context): List[CaseDef] + /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ type Term_Try <: Term + def Term_Try_body(self: Term_Try)(implicit ctx: Context): Term + def Term_Try_cases(self: Term_Try)(implicit ctx: Context): List[CaseDef] + def Term_Try_finalizer(self: Term_Try)(implicit ctx: Context): Option[Term] + /** Tree representing a `return` in the source code */ type Term_Return <: Term + def Term_Return_expr(self: Term_Return)(implicit ctx: Context): Term + /** Tree representing a variable argument list in the source code */ type Term_Repeated <: Term + def Term_Repeated_elems(self: Term_Repeated)(implicit ctx: Context): List[Term] + def Term_Repeated_elemtpt(self: Term_Repeated)(implicit ctx: Context): TypeTree + /** Tree representing the scope of an inlined tree */ type Term_Inlined <: Term + def Term_Inlined_call(self: Term_Inlined)(implicit ctx: Context): Option[TermOrTypeTree] + def Term_Inlined_bindings(self: Term_Inlined)(implicit ctx: Context): List[Definition] + def Term_Inlined_body(self: Term_Inlined)(implicit ctx: Context): Term + /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ type Term_SelectOuter <: Term + def Term_SelectOuter_qualifier(self: Term_SelectOuter)(implicit ctx: Context): Term + def Term_SelectOuter_level(self: Term_SelectOuter)(implicit ctx: Context): Int + def Term_SelectOuter_tpe(self: Term_SelectOuter)(implicit ctx: Context): Type + /** Tree representing a while loop */ type Term_While <: Term + def Term_While_cond(self: Term_While)(implicit ctx: Context): Term + def Term_While_body(self: Term_While)(implicit ctx: Context): Term + // // CASES // @@ -245,9 +355,16 @@ trait Kernel { /** Branch of a pattern match or catch clause */ type CaseDef <: AnyRef + def CaseDef_pattern(self: CaseDef)(implicit ctx: Context): Pattern + def CaseDef_guard(self: CaseDef)(implicit ctx: Context): Option[Term] + def CaseDef_rhs(self: CaseDef)(implicit ctx: Context): Term + /** Branch of a type pattern match */ type TypeCaseDef <: AnyRef + def TypeCaseDef_pattern(self: TypeCaseDef)(implicit ctx: Context): TypeTree + def TypeCaseDef_rhs(self: TypeCaseDef)(implicit ctx: Context): TypeTree + // // PATTERNS // @@ -258,18 +375,34 @@ trait Kernel { /** Pattern representing a value. This includes `1`, ```x``` and `_` */ type Value <: Pattern + def Pattern_Value_value(self: Value)(implicit ctx: Context): Term + /** Pattern representing a `_ @ _` binding. */ type Bind <: Pattern + def Pattern_Bind_name(self: Bind)(implicit ctx: Context): String + + def Pattern_Bind_pattern(self: Bind)(implicit ctx: Context): Pattern + /** Pattern representing a `Xyz(...)` unapply. */ type Unapply <: Pattern + def Pattern_Unapply_fun(self: Unapply)(implicit ctx: Context): Term + + def Pattern_Unapply_implicits(self: Unapply)(implicit ctx: Context): List[Term] + + def Pattern_Unapply_patterns(self: Unapply)(implicit ctx: Context): List[Pattern] + /** Pattern representing `X | Y | ...` alternatives. */ type Alternatives <: Pattern + def Pattern_Alternatives_patterns(self: Alternatives)(implicit ctx: Context): List[Pattern] + /** Pattern representing a `x: Y` type test. */ type TypeTest <: Pattern + def Pattern_TypeTest_tpt(self: TypeTest)(implicit ctx: Context): TypeTree + // // TYPE TREES // @@ -277,51 +410,95 @@ trait Kernel { /** Type tree representing a type or a bounds written in the source */ type TypeOrBoundsTree <: AnyRef + def TypeOrBoundsTree_tpe(self: TypeOrBoundsTree)(implicit ctx: Context): Type + /** Type tree representing a type written in the source */ type TypeTree <: TypeOrBoundsTree + def TypeTree_pos(self: TypeTree)(implicit ctx: Context): Position + def TypeTree_symbol(self: TypeTree)(implicit ctx: Context): Symbol + def TypeTree_tpe(self: TypeTree)(implicit ctx: Context): Type + /** Type tree representing an inferred type */ type TypeTree_Inferred <: TypeTree /** Type tree representing a reference to definition with a given name */ type TypeTree_Ident <: TypeTree + def TypeTree_Ident_name(self: TypeTree_Ident)(implicit ctx: Context): String + /** Type tree representing a selection of definition with a given name on a given term prefix */ type TypeTree_Select <: TypeTree + def TypeTree_Select_qualifier(self: TypeTree_Select)(implicit ctx: Context): Term + def TypeTree_Select_name(self: TypeTree_Select)(implicit ctx: Context): String + /** Type tree representing a selection of definition with a given name on a given type prefix */ type TypeTree_Projection <: TypeTree + def TypeTree_Projection_qualifier(self: TypeTree_Projection)(implicit ctx: Context): TypeTree + def TypeTree_Projection_name(self: TypeTree_Projection)(implicit ctx: Context): String + /** Type tree representing a singleton type */ type TypeTree_Singleton <: TypeTree + def TypeTree_Singleton_ref(self: TypeTree_Singleton)(implicit ctx: Context): Term + /** Type tree representing a type refinement */ type TypeTree_Refined <: TypeTree + def TypeTree_Refined_tpt(self: TypeTree_Refined)(implicit ctx: Context): TypeTree + def TypeTree_Refined_refinements(self: TypeTree_Refined)(implicit ctx: Context): List[Definition] + /** Type tree representing a type application */ type TypeTree_Applied <: TypeTree + def TypeTree_Applied_tpt(self: TypeTree_Applied)(implicit ctx: Context): TypeTree + def TypeTree_Applied_args(self: TypeTree_Applied)(implicit ctx: Context): List[TypeOrBoundsTree] + /** Type tree representing an annotated type */ type TypeTree_Annotated <: TypeTree + def TypeTree_Annotated_arg(self: TypeTree_Annotated)(implicit ctx: Context): TypeTree + def TypeTree_Annotated_annotation(self: TypeTree_Annotated)(implicit ctx: Context): Term + /** Type tree representing a type match */ type TypeTree_MatchType <: TypeTree + def TypeTree_MatchType_bound(self: TypeTree_MatchType)(implicit ctx: Context): Option[TypeTree] + def TypeTree_MatchType_selector(self: TypeTree_MatchType)(implicit ctx: Context): TypeTree + def TypeTree_MatchType_cases(self: TypeTree_MatchType)(implicit ctx: Context): List[TypeCaseDef] + /** Type tree representing a by name parameter */ type TypeTree_ByName <: TypeTree + def TypeTree_ByName_result(self: TypeTree_ByName)(implicit ctx: Context): TypeTree + /** Type tree representing a lambda abstraction type */ type TypeTree_LambdaTypeTree <: TypeTree + def TypeTree_LambdaTypeTree_tparams(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): List[TypeDef] + def TypeTree_LambdaTypeTree_body(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): TypeOrBoundsTree + /** Type tree representing a type binding */ type TypeTree_TypeBind <: TypeTree + def TypeTree_TypeBind_name(self: TypeTree_TypeBind)(implicit ctx: Context): String + def TypeTree_TypeBind_body(self: TypeTree_TypeBind)(implicit ctx: Context): TypeOrBoundsTree + /** Type tree within a block with aliases `{ type U1 = ... ; T[U1, U2] }` */ type TypeTree_TypeBlock <: TypeTree + def TypeTree_TypeBlock_aliases(self: TypeTree_TypeBlock)(implicit ctx: Context): List[TypeDef] + def TypeTree_TypeBlock_tpt(self: TypeTree_TypeBlock)(implicit ctx: Context): TypeTree + /** Type tree representing a type bound written in the source */ type TypeBoundsTree <: TypeOrBoundsTree + def TypeBoundsTree_tpe(self: TypeBoundsTree)(implicit ctx: Context): TypeBounds + def TypeBoundsTree_low(self: TypeBoundsTree)(implicit ctx: Context): TypeTree + def TypeBoundsTree_hi(self: TypeBoundsTree)(implicit ctx: Context): TypeTree + /** Type tree representing wildcard type bounds written in the source. * The wildcard type `_` (for example in in `List[_]`) will be a type tree that * represents a type but has `TypeBound`a inside. @@ -341,57 +518,125 @@ trait Kernel { /** Type bounds */ type TypeBounds <: TypeOrBounds + def TypeBounds_low(self: TypeBounds)(implicit ctx: Context): Type + def TypeBounds_hi(self: TypeBounds)(implicit ctx: Context): Type + /** A type */ type Type <: TypeOrBounds + def `Type_=:=`(self: Type)(that: Type)(implicit ctx: Context): Boolean + def `Type_<:<`(self: Type)(that: Type)(implicit ctx: Context): Boolean + + /** Widen from singleton type to its underlying non-singleton + * base type by applying one or more `underlying` dereferences, + * Also go from => T to T. + * Identity for all other types. Example: + * + * class Outer { class C ; val x: C } + * def o: Outer + * .widen = o.C + */ + def Type_widen(self: Type)(implicit ctx: Context): Type + + def Type_classSymbol(self: Type)(implicit ctx: Context): Option[ClassSymbol] + + def Type_typeSymbol(self: Type)(implicit ctx: Context): Symbol + + def Type_isSingleton(self: Type)(implicit ctx: Context): Boolean + + def Type_memberType(self: Type)(member: Symbol)(implicit ctx: Context): Type + /** A singleton type representing a known constant value */ type ConstantType <: Type + def ConstantType_value(self: ConstantType)(implicit ctx: Context): Any + /** Type of a reference to a symbol */ type SymRef <: Type + def SymRef_qualifier(self: SymRef)(implicit ctx: Context): TypeOrBounds + /** Type of a reference to a term */ type TermRef <: Type + def TermRef_qualifier(self: TermRef)(implicit ctx: Context): TypeOrBounds + /** Type of a reference to a type */ type TypeRef <: Type + def TypeRef_name(self: TypeRef)(implicit ctx: Context): String + def TypeRef_qualifier(self: TypeRef)(implicit ctx: Context): TypeOrBounds + /** Type of a `super` refernce */ type SuperType <: Type + def SuperType_thistpe(self: SuperType)(implicit ctx: Context): Type + def SuperType_supertpe(self: SuperType)(implicit ctx: Context): Type + /** A type with a type refinement `T { type U }` */ type Refinement <: Type + def Refinement_parent(self: Refinement)(implicit ctx: Context): Type + def Refinement_name(self: Refinement)(implicit ctx: Context): String + def Refinement_info(self: Refinement)(implicit ctx: Context): TypeOrBounds + /** A higher kinded type applied to some types `T[U]` */ type AppliedType <: Type + def AppliedType_tycon(self: AppliedType)(implicit ctx: Context): Type + def AppliedType_args(self: AppliedType)(implicit ctx: Context): List[TypeOrBounds] + /** A type with an anottation `T @foo` */ type AnnotatedType <: Type + def AnnotatedType_underlying(self: AnnotatedType)(implicit ctx: Context): Type + def AnnotatedType_annot(self: AnnotatedType)(implicit ctx: Context): Term + /** Intersection type `T & U` */ type AndType <: Type + def AndType_left(self: AndType)(implicit ctx: Context): Type + def AndType_right(self: AndType)(implicit ctx: Context): Type + /** Union type `T | U` */ type OrType <: Type + def OrType_left(self: OrType)(implicit ctx: Context): Type + def OrType_right(self: OrType)(implicit ctx: Context): Type + /** Type match `T match { case U => ... }` */ type MatchType <: Type + def MatchType_bound(self: MatchType)(implicit ctx: Context): Type + def MatchType_scrutinee(self: MatchType)(implicit ctx: Context): Type + def MatchType_cases(self: MatchType)(implicit ctx: Context): List[Type] + /** Type of a by by name parameter */ type ByNameType <: Type + def ByNameType_underlying(self: ByNameType)(implicit ctx: Context): Type + /** Type of a parameter reference */ type ParamRef <: Type + def ParamRef_binder(self: ParamRef)(implicit ctx: Context): LambdaType[TypeOrBounds] + def ParamRef_paramNum(self: ParamRef)(implicit ctx: Context): Int + /** Type of `this` */ type ThisType <: Type + def ThisType_underlying(self: ThisType)(implicit ctx: Context): Type + /** A type that is recursively defined `this` */ type RecursiveThis <: Type + def RecursiveThis_binder(self: RecursiveThis)(implicit ctx: Context): RecursiveType + /** A type that is recursively defined */ type RecursiveType <: Type + def RecursiveType_underlying(self: RecursiveType)(implicit ctx: Context): Type + // TODO can we add the bound back without an cake? // TODO is LambdaType really needed? ParamRefExtractor could be split into more precise extractors /** Common abstraction for lambda types (MethodType, PolyType and TypeLambda). */ @@ -400,12 +645,26 @@ trait Kernel { /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ type MethodType <: LambdaType[Type] + def MethodType_isErased(self: MethodType): Boolean + def MethodType_isImplicit(self: MethodType): Boolean + def MethodType_paramNames(self: MethodType)(implicit ctx: Context): List[String] + def MethodType_paramTypes(self: MethodType)(implicit ctx: Context): List[Type] + def MethodType_resType(self: MethodType)(implicit ctx: Context): Type + /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ type PolyType <: LambdaType[TypeBounds] + def PolyType_paramNames(self: PolyType)(implicit ctx: Context): List[String] + def PolyType_paramBounds(self: PolyType)(implicit ctx: Context): List[TypeBounds] + def PolyType_resType(self: PolyType)(implicit ctx: Context): Type + /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ type TypeLambda <: LambdaType[TypeBounds] + def TypeLambda_paramNames(self: TypeLambda)(implicit ctx: Context): List[String] + def TypeLambda_paramBounds(self: TypeLambda)(implicit ctx: Context): List[TypeBounds] + def TypeLambda_resType(self: TypeLambda)(implicit ctx: Context): Type + // // IMPORT SELECTORS // @@ -424,6 +683,12 @@ trait Kernel { /** Untyped identifier */ type Id <: AnyRef + /** Position in the source code */ + def Id_pos(self: Id)(implicit ctx: Context): Position + + /** Name of the identifier */ + def Id_name(self: Id)(implicit ctx: Context): String + // // SIGNATURES // @@ -431,6 +696,12 @@ trait Kernel { /** JVM signature of a method */ type Signature <: AnyRef + /** The (JVM) erased signatures of the parameters */ + def Signature_paramSigs(self: Signature): List[String] + + /** The (JVM) erased result type */ + def Signature_resultSig(self: Signature): String + // // POSITIONS // @@ -438,6 +709,33 @@ trait Kernel { /** Source position */ type Position <: AnyRef + /** The start offset in the source file */ + def Position_start(self: Position): Int + + /** The end offset in the source file */ + def Position_end(self: Position): Int + + /** Does this position exist */ + def Position_exists(self: Position): Boolean + + /** Source file in which this position is located */ + def Position_sourceFile(self: Position): java.nio.file.Path + + /** The start line in the source file */ + def Position_startLine(self: Position): Int + + /** The end line in the source file */ + def Position_endLine(self: Position): Int + + /** The start column in the source file */ + def Position_startColumn(self: Position): Int + + /** The end column in the source file */ + def Position_endColumn(self: Position): Int + + /** Source code within the position */ + def Position_sourceCode(self: Position): String + // // COMMENTS // @@ -452,6 +750,8 @@ trait Kernel { /** Constant value represented as the constant itself */ type Constant <: AnyRef + def Constant_value(const: Constant): Any + // // SYMBOLS // @@ -461,6 +761,51 @@ trait Kernel { */ type Symbol <: AnyRef + /** Owner of this symbol. The owner is the symbol in which this symbol is defined. */ + def Symbol_owner(self: Symbol)(implicit ctx: Context): Symbol + + /** Flags of this symbol */ + def Symbol_flags(self: Symbol)(implicit ctx: Context): Flags + + def Symbol_isLocalDummy(self: Symbol)(implicit ctx: Context): Boolean + + def Symbol_isRefinementClass(self: Symbol)(implicit ctx: Context): Boolean + + def Symbol_isAliasType(self: Symbol)(implicit ctx: Context): Boolean + + def Symbol_isAnonymousClass(self: Symbol)(implicit ctx: Context): Boolean + + def Symbol_isAnonymousFunction(self: Symbol)(implicit ctx: Context): Boolean + + def Symbol_isAbstractType(self: Symbol)(implicit ctx: Context): Boolean + + def Symbol_isClassConstructor(self: Symbol)(implicit ctx: Context): Boolean + + /** This symbol is private within the resulting type. */ + def Symbol_privateWithin(self: Symbol)(implicit ctx: Context): Option[Type] + + /** This symbol is protected within the resulting type. */ + def Symbol_protectedWithin(self: Symbol)(implicit ctx: Context): Option[Type] + + /** The name of this symbol. */ + def Symbol_name(self: Symbol)(implicit ctx: Context): String + + /** The full name of this symbol up to the root package. */ + def Symbol_fullName(self: Symbol)(implicit ctx: Context): String + + /** The position of this symbol */ + def Symbol_pos(self: Symbol)(implicit ctx: Context): Position + + def Symbol_localContext(self: Symbol)(implicit ctx: Context): Context + + /** The comment of the symbol */ + def Symbol_comment(self: Symbol)(implicit ctx: Context): Option[Comment] + + /** Annotations attached to this symbol */ + def Symbol_annots(self: Symbol)(implicit ctx: Context): List[Term] + + def Symbol_isDefinedInCurrentRun(self: Symbol)(implicit ctx: Context): Boolean + /** Symbol of a package definition */ type PackageSymbol <: Symbol @@ -489,4 +834,65 @@ trait Kernel { /** FlagSet of a Symbol */ type Flags + /** Is the given flag set a subset of this flag sets */ + def Flags_is(self: Flags)(that: Flags): Boolean + + /** Union of the two flag sets */ + def Flags_or(self: Flags)(that: Flags): Flags + + /** Intersection of the two flag sets */ + def Flags_and(self: Flags)(that: Flags): Flags + + def Flags_Private: Flags + def Flags_Protected: Flags + def Flags_Abstract: Flags + def Flags_Final: Flags + def Flags_Sealed: Flags + def Flags_Case: Flags + def Flags_Implicit: Flags + def Flags_Implied: Flags + def Flags_Erased: Flags + def Flags_Lazy: Flags + def Flags_Override: Flags + def Flags_Inline: Flags + def Flags_Macro: Flags + def Flags_Static: Flags + def Flags_JavaDefined: Flags + def Flags_Object: Flags + def Flags_Trait: Flags + def Flags_Local: Flags + def Flags_Synthetic: Flags + def Flags_Artifact: Flags + def Flags_Mutable: Flags + def Flags_FieldAccessor: Flags + def Flags_CaseAcessor: Flags + def Flags_Covariant: Flags + def Flags_Contravariant: Flags + def Flags_Scala2X: Flags + def Flags_DefaultParameterized: Flags + def Flags_StableRealizable: Flags + def Flags_Param: Flags + def Flags_ParamAccessor: Flags + def Flags_Enum: Flags + def Flags_ModuleClass: Flags + def Flags_PrivateLocal: Flags + def Flags_Package: Flags + def Flags_ImplClass: Flags + + // + // QUOTED SEAL/UNSEAL + // + + /** View this expression `Expr[_]` as a `Term` */ + def QuotedExpr_unseal(self: scala.quoted.Expr[_])(implicit ctx: Context): Term + + /** View this expression `Type[T]` as a `TypeTree` */ + def QuotedType_unseal(self: scala.quoted.Type[_])(implicit ctx: Context): TypeTree + + /** Convert `Term` to an `Expr[T]` and check that it conforms to `T` */ + def QuotedExpr_seal[T](self: Term)(tpe: scala.quoted.Type[T])(implicit ctx: Context): scala.quoted.Expr[T] + + /** Convert `Type` to an `quoted.Type[T]` */ + def QuotedType_seal(self: Type)(implicit ctx: Context): scala.quoted.Type[_] + } diff --git a/library/src/scala/tasty/reflect/PatternOps.scala b/library/src/scala/tasty/reflect/PatternOps.scala index dd43db40f035..4b49ed2ece21 100644 --- a/library/src/scala/tasty/reflect/PatternOps.scala +++ b/library/src/scala/tasty/reflect/PatternOps.scala @@ -3,11 +3,28 @@ package reflect trait PatternOps extends Core { - implicit def ValueDeco(value: Value): Pattern.ValueAPI - implicit def BindDeco(bind: Bind): Pattern.BindAPI - implicit def UnapplyDeco(unapply: Unapply): Pattern.UnapplyAPI - implicit def AlternativeDeco(alternatives: Alternatives): Pattern.AlternativesAPI - implicit def TypeTestDeco(typeTest: TypeTest): Pattern.TypeTestAPI + implicit class ValueAPI(value: Value) { + def value(implicit ctx: Context): Term = kernel.Pattern_Value_value(value) + } + + implicit class BindAPI(bind: Bind) { + def name(implicit ctx: Context): String = kernel.Pattern_Bind_name(bind) + def pattern(implicit ctx: Context): Pattern = kernel.Pattern_Bind_pattern(bind) + } + + implicit class UnapplyAPI(unapply: Unapply) { + def fun(implicit ctx: Context): Term = kernel.Pattern_Unapply_fun(unapply) + def implicits(implicit ctx: Context): List[Term] = kernel.Pattern_Unapply_implicits(unapply) + def patterns(implicit ctx: Context): List[Pattern] = kernel.Pattern_Unapply_patterns(unapply) + } + + implicit class AlternativesAPI(alternatives: Alternatives) { + def patterns(implicit ctx: Context): List[Pattern] = kernel.Pattern_Alternatives_patterns(alternatives) + } + + implicit class TypeTestAPI(typeTest: TypeTest) { + def tpt(implicit ctx: Context): TypeTree = kernel.Pattern_TypeTest_tpt(typeTest) + } trait PatternAPI { /** Position in the source code */ @@ -34,10 +51,6 @@ trait PatternOps extends Core { def unapply(pattern: Pattern)(implicit ctx: Context): Option[Term] } - trait ValueAPI { - def value(implicit ctx: Context): Term - } - val IsBind: IsBindModule abstract class IsBindModule { def unapply(pattern: Pattern)(implicit ctx: Context): Option[Bind] @@ -50,11 +63,6 @@ trait PatternOps extends Core { def unapply(pattern: Pattern)(implicit ctx: Context): Option[(String, Pattern)] } - trait BindAPI { - def name(implicit ctx: Context): String - def pattern(implicit ctx: Context): Pattern - } - val IsUnapply: IsUnapplyModule abstract class IsUnapplyModule { def unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] @@ -67,12 +75,6 @@ trait PatternOps extends Core { def unapply(pattern: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] } - trait UnapplyAPI { - def fun(implicit ctx: Context): Term - def implicits(implicit ctx: Context): List[Term] - def patterns(implicit ctx: Context): List[Pattern] - } - val IsAlternatives: IsAlternativesModule abstract class IsAlternativesModule { def unapply(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] @@ -85,10 +87,6 @@ trait PatternOps extends Core { def unapply(pattern: Pattern)(implicit ctx: Context): Option[List[Pattern]] } - trait AlternativesAPI { - def patterns(implicit ctx: Context): List[Pattern] - } - val IsTypeTest: IsTypeTestModule abstract class IsTypeTestModule { def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] @@ -101,10 +99,6 @@ trait PatternOps extends Core { def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTree] } - trait TypeTestAPI { - def tpt(implicit ctx: Context): TypeTree - } - } } diff --git a/library/src/scala/tasty/reflect/PositionOps.scala b/library/src/scala/tasty/reflect/PositionOps.scala index 625fc9ba1f42..f2141925fd28 100644 --- a/library/src/scala/tasty/reflect/PositionOps.scala +++ b/library/src/scala/tasty/reflect/PositionOps.scala @@ -2,34 +2,35 @@ package scala.tasty.reflect trait PositionOps extends Core { - trait PositionAPI { + implicit class PositionAPI(pos: Position) { - def exists: Boolean + /** The start offset in the source file */ + def start: Int = kernel.Position_start(pos) - def sourceFile: java.nio.file.Path + /** The end offset in the source file */ + def end: Int = kernel.Position_end(pos) - /** The start index in the source file */ - def start: Int + /** Does this position exist */ + def exists: Boolean = kernel.Position_exists(pos) - /** The end index in the source file */ - def end: Int + /** Source file in which this position is located */ + def sourceFile: java.nio.file.Path = kernel.Position_sourceFile(pos) /** The start line in the source file */ - def startLine: Int - - /** The start column in the source file */ - def startColumn: Int + def startLine: Int = kernel.Position_startLine(pos) /** The end line in the source file */ - def endLine: Int + def endLine: Int = kernel.Position_endLine(pos) + + /** The start column in the source file */ + def startColumn: Int = kernel.Position_startColumn(pos) /** The end column in the source file */ - def endColumn: Int + def endColumn: Int = kernel.Position_endColumn(pos) /** Source code within the position */ - def sourceCode: String + def sourceCode: String = kernel.Position_sourceCode(pos) } - implicit def PositionDeco(pos: Position): PositionAPI } diff --git a/library/src/scala/tasty/reflect/QuotedOps.scala b/library/src/scala/tasty/reflect/QuotedOps.scala index 65958da3d01f..e5307f1fd145 100644 --- a/library/src/scala/tasty/reflect/QuotedOps.scala +++ b/library/src/scala/tasty/reflect/QuotedOps.scala @@ -3,27 +3,27 @@ package scala.tasty.reflect /** Extension methods on scala.quoted.{Expr|Type} to convert to scala.tasty.Tasty objects */ trait QuotedOps extends Core { - trait QuotedExprAPI { + implicit class QuotedExprAPI[T](expr: scala.quoted.Expr[T]) { /** View this expression `Expr[T]` as a `Term` */ - def unseal(implicit ctx: Context): Term + def unseal(implicit ctx: Context): Term = + kernel.QuotedExpr_unseal(expr) } - implicit def QuotedExprDeco[T](expr: quoted.Expr[T]): QuotedExprAPI - trait QuotedTypeAPI { + implicit class QuotedTypeAPI[T](tpe: scala.quoted.Type[T]) { /** View this expression `Type[T]` as a `TypeTree` */ - def unseal(implicit ctx: Context): TypeTree + def unseal(implicit ctx: Context): TypeTree = + kernel.QuotedType_unseal(tpe) } - implicit def QuotedTypeDeco[T](tpe: quoted.Type[T]): QuotedTypeAPI - trait TermToQuotedAPI { + implicit class TermToQuotedAPI(term: Term) { /** Convert `Term` to an `Expr[T]` and check that it conforms to `T` */ - def seal[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T] + def seal[T](implicit tpe: scala.quoted.Type[T], ctx: Context): scala.quoted.Expr[T] = + kernel.QuotedExpr_seal(term)(tpe) } - implicit def TermToQuoteDeco(term: Term): TermToQuotedAPI - trait TypeToQuotedAPI { + implicit class TypeToQuotedAPI(tpe: Type) { /** Convert `Type` to an `quoted.Type[T]` */ - def seal(implicit ctx: Context): scala.quoted.Type[_] + def seal(implicit ctx: Context): scala.quoted.Type[_] = + kernel.QuotedType_seal(tpe) } - implicit def TypeToQuoteDeco(tpe: Type): TypeToQuotedAPI } diff --git a/library/src/scala/tasty/reflect/SignatureOps.scala b/library/src/scala/tasty/reflect/SignatureOps.scala index 7ddf56461bc9..c3bfe2634c03 100644 --- a/library/src/scala/tasty/reflect/SignatureOps.scala +++ b/library/src/scala/tasty/reflect/SignatureOps.scala @@ -9,12 +9,14 @@ trait SignatureOps extends Core { def unapply(sig: Signature)(implicit ctx: Context): Option[(List[String], String)] } - trait SignatureAPI { - /** The (JVM) erased signatures of the parameters. */ - def paramSigs: List[String] - /** The (JVM) erased result type. */ - def resultSig: String + implicit class SignatureAPI(sig: Signature) { + + /** The (JVM) erased signatures of the parameters */ + def paramSigs: List[String]= kernel.Signature_paramSigs(sig) + + /** The (JVM) erased result type */ + def resultSig: String = kernel.Signature_resultSig(sig) + } - implicit def SignatureDeco(sig: Signature): SignatureAPI } diff --git a/library/src/scala/tasty/reflect/SymbolOps.scala b/library/src/scala/tasty/reflect/SymbolOps.scala index d2aec1152da0..6ed87d3deebb 100644 --- a/library/src/scala/tasty/reflect/SymbolOps.scala +++ b/library/src/scala/tasty/reflect/SymbolOps.scala @@ -6,66 +6,83 @@ trait SymbolOps extends Core { // Symbol - trait SymbolAPI { + implicit class SymbolDeco(self: Symbol) { /** Owner of this symbol. The owner is the symbol in which this symbol is defined. */ - def owner(implicit ctx: Context): Symbol + def owner(implicit ctx: Context): Symbol = kernel.Symbol_owner(self) /** Flags of this symbol */ - def flags(implicit ctx: Context): Flags - - def isLocalDummy(implicit ctx: Context): Boolean - def isRefinementClass(implicit ctx: Context): Boolean - def isAliasType(implicit ctx: Context): Boolean - def isAnonymousClass(implicit ctx: Context): Boolean - def isAnonymousFunction(implicit ctx: Context): Boolean - def isAbstractType(implicit ctx: Context): Boolean - def isClassConstructor(implicit ctx: Context): Boolean + def flags(implicit ctx: Context): Flags = kernel.Symbol_flags(self) /** This symbol is private within the resulting type. */ - def privateWithin(implicit ctx: Context): Option[Type] + def privateWithin(implicit ctx: Context): Option[Type] = kernel.Symbol_privateWithin(self) /** This symbol is protected within the resulting type. */ - def protectedWithin(implicit ctx: Context): Option[Type] + def protectedWithin(implicit ctx: Context): Option[Type] = kernel.Symbol_protectedWithin(self) /** The name of this symbol. */ - def name(implicit ctx: Context): String + def name(implicit ctx: Context): String = kernel.Symbol_name(self) /** The full name of this symbol up to the root package. */ - def fullName(implicit ctx: Context): String + def fullName(implicit ctx: Context): String = kernel.Symbol_fullName(self) /** The position of this symbol */ - def pos(implicit ctx: Context): Position + def pos(implicit ctx: Context): Position = kernel.Symbol_pos(self) - /** The comment for this symbol, if any */ - def comment(implicit ctx: Context): Option[Comment] + def localContext(implicit ctx: Context): Context = kernel.Symbol_localContext(self) - def localContext(implicit ctx: Context): Context + /** The comment for this symbol, if any */ + def comment(implicit ctx: Context): Option[Comment] = kernel.Symbol_comment(self) /** Unsafe cast as to PackageSymbol. Use IsPackageSymbol to safly check and cast to PackageSymbol */ - def asPackage(implicit ctx: Context): PackageSymbol + def asPackage(implicit ctx: Context): PackageSymbol = self match { + case IsPackageSymbol(self) => self + case _ => throw new Exception("not a PackageSymbol") + } /** Unsafe cast as to ClassSymbol. Use IsClassSymbol to safly check and cast to ClassSymbol */ - def asClass(implicit ctx: Context): ClassSymbol + def asClass(implicit ctx: Context): ClassSymbol = self match { + case IsClassSymbol(self) => self + case _ => throw new Exception("not a ClassSymbol") + } /** Unsafe cast as to DefSymbol. Use IsDefSymbol to safly check and cast to DefSymbol */ - def asDef(implicit ctx: Context): DefSymbol + def asDef(implicit ctx: Context): DefSymbol = self match { + case IsDefSymbol(self) => self + case _ => throw new Exception("not a DefSymbol") + } /** Unsafe cast as to ValSymbol. Use IsValSymbol to safly check and cast to ValSymbol */ - def asVal(implicit ctx: Context): ValSymbol + def asVal(implicit ctx: Context): ValSymbol = self match { + case IsValSymbol(self) => self + case _ => throw new Exception("not a ValSymbol") + } /** Unsafe cast as to TypeSymbol. Use IsTypeSymbol to safly check and cast to TypeSymbol */ - def asType(implicit ctx: Context): TypeSymbol + def asType(implicit ctx: Context): TypeSymbol = self match { + case IsTypeSymbol(self) => self + case _ => throw new Exception("not a TypeSymbol") + } /** Unsafe cast as to BindSymbol. Use IsBindSymbol to safly check and cast to BindSymbol */ - def asBind(implicit ctx: Context): BindSymbol + def asBind(implicit ctx: Context): BindSymbol = self match { + case IsBindSymbol(self) => self + case _ => throw new Exception("not a BindSymbol") + } /** Annotations attached to this symbol */ - def annots(implicit ctx: Context): List[Term] + def annots(implicit ctx: Context): List[Term] = kernel.Symbol_annots(self) + + def isDefinedInCurrentRun(implicit ctx: Context): Boolean = kernel.Symbol_isDefinedInCurrentRun(self) - def isDefinedInCurrentRun(implicit ctx: Context): Boolean + def isLocalDummy(implicit ctx: Context): Boolean = kernel.Symbol_isLocalDummy(self) + def isRefinementClass(implicit ctx: Context): Boolean = kernel.Symbol_isRefinementClass(self) + def isAliasType(implicit ctx: Context): Boolean = kernel.Symbol_isAliasType(self) + def isAnonymousClass(implicit ctx: Context): Boolean = kernel.Symbol_isAnonymousClass(self) + def isAnonymousFunction(implicit ctx: Context): Boolean = kernel.Symbol_isAnonymousFunction(self) + def isAbstractType(implicit ctx: Context): Boolean = kernel.Symbol_isAbstractType(self) + def isClassConstructor(implicit ctx: Context): Boolean = kernel.Symbol_isClassConstructor(self) } - implicit def SymbolDeco(symbol: Symbol): SymbolAPI // PackageSymbol diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index 89f12ae03ba4..6a907bd7507d 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -2,49 +2,18 @@ package scala.tasty package reflect trait TreeOps extends Core { - // Decorators - implicit def TreeDeco(tree: Tree): TreeAPI - implicit def PackageClauseDeco(pack: PackageClause): PackageClauseAPI - implicit def ImportDeco(imp: Import): ImportAPI - implicit def DefinitionDeco(definition: Definition): DefinitionAPI - implicit def ClassDefDeco(cdef: ClassDef): ClassDefAPI - implicit def DefDefDeco(ddef: DefDef): DefDefAPI - implicit def ValDefDeco(vdef: ValDef): ValDefAPI - implicit def TypeDefDeco(tdef: TypeDef): TypeDefAPI - implicit def PackageDefDeco(pdef: PackageDef): PackageDefAPI - implicit def TermDeco(term: Term): TermAPI - implicit def IdentDeco(ident: Term.Ident): Term.IdentAPI - implicit def SelectDeco(select: Term.Select): Term.SelectAPI - implicit def LiteralDeco(x: Term.Literal): Term.LiteralAPI - implicit def ThisDeco(x: Term.This): Term.ThisAPI - implicit def NewDeco(x: Term.New): Term.NewAPI - implicit def NamedArgDeco(x: Term.NamedArg): Term.NamedArgAPI - implicit def ApplyDeco(x: Term.Apply): Term.ApplyAPI - implicit def TypeApplyDeco(x: Term.TypeApply): Term.TypeApplyAPI - implicit def SuperDeco(x: Term.Super): Term.SuperAPI - implicit def TypedDeco(x: Term.Typed): Term.TypedAPI - implicit def AssignDeco(x: Term.Assign): Term.AssignAPI - implicit def BlockDeco(x: Term.Block): Term.BlockAPI - implicit def LambdaDeco(x: Term.Lambda): Term.LambdaAPI - implicit def IfDeco(x: Term.If): Term.IfAPI - implicit def MatchDeco(x: Term.Match): Term.MatchAPI - implicit def TryDeco(x: Term.Try): Term.TryAPI - implicit def ReturnDeco(x: Term.Return): Term.ReturnAPI - implicit def RepeatedDeco(x: Term.Repeated): Term.RepeatedAPI - implicit def InlinedDeco(x: Term.Inlined): Term.InlinedAPI - implicit def SelectOuterDeco(x: Term.SelectOuter): Term.SelectOuterAPI - implicit def WhileDeco(x: Term.While): Term.WhileAPI + // Decorators implicit def termAsTermOrTypeTree(term: Term): TermOrTypeTree // ----- Tree ----------------------------------------------------- - trait TreeAPI { + implicit class TreeAPI(self: Tree) { /** Position in the source code */ - def pos(implicit ctx: Context): Position + def pos(implicit ctx: Context): Position = kernel.Tree_pos(self) - def symbol(implicit ctx: Context): Symbol + def symbol(implicit ctx: Context): Symbol = kernel.Tree_symbol(self) } val IsPackageClause: IsPackageClauseModule @@ -59,9 +28,9 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[(Term.Ref, List[Tree])] } - trait PackageClauseAPI { - def pid(implicit ctx: Context): Term.Ref - def stats(implicit ctx: Context): List[Tree] + implicit class PackageClauseAPI(self: PackageClause) { + def pid(implicit ctx: Context): Term.Ref = kernel.PackageClause_pid(self) + def stats(implicit ctx: Context): List[Tree] = kernel.PackageClause_stats(self) } val IsImport: IsImportModule @@ -76,10 +45,10 @@ trait TreeOps extends Core { def unapply(imp: Tree)(implicit ctx: Context): Option[(Boolean, Term, List[ImportSelector])] } - trait ImportAPI { - def impliedOnly: Boolean - def expr(implicit ctx: Context): Term - def selectors(implicit ctx: Context): List[ImportSelector] + implicit class ImportAPI(self: Import) { + def impliedOnly: Boolean = kernel.Import_impliedOnly(self) + def expr(implicit ctx: Context): Term = kernel.Import_expr(self) + def selectors(implicit ctx: Context): List[ImportSelector] = kernel.Import_selectors(self) } val IsStatement: IsStatementModule @@ -95,8 +64,8 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Definition] } - trait DefinitionAPI { - def name(implicit ctx: Context): String + implicit class DefinitionAPI(self: Definition) { + def name(implicit ctx: Context): String = kernel.Definition_name(self) } // ClassDef @@ -113,14 +82,13 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[(String, DefDef, List[TermOrTypeTree], List[TypeTree], Option[ValDef], List[Statement])] } - trait ClassDefAPI { - def constructor(implicit ctx: Context): DefDef - def parents(implicit ctx: Context): List[TermOrTypeTree] - def derived(implicit ctx: Context): List[TypeTree] - def self(implicit ctx: Context): Option[ValDef] - def body(implicit ctx: Context): List[Statement] - - def symbol(implicit ctx: Context): ClassSymbol + implicit class ClassDefAPI(self: ClassDef) { + def constructor(implicit ctx: Context): DefDef = kernel.ClassDef_constructor(self) + def parents(implicit ctx: Context): List[TermOrTypeTree] = kernel.ClassDef_parents(self) + def derived(implicit ctx: Context): List[TypeTree] = kernel.ClassDef_derived(self) + def self(implicit ctx: Context): Option[ValDef] = kernel.ClassDef_self(self) + def body(implicit ctx: Context): List[Statement] = kernel.ClassDef_body(self) + def symbol(implicit ctx: Context): ClassSymbol = kernel.ClassDef_symbol(self) } // DefDef @@ -137,13 +105,12 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] } - trait DefDefAPI { - def typeParams(implicit ctx: Context): List[TypeDef] - def paramss(implicit ctx: Context): List[List[ValDef]] - def returnTpt(implicit ctx: Context): TypeTree - def rhs(implicit ctx: Context): Option[Term] - - def symbol(implicit ctx: Context): DefSymbol + implicit class DefDefAPI(self: DefDef) { + def typeParams(implicit ctx: Context): List[TypeDef] = kernel.DefDef_typeParams(self) + def paramss(implicit ctx: Context): List[List[ValDef]] = kernel.DefDef_paramss(self) + def returnTpt(implicit ctx: Context): TypeTree = kernel.DefDef_returnTpt(self) + def rhs(implicit ctx: Context): Option[Term] = kernel.DefDef_rhs(self) + def symbol(implicit ctx: Context): DefSymbol = kernel.DefDef_symbol(self) } // ValDef @@ -160,11 +127,10 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeTree, Option[Term])] } - trait ValDefAPI { - def tpt(implicit ctx: Context): TypeTree - def rhs(implicit ctx: Context): Option[Term] - - def symbol(implicit ctx: Context): ValSymbol + implicit class ValDefAPI(self: ValDef) { + def tpt(implicit ctx: Context): TypeTree = kernel.ValDef_tpt(self) + def rhs(implicit ctx: Context): Option[Term] = kernel.ValDef_rhs(self) + def symbol(implicit ctx: Context): ValSymbol = kernel.ValDef_symbol(self) } // TypeDef @@ -181,9 +147,9 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree /* TypeTree | TypeBoundsTree */)] } - trait TypeDefAPI { - def rhs(implicit ctx: Context): TypeOrBoundsTree - def symbol(implicit ctx: Context): TypeSymbol + implicit class TypeDefAPI(self: TypeDef) { + def rhs(implicit ctx: Context): TypeOrBoundsTree = kernel.TypeDef_rhs(self) + def symbol(implicit ctx: Context): TypeSymbol = kernel.TypeDef_symbol(self) } // PackageDef @@ -193,10 +159,10 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[PackageDef] } - trait PackageDefAPI { - def owner(implicit ctx: Context): PackageDef - def members(implicit ctx: Context): List[Statement] - def symbol(implicit ctx: Context): PackageSymbol + implicit class PackageDefAPI(self: PackageDef) { + def owner(implicit ctx: Context): PackageDef = kernel.PackageDef_owner(self) + def members(implicit ctx: Context): List[Statement] = kernel.PackageDef_members(self) + def symbol(implicit ctx: Context): PackageSymbol = kernel.PackageDef_symbol(self) } val PackageDef: PackageDefModule @@ -206,11 +172,11 @@ trait TreeOps extends Core { // ----- Terms ---------------------------------------------------- - trait TermAPI { - def tpe(implicit ctx: Context): Type - def pos(implicit ctx: Context): Position - def underlyingArgument(implicit ctx: Context): Term - def underlying(implicit ctx: Context): Term + implicit class TermAPI(self: Term) { + def tpe(implicit ctx: Context): Type = kernel.Term_tpe(self) + def pos(implicit ctx: Context): Position = kernel.Term_pos(self) + def underlyingArgument(implicit ctx: Context): Term = kernel.Term_underlyingArgument(self) + def underlying(implicit ctx: Context): Term = kernel.Term_underlying(self) } val IsTerm: IsTermModule @@ -231,10 +197,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Ident] } - trait IdentAPI { - def name(implicit ctx: Context): String - } - val Ref: RefModule abstract class RefModule { @@ -263,12 +225,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Select] } - trait SelectAPI { - def qualifier(implicit ctx: Context): Term - def name(implicit ctx: Context): String - def signature(implicit ctx: Context): Option[Signature] - } - /** Scala term selection */ val Select: SelectModule abstract class SelectModule { @@ -295,10 +251,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Literal] } - trait LiteralAPI { - def constant(implicit ctx: Context): Constant - } - /** Scala literal constant */ val Literal: LiteralModule abstract class LiteralModule { @@ -319,10 +271,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[This] } - trait ThisAPI { - def id(implicit ctx: Context): Option[Id] - } - /** Scala `this` or `this[id]` */ val This: ThisModule abstract class ThisModule { @@ -343,10 +291,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[New] } - trait NewAPI { - def tpt(implicit ctx: Context): TypeTree - } - /** Scala `new` */ val New: NewModule abstract class NewModule { @@ -367,11 +311,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[NamedArg] } - trait NamedArgAPI { - def name(implicit ctx: Context): String - def value(implicit ctx: Context): Term - } - /** Scala named argument `x = y` in argument position */ val NamedArg: NamedArgModule abstract class NamedArgModule { @@ -392,11 +331,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Apply] } - trait ApplyAPI { - def fun(implicit ctx: Context): Term - def args(implicit ctx: Context): List[Term] - } - /** Scala parameter application */ val Apply: ApplyModule abstract class ApplyModule { @@ -417,11 +351,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[TypeApply] } - trait TypeApplyAPI { - def fun(implicit ctx: Context): Term - def args(implicit ctx: Context): List[TypeTree] - } - /** Scala type parameter application */ val TypeApply: TypeApplyModule abstract class TypeApplyModule { @@ -442,11 +371,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Super] } - trait SuperAPI { - def qualifier(implicit ctx: Context): Term - def id(implicit ctx: Context): Option[Id] - } - /** Scala `x.super` or `x.super[id]` */ val Super: SuperModule abstract class SuperModule { @@ -467,11 +391,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Typed] } - trait TypedAPI { - def expr(implicit ctx: Context): Term - def tpt(implicit ctx: Context): Term - } - /** Scala ascription `x: T` */ val Typed: TypedModule abstract class TypedModule { @@ -492,11 +411,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Assign] } - trait AssignAPI { - def lhs(implicit ctx: Context): Term - def rhs(implicit ctx: Context): Term - } - /** Scala assign `x = y` */ val Assign: AssignModule abstract class AssignModule { @@ -517,11 +431,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Block] } - trait BlockAPI { - def statements(implicit ctx: Context): List[Statement] - def expr(implicit ctx: Context): Term - } - /** Scala code block `{ stat0; ...; statN; expr }` term */ val Block: BlockModule abstract class BlockModule { @@ -542,11 +451,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Lambda] } - trait LambdaAPI { - def meth(implicit ctx: Context): Term - def tptOpt(implicit ctx: Context): Option[TypeTree] - } - val Lambda: LambdaModule abstract class LambdaModule { @@ -564,12 +468,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[If] } - trait IfAPI { - def cond(implicit ctx: Context): Term - def thenp(implicit ctx: Context): Term - def elsep(implicit ctx: Context): Term - } - /** Scala `if`/`else` term */ val If: IfModule abstract class IfModule { @@ -590,11 +488,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Match] } - trait MatchAPI { - def scrutinee(implicit ctx: Context): Term - def cases(implicit ctx: Context): List[CaseDef] - } - /** Scala `match` term */ val Match: MatchModule abstract class MatchModule { @@ -615,12 +508,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Try] } - trait TryAPI { - def body(implicit ctx: Context): Term - def cases(implicit ctx: Context): List[CaseDef] - def finalizer(implicit ctx: Context): Option[Term] - } - /** Scala `try`/`catch`/`finally` term */ val Try: TryModule abstract class TryModule { @@ -641,10 +528,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Return] } - trait ReturnAPI { - def expr(implicit ctx: Context): Term - } - /** Scala local `return` */ val Return: ReturnModule abstract class ReturnModule { @@ -665,11 +548,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Repeated] } - trait RepeatedAPI { - def elems(implicit ctx: Context): List[Term] - def elemtpt(implicit ctx: Context): TypeTree - } - val Repeated: RepeatedModule abstract class RepeatedModule { @@ -687,12 +565,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[Inlined] } - trait InlinedAPI { - def call(implicit ctx: Context): Option[TermOrTypeTree] - def bindings(implicit ctx: Context): List[Definition] - def body(implicit ctx: Context): Term - } - val Inlined: InlinedModule abstract class InlinedModule { @@ -710,12 +582,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[SelectOuter] } - trait SelectOuterAPI { - def qualifier(implicit ctx: Context): Term - def level(implicit ctx: Context): Int - def tpe(implicit ctx: Context): Type - } - val SelectOuter: SelectOuterModule abstract class SelectOuterModule { @@ -733,11 +599,6 @@ trait TreeOps extends Core { def unapply(tree: Tree)(implicit ctx: Context): Option[While] } - trait WhileAPI { - def cond(implicit ctx: Context): Term - def body(implicit ctx: Context): Term - } - val While: WhileModule abstract class WhileModule { @@ -752,4 +613,109 @@ trait TreeOps extends Core { } } + implicit class Term_IdentAPI(self: Term.Ident) { + def name(implicit ctx: Context): String = kernel.Term_Ident_name(self) + } + + implicit class Term_SelectAPI(self: Term.Select) { + def qualifier(implicit ctx: Context): Term = kernel.Term_Select_qualifier(self) + def name(implicit ctx: Context): String = kernel.Term_Select_name(self) + def signature(implicit ctx: Context): Option[Signature] = kernel.Term_Select_signature(self) + } + + implicit class Term_LiteralAPI(self: Term.Literal) { + def constant(implicit ctx: Context): Constant = kernel.Term_Literal_constant(self) + } + + implicit class Term_ThisAPI(self: Term.This) { + def id(implicit ctx: Context): Option[Id] = kernel.Term_This_id(self) + } + + implicit class Term_NewAPI(self: Term.New) { + def tpt(implicit ctx: Context): TypeTree = kernel.Term_New_tpt(self) + } + + implicit class Term_NamedArgAPI(self: Term.NamedArg) { + def name(implicit ctx: Context): String = kernel.Term_NamedArg_name(self) + def value(implicit ctx: Context): Term = kernel.Term_NamedArg_value(self) + } + + implicit class Term_ApplyAPI(self: Term.Apply) { + def fun(implicit ctx: Context): Term = kernel.Term_Apply_fun(self) + def args(implicit ctx: Context): List[Term] = kernel.Term_Apply_args(self) + } + + implicit class Term_TypeApplyAPI(self: Term.TypeApply) { + def fun(implicit ctx: Context): Term = kernel.Term_TypeApply_fun(self) + def args(implicit ctx: Context): List[TypeTree] = kernel.Term_TypeApply_args(self) + } + + implicit class Term_SuperAPI(self: Term.Super) { + def qualifier(implicit ctx: Context): Term = kernel.Term_Super_qualifier(self) + def id(implicit ctx: Context): Option[Id] = kernel.Term_Super_id(self) + } + + implicit class Term_TypedAPI(self: Term.Typed) { + def expr(implicit ctx: Context): Term = kernel.Term_Typed_expr(self) + def tpt(implicit ctx: Context): TypeTree = kernel.Term_Typed_tpt(self) + } + + implicit class Term_AssignAPI(self: Term.Assign) { + def lhs(implicit ctx: Context): Term = kernel.Term_Assign_lhs(self) + def rhs(implicit ctx: Context): Term = kernel.Term_Assign_rhs(self) + } + + implicit class Term_BlockAPI(self: Term.Block) { + def statements(implicit ctx: Context): List[Statement] = kernel.Term_Block_statements(self) + def expr(implicit ctx: Context): Term = kernel.Term_Block_expr(self) + } + + implicit class Term_LambdaAPI(self: Term.Lambda) { + def meth(implicit ctx: Context): Term = kernel.Term_Lambda_meth(self) + def tptOpt(implicit ctx: Context): Option[TypeTree] = kernel.Term_Lambda_tptOpt(self) + } + + implicit class Term_IfAPI(self: Term.If) { + def cond(implicit ctx: Context): Term = kernel.Term_If_cond(self) + def thenp(implicit ctx: Context): Term = kernel.Term_If_thenp(self) + def elsep(implicit ctx: Context): Term = kernel.Term_If_elsep(self) + } + + implicit class Term_MatchAPI(self: Term.Match) { + def scrutinee(implicit ctx: Context): Term = kernel.Term_Match_scrutinee(self) + def cases(implicit ctx: Context): List[CaseDef] = kernel.Term_Match_cases(self) + } + + implicit class Term_TryAPI(self: Term.Try) { + def body(implicit ctx: Context): Term = kernel.Term_Try_body(self) + def cases(implicit ctx: Context): List[CaseDef] = kernel.Term_Try_cases(self) + def finalizer(implicit ctx: Context): Option[Term] = kernel.Term_Try_finalizer(self) + } + + implicit class Term_ReturnAPI(self: Term.Return) { + def expr(implicit ctx: Context): Term = kernel.Term_Return_expr(self) + } + + implicit class Term_RepeatedAPI(self: Term.Repeated) { + def elems(implicit ctx: Context): List[Term] = kernel.Term_Repeated_elems(self) + def elemtpt(implicit ctx: Context): TypeTree = kernel.Term_Repeated_elemtpt(self) + } + + implicit class Term_InlinedAPI(self: Term.Inlined) { + def call(implicit ctx: Context): Option[TermOrTypeTree] = kernel.Term_Inlined_call(self) + def bindings(implicit ctx: Context): List[Definition] = kernel.Term_Inlined_bindings(self) + def body(implicit ctx: Context): Term = kernel.Term_Inlined_body(self) + } + + implicit class Term_SelectOuterAPI(self: Term.SelectOuter) { + def qualifier(implicit ctx: Context): Term = kernel.Term_SelectOuter_qualifier(self) + def level(implicit ctx: Context): Int = kernel.Term_SelectOuter_level(self) + def tpe(implicit ctx: Context): Type = kernel.Term_SelectOuter_tpe(self) + } + + implicit class Term_WhileAPI(self: Term.While) { + def cond(implicit ctx: Context): Term = kernel.Term_While_cond(self) + def body(implicit ctx: Context): Term = kernel.Term_While_body(self) + } + } diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala index 9e3beb602f37..b3754374045e 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala @@ -3,60 +3,18 @@ package reflect trait TypeOrBoundsOps extends Core { - implicit def TypeDeco(tpe: Type): TypeAPI - - implicit def ConstantTypeDeco(x: ConstantType): Type.ConstantTypeAPI - - implicit def SymRefDeco(x: SymRef): Type.SymRefAPI - - implicit def TermRefDeco(x: TermRef): Type.TermRefAPI - - implicit def TypeRefDeco(x: TypeRef): Type.TypeRefAPI - - implicit def SuperTypeDeco(x: SuperType): Type.SuperTypeAPI - - implicit def RefinementDeco(x: Refinement): Type.RefinementAPI - - implicit def AppliedTypeDeco(x: AppliedType): Type.AppliedTypeAPI - - implicit def AnnotatedTypeDeco(x: AnnotatedType): Type.AnnotatedTypeAPI - - implicit def AndTypeDeco(x: AndType): Type.AndTypeAPI - - implicit def OrTypeDeco(x: OrType): Type.OrTypeAPI - - implicit def MatchTypeDeco(x: MatchType): Type.MatchTypeAPI - - implicit def ByNameTypeDeco(x: ByNameType): Type.ByNameTypeAPI - - implicit def ParamRefDeco(x: ParamRef): Type.ParamRefAPI - - implicit def ThisTypeDeco(x: ThisType): Type.ThisTypeAPI - - implicit def RecursiveThisDeco(x: RecursiveThis): Type.RecursiveThisAPI - - implicit def RecursiveTypeDeco(x: RecursiveType): Type.RecursiveTypeAPI - - implicit def MethodTypeDeco(x: MethodType): Type.MethodTypeAPI - - implicit def PolyTypeDeco(x: PolyType): Type.PolyTypeAPI - - implicit def TypeLambdaDeco(x: TypeLambda): Type.TypeLambdaAPI - - implicit def TypeBoundsDeco(bounds: TypeBounds): TypeBoundsAPI - // ----- Types ---------------------------------------------------- def typeOf[T: scala.quoted.Type]: Type - trait TypeAPI { - def =:=(other: Type)(implicit ctx: Context): Boolean - def <:<(other: Type)(implicit ctx: Context): Boolean - def widen(implicit ctx: Context): Type - def classSymbol(implicit ctx: Context): Option[ClassSymbol] - def typeSymbol(implicit ctx: Context): Symbol - def isSingleton(implicit ctx: Context): Boolean - def memberType(member: Symbol)(implicit ctx: Context): Type + implicit class TypeAPI(self: Type) { + def =:=(that: Type)(implicit ctx: Context): Boolean = kernel.`Type_=:=`(self)(that) + def <:<(that: Type)(implicit ctx: Context): Boolean = kernel.`Type_<:<`(self)(that) + def widen(implicit ctx: Context): Type = kernel.Type_widen(self) + def classSymbol(implicit ctx: Context): Option[ClassSymbol] = kernel.Type_classSymbol(self) + def typeSymbol(implicit ctx: Context): Symbol = kernel.Type_typeSymbol(self) + def isSingleton(implicit ctx: Context): Boolean = kernel.Type_isSingleton(self) + def memberType(member: Symbol)(implicit ctx: Context): Type = kernel.Type_memberType(self)(member) } val IsType: IsTypeModule @@ -73,10 +31,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] } - trait ConstantTypeAPI { - def value(implicit ctx: Context): Any - } - val ConstantType: ConstantTypeModule abstract class ConstantTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Constant] @@ -88,10 +42,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] } - trait SymRefAPI { - def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ - } - val SymRef: SymRefModule abstract class SymRefModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] @@ -103,10 +53,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] } - trait TermRefAPI { - def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ - } - val TermRef: TermRefModule abstract class TermRefModule { def apply(qual: TypeOrBounds, name: String)(implicit ctx: Context): TermRef @@ -119,11 +65,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] } - trait TypeRefAPI { - def name(implicit ctx: Context): String - def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ - } - val TypeRef: TypeRefModule abstract class TypeRefModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] @@ -135,11 +76,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] } - trait SuperTypeAPI { - def thistpe(implicit ctx: Context): Type - def supertpe(implicit ctx: Context): Type - } - val SuperType: SuperTypeModule abstract class SuperTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] @@ -151,12 +87,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] } - trait RefinementAPI { - def parent(implicit ctx: Context): Type - def name(implicit ctx: Context): String - def info(implicit ctx: Context): TypeOrBounds - } - val Refinement: RefinementModule abstract class RefinementModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] @@ -168,11 +98,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] } - trait AppliedTypeAPI { - def tycon(implicit ctx: Context): Type - def args(implicit ctx: Context): List[TypeOrBounds /* Type | TypeBounds */] - } - val AppliedType: AppliedTypeModule abstract class AppliedTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] @@ -184,11 +109,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] } - trait AnnotatedTypeAPI { - def underlying(implicit ctx: Context): Type - def annot(implicit ctx: Context): Term - } - val AnnotatedType: AnnotatedTypeModule abstract class AnnotatedTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Term)] @@ -200,11 +120,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] } - trait AndTypeAPI { - def left(implicit ctx: Context): Type - def right(implicit ctx: Context): Type - } - val AndType: AndTypeModule abstract class AndTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] @@ -216,11 +131,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] } - trait OrTypeAPI { - def left(implicit ctx: Context): Type - def right(implicit ctx: Context): Type - } - val OrType: OrTypeModule abstract class OrTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] @@ -232,12 +142,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] } - trait MatchTypeAPI { - def bound(implicit ctx: Context): Type - def scrutinee(implicit ctx: Context): Type - def cases(implicit ctx: Context): List[Type] - } - val MatchType: MatchTypeModule abstract class MatchTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type, List[Type])] @@ -249,10 +153,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] } - trait ByNameTypeAPI { - def underlying(implicit ctx: Context): Type - } - val ByNameType: ByNameTypeModule abstract class ByNameTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] @@ -264,11 +164,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] } - trait ParamRefAPI { - def binder(implicit ctx: Context): LambdaType[TypeOrBounds] - def paramNum(implicit ctx: Context): Int - } - val ParamRef: ParamRefModule abstract class ParamRefModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] @@ -280,10 +175,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] } - trait ThisTypeAPI { - def underlying(implicit ctx: Context): Type - } - val ThisType: ThisTypeModule abstract class ThisTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] @@ -295,10 +186,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] } - trait RecursiveThisAPI { - def binder(implicit ctx: Context): RecursiveType - } - val RecursiveThis: RecursiveThisModule abstract class RecursiveThisModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] @@ -310,10 +197,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] } - trait RecursiveTypeAPI { - def underlying(implicit ctx: Context): Type - } - val RecursiveType: RecursiveTypeModule abstract class RecursiveTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] @@ -325,14 +208,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] } - trait MethodTypeAPI { - def isImplicit: Boolean - def isErased: Boolean - def paramNames(implicit ctx: Context): List[String] - def paramTypes(implicit ctx: Context): List[Type] - def resType(implicit ctx: Context): Type - } - val MethodType: MethodTypeModule abstract class MethodTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[Type], Type)] @@ -344,12 +219,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] } - trait PolyTypeAPI { - def paramNames(implicit ctx: Context): List[String] - def paramBounds(implicit ctx: Context): List[TypeBounds] - def resType(implicit ctx: Context): Type - } - val PolyType: PolyTypeModule abstract class PolyTypeModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] @@ -361,12 +230,6 @@ trait TypeOrBoundsOps extends Core { def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] } - trait TypeLambdaAPI { - def paramNames(implicit ctx: Context): List[String] - def paramBounds(implicit ctx: Context): List[TypeBounds] - def resType(implicit ctx: Context): Type - } - val TypeLambda: TypeLambdaModule abstract class TypeLambdaModule { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] @@ -374,6 +237,101 @@ trait TypeOrBoundsOps extends Core { } + implicit class Type_ConstantTypeAPI(self: ConstantType) { + def value(implicit ctx: Context): Any = kernel.ConstantType_value(self) + } + + implicit class Type_SymRefAPI(self: SymRef) { + def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ = kernel.SymRef_qualifier(self) + } + + implicit class Type_TermRefAPI(self: TermRef) { + def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ = kernel.TermRef_qualifier(self) + } + + implicit class Type_TypeRefAPI(self: TypeRef) { + def name(implicit ctx: Context): String = kernel.TypeRef_name(self) + def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ = kernel.TypeRef_qualifier(self) + } + + implicit class Type_SuperTypeAPI(self: SuperType) { + def thistpe(implicit ctx: Context): Type = kernel.SuperType_thistpe(self) + def supertpe(implicit ctx: Context): Type = kernel.SuperType_supertpe(self) + } + + implicit class Type_RefinementAPI(self: Refinement) { + def parent(implicit ctx: Context): Type = kernel.Refinement_parent(self) + def name(implicit ctx: Context): String = kernel.Refinement_name(self) + def info(implicit ctx: Context): TypeOrBounds = kernel.Refinement_info(self) + } + + implicit class Type_AppliedTypeAPI(self: AppliedType) { + def tycon(implicit ctx: Context): Type = kernel.AppliedType_tycon(self) + def args(implicit ctx: Context): List[TypeOrBounds /* Type | TypeBounds */] = kernel.AppliedType_args(self) + } + + implicit class Type_AnnotatedTypeAPI(self: AnnotatedType) { + def underlying(implicit ctx: Context): Type = kernel.AnnotatedType_underlying(self) + def annot(implicit ctx: Context): Term = kernel.AnnotatedType_annot(self) + } + + implicit class Type_AndTypeAPI(self: AndType) { + def left(implicit ctx: Context): Type = kernel.AndType_left(self) + def right(implicit ctx: Context): Type = kernel.AndType_right(self) + } + + implicit class Type_OrTypeAPI(self: OrType) { + def left(implicit ctx: Context): Type = kernel.OrType_left(self) + def right(implicit ctx: Context): Type = kernel.OrType_right(self) + } + + implicit class Type_MatchTypeAPI(self: MatchType) { + def bound(implicit ctx: Context): Type = kernel.MatchType_bound(self) + def scrutinee(implicit ctx: Context): Type = kernel.MatchType_scrutinee(self) + def cases(implicit ctx: Context): List[Type] = kernel.MatchType_cases(self) + } + + implicit class Type_ByNameTypeAPI(self: ByNameType) { + def underlying(implicit ctx: Context): Type = kernel.ByNameType_underlying(self) + } + + implicit class Type_ParamRefAPI(self: ParamRef) { + def binder(implicit ctx: Context): LambdaType[TypeOrBounds] = kernel.ParamRef_binder(self) + def paramNum(implicit ctx: Context): Int = kernel.ParamRef_paramNum(self) + } + + implicit class Type_ThisTypeAPI(self: ThisType) { + def underlying(implicit ctx: Context): Type = kernel.ThisType_underlying(self) + } + + implicit class Type_RecursiveThisAPI(self: RecursiveThis) { + def binder(implicit ctx: Context): RecursiveType = kernel.RecursiveThis_binder(self) + } + + implicit class Type_RecursiveTypeAPI(self: RecursiveType) { + def underlying(implicit ctx: Context): Type = kernel.RecursiveType_underlying(self) + } + + implicit class Type_MethodTypeAPI(self: MethodType) { + def isImplicit: Boolean = kernel.MethodType_isImplicit(self) + def isErased: Boolean = kernel.MethodType_isErased(self) + def paramNames(implicit ctx: Context): List[String] = kernel.MethodType_paramNames(self) + def paramTypes(implicit ctx: Context): List[Type] = kernel.MethodType_paramTypes(self) + def resType(implicit ctx: Context): Type = kernel.MethodType_resType(self) + } + + implicit class Type_PolyTypeAPI(self: PolyType) { + def paramNames(implicit ctx: Context): List[String] = kernel.PolyType_paramNames(self) + def paramBounds(implicit ctx: Context): List[TypeBounds] = kernel.PolyType_paramBounds(self) + def resType(implicit ctx: Context): Type = kernel.PolyType_resType(self) + } + + implicit class Type_TypeLambdaAPI(self: TypeLambda) { + def paramNames(implicit ctx: Context): List[String] = kernel.TypeLambda_paramNames(self) + def paramBounds(implicit ctx: Context): List[TypeBounds] = kernel.TypeLambda_paramBounds(self) + def resType(implicit ctx: Context): Type = kernel.TypeLambda_resType(self) + } + // ----- TypeBounds ----------------------------------------------- val IsTypeBounds: IsTypeBoundsModule @@ -386,9 +344,9 @@ trait TypeOrBoundsOps extends Core { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] } - trait TypeBoundsAPI { - def low(implicit ctx: Context): Type - def hi(implicit ctx: Context): Type + implicit class TypeBoundsAPI(self: TypeBounds) { + def low(implicit ctx: Context): Type = kernel.TypeBounds_low(self) + def hi(implicit ctx: Context): Type = kernel.TypeBounds_hi(self) } // ----- NoPrefix ------------------------------------------------- diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala index 35a1d8125080..a44c7d9fae58 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala @@ -3,39 +3,23 @@ package reflect trait TypeOrBoundsTreeOps extends Core { - implicit def TypeOrBoundsTreeDeco(tpt: TypeOrBoundsTree): TypeOrBoundsTreeAPI - - implicit def TypeTreeDeco(tpt: TypeTree): TypeTreeAPI - implicit def InferredDeco(x: TypeTree.Inferred): TypeTree.InferredAPI - implicit def TypeIdentDeco(x: TypeTree.Ident): TypeTree.IdentAPI - implicit def TypeSelectDeco(x: TypeTree.Select): TypeTree.SelectAPI - implicit def ProjectionDeco(x: TypeTree.Projection): TypeTree.ProjectionAPI - implicit def SingletonDeco(x: TypeTree.Singleton): TypeTree.SingletonAPI - implicit def RefinedDeco(x: TypeTree.Refined): TypeTree.RefinedAPI - implicit def AppliedDeco(x: TypeTree.Applied): TypeTree.AppliedAPI - implicit def AnnotatedDeco(x: TypeTree.Annotated): TypeTree.AnnotatedAPI - implicit def MatchTypeTreeDeco(x: TypeTree.MatchType): TypeTree.MatchTypeAPI - implicit def ByNameDeco(x: TypeTree.ByName): TypeTree.ByNameAPI - implicit def LambdaTypeTreeDeco(x: TypeTree.LambdaTypeTree): TypeTree.LambdaTypeTreeAPI - implicit def TypeBindDeco(x: TypeTree.TypeBind): TypeTree.TypeBindAPI - implicit def TypeBlockDeco(x: TypeTree.TypeBlock): TypeTree.TypeBlockAPI - - implicit def TypeBoundsTreeDeco(tpt: TypeBoundsTree): TypeBoundsTreeAPI - implicit def typeTreeAsParent(term: TypeTree): TermOrTypeTree - trait TypeOrBoundsTreeAPI { - def tpe(implicit ctx: Context): TypeOrBounds + implicit class TypeOrBoundsTreeAPI(self: TypeOrBoundsTree) { + def tpe(implicit ctx: Context): TypeOrBounds = kernel.TypeOrBoundsTree_tpe(self) } // ----- TypeTrees ------------------------------------------------ - trait TypeTreeAPI { + implicit class TypeTreeAPI(self: TypeTree) { /** Position in the source code */ - def pos(implicit ctx: Context): Position + def pos(implicit ctx: Context): Position = kernel.TypeTree_pos(self) + + /** Type of this type tree */ + def tpe(implicit ctx: Context): Type = kernel.TypeTree_tpe(self) - def tpe(implicit ctx: Context): Type - def symbol(implicit ctx: Context): Symbol + /** Symbol of this type tree */ + def symbol(implicit ctx: Context): Symbol = kernel.TypeTree_symbol(self) } val IsTypeTree: IsTypeTreeModule @@ -53,9 +37,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Inferred] } - trait InferredAPI { - } - /** TypeTree containing an inferred type */ val Inferred: InferredModule abstract class InferredModule { @@ -70,10 +51,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Ident] } - trait IdentAPI { - def name(implicit ctx: Context): String - } - val Ident: IdentModule abstract class IdentModule { // TODO def apply(name: String)(implicit ctx: Context): Ident @@ -87,11 +64,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Select] } - trait SelectAPI { - def qualifier(implicit ctx: Context): Term - def name(implicit ctx: Context): String - } - val Select: SelectModule abstract class SelectModule { def apply(qualifier: Term, name: String)(implicit ctx: Context): Select @@ -105,11 +77,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Projection] } - trait ProjectionAPI { - def qualifier(implicit ctx: Context): TypeTree - def name(implicit ctx: Context): String - } - val Projection: ProjectionModule abstract class ProjectionModule { // TODO def apply(qualifier: TypeTree, name: String)(implicit ctx: Context): Project @@ -123,10 +90,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Singleton] } - trait SingletonAPI { - def ref(implicit ctx: Context): Term - } - val Singleton: SingletonModule abstract class SingletonModule { def apply(ref: Term)(implicit ctx: Context): Singleton @@ -140,11 +103,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Refined] } - trait RefinedAPI { - def tpt(implicit ctx: Context): TypeTree - def refinements(implicit ctx: Context): List[Definition] - } - val Refined: RefinedModule abstract class RefinedModule { // TODO def apply(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): Refined @@ -158,11 +116,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Applied] } - trait AppliedAPI { - def tpt(implicit ctx: Context): TypeTree - def args(implicit ctx: Context): List[TypeOrBoundsTree] - } - val Applied: AppliedModule abstract class AppliedModule { def apply(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied @@ -176,11 +129,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Annotated] } - trait AnnotatedAPI { - def arg(implicit ctx: Context): TypeTree - def annotation(implicit ctx: Context): Term - } - val Annotated: AnnotatedModule abstract class AnnotatedModule { def apply(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated @@ -194,12 +142,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[MatchType] } - trait MatchTypeAPI { - def bound(implicit ctx: Context): Option[TypeTree] - def selector(implicit ctx: Context): TypeTree - def cases(implicit ctx: Context): List[TypeCaseDef] - } - val MatchType: MatchTypeModule abstract class MatchTypeModule { def apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType @@ -213,10 +155,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[ByName] } - trait ByNameAPI { - def result(implicit ctx: Context): TypeTree - } - val ByName: ByNameModule abstract class ByNameModule { def apply(result: TypeTree)(implicit ctx: Context): ByName @@ -230,11 +168,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[LambdaTypeTree] } - trait LambdaTypeTreeAPI { - def tparams(implicit ctx: Context): List[TypeDef] - def body(implicit ctx: Context): TypeOrBoundsTree - } - val LambdaTypeTree: LambdaTypeTreeModule abstract class LambdaTypeTreeModule { def apply(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree @@ -248,11 +181,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBind] } - trait TypeBindAPI { - def name(implicit ctx: Context): String - def body(implicit ctx: Context): TypeOrBoundsTree - } - val TypeBind: TypeBindModule abstract class TypeBindModule { // TODO def apply(name: String, tpt: TypeOrBoundsTree)(implicit ctx: Context): TypeBind @@ -266,11 +194,6 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBlock] } - trait TypeBlockAPI { - def aliases(implicit ctx: Context): List[TypeDef] - def tpt(implicit ctx: Context): TypeTree - } - val TypeBlock: TypeBlockModule abstract class TypeBlockModule { def apply(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock @@ -279,12 +202,70 @@ trait TypeOrBoundsTreeOps extends Core { } } + implicit class TypeTree_IdentAPI(self: TypeTree.Ident) { + def name(implicit ctx: Context): String = kernel.TypeTree_Ident_name(self) + } + + implicit class TypeTree_SelectAPI(self: TypeTree.Select) { + def qualifier(implicit ctx: Context): Term = kernel.TypeTree_Select_qualifier(self) + def name(implicit ctx: Context): String = kernel.TypeTree_Select_name(self) + } + + implicit class TypeTree_ProjectionAPI(self: TypeTree.Projection) { + def qualifier(implicit ctx: Context): TypeTree = kernel.TypeTree_Projection_qualifier(self) + def name(implicit ctx: Context): String = kernel.TypeTree_Projection_name(self) + } + + implicit class TypeTree_SingletonAPI(self: TypeTree.Singleton) { + def ref(implicit ctx: Context): Term = kernel.TypeTree_Singleton_ref(self) + } + + implicit class TypeTree_RefinedAPI(self: TypeTree.Refined) { + def tpt(implicit ctx: Context): TypeTree = kernel.TypeTree_Refined_tpt(self) + def refinements(implicit ctx: Context): List[Definition] = kernel.TypeTree_Refined_refinements(self) + } + + implicit class TypeTree_AppliedAPI(self: TypeTree.Applied) { + def tpt(implicit ctx: Context): TypeTree = kernel.TypeTree_Applied_tpt(self) + def args(implicit ctx: Context): List[TypeOrBoundsTree] = kernel.TypeTree_Applied_args(self) + } + + implicit class TypeTree_AnnotatedAPI(self: TypeTree.Annotated) { + def arg(implicit ctx: Context): TypeTree = kernel.TypeTree_Annotated_arg(self) + def annotation(implicit ctx: Context): Term = kernel.TypeTree_Annotated_annotation(self) + } + + implicit class TypeTree_MatchTypeAPI(self: TypeTree.MatchType) { + def bound(implicit ctx: Context): Option[TypeTree] = kernel.TypeTree_MatchType_bound(self) + def selector(implicit ctx: Context): TypeTree = kernel.TypeTree_MatchType_selector(self) + def cases(implicit ctx: Context): List[TypeCaseDef] = kernel.TypeTree_MatchType_cases(self) + } + + implicit class TypeTree_ByNameAPI(self: TypeTree.ByName) { + def result(implicit ctx: Context): TypeTree = kernel.TypeTree_ByName_result(self) + } + + implicit class TypeTree_LambdaTypeTreeAPI(self: TypeTree.LambdaTypeTree) { + def tparams(implicit ctx: Context): List[TypeDef] = kernel.TypeTree_LambdaTypeTree_tparams(self) + def body(implicit ctx: Context): TypeOrBoundsTree = kernel.TypeTree_LambdaTypeTree_body(self) + } + + implicit class TypeTree_TypeBindAPI(self: TypeTree.TypeBind) { + def name(implicit ctx: Context): String = kernel.TypeTree_TypeBind_name(self) + def body(implicit ctx: Context): TypeOrBoundsTree = kernel.TypeTree_TypeBind_body(self) + } + + implicit class TypeTree_TypeBlockAPI(self: TypeTree.TypeBlock) { + def aliases(implicit ctx: Context): List[TypeDef] = kernel.TypeTree_TypeBlock_aliases(self) + def tpt(implicit ctx: Context): TypeTree = kernel.TypeTree_TypeBlock_tpt(self) + } + // ----- TypeBoundsTrees ------------------------------------------------ - trait TypeBoundsTreeAPI { - def tpe(implicit ctx: Context): TypeBounds - def low(implicit ctx: Context): TypeTree - def hi(implicit ctx: Context): TypeTree + implicit class TypeBoundsTreeAPI(self: TypeBoundsTree) { + def tpe(implicit ctx: Context): TypeBounds = kernel.TypeBoundsTree_tpe(self) + def low(implicit ctx: Context): TypeTree = kernel.TypeBoundsTree_low(self) + def hi(implicit ctx: Context): TypeTree = kernel.TypeBoundsTree_hi(self) } val IsTypeBoundsTree: IsTypeBoundsTreeModule From 87eb14b252eec171c6cfc6538bad9b7f25d082cb Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 28 Feb 2019 11:42:50 +0100 Subject: [PATCH 03/17] Move rootContext and rootPosition to kernel --- .../consumetasty/TastyConsumerPhase.scala | 2 +- .../decompiler/DecompilationPrinter.scala | 2 +- .../dotc/decompiler/IDEDecompilerDriver.scala | 2 +- .../dotty/tools/dotc/quoted/QuoteDriver.scala | 2 +- .../dotc/tastyreflect/ContextOpsImpl.scala | 3 ++- .../tools/dotc/tastyreflect/CoreImpl.scala | 2 +- .../tools/dotc/tastyreflect/KernelImpl.scala | 2 +- .../dotc/tastyreflect/ReflectionImpl.scala | 19 +++++++++++++++++-- .../dotc/tastyreflect/RootPositionImpl.scala | 2 -- .../dotty/tools/dotc/transform/Splicer.scala | 6 +----- .../src/scala/tasty/reflect/ContextOps.scala | 2 +- library/src/scala/tasty/reflect/Kernel.scala | 6 ++++++ .../scala/tasty/reflect/RootPosition.scala | 2 +- 13 files changed, 34 insertions(+), 18 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/consumetasty/TastyConsumerPhase.scala b/compiler/src/dotty/tools/dotc/consumetasty/TastyConsumerPhase.scala index d57249090eae..6d1a5f1932e3 100644 --- a/compiler/src/dotty/tools/dotc/consumetasty/TastyConsumerPhase.scala +++ b/compiler/src/dotty/tools/dotc/consumetasty/TastyConsumerPhase.scala @@ -11,7 +11,7 @@ class TastyConsumerPhase(consumer: TastyConsumer) extends Phase { override def phaseName: String = "tastyConsumer" override def run(implicit ctx: Context): Unit = { - val reflect = new ReflectionImpl(ctx) + val reflect = ReflectionImpl(ctx) consumer(reflect)(ctx.compilationUnit.tpdTree) } diff --git a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala index 34acbd255d76..f91e6c666cfc 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala @@ -43,7 +43,7 @@ class DecompilationPrinter extends Phase { } else { val unitFile = unit.source.toString.replace("\\", "/").replace(".class", ".tasty") out.println(s"/** Decompiled from $unitFile */") - out.println(new ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree)(ctx)) + out.println(ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree)(ctx)) } } } diff --git a/compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala b/compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala index ae4541865c80..f7ff582f14e3 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala @@ -35,7 +35,7 @@ class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver { run.printSummary() val unit = ctx.run.units.head - val decompiled = new ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree) + val decompiled = ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree) val tree = new TastyHTMLPrinter(unit.pickled.head._2).printContents() reporter.removeBufferedMessages.foreach(message => System.err.println(message)) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index e63ab7a09ad4..0fb7b576adeb 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -47,7 +47,7 @@ class QuoteDriver extends Driver { val tree1 = if (ctx.settings.YshowRawQuoteTrees.value) tree else (new TreeCleaner).transform(tree) - new ReflectionImpl(ctx).showSourceCode.showTree(tree1) + ReflectionImpl(ctx).showSourceCode.showTree(tree1) } withTree(expr, show, settings) } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala index 16e296e183db..3293f21d4ed1 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala @@ -2,6 +2,7 @@ package dotty.tools.dotc.tastyreflect trait ContextOpsImpl extends scala.tasty.reflect.ContextOps with CoreImpl { - val rootContext: Context + // overridden to remove the implicit modifier inside the implementation + override def rootContext: Context = super.rootContext } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala index 8ef74dbd473c..7fab0b9f03c2 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala @@ -3,6 +3,6 @@ package tastyreflect trait CoreImpl extends scala.tasty.reflect.Core { - final val kernel: KernelImpl = new KernelImpl + val kernel: KernelImpl } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 6f18cb91669f..456d5c1efb15 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -13,7 +13,7 @@ import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFr import scala.tasty.reflect.Kernel -class KernelImpl extends Kernel { +class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.SourcePosition) extends Kernel { // // CONTEXT diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index bd689b7ee70a..b64a138b434e 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -1,8 +1,9 @@ package dotty.tools.dotc.tastyreflect import dotty.tools.dotc.core._ +import dotty.tools.dotc.util.{SourcePosition, Spans} -class ReflectionImpl(val rootContext: Contexts.Context) +class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition) extends scala.tasty.Reflection with CoreImpl with CaseDefOpsImpl @@ -23,4 +24,18 @@ class ReflectionImpl(val rootContext: Contexts.Context) with SymbolOpsImpl with TreeOpsImpl with TypeOrBoundsTreesOpsImpl - with TypeOrBoundsOpsImpl + with TypeOrBoundsOpsImpl { + + val kernel: KernelImpl = new KernelImpl(ctx, pos) + +} + +object ReflectionImpl { + + def apply(rootContext: Contexts.Context): ReflectionImpl = + apply(rootContext, SourcePosition(rootContext.source, Spans.NoSpan)) + + def apply(rootContext: Contexts.Context, rootPosition: SourcePosition): ReflectionImpl = + new ReflectionImpl(rootContext, rootPosition) + +} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/RootPositionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/RootPositionImpl.scala index 3e21bd0449f4..faeaaff824b9 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/RootPositionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/RootPositionImpl.scala @@ -4,8 +4,6 @@ import dotty.tools.dotc.util.{SourcePosition, Spans} trait RootPositionImpl extends scala.tasty.reflect.RootPosition with ContextOpsImpl with CoreImpl { - def rootPosition: SourcePosition = SourcePosition(rootContext.source, Spans.NoSpan) - protected def withDefaultPos[T <: Tree](fn: Context => T)(implicit ctx: Context): T = { fn(ctx.withSource(rootPosition.source)).withSpan(rootPosition.span) } diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 212eef754d1d..a21cecdb3020 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -106,11 +106,7 @@ object Splicer { protected def interpretVarargs(args: List[Object])(implicit env: Env): Object = args.toSeq - protected def interpretTastyContext()(implicit env: Env): Object = { - new ReflectionImpl(ctx) { - override def rootPosition: SourcePosition = pos - } - } + protected def interpretTastyContext()(implicit env: Env): Object = ReflectionImpl(ctx, pos) protected def interpretStaticMethodCall(moduleClass: Symbol, fn: Symbol, args: => List[Object])(implicit env: Env): Object = { val (inst, clazz) = diff --git a/library/src/scala/tasty/reflect/ContextOps.scala b/library/src/scala/tasty/reflect/ContextOps.scala index 881568b060bd..bb8703e4c505 100644 --- a/library/src/scala/tasty/reflect/ContextOps.scala +++ b/library/src/scala/tasty/reflect/ContextOps.scala @@ -12,6 +12,6 @@ trait ContextOps extends Core { } /** Context of the macro expansion */ - implicit def rootContext: Context + implicit def rootContext: Context = kernel.rootContext } diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 188e44f50453..edecca7b2344 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -117,6 +117,12 @@ package scala.tasty.reflect */ trait Kernel { + /** Context of the macro expansion */ + def rootContext: Context + + /** Root position of this tasty context. For macros it corresponds to the expansion site. */ + def rootPosition: Position + // // CONTEXT // diff --git a/library/src/scala/tasty/reflect/RootPosition.scala b/library/src/scala/tasty/reflect/RootPosition.scala index 3c5ed0af32db..8b8983cb90e0 100644 --- a/library/src/scala/tasty/reflect/RootPosition.scala +++ b/library/src/scala/tasty/reflect/RootPosition.scala @@ -3,6 +3,6 @@ package scala.tasty.reflect trait RootPosition extends Core { /** Root position of this tasty context. For macros it corresponds to the expansion site. */ - def rootPosition: Position + def rootPosition: Position = kernel.rootPosition } From 1fd8ffbd016d120c18d059dd59ee85aab1a2c63e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 28 Feb 2019 11:51:18 +0100 Subject: [PATCH 04/17] Move PatternAPI to kernel --- .../src/dotty/tools/dotc/tastyreflect/KernelImpl.scala | 5 +++++ .../dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala | 6 ------ library/src/scala/tasty/reflect/Kernel.scala | 4 ++++ library/src/scala/tasty/reflect/PatternOps.scala | 9 ++++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 456d5c1efb15..f232e23aec7a 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -238,6 +238,11 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. // type Pattern = tpd.Tree + + def Pattern_pos(self: Pattern)(implicit ctx: Context): Position = self.sourcePos + def Pattern_tpe(self: Pattern)(implicit ctx: Context): Type = self.tpe.stripTypeVar + def Pattern_symbol(self: Pattern)(implicit ctx: Context): Symbol = self.symbol + type Value = tpd.Tree def Pattern_Value_value(self: Value)(implicit ctx: Context): Term = self diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala index ac8dec3c4ce1..bd02f5484d64 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala @@ -7,12 +7,6 @@ import dotty.tools.dotc.core.StdNames.nme trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with RootPositionImpl { - def PatternDeco(pattern: Pattern): PatternAPI = new PatternAPI { - def pos(implicit ctx: Context): Position = pattern.sourcePos - def tpe(implicit ctx: Context): Type = pattern.tpe.stripTypeVar - def symbol(implicit ctx: Context): Symbol = pattern.symbol - } - object Pattern extends PatternModule { object IsValue extends IsValueModule { diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index edecca7b2344..dd1d32582f72 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -378,6 +378,10 @@ trait Kernel { /** Pattern tree of the pattern part of a CaseDef */ type Pattern <: AnyRef + def Pattern_pos(self: Pattern)(implicit ctx: Context): Position + def Pattern_tpe(self: Pattern)(implicit ctx: Context): Type + def Pattern_symbol(self: Pattern)(implicit ctx: Context): Symbol + /** Pattern representing a value. This includes `1`, ```x``` and `_` */ type Value <: Pattern diff --git a/library/src/scala/tasty/reflect/PatternOps.scala b/library/src/scala/tasty/reflect/PatternOps.scala index 4b49ed2ece21..f1e317eae0cb 100644 --- a/library/src/scala/tasty/reflect/PatternOps.scala +++ b/library/src/scala/tasty/reflect/PatternOps.scala @@ -26,15 +26,14 @@ trait PatternOps extends Core { def tpt(implicit ctx: Context): TypeTree = kernel.Pattern_TypeTest_tpt(typeTest) } - trait PatternAPI { + implicit class PatternAPI(self: Pattern) { /** Position in the source code */ - def pos(implicit ctx: Context): Position + def pos(implicit ctx: Context): Position = kernel.Pattern_pos(self) - def tpe(implicit ctx: Context): Type + def tpe(implicit ctx: Context): Type = kernel.Pattern_tpe(self) - def symbol(implicit ctx: Context): Symbol + def symbol(implicit ctx: Context): Symbol = kernel.Pattern_symbol(self) } - implicit def PatternDeco(pattern: Pattern): PatternAPI val Pattern: PatternModule abstract class PatternModule { From 0b97ab3bddd5f31ab4a458b3f87d41de60b78be7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 28 Feb 2019 12:31:05 +0100 Subject: [PATCH 05/17] Move module methods implementations to kernel --- .../dotc/tastyreflect/CaseDefOpsImpl.scala | 19 - .../dotc/tastyreflect/ConstantOpsImpl.scala | 101 --- .../tools/dotc/tastyreflect/IdOpsImpl.scala | 4 - .../tastyreflect/ImportSelectorOpsImpl.scala | 21 - .../tools/dotc/tastyreflect/KernelImpl.scala | 770 +++++++++++++++++- .../dotc/tastyreflect/PatternOpsImpl.scala | 106 --- .../dotc/tastyreflect/SettingsOpsImpl.scala | 6 - .../dotc/tastyreflect/SignatureOpsImpl.scala | 6 - .../tastyreflect/StandardDefinitions.scala | 74 -- .../dotc/tastyreflect/SymbolOpsImpl.scala | 33 - .../tools/dotc/tastyreflect/TreeOpsImpl.scala | 683 ---------------- .../TypeOrBoundsTreesOpsImpl.scala | 297 +------ .../src/scala/tasty/reflect/CaseDefOps.scala | 27 +- .../src/scala/tasty/reflect/ConstantOps.scala | 121 +-- library/src/scala/tasty/reflect/Core.scala | 5 +- library/src/scala/tasty/reflect/IdOps.scala | 5 +- .../tasty/reflect/ImportSelectorOps.scala | 36 +- library/src/scala/tasty/reflect/Kernel.scala | 383 ++++++++- .../src/scala/tasty/reflect/PatternOps.scala | 87 +- .../src/scala/tasty/reflect/SettingsOps.scala | 7 +- .../scala/tasty/reflect/SignatureOps.scala | 6 +- .../tasty/reflect/StandardDefinitions.scala | 119 +-- .../src/scala/tasty/reflect/SymbolOps.scala | 42 +- library/src/scala/tasty/reflect/TreeOps.scala | 519 ++++++------ .../tasty/reflect/TypeOrBoundsTreeOps.scala | 251 +++--- 25 files changed, 1809 insertions(+), 1919 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala index 6abc3bf708fb..a9de7a3fdd47 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala @@ -4,23 +4,4 @@ import dotty.tools.dotc.ast.tpd trait CaseDefOpsImpl extends scala.tasty.reflect.CaseDefOps with CoreImpl with Helpers { - object CaseDef extends CaseDefModule { - def apply(pattern: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef = - tpd.CaseDef(pattern, guard.getOrElse(tpd.EmptyTree), body) - - def copy(original: CaseDef)(pattern: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef = - tpd.cpy.CaseDef(original)(pattern, guard.getOrElse(tpd.EmptyTree), body) - - def unapply(x: CaseDef): Some[(Pattern, Option[Term], Term)] = Some(x.pat, optional(x.guard), x.body) - } - - object TypeCaseDef extends TypeCaseDefModule { - def apply(pattern: TypeTree, body: TypeTree)(implicit ctx: Context): TypeCaseDef = - tpd.CaseDef(pattern, tpd.EmptyTree, body) - - def copy(original: TypeCaseDef)(pattern: TypeTree, body: TypeTree)(implicit ctx: Context): TypeCaseDef = - tpd.cpy.CaseDef(original)(pattern, tpd.EmptyTree, body) - - def unapply(x: TypeCaseDef): Some[(TypeTree, TypeTree)] = Some((x.pat, x.body)) - } } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala index 7c2c50a651c9..733ff7260162 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala @@ -5,105 +5,4 @@ import dotty.tools.dotc.core.Constants trait ConstantOpsImpl extends scala.tasty.reflect.ConstantOps with CoreImpl { - object Constant extends ConstantModule { - - object Unit extends UnitModule { - def apply(): Constant = Constants.Constant(()) - def unapply(x: Constant): Boolean = x.tag == Constants.UnitTag - } - - object Null extends NullModule { - def apply(): Constant = Constants.Constant(null) - def unapply(x: Constant): Boolean = x.tag == Constants.NullTag - } - - object Boolean extends BooleanModule { - def apply(x: Boolean): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[Boolean] = x match { - case x: Constants.Constant if x.tag == Constants.BooleanTag => Some(x.booleanValue) - case _ => None - } - } - - object Byte extends ByteModule { - def apply(x: Byte): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[Byte] = x match { - case x: Constants.Constant if x.tag == Constants.ByteTag => Some(x.byteValue) - case _ => None - } - } - - object Short extends ShortModule { - def apply(x: Short): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[Short] = x match { - case x: Constants.Constant if x.tag == Constants.ShortTag => Some(x.shortValue) - case _ => None - } - } - - object Char extends CharModule { - def apply(x: Char): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[Char] = x match { - case x: Constants.Constant if x.tag == Constants.CharTag => Some(x.charValue) - case _ => None - } - } - - object Int extends IntModule { - def apply(x: Int): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[Int] = x match { - case x: Constants.Constant if x.tag == Constants.IntTag => Some(x.intValue) - case _ => None - } - } - - object Long extends LongModule { - def apply(x: Long): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[Long] = x match { - case x: Constants.Constant if x.tag == Constants.LongTag => Some(x.longValue) - case _ => None - } - } - - object Float extends FloatModule { - def apply(x: Float): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[Float] = x match { - case x: Constants.Constant if x.tag == Constants.FloatTag => Some(x.floatValue) - case _ => None - } - } - - object Double extends DoubleModule { - def apply(x: Double): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[Double] = x match { - case x: Constants.Constant if x.tag == Constants.DoubleTag => Some(x.doubleValue) - case _ => None - } - } - - object String extends StringModule { - def apply(x: String): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[String] = x match { - case x: Constants.Constant if x.tag == Constants.StringTag => Some(x.stringValue) - case _ => None - } - } - - object ClassTag extends ClassTagModule { - def apply[T](implicit x: scala.reflect.ClassTag[T]): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[Type] = x match { - case x: Constants.Constant if x.tag == Constants.ClazzTag => Some(x.typeValue) - case _ => None - } - } - - object Symbol extends SymbolModule { - def apply(x: scala.Symbol): Constant = Constants.Constant(x) - def unapply(x: Constant): Option[scala.Symbol] = x match { - case x: Constants.Constant if x.tag == Constants.ScalaSymbolTag => Some(x.scalaSymbolValue) - case _ => None - } - } - } - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala index c85a8667020c..187ca0971005 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala @@ -4,8 +4,4 @@ import dotty.tools.dotc.core.Decorators._ trait IdOpsImpl extends scala.tasty.reflect.IdOps with CoreImpl { - object Id extends IdModule { - def unapply(id: Id): Option[String] = Some(id.name.toString) - } - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala index 8300b213d93f..cc5c8dbcbf24 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala @@ -6,25 +6,4 @@ import dotty.tools.dotc.core.Decorators._ trait ImportSelectorOpsImpl extends scala.tasty.reflect.ImportSelectorOps with CoreImpl { - object SimpleSelector extends SimpleSelectorModule { - def unapply(x: ImportSelector)(implicit ctx: Context): Option[Id] = x match { - case x: untpd.Ident => Some(x) - case _ => None - } - } - - object RenameSelector extends RenameSelectorModule { - def unapply(x: ImportSelector)(implicit ctx: Context): Option[(Id, Id)] = x match { - case Trees.Thicket((id1: untpd.Ident) :: (id2: untpd.Ident) :: Nil) if id2.name != nme.WILDCARD => Some(id1, id2) - case _ => None - } - } - - object OmitSelector extends OmitSelectorModule { - def unapply(x: ImportSelector)(implicit ctx: Context): Option[Id] = x match { - case Trees.Thicket((id: untpd.Ident) :: Trees.Ident(nme.WILDCARD) :: Nil) => Some(id) - case _ => None - } - } - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index f232e23aec7a..e38cc64a96dc 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -15,6 +15,10 @@ import scala.tasty.reflect.Kernel class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.SourcePosition) extends Kernel { + private implicit def ctx: core.Contexts.Context = rootContext + + def settings: Settings = rootContext.settings + // // CONTEXT // @@ -31,6 +35,8 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Settings = config.ScalaSettings + def Settings_color(self: Settings): Boolean = self.color.value(rootContext) == "always" + // // TREES // @@ -44,23 +50,64 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type PackageClause = tpd.PackageDef + def isPackageClause(tree: Tree)(implicit ctx: Context): Option[PackageClause] = tree match { + case x: tpd.PackageDef => Some(x) + case _ => None + } + def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Term_Ref = self.pid def PackageClause_stats(self: PackageClause)(implicit ctx: Context): List[Tree] = self.stats + def PackageClause_apply(pid: Term_Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = + withDefaultPos(ctx => tpd.PackageDef(pid.asInstanceOf[tpd.RefTree], stats)(ctx)) + + def PackageClause_copy(original: PackageClause)(pid: Term_Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = + tpd.cpy.PackageDef(original)(pid, stats) + type Statement = tpd.Tree + def isStatement(tree: Tree)(implicit ctx: Context): Option[Statement] = tree match { + case tree if tree.isTerm => Some(tree) + case _ => isDefinition(tree) + } + type Import = tpd.Import + override def isImport(tree: Tree)(implicit ctx: Context): Option[Import] = tree match { + case tree: tpd.Import => Some(tree) + case _ => None + } + def Import_impliedOnly(self: Import): Boolean = self.impliedOnly def Import_expr(self: Import)(implicit ctx: Context): Tree = self.expr def Import_selectors(self: Import)(implicit ctx: Context): List[ImportSelector] = self.selectors + def Import_apply(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import = + withDefaultPos(ctx => tpd.Import(impliedOnly, expr, selectors)(ctx)) + + def Import_copy(original: Import)(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import = + tpd.cpy.Import(original)(impliedOnly, expr, selectors) + type Definition = tpd.Tree - def Definition_name(self: Definition)(implicit ctx: Context): String = self.symbol.name.toString + def isDefinition(tree: Tree)(implicit ctx: Context): Option[Definition] = tree match { + case tree: tpd.MemberDef => Some(tree) + case tree: PackageDefinition => Some(tree) + case _ => None + } + + def Definition_name(self: Definition)(implicit ctx: Context): String = self match { + case self: tpd.MemberDef => self.name.toString + case self: PackageDefinition => self.symbol.name.toString // TODO make PackageDefinition a MemberDef or NameTree + } type PackageDef = PackageDefinition + def isPackageDef(tree: Tree)(implicit ctx: Context): Option[PackageDef] = tree match { + case x: PackageDefinition => Some(x) + case _ => None + } + def PackageDef_owner(self: PackageDef)(implicit ctx: Context): PackageDef = packageDefFromSym(self.symbol.owner) def PackageDef_members(self: PackageDef)(implicit ctx: Context): List[Statement] = { @@ -72,6 +119,11 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ClassDef = tpd.TypeDef + def isClassDef(tree: Tree)(implicit ctx: Context): Option[ClassDef] = tree match { + case x: tpd.TypeDef if x.isClassDef => Some(x) + case _ => None + } + def ClassDef_constructor(self: ClassDef)(implicit ctx: Context): DefDef = ClassDef_rhs(self).constr def ClassDef_parents(self: ClassDef)(implicit ctx: Context): List[TermOrTypeTree] = ClassDef_rhs(self).parents def ClassDef_derived(self: ClassDef)(implicit ctx: Context): List[TypeTree] = ClassDef_rhs(self).derived.asInstanceOf[List[TypeTree]] @@ -80,27 +132,70 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def ClassDef_symbol(self: ClassDef)(implicit ctx: Context): ClassSymbol = self.symbol.asClass private def ClassDef_rhs(self: ClassDef) = self.rhs.asInstanceOf[tpd.Template] + def ClassDef_copy(original: ClassDef)(name: String, constr: DefDef, parents: List[TermOrTypeTree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement])(implicit ctx: Context): ClassDef = { + val Trees.TypeDef(_, originalImpl: tpd.Template) = original + tpd.cpy.TypeDef(original)(name.toTypeName, tpd.cpy.Template(originalImpl)(constr, parents, derived, selfOpt.getOrElse(tpd.EmptyValDef), body)) + } + type TypeDef = tpd.TypeDef + def isTypeDef(tree: Tree)(implicit ctx: Context): Option[TypeDef] = tree match { + case x: tpd.TypeDef if !x.symbol.isClass => Some(x) + case _ => None + } + def TypeDef_rhs(self: TypeDef)(implicit ctx: Context): TypeOrBoundsTree = self.rhs def TypeDef_symbol(self: TypeDef)(implicit ctx: Context): TypeSymbol = self.symbol.asType + def TypeDef_apply(symbol: TypeSymbol)(implicit ctx: Context): TypeDef = withDefaultPos(ctx => tpd.TypeDef(symbol)(ctx)) + def TypeDef_copy(original: TypeDef)(name: String, rhs: TypeOrBoundsTree)(implicit ctx: Context): TypeDef = + tpd.cpy.TypeDef(original)(name.toTypeName, rhs) + type DefDef = tpd.DefDef + def isDefDef(tree: Tree)(implicit ctx: Context): Option[DefDef] = tree match { + case x: tpd.DefDef => Some(x) + case _ => None + } + def DefDef_typeParams(self: DefDef)(implicit ctx: Context): List[TypeDef] = self.tparams def DefDef_paramss(self: DefDef)(implicit ctx: Context): List[List[ValDef]] = self.vparamss def DefDef_returnTpt(self: DefDef)(implicit ctx: Context): TypeTree = self.tpt def DefDef_rhs(self: DefDef)(implicit ctx: Context): Option[Tree] = optional(self.rhs) def DefDef_symbol(self: DefDef)(implicit ctx: Context): DefSymbol = self.symbol.asTerm + def DefDef_apply(symbol: DefSymbol, rhsFn: List[Type] => List[List[Term]] => Option[Term])(implicit ctx: Context): DefDef = + withDefaultPos(ctx => tpd.polyDefDef(symbol, tparams => vparamss => rhsFn(tparams)(vparamss).getOrElse(tpd.EmptyTree))(ctx)) + + def DefDef_copy(original: DefDef)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): DefDef = + tpd.cpy.DefDef(original)(name.toTermName, typeParams, paramss, tpt, rhs.getOrElse(tpd.EmptyTree)) + type ValDef = tpd.ValDef + def isValDef(tree: Tree)(implicit ctx: Context): Option[ValDef] = tree match { + case x: tpd.ValDef => Some(x) + case _ => None + } + def ValDef_tpt(self: ValDef)(implicit ctx: Context): TypeTree = self.tpt def ValDef_rhs(self: ValDef)(implicit ctx: Context): Option[Tree] = optional(self.rhs) def ValDef_symbol(self: ValDef)(implicit ctx: Context): ValSymbol = self.symbol.asTerm + def ValDef_apply(symbol: ValSymbol, rhs: Option[Term])(implicit ctx: Context): ValDef = + tpd.ValDef(symbol, rhs.getOrElse(tpd.EmptyTree)) + + def ValDef_copy(original: ValDef)(name: String, tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): ValDef = + tpd.cpy.ValDef(original)(name.toTermName, tpt, rhs.getOrElse(tpd.EmptyTree)) + type Term = tpd.Tree + def isTerm(tree: Tree)(implicit ctx: Context): Option[Term] = + if (tree.isTerm) Some(tree) else None + + // TODO move to Kernel and use isTerm directly with a cast + def isTermNotTypeTree(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[Term] = + if (termOrTypeTree.isTerm) Some(termOrTypeTree) else None + def Term_pos(self: Term)(implicit ctx: Context): Position = self.sourcePos def Term_tpe(self: Term)(implicit ctx: Context): Type = self.tpe def Term_underlyingArgument(self: Term)(implicit ctx: Context): Term = self.underlyingArgument @@ -108,104 +203,361 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Ref = tpd.RefTree + def Term_Ref_apply(sym: Symbol)(implicit ctx: Context): Term_Ref = + withDefaultPos(ctx => tpd.ref(sym)(ctx).asInstanceOf[tpd.RefTree]) + type Term_Ident = tpd.Ident + def isTerm_Ident(x: Term)(implicit ctx: Context): Option[Term_Ident] = x match { + case x: tpd.Ident if x.isTerm => Some(x) + case _ => None + } + def Term_Ident_name(self: Term_Ident)(implicit ctx: Context): String = self.name.show + def Term_Ident_apply(tmref: TermRef)(implicit ctx: Context): Term = + withDefaultPos(implicit ctx => tpd.ref(tmref).asInstanceOf[Term]) + + def Term_Ident_copy(original: Tree)(name: String)(implicit ctx: Context): Term_Ident = + tpd.cpy.Ident(original)(name.toTermName) + type Term_Select = tpd.Select + def isTerm_Select(x: Term)(implicit ctx: Context): Option[Term_Select] = x match { + case x: tpd.Select if x.isTerm => Some(x) + case _ => None + } + def Term_Select_qualifier(self: Term_Select)(implicit ctx: Context): Term = self.qualifier def Term_Select_name(self: Term_Select)(implicit ctx: Context): String = self.name.toString def Term_Select_signature(self: Term_Select)(implicit ctx: Context): Option[Signature] = if (self.symbol.signature == core.Signature.NotAMethod) None else Some(self.symbol.signature) + def Term_Select_unique(qualifier: Term, name: String)(implicit ctx: Context): Term_Select = { + val denot = qualifier.tpe.member(name.toTermName) + assert(!denot.isOverloaded, s"The symbol `$name` is overloaded. The method Select.unique can only be used for non-overloaded symbols.") + withDefaultPos(implicit ctx => tpd.Select(qualifier, name.toTermName)) + } + + // TODO rename, this returns an Apply and not a Select + def Term_Select_overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Term_Apply = + withDefaultPos(implicit ctx => tpd.applyOverloaded(qualifier, name.toTermName, args, targs, Types.WildcardType).asInstanceOf[Term_Apply]) + + def Term_Select_copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Term_Select = + tpd.cpy.Select(original)(qualifier, name.toTermName) + type Term_Literal = tpd.Literal + def isTerm_Literal(x: Term)(implicit ctx: Context): Option[Term_Literal] = x match { + case x: tpd.Literal => Some(x) + case _ => None + } + def Term_Literal_constant(self: Term_Literal)(implicit ctx: Context): Constant = self.const + def Term_Literal_apply(constant: Constant)(implicit ctx: Context): Term_Literal = + withDefaultPos(ctx => tpd.Literal(constant)(ctx)) + + def Term_Literal_copy(original: Tree)(constant: Constant)(implicit ctx: Context): Term_Literal = + tpd.cpy.Literal(original)(constant) + type Term_This = tpd.This + def isTerm_This(x: Term)(implicit ctx: Context): Option[Term_This] = x match { + case x: tpd.This => Some(x) + case _ => None + } + def Term_This_id(self: Term_This)(implicit ctx: Context): Option[Id] = optional(self.qual) + def Term_This_apply(cls: ClassSymbol)(implicit ctx: Context): Term_This = + withDefaultPos(ctx => tpd.This(cls)(ctx)) + + def Term_This_copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): Term_This = + tpd.cpy.This(original)(qual.getOrElse(untpd.EmptyTypeIdent)) + type Term_New = tpd.New + def isTerm_New(x: Term)(implicit ctx: Context): Option[Term_New] = x match { + case x: tpd.New => Some(x) + case _ => None + } + def Term_New_tpt(self: Term_New)(implicit ctx: Context): TypeTree = self.tpt + def Term_New_apply(tpt: TypeTree)(implicit ctx: Context): Term_New = withDefaultPos(ctx => tpd.New(tpt)(ctx)) + + def Term_New_copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): Term_New = + tpd.cpy.New(original)(tpt) + type Term_NamedArg = tpd.NamedArg + def isTerm_NamedArg(x: Term)(implicit ctx: Context): Option[Term_NamedArg] = x match { + case x: tpd.NamedArg if x.name.isInstanceOf[core.Names.TermName] => Some(x) // TODO: Now, the name should alwas be a term name + case _ => None + } + def Term_NamedArg_name(self: Term_NamedArg)(implicit ctx: Context): String = self.name.toString def Term_NamedArg_value(self: Term_NamedArg)(implicit ctx: Context): Term = self.arg + def Term_NamedArg_apply(name: String, arg: Term)(implicit ctx: Context): Term_NamedArg = + withDefaultPos(ctx => tpd.NamedArg(name.toTermName, arg)(ctx)) + + def Term_NamedArg_copy(tree: Term_NamedArg)(name: String, arg: Term)(implicit ctx: Context): Term_NamedArg = + tpd.cpy.NamedArg(tree)(name.toTermName, arg) + type Term_Apply = tpd.Apply + def isTerm_Apply(x: Term)(implicit ctx: Context): Option[Term_Apply] = x match { + case x: tpd.Apply => Some(x) + case _ => None + } + def Term_Apply_fun(self: Term_Apply)(implicit ctx: Context): Term = self.fun def Term_Apply_args(self: Term_Apply)(implicit ctx: Context): List[Term] = self.args + + def Term_Apply_apply(fn: Term, args: List[Term])(implicit ctx: Context): Term_Apply = + withDefaultPos(ctx => tpd.Apply(fn, args)(ctx)) + + def Term_Apply_copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Term_Apply = + tpd.cpy.Apply(original)(fun, args) + type Term_TypeApply = tpd.TypeApply + def isTerm_TypeApply(x: Term)(implicit ctx: Context): Option[Term_TypeApply] = x match { + case x: tpd.TypeApply => Some(x) + case _ => None + } + def Term_TypeApply_fun(self: Term_TypeApply)(implicit ctx: Context): Term = self.fun def Term_TypeApply_args(self: Term_TypeApply)(implicit ctx: Context): List[TypeTree] = self.args + def Term_TypeApply_apply(fn: Term, args: List[TypeTree])(implicit ctx: Context): Term_TypeApply = + withDefaultPos(ctx => tpd.TypeApply(fn, args)(ctx)) + + def Term_TypeApply_copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): Term_TypeApply = + tpd.cpy.TypeApply(original)(fun, args) + type Term_Super = tpd.Super + def isTerm_Super(x: Term)(implicit ctx: Context): Option[Term_Super] = x match { + case x: tpd.Super => Some(x) + case _ => None + } + def Term_Super_qualifier(self: Term_Super)(implicit ctx: Context): Term = self.qual def Term_Super_id(self: Term_Super)(implicit ctx: Context): Option[Id] = optional(self.mix) + def Term_Super_apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Term_Super = + withDefaultPos(ctx => tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), false, NoSymbol)(ctx)) + + def Term_Super_copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Term_Super = + tpd.cpy.Super(original)(qual, mix.getOrElse(untpd.EmptyTypeIdent)) + type Term_Typed = tpd.Typed + def isTerm_Typed(x: Term)(implicit ctx: Context): Option[Term_Typed] = x match { + case x: tpd.Typed => Some(x) + case _ => None + } + def Term_Typed_expr(self: Term_Typed)(implicit ctx: Context): Term = self.expr def Term_Typed_tpt(self: Term_Typed)(implicit ctx: Context): TypeTree = self.tpt + def Term_Typed_apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Term_Typed = + withDefaultPos(ctx => tpd.Typed(expr, tpt)(ctx)) + + def Term_Typed_copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Term_Typed = + tpd.cpy.Typed(original)(expr, tpt) + type Term_Assign = tpd.Assign + def isTerm_Assign(x: Term)(implicit ctx: Context): Option[Term_Assign] = x match { + case x: tpd.Assign => Some(x) + case _ => None + } + def Term_Assign_lhs(self: Term_Assign)(implicit ctx: Context): Term = self.lhs def Term_Assign_rhs(self: Term_Assign)(implicit ctx: Context): Term = self.rhs + def Term_Assign_apply(lhs: Term, rhs: Term)(implicit ctx: Context): Term_Assign = + withDefaultPos(ctx => tpd.Assign(lhs, rhs)(ctx)) + + def Term_Assign_copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Term_Assign = + tpd.cpy.Assign(original)(lhs, rhs) + type Term_Block = tpd.Block + def isTerm_Block(x: Term)(implicit ctx: Context): Option[Term_Block] = normalizedLoops(x) match { + case x: tpd.Block => Some(x) + case _ => None + } + + /** Normalizes non Blocks. + * i) Put `while` and `doWhile` loops in their own blocks: `{ def while$() = ...; while$() }` + * ii) Put closures in their own blocks: `{ def anon$() = ...; closure(anon$, ...) }` + */ + private def normalizedLoops(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match { + case block: tpd.Block if block.stats.size > 1 => + def normalizeInnerLoops(stats: List[tpd.Tree]): List[tpd.Tree] = stats match { + case (x: tpd.DefDef) :: y :: xs if needsNormalization(y) => + tpd.Block(x :: Nil, y) :: normalizeInnerLoops(xs) + case x :: xs => x :: normalizeInnerLoops(xs) + case Nil => Nil + } + if (needsNormalization(block.expr)) { + val stats1 = normalizeInnerLoops(block.stats.init) + val normalLoop = tpd.Block(block.stats.last :: Nil, block.expr) + tpd.Block(stats1, normalLoop) + } else { + val stats1 = normalizeInnerLoops(block.stats) + tpd.cpy.Block(block)(stats1, block.expr) + } + case _ => tree + } + + /** If it is the second statement of a closure. See: `normalizedLoops` */ + private def needsNormalization(tree: tpd.Tree)(implicit ctx: Context): Boolean = tree match { + case _: tpd.Closure => true + case _ => false + } + def Term_Block_statements(self: Term_Block)(implicit ctx: Context): List[Statement] = self.stats def Term_Block_expr(self: Term_Block)(implicit ctx: Context): Term = self.expr + def Term_Block_apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Term_Block = + withDefaultPos(ctx => tpd.Block(stats, expr)(ctx)) + + def Term_Block_copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Term_Block = + tpd.cpy.Block(original)(stats, expr) + type Term_Inlined = tpd.Inlined + def isTerm_Inlined(x: Term)(implicit ctx: Context): Option[Term_Inlined] = x match { + case x: tpd.Inlined => Some(x) + case _ => None + } + def Term_Inlined_call(self: Term_Inlined)(implicit ctx: Context): Option[TermOrTypeTree] = optional(self.call) def Term_Inlined_bindings(self: Term_Inlined)(implicit ctx: Context): List[Definition] = self.bindings def Term_Inlined_body(self: Term_Inlined)(implicit ctx: Context): Term = self.expansion + def Term_Inlined_apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Term_Inlined = + withDefaultPos(ctx => tpd.Inlined(call.getOrElse(tpd.EmptyTree), bindings.map { case b: tpd.MemberDef => b }, expansion)(ctx)) + + def Term_Inlined_copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Term_Inlined = + tpd.cpy.Inlined(original)(call.getOrElse(tpd.EmptyTree), bindings.asInstanceOf[List[tpd.MemberDef]], expansion) + type Term_Lambda = tpd.Closure + def isTerm_Lambda(x: Term)(implicit ctx: Context): Option[Term_Lambda] = x match { + case x: tpd.Closure => Some(x) + case _ => None + } + def Term_Lambda_meth(self: Term_Lambda)(implicit ctx: Context): Term = self.meth def Term_Lambda_tptOpt(self: Term_Lambda)(implicit ctx: Context): Option[TypeTree] = optional(self.tpt) + def Term_Lambda_apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Term_Lambda = + withDefaultPos(ctx => tpd.Closure(Nil, meth, tpt.getOrElse(tpd.EmptyTree))(ctx)) + + def Term_Lambda_copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Term_Lambda = + tpd.cpy.Closure(original)(Nil, meth, tpt.getOrElse(tpd.EmptyTree)) + type Term_If = tpd.If + def isTerm_If(x: Term)(implicit ctx: Context): Option[Term_If] = x match { + case x: tpd.If => Some(x) + case _ => None + } + def Term_If_cond(self: Term_If)(implicit ctx: Context): Term = self.cond def Term_If_thenp(self: Term_If)(implicit ctx: Context): Term = self.thenp def Term_If_elsep(self: Term_If)(implicit ctx: Context): Term = self.elsep + def Term_If_apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): Term_If = + withDefaultPos(ctx => tpd.If(cond, thenp, elsep)(ctx)) + + def Term_If_copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): Term_If = + tpd.cpy.If(original)(cond, thenp, elsep) + type Term_Match = tpd.Match + def isTerm_Match(x: Term)(implicit ctx: Context): Option[Term_Match] = x match { + case x: tpd.Match => Some(x) + case _ => None + } + def Term_Match_scrutinee(self: Term_Match)(implicit ctx: Context): Term = self.selector def Term_Match_cases(self: Term_Match)(implicit ctx: Context): List[CaseDef] = self.cases + def Term_Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Term_Match = + withDefaultPos(ctx => tpd.Match(selector, cases)(ctx)) + + def Term_Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Term_Match = + tpd.cpy.Match(original)(selector, cases) + type Term_Try = tpd.Try + def isTerm_Try(x: Term)(implicit ctx: Context): Option[Term_Try] = x match { + case x: tpd.Try => Some(x) + case _ => None + } + def Term_Try_body(self: Term_Try)(implicit ctx: Context): Term = self.expr def Term_Try_cases(self: Term_Try)(implicit ctx: Context): List[CaseDef] = self.cases def Term_Try_finalizer(self: Term_Try)(implicit ctx: Context): Option[Term] = optional(self.finalizer) + def Term_Try_apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Term_Try = + withDefaultPos(ctx => tpd.Try(expr, cases, finalizer.getOrElse(tpd.EmptyTree))(ctx)) + + def Term_Try_copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Term_Try = + tpd.cpy.Try(original)(expr, cases, finalizer.getOrElse(tpd.EmptyTree)) + type Term_Return = tpd.Return + def isTerm_Return(x: Term)(implicit ctx: Context): Option[Term_Return] = x match { + case x: tpd.Return => Some(x) + case _ => None + } + def Term_Return_expr(self: Term_Return)(implicit ctx: Context): Term = self.expr + def Term_Return_apply(expr: Term)(implicit ctx: Context): Term_Return = + withDefaultPos(ctx => tpd.Return(expr, ctx.owner)(ctx)) + + def Term_Return_copy(original: Tree)(expr: Term)(implicit ctx: Context): Term_Return = + tpd.cpy.Return(original)(expr, tpd.ref(ctx.owner)) + type Term_Repeated = tpd.SeqLiteral + def isTerm_Repeated(x: Term)(implicit ctx: Context): Option[Term_Repeated] = x match { + case x: tpd.SeqLiteral => Some(x) + case _ => None + } + def Term_Repeated_elems(self: Term_Repeated)(implicit ctx: Context): List[Term] = self.elems def Term_Repeated_elemtpt(self: Term_Repeated)(implicit ctx: Context): TypeTree = self.elemtpt + def Term_Repeated_apply(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Term_Repeated = + withDefaultPos(ctx => tpd.SeqLiteral(elems, elemtpt)(ctx)) + + def Term_Repeated_copy(original: Tree)(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Term_Repeated = + tpd.cpy.SeqLiteral(original)(elems, elemtpt) + type Term_SelectOuter = tpd.Select + def isTerm_SelectOuter(x: Term)(implicit ctx: Context): Option[Term_SelectOuter] = x match { + case x: tpd.Select => + x.name match { + case NameKinds.OuterSelectName(_, _) => Some(x) + case _ => None + } + case _ => None + } + def Term_SelectOuter_qualifier(self: Term_SelectOuter)(implicit ctx: Context): Term = self.qualifier def Term_SelectOuter_level(self: Term_SelectOuter)(implicit ctx: Context): Int = { val NameKinds.OuterSelectName(_, levels) = self.name @@ -213,11 +565,28 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. } def Term_SelectOuter_tpe(self: Term_SelectOuter)(implicit ctx: Context): Type = self.tpe.stripTypeVar + def Term_SelectOuter_apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): Term_SelectOuter = + withDefaultPos(ctx => tpd.Select(qualifier, NameKinds.OuterSelectName(name.toTermName, levels))(ctx)) + + def Term_SelectOuter_copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): Term_SelectOuter = + tpd.cpy.Select(original)(qualifier, NameKinds.OuterSelectName(name.toTermName, levels)) + type Term_While = tpd.WhileDo + def isTerm_While(x: Term)(implicit ctx: Context): Option[Term_While] = x match { + case x: tpd.WhileDo => Some(x) + case _ => None + } + def Term_While_cond(self: Term_While)(implicit ctx: Context): Term = self.cond def Term_While_body(self: Term_While)(implicit ctx: Context): Term = self.body + def Term_While_apply(cond: Term, body: Term)(implicit ctx: Context): Term_While = + withDefaultPos(ctx => tpd.WhileDo(cond, body)(ctx)) + + def Term_While_copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): Term_While = + tpd.cpy.WhileDo(original)(cond, body) + // // CASES // @@ -228,11 +597,23 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def CaseDef_guard(self: CaseDef)(implicit ctx: Context): Option[Term] = optional(self.guard) def CaseDef_rhs(self: CaseDef)(implicit ctx: Context): Term = self.body + def CaseDef_module_apply(pattern: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef = + tpd.CaseDef(pattern, guard.getOrElse(tpd.EmptyTree), body) + + def CaseDef_module_copy(original: CaseDef)(pattern: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef = + tpd.cpy.CaseDef(original)(pattern, guard.getOrElse(tpd.EmptyTree), body) + type TypeCaseDef = tpd.CaseDef def TypeCaseDef_pattern(self: TypeCaseDef)(implicit ctx: Context): TypeTree = self.pat def TypeCaseDef_rhs(self: TypeCaseDef)(implicit ctx: Context): TypeTree = self.body + def TypeCaseDef_module_apply(pattern: TypeTree, body: TypeTree)(implicit ctx: Context): TypeCaseDef = + tpd.CaseDef(pattern, tpd.EmptyTree, body) + + def TypeCaseDef_module_copy(original: TypeCaseDef)(pattern: TypeTree, body: TypeTree)(implicit ctx: Context): TypeCaseDef = + tpd.cpy.CaseDef(original)(pattern, tpd.EmptyTree, body) + // // PATTERNS // @@ -245,20 +626,55 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Value = tpd.Tree + def isPattern_Value(pattern: Pattern): Option[Value] = pattern match { + case lit: tpd.Literal => Some(lit) + case ref: tpd.RefTree if ref.isTerm => Some(ref) + case ths: tpd.This => Some(ths) + case _ => None + } + def Pattern_Value_value(self: Value)(implicit ctx: Context): Term = self + def Pattern_Value_module_apply(term: Term)(implicit ctx: Context): Value = term match { + case lit: tpd.Literal => lit + case ref: tpd.RefTree if ref.isTerm => ref + case ths: tpd.This => ths + } + def Pattern_Value_module_copy(original: Value)(term: Term)(implicit ctx: Context): Value = term match { + case lit: tpd.Literal => tpd.cpy.Literal(original)(lit.const) + case ref: tpd.RefTree if ref.isTerm => tpd.cpy.Ref(original.asInstanceOf[tpd.RefTree])(ref.name) + case ths: tpd.This => tpd.cpy.This(original)(ths.qual) + } + type Bind = tpd.Bind + def isPattern_Bind(x: Pattern)(implicit ctx: Context): Option[Bind] = x match { + case x: tpd.Bind if x.name.isTermName => Some(x) + case _ => None + } + def Pattern_Bind_name(self: Bind)(implicit ctx: Context): String = self.name.toString def Pattern_Bind_pattern(self: Bind)(implicit ctx: Context): Pattern = self.body + def Pattern_Bind_module_copy(original: Bind)(name: String, pattern: Pattern)(implicit ctx: Context): Bind = + withDefaultPos(ctx => tpd.cpy.Bind(original)(name.toTermName, pattern)(ctx)) + type Unapply = tpd.UnApply + def isPattern_Unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] = pattern match { + case pattern @ Trees.UnApply(_, _, _) => Some(pattern) + case Trees.Typed(pattern @ Trees.UnApply(_, _, _), _) => Some(pattern) + case _ => None + } + def Pattern_Unapply_fun(self: Unapply)(implicit ctx: Context): Term = self.fun def Pattern_Unapply_implicits(self: Unapply)(implicit ctx: Context): List[Term] = self.implicits def Pattern_Unapply_patterns(self: Unapply)(implicit ctx: Context): List[Pattern] = effectivePatterns(self.patterns) + def Pattern_Unapply_module_copy(original: Unapply)(fun: Term, implicits: List[Term], patterns: List[Pattern])(implicit ctx: Context): Unapply = + withDefaultPos(ctx => tpd.cpy.UnApply(original)(fun, implicits, patterns)(ctx)) + private def effectivePatterns(patterns: List[Pattern]): List[Pattern] = patterns match { case patterns0 :+ Trees.SeqLiteral(elems, _) => patterns0 ::: elems case _ => patterns @@ -266,12 +682,35 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Alternatives = tpd.Alternative + def isPattern_Alternatives(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] = pattern match { + case pattern: tpd.Alternative => Some(pattern) + case _ => None + } + def Pattern_Alternatives_patterns(self: Alternatives)(implicit ctx: Context): List[Pattern] = self.trees + def Pattern_Alternatives_module_apply(patterns: List[Pattern])(implicit ctx: Context): Alternatives = + withDefaultPos(ctx => tpd.Alternative(patterns)(ctx)) + + def Pattern_Alternatives_module_copy(original: Alternatives)(patterns: List[Pattern])(implicit ctx: Context): Alternatives = + tpd.cpy.Alternative(original)(patterns) + type TypeTest = tpd.Typed + def isPattern_TypeTest(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] = pattern match { + case Trees.Typed(_: tpd.UnApply, _) => None + case pattern: tpd.Typed => Some(pattern) + case _ => None + } + def Pattern_TypeTest_tpt(self: TypeTest)(implicit ctx: Context): TypeTree = self.tpt + def Pattern_TypeTest_module_apply(tpt: TypeTree)(implicit ctx: Context): TypeTest = + withDefaultPos(ctx => tpd.Typed(untpd.Ident(nme.WILDCARD)(ctx.source).withType(tpt.tpe)(ctx), tpt)(ctx)) + + def Pattern_TypeTest_module_copy(original: TypeTest)(tpt: TypeTree)(implicit ctx: Context): TypeTest = + tpd.cpy.Typed(original)(untpd.Ident(nme.WILDCARD).withSpan(original.span).withType(tpt.tpe), tpt) + // // TYPE TREES // @@ -282,77 +721,233 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree = tpd.Tree + def isTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] = x match { + case x: tpd.TypeBoundsTree => None + case _ => if (x.isType) Some(x) else None + } + + // TODO move to Kernel and use isTypeTree directly with a cast + def isTypeTreeNotTerm(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[TypeTree] = termOrTypeTree match { + case _: tpd.TypeBoundsTree => None + case _ => if (termOrTypeTree.isType) Some(termOrTypeTree) else None + } + def TypeTree_pos(self: TypeTree)(implicit ctx: Context): Position = self.sourcePos def TypeTree_symbol(self: TypeTree)(implicit ctx: Context): Symbol = self.symbol def TypeTree_tpe(self: TypeTree)(implicit ctx: Context): Type = self.tpe.stripTypeVar type TypeTree_Inferred = tpd.TypeTree + def isTypeTree_Inferred(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Inferred] = tpt match { + case tpt: tpd.TypeTree if !tpt.tpe.isInstanceOf[Types.TypeBounds] => Some(tpt) + case _ => None + } + + def TypeTree_Inferred_apply(tpe: Type)(implicit ctx: Context): TypeTree_Inferred = withDefaultPos(ctx => tpd.TypeTree(tpe)(ctx)) + type TypeTree_Ident = tpd.Ident + def isTypeTree_Ident(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Ident] = tpt match { + case tpt: tpd.Ident if tpt.isType => Some(tpt) + case _ => None + } + def TypeTree_Ident_name(self: TypeTree_Ident)(implicit ctx: Context): String = self.name.toString + def TypeTree_Ident_copy(original: TypeTree_Ident)(name: String)(implicit ctx: Context): TypeTree_Ident = + tpd.cpy.Ident(original)(name.toTypeName) + type TypeTree_Select = tpd.Select + def isTypeTree_Select(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Select] = tpt match { + case tpt: tpd.Select if tpt.isType && tpt.qualifier.isTerm => Some(tpt) + case _ => None + } + def TypeTree_Select_qualifier(self: TypeTree_Select)(implicit ctx: Context): Term = self.qualifier def TypeTree_Select_name(self: TypeTree_Select)(implicit ctx: Context): String = self.name.toString + def TypeTree_Select_apply(qualifier: Term, name: String)(implicit ctx: Context): TypeTree_Select = + withDefaultPos(ctx => tpd.Select(qualifier, name.toTypeName)(ctx)) + + def TypeTree_Select_copy(original: TypeTree_Select)(qualifier: Term, name: String)(implicit ctx: Context): TypeTree_Select = + tpd.cpy.Select(original)(qualifier, name.toTypeName) + + type TypeTree_Projection = tpd.Select + def isTypeTree_Projection(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Projection] = tpt match { + case tpt: tpd.Select if tpt.isType && tpt.qualifier.isType => Some(tpt) + case _ => None + } + def TypeTree_Projection_qualifier(self: TypeTree_Projection)(implicit ctx: Context): TypeTree = self.qualifier def TypeTree_Projection_name(self: TypeTree_Projection)(implicit ctx: Context): String = self.name.toString + def TypeTree_Projection_copy(original: TypeTree_Projection)(qualifier: TypeTree, name: String)(implicit ctx: Context): TypeTree_Projection = + tpd.cpy.Select(original)(qualifier, name.toTypeName) + type TypeTree_Singleton = tpd.SingletonTypeTree + def isTypeTree_Singleton(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Singleton] = tpt match { + case tpt: tpd.SingletonTypeTree => Some(tpt) + case _ => None + } + def TypeTree_Singleton_ref(self: TypeTree_Singleton)(implicit ctx: Context): Term = self.ref + def TypeTree_Singleton_apply(ref: Term)(implicit ctx: Context): TypeTree_Singleton = + withDefaultPos(ctx => tpd.SingletonTypeTree(ref)(ctx)) + + def TypeTree_Singleton_copy(original: TypeTree_Singleton)(ref: Term)(implicit ctx: Context): TypeTree_Singleton = + tpd.cpy.SingletonTypeTree(original)(ref) + type TypeTree_Refined = tpd.RefinedTypeTree + def isTypeTree_Refined(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Refined] = tpt match { + case tpt: tpd.RefinedTypeTree => Some(tpt) + case _ => None + } + def TypeTree_Refined_tpt(self: TypeTree_Refined)(implicit ctx: Context): TypeTree = self.tpt def TypeTree_Refined_refinements(self: TypeTree_Refined)(implicit ctx: Context): List[Definition] = self.refinements + def TypeTree_Refined_copy(original: TypeTree_Refined)(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): TypeTree_Refined = + tpd.cpy.RefinedTypeTree(original)(tpt, refinements) + type TypeTree_Applied = tpd.AppliedTypeTree + def isTypeTree_Applied(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Applied] = tpt match { + case tpt: tpd.AppliedTypeTree => Some(tpt) + case _ => None + } + def TypeTree_Applied_tpt(self: TypeTree_Applied)(implicit ctx: Context): TypeTree = self.tpt def TypeTree_Applied_args(self: TypeTree_Applied)(implicit ctx: Context): List[TypeOrBoundsTree] = self.args + def TypeTree_Applied_apply(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): TypeTree_Applied = + withDefaultPos(ctx => tpd.AppliedTypeTree(tpt, args)(ctx)) + + def TypeTree_Applied_copy(original: TypeTree_Applied)(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): TypeTree_Applied = + tpd.cpy.AppliedTypeTree(original)(tpt, args) + type TypeTree_Annotated = tpd.Annotated + def isTypeTree_Annotated(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Annotated] = tpt match { + case tpt: tpd.Annotated => Some(tpt) + case _ => None + } + def TypeTree_Annotated_arg(self: TypeTree_Annotated)(implicit ctx: Context): TypeTree = self.arg def TypeTree_Annotated_annotation(self: TypeTree_Annotated)(implicit ctx: Context): Term = self.annot + def TypeTree_Annotated_apply(arg: TypeTree, annotation: Term)(implicit ctx: Context): TypeTree_Annotated = + withDefaultPos(ctx => tpd.Annotated(arg, annotation)(ctx)) + + def TypeTree_Annotated_copy(original: TypeTree_Annotated)(arg: TypeTree, annotation: Term)(implicit ctx: Context): TypeTree_Annotated = + tpd.cpy.Annotated(original)(arg, annotation) + type TypeTree_MatchType = tpd.MatchTypeTree + def isTypeTree_MatchType(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_MatchType] = tpt match { + case tpt: tpd.MatchTypeTree => Some(tpt) + case _ => None + } + def TypeTree_MatchType_bound(self: TypeTree_MatchType)(implicit ctx: Context): Option[TypeTree] = if (self.bound == tpd.EmptyTree) None else Some(self.bound) def TypeTree_MatchType_selector(self: TypeTree_MatchType)(implicit ctx: Context): TypeTree = self.selector def TypeTree_MatchType_cases(self: TypeTree_MatchType)(implicit ctx: Context): List[CaseDef] = self.cases + def TypeTree_MatchType_apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): TypeTree_MatchType = + withDefaultPos(ctx => tpd.MatchTypeTree(bound.getOrElse(tpd.EmptyTree), selector, cases)(ctx)) + + def TypeTree_MatchType_copy(original: TypeTree_MatchType)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): TypeTree_MatchType = + tpd.cpy.MatchTypeTree(original)(bound.getOrElse(tpd.EmptyTree), selector, cases) + type TypeTree_ByName = tpd.ByNameTypeTree + def isTypeTree_ByName(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_ByName] = tpt match { + case tpt: tpd.ByNameTypeTree => Some(tpt) + case _ => None + } + def TypeTree_ByName_result(self: TypeTree_ByName)(implicit ctx: Context): TypeTree = self.result + def TypeTree_ByName_apply(result: TypeTree)(implicit ctx: Context): TypeTree_ByName = + withDefaultPos(ctx => tpd.ByNameTypeTree(result)(ctx)) + + def TypeTree_ByName_copy(original: TypeTree_ByName)(result: TypeTree)(implicit ctx: Context): TypeTree_ByName = + tpd.cpy.ByNameTypeTree(original)(result) + type TypeTree_LambdaTypeTree = tpd.LambdaTypeTree + def isTypeTree_LambdaTypeTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_LambdaTypeTree] = tpt match { + case tpt: tpd.LambdaTypeTree => Some(tpt) + case _ => None + } + def TypeTree_LambdaTypeTree_tparams(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): List[TypeDef] = self.tparams def TypeTree_LambdaTypeTree_body(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): TypeOrBoundsTree = self.body + def TypeTree_LambdaTypeTree_apply(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): TypeTree_LambdaTypeTree = + withDefaultPos(ctx => tpd.LambdaTypeTree(tparams, body)(ctx)) + + def TypeTree_LambdaTypeTree_copy(original: TypeTree_LambdaTypeTree)(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): TypeTree_LambdaTypeTree = + tpd.cpy.LambdaTypeTree(original)(tparams, body) + type TypeTree_TypeBind = tpd.Bind + def isTypeTree_TypeBind(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBind] = tpt match { + case tpt: tpd.Bind if tpt.name.isTypeName => Some(tpt) + case _ => None + } + def TypeTree_TypeBind_name(self: TypeTree_TypeBind)(implicit ctx: Context): String = self.name.toString def TypeTree_TypeBind_body(self: TypeTree_TypeBind)(implicit ctx: Context): TypeOrBoundsTree = self.body + def TypeTree_TypeBind_copy(original: TypeTree_TypeBind)(name: String, tpt: TypeOrBoundsTree)(implicit ctx: Context): TypeTree_TypeBind = + tpd.cpy.Bind(original)(name.toTypeName, tpt) + type TypeTree_TypeBlock = tpd.Block + def isTypeTree_TypeBlock(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBlock] = tpt match { + case tpt: tpd.Block => Some(tpt) + case _ => None + } + def TypeTree_TypeBlock_aliases(self: TypeTree_TypeBlock)(implicit ctx: Context): List[TypeDef] = self.stats.map { case alias: TypeDef => alias } def TypeTree_TypeBlock_tpt(self: TypeTree_TypeBlock)(implicit ctx: Context): TypeTree = self.expr + def TypeTree_TypeBlock_apply(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeTree_TypeBlock = + withDefaultPos(ctx => tpd.Block(aliases, tpt)(ctx)) + + def TypeTree_TypeBlock_copy(original: TypeTree_TypeBlock)(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeTree_TypeBlock = + tpd.cpy.Block(original)(aliases, tpt) + type TypeBoundsTree = tpd.TypeBoundsTree + def isTypeBoundsTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] = x match { + case x: tpd.TypeBoundsTree => Some(x) + case x @ Trees.TypeTree() => + // TODO only enums generate this kind of type bounds. Is this possible without enums? If not generate tpd.TypeBoundsTree for enums instead + x.tpe match { + case tpe: Types.TypeBounds => + Some(tpd.TypeBoundsTree(tpd.TypeTree(tpe.lo).withSpan(x.span), tpd.TypeTree(tpe.hi).withSpan(x.span))) + case _ => None + } + case _ => None + } + def TypeBoundsTree_tpe(self: TypeBoundsTree)(implicit ctx: Context): TypeBounds = self.tpe.asInstanceOf[Types.TypeBounds] def TypeBoundsTree_low(self: TypeBoundsTree)(implicit ctx: Context): TypeTree = self.lo def TypeBoundsTree_hi(self: TypeBoundsTree)(implicit ctx: Context): TypeTree = self.hi - type WildcardType = tpd.TypeTree + type WildcardTypeTree = tpd.Ident + + def isWildcardTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] = x match { + case x @ Trees.Ident(nme.WILDCARD) => Some(x) + case _ => None + } // // TYPES @@ -498,6 +1093,37 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ImportSelector = untpd.Tree + type SimpleSelector = untpd.Ident + + def isSimpleSelector(self: ImportSelector)(implicit ctx: Context): Option[SimpleSelector] = self match { + case self: untpd.Ident => Some(self) + case _ => None + } + + def SimpleSelector_selection(self: SimpleSelector)(implicit ctx: Context): Id = self + + type RenameSelector = untpd.Thicket + + def isRenameSelector(self: ImportSelector)(implicit ctx: Context): Option[RenameSelector] = self match { + case self @ Trees.Thicket((id1: untpd.Ident) :: (id2: untpd.Ident) :: Nil) if id2.name != nme.WILDCARD => Some(self) + case _ => None + } + + def RenameSelector_from(self: RenameSelector)(implicit ctx: Context): Id = + self.trees.head.asInstanceOf[untpd.Ident] + def RenameSelector_to(self: RenameSelector)(implicit ctx: Context): Id = + self.trees.last.asInstanceOf[untpd.Ident] + + type OmitSelector = untpd.Thicket + + def isOmitSelector(self: ImportSelector)(implicit ctx: Context): Option[OmitSelector] = self match { + case self @ Trees.Thicket((id: untpd.Ident) :: Trees.Ident(nme.WILDCARD) :: Nil) => Some(self) + case _ => None + } + + def SimpleSelector_omited(self: OmitSelector)(implicit ctx: Context): Id = + self.trees.head.asInstanceOf[untpd.Ident] + // // IDENTIFIERS // @@ -557,7 +1183,46 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Constant = Constants.Constant - final def Constant_value(const: Constant): Any = const.value + def Constant_value(const: Constant): Any = const.value + + def isConstant_Unit(x: Constant): Boolean = x.tag == Constants.UnitTag + def isConstant_Null(x: Constant): Boolean = x.tag == Constants.NullTag + def isConstant_Boolean(x: Constant): Option[Boolean] = + if (x.tag == Constants.BooleanTag) Some(x.booleanValue) else None + def isConstant_Byte(x: Constant): Option[Byte] = + if (x.tag == Constants.ByteTag) Some(x.byteValue) else None + def isConstant_Short(x: Constant): Option[Short] = + if (x.tag == Constants.ShortTag) Some(x.shortValue) else None + def isConstant_Char(x: Constant): Option[Char] = + if (x.tag == Constants.CharTag) Some(x.charValue) else None + def isConstant_Int(x: Constant): Option[Int] = + if (x.tag == Constants.IntTag) Some(x.intValue) else None + def isConstant_Long(x: Constant): Option[Long] = + if (x.tag == Constants.LongTag) Some(x.longValue) else None + def isConstant_Float(x: Constant): Option[Float] = + if (x.tag == Constants.FloatTag) Some(x.floatValue) else None + def isConstant_Double(x: Constant): Option[Double] = + if (x.tag == Constants.DoubleTag) Some(x.doubleValue) else None + def isConstant_String(x: Constant): Option[String] = + if (x.tag == Constants.StringTag) Some(x.stringValue) else None + def isConstant_ClassTag(x: Constant): Option[Type] = + if (x.tag == Constants.ClazzTag) Some(x.typeValue) else None + def isConstant_Symbol(x: Constant): Option[scala.Symbol] = + if (x.tag == Constants.ScalaSymbolTag) Some(x.scalaSymbolValue) else None + + def Constant_Unit_apply(): Constant = Constants.Constant(()) + def Constant_Null_apply(): Constant = Constants.Constant(null) + def Constant_Boolean_apply(x: Boolean): Constant = Constants.Constant(x) + def Constant_Byte_apply(x: Byte): Constant = Constants.Constant(x) + def Constant_Short_apply(x: Short): Constant = Constants.Constant(x) + def Constant_Char_apply(x: Char): Constant = Constants.Constant(x) + def Constant_Int_apply(x: Int): Constant = Constants.Constant(x) + def Constant_Long_apply(x: Long): Constant = Constants.Constant(x) + def Constant_Float_apply(x: Float): Constant = Constants.Constant(x) + def Constant_Double_apply(x: Double): Constant = Constants.Constant(x) + def Constant_String_apply(x: String): Constant = Constants.Constant(x) + def Constant_ClassTag_apply(x: scala.reflect.ClassTag[_]): Constant = Constants.Constant(x) + def Constant_Symbol_apply(x: scala.Symbol): Constant = Constants.Constant(x) // // SYMBOLS @@ -569,7 +1234,6 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Symbol_flags(self: Symbol)(implicit ctx: Context): Flags = self.flags - def Symbol_privateWithin(self: Symbol)(implicit ctx: Context): Option[Type] = { val within = self.privateWithin if (within.exists && !self.is(core.Flags.Protected)) Some(within.typeRef) @@ -621,13 +1285,39 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Symbol_isClassConstructor(self: Symbol)(implicit ctx: Context): Boolean = self.isClassConstructor type PackageSymbol = core.Symbols.Symbol + + def isPackageSymbol(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] = + if (symbol.is(core.Flags.Package)) Some(symbol) else None + type ClassSymbol = core.Symbols.ClassSymbol + + def isClassSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] = + if (symbol.isClass) Some(symbol.asClass) else None + type TypeSymbol = core.Symbols.TypeSymbol + + def isTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] = + if (symbol.isType) Some(symbol.asType) else None + type DefSymbol = core.Symbols.TermSymbol + + def isDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] = + if (symbol.isTerm && symbol.is(core.Flags.Method)) Some(symbol.asTerm) else None + type BindSymbol = core.Symbols.TermSymbol + + def isBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] = + if (symbol.isTerm && symbol.is(core.Flags.Case)) Some(symbol.asTerm) else None + type ValSymbol = core.Symbols.TermSymbol + + def isValSymbol(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] = + if (symbol.isTerm && !symbol.is(core.Flags.Method) && !symbol.is(core.Flags.Case)) Some(symbol.asTerm) else None + type NoSymbol = core.Symbols.NoSymbol.type + def isNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean = symbol ne core.Symbols.NoSymbol + // // FLAGS // @@ -726,6 +1416,75 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. new scala.quoted.Types.TreeType(tpd.TypeTree(self).withSpan(dummySpan)) } + // + // DEFINITIONS + // + + def Definitions_RootPackage: Symbol = defn.RootPackage + def Definitions_RootClass: Symbol = defn.RootClass + + def Definitions_EmptyPackageClass: Symbol = defn.EmptyPackageClass + + def Definitions_ScalaPackage: Symbol = defn.ScalaPackageVal + def Definitions_ScalaPackageClass: Symbol = defn.ScalaPackageClass + + def Definitions_AnyClass: Symbol = defn.AnyClass + def Definitions_AnyValClass: Symbol = defn.AnyValClass + def Definitions_ObjectClass: Symbol = defn.ObjectClass + def Definitions_AnyRefClass: Symbol = defn.AnyRefAlias + def Definitions_NullClass: Symbol = defn.AnyClass + def Definitions_NothingClass: Symbol = defn.NothingClass + def Definitions_UnitClass: Symbol = defn.UnitClass + def Definitions_ByteClass: Symbol = defn.ByteClass + def Definitions_ShortClass: Symbol = defn.ShortClass + def Definitions_CharClass: Symbol = defn.CharClass + def Definitions_IntClass: Symbol = defn.IntClass + def Definitions_LongClass: Symbol = defn.LongClass + def Definitions_FloatClass: Symbol = defn.FloatClass + def Definitions_DoubleClass: Symbol = defn.DoubleClass + def Definitions_BooleanClass: Symbol = defn.BooleanClass + def Definitions_StringClass: Symbol = defn.StringClass + def Definitions_ClassClass: Symbol = defn.ClassClass + def Definitions_ArrayClass: Symbol = defn.ArrayClass + def Definitions_PredefModule: Symbol = defn.ScalaPredefModule.asTerm + + def Definitions_JavaLangPackage: Symbol = defn.JavaLangPackageVal + + def Definitions_ArrayModule: Symbol = defn.ArrayClass.companionModule.asTerm + + def Definitions_Array_apply: Symbol = defn.Array_apply.asTerm + def Definitions_Array_clone: Symbol = defn.Array_clone.asTerm + def Definitions_Array_length: Symbol = defn.Array_length.asTerm + def Definitions_Array_update: Symbol = defn.Array_update.asTerm + + def Definitions_RepeatedParamClass: Symbol = defn.RepeatedParamClass + + def Definitions_OptionClass: Symbol = defn.OptionClass + def Definitions_NoneModule: Symbol = defn.NoneClass.companionModule.asTerm + def Definitions_SomeModule: Symbol = defn.SomeClass.companionModule.asTerm + + def Definitions_ProductClass: Symbol = defn.ProductClass + def Definitions_FunctionClass(arity: Int, isImplicit: Boolean, isErased: Boolean): Symbol = + defn.FunctionClass(arity, isImplicit, isErased).asClass + def Definitions_TupleClass(arity: Int): Symbol = defn.TupleType(arity).classSymbol.asClass + + def Definitions_UnitType: Type = defn.UnitType + def Definitions_ByteType: Type = defn.ByteType + def Definitions_ShortType: Type = defn.ShortType + def Definitions_CharType: Type = defn.CharType + def Definitions_IntType: Type = defn.IntType + def Definitions_LongType: Type = defn.LongType + def Definitions_FloatType: Type = defn.FloatType + def Definitions_DoubleType: Type = defn.DoubleType + def Definitions_BooleanType: Type = defn.BooleanType + def Definitions_AnyType: Type = defn.AnyType + def Definitions_AnyValType: Type = defn.AnyValType + def Definitions_AnyRefType: Type = defn.AnyRefType + def Definitions_ObjectType: Type = defn.ObjectType + def Definitions_NothingType: Type = defn.NothingType + def Definitions_NullType: Type = defn.NullType + def Definitions_StringType: Type = defn.StringType + // // HELPERS // @@ -733,4 +1492,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. private def optional[T <: Trees.Tree[_]](tree: T): Option[tree.type] = if (tree.isEmpty) None else Some(tree) + private def withDefaultPos[T <: Tree](fn: Context => T)(implicit ctx: Context): T = { + fn(ctx.withSource(rootPosition.source)).withSpan(rootPosition.span) + } } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala index bd02f5484d64..e94779ef525e 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala @@ -7,110 +7,4 @@ import dotty.tools.dotc.core.StdNames.nme trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with RootPositionImpl { - object Pattern extends PatternModule { - - object IsValue extends IsValueModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Value] = pattern match { - case lit: tpd.Literal => Some(lit) - case ref: tpd.RefTree if ref.isTerm => Some(ref) - case ths: tpd.This => Some(ths) - case _ => None - } - } - - object Value extends ValueModule { - def apply(term: Term)(implicit ctx: Context): Value = term match { - case lit: tpd.Literal => lit - case ref: tpd.RefTree if ref.isTerm => ref - case ths: tpd.This => ths - } - def copy(original: Value)(term: Term)(implicit ctx: Context): Value = term match { - case lit: tpd.Literal => tpd.cpy.Literal(original)(lit.const) - case ref: tpd.RefTree if ref.isTerm => tpd.cpy.Ref(original.asInstanceOf[tpd.RefTree])(ref.name) - case ths: tpd.This => tpd.cpy.This(original)(ths.qual) - } - def unapply(x: Pattern)(implicit ctx: Context): Option[Term] = IsValue.unapply(x) - } - - object IsBind extends IsBindModule { - def unapply(x: Pattern)(implicit ctx: Context): Option[Bind] = x match { - case x: tpd.Bind if x.name.isTermName => Some(x) - case _ => None - } - } - - object Bind extends BindModule { - - def copy(original: Bind)(name: String, pattern: Pattern)(implicit ctx: Context): Bind = - withDefaultPos(ctx => tpd.cpy.Bind(original)(name.toTermName, pattern)(ctx)) - - def unapply(pattern: Pattern)(implicit ctx: Context): Option[(String, Pattern)] = pattern match { - case IsBind(pattern) => Some((pattern.name.toString, pattern.body)) - case _ => None - } - } - - object IsUnapply extends IsUnapplyModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] = pattern match { - case pattern @ Trees.UnApply(_, _, _) => Some(pattern) - case Trees.Typed(pattern @ Trees.UnApply(_, _, _), _) => Some(pattern) - case _ => None - } - } - - object Unapply extends UnapplyModule { - - def copy(original: Unapply)(fun: Term, implicits: List[Term], patterns: List[Pattern])(implicit ctx: Context): Unapply = - withDefaultPos(ctx => tpd.cpy.UnApply(original)(fun, implicits, patterns)(ctx)) - - def unapply(x: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] = x match { - case IsUnapply(x) => Some((x.fun, x.implicits, UnapplyAPI(x).patterns)) - case _ => None - } - } - - object IsAlternatives extends IsAlternativesModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] = pattern match { - case pattern: tpd.Alternative => Some(pattern) - case _ => None - } - } - - object Alternatives extends AlternativesModule { - def apply(patterns: List[Pattern])(implicit ctx: Context): Alternatives = - withDefaultPos(ctx => tpd.Alternative(patterns)(ctx)) - - def copy(original: Alternatives)(patterns: List[Pattern])(implicit ctx: Context): Alternatives = - tpd.cpy.Alternative(original)(patterns) - - def unapply(x: Pattern)(implicit ctx: Context): Option[List[Pattern]] = x match { - case x: tpd.Alternative => Some(x.trees) - case _ => None - } - } - - object IsTypeTest extends IsTypeTestModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] = pattern match { - case Trees.Typed(_: tpd.UnApply, _) => None - case pattern: tpd.Typed => Some(pattern) - case _ => None - } - } - - object TypeTest extends TypeTestModule { - def apply(tpt: TypeTree)(implicit ctx: Context): TypeTest = - withDefaultPos(ctx => tpd.Typed(untpd.Ident(nme.WILDCARD)(ctx.source).withType(tpt.tpe)(ctx), tpt)(ctx)) - - def copy(original: TypeTest)(tpt: TypeTree)(implicit ctx: Context): TypeTest = - tpd.cpy.Typed(original)(untpd.Ident(nme.WILDCARD).withSpan(original.span).withType(tpt.tpe), tpt) - - def unapply(x: Pattern)(implicit ctx: Context): Option[TypeTree] = x match { - case Trees.Typed(Trees.UnApply(_, _, _), _) => None - case Trees.Typed(expr, tpt) => Some(tpt) - case _ => None - } - } - - } - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala index 9847660aebad..c7c6f5c22ba4 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala @@ -2,10 +2,4 @@ package dotty.tools.dotc.tastyreflect trait SettingsOpsImpl extends scala.tasty.reflect.SettingsOps with scala.tasty.reflect.ContextOps with CoreImpl { - def settings: Settings = rootContext.settings - - def SettingsDeco(settings: Settings): SettingsAPI = new SettingsAPI { - def color: Boolean = settings.color.value == "always" - } - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala index f11aeca7d420..71772ebbaf1d 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala @@ -2,10 +2,4 @@ package dotty.tools.dotc.tastyreflect trait SignatureOpsImpl extends scala.tasty.reflect.SignatureOps with CoreImpl { - object Signature extends SignatureModule { - def unapply(x: Signature)(implicit ctx: Context): Option[(List[String], String)] = { - Some((x.paramsSig.map(_.toString), x.resSig.toString)) - } - } - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala b/compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala index 667df17c025a..852f752ab769 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala @@ -6,78 +6,4 @@ import dotty.tools.dotc.core.Symbols._ trait StandardDefinitions extends scala.tasty.reflect.StandardDefinitions { tasty: ReflectionImpl => - private implicit def ctx: Context = rootContext - - val definitions: DefinitionsAPI = new DefinitionsAPI { - - def RootPackage: Symbol = defn.RootPackage - def RootClass: Symbol = defn.RootClass - - def EmptyPackageClass: Symbol = defn.EmptyPackageClass - - def ScalaPackage: Symbol = defn.ScalaPackageVal - def ScalaPackageClass: Symbol = defn.ScalaPackageClass - - def AnyClass: Symbol = defn.AnyClass - def AnyValClass: Symbol = defn.AnyValClass - def ObjectClass: Symbol = defn.ObjectClass - def AnyRefClass: Symbol = defn.AnyRefAlias - def NullClass: Symbol = defn.AnyClass - def NothingClass: Symbol = defn.NothingClass - def UnitClass: Symbol = defn.UnitClass - def ByteClass: Symbol = defn.ByteClass - def ShortClass: Symbol = defn.ShortClass - def CharClass: Symbol = defn.CharClass - def IntClass: Symbol = defn.IntClass - def LongClass: Symbol = defn.LongClass - def FloatClass: Symbol = defn.FloatClass - def DoubleClass: Symbol = defn.DoubleClass - def BooleanClass: Symbol = defn.BooleanClass - def StringClass: Symbol = defn.StringClass - def ClassClass: Symbol = defn.ClassClass - def ArrayClass: Symbol = defn.ArrayClass - def PredefModule: Symbol = defn.ScalaPredefModule.asTerm - - def JavaLangPackage: Symbol = defn.JavaLangPackageVal - - def ArrayModule: Symbol = defn.ArrayClass.companionModule.asTerm - - def Array_apply: Symbol = defn.Array_apply.asTerm - def Array_clone: Symbol = defn.Array_clone.asTerm - def Array_length: Symbol = defn.Array_length.asTerm - def Array_update: Symbol = defn.Array_update.asTerm - - def RepeatedParamClass: Symbol = defn.RepeatedParamClass - - def OptionClass: Symbol = defn.OptionClass - def NoneModule: Symbol = defn.NoneClass.companionModule.asTerm - def SomeModule: Symbol = defn.SomeClass.companionModule.asTerm - - def ProductClass: Symbol = defn.ProductClass - def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol = - defn.FunctionClass(arity, isImplicit, isErased).asClass - def TupleClass(arity: Int): Symbol = defn.TupleType(arity).classSymbol.asClass - - def ScalaPrimitiveValueClasses: List[Symbol] = - UnitClass :: BooleanClass :: ScalaNumericValueClasses - def ScalaNumericValueClasses: List[Symbol] = - ByteClass :: ShortClass :: IntClass :: LongClass :: FloatClass :: DoubleClass :: CharClass :: Nil - - def UnitType: Type = defn.UnitType - def ByteType: Type = defn.ByteType - def ShortType: Type = defn.ShortType - def CharType: Type = defn.CharType - def IntType: Type = defn.IntType - def LongType: Type = defn.LongType - def FloatType: Type = defn.FloatType - def DoubleType: Type = defn.DoubleType - def BooleanType: Type = defn.BooleanType - def AnyType: Type = defn.AnyType - def AnyValType: Type = defn.AnyValType - def AnyRefType: Type = defn.AnyRefType - def ObjectType: Type = defn.ObjectType - def NothingType: Type = defn.NothingType - def NullType: Type = defn.NullType - def StringType: Type = defn.StringType - } } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala index e9315528aa02..8f85a27aef4e 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala @@ -7,20 +7,10 @@ import dotty.tools.dotc.core.Decorators._ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl { - object IsPackageSymbol extends IsPackageSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] = - if (symbol.is(Flags.Package)) Some(symbol) else None - } - def PackageSymbolDeco(symbol: PackageSymbol): PackageSymbolAPI = new PackageSymbolAPI { def tree(implicit ctx: Context): PackageDef = FromSymbol.packageDefFromSym(symbol) } - object IsTypeSymbol extends IsTypeSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] = - if (symbol.isType) Some(symbol.asType) else None - } - def TypeSymbolDeco(symbol: TypeSymbol): TypeSymbolAPI = new TypeSymbolAPI { def tree(implicit ctx: Context): TypeDef = FromSymbol.typeDefFromSym(symbol) @@ -31,11 +21,6 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl { def of(fullName: String)(implicit ctx: Context): ClassSymbol = ctx.requiredClass(fullName) } - object IsClassSymbol extends IsClassSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] = - if (symbol.isClass) Some(symbol.asClass) else None - } - def ClassSymbolDeco(symbol: ClassSymbol): ClassSymbolAPI = new ClassSymbolAPI { def tree(implicit ctx: Context): ClassDef = FromSymbol.classDef(symbol) @@ -100,11 +85,6 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl { private def isField(sym: Symbol)(implicit ctx: Context): Boolean = sym.isTerm && !sym.is(Flags.Method) } - object IsDefSymbol extends IsDefSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] = - if (symbol.isTerm && symbol.is(Flags.Method)) Some(symbol.asTerm) else None - } - def DefSymbolDeco(symbol: DefSymbol): DefSymbolAPI = new DefSymbolAPI { def tree(implicit ctx: Context): DefDef = FromSymbol.defDefFromSym(symbol) @@ -113,11 +93,6 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl { } } - object IsValSymbol extends IsValSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] = - if (symbol.isTerm && !symbol.is(Flags.Method) && !symbol.is(Flags.Case)) Some(symbol.asTerm) else None - } - def ValSymbolDeco(symbol: ValSymbol): ValSymbolAPI = new ValSymbolAPI { def tree(implicit ctx: Context): ValDef = FromSymbol.valDefFromSym(symbol) @@ -132,16 +107,8 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl { } } - object IsBindSymbol extends IsBindSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] = - if (symbol.isTerm && symbol.is(Flags.Case)) Some(symbol.asTerm) else None // TODO - } - def BindSymbolDeco(symbol: BindSymbol): BindSymbolAPI = new BindSymbolAPI { def tree(implicit ctx: Context): Bind = FromSymbol.bindFromSym(symbol) } - object NoSymbol extends NoSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Boolean = symbol ne core.Symbols.NoSymbol - } } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala index 62e359279055..64230a19e878 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala @@ -1,690 +1,7 @@ package dotty.tools.dotc.tastyreflect -import dotty.tools.dotc.ast.{Trees, tpd, untpd} -import dotty.tools.dotc.core.Decorators._ -import dotty.tools.dotc.core.Symbols.NoSymbol -import dotty.tools.dotc.core._ -import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFromSym} - trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with RootPositionImpl with Helpers { - // ----- Tree ---------------------------------------------------- - - object IsPackageClause extends IsPackageClauseModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[PackageClause] = tree match { - case x: tpd.PackageDef => Some(x) - case _ => None - } - } - - object PackageClause extends PackageClauseModule { - def apply(pid: Term.Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = - withDefaultPos(ctx => tpd.PackageDef(pid.asInstanceOf[tpd.RefTree], stats)(ctx)) - - def copy(original: PackageClause)(pid: Term.Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = - tpd.cpy.PackageDef(original)(pid, stats) - - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term.Ref, List[Tree])] = tree match { - case x: tpd.PackageDef => Some((x.pid, x.stats)) - case _ => None - } - } - - object IsImport extends IsImportModule { - override def unapply(tree: Tree)(implicit ctx: Contexts.Context): Option[Import] = tree match { - case tree: tpd.Import => Some(tree) - case _ => None - } - } - - object Import extends ImportModule { - def apply(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import = - withDefaultPos(ctx => tpd.Import(impliedOnly, expr, selectors)(ctx)) - - def copy(original: Import)(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import = - tpd.cpy.Import(original)(impliedOnly, expr, selectors) - - def unapply(x: Tree)(implicit ctx: Context): Option[(Boolean, Term, List[ImportSelector])] = x match { - case x: tpd.Import => Some((x.impliedOnly, x.expr, x.selectors)) - case _ => None - } - } - - object IsStatement extends IsStatementModule { - /** Matches any Statement and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Statement] = tree match { - case IsDefinition(tree) => Some(tree) - case tree if tree.isTerm => Some(tree) - case _ => None - } - } - - // ----- Definitions ---------------------------------------------- - - object IsDefinition extends IsDefinitionModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[Definition] = tree match { - case tree: tpd.MemberDef => Some(tree) - case tree: PackageDefinition => Some(tree) - case _ => None - } - } - - - // ClassDef - - object IsClassDef extends IsClassDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[ClassDef] = tree match { - case x: tpd.TypeDef if x.isClassDef => Some(x) - case _ => None - } - } - - object ClassDef extends ClassDefModule { - - def copy(original: ClassDef)(name: String, constr: DefDef, parents: List[TermOrTypeTree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement])(implicit ctx: Context): ClassDef = { - val Trees.TypeDef(_, originalImpl: tpd.Template) = original - tpd.cpy.TypeDef(original)(name.toTypeName, tpd.cpy.Template(originalImpl)(constr, parents, derived, selfOpt.getOrElse(tpd.EmptyValDef), body)) - } - - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, DefDef, List[TermOrTypeTree], List[TypeTree], Option[ValDef], List[Statement])] = tree match { - case Trees.TypeDef(name, impl: tpd.Template) => - Some((name.toString, impl.constr, impl.parents, impl.derived.asInstanceOf[List[TypeTree]], optional(impl.self), impl.body)) - case _ => None - } - } - - - // DefDef - - object IsDefDef extends IsDefDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[DefDef] = tree match { - case x: tpd.DefDef => Some(x) - case _ => None - } - } - - object DefDef extends DefDefModule { - def apply(symbol: DefSymbol, rhsFn: List[Type] => List[List[Term]] => Option[Term])(implicit ctx: Context): DefDef = - withDefaultPos(ctx => tpd.polyDefDef(symbol, tparams => vparamss => rhsFn(tparams)(vparamss).getOrElse(tpd.EmptyTree))(ctx)) - - def copy(original: DefDef)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): DefDef = - tpd.cpy.DefDef(original)(name.toTermName, typeParams, paramss, tpt, rhs.getOrElse(tpd.EmptyTree)) - - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] = tree match { - case x: tpd.DefDef => - Some((x.name.toString, x.tparams, x.vparamss, x.tpt, optional(x.rhs))) - case _ => None - } - } - - - // ValDef - - object IsValDef extends IsValDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[ValDef] = tree match { - case x: tpd.ValDef => Some(x) - case _ => None - } - } - - object ValDef extends ValDefModule { - def apply(symbol: ValSymbol, rhs: Option[Term])(implicit ctx: Context): ValDef = - tpd.ValDef(symbol, rhs.getOrElse(tpd.EmptyTree)) - - def copy(original: ValDef)(name: String, tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): ValDef = - tpd.cpy.ValDef(original)(name.toTermName, tpt, rhs.getOrElse(tpd.EmptyTree)) - - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeTree, Option[Term])] = tree match { - case x: tpd.ValDef => - Some((x.name.toString, x.tpt, optional(x.rhs))) - case _ => None - } - } - - - // TypeDef - - object IsTypeDef extends IsTypeDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[TypeDef] = tree match { - case x: tpd.TypeDef if !x.symbol.isClass => Some(x) - case _ => None - } - } - - object TypeDef extends TypeDefModule { - def apply(symbol: TypeSymbol)(implicit ctx: Context): TypeDef = withDefaultPos(ctx => tpd.TypeDef(symbol)(ctx)) - def copy(original: TypeDef)(name: String, rhs: TypeOrBoundsTree)(implicit ctx: Context): TypeDef = - tpd.cpy.TypeDef(original)(name.toTypeName, rhs) - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree /* TypeTree | TypeBoundsTree */)] = tree match { - case x: tpd.TypeDef if !x.symbol.isClass => Some((x.name.toString, x.rhs)) - case _ => None - } - } - - - // PackageDef - - - object IsPackageDef extends IsPackageDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[PackageDef] = tree match { - case x: PackageDefinition => Some(x) - case _ => None - } - } - - object PackageDef extends PackageDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, PackageDef)] = tree match { - case x: PackageDefinition => - Some((x.symbol.name.toString, packageDefFromSym(x.symbol.owner))) - case _ => None - } - } - - // ----- Terms ---------------------------------------------------- - - object IsTerm extends IsTermModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[Term] = - if (tree.isTerm) Some(tree) else None - def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[Term] = - if (termOrTypeTree.isTerm) Some(termOrTypeTree) else None - } - - object Term extends TermModule with TermCoreModule { - - object IsIdent extends IsIdentModule { - def unapply(x: Term)(implicit ctx: Context): Option[Ident] = x match { - case x: tpd.Ident if x.isTerm => Some(x) - case _ => None - } - } - - object Ref extends RefModule { - def apply(sym: Symbol)(implicit ctx: Context): Ref = withDefaultPos(ctx => tpd.ref(sym)(ctx).asInstanceOf[tpd.RefTree]) - } - - object Ident extends IdentModule { - def apply(tmref: TermRef)(implicit ctx: Context): Term = - withDefaultPos(implicit ctx => tpd.ref(tmref).asInstanceOf[Term]) - - def copy(original: Tree)(name: String)(implicit ctx: Context): Ident = - tpd.cpy.Ident(original)(name.toTermName) - - def unapply(x: Term)(implicit ctx: Context): Option[String] = x match { - case x: tpd.Ident if x.isTerm => Some(x.name.show) - case _ => None - } - } - - object IsSelect extends IsSelectModule { - def unapply(x: Term)(implicit ctx: Context): Option[Select] = x match { - case x: tpd.Select if x.isTerm => Some(x) - case _ => None - } - } - - - object Select extends SelectModule { - def unique(qualifier: Term, name: String)(implicit ctx: Context): Select = { - val denot = qualifier.tpe.member(name.toTermName) - assert(!denot.isOverloaded, s"The symbol `$name` is overloaded. The method Select.unique can only be used for non-overloaded symbols.") - withDefaultPos(implicit ctx => tpd.Select(qualifier, name.toTermName)) - } - - def overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Apply = - withDefaultPos(implicit ctx => tpd.applyOverloaded(qualifier, name.toTermName, args, targs, Types.WildcardType).asInstanceOf[Apply]) - - def copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Select = - tpd.cpy.Select(original)(qualifier, name.toTermName) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, String)] = x match { - case x: tpd.Select if x.isTerm => Some((x.qualifier, x.name.toString)) - case _ => None - } - } - - object IsLiteral extends IsLiteralModule { - def unapply(x: Term)(implicit ctx: Context): Option[Literal] = x match { - case x: tpd.Literal => Some(x) - case _ => None - } - } - - - - object Literal extends LiteralModule { - - def apply(constant: Constant)(implicit ctx: Context): Literal = - withDefaultPos(ctx => tpd.Literal(constant)(ctx)) - - def copy(original: Tree)(constant: Constant)(implicit ctx: Context): Literal = - tpd.cpy.Literal(original)(constant) - - def unapply(x: Term)(implicit ctx: Context): Option[Constant] = x match { - case Trees.Literal(const) => Some(const) - case _ => None - } - } - - object IsThis extends IsThisModule { - def unapply(x: Term)(implicit ctx: Context): Option[This] = x match { - case x: tpd.This => Some(x) - case _ => None - } - } - - - object This extends ThisModule { - - def apply(cls: ClassSymbol)(implicit ctx: Context): This = - withDefaultPos(ctx => tpd.This(cls)(ctx)) - - def copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): This = - tpd.cpy.This(original)(qual.getOrElse(untpd.EmptyTypeIdent)) - - def unapply(x: Term)(implicit ctx: Context): Option[Option[Id]] = x match { - case Trees.This(qual) => Some(optional(qual)) - case _ => None - } - } - - object IsNew extends IsNewModule { - def unapply(x: Term)(implicit ctx: Context): Option[New] = x match { - case x: tpd.New => Some(x) - case _ => None - } - } - - object New extends NewModule { - - def apply(tpt: TypeTree)(implicit ctx: Context): New = withDefaultPos(ctx => tpd.New(tpt)(ctx)) - - def copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): New = - tpd.cpy.New(original)(tpt) - - def unapply(x: Term)(implicit ctx: Context): Option[TypeTree] = x match { - case x: tpd.New => Some(x.tpt) - case _ => None - } - } - - object IsNamedArg extends IsNamedArgModule { - def unapply(x: Term)(implicit ctx: Context): Option[NamedArg] = x match { - case x: tpd.NamedArg if x.name.isInstanceOf[Names.TermName] => Some(x) // TODO: Now, the name should alwas be a term name - case _ => None - } - } - - object NamedArg extends NamedArgModule { - - def apply(name: String, arg: Term)(implicit ctx: Context): NamedArg = - withDefaultPos(ctx => tpd.NamedArg(name.toTermName, arg)(ctx)) - - def copy(tree: NamedArg)(name: String, arg: Term)(implicit ctx: Context): NamedArg = - tpd.cpy.NamedArg(tree)(name.toTermName, arg) - - def unapply(x: Term)(implicit ctx: Context): Option[(String, Term)] = x match { - case x: tpd.NamedArg if x.name.isInstanceOf[Names.TermName] => Some((x.name.toString, x.arg)) - case _ => None - } - } - - object IsApply extends IsApplyModule { - def unapply(x: Term)(implicit ctx: Context): Option[Apply] = x match { - case x: tpd.Apply => Some(x) - case _ => None - } - } - - - object Apply extends ApplyModule { - - def apply(fn: Term, args: List[Term])(implicit ctx: Context): Apply = - withDefaultPos(ctx => tpd.Apply(fn, args)(ctx)) - - def copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Apply = - tpd.cpy.Apply(original)(fun, args) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[Term])] = x match { - case x: tpd.Apply => Some((x.fun, x.args)) - case _ => None - } - } - - object IsTypeApply extends IsTypeApplyModule { - def unapply(x: Term)(implicit ctx: Context): Option[TypeApply] = x match { - case x: tpd.TypeApply => Some(x) - case _ => None - } - } - - - object TypeApply extends TypeApplyModule { - - def apply(fn: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = - withDefaultPos(ctx => tpd.TypeApply(fn, args)(ctx)) - - def copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = - tpd.cpy.TypeApply(original)(fun, args) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[TypeTree])] = x match { - case x: tpd.TypeApply => Some((x.fun, x.args)) - case _ => None - } - } - - object IsSuper extends IsSuperModule { - def unapply(x: Term)(implicit ctx: Context): Option[Super] = x match { - case x: tpd.Super => Some(x) - case _ => None - } - } - - - object Super extends SuperModule { - def apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = - withDefaultPos(ctx => tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), false, NoSymbol)(ctx)) - - def copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = - tpd.cpy.Super(original)(qual, mix.getOrElse(untpd.EmptyTypeIdent)) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, Option[Id])] = x match { - case x: tpd.Super => Some((x.qual, if (x.mix.isEmpty) None else Some(x.mix))) - case _ => None - } - } - - object IsTyped extends IsTypedModule { - def unapply(x: Term)(implicit ctx: Context): Option[Typed] = x match { - case x: tpd.Typed => Some(x) - case _ => None - } - } - - - object Typed extends TypedModule { - def apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = - withDefaultPos(ctx => tpd.Typed(expr, tpt)(ctx)) - - def copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = - tpd.cpy.Typed(original)(expr, tpt) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, TypeTree)] = x match { - case x: tpd.Typed => Some((x.expr, x.tpt)) - case _ => None - } - } - - object IsAssign extends IsAssignModule { - def unapply(x: Term)(implicit ctx: Context): Option[Assign] = x match { - case x: tpd.Assign => Some(x) - case _ => None - } - } - - - object Assign extends AssignModule { - def apply(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = - withDefaultPos(ctx => tpd.Assign(lhs, rhs)(ctx)) - - def copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = - tpd.cpy.Assign(original)(lhs, rhs) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, Term)] = x match { - case x: tpd.Assign => Some((x.lhs, x.rhs)) - case _ => None - } - } - - object IsBlock extends IsBlockModule { - def unapply(x: Term)(implicit ctx: Context): Option[Block] = normalizedLoops(x) match { - case x: tpd.Block => Some(x) - case _ => None - } - - /** Normalizes non Blocks. - * i) Put `while` and `doWhile` loops in their own blocks: `{ def while$() = ...; while$() }` - * ii) Put closures in their own blocks: `{ def anon$() = ...; closure(anon$, ...) }` - */ - private def normalizedLoops(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match { - case block: tpd.Block if block.stats.size > 1 => - def normalizeInnerLoops(stats: List[tpd.Tree]): List[tpd.Tree] = stats match { - case (x: tpd.DefDef) :: y :: xs if needsNormalization(y) => - tpd.Block(x :: Nil, y) :: normalizeInnerLoops(xs) - case x :: xs => x :: normalizeInnerLoops(xs) - case Nil => Nil - } - if (needsNormalization(block.expr)) { - val stats1 = normalizeInnerLoops(block.stats.init) - val normalLoop = tpd.Block(block.stats.last :: Nil, block.expr) - tpd.Block(stats1, normalLoop) - } else { - val stats1 = normalizeInnerLoops(block.stats) - tpd.cpy.Block(block)(stats1, block.expr) - } - case _ => tree - } - - /** If it is the second statement of a closure. See: `normalizedLoops` */ - private def needsNormalization(tree: tpd.Tree)(implicit ctx: Context): Boolean = tree match { - case _: tpd.Closure => true - case _ => false - } - } - - - object Block extends BlockModule { - def apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = - withDefaultPos(ctx => tpd.Block(stats, expr)(ctx)) - - def copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = - tpd.cpy.Block(original)(stats, expr) - - def unapply(x: Term)(implicit ctx: Context): Option[(List[Statement], Term)] = x match { - case IsBlock(x) => Some((x.stats, x.expr)) - case _ => None - } - } - - object IsInlined extends IsInlinedModule { - def unapply(x: Term)(implicit ctx: Context): Option[Inlined] = x match { - case x: tpd.Inlined => Some(x) - case _ => None - } - } - - - object Inlined extends InlinedModule { - def apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined = - withDefaultPos(ctx => tpd.Inlined(call.getOrElse(tpd.EmptyTree), bindings.map { case b: tpd.MemberDef => b }, expansion)(ctx)) - - def copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined = - tpd.cpy.Inlined(original)(call.getOrElse(tpd.EmptyTree), bindings.asInstanceOf[List[tpd.MemberDef]], expansion) - - def unapply(x: Term)(implicit ctx: Context): Option[(Option[TermOrTypeTree], List[Statement], Term)] = x match { - case x: tpd.Inlined => - Some((optional(x.call), x.bindings, x.expansion)) - case _ => None - } - } - - object IsLambda extends IsLambdaModule { - def unapply(x: Term)(implicit ctx: Context): Option[Lambda] = x match { - case x: tpd.Closure => Some(x) - case _ => None - } - } - - - object Lambda extends LambdaModule { - def apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Lambda = - withDefaultPos(ctx => tpd.Closure(Nil, meth, tpt.getOrElse(tpd.EmptyTree))(ctx)) - - def copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Lambda = - tpd.cpy.Closure(original)(Nil, meth, tpt.getOrElse(tpd.EmptyTree)) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, Option[TypeTree])] = x match { - case x: tpd.Closure => Some((x.meth, optional(x.tpt))) - case _ => None - } - } - - object IsIf extends IsIfModule { - def unapply(x: Term)(implicit ctx: Context): Option[If] = x match { - case x: tpd.If => Some(x) - case _ => None - } - } - - - object If extends IfModule { - def apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = - withDefaultPos(ctx => tpd.If(cond, thenp, elsep)(ctx)) - - def copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = - tpd.cpy.If(original)(cond, thenp, elsep) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, Term, Term)] = x match { - case x: tpd.If => Some((x.cond, x.thenp, x.elsep)) - case _ => None - } - } - - object IsMatch extends IsMatchModule { - def unapply(x: Term)(implicit ctx: Context): Option[Match] = x match { - case x: tpd.Match => Some(x) - case _ => None - } - } - - - object Match extends MatchModule { - def apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = - withDefaultPos(ctx => tpd.Match(selector, cases)(ctx)) - - def copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = - tpd.cpy.Match(original)(selector, cases) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[CaseDef])] = x match { - case x: tpd.Match => Some((x.selector, x.cases)) - case _ => None - } - } - - object IsTry extends IsTryModule { - def unapply(x: Term)(implicit ctx: Context): Option[Try] = x match { - case x: tpd.Try => Some(x) - case _ => None - } - } - - - object Try extends TryModule { - def apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try = - withDefaultPos(ctx => tpd.Try(expr, cases, finalizer.getOrElse(tpd.EmptyTree))(ctx)) - - def copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try = - tpd.cpy.Try(original)(expr, cases, finalizer.getOrElse(tpd.EmptyTree)) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[CaseDef], Option[Term])] = x match { - case x: tpd.Try => Some((x.expr, x.cases, optional(x.finalizer))) - case _ => None - } - } - - object IsReturn extends IsReturnModule { - def unapply(x: Term)(implicit ctx: Context): Option[Return] = x match { - case x: tpd.Return => Some(x) - case _ => None - } - } - - - object Return extends ReturnModule { - def apply(expr: Term)(implicit ctx: Context): Return = - withDefaultPos(ctx => tpd.Return(expr, ctx.owner)(ctx)) - - def copy(original: Tree)(expr: Term)(implicit ctx: Context): Return = - tpd.cpy.Return(original)(expr, tpd.ref(ctx.owner)) - - def unapply(x: Term)(implicit ctx: Context): Option[Term] = x match { - case x: tpd.Return => Some(x.expr) - case _ => None - } - } - - object IsRepeated extends IsRepeatedModule { - def unapply(x: Term)(implicit ctx: Context): Option[Repeated] = x match { - case x: tpd.SeqLiteral => Some(x) - case _ => None - } - } - - - object Repeated extends RepeatedModule { - def apply(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Repeated = - withDefaultPos(ctx => tpd.SeqLiteral(elems, elemtpt)(ctx)) - - def copy(original: Tree)(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Repeated = - tpd.cpy.SeqLiteral(original)(elems, elemtpt) - - def unapply(x: Tree)(implicit ctx: Context): Option[(List[Term], TypeTree)] = x match { - case x: tpd.SeqLiteral => Some((x.elems, x.elemtpt)) - case _ => None - } - } - - object IsSelectOuter extends IsSelectOuterModule { - def unapply(x: Term)(implicit ctx: Context): Option[SelectOuter] = x match { - case x: tpd.Select => - x.name match { - case NameKinds.OuterSelectName(_, _) => Some(x) - case _ => None - } - case _ => None - } - } - - - object SelectOuter extends SelectOuterModule { - - def apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter = - withDefaultPos(ctx => tpd.Select(qualifier, NameKinds.OuterSelectName(name.toTermName, levels))(ctx)) - - def copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter = - tpd.cpy.Select(original)(qualifier, NameKinds.OuterSelectName(name.toTermName, levels)) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, Int, Type)] = x match { - case x: tpd.Select => - x.name match { - case NameKinds.OuterSelectName(_, levels) => Some((x.qualifier, levels, x.tpe.stripTypeVar)) - case _ => None - } - case _ => None - } - } - - object IsWhile extends IsWhileModule { - def unapply(x: Term)(implicit ctx: Context): Option[While] = x match { - case x: tpd.WhileDo => Some(x) - case _ => None - } - } - - - object While extends WhileModule { - def apply(cond: Term, body: Term)(implicit ctx: Context): While = - withDefaultPos(ctx => tpd.WhileDo(cond, body)(ctx)) - - def copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): While = - tpd.cpy.WhileDo(original)(cond, body) - - def unapply(x: Term)(implicit ctx: Context): Option[(Term, Term)] = x match { - case x: tpd.WhileDo => Some((x.cond, x.body)) - case _ => None - } - } - } - def termAsTermOrTypeTree(term: Term): TermOrTypeTree = term } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala index 2e60623d2bc2..6d2a1ae3bae4 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala @@ -1,303 +1,8 @@ package dotty.tools.dotc.tastyreflect -import dotty.tools.dotc.ast.{Trees, tpd} -import dotty.tools.dotc.core.Decorators._ -import dotty.tools.dotc.core.StdNames.nme -import dotty.tools.dotc.core.{Contexts, Types} - - trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps with RootPositionImpl { - // ----- TypeTrees ------------------------------------------------ - - object IsTypeTree extends IsTypeTreeModule { - def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] = x match { - case x: tpd.TypeBoundsTree => None - case _ => if (x.isType) Some(x) else None - } - - def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] = termOrTypeTree match { - case _: tpd.TypeBoundsTree => None - case _ => if (termOrTypeTree.isType) Some(termOrTypeTree) else None - } - } - - object TypeTree extends TypeTreeModule with TypeTreeCoreModule { - - object IsInferred extends IsInferredModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Inferred] = tpt match { - case tpt: tpd.TypeTree if !tpt.tpe.isInstanceOf[Types.TypeBounds] => Some(tpt) - case _ => None - } - } - - object Inferred extends InferredModule { - def apply(tpe: Type)(implicit ctx: Context): Inferred = withDefaultPos(ctx => tpd.TypeTree(tpe)(ctx)) - - def unapply(x: TypeTree)(implicit ctx: Context): Boolean = x match { - case x @ Trees.TypeTree() => !x.tpe.isInstanceOf[Types.TypeBounds] - case _ => false - } - } - - object IsIdent extends IsIdentModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Ident] = tpt match { - case tpt: tpd.Ident if tpt.isType => Some(tpt) - case _ => None - } - } - - object Ident extends IdentModule { - def copy(original: Ident)(name: String)(implicit ctx: Context): Ident = - tpd.cpy.Ident(original)(name.toTypeName) - def unapply(x: TypeTree)(implicit ctx: Context): Option[String] = x match { - case x: tpd.Ident if x.isType => Some(x.name.toString) - case _ => None - } - } - - object IsSelect extends IsSelectModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Select] = tpt match { - case tpt: tpd.Select if tpt.isType && tpt.qualifier.isTerm => Some(tpt) - case _ => None - } - } - - object Select extends SelectModule { - def apply(qualifier: Term, name: String)(implicit ctx: Context): Select = - withDefaultPos(ctx => tpd.Select(qualifier, name.toTypeName)(ctx)) - - def copy(original: Select)(qualifier: Term, name: String)(implicit ctx: Context): Select = - tpd.cpy.Select(original)(qualifier, name.toTypeName) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[(Term, String)] = x match { - case x: tpd.Select if x.isType && x.qualifier.isTerm => Some(x.qualifier, x.name.toString) - case _ => None - } - } - - object IsProjection extends IsProjectionModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Projection] = tpt match { - case tpt: tpd.Select if tpt.isType && tpt.qualifier.isType => Some(tpt) - case _ => None - } - } - - object Projection extends ProjectionModule { - def copy(original: Projection)(qualifier: TypeTree, name: String)(implicit ctx: Context): Projection = - tpd.cpy.Select(original)(qualifier, name.toTypeName) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, String)] = x match { - case x: tpd.Select if x.isType && x.qualifier.isType => Some(x.qualifier, x.name.toString) - case _ => None - } - } - - object IsSingleton extends IsSingletonModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Singleton] = tpt match { - case tpt: tpd.SingletonTypeTree => Some(tpt) - case _ => None - } - } - - object Singleton extends SingletonModule { - def apply(ref: Term)(implicit ctx: Context): Singleton = - withDefaultPos(ctx => tpd.SingletonTypeTree(ref)(ctx)) - - def copy(original: Singleton)(ref: Term)(implicit ctx: Context): Singleton = - tpd.cpy.SingletonTypeTree(original)(ref) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[Term] = x match { - case x: tpd.SingletonTypeTree => Some(x.ref) - case _ => None - } - } - - object IsRefined extends IsRefinedModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Refined] = tpt match { - case tpt: tpd.RefinedTypeTree => Some(tpt) - case _ => None - } - } - - object Refined extends RefinedModule { - def copy(original: Refined)(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): Refined = - tpd.cpy.RefinedTypeTree(original)(tpt, refinements) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[Definition])] = x match { - case x: tpd.RefinedTypeTree => Some(x.tpt, x.refinements) - case _ => None - } - } - - object IsApplied extends IsAppliedModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Applied] = tpt match { - case tpt: tpd.AppliedTypeTree => Some(tpt) - case _ => None - } - } - - object Applied extends AppliedModule { - def apply(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied = - withDefaultPos(ctx => tpd.AppliedTypeTree(tpt, args)(ctx)) - - def copy(original: Applied)(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied = - tpd.cpy.AppliedTypeTree(original)(tpt, args) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] = x match { - case x: tpd.AppliedTypeTree => Some(x.tpt, x.args) - case _ => None - } - } - - object IsAnnotated extends IsAnnotatedModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Annotated] = tpt match { - case tpt: tpd.Annotated => Some(tpt) - case _ => None - } - } - - object Annotated extends AnnotatedModule { - def apply(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated = - withDefaultPos(ctx => tpd.Annotated(arg, annotation)(ctx)) - - def copy(original: Annotated)(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated = - tpd.cpy.Annotated(original)(arg, annotation) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, Term)] = x match { - case x: tpd.Annotated => Some(x.arg, x.annot) - case _ => None - } - } - - object IsMatchType extends IsMatchTypeModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[MatchType] = tpt match { - case tpt: tpd.MatchTypeTree => Some(tpt) - case _ => None - } - } - - object MatchType extends MatchTypeModule { - def apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType = - withDefaultPos(ctx => tpd.MatchTypeTree(bound.getOrElse(tpd.EmptyTree), selector, cases)(ctx)) - - def copy(original: MatchType)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType = - tpd.cpy.MatchTypeTree(original)(bound.getOrElse(tpd.EmptyTree), selector, cases) - - def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[(Option[TypeTree], TypeTree, List[CaseDef])] = x match { - case x: tpd.MatchTypeTree => Some((if (x.bound == tpd.EmptyTree) None else Some(x.bound), x.selector, x.cases)) - case _ => None - } - } - - object IsByName extends IsByNameModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[ByName] = tpt match { - case tpt: tpd.ByNameTypeTree => Some(tpt) - case _ => None - } - } - - object ByName extends ByNameModule { - def apply(result: TypeTree)(implicit ctx: Context): ByName = - withDefaultPos(ctx => tpd.ByNameTypeTree(result)(ctx)) - - def copy(original: ByName)(result: TypeTree)(implicit ctx: Context): ByName = - tpd.cpy.ByNameTypeTree(original)(result) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[TypeTree] = x match { - case x: tpd.ByNameTypeTree => Some(x.result) - case _ => None - } - } - - object IsLambdaTypeTree extends IsLambdaTypeTreeModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[LambdaTypeTree] = tpt match { - case tpt: tpd.LambdaTypeTree => Some(tpt) - case _ => None - } - } - - object LambdaTypeTree extends LambdaTypeTreeModule { - def apply(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree = - withDefaultPos(ctx => tpd.LambdaTypeTree(tparams, body)(ctx)) - - def copy(original: LambdaTypeTree)(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree = - tpd.cpy.LambdaTypeTree(original)(tparams, body) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[(List[TypeDef], TypeOrBoundsTree)] = x match { - case Trees.LambdaTypeTree(tparams, body) => Some((tparams, body)) - case _ => None - } - } - - object IsTypeBind extends IsTypeBindModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBind] = tpt match { - case tpt: tpd.Bind if tpt.name.isTypeName => Some(tpt) - case _ => None - } - } - - object TypeBind extends TypeBindModule { - def copy(original: TypeBind)(name: String, tpt: TypeOrBoundsTree)(implicit ctx: Context): TypeBind = - tpd.cpy.Bind(original)(name.toTypeName, tpt) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree)] = x match { - case x: tpd.Bind if x.name.isTypeName => Some((x.name.toString, x.body)) - case _ => None - } - } - - object IsTypeBlock extends IsTypeBlockModule { - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBlock] = tpt match { - case tpt: tpd.Block => Some(tpt) - case _ => None - } - } - - - object TypeBlock extends TypeBlockModule { - def apply(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock = - withDefaultPos(ctx => tpd.Block(aliases, tpt)(ctx)) - - def copy(original: TypeBlock)(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock = - tpd.cpy.Block(original)(aliases, tpt) - - def unapply(x: TypeTree)(implicit ctx: Context): Option[(List[TypeDef], TypeTree)] = x match { - case x: tpd.Block => Some((x.stats.map { case alias: TypeDef => alias }, x.expr)) - case _ => None - } - } - } - - // ----- TypeBoundsTrees ------------------------------------------------ - - object IsTypeBoundsTree extends IsTypeBoundsTreeModule { - def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] = x match { - case x: tpd.TypeBoundsTree => Some(x) - case x @ Trees.TypeTree() => - // TODO only enums generate this kind of type bounds. Is this possible without enums? If not generate tpd.TypeBoundsTree for enums instead - x.tpe match { - case tpe: Types.TypeBounds => - Some(tpd.TypeBoundsTree(tpd.TypeTree(tpe.lo).withSpan(x.span), tpd.TypeTree(tpe.hi).withSpan(x.span))) - case _ => None - } - case _ => None - } - } - - object TypeBoundsTree extends TypeBoundsTreeModule { - def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] = x match { - case IsTypeBoundsTree(x) => Some((x.lo, x.hi)) - case _ => None - } - } - - object WildcardTypeTree extends WildcardTypeTreeModule { - def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Boolean = x match { - case Trees.Ident(nme.WILDCARD) => x.tpe.isInstanceOf[Types.TypeBounds] - case _ => false - } - } + object TypeTree extends TypeTreeModule with TypeTreeCoreModule def typeTreeAsParent(typeTree: TypeTree): TermOrTypeTree = typeTree } diff --git a/library/src/scala/tasty/reflect/CaseDefOps.scala b/library/src/scala/tasty/reflect/CaseDefOps.scala index f7ea1dd4beb2..5b595f4e337e 100644 --- a/library/src/scala/tasty/reflect/CaseDefOps.scala +++ b/library/src/scala/tasty/reflect/CaseDefOps.scala @@ -10,28 +10,31 @@ trait CaseDefOps extends Core { def rhs(implicit ctx: Context): Term = kernel.CaseDef_rhs(caseDef) } - val CaseDef: CaseDefModule - abstract class CaseDefModule { + object CaseDef { + def apply(pattern: Pattern, guard: Option[Term], rhs: Term)(implicit ctx: Context): CaseDef = + kernel.CaseDef_module_apply(pattern, guard, rhs) - def apply(pattern: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef + def copy(original: CaseDef)(pattern: Pattern, guard: Option[Term], rhs: Term)(implicit ctx: Context): CaseDef = + kernel.CaseDef_module_copy(original)(pattern, guard, rhs) - def copy(original: CaseDef)(pattern: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef - - def unapply(x: CaseDef): Option[(Pattern, Option[Term], Term)] + def unapply(x: CaseDef)(implicit ctx: Context): Option[(Pattern, Option[Term], Term)] = + Some((x.pattern, x.guard, x.rhs)) } - implicit class TypeCaseDefAPI(caseDef: TypeCaseDef) { def pattern(implicit ctx: Context): TypeTree = kernel.TypeCaseDef_pattern(caseDef) def rhs(implicit ctx: Context): TypeTree = kernel.TypeCaseDef_rhs(caseDef) } - val TypeCaseDef: TypeCaseDefModule - abstract class TypeCaseDefModule { - def apply(pattern: TypeTree, body: TypeTree)(implicit ctx: Context): TypeCaseDef + object TypeCaseDef { + def apply(pattern: TypeTree, rhs: TypeTree)(implicit ctx: Context): TypeCaseDef = + kernel.TypeCaseDef_module_apply(pattern, rhs) - def copy(original: TypeCaseDef)(pattern: TypeTree, body: TypeTree)(implicit ctx: Context): TypeCaseDef + def copy(original: TypeCaseDef)(pattern: TypeTree, rhs: TypeTree)(implicit ctx: Context): TypeCaseDef = + kernel.TypeCaseDef_module_copy(original)(pattern, rhs) - def unapply(x: TypeCaseDef): Option[(TypeTree, TypeTree)] + def unapply(x: TypeCaseDef)(implicit ctx: Context): Option[(TypeTree, TypeTree)] = + Some((x.pattern, x.rhs)) } + } diff --git a/library/src/scala/tasty/reflect/ConstantOps.scala b/library/src/scala/tasty/reflect/ConstantOps.scala index a71118530e5b..7668a0326a70 100644 --- a/library/src/scala/tasty/reflect/ConstantOps.scala +++ b/library/src/scala/tasty/reflect/ConstantOps.scala @@ -8,138 +8,149 @@ trait ConstantOps extends Core { } /** Module of Constant literals */ - val Constant: ConstantModule - abstract class ConstantModule { + object Constant { /** Module of Null literals */ - val Unit: UnitModule - abstract class UnitModule { + object Unit { /** Unit `()` literal */ - def apply(): Constant + def apply(): Constant = + kernel.Constant_Unit_apply() /** Extractor for Unit literals */ - def unapply(constant: Constant): Boolean + def unapply(constant: Constant): Boolean = + kernel.isConstant_Unit(constant) } /** Module of Null literals */ - val Null: NullModule - abstract class NullModule { + object Null { /** `null` literal */ - def apply(): Constant + def apply(): Constant = + kernel.Constant_Null_apply() /** Extractor for Null literals */ - def unapply(constant: Constant): Boolean + def unapply(constant: Constant): Boolean = + kernel.isConstant_Null(constant) } /** Module of Boolean literals */ - val Boolean: BooleanModule - abstract class BooleanModule { + object Boolean { /** Boolean literal */ - def apply(x: Boolean): Constant + def apply(x: Boolean): Constant = + kernel.Constant_Boolean_apply(x) /** Extractor for Boolean literals */ - def unapply(constant: Constant): Option[Boolean] + def unapply(constant: Constant): Option[Boolean] = + kernel.isConstant_Boolean(constant) } /** Module of Byte literals */ - val Byte: ByteModule - abstract class ByteModule { + object Byte { /** Byte literal */ - def apply(x: Byte): Constant + def apply(x: Byte): Constant = + kernel.Constant_Byte_apply(x) /** Extractor for Byte literals */ - def unapply(constant: Constant): Option[Byte] + def unapply(constant: Constant): Option[Byte] = + kernel.isConstant_Byte(constant) } /** Module of Short literals */ - val Short: ShortModule - abstract class ShortModule { + object Short { /** Short literal */ - def apply(x: Short): Constant + def apply(x: Short): Constant = + kernel.Constant_Short_apply(x) /** Extractor for Short literals */ - def unapply(constant: Constant): Option[Short] + def unapply(constant: Constant): Option[Short] = + kernel.isConstant_Short(constant) } /** Module of Char literals */ - val Char: CharModule - abstract class CharModule { + object Char { /** Char literal */ - def apply(x: Char): Constant + def apply(x: Char): Constant = + kernel.Constant_Char_apply(x) /** Extractor for Char literals */ - def unapply(constant: Constant): Option[Char] + def unapply(constant: Constant): Option[Char] = + kernel.isConstant_Char(constant) } /** Module of Int literals */ - val Int: IntModule - abstract class IntModule { + object Int { /** Int literal */ - def apply(x: Int): Constant + def apply(x: Int): Constant = + kernel.Constant_Int_apply(x) /** Extractor for Int literals */ - def unapply(constant: Constant): Option[Int] + def unapply(constant: Constant): Option[Int] = + kernel.isConstant_Int(constant) } /** Module of Long literals */ - val Long: LongModule - abstract class LongModule { + object Long { /** Long literal */ - def apply(x: Long): Constant + def apply(x: Long): Constant = + kernel.Constant_Long_apply(x) /** Extractor for Long literals */ - def unapply(constant: Constant): Option[Long] + def unapply(constant: Constant): Option[Long] = + kernel.isConstant_Long(constant) } /** Module of Float literals */ - val Float: FloatModule - abstract class FloatModule { + object Float { /** Float literal */ - def apply(x: Float): Constant + def apply(x: Float): Constant = + kernel.Constant_Float_apply(x) /** Extractor for Float literals */ - def unapply(constant: Constant): Option[Float] + def unapply(constant: Constant): Option[Float] = + kernel.isConstant_Float(constant) } /** Module of Double literals */ - val Double: DoubleModule - abstract class DoubleModule { + object Double { /** Double literal */ - def apply(x: Double): Constant + def apply(x: Double): Constant = + kernel.Constant_Double_apply(x) /** Extractor for Double literals */ - def unapply(constant: Constant): Option[Double] + def unapply(constant: Constant): Option[Double] = + kernel.isConstant_Double(constant) } /** Module of String literals */ - val String: StringModule - abstract class StringModule { + object String { /** String literal */ - def apply(x: String): Constant + def apply(x: String): Constant = + kernel.Constant_String_apply(x) /** Extractor for String literals */ - def unapply(constant: Constant): Option[String] + def unapply(constant: Constant): Option[String] = + kernel.isConstant_String(constant) } /** Module of ClassTag literals */ - val ClassTag: ClassTagModule - abstract class ClassTagModule { + object ClassTag { /** scala.reflect.ClassTag literal */ - def apply[T](implicit x: scala.reflect.ClassTag[T]): Constant + def apply[T](implicit x: scala.reflect.ClassTag[T]): Constant = + kernel.Constant_ClassTag_apply(x) /** Extractor for ClassTag literals */ - def unapply(constant: Constant): Option[Type] + def unapply(constant: Constant): Option[Type] = + kernel.isConstant_ClassTag(constant) } /** Module of scala.Symbol literals */ - val Symbol: SymbolModule - /** Extractor for scala.Symbol literals */ - abstract class SymbolModule { + object Symbol { /** scala.Symbol literal */ - def apply(x: scala.Symbol): Constant + def apply(x: scala.Symbol): Constant = + kernel.Constant_Symbol_apply(x) /** Extractor for scala.Symbol literals */ - def unapply(constant: Constant): Option[scala.Symbol] + def unapply(constant: Constant): Option[scala.Symbol] = + kernel.isConstant_Symbol(constant) } } } diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index a1f7541dda31..49b2b0d0f408 100644 --- a/library/src/scala/tasty/reflect/Core.scala +++ b/library/src/scala/tasty/reflect/Core.scala @@ -321,7 +321,7 @@ trait Core { * The wildcard type `_` (for example in in `List[_]`) will be a type tree that * represents a type but has `TypeBound`a inside. */ - type WildcardType = kernel.WildcardType + type WildcardTypeTree = kernel.WildcardTypeTree /** Type or bounds */ type TypeOrBounds = kernel.TypeOrBounds @@ -404,6 +404,9 @@ trait Core { * * OmitSelector: `.{bar => _}` in `import foo.{bar => _}` */ type ImportSelector = kernel.ImportSelector + type SimpleSelector = kernel.SimpleSelector + type RenameSelector = kernel.RenameSelector + type OmitSelector = kernel.OmitSelector /** Untyped identifier */ type Id = kernel.Id diff --git a/library/src/scala/tasty/reflect/IdOps.scala b/library/src/scala/tasty/reflect/IdOps.scala index efbc6e7c0502..b7f79340840d 100644 --- a/library/src/scala/tasty/reflect/IdOps.scala +++ b/library/src/scala/tasty/reflect/IdOps.scala @@ -13,9 +13,8 @@ trait IdOps extends Core { } - val Id: IdModule - abstract class IdModule { - def unapply(id: Id): Option[String] + object Id { + def unapply(id: Id)(implicit ctx: Context): Option[String] = Some(id.name) } } diff --git a/library/src/scala/tasty/reflect/ImportSelectorOps.scala b/library/src/scala/tasty/reflect/ImportSelectorOps.scala index 898cdb54fd6c..8007afc838fa 100644 --- a/library/src/scala/tasty/reflect/ImportSelectorOps.scala +++ b/library/src/scala/tasty/reflect/ImportSelectorOps.scala @@ -3,19 +3,37 @@ package reflect trait ImportSelectorOps extends Core { - val SimpleSelector: SimpleSelectorModule - abstract class SimpleSelectorModule { - def unapply(importSelector: ImportSelector)(implicit ctx: Context): Option[Id] + implicit class SimpleSelectorAPI(self: SimpleSelector) { + def selection(implicit ctx: Context): Id = + kernel.SimpleSelector_selection(self) } - val RenameSelector: RenameSelectorModule - abstract class RenameSelectorModule { - def unapply(importSelector: ImportSelector)(implicit ctx: Context): Option[(Id, Id)] + object SimpleSelector { + def unapply(importSelector: ImportSelector)(implicit ctx: Context): Option[Id] = + kernel.isSimpleSelector(importSelector).map(_.selection) } - val OmitSelector: OmitSelectorModule - abstract class OmitSelectorModule { - def unapply(importSelector: ImportSelector)(implicit ctx: Context): Option[Id] + implicit class RenameSelectorAPI(self: RenameSelector) { + def from(implicit ctx: Context): Id = + kernel.RenameSelector_from(self) + + def to(implicit ctx: Context): Id = + kernel.RenameSelector_to(self) + } + + object RenameSelector { + def unapply(importSelector: ImportSelector)(implicit ctx: Context): Option[(Id, Id)] = + kernel.isRenameSelector(importSelector).map(x => (x.from, x.to)) + } + + implicit class OmitSelectorAPI(self: OmitSelector) { + def omitted(implicit ctx: Context): Id = + kernel.SimpleSelector_omited(self) + } + + object OmitSelector { + def unapply(importSelector: ImportSelector)(implicit ctx: Context): Option[Id] = + kernel.isOmitSelector(importSelector).map(_.omitted) } } diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index dd1d32582f72..96f93e32cf90 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -123,6 +123,8 @@ trait Kernel { /** Root position of this tasty context. For macros it corresponds to the expansion site. */ def rootPosition: Position + def settings: Settings + // // CONTEXT // @@ -143,6 +145,8 @@ trait Kernel { /** Settings */ type Settings <: AnyRef + def Settings_color(self: Settings): Boolean + // // TREES // @@ -160,27 +164,45 @@ trait Kernel { /** Tree representing a pacakage clause in the source code */ type PackageClause <: Tree + def isPackageClause(tree: Tree)(implicit ctx: Context): Option[PackageClause] + def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Term_Ref def PackageClause_stats(self: PackageClause)(implicit ctx: Context): List[Tree] + def PackageClause_apply(pid: Term_Ref, stats: List[Tree])(implicit ctx: Context): PackageClause + + def PackageClause_copy(original: PackageClause)(pid: Term_Ref, stats: List[Tree])(implicit ctx: Context): PackageClause + /** Tree representing a statement in the source code */ type Statement <: Tree + def isStatement(tree: Tree)(implicit ctx: Context): Option[Statement] + /** Tree representing an import in the source code */ type Import <: Statement + def isImport(tree: Tree)(implicit ctx: Context): Option[Import] + def Import_impliedOnly(self: Import): Boolean def Import_expr(self: Import)(implicit ctx: Context): Term def Import_selectors(self: Import)(implicit ctx: Context): List[ImportSelector] + def Import_apply(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import + + def Import_copy(original: Import)(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import + /** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef` */ type Definition <: Statement + def isDefinition(tree: Tree)(implicit ctx: Context): Option[Definition] + def Definition_name(self: Definition)(implicit ctx: Context): String /** Tree representing a package definition. This includes definitions in all source files */ type PackageDef <: Definition + def isPackageDef(tree: Tree)(implicit ctx: Context): Option[PackageDef] + def PackageDef_owner(self: PackageDef)(implicit ctx: Context): PackageDef def PackageDef_members(self: PackageDef)(implicit ctx: Context): List[Statement] def PackageDef_symbol(self: PackageDef)(implicit ctx: Context): PackageSymbol @@ -188,6 +210,8 @@ trait Kernel { /** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */ type ClassDef <: Definition + def isClassDef(tree: Tree)(implicit ctx: Context): Option[ClassDef] + def ClassDef_constructor(self: ClassDef)(implicit ctx: Context): DefDef def ClassDef_parents(self: ClassDef)(implicit ctx: Context): List[TermOrTypeTree] def ClassDef_derived(self: ClassDef)(implicit ctx: Context): List[TypeTree] @@ -195,31 +219,52 @@ trait Kernel { def ClassDef_body(self: ClassDef)(implicit ctx: Context): List[Statement] def ClassDef_symbol(self: ClassDef)(implicit ctx: Context): ClassSymbol + def ClassDef_copy(original: ClassDef)(name: String, constr: DefDef, parents: List[TermOrTypeTree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement])(implicit ctx: Context): ClassDef + /** Tree representing a type (paramter or member) definition in the source code */ type TypeDef <: Definition + def isTypeDef(tree: Tree)(implicit ctx: Context): Option[TypeDef] + def TypeDef_rhs(self: TypeDef)(implicit ctx: Context): TypeOrBoundsTree def TypeDef_symbol(self: TypeDef)(implicit ctx: Context): TypeSymbol + def TypeDef_apply(symbol: TypeSymbol)(implicit ctx: Context): TypeDef + def TypeDef_copy(original: TypeDef)(name: String, rhs: TypeOrBoundsTree)(implicit ctx: Context): TypeDef + /** Tree representing a method definition in the source code */ type DefDef <: Definition + def isDefDef(tree: Tree)(implicit ctx: Context): Option[DefDef] + def DefDef_typeParams(self: DefDef)(implicit ctx: Context): List[TypeDef] def DefDef_paramss(self: DefDef)(implicit ctx: Context): List[List[ValDef]] def DefDef_returnTpt(self: DefDef)(implicit ctx: Context): TypeTree def DefDef_rhs(self: DefDef)(implicit ctx: Context): Option[Term] def DefDef_symbol(self: DefDef)(implicit ctx: Context): DefSymbol + def DefDef_apply(symbol: DefSymbol, 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. */ type ValDef <: Definition + def isValDef(tree: Tree)(implicit ctx: Context): Option[ValDef] + def ValDef_tpt(self: ValDef)(implicit ctx: Context): TypeTree def ValDef_rhs(self: ValDef)(implicit ctx: Context): Option[Term] def ValDef_symbol(self: ValDef)(implicit ctx: Context): ValSymbol + def ValDef_apply(symbol: ValSymbol, rhs: Option[Term])(implicit ctx: Context): ValDef + def ValDef_copy(original: ValDef)(name: String, tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): ValDef + /** Tree representing an expression in the source code */ type Term <: Statement + def isTerm(tree: Tree)(implicit ctx: Context): Option[Term] + + def isTermNotTypeTree(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[Term] + def Term_pos(self: Term)(implicit ctx: Context): Position def Term_tpe(self: Term)(implicit ctx: Context): Type def Term_underlyingArgument(self: Term)(implicit ctx: Context): Term @@ -228,132 +273,241 @@ trait Kernel { /** Tree representing a reference to definition */ type Term_Ref <: Term + def Term_Ref_apply(sym: Symbol)(implicit ctx: Context): Term_Ref + /** Tree representing a reference to definition with a given name */ type Term_Ident <: Term_Ref + def isTerm_Ident(tree: Tree)(implicit ctx: Context): Option[Term_Ident] + def Term_Ident_name(self: Term_Ident)(implicit ctx: Context): String + def Term_Ident_apply(tmref: TermRef)(implicit ctx: Context): Term + def Term_Ident_copy(original: Tree)(name: String)(implicit ctx: Context): Term_Ident + /** Tree representing a selection of definition with a given name on a given prefix */ type Term_Select <: Term_Ref + def isTerm_Select(tree: Tree)(implicit ctx: Context): Option[Term_Select] + def Term_Select_qualifier(self: Term_Select)(implicit ctx: Context): Term def Term_Select_name(self: Term_Select)(implicit ctx: Context): String def Term_Select_signature(self: Term_Select)(implicit ctx: Context): Option[Signature] + def Term_Select_unique(qualifier: Term, name: String)(implicit ctx: Context): Term_Select + // TODO rename, this returns an Apply and not a Select + def Term_Select_overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Term_Apply + def Term_Select_copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Term_Select + /** Tree representing a literal value in the source code */ type Term_Literal <: Term + def isTerm_Literal(tree: Tree)(implicit ctx: Context): Option[Term_Literal] + def Term_Literal_constant(self: Term_Literal)(implicit ctx: Context): Constant + def Term_Literal_apply(constant: Constant)(implicit ctx: Context): Term_Literal + def Term_Literal_copy(original: Tree)(constant: Constant)(implicit ctx: Context): Term_Literal + /** Tree representing `this` in the source code */ type Term_This <: Term + def isTerm_This(tree: Tree)(implicit ctx: Context): Option[Term_This] + def Term_This_id(self: Term_This)(implicit ctx: Context): Option[Id] + def Term_This_apply(cls: ClassSymbol)(implicit ctx: Context): Term_This + def Term_This_copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): Term_This + /** Tree representing `new` in the source code */ type Term_New <: Term + def isTerm_New(tree: Tree)(implicit ctx: Context): Option[Term_New] + def Term_New_tpt(self: Term_New)(implicit ctx: Context): TypeTree + def Term_New_apply(tpt: TypeTree)(implicit ctx: Context): Term_New + def Term_New_copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): Term_New + /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ type Term_NamedArg <: Term + def isTerm_NamedArg(tree: Tree)(implicit ctx: Context): Option[Term_NamedArg] + def Term_NamedArg_name(self: Term_NamedArg)(implicit ctx: Context): String def Term_NamedArg_value(self: Term_NamedArg)(implicit ctx: Context): Term + def Term_NamedArg_apply(name: String, arg: Term)(implicit ctx: Context): Term_NamedArg + def Term_NamedArg_copy(tree: Term_NamedArg)(name: String, arg: Term)(implicit ctx: Context): Term_NamedArg + /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ type Term_Apply <: Term + def isTerm_Apply(tree: Tree)(implicit ctx: Context): Option[Term_Apply] + def Term_Apply_fun(self: Term_Apply)(implicit ctx: Context): Term def Term_Apply_args(self: Term_Apply)(implicit ctx: Context): List[Term] + def Term_Apply_apply(fn: Term, args: List[Term])(implicit ctx: Context): Term_Apply + def Term_Apply_copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Term_Apply + /** Tree an application of type arguments */ type Term_TypeApply <: Term + def isTerm_TypeApply(tree: Tree)(implicit ctx: Context): Option[Term_TypeApply] + def Term_TypeApply_fun(self: Term_TypeApply)(implicit ctx: Context): Term def Term_TypeApply_args(self: Term_TypeApply)(implicit ctx: Context): List[TypeTree] + def Term_TypeApply_apply(fn: Term, args: List[TypeTree])(implicit ctx: Context): Term_TypeApply + def Term_TypeApply_copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): Term_TypeApply + /** Tree representing `super` in the source code */ type Term_Super <: Term + def isTerm_Super(tree: Tree)(implicit ctx: Context): Option[Term_Super] + def Term_Super_qualifier(self: Term_Super)(implicit ctx: Context): Term def Term_Super_id(self: Term_Super)(implicit ctx: Context): Option[Id] + def Term_Super_apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Term_Super + def Term_Super_copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Term_Super + /** Tree representing a type ascription `x: T` in the source code */ type Term_Typed <: Term + def isTerm_Typed(tree: Tree)(implicit ctx: Context): Option[Term_Typed] + def Term_Typed_expr(self: Term_Typed)(implicit ctx: Context): Term def Term_Typed_tpt(self: Term_Typed)(implicit ctx: Context): TypeTree + def Term_Typed_apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Term_Typed + def Term_Typed_copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Term_Typed + /** Tree representing an assignment `x = y` in the source code */ type Term_Assign <: Term + def isTerm_Assign(tree: Tree)(implicit ctx: Context): Option[Term_Assign] + def Term_Assign_lhs(self: Term_Assign)(implicit ctx: Context): Term def Term_Assign_rhs(self: Term_Assign)(implicit ctx: Context): Term + def Term_Assign_apply(lhs: Term, rhs: Term)(implicit ctx: Context): Term_Assign + def Term_Assign_copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Term_Assign + /** Tree representing a block `{ ... }` in the source code */ type Term_Block <: Term + def isTerm_Block(tree: Tree)(implicit ctx: Context): Option[Term_Block] + def Term_Block_statements(self: Term_Block)(implicit ctx: Context): List[Statement] def Term_Block_expr(self: Term_Block)(implicit ctx: Context): Term + def Term_Block_apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Term_Block + def Term_Block_copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Term_Block + /** Tree representing a lambda `(...) => ...` in the source code */ type Term_Lambda <: Term + def isTerm_Lambda(tree: Tree)(implicit ctx: Context): Option[Term_Lambda] + def Term_Lambda_meth(self: Term_Lambda)(implicit ctx: Context): Term def Term_Lambda_tptOpt(self: Term_Lambda)(implicit ctx: Context): Option[TypeTree] + def Term_Lambda_apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Term_Lambda + def Term_Lambda_copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Term_Lambda + /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ type Term_If <: Term + def isTerm_If(tree: Tree)(implicit ctx: Context): Option[Term_If] + def Term_If_cond(self: Term_If)(implicit ctx: Context): Term def Term_If_thenp(self: Term_If)(implicit ctx: Context): Term def Term_If_elsep(self: Term_If)(implicit ctx: Context): Term + def Term_If_apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): Term_If + def Term_If_copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): Term_If + /** Tree representing a pattern match `x match { ... }` in the source code */ type Term_Match <: Term + def isTerm_Match(tree: Tree)(implicit ctx: Context): Option[Term_Match] + def Term_Match_scrutinee(self: Term_Match)(implicit ctx: Context): Term def Term_Match_cases(self: Term_Match)(implicit ctx: Context): List[CaseDef] + def Term_Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Term_Match + def Term_Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Term_Match + /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ type Term_Try <: Term + def isTerm_Try(tree: Tree)(implicit ctx: Context): Option[Term_Try] + def Term_Try_body(self: Term_Try)(implicit ctx: Context): Term def Term_Try_cases(self: Term_Try)(implicit ctx: Context): List[CaseDef] def Term_Try_finalizer(self: Term_Try)(implicit ctx: Context): Option[Term] + def Term_Try_apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Term_Try + def Term_Try_copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Term_Try + /** Tree representing a `return` in the source code */ type Term_Return <: Term + def isTerm_Return(tree: Tree)(implicit ctx: Context): Option[Term_Return] + def Term_Return_expr(self: Term_Return)(implicit ctx: Context): Term + def Term_Return_apply(expr: Term)(implicit ctx: Context): Term_Return + def Term_Return_copy(original: Tree)(expr: Term)(implicit ctx: Context): Term_Return + /** Tree representing a variable argument list in the source code */ type Term_Repeated <: Term + def isTerm_Repeated(tree: Tree)(implicit ctx: Context): Option[Term_Repeated] + def Term_Repeated_elems(self: Term_Repeated)(implicit ctx: Context): List[Term] def Term_Repeated_elemtpt(self: Term_Repeated)(implicit ctx: Context): TypeTree + def Term_Repeated_apply(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Term_Repeated + def Term_Repeated_copy(original: Tree)(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Term_Repeated + /** Tree representing the scope of an inlined tree */ type Term_Inlined <: Term + def isTerm_Inlined(tree: Tree)(implicit ctx: Context): Option[Term_Inlined] + def Term_Inlined_call(self: Term_Inlined)(implicit ctx: Context): Option[TermOrTypeTree] def Term_Inlined_bindings(self: Term_Inlined)(implicit ctx: Context): List[Definition] def Term_Inlined_body(self: Term_Inlined)(implicit ctx: Context): Term + def Term_Inlined_apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Term_Inlined + def Term_Inlined_copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Term_Inlined + /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ type Term_SelectOuter <: Term + def isTerm_SelectOuter(tree: Tree)(implicit ctx: Context): Option[Term_SelectOuter] + def Term_SelectOuter_qualifier(self: Term_SelectOuter)(implicit ctx: Context): Term def Term_SelectOuter_level(self: Term_SelectOuter)(implicit ctx: Context): Int def Term_SelectOuter_tpe(self: Term_SelectOuter)(implicit ctx: Context): Type + def Term_SelectOuter_apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): Term_SelectOuter + def Term_SelectOuter_copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): Term_SelectOuter + /** Tree representing a while loop */ type Term_While <: Term + def isTerm_While(tree: Tree)(implicit ctx: Context): Option[Term_While] + def Term_While_cond(self: Term_While)(implicit ctx: Context): Term def Term_While_body(self: Term_While)(implicit ctx: Context): Term + def Term_While_apply(cond: Term, body: Term)(implicit ctx: Context): Term_While + def Term_While_copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): Term_While + // // CASES // @@ -365,12 +519,18 @@ trait Kernel { def CaseDef_guard(self: CaseDef)(implicit ctx: Context): Option[Term] def CaseDef_rhs(self: CaseDef)(implicit ctx: Context): Term + def CaseDef_module_apply(pattern: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef + def CaseDef_module_copy(original: CaseDef)(pattern: Pattern, guard: Option[Term], body: Term)(implicit ctx: Context): CaseDef + /** Branch of a type pattern match */ type TypeCaseDef <: AnyRef def TypeCaseDef_pattern(self: TypeCaseDef)(implicit ctx: Context): TypeTree def TypeCaseDef_rhs(self: TypeCaseDef)(implicit ctx: Context): TypeTree + def TypeCaseDef_module_apply(pattern: TypeTree, body: TypeTree)(implicit ctx: Context): TypeCaseDef + def TypeCaseDef_module_copy(original: TypeCaseDef)(pattern: TypeTree, body: TypeTree)(implicit ctx: Context): TypeCaseDef + // // PATTERNS // @@ -385,34 +545,57 @@ trait Kernel { /** Pattern representing a value. This includes `1`, ```x``` and `_` */ type Value <: Pattern + def isPattern_Value(pattern: Pattern): Option[Value] + def Pattern_Value_value(self: Value)(implicit ctx: Context): Term + def Pattern_Value_module_apply(term: Term)(implicit ctx: Context): Value + def Pattern_Value_module_copy(original: Value)(term: Term)(implicit ctx: Context): Value + /** Pattern representing a `_ @ _` binding. */ type Bind <: Pattern + def isPattern_Bind(x: Pattern)(implicit ctx: Context): Option[Bind] + def Pattern_Bind_name(self: Bind)(implicit ctx: Context): String def Pattern_Bind_pattern(self: Bind)(implicit ctx: Context): Pattern + def Pattern_Bind_module_copy(original: Bind)(name: String, pattern: Pattern)(implicit ctx: Context): Bind + /** Pattern representing a `Xyz(...)` unapply. */ type Unapply <: Pattern + def isPattern_Unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] + def Pattern_Unapply_fun(self: Unapply)(implicit ctx: Context): Term def Pattern_Unapply_implicits(self: Unapply)(implicit ctx: Context): List[Term] def Pattern_Unapply_patterns(self: Unapply)(implicit ctx: Context): List[Pattern] + def Pattern_Unapply_module_copy(original: Unapply)(fun: Term, implicits: List[Term], patterns: List[Pattern])(implicit ctx: Context): Unapply + /** Pattern representing `X | Y | ...` alternatives. */ type Alternatives <: Pattern + def isPattern_Alternatives(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] + def Pattern_Alternatives_patterns(self: Alternatives)(implicit ctx: Context): List[Pattern] + def Pattern_Alternatives_module_apply(patterns: List[Pattern])(implicit ctx: Context): Alternatives + def Pattern_Alternatives_module_copy(original: Alternatives)(patterns: List[Pattern])(implicit ctx: Context): Alternatives + /** Pattern representing a `x: Y` type test. */ type TypeTest <: Pattern + def isPattern_TypeTest(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] + def Pattern_TypeTest_tpt(self: TypeTest)(implicit ctx: Context): TypeTree + def Pattern_TypeTest_module_apply(tpt: TypeTree)(implicit ctx: Context): TypeTest + def Pattern_TypeTest_module_copy(original: TypeTest)(tpt: TypeTree)(implicit ctx: Context): TypeTest + // // TYPE TREES // @@ -425,6 +608,9 @@ trait Kernel { /** Type tree representing a type written in the source */ type TypeTree <: TypeOrBoundsTree + def isTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] + def isTypeTreeNotTerm(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[TypeTree] + def TypeTree_pos(self: TypeTree)(implicit ctx: Context): Position def TypeTree_symbol(self: TypeTree)(implicit ctx: Context): Symbol def TypeTree_tpe(self: TypeTree)(implicit ctx: Context): Type @@ -432,79 +618,141 @@ trait Kernel { /** Type tree representing an inferred type */ type TypeTree_Inferred <: TypeTree + def isTypeTree_Inferred(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Inferred] + + def TypeTree_Inferred_apply(tpe: Type)(implicit ctx: Context): TypeTree_Inferred + /** Type tree representing a reference to definition with a given name */ type TypeTree_Ident <: TypeTree + def isTypeTree_Ident(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Ident] + def TypeTree_Ident_name(self: TypeTree_Ident)(implicit ctx: Context): String + def TypeTree_Ident_copy(original: TypeTree_Ident)(name: String)(implicit ctx: Context): TypeTree_Ident + /** Type tree representing a selection of definition with a given name on a given term prefix */ type TypeTree_Select <: TypeTree + def isTypeTree_Select(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Select] + def TypeTree_Select_qualifier(self: TypeTree_Select)(implicit ctx: Context): Term def TypeTree_Select_name(self: TypeTree_Select)(implicit ctx: Context): String + def TypeTree_Select_apply(qualifier: Term, name: String)(implicit ctx: Context): TypeTree_Select + def TypeTree_Select_copy(original: TypeTree_Select)(qualifier: Term, name: String)(implicit ctx: Context): TypeTree_Select + /** Type tree representing a selection of definition with a given name on a given type prefix */ type TypeTree_Projection <: TypeTree + def isTypeTree_Projection(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Projection] + def TypeTree_Projection_qualifier(self: TypeTree_Projection)(implicit ctx: Context): TypeTree def TypeTree_Projection_name(self: TypeTree_Projection)(implicit ctx: Context): String + def TypeTree_Projection_copy(original: TypeTree_Projection)(qualifier: TypeTree, name: String)(implicit ctx: Context): TypeTree_Projection + /** Type tree representing a singleton type */ type TypeTree_Singleton <: TypeTree + def isTypeTree_Singleton(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Singleton] + def TypeTree_Singleton_ref(self: TypeTree_Singleton)(implicit ctx: Context): Term + def TypeTree_Singleton_apply(ref: Term)(implicit ctx: Context): TypeTree_Singleton + def TypeTree_Singleton_copy(original: TypeTree_Singleton)(ref: Term)(implicit ctx: Context): TypeTree_Singleton + /** Type tree representing a type refinement */ type TypeTree_Refined <: TypeTree + def isTypeTree_Refined(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Refined] + def TypeTree_Refined_tpt(self: TypeTree_Refined)(implicit ctx: Context): TypeTree def TypeTree_Refined_refinements(self: TypeTree_Refined)(implicit ctx: Context): List[Definition] + def TypeTree_Refined_copy(original: TypeTree_Refined)(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): TypeTree_Refined + /** Type tree representing a type application */ type TypeTree_Applied <: TypeTree + def isTypeTree_Applied(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Applied] + def TypeTree_Applied_tpt(self: TypeTree_Applied)(implicit ctx: Context): TypeTree def TypeTree_Applied_args(self: TypeTree_Applied)(implicit ctx: Context): List[TypeOrBoundsTree] + def TypeTree_Applied_apply(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): TypeTree_Applied + def TypeTree_Applied_copy(original: TypeTree_Applied)(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): TypeTree_Applied + /** Type tree representing an annotated type */ type TypeTree_Annotated <: TypeTree + def isTypeTree_Annotated(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Annotated] + def TypeTree_Annotated_arg(self: TypeTree_Annotated)(implicit ctx: Context): TypeTree def TypeTree_Annotated_annotation(self: TypeTree_Annotated)(implicit ctx: Context): Term + def TypeTree_Annotated_apply(arg: TypeTree, annotation: Term)(implicit ctx: Context): TypeTree_Annotated + def TypeTree_Annotated_copy(original: TypeTree_Annotated)(arg: TypeTree, annotation: Term)(implicit ctx: Context): TypeTree_Annotated + /** Type tree representing a type match */ type TypeTree_MatchType <: TypeTree + def isTypeTree_MatchType(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_MatchType] + def TypeTree_MatchType_bound(self: TypeTree_MatchType)(implicit ctx: Context): Option[TypeTree] def TypeTree_MatchType_selector(self: TypeTree_MatchType)(implicit ctx: Context): TypeTree def TypeTree_MatchType_cases(self: TypeTree_MatchType)(implicit ctx: Context): List[TypeCaseDef] + def TypeTree_MatchType_apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): TypeTree_MatchType + def TypeTree_MatchType_copy(original: TypeTree_MatchType)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): TypeTree_MatchType + /** Type tree representing a by name parameter */ type TypeTree_ByName <: TypeTree def TypeTree_ByName_result(self: TypeTree_ByName)(implicit ctx: Context): TypeTree + def isTypeTree_ByName(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_ByName] + + def TypeTree_ByName_apply(result: TypeTree)(implicit ctx: Context): TypeTree_ByName + def TypeTree_ByName_copy(original: TypeTree_ByName)(result: TypeTree)(implicit ctx: Context): TypeTree_ByName + /** Type tree representing a lambda abstraction type */ type TypeTree_LambdaTypeTree <: TypeTree + def isTypeTree_LambdaTypeTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_LambdaTypeTree] + def TypeTree_LambdaTypeTree_tparams(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): List[TypeDef] def TypeTree_LambdaTypeTree_body(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): TypeOrBoundsTree + def TypeTree_LambdaTypeTree_apply(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): TypeTree_LambdaTypeTree + def TypeTree_LambdaTypeTree_copy(original: TypeTree_LambdaTypeTree)(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): TypeTree_LambdaTypeTree + /** Type tree representing a type binding */ type TypeTree_TypeBind <: TypeTree + def isTypeTree_TypeBind(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBind] + def TypeTree_TypeBind_name(self: TypeTree_TypeBind)(implicit ctx: Context): String def TypeTree_TypeBind_body(self: TypeTree_TypeBind)(implicit ctx: Context): TypeOrBoundsTree + def TypeTree_TypeBind_copy(original: TypeTree_TypeBind)(name: String, tpt: TypeOrBoundsTree)(implicit ctx: Context): TypeTree_TypeBind + /** Type tree within a block with aliases `{ type U1 = ... ; T[U1, U2] }` */ type TypeTree_TypeBlock <: TypeTree + def isTypeTree_TypeBlock(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBlock] + def TypeTree_TypeBlock_aliases(self: TypeTree_TypeBlock)(implicit ctx: Context): List[TypeDef] def TypeTree_TypeBlock_tpt(self: TypeTree_TypeBlock)(implicit ctx: Context): TypeTree + def TypeTree_TypeBlock_apply(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeTree_TypeBlock + def TypeTree_TypeBlock_copy(original: TypeTree_TypeBlock)(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeTree_TypeBlock + /** Type tree representing a type bound written in the source */ type TypeBoundsTree <: TypeOrBoundsTree + def isTypeBoundsTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] + def TypeBoundsTree_tpe(self: TypeBoundsTree)(implicit ctx: Context): TypeBounds def TypeBoundsTree_low(self: TypeBoundsTree)(implicit ctx: Context): TypeTree def TypeBoundsTree_hi(self: TypeBoundsTree)(implicit ctx: Context): TypeTree @@ -513,7 +761,9 @@ trait Kernel { * The wildcard type `_` (for example in in `List[_]`) will be a type tree that * represents a type but has `TypeBound`a inside. */ - type WildcardType <: TypeOrBoundsTree + type WildcardTypeTree <: TypeOrBoundsTree + + def isWildcardTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] // // TYPES @@ -686,6 +936,25 @@ trait Kernel { */ type ImportSelector <: AnyRef + type SimpleSelector <: ImportSelector + + def isSimpleSelector(self: ImportSelector)(implicit ctx: Context): Option[SimpleSelector] + + def SimpleSelector_selection(self: SimpleSelector)(implicit ctx: Context): Id + + type RenameSelector <: ImportSelector + + def isRenameSelector(self: ImportSelector)(implicit ctx: Context): Option[RenameSelector] + + def RenameSelector_from(self: RenameSelector)(implicit ctx: Context): Id + def RenameSelector_to(self: RenameSelector)(implicit ctx: Context): Id + + type OmitSelector <: ImportSelector + + def isOmitSelector(self: ImportSelector)(implicit ctx: Context): Option[OmitSelector] + + def SimpleSelector_omited(self: OmitSelector)(implicit ctx: Context): Id + // // IDENTIFIERS // @@ -762,6 +1031,34 @@ trait Kernel { def Constant_value(const: Constant): Any + def isConstant_Unit(constant: Constant): Boolean + def isConstant_Null(constant: Constant): Boolean + def isConstant_Boolean(constant: Constant): Option[Boolean] + def isConstant_Byte(constant: Constant): Option[Byte] + def isConstant_Short(constant: Constant): Option[Short] + def isConstant_Char(constant: Constant): Option[Char] + def isConstant_Int(constant: Constant): Option[Int] + def isConstant_Long(constant: Constant): Option[Long] + def isConstant_Float(constant: Constant): Option[Float] + def isConstant_Double(constant: Constant): Option[Double] + def isConstant_String(constant: Constant): Option[String] + def isConstant_ClassTag(constant: Constant): Option[Type] + def isConstant_Symbol(constant: Constant): Option[scala.Symbol] + + def Constant_Unit_apply(): Constant + def Constant_Null_apply(): Constant + def Constant_Boolean_apply(x: Boolean): Constant + def Constant_Byte_apply(x: Byte): Constant + def Constant_Short_apply(x: Short): Constant + def Constant_Char_apply(x: Char): Constant + def Constant_Int_apply(x: Int): Constant + def Constant_Long_apply(x: Long): Constant + def Constant_Float_apply(x: Float): Constant + def Constant_Double_apply(x: Double): Constant + def Constant_String_apply(x: String): Constant + def Constant_ClassTag_apply(x: scala.reflect.ClassTag[_]): Constant + def Constant_Symbol_apply(x: scala.Symbol): Constant + // // SYMBOLS // @@ -819,24 +1116,38 @@ trait Kernel { /** Symbol of a package definition */ type PackageSymbol <: Symbol + def isPackageSymbol(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] + /** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */ type ClassSymbol <: Symbol + def isClassSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] + /** Symbol of a type (parameter or member) definition. */ type TypeSymbol <: Symbol + def isTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] + /** Symbol representing a method definition. */ type DefSymbol <: Symbol + def isDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] + /** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */ type ValSymbol <: Symbol + def isValSymbol(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] + /** Symbol representing a bind definition. */ type BindSymbol <: Symbol + def isBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] + /** No symbol available. */ type NoSymbol <: Symbol + def isNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean + // // FLAGS // @@ -905,4 +1216,74 @@ trait Kernel { /** Convert `Type` to an `quoted.Type[T]` */ def QuotedType_seal(self: Type)(implicit ctx: Context): scala.quoted.Type[_] + // + // DEFINITIONS + // + + def Definitions_RootPackage: Symbol + def Definitions_RootClass: Symbol + + def Definitions_EmptyPackageClass: Symbol + + def Definitions_ScalaPackage: Symbol + def Definitions_ScalaPackageClass: Symbol + + def Definitions_AnyClass: Symbol + def Definitions_AnyValClass: Symbol + def Definitions_ObjectClass: Symbol + def Definitions_AnyRefClass: Symbol + def Definitions_NullClass: Symbol + def Definitions_NothingClass: Symbol + def Definitions_UnitClass: Symbol + def Definitions_ByteClass: Symbol + def Definitions_ShortClass: Symbol + def Definitions_CharClass: Symbol + def Definitions_IntClass: Symbol + def Definitions_LongClass: Symbol + def Definitions_FloatClass: Symbol + def Definitions_DoubleClass: Symbol + def Definitions_BooleanClass: Symbol + def Definitions_StringClass: Symbol + def Definitions_ClassClass: Symbol + def Definitions_ArrayClass: Symbol + def Definitions_PredefModule: Symbol + + def Definitions_JavaLangPackage: Symbol + + def Definitions_ArrayModule: Symbol + + def Definitions_Array_apply: Symbol + def Definitions_Array_clone: Symbol + def Definitions_Array_length: Symbol + def Definitions_Array_update: Symbol + + def Definitions_RepeatedParamClass: Symbol + + def Definitions_OptionClass: Symbol + def Definitions_NoneModule: Symbol + def Definitions_SomeModule: Symbol + + def Definitions_ProductClass: Symbol + // TODO avoid default parameters + def Definitions_FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol + + def Definitions_TupleClass(arity: Int): Symbol + + def Definitions_UnitType: Type + def Definitions_ByteType: Type + def Definitions_ShortType: Type + def Definitions_CharType: Type + def Definitions_IntType: Type + def Definitions_LongType: Type + def Definitions_FloatType: Type + def Definitions_DoubleType: Type + def Definitions_BooleanType: Type + def Definitions_AnyType: Type + def Definitions_AnyValType: Type + def Definitions_AnyRefType: Type + def Definitions_ObjectType: Type + def Definitions_NothingType: Type + def Definitions_NullType: Type + def Definitions_StringType: Type + } diff --git a/library/src/scala/tasty/reflect/PatternOps.scala b/library/src/scala/tasty/reflect/PatternOps.scala index f1e317eae0cb..97e9cced26af 100644 --- a/library/src/scala/tasty/reflect/PatternOps.scala +++ b/library/src/scala/tasty/reflect/PatternOps.scala @@ -35,67 +35,74 @@ trait PatternOps extends Core { def symbol(implicit ctx: Context): Symbol = kernel.Pattern_symbol(self) } - val Pattern: PatternModule - abstract class PatternModule { + object Pattern { - val IsValue: IsValueModule - abstract class IsValueModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Value] + object IsValue { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[Value] = + kernel.isPattern_Value(pattern) } - val Value: ValueModule - abstract class ValueModule { - def apply(tpt: Term)(implicit ctx: Context): Value - def copy(original: Value)(tpt: Term)(implicit ctx: Context): Value - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Term] + object Value { + def apply(tpt: Term)(implicit ctx: Context): Value = + kernel.Pattern_Value_module_apply(tpt) + def copy(original: Value)(tpt: Term)(implicit ctx: Context): Value = + kernel.Pattern_Value_module_copy(original)(tpt) + def unapply(pattern: Pattern)(implicit ctx: Context): Option[Term] = + kernel.isPattern_Value(pattern).map(_.value) } - val IsBind: IsBindModule - abstract class IsBindModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Bind] + object IsBind { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[Bind] = + kernel.isPattern_Bind(pattern) } - val Bind: BindModule - abstract class BindModule { + object Bind { // TODO def apply(name: String, pattern: Pattern)(implicit ctx: Context): Bind - def copy(original: Bind)(name: String, pattern: Pattern)(implicit ctx: Context): Bind - def unapply(pattern: Pattern)(implicit ctx: Context): Option[(String, Pattern)] + def copy(original: Bind)(name: String, pattern: Pattern)(implicit ctx: Context): Bind = + kernel.Pattern_Bind_module_copy(original)(name, pattern) + def unapply(pattern: Pattern)(implicit ctx: Context): Option[(String, Pattern)] = + kernel.isPattern_Bind(pattern).map(x => (x.name, x.pattern)) } - val IsUnapply: IsUnapplyModule - abstract class IsUnapplyModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] + object IsUnapply { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] = + kernel.isPattern_Unapply(pattern) } - val Unapply: UnapplyModule - abstract class UnapplyModule { + object Unapply { // TODO def apply(fun: Term, implicits: List[Term], patterns: List[Pattern])(implicit ctx: Context): Unapply - def copy(original: Unapply)(fun: Term, implicits: List[Term], patterns: List[Pattern])(implicit ctx: Context): Unapply - def unapply(pattern: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] + def copy(original: Unapply)(fun: Term, implicits: List[Term], patterns: List[Pattern])(implicit ctx: Context): Unapply = + kernel.Pattern_Unapply_module_copy(original)(fun, implicits, patterns) + def unapply(pattern: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] = + kernel.isPattern_Unapply(pattern).map(x => (x.fun, x.implicits, x.patterns)) } - val IsAlternatives: IsAlternativesModule - abstract class IsAlternativesModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] + object IsAlternatives { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] = + kernel.isPattern_Alternatives(pattern) } - val Alternatives: AlternativesModule - abstract class AlternativesModule { - def apply(patterns: List[Pattern])(implicit ctx: Context): Alternatives - def copy(original: Alternatives)(patterns: List[Pattern])(implicit ctx: Context): Alternatives - def unapply(pattern: Pattern)(implicit ctx: Context): Option[List[Pattern]] + object Alternatives { + def apply(patterns: List[Pattern])(implicit ctx: Context): Alternatives = + kernel.Pattern_Alternatives_module_apply(patterns) + def copy(original: Alternatives)(patterns: List[Pattern])(implicit ctx: Context): Alternatives = + kernel.Pattern_Alternatives_module_copy(original)(patterns) + def unapply(pattern: Pattern)(implicit ctx: Context): Option[List[Pattern]] = + kernel.isPattern_Alternatives(pattern).map(_.patterns) } - val IsTypeTest: IsTypeTestModule - abstract class IsTypeTestModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] + object IsTypeTest { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] = + kernel.isPattern_TypeTest(pattern) } - val TypeTest: TypeTestModule - abstract class TypeTestModule { - def apply(tpt: TypeTree)(implicit ctx: Context): TypeTest - def copy(original: TypeTest)(tpt: TypeTree)(implicit ctx: Context): TypeTest - def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTree] + object TypeTest { + def apply(tpt: TypeTree)(implicit ctx: Context): TypeTest = + kernel.Pattern_TypeTest_module_apply(tpt) + def copy(original: TypeTest)(tpt: TypeTree)(implicit ctx: Context): TypeTest = + kernel.Pattern_TypeTest_module_copy(original)(tpt) + def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTree] = + kernel.isPattern_TypeTest(pattern).map(_.tpt) } } diff --git a/library/src/scala/tasty/reflect/SettingsOps.scala b/library/src/scala/tasty/reflect/SettingsOps.scala index 021fa4bb7f3a..4f86f2157524 100644 --- a/library/src/scala/tasty/reflect/SettingsOps.scala +++ b/library/src/scala/tasty/reflect/SettingsOps.scala @@ -3,12 +3,11 @@ package scala.tasty.reflect trait SettingsOps extends Core { /** Compiler settings */ - def settings: Settings + def settings: Settings = kernel.settings - trait SettingsAPI { + implicit class SettingsAPI(self: Settings) { /** Can print output using colors? */ - def color: Boolean + def color: Boolean = kernel.Settings_color(self) } - implicit def SettingsDeco(settings: Settings): SettingsAPI } diff --git a/library/src/scala/tasty/reflect/SignatureOps.scala b/library/src/scala/tasty/reflect/SignatureOps.scala index c3bfe2634c03..7620b2bd6a2a 100644 --- a/library/src/scala/tasty/reflect/SignatureOps.scala +++ b/library/src/scala/tasty/reflect/SignatureOps.scala @@ -3,10 +3,10 @@ package scala.tasty.reflect trait SignatureOps extends Core { /** Erased (JVM) signatures. */ - val Signature: SignatureModule - abstract class SignatureModule { + object Signature { /** Matches the erased (JVM) signature and returns its parameters and result type. */ - def unapply(sig: Signature)(implicit ctx: Context): Option[(List[String], String)] + def unapply(sig: Signature)(implicit ctx: Context): Option[(List[String], String)] = + Some((sig.paramSigs, sig.resultSig)) } implicit class SignatureAPI(sig: Signature) { diff --git a/library/src/scala/tasty/reflect/StandardDefinitions.scala b/library/src/scala/tasty/reflect/StandardDefinitions.scala index 549461053b0e..b8e8e3625d88 100644 --- a/library/src/scala/tasty/reflect/StandardDefinitions.scala +++ b/library/src/scala/tasty/reflect/StandardDefinitions.scala @@ -6,119 +6,119 @@ trait StandardDefinitions extends Core { /** A value containing all standard definitions in [[DefinitionsAPI]] * @group Definitions */ - val definitions: DefinitionsAPI + object definitions extends StandardSymbols with StandardTypes /** Defines standard symbols (and types via its base trait). * @group API */ - trait DefinitionsAPI extends StandardTypes { + trait StandardSymbols { /** The module symbol of root package `_root_`. */ - def RootPackage: Symbol + def RootPackage: Symbol = kernel.Definitions_RootPackage /** The class symbol of root package `_root_`. */ - def RootClass: Symbol + def RootClass: Symbol = kernel.Definitions_RootClass /** The class symbol of empty package `_root_._empty_`. */ - def EmptyPackageClass: Symbol + def EmptyPackageClass: Symbol = kernel.Definitions_EmptyPackageClass /** The module symbol of package `scala`. */ - def ScalaPackage: Symbol + def ScalaPackage: Symbol = kernel.Definitions_ScalaPackage /** The class symbol of package `scala`. */ - def ScalaPackageClass: Symbol + def ScalaPackageClass: Symbol = kernel.Definitions_ScalaPackageClass /** The class symbol of core class `scala.Any`. */ - def AnyClass: Symbol + def AnyClass: Symbol = kernel.Definitions_AnyClass /** The class symbol of core class `scala.AnyVal`. */ - def AnyValClass: Symbol + def AnyValClass: Symbol = kernel.Definitions_AnyValClass /** The class symbol of core class `java.lang.Object`. */ - def ObjectClass: Symbol + def ObjectClass: Symbol = kernel.Definitions_ObjectClass /** The type symbol of core class `scala.AnyRef`. */ - def AnyRefClass: Symbol + def AnyRefClass: Symbol = kernel.Definitions_AnyRefClass /** The class symbol of core class `scala.Null`. */ - def NullClass: Symbol + def NullClass: Symbol = kernel.Definitions_NullClass /** The class symbol of core class `scala.Nothing`. */ - def NothingClass: Symbol + def NothingClass: Symbol = kernel.Definitions_NothingClass /** The class symbol of primitive class `scala.Unit`. */ - def UnitClass: Symbol + def UnitClass: Symbol = kernel.Definitions_UnitClass /** The class symbol of primitive class `scala.Byte`. */ - def ByteClass: Symbol + def ByteClass: Symbol = kernel.Definitions_ByteClass /** The class symbol of primitive class `scala.Short`. */ - def ShortClass: Symbol + def ShortClass: Symbol = kernel.Definitions_ShortClass /** The class symbol of primitive class `scala.Char`. */ - def CharClass: Symbol + def CharClass: Symbol = kernel.Definitions_CharClass /** The class symbol of primitive class `scala.Int`. */ - def IntClass: Symbol + def IntClass: Symbol = kernel.Definitions_IntClass /** The class symbol of primitive class `scala.Long`. */ - def LongClass: Symbol + def LongClass: Symbol = kernel.Definitions_LongClass /** The class symbol of primitive class `scala.Float`. */ - def FloatClass: Symbol + def FloatClass: Symbol = kernel.Definitions_FloatClass /** The class symbol of primitive class `scala.Double`. */ - def DoubleClass: Symbol + def DoubleClass: Symbol = kernel.Definitions_DoubleClass /** The class symbol of primitive class `scala.Boolean`. */ - def BooleanClass: Symbol + def BooleanClass: Symbol = kernel.Definitions_BooleanClass /** The class symbol of class `scala.String`. */ - def StringClass: Symbol + def StringClass: Symbol = kernel.Definitions_StringClass /** The class symbol of class `java.lang.Class`. */ - def ClassClass: Symbol + def ClassClass: Symbol = kernel.Definitions_ClassClass /** The class symbol of class `scala.Array`. */ - def ArrayClass: Symbol + def ArrayClass: Symbol = kernel.Definitions_ArrayClass /** The module symbol of module `scala.Predef`. */ - def PredefModule: Symbol + def PredefModule: Symbol = kernel.Definitions_PredefModule /** The module symbol of package `java.lang`. */ - def JavaLangPackage: Symbol + def JavaLangPackage: Symbol = kernel.Definitions_JavaLangPackage /** The module symbol of module `scala.Array`. */ - def ArrayModule: Symbol + def ArrayModule: Symbol = kernel.Definitions_ArrayModule /** The method symbol of method `apply` in class `scala.Array`. */ - def Array_apply: Symbol + def Array_apply: Symbol = kernel.Definitions_Array_apply /** The method symbol of method `clone` in class `scala.Array`. */ - def Array_clone: Symbol + def Array_clone: Symbol = kernel.Definitions_Array_clone /** The method symbol of method `length` in class `scala.Array`. */ - def Array_length: Symbol + def Array_length: Symbol = kernel.Definitions_Array_length /** The method symbol of method `update` in class `scala.Array`. */ - def Array_update: Symbol + def Array_update: Symbol = kernel.Definitions_Array_update /** A dummy class symbol that is used to indicate repeated parameters * compiled by the Scala compiler. */ - def RepeatedParamClass: Symbol + def RepeatedParamClass: Symbol = kernel.Definitions_RepeatedParamClass /** The class symbol of class `scala.Option`. */ - def OptionClass: Symbol + def OptionClass: Symbol = kernel.Definitions_OptionClass /** The module symbol of module `scala.None`. */ - def NoneModule: Symbol + def NoneModule: Symbol = kernel.Definitions_NoneModule /** The module symbol of module `scala.Some`. */ - def SomeModule: Symbol + def SomeModule: Symbol = kernel.Definitions_SomeModule /** Function-like object that maps arity to symbols for classes `scala.Product` */ - def ProductClass: Symbol + def ProductClass: Symbol = kernel.Definitions_ProductClass /** Function-like object that maps arity to symbols for classes `scala.FunctionX`. * - 0th element is `Function0` @@ -126,7 +126,8 @@ trait StandardDefinitions extends Core { * - ... * - Nth element is `FunctionN` */ - def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol + def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol = + kernel.Definitions_FunctionClass(arity, isImplicit, isErased) /** Function-like object that maps arity to symbols for classes `scala.TupleX`. * - 0th element is `NoSymbol` @@ -137,7 +138,8 @@ trait StandardDefinitions extends Core { * - 23nd element is `NoSymbol` // TODO update when we will have more tuples * - ... */ - def TupleClass(arity: Int): Symbol + def TupleClass(arity: Int): Symbol = + kernel.Definitions_TupleClass(arity) /** Contains Scala primitive value classes: * - Byte @@ -150,7 +152,8 @@ trait StandardDefinitions extends Core { * - Boolean * - Unit */ - def ScalaPrimitiveValueClasses: List[Symbol] + def ScalaPrimitiveValueClasses: List[Symbol] = + UnitClass :: BooleanClass :: ScalaNumericValueClasses /** Contains Scala numeric value classes: * - Byte @@ -161,7 +164,9 @@ trait StandardDefinitions extends Core { * - Double * - Char */ - def ScalaNumericValueClasses: List[Symbol] + def ScalaNumericValueClasses: List[Symbol] = + ByteClass :: ShortClass :: IntClass :: LongClass :: FloatClass :: DoubleClass :: CharClass :: Nil + } /** Defines standard types. @@ -169,51 +174,51 @@ trait StandardDefinitions extends Core { */ trait StandardTypes { /** The type of primitive type `Unit`. */ - def UnitType: Type + def UnitType: Type = kernel.Definitions_UnitType /** The type of primitive type `Byte`. */ - def ByteType: Type + def ByteType: Type = kernel.Definitions_ByteType /** The type of primitive type `Short`. */ - def ShortType: Type + def ShortType: Type = kernel.Definitions_ShortType /** The type of primitive type `Char`. */ - def CharType: Type + def CharType: Type = kernel.Definitions_CharType /** The type of primitive type `Int`. */ - def IntType: Type + def IntType: Type = kernel.Definitions_IntType /** The type of primitive type `Long`. */ - def LongType: Type + def LongType: Type = kernel.Definitions_LongType /** The type of primitive type `Float`. */ - def FloatType: Type + def FloatType: Type = kernel.Definitions_FloatType /** The type of primitive type `Double`. */ - def DoubleType: Type + def DoubleType: Type = kernel.Definitions_DoubleType /** The type of primitive type `Boolean`. */ - def BooleanType: Type + def BooleanType: Type = kernel.Definitions_BooleanType /** The type of core type `Any`. */ - def AnyType: Type + def AnyType: Type = kernel.Definitions_AnyType /** The type of core type `AnyVal`. */ - def AnyValType: Type + def AnyValType: Type = kernel.Definitions_AnyValType /** The type of core type `AnyRef`. */ - def AnyRefType: Type + def AnyRefType: Type = kernel.Definitions_AnyRefType /** The type of core type `Object`. */ - def ObjectType: Type + def ObjectType: Type = kernel.Definitions_ObjectType /** The type of core type `Nothing`. */ - def NothingType: Type + def NothingType: Type = kernel.Definitions_NothingType /** The type of core type `Null`. */ - def NullType: Type + def NullType: Type = kernel.Definitions_NullType /** The type for `scala.String`. */ - def StringType: Type + def StringType: Type = kernel.Definitions_StringType } } diff --git a/library/src/scala/tasty/reflect/SymbolOps.scala b/library/src/scala/tasty/reflect/SymbolOps.scala index 6ed87d3deebb..3fa57a4dcc0c 100644 --- a/library/src/scala/tasty/reflect/SymbolOps.scala +++ b/library/src/scala/tasty/reflect/SymbolOps.scala @@ -86,9 +86,9 @@ trait SymbolOps extends Core { // PackageSymbol - val IsPackageSymbol: IsPackageSymbolModule - abstract class IsPackageSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] + object IsPackageSymbol { + def unapply(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] = + kernel.isPackageSymbol(symbol) } trait PackageSymbolAPI { @@ -98,9 +98,9 @@ trait SymbolOps extends Core { // ClassSymbol - val IsClassSymbol: IsClassSymbolModule - abstract class IsClassSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] + object IsClassSymbol { + def unapply(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] = + kernel.isClassSymbol(symbol) } val ClassSymbol: ClassSymbolModule @@ -146,9 +146,9 @@ trait SymbolOps extends Core { // TypeSymbol - val IsTypeSymbol: IsTypeSymbolModule - abstract class IsTypeSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] + object IsTypeSymbol { + def unapply(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] = + kernel.isTypeSymbol(symbol) } trait TypeSymbolAPI { @@ -161,9 +161,9 @@ trait SymbolOps extends Core { // DefSymbol - val IsDefSymbol: IsDefSymbolModule - abstract class IsDefSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] + object IsDefSymbol { + def unapply(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] = + kernel.isDefSymbol(symbol) } trait DefSymbolAPI { @@ -176,9 +176,9 @@ trait SymbolOps extends Core { // ValSymbol - val IsValSymbol: IsValSymbolModule - abstract class IsValSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] + object IsValSymbol { + def unapply(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] = + kernel.isValSymbol(symbol) } trait ValSymbolAPI { @@ -194,9 +194,9 @@ trait SymbolOps extends Core { // BindSymbol - val IsBindSymbol: IsBindSymbolModule - abstract class IsBindSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] + object IsBindSymbol { + def unapply(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] = + kernel.isBindSymbol(symbol) } trait BindSymbolAPI { @@ -207,8 +207,8 @@ trait SymbolOps extends Core { // NoSymbol - val NoSymbol: NoSymbolModule - abstract class NoSymbolModule { - def unapply(symbol: Symbol)(implicit ctx: Context): Boolean + object NoSymbol { + def unapply(symbol: Symbol)(implicit ctx: Context): Boolean = + kernel.isNoSymbol(symbol) } } diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index 6a907bd7507d..a85a246b4a6e 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -16,16 +16,18 @@ trait TreeOps extends Core { def symbol(implicit ctx: Context): Symbol = kernel.Tree_symbol(self) } - val IsPackageClause: IsPackageClauseModule - abstract class IsPackageClauseModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[PackageClause] + object IsPackageClause { + def unapply(tree: Tree)(implicit ctx: Context): Option[PackageClause] = + kernel.isPackageClause(tree) } - val PackageClause: PackageClauseModule - abstract class PackageClauseModule { - def apply(pid: Term.Ref, stats: List[Tree])(implicit ctx: Context): PackageClause - def copy(original: PackageClause)(pid: Term.Ref, stats: List[Tree])(implicit ctx: Context): PackageClause - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term.Ref, List[Tree])] + object PackageClause { + def apply(pid: Term.Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = + kernel.PackageClause_apply(pid, stats) + def copy(original: PackageClause)(pid: Term.Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = + kernel.PackageClause_copy(original)(pid, stats) + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term.Ref, List[Tree])] = + kernel.isPackageClause(tree).map(x => (x.pid, x.stats)) } implicit class PackageClauseAPI(self: PackageClause) { @@ -33,35 +35,36 @@ trait TreeOps extends Core { def stats(implicit ctx: Context): List[Tree] = kernel.PackageClause_stats(self) } - val IsImport: IsImportModule - abstract class IsImportModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[Import] + object IsImport { + def unapply(tree: Tree)(implicit ctx: Context): Option[Import] = + kernel.isImport(tree) } - val Import: ImportModule - abstract class ImportModule { - def apply(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import - def copy(original: Import)(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import - def unapply(imp: Tree)(implicit ctx: Context): Option[(Boolean, Term, List[ImportSelector])] + object Import { + def apply(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import = + kernel.Import_apply(impliedOnly, expr, selectors) + def copy(original: Import)(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import = + kernel.Import_copy(original)(impliedOnly, expr, selectors) + def unapply(tree: Tree)(implicit ctx: Context): Option[(Boolean, Term, List[ImportSelector])] = + kernel.isImport(tree).map(x => (x.impliedOnly, x.expr, x.selectors)) } implicit class ImportAPI(self: Import) { def impliedOnly: Boolean = kernel.Import_impliedOnly(self) def expr(implicit ctx: Context): Term = kernel.Import_expr(self) - def selectors(implicit ctx: Context): List[ImportSelector] = kernel.Import_selectors(self) + def selectors(implicit ctx: Context): List[ImportSelector] = + kernel.Import_selectors(self) } - val IsStatement: IsStatementModule - abstract class IsStatementModule { + object IsStatement { /** Matches any Statement and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Statement] + def unapply(tree: Tree)(implicit ctx: Context): Option[Statement] = kernel.isStatement(tree) } // ----- Definitions ---------------------------------------------- - val IsDefinition: IsDefinitionModule - abstract class IsDefinitionModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[Definition] + object IsDefinition { + def unapply(tree: Tree)(implicit ctx: Context): Option[Definition] = kernel.isDefinition(tree) } implicit class DefinitionAPI(self: Definition) { @@ -70,16 +73,16 @@ trait TreeOps extends Core { // ClassDef - val IsClassDef: IsClassDefModule - abstract class IsClassDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[ClassDef] + object IsClassDef { + def unapply(tree: Tree)(implicit ctx: Context): Option[ClassDef] = kernel.isClassDef(tree) } - val ClassDef: ClassDefModule - abstract class ClassDefModule { + object ClassDef { // TODO def apply(name: String, constr: DefDef, parents: List[TermOrTypeTree], selfOpt: Option[ValDef], body: List[Statement])(implicit ctx: Context): ClassDef - def copy(original: ClassDef)(name: String, constr: DefDef, parents: List[TermOrTypeTree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement])(implicit ctx: Context): ClassDef - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, DefDef, List[TermOrTypeTree], List[TypeTree], Option[ValDef], List[Statement])] + def copy(original: ClassDef)(name: String, constr: DefDef, parents: List[TermOrTypeTree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement])(implicit ctx: Context): ClassDef = + kernel.ClassDef_copy(original)(name, constr, parents, derived, selfOpt, body) + def unapply(tree: Tree)(implicit ctx: Context): Option[(String, DefDef, List[TermOrTypeTree], List[TypeTree], Option[ValDef], List[Statement])] = + kernel.isClassDef(tree).map(x => (x.name, x.constructor, x.parents, x.derived, x.self, x.body)) } implicit class ClassDefAPI(self: ClassDef) { @@ -93,38 +96,40 @@ trait TreeOps extends Core { // DefDef - val IsDefDef: IsDefDefModule - abstract class IsDefDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[DefDef] + object IsDefDef { + def unapply(tree: Tree)(implicit ctx: Context): Option[DefDef] = kernel.isDefDef(tree) } - val DefDef: DefDefModule - abstract class DefDefModule { - def apply(symbol: DefSymbol, rhsFn: List[Type] => List[List[Term]] => Option[Term])(implicit ctx: Context): DefDef - def copy(original: DefDef)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): DefDef - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] + object DefDef { + def apply(symbol: DefSymbol, rhsFn: List[Type] => List[List[Term]] => Option[Term])(implicit ctx: Context): DefDef = + kernel.DefDef_apply(symbol, rhsFn) + def copy(original: DefDef)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): DefDef = + kernel.DefDef_copy(original)(name, typeParams, paramss, tpt, rhs) + def unapply(tree: Tree)(implicit ctx: Context): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] = + kernel.isDefDef(tree).map(x => (x.name, x.typeParams, x.paramss, x.returnTpt, x.rhs)) } implicit class DefDefAPI(self: DefDef) { def typeParams(implicit ctx: Context): List[TypeDef] = kernel.DefDef_typeParams(self) def paramss(implicit ctx: Context): List[List[ValDef]] = kernel.DefDef_paramss(self) - def returnTpt(implicit ctx: Context): TypeTree = kernel.DefDef_returnTpt(self) + def returnTpt(implicit ctx: Context): TypeTree = kernel.DefDef_returnTpt(self) // TODO rename to tpt def rhs(implicit ctx: Context): Option[Term] = kernel.DefDef_rhs(self) def symbol(implicit ctx: Context): DefSymbol = kernel.DefDef_symbol(self) } // ValDef - val IsValDef: IsValDefModule - abstract class IsValDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[ValDef] + object IsValDef { + def unapply(tree: Tree)(implicit ctx: Context): Option[ValDef] = kernel.isValDef(tree) } - val ValDef: ValDefModule - abstract class ValDefModule { - def apply(sym: ValSymbol, rhs: Option[Term])(implicit ctx: Context): ValDef - def copy(original: ValDef)(name: String, tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): ValDef - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeTree, Option[Term])] + object ValDef { + def apply(symbol: ValSymbol, rhs: Option[Term])(implicit ctx: Context): ValDef = + kernel.ValDef_apply(symbol, rhs) + def copy(original: ValDef)(name: String, tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): ValDef = + kernel.ValDef_copy(original)(name, tpt, rhs) + def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeTree, Option[Term])] = + kernel.isValDef(tree).map(x => (x.name, x.tpt, x.rhs)) } implicit class ValDefAPI(self: ValDef) { @@ -135,16 +140,17 @@ trait TreeOps extends Core { // TypeDef - val IsTypeDef: IsTypeDefModule - abstract class IsTypeDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[TypeDef] + object IsTypeDef { + def unapply(tree: Tree)(implicit ctx: Context): Option[TypeDef] = kernel.isTypeDef(tree) } - val TypeDef: TypeDefModule - abstract class TypeDefModule { - def apply(symbol: TypeSymbol)(implicit ctx: Context): TypeDef - def copy(original: TypeDef)(name: String, rhs: TypeOrBoundsTree)(implicit ctx: Context): TypeDef - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree /* TypeTree | TypeBoundsTree */)] + object TypeDef { + def apply(symbol: TypeSymbol)(implicit ctx: Context): TypeDef = + kernel.TypeDef_apply(symbol) + def copy(original: TypeDef)(name: String, rhs: TypeOrBoundsTree)(implicit ctx: Context): TypeDef = + kernel.TypeDef_copy(original)(name, rhs) + def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree /* TypeTree | TypeBoundsTree */)] = + kernel.isTypeDef(tree).map(x => (x.name, x.rhs)) } implicit class TypeDefAPI(self: TypeDef) { @@ -154,9 +160,9 @@ trait TreeOps extends Core { // PackageDef - val IsPackageDef: IsPackageDefModule - abstract class IsPackageDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[PackageDef] + object IsPackageDef { + def unapply(tree: Tree)(implicit ctx: Context): Option[PackageDef] = + kernel.isPackageDef(tree) } implicit class PackageDefAPI(self: PackageDef) { @@ -165,9 +171,9 @@ trait TreeOps extends Core { def symbol(implicit ctx: Context): PackageSymbol = kernel.PackageDef_symbol(self) } - val PackageDef: PackageDefModule - abstract class PackageDefModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, PackageDef)] + object PackageDef { + def unapply(tree: Tree)(implicit ctx: Context): Option[(String, PackageDef)] = + kernel.isPackageDef(tree).map(x => (x.name, x.owner)) } // ----- Terms ---------------------------------------------------- @@ -179,436 +185,453 @@ trait TreeOps extends Core { def underlying(implicit ctx: Context): Term = kernel.Term_underlying(self) } - val IsTerm: IsTermModule - abstract class IsTermModule { + object IsTerm { /** Matches any term */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Term] + def unapply(tree: Tree)(implicit ctx: Context): Option[Term] = + kernel.isTerm(tree) + /** Matches any term */ - def unapply(parent: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[Term] + def unapply(parent: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[Term] = + kernel.isTermNotTypeTree(parent) } /** Scala term. Any tree that can go in expression position. */ - val Term: TermModule - abstract class TermModule extends TermCoreModule { + object Term extends TermCoreModule { - val IsIdent: IsIdentModule - abstract class IsIdentModule { + object IsIdent { /** Matches any Ident and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Ident] + def unapply(tree: Tree)(implicit ctx: Context): Option[Ident] = kernel.isTerm_Ident(tree) } - val Ref: RefModule - abstract class RefModule { + object Ref { /** Create a reference tree */ - def apply(sym: Symbol)(implicit ctx: Context): Ref + def apply(sym: Symbol)(implicit ctx: Context): Ref = + kernel.Term_Ref_apply(sym) // TODO def copy(original: Tree)(name: String)(implicit ctx: Context): Ref } /** Scala term identifier */ - val Ident: IdentModule - abstract class IdentModule { - def apply(tmref: TermRef)(implicit ctx: Context): Term + object Ident { + def apply(tmref: TermRef)(implicit ctx: Context): Term = + kernel.Term_Ident_apply(tmref) - def copy(original: Tree)(name: String)(implicit ctx: Context): Ident + def copy(original: Tree)(name: String)(implicit ctx: Context): Ident = + kernel.Term_Ident_copy(original)(name) /** Matches a term identifier and returns its name */ - def unapply(tree: Tree)(implicit ctx: Context): Option[String] - + def unapply(tree: Tree)(implicit ctx: Context): Option[String] = + kernel.isTerm_Ident(tree).map(_.name) } - val IsSelect: IsSelectModule - abstract class IsSelectModule { + object IsSelect { /** Matches any Select and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Select] + def unapply(tree: Tree)(implicit ctx: Context): Option[Select] = kernel.isTerm_Select(tree) } /** Scala term selection */ - val Select: SelectModule - abstract class SelectModule { + object Select { /** Select a field or a non-overloaded method by name * * @note The method will produce an assertion error if the selected * method is overloaded. The method `overloaded` should be used * in that case. */ - def unique(qualifier: Term, name: String)(implicit ctx: Context): Select + def unique(qualifier: Term, name: String)(implicit ctx: Context): Select = + kernel.Term_Select_unique(qualifier, name) + // TODO rename, this returns an Apply and not a Select /** Call an overloaded method with the given type and term parameters */ - def overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Apply + def overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Apply = + kernel.Term_Select_overloaded(qualifier, name, targs, args) - def copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Select + def copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Select = + kernel.Term_Select_copy(original)(qualifier, name) - /** Matches `.` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, String)] + /** Matches `.` */ + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, String)] = + kernel.isTerm_Select(tree).map(x => (x.qualifier, x.name)) } - val IsLiteral: IsLiteralModule - abstract class IsLiteralModule { + object IsLiteral { /** Matches any Literal and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Literal] + def unapply(tree: Tree)(implicit ctx: Context): Option[Literal] = kernel.isTerm_Literal(tree) } /** Scala literal constant */ - val Literal: LiteralModule - abstract class LiteralModule { + object Literal { /** Create a literal constant */ - def apply(constant: Constant)(implicit ctx: Context): Literal + def apply(constant: Constant)(implicit ctx: Context): Literal = + kernel.Term_Literal_apply(constant) - def copy(original: Tree)(constant: Constant)(implicit ctx: Context): Literal + def copy(original: Tree)(constant: Constant)(implicit ctx: Context): Literal = + kernel.Term_Literal_copy(original)(constant) /** Matches a literal constant */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Constant] - + def unapply(tree: Tree)(implicit ctx: Context): Option[Constant] = + kernel.isTerm_Literal(tree).map(_.constant) } - val IsThis: IsThisModule - abstract class IsThisModule { + object IsThis { /** Matches any This and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[This] + def unapply(tree: Tree)(implicit ctx: Context): Option[This] = kernel.isTerm_This(tree) } /** Scala `this` or `this[id]` */ - val This: ThisModule - abstract class ThisModule { + object This { /** Create a `this[` */ - def apply(cls: ClassSymbol)(implicit ctx: Context): This + def apply(cls: ClassSymbol)(implicit ctx: Context): This = + kernel.Term_This_apply(cls) - def copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): This + def copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): This = + kernel.Term_This_copy(original)(qual) /** Matches `this[` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Option[Id]] + def unapply(tree: Tree)(implicit ctx: Context): Option[Option[Id]] = + kernel.isTerm_This(tree).map(_.id) } - val IsNew: IsNewModule - abstract class IsNewModule { + object IsNew { /** Matches any New and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[New] + def unapply(tree: Tree)(implicit ctx: Context): Option[New] = kernel.isTerm_New(tree) } /** Scala `new` */ - val New: NewModule - abstract class NewModule { + object New { /** Create a `new ` */ - def apply(tpt: TypeTree)(implicit ctx: Context): New + def apply(tpt: TypeTree)(implicit ctx: Context): New = + kernel.Term_New_apply(tpt) - def copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): New + def copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): New = + kernel.Term_New_copy(original)(tpt) /** Matches a `new ` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[TypeTree] - + def unapply(tree: Tree)(implicit ctx: Context): Option[TypeTree] = + kernel.isTerm_New(tree).map(_.tpt) } - val IsNamedArg: IsNamedArgModule - abstract class IsNamedArgModule { + object IsNamedArg { /** Matches any NamedArg and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[NamedArg] + def unapply(tree: Tree)(implicit ctx: Context): Option[NamedArg] = kernel.isTerm_NamedArg(tree) } /** Scala named argument `x = y` in argument position */ - val NamedArg: NamedArgModule - abstract class NamedArgModule { + object NamedArg { /** Create a named argument ` = ` */ - def apply(name: String, arg: Term)(implicit ctx: Context): NamedArg + def apply(name: String, arg: Term)(implicit ctx: Context): NamedArg = + kernel.Term_NamedArg_apply(name, arg) - def copy(tree: NamedArg)(name: String, arg: Term)(implicit ctx: Context): NamedArg + def copy(original: NamedArg)(name: String, arg: Term)(implicit ctx: Context): NamedArg = + kernel.Term_NamedArg_copy(original)(name, arg) /** Matches a named argument ` = ` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(String, Term)] + def unapply(tree: Tree)(implicit ctx: Context): Option[(String, Term)] = + kernel.isTerm_NamedArg(tree).map(x => (x.name, x.value)) } - val IsApply: IsApplyModule - abstract class IsApplyModule { + object IsApply { /** Matches any Apply and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Apply] + def unapply(tree: Tree)(implicit ctx: Context): Option[Apply] = kernel.isTerm_Apply(tree) } /** Scala parameter application */ - val Apply: ApplyModule - abstract class ApplyModule { + object Apply { /** Create a function application `()` */ - def apply(fn: Term, args: List[Term])(implicit ctx: Context): Apply + def apply(fun: Term, args: List[Term])(implicit ctx: Context): Apply = + kernel.Term_Apply_apply(fun, args) - def copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Apply + def copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Apply = + kernel.Term_Apply_copy(original)(fun, args) /** Matches a function application `()` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[Term])] - + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[Term])] = + kernel.isTerm_Apply(tree).map(x => (x.fun, x.args)) } - val IsTypeApply: IsTypeApplyModule - abstract class IsTypeApplyModule { + object IsTypeApply { /** Matches any TypeApply and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[TypeApply] + def unapply(tree: Tree)(implicit ctx: Context): Option[TypeApply] = + kernel.isTerm_TypeApply(tree) } /** Scala type parameter application */ - val TypeApply: TypeApplyModule - abstract class TypeApplyModule { + object TypeApply { /** Create a function type application `[]` */ - def apply(fn: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply + def apply(fun: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = + kernel.Term_TypeApply_apply(fun, args) - def copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply + def copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = + kernel.Term_TypeApply_copy(original)(fun, args) /** Matches a function type application `[]` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[TypeTree])] + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[TypeTree])] = + kernel.isTerm_TypeApply(tree).map(x => (x.fun, x.args)) } - val IsSuper: IsSuperModule - abstract class IsSuperModule { + object IsSuper { /** Matches any Super and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Super] + def unapply(tree: Tree)(implicit ctx: Context): Option[Super] = kernel.isTerm_Super(tree) } /** Scala `x.super` or `x.super[id]` */ - val Super: SuperModule - abstract class SuperModule { + object Super { /** Creates a `.super[` */ - def apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Super + def apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = + kernel.Term_Super_apply(qual, mix) - def copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Super + def copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = + kernel.Term_Super_copy(original)(qual, mix) /** Matches a `.super[` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Option[Id])] - + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Option[Id])] = + kernel.isTerm_Super(tree).map(x => (x.qualifier, x.id)) } - val IsTyped: IsTypedModule - abstract class IsTypedModule { + object IsTyped { /** Matches any Typed and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Typed] + def unapply(tree: Tree)(implicit ctx: Context): Option[Typed] = kernel.isTerm_Typed(tree) } /** Scala ascription `x: T` */ - val Typed: TypedModule - abstract class TypedModule { + object Typed { /** Create a type ascription `: ` */ - def apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed + def apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = + kernel.Term_Typed_apply(expr, tpt) - def copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed + def copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = + kernel.Term_Typed_copy(original)(expr, tpt) /** Matches `: ` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, TypeTree)] + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, TypeTree)] = + kernel.isTerm_Typed(tree).map(x => (x.expr, x.tpt)) } - val IsAssign: IsAssignModule - abstract class IsAssignModule { + object IsAssign { /** Matches any Assign and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Assign] + def unapply(tree: Tree)(implicit ctx: Context): Option[Assign] = kernel.isTerm_Assign(tree) } /** Scala assign `x = y` */ - val Assign: AssignModule - abstract class AssignModule { + object Assign { /** Create an assignment ` = ` */ - def apply(lhs: Term, rhs: Term)(implicit ctx: Context): Assign + def apply(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = + kernel.Term_Assign_apply(lhs, rhs) - def copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Assign + def copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = + kernel.Term_Assign_copy(original)(lhs, rhs) /** Matches an assignment ` = ` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term)] - + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term)] = + kernel.isTerm_Assign(tree).map(x => (x.lhs, x.rhs)) } - val IsBlock: IsBlockModule - abstract class IsBlockModule { + object IsBlock { /** Matches any Block and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Block] + def unapply(tree: Tree)(implicit ctx: Context): Option[Block] = kernel.isTerm_Block(tree) } /** Scala code block `{ stat0; ...; statN; expr }` term */ - val Block: BlockModule - abstract class BlockModule { + object Block { /** Creates a block `{ ; }` */ - def apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Block + def apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = + kernel.Term_Block_apply(stats, expr) - def copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Block + def copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = + kernel.Term_Block_copy(original)(stats, expr) /** Matches a block `{ ; }` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Statement], Term)] - + def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Statement], Term)] = + kernel.isTerm_Block(tree).map(x => (x.statements, x.expr)) } - val IsLambda: IsLambdaModule - abstract class IsLambdaModule { + object IsLambda { /** Matches any Lambda and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Lambda] + def unapply(tree: Tree)(implicit ctx: Context): Option[Lambda] = kernel.isTerm_Lambda(tree) } - val Lambda: LambdaModule - abstract class LambdaModule { - - def apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Lambda + object Lambda { - def copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Lambda + def apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Lambda = + kernel.Term_Lambda_apply(meth, tpt) - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Option[TypeTree])] + def copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Lambda = + kernel.Term_Lambda_copy(original)(meth, tpt) + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Option[TypeTree])] = + kernel.isTerm_Lambda(tree).map(x => (x.meth, x.tptOpt)) } - val IsIf: IsIfModule - abstract class IsIfModule { + object IsIf { /** Matches any If and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[If] + def unapply(tree: Tree)(implicit ctx: Context): Option[If] = kernel.isTerm_If(tree) } /** Scala `if`/`else` term */ - val If: IfModule - abstract class IfModule { + object If { /** Create an if/then/else `if () else ` */ - def apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If + def apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = + kernel.Term_If_apply(cond, thenp, elsep) - def copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If + def copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = + kernel.Term_If_copy(original)(cond, thenp, elsep) /** Matches an if/then/else `if () else ` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term, Term)] + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term, Term)] = + kernel.isTerm_If(tree).map(x => (x.cond, x.thenp, x.elsep)) } - val IsMatch: IsMatchModule - abstract class IsMatchModule { + object IsMatch { /** Matches any Match and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Match] + def unapply(tree: Tree)(implicit ctx: Context): Option[Match] = kernel.isTerm_Match(tree) } /** Scala `match` term */ - val Match: MatchModule - abstract class MatchModule { + object Match { /** Creates a pattern match ` match { }` */ - def apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match + def apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = + kernel.Term_Match_apply(selector, cases) - def copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match + def copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = + kernel.Term_Match_copy(original)(selector, cases) /** Matches a pattern match ` match { }` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[CaseDef])] + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[CaseDef])] = + kernel.isTerm_Match(tree).map(x => (x.scrutinee, x.cases)) } - val IsTry: IsTryModule - abstract class IsTryModule { + object IsTry { /** Matches any Try and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Try] + def unapply(tree: Tree)(implicit ctx: Context): Option[Try] = kernel.isTerm_Try(tree) } /** Scala `try`/`catch`/`finally` term */ - val Try: TryModule - abstract class TryModule { + object Try { /** Create a try/catch `try catch { } finally ` */ - def apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try + def apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try = + kernel.Term_Try_apply(expr, cases, finalizer) - def copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try + def copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try = + kernel.Term_Try_copy(original)(expr, cases, finalizer) /** Matches a try/catch `try catch { } finally ` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[CaseDef], Option[Term])] + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[CaseDef], Option[Term])] = + kernel.isTerm_Try(tree).map(x => (x.body, x.cases, x.finalizer)) } - val IsReturn: IsReturnModule - abstract class IsReturnModule { + object IsReturn { /** Matches any Return and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Return] + def unapply(tree: Tree)(implicit ctx: Context): Option[Return] = kernel.isTerm_Return(tree) } /** Scala local `return` */ - val Return: ReturnModule - abstract class ReturnModule { + object Return { /** Creates `return ` */ - def apply(expr: Term)(implicit ctx: Context): Return + def apply(expr: Term)(implicit ctx: Context): Return = + kernel.Term_Return_apply(expr) - def copy(original: Tree)(expr: Term)(implicit ctx: Context): Return + def copy(original: Tree)(expr: Term)(implicit ctx: Context): Return = + kernel.Term_Return_copy(original)(expr) /** Matches `return ` */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Term] + def unapply(tree: Tree)(implicit ctx: Context): Option[Term] = + kernel.isTerm_Return(tree).map(_.expr) } - val IsRepeated: IsRepeatedModule - abstract class IsRepeatedModule { + object IsRepeated { /** Matches any Repeated and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Repeated] + def unapply(tree: Tree)(implicit ctx: Context): Option[Repeated] = kernel.isTerm_Repeated(tree) } - val Repeated: RepeatedModule - abstract class RepeatedModule { + object Repeated { - def apply(elems: List[Term], tpt: TypeTree)(implicit ctx: Context): Repeated + def apply(elems: List[Term], tpt: TypeTree)(implicit ctx: Context): Repeated = + kernel.Term_Repeated_apply(elems, tpt) - def copy(original: Tree)(elems: List[Term], tpt: TypeTree)(implicit ctx: Context): Repeated + def copy(original: Tree)(elems: List[Term], tpt: TypeTree)(implicit ctx: Context): Repeated = + kernel.Term_Repeated_copy(original)(elems, tpt) - def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Term], TypeTree)] + def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Term], TypeTree)] = + kernel.isTerm_Repeated(tree).map(x => (x.elems, x.elemtpt)) } - val IsInlined: IsInlinedModule - abstract class IsInlinedModule { + object IsInlined { /** Matches any Inlined and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Inlined] + def unapply(tree: Tree)(implicit ctx: Context): Option[Inlined] = kernel.isTerm_Inlined(tree) } - val Inlined: InlinedModule - abstract class InlinedModule { + object Inlined { - def apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined + def apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined = + kernel.Term_Inlined_apply(call, bindings, expansion) - def copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined + def copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined = + kernel.Term_Inlined_copy(original)(call, bindings, expansion) - def unapply(tree: Tree)(implicit ctx: Context): Option[(Option[TermOrTypeTree], List[Definition], Term)] + def unapply(tree: Tree)(implicit ctx: Context): Option[(Option[TermOrTypeTree], List[Definition], Term)] = + kernel.isTerm_Inlined(tree).map(x => (x.call, x.bindings, x.body)) } - val IsSelectOuter: IsSelectOuterModule - abstract class IsSelectOuterModule { + object IsSelectOuter { /** Matches any SelectOuter and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[SelectOuter] + def unapply(tree: Tree)(implicit ctx: Context): Option[SelectOuter] = kernel.isTerm_SelectOuter(tree) } - val SelectOuter: SelectOuterModule - abstract class SelectOuterModule { + object SelectOuter { - def apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter + def apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter = + kernel.Term_SelectOuter_apply(qualifier, name, levels) - def copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter + def copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter = + kernel.Term_SelectOuter_copy(original)(qualifier, name, levels) - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Int, Type)] + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Int, Type)] = // TODO homogenize order of parameters + kernel.isTerm_SelectOuter(tree).map(x => (x.qualifier, x.level, x.tpe)) } - val IsWhile: IsWhileModule - abstract class IsWhileModule { + object IsWhile { /** Matches any While and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[While] + def unapply(tree: Tree)(implicit ctx: Context): Option[While] = kernel.isTerm_While(tree) } - val While: WhileModule - abstract class WhileModule { + object While { /** Creates a while loop `while () ` and returns (, ) */ - def apply(cond: Term, body: Term)(implicit ctx: Context): While + def apply(cond: Term, body: Term)(implicit ctx: Context): While = + kernel.Term_While_apply(cond, body) - def copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): While + def copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): While = + kernel.Term_While_copy(original)(cond, body) /** Extractor for while loops. Matches `while () ` and returns (, ) */ - def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term)] + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term)] = + kernel.isTerm_While(tree).map(x => (x.cond, x.body)) } } diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala index a44c7d9fae58..83db5448cd63 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala @@ -22,183 +22,205 @@ trait TypeOrBoundsTreeOps extends Core { def symbol(implicit ctx: Context): Symbol = kernel.TypeTree_symbol(self) } - val IsTypeTree: IsTypeTreeModule - abstract class IsTypeTreeModule { - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] - def unapply(parent: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] + object IsTypeTree { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] = + kernel.isTypeTree(tpt) + def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] = + kernel.isTypeTreeNotTerm(termOrTypeTree) } val TypeTree: TypeTreeModule abstract class TypeTreeModule extends TypeTreeCoreModule { - val IsInferred: IsInferredModule - abstract class IsInferredModule { + object IsInferred { /** Matches any Inferred and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Inferred] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Inferred] = + kernel.isTypeTree_Inferred(tpt) } /** TypeTree containing an inferred type */ - val Inferred: InferredModule - abstract class InferredModule { - def apply(tpe: Type)(implicit ctx: Context): Inferred + object Inferred { + def apply(tpe: Type)(implicit ctx: Context): Inferred = + kernel.TypeTree_Inferred_apply(tpe) /** Matches a TypeTree containing an inferred type */ - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean = + kernel.isTypeTree_Inferred(typeOrBoundsTree).isDefined } - val IsIdent: IsIdentModule - abstract class IsIdentModule { + object IsIdent { /** Matches any Ident and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Ident] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Ident] = + kernel.isTypeTree_Ident(tpt) } - val Ident: IdentModule - abstract class IdentModule { + object Ident { // TODO def apply(name: String)(implicit ctx: Context): Ident - def copy(original: Ident)(name: String)(implicit ctx: Context): Ident - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[String] + def copy(original: Ident)(name: String)(implicit ctx: Context): Ident = + kernel.TypeTree_Ident_copy(original)(name) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[String] = + kernel.isTypeTree_Ident(typeOrBoundsTree).map(_.name) } - val IsSelect: IsSelectModule - abstract class IsSelectModule { + object IsSelect { /** Matches any Select and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Select] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Select] = + kernel.isTypeTree_Select(tpt) } - val Select: SelectModule - abstract class SelectModule { - def apply(qualifier: Term, name: String)(implicit ctx: Context): Select - def copy(original: Select)(qualifier: Term, name: String)(implicit ctx: Context): Select - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(Term, String)] + object Select { + def apply(qualifier: Term, name: String)(implicit ctx: Context): Select = + kernel.TypeTree_Select_apply(qualifier, name) + def copy(original: Select)(qualifier: Term, name: String)(implicit ctx: Context): Select = + kernel.TypeTree_Select_copy(original)(qualifier, name) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(Term, String)] = + kernel.isTypeTree_Select(typeOrBoundsTree).map(x => (x.qualifier, x.name)) } - val IsProjection: IsProjectionModule - abstract class IsProjectionModule { + object IsProjection { /** Matches any Projection and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Projection] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Projection] = + kernel.isTypeTree_Projection(tpt) } - val Projection: ProjectionModule - abstract class ProjectionModule { + object Projection { // TODO def apply(qualifier: TypeTree, name: String)(implicit ctx: Context): Project - def copy(original: Projection)(qualifier: TypeTree, name: String)(implicit ctx: Context): Projection - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, String)] + def copy(original: Projection)(qualifier: TypeTree, name: String)(implicit ctx: Context): Projection = + kernel.TypeTree_Projection_copy(original)(qualifier, name) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, String)] = + kernel.isTypeTree_Projection(typeOrBoundsTree).map(x => (x.qualifier, x.name)) } - val IsSingleton: IsSingletonModule - abstract class IsSingletonModule { + object IsSingleton { /** Matches any Singleton and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Singleton] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Singleton] = + kernel.isTypeTree_Singleton(tpt) } - val Singleton: SingletonModule - abstract class SingletonModule { - def apply(ref: Term)(implicit ctx: Context): Singleton - def copy(original: Singleton)(ref: Term)(implicit ctx: Context): Singleton - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[Term] + object Singleton { + def apply(ref: Term)(implicit ctx: Context): Singleton = + kernel.TypeTree_Singleton_apply(ref) + def copy(original: Singleton)(ref: Term)(implicit ctx: Context): Singleton = + kernel.TypeTree_Singleton_copy(original)(ref) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[Term] = + kernel.isTypeTree_Singleton(typeOrBoundsTree).map(_.ref) } - val IsRefined: IsRefinedModule - abstract class IsRefinedModule { + object IsRefined { /** Matches any Refined and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Refined] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Refined] = + kernel.isTypeTree_Refined(tpt) } - val Refined: RefinedModule - abstract class RefinedModule { + object Refined { // TODO def apply(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): Refined - def copy(original: Refined)(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): Refined - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, List[Definition])] + def copy(original: Refined)(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): Refined = + kernel.TypeTree_Refined_copy(original)(tpt, refinements) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, List[Definition])] = + kernel.isTypeTree_Refined(typeOrBoundsTree).map(x => (x.tpt, x.refinements)) } - val IsApplied: IsAppliedModule - abstract class IsAppliedModule { + object IsApplied { /** Matches any Applied and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Applied] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Applied] = + kernel.isTypeTree_Applied(tpt) } - val Applied: AppliedModule - abstract class AppliedModule { - def apply(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied - def copy(original: Applied)(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] + object Applied { + def apply(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied = + kernel.TypeTree_Applied_apply(tpt, args) + def copy(original: Applied)(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied = + kernel.TypeTree_Applied_copy(original)(tpt, args) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] = + kernel.isTypeTree_Applied(typeOrBoundsTree).map(x => (x.tpt, x.args)) } - val IsAnnotated: IsAnnotatedModule - abstract class IsAnnotatedModule { + object IsAnnotated { /** Matches any Annotated and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Annotated] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Annotated] = + kernel.isTypeTree_Annotated(tpt) } - val Annotated: AnnotatedModule - abstract class AnnotatedModule { - def apply(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated - def copy(original: Annotated)(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, Term)] + object Annotated { + def apply(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated = + kernel.TypeTree_Annotated_apply(arg, annotation) + def copy(original: Annotated)(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated = + kernel.TypeTree_Annotated_copy(original)(arg, annotation) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, Term)] = + kernel.isTypeTree_Annotated(typeOrBoundsTree).map(x => (x.arg, x.annotation)) } - val IsMatchType: IsMatchTypeModule - abstract class IsMatchTypeModule { + object IsMatchType { /** Matches any MatchType and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[MatchType] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[MatchType] = + kernel.isTypeTree_MatchType(tpt) } - val MatchType: MatchTypeModule - abstract class MatchTypeModule { - def apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType - def copy(original: MatchType)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] + object MatchType { + def apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType = + kernel.TypeTree_MatchType_apply(bound, selector, cases) + def copy(original: MatchType)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType = + kernel.TypeTree_MatchType_copy(original)(bound, selector, cases) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] = + kernel.isTypeTree_MatchType(typeOrBoundsTree).map(x => (x.bound, x.selector, x.cases)) } - val IsByName: IsByNameModule - abstract class IsByNameModule { + object IsByName { /** Matches any ByName and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[ByName] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[ByName] = + kernel.isTypeTree_ByName(tpt) } - val ByName: ByNameModule - abstract class ByNameModule { - def apply(result: TypeTree)(implicit ctx: Context): ByName - def copy(original: ByName)(result: TypeTree)(implicit ctx: Context): ByName - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] + object ByName { + def apply(result: TypeTree)(implicit ctx: Context): ByName = + kernel.TypeTree_ByName_apply(result) + def copy(original: ByName)(result: TypeTree)(implicit ctx: Context): ByName = + kernel.TypeTree_ByName_copy(original)(result) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] = + kernel.isTypeTree_ByName(typeOrBoundsTree).map(_.result) } - val IsLambdaTypeTree: IsLambdaTypeTreeModule - abstract class IsLambdaTypeTreeModule { + object IsLambdaTypeTree { /** Matches any LambdaTypeTree and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[LambdaTypeTree] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[LambdaTypeTree] = + kernel.isTypeTree_LambdaTypeTree(tpt) } - val LambdaTypeTree: LambdaTypeTreeModule - abstract class LambdaTypeTreeModule { - def apply(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree - def copy(original: LambdaTypeTree)(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(List[TypeDef], TypeOrBoundsTree)] + object LambdaTypeTree { + def apply(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree = + kernel.TypeTree_LambdaTypeTree_apply(tparams, body) + def copy(original: LambdaTypeTree)(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree = + kernel.TypeTree_LambdaTypeTree_copy(original)(tparams, body) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(List[TypeDef], TypeOrBoundsTree)] = + kernel.isTypeTree_LambdaTypeTree(typeOrBoundsTree).map(x => (x.tparams, x.body)) } - val IsTypeBind: IsTypeBindModule - abstract class IsTypeBindModule { + object IsTypeBind { /** Matches any TypeBind and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBind] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBind] = + kernel.isTypeTree_TypeBind(tpt) } - val TypeBind: TypeBindModule - abstract class TypeBindModule { + object TypeBind { // TODO def apply(name: String, tpt: TypeOrBoundsTree)(implicit ctx: Context): TypeBind - def copy(original: TypeBind)(name: String, tpt: TypeOrBoundsTree)(implicit ctx: Context): TypeBind - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree)] + def copy(original: TypeBind)(name: String, tpt: TypeOrBoundsTree)(implicit ctx: Context): TypeBind = + kernel.TypeTree_TypeBind_copy(original)(name, tpt) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree)] = + kernel.isTypeTree_TypeBind(typeOrBoundsTree).map(x => (x.name, x.body)) } - val IsTypeBlock: IsTypeBlockModule - abstract class IsTypeBlockModule { + object IsTypeBlock { /** Matches any TypeBlock and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBlock] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBlock] = + kernel.isTypeTree_TypeBlock(tpt) } - val TypeBlock: TypeBlockModule - abstract class TypeBlockModule { - def apply(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock - def copy(original: TypeBlock)(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(List[TypeDef], TypeTree)] + object TypeBlock { + def apply(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock = + kernel.TypeTree_TypeBlock_apply(aliases, tpt) + def copy(original: TypeBlock)(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock = + kernel.TypeTree_TypeBlock_copy(original)(aliases, tpt) + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(List[TypeDef], TypeTree)] = + kernel.isTypeTree_TypeBlock(typeOrBoundsTree).map(x => (x.aliases, x.tpt)) } } @@ -268,21 +290,26 @@ trait TypeOrBoundsTreeOps extends Core { def hi(implicit ctx: Context): TypeTree = kernel.TypeBoundsTree_hi(self) } - val IsTypeBoundsTree: IsTypeBoundsTreeModule - abstract class IsTypeBoundsTreeModule { - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] + object IsTypeBoundsTree { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] = + kernel.isTypeBoundsTree(tpt) } - val TypeBoundsTree: TypeBoundsTreeModule - abstract class TypeBoundsTreeModule { - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] + object TypeBoundsTree { + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] = + kernel.isTypeBoundsTree(typeOrBoundsTree).map(x => (x.low, x.hi)) + } + + object IsWildcardTypeTree { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] = + kernel.isWildcardTypeTree(tpt) } /** TypeBoundsTree containing wildcard type bounds */ - val WildcardTypeTree: WildcardTypeTreeModule - abstract class WildcardTypeTreeModule { + object WildcardTypeTree { /** Matches a TypeBoundsTree containing wildcard type bounds */ - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean = + kernel.isWildcardTypeTree(typeOrBoundsTree).isDefined } } From 6c50a400b8df2215a89685724a6c2cd266863268 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 4 Mar 2019 22:22:59 +0100 Subject: [PATCH 06/17] Remove unused classes --- .../tools/dotc/tastyreflect/CaseDefOpsImpl.scala | 7 ------- .../tools/dotc/tastyreflect/ConstantOpsImpl.scala | 8 -------- .../tools/dotc/tastyreflect/FlagsOpsImpl.scala | 6 ------ .../src/dotty/tools/dotc/tastyreflect/Helpers.scala | 12 ------------ .../dotty/tools/dotc/tastyreflect/IdOpsImpl.scala | 7 ------- .../dotc/tastyreflect/ImportSelectorOpsImpl.scala | 9 --------- .../tools/dotc/tastyreflect/PatternOpsImpl.scala | 10 ---------- .../tools/dotc/tastyreflect/PositionOpsImpl.scala | 5 ----- .../tools/dotc/tastyreflect/QuotedOpsImpl.scala | 13 ------------- .../tools/dotc/tastyreflect/ReflectionImpl.scala | 12 ------------ .../tools/dotc/tastyreflect/RootPositionImpl.scala | 11 ----------- .../tools/dotc/tastyreflect/SettingsOpsImpl.scala | 5 ----- .../tools/dotc/tastyreflect/SignatureOpsImpl.scala | 5 ----- .../dotc/tastyreflect/StandardDefinitions.scala | 9 --------- .../dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala | 4 +--- .../tastyreflect/TypeOrBoundsTreesOpsImpl.scala | 5 +---- .../scala/tasty/reflect/TypeOrBoundsTreeOps.scala | 3 +-- 17 files changed, 3 insertions(+), 128 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/Helpers.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/RootPositionImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala deleted file mode 100644 index a9de7a3fdd47..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala +++ /dev/null @@ -1,7 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.ast.tpd - -trait CaseDefOpsImpl extends scala.tasty.reflect.CaseDefOps with CoreImpl with Helpers { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala deleted file mode 100644 index 733ff7260162..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala +++ /dev/null @@ -1,8 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.core.Constants - - -trait ConstantOpsImpl extends scala.tasty.reflect.ConstantOps with CoreImpl { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala deleted file mode 100644 index aaa28cb4ecc2..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala +++ /dev/null @@ -1,6 +0,0 @@ -package dotty.tools.dotc -package tastyreflect - -trait FlagsOpsImpl extends scala.tasty.reflect.FlagsOps with CoreImpl { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/Helpers.scala b/compiler/src/dotty/tools/dotc/tastyreflect/Helpers.scala deleted file mode 100644 index 9579063f0f7e..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/Helpers.scala +++ /dev/null @@ -1,12 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.ast.Trees -import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.core.Contexts._ - -trait Helpers { - - protected final def optional[T <: Trees.Tree[_]](tree: T): Option[tree.type] = - if (tree.isEmpty) None else Some(tree) - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala deleted file mode 100644 index 187ca0971005..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala +++ /dev/null @@ -1,7 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.core.Decorators._ - -trait IdOpsImpl extends scala.tasty.reflect.IdOps with CoreImpl { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala deleted file mode 100644 index cc5c8dbcbf24..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala +++ /dev/null @@ -1,9 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.ast.{Trees, untpd} -import dotty.tools.dotc.core.StdNames.nme -import dotty.tools.dotc.core.Decorators._ - -trait ImportSelectorOpsImpl extends scala.tasty.reflect.ImportSelectorOps with CoreImpl { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala deleted file mode 100644 index e94779ef525e..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala +++ /dev/null @@ -1,10 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.ast.{Trees, tpd, untpd} -import dotty.tools.dotc.core.Contexts -import dotty.tools.dotc.core.Decorators._ -import dotty.tools.dotc.core.StdNames.nme - -trait PatternOpsImpl extends scala.tasty.reflect.PatternOps with RootPositionImpl { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala deleted file mode 100644 index 970f667d7903..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala +++ /dev/null @@ -1,5 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -trait PositionOpsImpl extends scala.tasty.reflect.PositionOps with CoreImpl { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala deleted file mode 100644 index bb91368d5c56..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala +++ /dev/null @@ -1,13 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.ast.Trees -import dotty.tools.dotc.core.Flags._ -import dotty.tools.dotc.core.Symbols.defn -import dotty.tools.dotc.core.StdNames.nme -import dotty.tools.dotc.core.quoted.PickledQuotes -import dotty.tools.dotc.core.Types - -trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index b64a138b434e..433d3c79a1ed 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -6,21 +6,9 @@ import dotty.tools.dotc.util.{SourcePosition, Spans} class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition) extends scala.tasty.Reflection with CoreImpl - with CaseDefOpsImpl - with ConstantOpsImpl with ContextOpsImpl with CommentOpsImpl - with FlagsOpsImpl - with IdOpsImpl - with ImportSelectorOpsImpl - with QuotedOpsImpl - with PatternOpsImpl - with PositionOpsImpl with PrintersImpl - with RootPositionImpl - with SettingsOpsImpl - with SignatureOpsImpl - with StandardDefinitions with SymbolOpsImpl with TreeOpsImpl with TypeOrBoundsTreesOpsImpl diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/RootPositionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/RootPositionImpl.scala deleted file mode 100644 index faeaaff824b9..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/RootPositionImpl.scala +++ /dev/null @@ -1,11 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.util.{SourcePosition, Spans} - -trait RootPositionImpl extends scala.tasty.reflect.RootPosition with ContextOpsImpl with CoreImpl { - - protected def withDefaultPos[T <: Tree](fn: Context => T)(implicit ctx: Context): T = { - fn(ctx.withSource(rootPosition.source)).withSpan(rootPosition.span) - } - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala deleted file mode 100644 index c7c6f5c22ba4..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala +++ /dev/null @@ -1,5 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -trait SettingsOpsImpl extends scala.tasty.reflect.SettingsOps with scala.tasty.reflect.ContextOps with CoreImpl { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala deleted file mode 100644 index 71772ebbaf1d..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala +++ /dev/null @@ -1,5 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -trait SignatureOpsImpl extends scala.tasty.reflect.SignatureOps with CoreImpl { - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala b/compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala deleted file mode 100644 index 852f752ab769..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala +++ /dev/null @@ -1,9 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.core.Symbols._ - - -trait StandardDefinitions extends scala.tasty.reflect.StandardDefinitions { - tasty: ReflectionImpl => - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala index 64230a19e878..092615475c80 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala @@ -1,7 +1,5 @@ package dotty.tools.dotc.tastyreflect -trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with RootPositionImpl with Helpers { - +trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl { def termAsTermOrTypeTree(term: Term): TermOrTypeTree = term - } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala index 6d2a1ae3bae4..87afb7134ef7 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala @@ -1,8 +1,5 @@ package dotty.tools.dotc.tastyreflect -trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps with RootPositionImpl { - - object TypeTree extends TypeTreeModule with TypeTreeCoreModule - +trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps with CoreImpl { def typeTreeAsParent(typeTree: TypeTree): TermOrTypeTree = typeTree } diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala index 83db5448cd63..3435a74c751f 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala @@ -29,8 +29,7 @@ trait TypeOrBoundsTreeOps extends Core { kernel.isTypeTreeNotTerm(termOrTypeTree) } - val TypeTree: TypeTreeModule - abstract class TypeTreeModule extends TypeTreeCoreModule { + object TypeTree extends TypeTreeCoreModule { object IsInferred { /** Matches any Inferred and returns it */ From 24034b8863522f41d15f9fcb52f8cc564b939199 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 4 Mar 2019 22:45:04 +0100 Subject: [PATCH 07/17] Remove ReflectionImpl --- .../decompiler/DecompilationPrinter.scala | 3 +- .../dotc/decompiler/IDEDecompilerDriver.scala | 3 +- .../dotty/tools/dotc/quoted/QuoteDriver.scala | 3 +- .../dotc/tastyreflect/PrintersImpl.scala | 57 ------------------ .../dotc/tastyreflect/ReflectionImpl.scala | 1 - .../src/scala/tasty/reflect/Printers.scala | 59 ++++++++++++++----- 6 files changed, 51 insertions(+), 75 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/PrintersImpl.scala diff --git a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala index f91e6c666cfc..b36741c65d4a 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala @@ -43,7 +43,8 @@ class DecompilationPrinter extends Phase { } else { val unitFile = unit.source.toString.replace("\\", "/").replace(".class", ".tasty") out.println(s"/** Decompiled from $unitFile */") - out.println(ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree)(ctx)) + val refl = ReflectionImpl(ctx) + out.println(new refl.SourceCodePrinter().showTree(unit.tpdTree)(ctx)) } } } diff --git a/compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala b/compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala index f7ff582f14e3..7219b25be44c 100644 --- a/compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala +++ b/compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala @@ -35,7 +35,8 @@ class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver { run.printSummary() val unit = ctx.run.units.head - val decompiled = ReflectionImpl(ctx).showSourceCode.showTree(unit.tpdTree) + val refl = ReflectionImpl(ctx) + val decompiled = new refl.SourceCodePrinter().showTree(unit.tpdTree) val tree = new TastyHTMLPrinter(unit.pickled.head._2).printContents() reporter.removeBufferedMessages.foreach(message => System.err.println(message)) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index 0fb7b576adeb..c7f97eec6925 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -47,7 +47,8 @@ class QuoteDriver extends Driver { val tree1 = if (ctx.settings.YshowRawQuoteTrees.value) tree else (new TreeCleaner).transform(tree) - ReflectionImpl(ctx).showSourceCode.showTree(tree1) + val refl = ReflectionImpl(ctx) + new refl.SourceCodePrinter().showTree(tree1) } withTree(expr, show, settings) } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/PrintersImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/PrintersImpl.scala deleted file mode 100644 index f5cd53d3dd3f..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/PrintersImpl.scala +++ /dev/null @@ -1,57 +0,0 @@ -package dotty.tools.dotc.tastyreflect -import dotty.tools.dotc.core.Flags - -trait PrintersImpl extends scala.tasty.reflect.Printers with scala.tasty.reflect.Core { reflect: ReflectionImpl => - - def showExtractors: reflect.Printer = new reflect.ExtractorsPrinter - - def showSourceCode: reflect.Printer = new reflect.SourceCodePrinter - - /** Adds `show` as an extension method of a `Tree` */ - def TreeShowDeco(tree: Tree): ShowAPI = new ShowAPI { - def show(implicit ctx: Context): String = showExtractors.showTree(tree) - def showCode(implicit ctx: Context): String = showSourceCode.showTree(tree) - } - - /** Adds `show` as an extension method of a `TypeOrBoundsTree` */ - def TypeOrBoundsTreeShowDeco(tpt: TypeOrBoundsTree): ShowAPI = new ShowAPI { - def show(implicit ctx: Context): String = showExtractors.showTypeOrBoundsTree(tpt) - def showCode(implicit ctx: Context): String = showSourceCode.showTypeOrBoundsTree(tpt) - } - - /** Adds `show` as an extension method of a `TypeOrBounds` */ - def TypeOrBoundsShowDeco(tpe: TypeOrBounds): ShowAPI = new ShowAPI { - def show(implicit ctx: Context): String = showExtractors.showTypeOrBounds(tpe) - def showCode(implicit ctx: Context): String = showSourceCode.showTypeOrBounds(tpe) - } - - /** Adds `show` as an extension method of a `CaseDef` */ - def CaseDefShowDeco(caseDef: CaseDef): ShowAPI = new ShowAPI { - def show(implicit ctx: Context): String = showExtractors.showCaseDef(caseDef) - def showCode(implicit ctx: Context): String = showSourceCode.showCaseDef(caseDef) - } - - /** Adds `show` as an extension method of a `Pattern` */ - def PatternShowDeco(pattern: Pattern): ShowAPI = new ShowAPI { - def show(implicit ctx: Context): String = showExtractors.showPattern(pattern) - def showCode(implicit ctx: Context): String = showSourceCode.showPattern(pattern) - } - - /** Adds `show` as an extension method of a `Constant` */ - def ConstantShowDeco(const: Constant): ShowAPI = new ShowAPI { - def show(implicit ctx: Context): String = showExtractors.showConstant(const) - def showCode(implicit ctx: Context): String = showSourceCode.showConstant(const) - } - - /** Adds `show` as an extension method of a `Symbol` */ - def SymbolShowDeco(symbol: Symbol): ShowAPI = new ShowAPI { - def show(implicit ctx: Context): String = showExtractors.showSymbol(symbol) - def showCode(implicit ctx: Context): String = showSourceCode.showSymbol(symbol) - } - - /** Adds `show` as an extension method of a `Flags` */ - implicit def FlagsShowDeco(flags: Flags): ShowAPI = new ShowAPI { - def show(implicit ctx: Context): String = showExtractors.showFlags(flags) - def showCode(implicit ctx: Context): String = showSourceCode.showFlags(flags) - } -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index 433d3c79a1ed..b06032e7eeab 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -8,7 +8,6 @@ class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition) with CoreImpl with ContextOpsImpl with CommentOpsImpl - with PrintersImpl with SymbolOpsImpl with TreeOpsImpl with TypeOrBoundsTreesOpsImpl diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index ce3128c8b07b..d8672ec32763 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -24,36 +24,67 @@ trait Printers with TypeOrBoundsOps { /** Adds `show` as an extension method of a `Tree` */ - implicit def TreeShowDeco(tree: Tree): ShowAPI + implicit class TreeShowDeco(tree: Tree) { + /** Shows the tree as extractors */ + def show(implicit ctx: Context): String = new ExtractorsPrinter().showTree(tree) + /** Shows the tree as source code */ + def showCode(implicit ctx: Context): String = new SourceCodePrinter().showTree(tree) + } /** Adds `show` as an extension method of a `TypeOrBoundsTree` */ - implicit def TypeOrBoundsTreeShowDeco(tpt: TypeOrBoundsTree): ShowAPI + implicit class TypeOrBoundsTreeShowDeco(tpt: TypeOrBoundsTree) { + /** Shows the tree as extractors */ + def show(implicit ctx: Context): String = new ExtractorsPrinter().showTypeOrBoundsTree(tpt) + /** Shows the tree as source code */ + def showCode(implicit ctx: Context): String = new SourceCodePrinter().showTypeOrBoundsTree(tpt) + } /** Adds `show` as an extension method of a `TypeOrBounds` */ - implicit def TypeOrBoundsShowDeco(tpt: TypeOrBounds): ShowAPI + implicit class TypeOrBoundsShowDeco(tpe: TypeOrBounds) { + /** Shows the tree as extractors */ + def show(implicit ctx: Context): String = new ExtractorsPrinter().showTypeOrBounds(tpe) + /** Shows the tree as source code */ + def showCode(implicit ctx: Context): String = new SourceCodePrinter().showTypeOrBounds(tpe) + } /** Adds `show` as an extension method of a `CaseDef` */ - implicit def CaseDefShowDeco(caseDef: CaseDef): ShowAPI + implicit class CaseDefShowDeco(caseDef: CaseDef) { + /** Shows the tree as extractors */ + def show(implicit ctx: Context): String = new ExtractorsPrinter().showCaseDef(caseDef) + /** Shows the tree as source code */ + def showCode(implicit ctx: Context): String = new SourceCodePrinter().showCaseDef(caseDef) + } /** Adds `show` as an extension method of a `Pattern` */ - implicit def PatternShowDeco(pattern: Pattern): ShowAPI + implicit class PatternShowDeco(pattern: Pattern) { + /** Shows the tree as extractors */ + def show(implicit ctx: Context): String = new ExtractorsPrinter().showPattern(pattern) + /** Shows the tree as source code */ + def showCode(implicit ctx: Context): String = new SourceCodePrinter().showPattern(pattern) + } /** Adds `show` as an extension method of a `Constant` */ - implicit def ConstantShowDeco(const: Constant): ShowAPI + implicit class ConstantShowDeco(const: Constant) { + /** Shows the tree as extractors */ + def show(implicit ctx: Context): String = new ExtractorsPrinter().showConstant(const) + /** Shows the tree as source code */ + def showCode(implicit ctx: Context): String = new SourceCodePrinter().showConstant(const) + } /** Adds `show` as an extension method of a `Symbol` */ - implicit def SymbolShowDeco(symbol: Symbol): ShowAPI + implicit class SymbolShowDeco(symbol: Symbol) { + /** Shows the tree as extractors */ + def show(implicit ctx: Context): String = new ExtractorsPrinter().showSymbol(symbol) + /** Shows the tree as source code */ + def showCode(implicit ctx: Context): String = new SourceCodePrinter().showSymbol(symbol) + } /** Adds `show` as an extension method of a `Flags` */ - implicit def FlagsShowDeco(flags: Flags): ShowAPI - - /** Define `show` as method */ - trait ShowAPI { + implicit class FlagsShowDeco(flags: Flags) { /** Shows the tree as extractors */ - def show(implicit ctx: Context): String - + def show(implicit ctx: Context): String = new ExtractorsPrinter().showFlags(flags) /** Shows the tree as source code */ - def showCode(implicit ctx: Context): String + def showCode(implicit ctx: Context): String = new SourceCodePrinter().showFlags(flags) } abstract class Printer { From ed4180d4e0d0404c3a67c48428f3cb96d05f0b4a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 4 Mar 2019 22:46:56 +0100 Subject: [PATCH 08/17] Implement TermOrTypeTree metods in library --- .../src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala | 2 -- compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala | 5 ----- .../tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala | 5 ----- library/src/scala/tasty/reflect/TreeOps.scala | 2 +- library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala | 2 +- 5 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index b06032e7eeab..6dfcb33e0dc2 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -9,8 +9,6 @@ class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition) with ContextOpsImpl with CommentOpsImpl with SymbolOpsImpl - with TreeOpsImpl - with TypeOrBoundsTreesOpsImpl with TypeOrBoundsOpsImpl { val kernel: KernelImpl = new KernelImpl(ctx, pos) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala deleted file mode 100644 index 092615475c80..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala +++ /dev/null @@ -1,5 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl { - def termAsTermOrTypeTree(term: Term): TermOrTypeTree = term -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala deleted file mode 100644 index 87afb7134ef7..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala +++ /dev/null @@ -1,5 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps with CoreImpl { - def typeTreeAsParent(typeTree: TypeTree): TermOrTypeTree = typeTree -} diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index a85a246b4a6e..3467cbe1c620 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -5,7 +5,7 @@ trait TreeOps extends Core { // Decorators - implicit def termAsTermOrTypeTree(term: Term): TermOrTypeTree + implicit def termAsTermOrTypeTree(term: Term): TermOrTypeTree = term.asInstanceOf[TermOrTypeTree] // ----- Tree ----------------------------------------------------- diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala index 3435a74c751f..72685bb4dbfb 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala @@ -3,7 +3,7 @@ package reflect trait TypeOrBoundsTreeOps extends Core { - implicit def typeTreeAsParent(term: TypeTree): TermOrTypeTree + implicit def typeTreeAsParent(term: TypeTree): TermOrTypeTree = term.asInstanceOf[TermOrTypeTree] implicit class TypeOrBoundsTreeAPI(self: TypeOrBoundsTree) { def tpe(implicit ctx: Context): TypeOrBounds = kernel.TypeOrBoundsTree_tpe(self) From 4c94200f607b01a9e23b04d3847ba1f510e91dda Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 4 Mar 2019 22:49:37 +0100 Subject: [PATCH 09/17] Remove rootContext workaround --- .../dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala | 8 -------- .../dotty/tools/dotc/tastyreflect/ReflectionImpl.scala | 1 - 2 files changed, 9 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala deleted file mode 100644 index 3293f21d4ed1..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala +++ /dev/null @@ -1,8 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -trait ContextOpsImpl extends scala.tasty.reflect.ContextOps with CoreImpl { - - // overridden to remove the implicit modifier inside the implementation - override def rootContext: Context = super.rootContext - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index 6dfcb33e0dc2..8c7092dece15 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -6,7 +6,6 @@ import dotty.tools.dotc.util.{SourcePosition, Spans} class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition) extends scala.tasty.Reflection with CoreImpl - with ContextOpsImpl with CommentOpsImpl with SymbolOpsImpl with TypeOrBoundsOpsImpl { From 03382053013ce343194c22ac7788d1ec562988a3 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 5 Mar 2019 08:15:44 +0100 Subject: [PATCH 10/17] Implement TypeOrBounds in kernel --- .../tools/dotc/tastyreflect/KernelImpl.scala | 142 +++++++- .../dotc/tastyreflect/ReflectionImpl.scala | 3 +- .../tastyreflect/TypeOrBoundsOpsImpl.scala | 343 ------------------ library/src/scala/tasty/reflect/Kernel.scala | 54 ++- .../scala/tasty/reflect/TypeOrBoundsOps.scala | 264 +++++++------- 5 files changed, 325 insertions(+), 481 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index e38cc64a96dc..c2d10b50357d 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -3,7 +3,7 @@ package tastyreflect import dotty.tools.dotc.ast.{Trees, tpd, untpd} import dotty.tools.dotc.ast.tpd.TreeOps -import dotty.tools.dotc.core.{Constants, NameKinds, Types} +import dotty.tools.dotc.core.{Constants, NameKinds, Names, Types} import dotty.tools.dotc.core.Flags._ import dotty.tools.dotc.core.StdNames.nme import dotty.tools.dotc.core.quoted.PickledQuotes @@ -957,13 +957,27 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type NoPrefix = Types.NoPrefix.type + def isNoPrefix(x: TypeOrBounds)(implicit ctx: Context): Option[NoPrefix] = + if (x == Types.NoPrefix) Some(Types.NoPrefix) else None + type TypeBounds = Types.TypeBounds + def isTypeBounds(x: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] = x match { + case x: Types.TypeBounds => Some(x) + case _ => None + } + def TypeBounds_low(self: TypeBounds)(implicit ctx: Context): Type = self.lo def TypeBounds_hi(self: TypeBounds)(implicit ctx: Context): Type = self.hi type Type = Types.Type + def isType(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { + case x: TypeBounds => None + case x if x == Types.NoPrefix => None + case _ => Some(x) + } + def `Type_=:=`(self: Type)(that: Type)(implicit ctx: Context): Boolean = self =:= that def `Type_<:<`(self: Type)(that: Type)(implicit ctx: Context): Boolean = self <:< that @@ -991,84 +1005,196 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ConstantType = Types.ConstantType - def ConstantType_value(self: ConstantType)(implicit ctx: Context): Any = self.value + def isConstantType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] = tpe match { + case tpe: Types.ConstantType => Some(tpe) + case _ => None + } + + def ConstantType_constant(self: ConstantType)(implicit ctx: Context): Constant = self.value type SymRef = Types.NamedType + def isSymRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] = tpe match { + case tp: Types.NamedType => + tp.designator match { + case sym: Symbol => Some(tp) + case _ => None + } + case _ => None + } + def SymRef_qualifier(self: SymRef)(implicit ctx: Context): TypeOrBounds = self.prefix + // TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef + def isSymRef_unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] = tpe match { + case tpe: Types.NamedType => + tpe.designator match { + case sym: Symbol => Some((sym, tpe.prefix)) + case _ => None + } + case _ => None + } + type TermRef = Types.NamedType + def isTermRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] = tpe match { + case tpe: Types.NamedType => + tpe.designator match { + case name: Names.TermName => Some(tpe) + case _ => None + } + case _ => None + } + + def TermRef_name(self: TermRef)(implicit ctx: Context): String = self.name.toString def TermRef_qualifier(self: TermRef)(implicit ctx: Context): TypeOrBounds = self.prefix + def TermRef_apply(qual: TypeOrBounds, name: String)(implicit ctx: Context): TermRef = + Types.TermRef(qual, name.toTermName) + type TypeRef = Types.NamedType + def isTypeRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] = tpe match { + case tpe: Types.NamedType => + tpe.designator match { + case name: Names.TypeName => Some(tpe) + case _ => None + } + case _ => None + } + def TypeRef_name(self: TypeRef)(implicit ctx: Context): String = self.name.toString def TypeRef_qualifier(self: TypeRef)(implicit ctx: Context): TypeOrBounds = self.prefix type SuperType = Types.SuperType + def isSuperType(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] = tpe match { + case tpe: Types.SuperType => Some(tpe) + case _ => None + } + def SuperType_thistpe(self: SuperType)(implicit ctx: Context): Type = self.thistpe def SuperType_supertpe(self: SuperType)(implicit ctx: Context): Type = self.supertpe type Refinement = Types.RefinedType + def isRefinement(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] = tpe match { + case tpe: Types.RefinedType => Some(tpe) + case _ => None + } + def Refinement_parent(self: Refinement)(implicit ctx: Context): Type = self.parent def Refinement_name(self: Refinement)(implicit ctx: Context): String = self.refinedName.toString def Refinement_info(self: Refinement)(implicit ctx: Context): TypeOrBounds = self.refinedInfo type AppliedType = Types.AppliedType + def isAppliedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] = tpe match { + case tpe: Types.AppliedType => Some(tpe) + case _ => None + } + def AppliedType_tycon(self: AppliedType)(implicit ctx: Context): Type = self.tycon def AppliedType_args(self: AppliedType)(implicit ctx: Context): List[TypeOrBounds] = self.args type AnnotatedType = Types.AnnotatedType + def isAnnotatedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] = tpe match { + case tpe: Types.AnnotatedType => Some(tpe) + case _ => None + } + def AnnotatedType_underlying(self: AnnotatedType)(implicit ctx: Context): Type = self.underlying.stripTypeVar def AnnotatedType_annot(self: AnnotatedType)(implicit ctx: Context): Term = self.annot.tree type AndType = Types.AndType + def isAndType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] = tpe match { + case tpe: Types.AndType => Some(tpe) + case _ => None + } + def AndType_left(self: AndType)(implicit ctx: Context): Type = self.tp1.stripTypeVar def AndType_right(self: AndType)(implicit ctx: Context): Type = self.tp2.stripTypeVar type OrType = Types.OrType + def isOrType(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] = tpe match { + case tpe: Types.OrType => Some(tpe) + case _ => None + } + def OrType_left(self: OrType)(implicit ctx: Context): Type = self.tp1.stripTypeVar def OrType_right(self: OrType)(implicit ctx: Context): Type = self.tp2.stripTypeVar type MatchType = Types.MatchType + def isMatchType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] = tpe match { + case tpe: Types.MatchType => Some(tpe) + case _ => None + } + def MatchType_bound(self: MatchType)(implicit ctx: Context): Type = self.bound def MatchType_scrutinee(self: MatchType)(implicit ctx: Context): Type = self.scrutinee def MatchType_cases(self: MatchType)(implicit ctx: Context): List[Type] = self.cases type ByNameType = Types.ExprType + def isByNameType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] = tpe match { + case tpe: Types.ExprType => Some(tpe) + case _ => None + } + def ByNameType_underlying(self: ByNameType)(implicit ctx: Context): Type = self.resType.stripTypeVar type ParamRef = Types.ParamRef + def isParamRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] = tpe match { + case tpe: Types.TypeParamRef => Some(tpe) + case tpe: Types.TermParamRef => Some(tpe) + case _ => None + } + def ParamRef_binder(self: ParamRef)(implicit ctx: Context): LambdaType[TypeOrBounds] = self.binder.asInstanceOf[LambdaType[TypeOrBounds]] // Cast to tpd def ParamRef_paramNum(self: ParamRef)(implicit ctx: Context): Int = self.paramNum type ThisType = Types.ThisType - def ThisType_underlying(self: ThisType)(implicit ctx: Context): Type = self.underlying + def isThisType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] = tpe match { + case tpe: Types.ThisType => Some(tpe) + case _ => None + } + + def ThisType_tref(self: ThisType)(implicit ctx: Context): Type = self.tref type RecursiveThis = Types.RecThis + def isRecursiveThis(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] = tpe match { + case tpe: Types.RecThis => Some(tpe) + case _ => None + } + def RecursiveThis_binder(self: RecursiveThis)(implicit ctx: Context): RecursiveType = self.binder type RecursiveType = Types.RecType + def isRecursiveType(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = tpe match { + case tpe: Types.RecType => Some(tpe) + case _ => None + } + def RecursiveType_underlying(self: RecursiveType)(implicit ctx: Context): Type = self.underlying.stripTypeVar type LambdaType[ParamInfo] = Types.LambdaType { type PInfo = ParamInfo } type MethodType = Types.MethodType + def isMethodType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] = tpe match { + case tpe: Types.MethodType => Some(tpe) + case _ => None + } + def MethodType_isErased(self: MethodType): Boolean = self.isErasedMethod def MethodType_isImplicit(self: MethodType): Boolean = self.isImplicitMethod def MethodType_paramNames(self: MethodType)(implicit ctx: Context): List[String] = self.paramNames.map(_.toString) @@ -1077,12 +1203,22 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type PolyType = Types.PolyType + def isPolyType(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] = tpe match { + case tpe: Types.PolyType => Some(tpe) + case _ => None + } + def PolyType_paramNames(self: PolyType)(implicit ctx: Context): List[String] = self.paramNames.map(_.toString) def PolyType_paramBounds(self: PolyType)(implicit ctx: Context): List[TypeBounds] = self.paramInfos def PolyType_resType(self: PolyType)(implicit ctx: Context): Type = self.resType type TypeLambda = Types.TypeLambda + def isTypeLambda(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] = tpe match { + case tpe: Types.TypeLambda => Some(tpe) + case _ => None + } + def TypeLambda_paramNames(self: TypeLambda)(implicit ctx: Context): List[String] = self.paramNames.map(_.toString) def TypeLambda_paramBounds(self: TypeLambda)(implicit ctx: Context): List[TypeBounds] = self.paramInfos def TypeLambda_resType(self: TypeLambda)(implicit ctx: Context): Type = self.resType diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index 8c7092dece15..61b97872b8c9 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -7,8 +7,7 @@ class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition) extends scala.tasty.Reflection with CoreImpl with CommentOpsImpl - with SymbolOpsImpl - with TypeOrBoundsOpsImpl { + with SymbolOpsImpl { val kernel: KernelImpl = new KernelImpl(ctx, pos) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala deleted file mode 100644 index a6a0c19fac55..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala +++ /dev/null @@ -1,343 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -import dotty.tools.dotc.core.{Contexts, Names, Types} -import dotty.tools.dotc.core.Decorators._ - -trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreImpl { - - // ===== Types ==================================================== - - object IsType extends IsTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { - case x: TypeBounds => None - case x if x == Types.NoPrefix => None - case _ => Some(x) - } - } - - object Type extends TypeModule { - - object IsConstantType extends IsConstantTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] = tpe match { - case tpe: Types.ConstantType => Some(tpe) - case _ => None - } - } - - object ConstantType extends ConstantTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[Constant] = x match { - case Types.ConstantType(value) => Some(value) - case _ => None - } - } - - object IsSymRef extends IsSymRefModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] = tpe match { - case tp: Types.NamedType => - tp.designator match { - case sym: Symbol => Some(tp) - case _ => None - } - case _ => None - } - } - - object SymRef extends SymRefModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] = x match { - case tp: Types.NamedType => - tp.designator match { - case sym: Symbol => Some((sym, tp.prefix)) - case _ => None - } - case _ => None - } - } - - object IsTermRef extends IsTermRefModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] = tpe match { - case tpe: Types.NamedType => - tpe.designator match { - case name: Names.TermName => Some(tpe) - case _ => None - } - case _ => None - } - } - - object TermRef extends TermRefModule { - def apply(qual: TypeOrBounds, name: String)(implicit ctx: Context): TermRef = - Types.TermRef(qual, name.toTermName) - - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] = x match { - case tp: Types.NamedType => - tp.designator match { - case name: Names.TermName => Some(name.toString, tp.prefix) - case _ => None - } - case _ => None - } - } - - object IsTypeRef extends IsTypeRefModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] = tpe match { - case tpe: Types.NamedType => - tpe.designator match { - case name: Names.TypeName => Some(tpe) - case _ => None - } - case _ => None - } - } - - object TypeRef extends TypeRefModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] = x match { - case tp: Types.NamedType => - tp.designator match { - case name: Names.TypeName => Some(name.toString, tp.prefix) - case _ => None - } - case _ => None - } - } - - object IsSuperType extends IsSuperTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] = tpe match { - case tpe: Types.SuperType => Some(tpe) - case _ => None - } - } - - object SuperType extends SuperTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = x match { - case Types.SuperType(thistpe, supertpe) => Some(thistpe, supertpe) - case _ => None - } - } - - object IsRefinement extends IsRefinementModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] = tpe match { - case tpe: Types.RefinedType => Some(tpe) - case _ => None - } - } - - - object Refinement extends RefinementModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] = x match { - case Types.RefinedType(parent, name, info) => Some(parent, name.toString, info) - case _ => None - } - } - - object IsAppliedType extends IsAppliedTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] = tpe match { - case tpe: Types.AppliedType => Some(tpe) - case _ => None - } - } - - object AppliedType extends AppliedTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] = x match { - case Types.AppliedType(tycon, args) => Some((tycon.stripTypeVar, args.map(_.stripTypeVar))) - case _ => None - } - } - - object IsAnnotatedType extends IsAnnotatedTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] = tpe match { - case tpe: Types.AnnotatedType => Some(tpe) - case _ => None - } - } - - object AnnotatedType extends AnnotatedTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Term)] = x match { - case Types.AnnotatedType(underlying, annot) => Some((underlying.stripTypeVar, annot.tree)) - case _ => None - } - } - - object IsAndType extends IsAndTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] = tpe match { - case tpe: Types.AndType => Some(tpe) - case _ => None - } - } - - object AndType extends AndTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = x match { - case Types.AndType(left, right) => Some(left.stripTypeVar, right.stripTypeVar) - case _ => None - } - } - - object IsOrType extends IsOrTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] = tpe match { - case tpe: Types.OrType => Some(tpe) - case _ => None - } - } - - object OrType extends OrTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = x match { - case Types.OrType(left, right) => Some(left.stripTypeVar, right.stripTypeVar) - case _ => None - } - } - - object IsMatchType extends IsMatchTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] = tpe match { - case tpe: Types.MatchType => Some(tpe) - case _ => None - } - } - - object MatchType extends MatchTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type, List[Type])] = x match { - case Types.MatchType(bound, scrutinee, cases) => Some((bound, scrutinee, cases)) - case _ => None - } - } - - object IsByNameType extends IsByNameTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] = tpe match { - case tpe: Types.ExprType => Some(tpe) - case _ => None - } - } - - object ByNameType extends ByNameTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { - case Types.ExprType(resType) => Some(resType.stripTypeVar) - case _ => None - } - } - - object IsParamRef extends IsParamRefModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] = tpe match { - case tpe: Types.TypeParamRef => Some(tpe) - case tpe: Types.TermParamRef => Some(tpe) - case _ => None - } - } - - object ParamRef extends ParamRefModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] = x match { - case Types.TypeParamRef(binder, idx) => - Some(( - binder.asInstanceOf[LambdaType[TypeOrBounds]], // Cast to tpd - idx)) - case Types.TermParamRef(binder, idx) => Some((binder, idx)) - case _ => None - } - } - - object IsThisType extends IsThisTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] = tpe match { - case tpe: Types.ThisType => Some(tpe) - case _ => None - } - } - - object ThisType extends ThisTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { - case Types.ThisType(tp) => Some(tp) - case _ => None - } - } - - object IsRecursiveThis extends IsRecursiveThisModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] = tpe match { - case tpe: Types.RecThis => Some(tpe) - case _ => None - } - } - - object RecursiveThis extends RecursiveThisModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = x match { - case Types.RecThis(binder) => Some(binder) - case _ => None - } - } - - object IsRecursiveType extends IsRecursiveTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = tpe match { - case tpe: Types.RecType => Some(tpe) - case _ => None - } - } - - object RecursiveType extends RecursiveTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { - case tp: Types.RecType => Some(tp.underlying.stripTypeVar) - case _ => None - } - } - - object IsMethodType extends IsMethodTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] = tpe match { - case tpe: Types.MethodType => Some(tpe) - case _ => None - } - } - - object MethodType extends MethodTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[Type], Type)] = x match { - case x: MethodType => Some(x.paramNames.map(_.toString), x.paramInfos, x.resType) - case _ => None - } - } - - object IsPolyType extends IsPolyTypeModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] = tpe match { - case tpe: Types.PolyType => Some(tpe) - case _ => None - } - } - - object PolyType extends PolyTypeModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] = x match { - case x: PolyType => Some(x.paramNames.map(_.toString), x.paramInfos, x.resType) - case _ => None - } - } - - object IsTypeLambda extends IsTypeLambdaModule { - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] = tpe match { - case tpe: Types.TypeLambda => Some(tpe) - case _ => None - } - } - - object TypeLambda extends TypeLambdaModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] = x match { - case x: TypeLambda => Some(x.paramNames.map(_.toString), x.paramInfos, x.resType) - case _ => None - } - } - - } - - // ----- TypeBounds ------------------------------------------------ - - object IsTypeBounds extends IsTypeBoundsModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] = x match { - case x: TypeBounds => Some(x) - case _ => None - } - } - - object TypeBounds extends TypeBoundsModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = x match { - case x: TypeBounds => Some(x.lo, x.hi) - case _ => None - } - } - - // ----- NoPrefix -------------------------------------------------- - - object NoPrefix extends NoPrefixModule { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Boolean = x == Types.NoPrefix - } - -} diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 96f93e32cf90..63608c1b711c 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -775,15 +775,21 @@ trait Kernel { /** NoPrefix for a type selection */ type NoPrefix <: TypeOrBounds + def isNoPrefix(x: TypeOrBounds)(implicit ctx: Context): Option[NoPrefix] + /** Type bounds */ type TypeBounds <: TypeOrBounds + def isTypeBounds(x: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] + def TypeBounds_low(self: TypeBounds)(implicit ctx: Context): Type def TypeBounds_hi(self: TypeBounds)(implicit ctx: Context): Type /** A type */ type Type <: TypeOrBounds + def isType(x: TypeOrBounds)(implicit ctx: Context): Option[Type] + def `Type_=:=`(self: Type)(that: Type)(implicit ctx: Context): Boolean def `Type_<:<`(self: Type)(that: Type)(implicit ctx: Context): Boolean @@ -809,33 +815,51 @@ trait Kernel { /** A singleton type representing a known constant value */ type ConstantType <: Type - def ConstantType_value(self: ConstantType)(implicit ctx: Context): Any + def isConstantType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] + + def ConstantType_constant(self: ConstantType)(implicit ctx: Context): Constant /** Type of a reference to a symbol */ type SymRef <: Type + def isSymRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] + + // TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef + def isSymRef_unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] + def SymRef_qualifier(self: SymRef)(implicit ctx: Context): TypeOrBounds /** Type of a reference to a term */ type TermRef <: Type + def isTermRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] + + def TermRef_name(self: TermRef)(implicit ctx: Context): String def TermRef_qualifier(self: TermRef)(implicit ctx: Context): TypeOrBounds + def TermRef_apply(qual: TypeOrBounds, name: String)(implicit ctx: Context): TermRef + /** Type of a reference to a type */ type TypeRef <: Type + def isTypeRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] + def TypeRef_name(self: TypeRef)(implicit ctx: Context): String def TypeRef_qualifier(self: TypeRef)(implicit ctx: Context): TypeOrBounds /** Type of a `super` refernce */ type SuperType <: Type + def isSuperType(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] + def SuperType_thistpe(self: SuperType)(implicit ctx: Context): Type def SuperType_supertpe(self: SuperType)(implicit ctx: Context): Type /** A type with a type refinement `T { type U }` */ type Refinement <: Type + def isRefinement(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] + def Refinement_parent(self: Refinement)(implicit ctx: Context): Type def Refinement_name(self: Refinement)(implicit ctx: Context): String def Refinement_info(self: Refinement)(implicit ctx: Context): TypeOrBounds @@ -843,30 +867,40 @@ trait Kernel { /** A higher kinded type applied to some types `T[U]` */ type AppliedType <: Type + def isAppliedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] + def AppliedType_tycon(self: AppliedType)(implicit ctx: Context): Type def AppliedType_args(self: AppliedType)(implicit ctx: Context): List[TypeOrBounds] /** A type with an anottation `T @foo` */ type AnnotatedType <: Type + def isAnnotatedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] + def AnnotatedType_underlying(self: AnnotatedType)(implicit ctx: Context): Type def AnnotatedType_annot(self: AnnotatedType)(implicit ctx: Context): Term /** Intersection type `T & U` */ type AndType <: Type + def isAndType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] + def AndType_left(self: AndType)(implicit ctx: Context): Type def AndType_right(self: AndType)(implicit ctx: Context): Type /** Union type `T | U` */ type OrType <: Type + def isOrType(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] + def OrType_left(self: OrType)(implicit ctx: Context): Type def OrType_right(self: OrType)(implicit ctx: Context): Type /** Type match `T match { case U => ... }` */ type MatchType <: Type + def isMatchType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] + def MatchType_bound(self: MatchType)(implicit ctx: Context): Type def MatchType_scrutinee(self: MatchType)(implicit ctx: Context): Type def MatchType_cases(self: MatchType)(implicit ctx: Context): List[Type] @@ -874,27 +908,37 @@ trait Kernel { /** Type of a by by name parameter */ type ByNameType <: Type + def isByNameType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] + def ByNameType_underlying(self: ByNameType)(implicit ctx: Context): Type /** Type of a parameter reference */ type ParamRef <: Type + def isParamRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] + def ParamRef_binder(self: ParamRef)(implicit ctx: Context): LambdaType[TypeOrBounds] def ParamRef_paramNum(self: ParamRef)(implicit ctx: Context): Int /** Type of `this` */ type ThisType <: Type - def ThisType_underlying(self: ThisType)(implicit ctx: Context): Type + def isThisType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] + + def ThisType_tref(self: ThisType)(implicit ctx: Context): Type /** A type that is recursively defined `this` */ type RecursiveThis <: Type + def isRecursiveThis(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] + def RecursiveThis_binder(self: RecursiveThis)(implicit ctx: Context): RecursiveType /** A type that is recursively defined */ type RecursiveType <: Type + def isRecursiveType(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] + def RecursiveType_underlying(self: RecursiveType)(implicit ctx: Context): Type // TODO can we add the bound back without an cake? @@ -905,6 +949,8 @@ trait Kernel { /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ type MethodType <: LambdaType[Type] + def isMethodType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] + def MethodType_isErased(self: MethodType): Boolean def MethodType_isImplicit(self: MethodType): Boolean def MethodType_paramNames(self: MethodType)(implicit ctx: Context): List[String] @@ -914,6 +960,8 @@ trait Kernel { /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ type PolyType <: LambdaType[TypeBounds] + def isPolyType(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] + def PolyType_paramNames(self: PolyType)(implicit ctx: Context): List[String] def PolyType_paramBounds(self: PolyType)(implicit ctx: Context): List[TypeBounds] def PolyType_resType(self: PolyType)(implicit ctx: Context): Type @@ -921,6 +969,8 @@ trait Kernel { /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ type TypeLambda <: LambdaType[TypeBounds] + def isTypeLambda(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] + def TypeLambda_paramNames(self: TypeLambda)(implicit ctx: Context): List[String] def TypeLambda_paramBounds(self: TypeLambda)(implicit ctx: Context): List[TypeBounds] def TypeLambda_resType(self: TypeLambda)(implicit ctx: Context): Type diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala index b3754374045e..97cdf53126a6 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala @@ -17,228 +17,229 @@ trait TypeOrBoundsOps extends Core { def memberType(member: Symbol)(implicit ctx: Context): Type = kernel.Type_memberType(self)(member) } - val IsType: IsTypeModule - abstract class IsTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] + object IsType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = + kernel.isType(typeOrBounds) } - val Type: TypeModule - abstract class TypeModule { + object Type { - val IsConstantType: IsConstantTypeModule - abstract class IsConstantTypeModule { + object IsConstantType { /** Matches any ConstantType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] = + kernel.isConstantType(tpe) } - val ConstantType: ConstantTypeModule - abstract class ConstantTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Constant] + object ConstantType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Constant] = + kernel.isConstantType(typeOrBounds).map(_.constant) } - val IsSymRef: IsSymRefModule - abstract class IsSymRefModule { + object IsSymRef { /** Matches any SymRef and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] = + kernel.isSymRef(tpe) } - val SymRef: SymRefModule - abstract class SymRefModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] + object SymRef { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] = + kernel.isSymRef_unapply(typeOrBounds) } - val IsTermRef: IsTermRefModule - abstract class IsTermRefModule { + object IsTermRef { /** Matches any TermRef and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] = + kernel.isTermRef(tpe) } - val TermRef: TermRefModule - abstract class TermRefModule { - def apply(qual: TypeOrBounds, name: String)(implicit ctx: Context): TermRef - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] + object TermRef { + // TODO should qual be a Type? + def apply(qual: TypeOrBounds, name: String)(implicit ctx: Context): TermRef = + kernel.TermRef_apply(qual, name) + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] = + kernel.isTermRef(typeOrBounds).map(x => (x.name, x.qualifier)) } - val IsTypeRef: IsTypeRefModule - abstract class IsTypeRefModule { + object IsTypeRef { /** Matches any TypeRef and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] = + kernel.isTypeRef(tpe) } - val TypeRef: TypeRefModule - abstract class TypeRefModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] + object TypeRef { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] = + kernel.isTypeRef(typeOrBounds).map(x => (x.name, x.qualifier)) } - val IsSuperType: IsSuperTypeModule - abstract class IsSuperTypeModule { + object IsSuperType { /** Matches any SuperType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] = + kernel.isSuperType(tpe) } - val SuperType: SuperTypeModule - abstract class SuperTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] + object SuperType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = + kernel.isSuperType(typeOrBounds).map(x => (x.thistpe, x.supertpe)) } - val IsRefinement: IsRefinementModule - abstract class IsRefinementModule { + object IsRefinement { /** Matches any Refinement and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] = + kernel.isRefinement(tpe) } - val Refinement: RefinementModule - abstract class RefinementModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] + object Refinement { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] = + kernel.isRefinement(typeOrBounds).map(x => (x.parent, x.name, x.info)) } - val IsAppliedType: IsAppliedTypeModule - abstract class IsAppliedTypeModule { + object IsAppliedType { /** Matches any AppliedType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] = + kernel.isAppliedType(tpe) } - val AppliedType: AppliedTypeModule - abstract class AppliedTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] + object AppliedType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] = + kernel.isAppliedType(typeOrBounds).map(x => (x.tycon, x.args)) } - val IsAnnotatedType: IsAnnotatedTypeModule - abstract class IsAnnotatedTypeModule { + object IsAnnotatedType { /** Matches any AnnotatedType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] = + kernel.isAnnotatedType(tpe) } - val AnnotatedType: AnnotatedTypeModule - abstract class AnnotatedTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Term)] + object AnnotatedType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Term)] = + kernel.isAnnotatedType(typeOrBounds).map(x => (x.underlying, x.annot)) } - val IsAndType: IsAndTypeModule - abstract class IsAndTypeModule { + object IsAndType { /** Matches any AndType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] = + kernel.isAndType(tpe) } - val AndType: AndTypeModule - abstract class AndTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] + object AndType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = + kernel.isAndType(typeOrBounds).map(x => (x.left, x.right)) } - val IsOrType: IsOrTypeModule - abstract class IsOrTypeModule { + object IsOrType { /** Matches any OrType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] = + kernel.isOrType(tpe) } - val OrType: OrTypeModule - abstract class OrTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] + object OrType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = + kernel.isOrType(typeOrBounds).map(x => (x.left, x.right)) } - val IsMatchType: IsMatchTypeModule - abstract class IsMatchTypeModule { + object IsMatchType { /** Matches any MatchType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] = + kernel.isMatchType(tpe) } - val MatchType: MatchTypeModule - abstract class MatchTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type, List[Type])] + object MatchType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type, List[Type])] = + kernel.isMatchType(typeOrBounds).map(x => (x.bound, x.scrutinee, x.cases)) } - val IsByNameType: IsByNameTypeModule - abstract class IsByNameTypeModule { + object IsByNameType { /** Matches any ByNameType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] = + kernel.isByNameType(tpe) } - val ByNameType: ByNameTypeModule - abstract class ByNameTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] + object ByNameType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = + kernel.isByNameType(typeOrBounds).map(_.underlying) } - val IsParamRef: IsParamRefModule - abstract class IsParamRefModule { + object IsParamRef { /** Matches any ParamRef and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] = + kernel.isParamRef(tpe) } - val ParamRef: ParamRefModule - abstract class ParamRefModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] + object ParamRef { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] = + kernel.isParamRef(typeOrBounds).map(x => (x.binder, x.paramNum)) } - val IsThisType: IsThisTypeModule - abstract class IsThisTypeModule { + object IsThisType { /** Matches any ThisType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] = + kernel.isThisType(tpe) } - val ThisType: ThisTypeModule - abstract class ThisTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] + object ThisType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = + kernel.isThisType(typeOrBounds).map(_.tref) } - val IsRecursiveThis: IsRecursiveThisModule - abstract class IsRecursiveThisModule { + object IsRecursiveThis { /** Matches any RecursiveThis and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] = + kernel.isRecursiveThis(tpe) } - val RecursiveThis: RecursiveThisModule - abstract class RecursiveThisModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] + object RecursiveThis { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = + kernel.isRecursiveThis(typeOrBounds).map(_.binder) } - val IsRecursiveType: IsRecursiveTypeModule - abstract class IsRecursiveTypeModule { + object IsRecursiveType { /** Matches any RecursiveType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = + kernel.isRecursiveType(tpe) } - val RecursiveType: RecursiveTypeModule - abstract class RecursiveTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] + object RecursiveType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = + kernel.isRecursiveType(typeOrBounds).map(_.underlying) } - val IsMethodType: IsMethodTypeModule - abstract class IsMethodTypeModule { + object IsMethodType { /** Matches any MethodType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] = + kernel.isMethodType(tpe) } - val MethodType: MethodTypeModule - abstract class MethodTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[Type], Type)] + object MethodType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[Type], Type)] = + kernel.isMethodType(typeOrBounds).map(x => (x.paramNames, x.paramTypes, x.resType)) } - val IsPolyType: IsPolyTypeModule - abstract class IsPolyTypeModule { + object IsPolyType { /** Matches any PolyType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] = + kernel.isPolyType(tpe) } - val PolyType: PolyTypeModule - abstract class PolyTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] + object PolyType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] = + kernel.isPolyType(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) } - val IsTypeLambda: IsTypeLambdaModule - abstract class IsTypeLambdaModule { + object IsTypeLambda { /** Matches any TypeLambda and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] = + kernel.isTypeLambda(tpe) } - val TypeLambda: TypeLambdaModule - abstract class TypeLambdaModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] + object TypeLambda { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] = + kernel.isTypeLambda(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) } } implicit class Type_ConstantTypeAPI(self: ConstantType) { - def value(implicit ctx: Context): Any = kernel.ConstantType_value(self) + def constant(implicit ctx: Context): Constant = kernel.ConstantType_constant(self) } implicit class Type_SymRefAPI(self: SymRef) { @@ -246,6 +247,7 @@ trait TypeOrBoundsOps extends Core { } implicit class Type_TermRefAPI(self: TermRef) { + def name(implicit ctx: Context): String = kernel.TermRef_name(self) def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ = kernel.TermRef_qualifier(self) } @@ -301,7 +303,7 @@ trait TypeOrBoundsOps extends Core { } implicit class Type_ThisTypeAPI(self: ThisType) { - def underlying(implicit ctx: Context): Type = kernel.ThisType_underlying(self) + def tref(implicit ctx: Context): Type = kernel.ThisType_tref(self) } implicit class Type_RecursiveThisAPI(self: RecursiveThis) { @@ -334,14 +336,14 @@ trait TypeOrBoundsOps extends Core { // ----- TypeBounds ----------------------------------------------- - val IsTypeBounds: IsTypeBoundsModule - abstract class IsTypeBoundsModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] + object IsTypeBounds { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] = + kernel.isTypeBounds(typeOrBounds) } - val TypeBounds: TypeBoundsModule - abstract class TypeBoundsModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] + object TypeBounds { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = + kernel.isTypeBounds(typeOrBounds).map(x => (x.low, x.hi)) } implicit class TypeBoundsAPI(self: TypeBounds) { @@ -351,9 +353,9 @@ trait TypeOrBoundsOps extends Core { // ----- NoPrefix ------------------------------------------------- - val NoPrefix: NoPrefixModule - abstract class NoPrefixModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Boolean + object NoPrefix { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Boolean = + kernel.isNoPrefix(typeOrBounds).isDefined } } From 392d7bdee40493df80e013c0e99bf56abd6bf74f Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 5 Mar 2019 11:12:38 +0100 Subject: [PATCH 11/17] Implement SymbolOps members in kernel --- .../tools/dotc/tastyreflect/KernelImpl.scala | 102 +++++++++++++++- .../dotc/tastyreflect/ReflectionImpl.scala | 3 +- .../dotc/tastyreflect/SymbolOpsImpl.scala | 114 ------------------ library/src/scala/tasty/reflect/Kernel.scala | 59 +++++++++ .../src/scala/tasty/reflect/SymbolOps.scala | 108 ++++++++++------- 5 files changed, 220 insertions(+), 166 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index c2d10b50357d..ded666b64c5b 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -3,7 +3,7 @@ package tastyreflect import dotty.tools.dotc.ast.{Trees, tpd, untpd} import dotty.tools.dotc.ast.tpd.TreeOps -import dotty.tools.dotc.core.{Constants, NameKinds, Names, Types} +import dotty.tools.dotc.core._ import dotty.tools.dotc.core.Flags._ import dotty.tools.dotc.core.StdNames.nme import dotty.tools.dotc.core.quoted.PickledQuotes @@ -1425,31 +1425,125 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def isPackageSymbol(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] = if (symbol.is(core.Flags.Package)) Some(symbol) else None + def PackageSymbol_tree(self: PackageSymbol)(implicit ctx: Context): PackageDef = + FromSymbol.packageDefFromSym(self) + type ClassSymbol = core.Symbols.ClassSymbol def isClassSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] = if (symbol.isClass) Some(symbol.asClass) else None + def ClassSymbol_tree(self: ClassSymbol)(implicit ctx: Context): ClassDef = + FromSymbol.classDef(self) + + def ClassSymbol_fields(self: Symbol)(implicit ctx: Context): List[Symbol] = + self.unforcedDecls.filter(isField) + + def ClassSymbol_field(self: Symbol)(name: String)(implicit ctx: Context): Option[Symbol] = { + val sym = self.unforcedDecls.find(sym => sym.name == name.toTermName) + if (sym.exists && isField(sym)) Some(sym) else None + } + + def ClassSymbol_classMethod(self: Symbol)(name: String)(implicit ctx: Context): List[DefSymbol] = { + self.typeRef.decls.iterator.collect { + case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm + }.toList + } + + def ClassSymbol_classMethods(self: Symbol)(implicit ctx: Context): List[DefSymbol] = { + self.typeRef.decls.iterator.collect { + case sym if isMethod(sym) => sym.asTerm + }.toList + } + + def ClassSymbol_method(self: Symbol)(name: String)(implicit ctx: Context): List[DefSymbol] = { + self.typeRef.allMembers.iterator.map(_.symbol).collect { + case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm + }.toList + } + + def ClassSymbol_methods(self: Symbol)(implicit ctx: Context): List[DefSymbol] = { + self.typeRef.allMembers.iterator.map(_.symbol).collect { + case sym if isMethod(sym) => sym.asTerm + }.toList + } + + private def isMethod(sym: Symbol)(implicit ctx: Context): Boolean = + sym.isTerm && sym.is(Flags.Method) && !sym.isConstructor + + def ClassSymbol_caseFields(self: Symbol)(implicit ctx: Context): List[ValSymbol] = { + if (!self.isClass) Nil + else self.asClass.paramAccessors.collect { + case sym if sym.is(Flags.CaseAccessor) => sym.asTerm + } + } + + def ClassSymbol_companionClass(self: Symbol)(implicit ctx: Context): Option[ClassSymbol] = { + val sym = self.companionModule.companionClass + if (sym.exists) Some(sym.asClass) else None + } + + def ClassSymbol_companionModule(self: Symbol)(implicit ctx: Context): Option[ValSymbol] = { + val sym = self.companionModule + if (sym.exists) Some(sym.asTerm) else None + } + + def ClassSymbol_moduleClass(self: Symbol)(implicit ctx: Context): Option[Symbol] = { + val sym = self.moduleClass + if (sym.exists) Some(sym.asTerm) else None + } + + private def isField(sym: Symbol)(implicit ctx: Context): Boolean = sym.isTerm && !sym.is(Flags.Method) + + def ClassSymbol_of(fullName: String)(implicit ctx: Context): ClassSymbol = ctx.requiredClass(fullName) + type TypeSymbol = core.Symbols.TypeSymbol def isTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] = if (symbol.isType) Some(symbol.asType) else None + def TypeSymbol_tree(self: TypeSymbol)(implicit ctx: Context): TypeDef = + FromSymbol.typeDefFromSym(self) + def TypeSymbol_isTypeParam(self: TypeSymbol)(implicit ctx: Context): Boolean = + self.isTypeParam + type DefSymbol = core.Symbols.TermSymbol def isDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] = if (symbol.isTerm && symbol.is(core.Flags.Method)) Some(symbol.asTerm) else None - type BindSymbol = core.Symbols.TermSymbol + def DefSymbol_tree(self: DefSymbol)(implicit ctx: Context): DefDef = + FromSymbol.defDefFromSym(self) - def isBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] = - if (symbol.isTerm && symbol.is(core.Flags.Case)) Some(symbol.asTerm) else None + def DefSymbol_signature(self: DefSymbol)(implicit ctx: Context): Signature = + self.signature type ValSymbol = core.Symbols.TermSymbol def isValSymbol(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] = if (symbol.isTerm && !symbol.is(core.Flags.Method) && !symbol.is(core.Flags.Case)) Some(symbol.asTerm) else None + def ValSymbol_tree(self: ValSymbol)(implicit ctx: Context): ValDef = + FromSymbol.valDefFromSym(self) + + def ValSymbol_moduleClass(self: ValSymbol)(implicit ctx: Context): Option[ClassSymbol] = { + val sym = self.moduleClass + if (sym.exists) Some(sym.asClass) else None + } + + def ValSymbol_companionClass(self: ValSymbol)(implicit ctx: Context): Option[ClassSymbol] = { + val sym = self.companionClass + if (sym.exists) Some(sym.asClass) else None + } + + type BindSymbol = core.Symbols.TermSymbol + + def isBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] = + if (symbol.isTerm && symbol.is(core.Flags.Case)) Some(symbol.asTerm) else None + + def BindSymbol_tree(self: BindSymbol)(implicit ctx: Context): Bind = + FromSymbol.bindFromSym(self) + type NoSymbol = core.Symbols.NoSymbol.type def isNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean = symbol ne core.Symbols.NoSymbol diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index 61b97872b8c9..64e2723ab271 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -6,8 +6,7 @@ import dotty.tools.dotc.util.{SourcePosition, Spans} class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition) extends scala.tasty.Reflection with CoreImpl - with CommentOpsImpl - with SymbolOpsImpl { + with CommentOpsImpl { val kernel: KernelImpl = new KernelImpl(ctx, pos) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala deleted file mode 100644 index 8f85a27aef4e..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala +++ /dev/null @@ -1,114 +0,0 @@ -package dotty.tools.dotc -package tastyreflect - -import dotty.tools.dotc.core.Flags -import dotty.tools.dotc.core.Symbols._ -import dotty.tools.dotc.core.Decorators._ - -trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl { - - def PackageSymbolDeco(symbol: PackageSymbol): PackageSymbolAPI = new PackageSymbolAPI { - def tree(implicit ctx: Context): PackageDef = FromSymbol.packageDefFromSym(symbol) - } - - def TypeSymbolDeco(symbol: TypeSymbol): TypeSymbolAPI = new TypeSymbolAPI { - def tree(implicit ctx: Context): TypeDef = FromSymbol.typeDefFromSym(symbol) - - def isTypeParam(implicit ctx: Context): Boolean = symbol.isTypeParam - } - - object ClassSymbol extends ClassSymbolModule { - def of(fullName: String)(implicit ctx: Context): ClassSymbol = ctx.requiredClass(fullName) - } - - def ClassSymbolDeco(symbol: ClassSymbol): ClassSymbolAPI = new ClassSymbolAPI { - def tree(implicit ctx: Context): ClassDef = FromSymbol.classDef(symbol) - - def fields(implicit ctx: Context): List[Symbol] = { - symbol.unforcedDecls.filter(isField) - } - - def field(name: String)(implicit ctx: Context): Option[Symbol] = { - val sym = symbol.unforcedDecls.find(sym => sym.name == name.toTermName) - if (sym.exists && isField(sym)) Some(sym) else None - } - - def classMethod(name: String)(implicit ctx: Context): List[DefSymbol] = { - symbol.typeRef.decls.iterator.collect { - case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm - }.toList - } - - def classMethods(implicit ctx: Context): List[DefSymbol] = { - symbol.typeRef.decls.iterator.collect { - case sym if isMethod(sym) => sym.asTerm - }.toList - } - - def method(name: String)(implicit ctx: Context): List[DefSymbol] = { - symbol.typeRef.allMembers.iterator.map(_.symbol).collect { - case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm - }.toList - } - - def methods(implicit ctx: Context): List[DefSymbol] = { - symbol.typeRef.allMembers.iterator.map(_.symbol).collect { - case sym if isMethod(sym) => sym.asTerm - }.toList - } - - private def isMethod(sym: Symbol)(implicit ctx: Context): Boolean = - sym.isTerm && sym.is(Flags.Method) && !sym.isConstructor - - def caseFields(implicit ctx: Context): List[ValSymbol] = { - if (!symbol.isClass) Nil - else symbol.asClass.paramAccessors.collect { - case sym if sym.is(Flags.CaseAccessor) => sym.asTerm - } - } - - def companionClass(implicit ctx: Context): Option[ClassSymbol] = { - val sym = symbol.companionModule.companionClass - if (sym.exists) Some(sym.asClass) else None - } - - def companionModule(implicit ctx: Context): Option[ValSymbol] = { - val sym = symbol.companionModule - if (sym.exists) Some(sym.asTerm) else None - } - - def moduleClass(implicit ctx: Context): Option[Symbol] = { - val sym = symbol.moduleClass - if (sym.exists) Some(sym.asTerm) else None - } - - private def isField(sym: Symbol)(implicit ctx: Context): Boolean = sym.isTerm && !sym.is(Flags.Method) - } - - def DefSymbolDeco(symbol: DefSymbol): DefSymbolAPI = new DefSymbolAPI { - def tree(implicit ctx: Context): DefDef = FromSymbol.defDefFromSym(symbol) - - def signature(implicit ctx: Context): Signature = { - symbol.signature - } - } - - def ValSymbolDeco(symbol: ValSymbol): ValSymbolAPI = new ValSymbolAPI { - def tree(implicit ctx: Context): ValDef = FromSymbol.valDefFromSym(symbol) - - def moduleClass(implicit ctx: Context): Option[ClassSymbol] = { - val sym = symbol.moduleClass - if (sym.exists) Some(sym.asClass) else None - } - - def companionClass(implicit ctx: Context): Option[ClassSymbol] = { - val sym = symbol.companionClass - if (sym.exists) Some(sym.asClass) else None - } - } - - def BindSymbolDeco(symbol: BindSymbol): BindSymbolAPI = new BindSymbolAPI { - def tree(implicit ctx: Context): Bind = FromSymbol.bindFromSym(symbol) - } - -} diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 63608c1b711c..7ea348655fea 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -1168,31 +1168,90 @@ trait Kernel { def isPackageSymbol(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] + def PackageSymbol_tree(self: PackageSymbol)(implicit ctx: Context): PackageDef + /** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */ type ClassSymbol <: Symbol def isClassSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] + /** ClassDef tree of this defintion */ + def ClassSymbol_tree(self: ClassSymbol)(implicit ctx: Context): ClassDef + + /** Fields directly declared in the class */ + def ClassSymbol_fields(self: Symbol)(implicit ctx: Context): List[Symbol] + + /** Field with the given name directly declared in the class */ + def ClassSymbol_field(self: Symbol)(name: String)(implicit ctx: Context): Option[Symbol] + + /** Get non-private named methods defined directly inside the class */ + def ClassSymbol_classMethod(self: Symbol)(name: String)(implicit ctx: Context): List[DefSymbol] + + /** Get all non-private methods defined directly inside the class, exluding constructors */ + def ClassSymbol_classMethods(self: Symbol)(implicit ctx: Context): List[DefSymbol] + + /** Get named non-private methods declared or inherited */ + def ClassSymbol_method(self: Symbol)(name: String)(implicit ctx: Context): List[DefSymbol] + + /** Get all non-private methods declared or inherited */ + def ClassSymbol_methods(self: Symbol)(implicit ctx: Context): List[DefSymbol] + + /** Fields of a case class type -- only the ones declared in primary constructor */ + def ClassSymbol_caseFields(self: Symbol)(implicit ctx: Context): List[ValSymbol] + + /** The class symbol of the companion module class */ + def ClassSymbol_companionClass(self: Symbol)(implicit ctx: Context): Option[ClassSymbol] + + /** The symbol of the companion module */ + def ClassSymbol_companionModule(self: Symbol)(implicit ctx: Context): Option[ValSymbol] + + /** The symbol of the class of the companion module */ + def ClassSymbol_moduleClass(self: Symbol)(implicit ctx: Context): Option[Symbol] + + def ClassSymbol_of(fullName: String)(implicit ctx: Context): ClassSymbol + /** Symbol of a type (parameter or member) definition. */ type TypeSymbol <: Symbol def isTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] + def TypeSymbol_isTypeParam(self: TypeSymbol)(implicit ctx: Context): Boolean + + /** TypeDef tree of this definition */ + def TypeSymbol_tree(self: TypeSymbol)(implicit ctx: Context): TypeDef + /** Symbol representing a method definition. */ type DefSymbol <: Symbol def isDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] + /** DefDef tree of this defintion */ + def DefSymbol_tree(self: DefSymbol)(implicit ctx: Context): DefDef + + /** Signature of this defintion */ + def DefSymbol_signature(self: DefSymbol)(implicit ctx: Context): Signature + /** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */ type ValSymbol <: Symbol def isValSymbol(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] + /** ValDef tree of this defintion */ + def ValSymbol_tree(self: ValSymbol)(implicit ctx: Context): ValDef + + /** The class symbol of the companion module class */ + def ValSymbol_moduleClass(self: ValSymbol)(implicit ctx: Context): Option[ClassSymbol] + + def ValSymbol_companionClass(self: ValSymbol)(implicit ctx: Context): Option[ClassSymbol] + /** Symbol representing a bind definition. */ type BindSymbol <: Symbol def isBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] + /** Bind pattern of this definition */ + def BindSymbol_tree(self: BindSymbol)(implicit ctx: Context): Bind + /** No symbol available. */ type NoSymbol <: Symbol diff --git a/library/src/scala/tasty/reflect/SymbolOps.scala b/library/src/scala/tasty/reflect/SymbolOps.scala index 3fa57a4dcc0c..e71d8878ec99 100644 --- a/library/src/scala/tasty/reflect/SymbolOps.scala +++ b/library/src/scala/tasty/reflect/SymbolOps.scala @@ -6,24 +6,24 @@ trait SymbolOps extends Core { // Symbol - implicit class SymbolDeco(self: Symbol) { + implicit class SymbolAPI(self: Symbol) { - /** Owner of this symbol. The owner is the symbol in which this symbol is defined. */ + /** Owner of this symbol. The owner is the symbol in which this symbol is defined */ def owner(implicit ctx: Context): Symbol = kernel.Symbol_owner(self) /** Flags of this symbol */ def flags(implicit ctx: Context): Flags = kernel.Symbol_flags(self) - /** This symbol is private within the resulting type. */ + /** This symbol is private within the resulting type */ def privateWithin(implicit ctx: Context): Option[Type] = kernel.Symbol_privateWithin(self) - /** This symbol is protected within the resulting type. */ + /** This symbol is protected within the resulting type */ def protectedWithin(implicit ctx: Context): Option[Type] = kernel.Symbol_protectedWithin(self) - /** The name of this symbol. */ + /** The name of this symbol */ def name(implicit ctx: Context): String = kernel.Symbol_name(self) - /** The full name of this symbol up to the root package. */ + /** The full name of this symbol up to the root package */ def fullName(implicit ctx: Context): String = kernel.Symbol_fullName(self) /** The position of this symbol */ @@ -91,10 +91,10 @@ trait SymbolOps extends Core { kernel.isPackageSymbol(symbol) } - trait PackageSymbolAPI { - def tree(implicit ctx: Context): PackageDef + implicit class PackageSymbolAPI(self: PackageSymbol) { + def tree(implicit ctx: Context): PackageDef = + kernel.PackageSymbol_tree(self) } - implicit def PackageSymbolDeco(symbol: PackageSymbol): PackageSymbolAPI // ClassSymbol @@ -103,46 +103,57 @@ trait SymbolOps extends Core { kernel.isClassSymbol(symbol) } - val ClassSymbol: ClassSymbolModule - abstract class ClassSymbolModule { + object ClassSymbol { /** The ClassSymbol of a global class definition */ - def of(fullName: String)(implicit ctx: Context): ClassSymbol + def of(fullName: String)(implicit ctx: Context): ClassSymbol = + kernel.ClassSymbol_of(fullName) } - trait ClassSymbolAPI { - /** ClassDef tree of this defintion. */ - def tree(implicit ctx: Context): ClassDef + implicit class ClassSymbolAPI(self: ClassSymbol) { + /** ClassDef tree of this defintion */ + def tree(implicit ctx: Context): ClassDef = + kernel.ClassSymbol_tree(self) /** Fields directly declared in the class */ - def fields(implicit ctx: Context): List[Symbol] + def fields(implicit ctx: Context): List[Symbol] = + kernel.ClassSymbol_fields(self) /** Field with the given name directly declared in the class */ - def field(name: String)(implicit ctx: Context): Option[Symbol] + def field(name: String)(implicit ctx: Context): Option[Symbol] = + kernel.ClassSymbol_field(self)(name) /** Get non-private named methods defined directly inside the class */ - def classMethod(name: String)(implicit ctx: Context): List[DefSymbol] + def classMethod(name: String)(implicit ctx: Context): List[DefSymbol] = + kernel.ClassSymbol_classMethod(self)(name) /** Get all non-private methods defined directly inside the class, exluding constructors */ - def classMethods(implicit ctx: Context): List[DefSymbol] + def classMethods(implicit ctx: Context): List[DefSymbol] = + kernel.ClassSymbol_classMethods(self) /** Get named non-private methods declared or inherited */ - def method(name: String)(implicit ctx: Context): List[DefSymbol] + def method(name: String)(implicit ctx: Context): List[DefSymbol] = + kernel.ClassSymbol_method(self)(name) /** Get all non-private methods declared or inherited */ - def methods(implicit ctx: Context): List[DefSymbol] + def methods(implicit ctx: Context): List[DefSymbol] = + kernel.ClassSymbol_methods(self) /** Fields of a case class type -- only the ones declared in primary constructor */ - def caseFields(implicit ctx: Context): List[ValSymbol] + def caseFields(implicit ctx: Context): List[ValSymbol] = + kernel.ClassSymbol_caseFields(self) /** The class symbol of the companion module class */ - def companionClass(implicit ctx: Context): Option[ClassSymbol] + def companionClass(implicit ctx: Context): Option[ClassSymbol] = + kernel.ClassSymbol_companionClass(self) /** The symbol of the companion module */ - def companionModule(implicit ctx: Context): Option[ValSymbol] + def companionModule(implicit ctx: Context): Option[ValSymbol] = + kernel.ClassSymbol_companionModule(self) - def moduleClass(implicit ctx: Context): Option[Symbol] + /** The symbol of the class of the companion module */ + def moduleClass(implicit ctx: Context): Option[Symbol] = + kernel.ClassSymbol_moduleClass(self) } - implicit def ClassSymbolDeco(symbol: ClassSymbol): ClassSymbolAPI // TypeSymbol @@ -151,13 +162,14 @@ trait SymbolOps extends Core { kernel.isTypeSymbol(symbol) } - trait TypeSymbolAPI { - /** TypeDef tree of this definition. */ - def tree(implicit ctx: Context): TypeDef + implicit class TypeSymbolAPI(self: TypeSymbol) { + /** TypeDef tree of this definition */ + def tree(implicit ctx: Context): TypeDef = + kernel.TypeSymbol_tree(self) - def isTypeParam(implicit ctx: Context): Boolean + def isTypeParam(implicit ctx: Context): Boolean = + kernel.TypeSymbol_isTypeParam(self) } - implicit def TypeSymbolDeco(symbol: TypeSymbol): TypeSymbolAPI // DefSymbol @@ -166,13 +178,15 @@ trait SymbolOps extends Core { kernel.isDefSymbol(symbol) } - trait DefSymbolAPI { - /** DefDef tree of this defintion. */ - def tree(implicit ctx: Context): DefDef + implicit class DefSymbolAPI(self: DefSymbol) { + /** DefDef tree of this defintion */ + def tree(implicit ctx: Context): DefDef = + kernel.DefSymbol_tree(self) - def signature(implicit ctx: Context): Signature + /** Signature of this defintion */ + def signature(implicit ctx: Context): Signature = + kernel.DefSymbol_signature(self) } - implicit def DefSymbolDeco(symbol: DefSymbol): DefSymbolAPI // ValSymbol @@ -181,16 +195,18 @@ trait SymbolOps extends Core { kernel.isValSymbol(symbol) } - trait ValSymbolAPI { - /** ValDef tree of this defintion. */ - def tree(implicit ctx: Context): ValDef + implicit class ValSymbolAPI(self: ValSymbol) { + /** ValDef tree of this defintion */ + def tree(implicit ctx: Context): ValDef = + kernel.ValSymbol_tree(self) /** The class symbol of the companion module class */ - def moduleClass(implicit ctx: Context): Option[ClassSymbol] + def moduleClass(implicit ctx: Context): Option[ClassSymbol] = + kernel.ValSymbol_moduleClass(self) - def companionClass(implicit ctx: Context): Option[ClassSymbol] + def companionClass(implicit ctx: Context): Option[ClassSymbol] = + kernel.ValSymbol_companionClass(self) } - implicit def ValSymbolDeco(symbol: ValSymbol): ValSymbolAPI // BindSymbol @@ -199,11 +215,11 @@ trait SymbolOps extends Core { kernel.isBindSymbol(symbol) } - trait BindSymbolAPI { - /** Bind pattern of this definition. */ - def tree(implicit ctx: Context): Bind + implicit class BindSymbolAPI(self: BindSymbol) { + /** Bind pattern of this definition */ + def tree(implicit ctx: Context): Bind = + kernel.BindSymbol_tree(self) } - implicit def BindSymbolDeco(symbol: BindSymbol): BindSymbolAPI // NoSymbol From 6b2a67681239340c10007e0e096da6d0b77886d7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 5 Mar 2019 11:14:21 +0100 Subject: [PATCH 12/17] Add missing spaces --- .../src/scala/tasty/reflect/FlagsOps.scala | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/library/src/scala/tasty/reflect/FlagsOps.scala b/library/src/scala/tasty/reflect/FlagsOps.scala index 914ff42f31da..4b5422fbc4af 100644 --- a/library/src/scala/tasty/reflect/FlagsOps.scala +++ b/library/src/scala/tasty/reflect/FlagsOps.scala @@ -21,103 +21,103 @@ trait FlagsOps extends Core { def Private: Flags = kernel.Flags_Private /** Is this symbol `protected` */ - def Protected:Flags = kernel.Flags_Protected + def Protected: Flags = kernel.Flags_Protected /** Is this symbol `abstract` */ - def Abstract:Flags = kernel.Flags_Abstract + def Abstract: Flags = kernel.Flags_Abstract /** Is this symbol `final` */ - def Final:Flags = kernel.Flags_Final + def Final: Flags = kernel.Flags_Final /** Is this symbol `sealed` */ - def Sealed:Flags = kernel.Flags_Sealed + def Sealed: Flags = kernel.Flags_Sealed /** Is this symbol `case` */ - def Case:Flags = kernel.Flags_Case + def Case: Flags = kernel.Flags_Case /** Is this symbol `implicit` */ - def Implicit:Flags = kernel.Flags_Implicit + def Implicit: Flags = kernel.Flags_Implicit /** Is this symbol `erased` */ - def Erased:Flags = kernel.Flags_Erased + def Erased: Flags = kernel.Flags_Erased /** Is this symbol `lazy` */ - def Lazy:Flags = kernel.Flags_Lazy + def Lazy: Flags = kernel.Flags_Lazy /** Is this symbol `override` */ - def Override:Flags = kernel.Flags_Override + def Override: Flags = kernel.Flags_Override /** Is this symbol `inline` */ - def Inline:Flags = kernel.Flags_Inline + def Inline: Flags = kernel.Flags_Inline /** Is this symbol markes as a macro. An inline method containing toplevel splices */ - def Macro:Flags = kernel.Flags_Macro + def Macro: Flags = kernel.Flags_Macro /** Is this symbol marked as static. Mapped to static Java member */ - def Static:Flags = kernel.Flags_Static + def Static: Flags = kernel.Flags_Static /** Is this symbol defined in a Java class */ - def JavaDefined:Flags = kernel.Flags_JavaDefined + def JavaDefined: Flags = kernel.Flags_JavaDefined /** Is this symbol an object or its class (used for a ValDef or a ClassDef extends Modifier respectively) */ - def Object:Flags = kernel.Flags_Object + def Object: Flags = kernel.Flags_Object /** Is this symbol a trait */ - def Trait:Flags = kernel.Flags_Trait + def Trait: Flags = kernel.Flags_Trait /** Is this symbol local? Used in conjunction with private/private[Type] to mean private[this] extends Modifier proctected[this] */ - def Local:Flags = kernel.Flags_Local + def Local: Flags = kernel.Flags_Local /** Was this symbol generated by Scala compiler */ - def Synthetic:Flags = kernel.Flags_Synthetic + def Synthetic: Flags = kernel.Flags_Synthetic /** Is this symbol to be tagged Java Synthetic */ - def Artifact:Flags = kernel.Flags_Artifact + def Artifact: Flags = kernel.Flags_Artifact /** Is this symbol a `var` (when used on a ValDef) */ - def Mutable:Flags = kernel.Flags_Mutable + def Mutable: Flags = kernel.Flags_Mutable /** Is this symbol a getter or a setter */ - def FieldAccessor:Flags = kernel.Flags_FieldAccessor + def FieldAccessor: Flags = kernel.Flags_FieldAccessor /** Is this symbol a getter for case class parameter */ - def CaseAcessor:Flags = kernel.Flags_CaseAcessor + def CaseAcessor: Flags = kernel.Flags_CaseAcessor /** Is this symbol a type parameter marked as covariant `+` */ - def Covariant:Flags = kernel.Flags_Covariant + def Covariant: Flags = kernel.Flags_Covariant /** Is this symbol a type parameter marked as contravariant `-` */ - def Contravariant:Flags = kernel.Flags_Contravariant + def Contravariant: Flags = kernel.Flags_Contravariant /** Was this symbol imported from Scala2.x */ - def Scala2X:Flags = kernel.Flags_Scala2X + def Scala2X: Flags = kernel.Flags_Scala2X /** Is this symbol a method with default parameters */ - def DefaultParameterized:Flags = kernel.Flags_DefaultParameterized + def DefaultParameterized: Flags = kernel.Flags_DefaultParameterized /** Is this symbol member that is assumed to be stable and realizable */ - def StableRealizable:Flags = kernel.Flags_StableRealizable + def StableRealizable: Flags = kernel.Flags_StableRealizable /** Is this symbol a parameter */ - def Param:Flags = kernel.Flags_Param + def Param: Flags = kernel.Flags_Param /** Is this symbol a parameter accessor */ - def ParamAccessor:Flags = kernel.Flags_ParamAccessor + def ParamAccessor: Flags = kernel.Flags_ParamAccessor /** Is this symbol an enum */ - def Enum:Flags = kernel.Flags_Enum + def Enum: Flags = kernel.Flags_Enum /** Is this symbol a module class */ - def ModuleClass:Flags = kernel.Flags_ModuleClass + def ModuleClass: Flags = kernel.Flags_ModuleClass /** Is this symbol labeled private[this] */ - def PrivateLocal:Flags = kernel.Flags_PrivateLocal + def PrivateLocal: Flags = kernel.Flags_PrivateLocal /** Is this symbol a package */ - def Package:Flags = kernel.Flags_Package + def Package: Flags = kernel.Flags_Package /** Is this symbol an implementation class of a Scala2 trait */ - def ImplClass:Flags = kernel.Flags_ImplClass + def ImplClass: Flags = kernel.Flags_ImplClass } } From 5c09ad8545f72de82b3df35e7a0eaff5f165c285 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 5 Mar 2019 11:50:01 +0100 Subject: [PATCH 13/17] Simplify ReflectionImpl --- .../dotc/tastyreflect/ReflectionImpl.scala | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index 64e2723ab271..e496ed2e01c5 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -3,21 +3,14 @@ package dotty.tools.dotc.tastyreflect import dotty.tools.dotc.core._ import dotty.tools.dotc.util.{SourcePosition, Spans} -class ReflectionImpl private (ctx: Contexts.Context, pos: SourcePosition) - extends scala.tasty.Reflection - with CoreImpl - with CommentOpsImpl { - - val kernel: KernelImpl = new KernelImpl(ctx, pos) - -} - object ReflectionImpl { - def apply(rootContext: Contexts.Context): ReflectionImpl = + def apply(rootContext: Contexts.Context): scala.tasty.Reflection { val kernel: KernelImpl } = apply(rootContext, SourcePosition(rootContext.source, Spans.NoSpan)) - def apply(rootContext: Contexts.Context, rootPosition: SourcePosition): ReflectionImpl = - new ReflectionImpl(rootContext, rootPosition) + def apply(rootContext: Contexts.Context, rootPosition: SourcePosition): scala.tasty.Reflection { val kernel: KernelImpl } = { + class ReflectionImpl(val kernel: KernelImpl) extends scala.tasty.Reflection with CoreImpl with CommentOpsImpl + new ReflectionImpl(new KernelImpl(rootContext, rootPosition)) + } } From 0730052122a898d9a1a926be9c30dc18405f887b Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 5 Mar 2019 16:55:41 +0100 Subject: [PATCH 14/17] Rename kernel isXYZ to matchXYZ --- .../tools/dotc/tastyreflect/KernelImpl.scala | 202 +++++++++--------- .../src/scala/tasty/reflect/ConstantOps.scala | 26 +-- .../tasty/reflect/ImportSelectorOps.scala | 6 +- library/src/scala/tasty/reflect/Kernel.scala | 200 ++++++++--------- .../src/scala/tasty/reflect/PatternOps.scala | 20 +- .../src/scala/tasty/reflect/SymbolOps.scala | 14 +- library/src/scala/tasty/reflect/TreeOps.scala | 120 +++++------ .../scala/tasty/reflect/TypeOrBoundsOps.scala | 84 ++++---- .../tasty/reflect/TypeOrBoundsTreeOps.scala | 64 +++--- 9 files changed, 368 insertions(+), 368 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index ded666b64c5b..113477f6d099 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -50,7 +50,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type PackageClause = tpd.PackageDef - def isPackageClause(tree: Tree)(implicit ctx: Context): Option[PackageClause] = tree match { + def matchPackageClause(tree: Tree)(implicit ctx: Context): Option[PackageClause] = tree match { case x: tpd.PackageDef => Some(x) case _ => None } @@ -66,14 +66,14 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Statement = tpd.Tree - def isStatement(tree: Tree)(implicit ctx: Context): Option[Statement] = tree match { + def matchStatement(tree: Tree)(implicit ctx: Context): Option[Statement] = tree match { case tree if tree.isTerm => Some(tree) - case _ => isDefinition(tree) + case _ => matchDefinition(tree) } type Import = tpd.Import - override def isImport(tree: Tree)(implicit ctx: Context): Option[Import] = tree match { + def matchImport(tree: Tree)(implicit ctx: Context): Option[Import] = tree match { case tree: tpd.Import => Some(tree) case _ => None } @@ -90,7 +90,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Definition = tpd.Tree - def isDefinition(tree: Tree)(implicit ctx: Context): Option[Definition] = tree match { + def matchDefinition(tree: Tree)(implicit ctx: Context): Option[Definition] = tree match { case tree: tpd.MemberDef => Some(tree) case tree: PackageDefinition => Some(tree) case _ => None @@ -103,7 +103,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type PackageDef = PackageDefinition - def isPackageDef(tree: Tree)(implicit ctx: Context): Option[PackageDef] = tree match { + def matchPackageDef(tree: Tree)(implicit ctx: Context): Option[PackageDef] = tree match { case x: PackageDefinition => Some(x) case _ => None } @@ -119,7 +119,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ClassDef = tpd.TypeDef - def isClassDef(tree: Tree)(implicit ctx: Context): Option[ClassDef] = tree match { + def matchClassDef(tree: Tree)(implicit ctx: Context): Option[ClassDef] = tree match { case x: tpd.TypeDef if x.isClassDef => Some(x) case _ => None } @@ -139,7 +139,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeDef = tpd.TypeDef - def isTypeDef(tree: Tree)(implicit ctx: Context): Option[TypeDef] = tree match { + def matchTypeDef(tree: Tree)(implicit ctx: Context): Option[TypeDef] = tree match { case x: tpd.TypeDef if !x.symbol.isClass => Some(x) case _ => None } @@ -153,7 +153,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type DefDef = tpd.DefDef - def isDefDef(tree: Tree)(implicit ctx: Context): Option[DefDef] = tree match { + def matchDefDef(tree: Tree)(implicit ctx: Context): Option[DefDef] = tree match { case x: tpd.DefDef => Some(x) case _ => None } @@ -172,7 +172,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ValDef = tpd.ValDef - def isValDef(tree: Tree)(implicit ctx: Context): Option[ValDef] = tree match { + def matchValDef(tree: Tree)(implicit ctx: Context): Option[ValDef] = tree match { case x: tpd.ValDef => Some(x) case _ => None } @@ -189,11 +189,11 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term = tpd.Tree - def isTerm(tree: Tree)(implicit ctx: Context): Option[Term] = + def matchTerm(tree: Tree)(implicit ctx: Context): Option[Term] = if (tree.isTerm) Some(tree) else None // TODO move to Kernel and use isTerm directly with a cast - def isTermNotTypeTree(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[Term] = + def matchTermNotTypeTree(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[Term] = if (termOrTypeTree.isTerm) Some(termOrTypeTree) else None def Term_pos(self: Term)(implicit ctx: Context): Position = self.sourcePos @@ -208,7 +208,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Ident = tpd.Ident - def isTerm_Ident(x: Term)(implicit ctx: Context): Option[Term_Ident] = x match { + def matchTerm_Ident(x: Term)(implicit ctx: Context): Option[Term_Ident] = x match { case x: tpd.Ident if x.isTerm => Some(x) case _ => None } @@ -223,7 +223,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Select = tpd.Select - def isTerm_Select(x: Term)(implicit ctx: Context): Option[Term_Select] = x match { + def matchTerm_Select(x: Term)(implicit ctx: Context): Option[Term_Select] = x match { case x: tpd.Select if x.isTerm => Some(x) case _ => None } @@ -249,7 +249,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Literal = tpd.Literal - def isTerm_Literal(x: Term)(implicit ctx: Context): Option[Term_Literal] = x match { + def matchTerm_Literal(x: Term)(implicit ctx: Context): Option[Term_Literal] = x match { case x: tpd.Literal => Some(x) case _ => None } @@ -264,7 +264,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_This = tpd.This - def isTerm_This(x: Term)(implicit ctx: Context): Option[Term_This] = x match { + def matchTerm_This(x: Term)(implicit ctx: Context): Option[Term_This] = x match { case x: tpd.This => Some(x) case _ => None } @@ -279,7 +279,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_New = tpd.New - def isTerm_New(x: Term)(implicit ctx: Context): Option[Term_New] = x match { + def matchTerm_New(x: Term)(implicit ctx: Context): Option[Term_New] = x match { case x: tpd.New => Some(x) case _ => None } @@ -293,7 +293,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_NamedArg = tpd.NamedArg - def isTerm_NamedArg(x: Term)(implicit ctx: Context): Option[Term_NamedArg] = x match { + def matchTerm_NamedArg(x: Term)(implicit ctx: Context): Option[Term_NamedArg] = x match { case x: tpd.NamedArg if x.name.isInstanceOf[core.Names.TermName] => Some(x) // TODO: Now, the name should alwas be a term name case _ => None } @@ -309,7 +309,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Apply = tpd.Apply - def isTerm_Apply(x: Term)(implicit ctx: Context): Option[Term_Apply] = x match { + def matchTerm_Apply(x: Term)(implicit ctx: Context): Option[Term_Apply] = x match { case x: tpd.Apply => Some(x) case _ => None } @@ -326,7 +326,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_TypeApply = tpd.TypeApply - def isTerm_TypeApply(x: Term)(implicit ctx: Context): Option[Term_TypeApply] = x match { + def matchTerm_TypeApply(x: Term)(implicit ctx: Context): Option[Term_TypeApply] = x match { case x: tpd.TypeApply => Some(x) case _ => None } @@ -342,7 +342,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Super = tpd.Super - def isTerm_Super(x: Term)(implicit ctx: Context): Option[Term_Super] = x match { + def matchTerm_Super(x: Term)(implicit ctx: Context): Option[Term_Super] = x match { case x: tpd.Super => Some(x) case _ => None } @@ -358,7 +358,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Typed = tpd.Typed - def isTerm_Typed(x: Term)(implicit ctx: Context): Option[Term_Typed] = x match { + def matchTerm_Typed(x: Term)(implicit ctx: Context): Option[Term_Typed] = x match { case x: tpd.Typed => Some(x) case _ => None } @@ -374,7 +374,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Assign = tpd.Assign - def isTerm_Assign(x: Term)(implicit ctx: Context): Option[Term_Assign] = x match { + def matchTerm_Assign(x: Term)(implicit ctx: Context): Option[Term_Assign] = x match { case x: tpd.Assign => Some(x) case _ => None } @@ -390,7 +390,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Block = tpd.Block - def isTerm_Block(x: Term)(implicit ctx: Context): Option[Term_Block] = normalizedLoops(x) match { + def matchTerm_Block(x: Term)(implicit ctx: Context): Option[Term_Block] = normalizedLoops(x) match { case x: tpd.Block => Some(x) case _ => None } @@ -435,7 +435,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Inlined = tpd.Inlined - def isTerm_Inlined(x: Term)(implicit ctx: Context): Option[Term_Inlined] = x match { + def matchTerm_Inlined(x: Term)(implicit ctx: Context): Option[Term_Inlined] = x match { case x: tpd.Inlined => Some(x) case _ => None } @@ -452,7 +452,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Lambda = tpd.Closure - def isTerm_Lambda(x: Term)(implicit ctx: Context): Option[Term_Lambda] = x match { + def matchTerm_Lambda(x: Term)(implicit ctx: Context): Option[Term_Lambda] = x match { case x: tpd.Closure => Some(x) case _ => None } @@ -468,7 +468,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_If = tpd.If - def isTerm_If(x: Term)(implicit ctx: Context): Option[Term_If] = x match { + def matchTerm_If(x: Term)(implicit ctx: Context): Option[Term_If] = x match { case x: tpd.If => Some(x) case _ => None } @@ -485,7 +485,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Match = tpd.Match - def isTerm_Match(x: Term)(implicit ctx: Context): Option[Term_Match] = x match { + def matchTerm_Match(x: Term)(implicit ctx: Context): Option[Term_Match] = x match { case x: tpd.Match => Some(x) case _ => None } @@ -501,7 +501,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Try = tpd.Try - def isTerm_Try(x: Term)(implicit ctx: Context): Option[Term_Try] = x match { + def matchTerm_Try(x: Term)(implicit ctx: Context): Option[Term_Try] = x match { case x: tpd.Try => Some(x) case _ => None } @@ -518,7 +518,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Return = tpd.Return - def isTerm_Return(x: Term)(implicit ctx: Context): Option[Term_Return] = x match { + def matchTerm_Return(x: Term)(implicit ctx: Context): Option[Term_Return] = x match { case x: tpd.Return => Some(x) case _ => None } @@ -533,7 +533,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_Repeated = tpd.SeqLiteral - def isTerm_Repeated(x: Term)(implicit ctx: Context): Option[Term_Repeated] = x match { + def matchTerm_Repeated(x: Term)(implicit ctx: Context): Option[Term_Repeated] = x match { case x: tpd.SeqLiteral => Some(x) case _ => None } @@ -549,7 +549,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_SelectOuter = tpd.Select - def isTerm_SelectOuter(x: Term)(implicit ctx: Context): Option[Term_SelectOuter] = x match { + def matchTerm_SelectOuter(x: Term)(implicit ctx: Context): Option[Term_SelectOuter] = x match { case x: tpd.Select => x.name match { case NameKinds.OuterSelectName(_, _) => Some(x) @@ -573,7 +573,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Term_While = tpd.WhileDo - def isTerm_While(x: Term)(implicit ctx: Context): Option[Term_While] = x match { + def matchTerm_While(x: Term)(implicit ctx: Context): Option[Term_While] = x match { case x: tpd.WhileDo => Some(x) case _ => None } @@ -626,7 +626,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Value = tpd.Tree - def isPattern_Value(pattern: Pattern): Option[Value] = pattern match { + def matchPattern_Value(pattern: Pattern): Option[Value] = pattern match { case lit: tpd.Literal => Some(lit) case ref: tpd.RefTree if ref.isTerm => Some(ref) case ths: tpd.This => Some(ths) @@ -648,7 +648,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Bind = tpd.Bind - def isPattern_Bind(x: Pattern)(implicit ctx: Context): Option[Bind] = x match { + def matchPattern_Bind(x: Pattern)(implicit ctx: Context): Option[Bind] = x match { case x: tpd.Bind if x.name.isTermName => Some(x) case _ => None } @@ -662,7 +662,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Unapply = tpd.UnApply - def isPattern_Unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] = pattern match { + def matchPattern_Unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] = pattern match { case pattern @ Trees.UnApply(_, _, _) => Some(pattern) case Trees.Typed(pattern @ Trees.UnApply(_, _, _), _) => Some(pattern) case _ => None @@ -682,7 +682,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Alternatives = tpd.Alternative - def isPattern_Alternatives(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] = pattern match { + def matchPattern_Alternatives(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] = pattern match { case pattern: tpd.Alternative => Some(pattern) case _ => None } @@ -697,7 +697,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTest = tpd.Typed - def isPattern_TypeTest(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] = pattern match { + def matchPattern_TypeTest(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] = pattern match { case Trees.Typed(_: tpd.UnApply, _) => None case pattern: tpd.Typed => Some(pattern) case _ => None @@ -721,13 +721,13 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree = tpd.Tree - def isTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] = x match { + def matchTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] = x match { case x: tpd.TypeBoundsTree => None case _ => if (x.isType) Some(x) else None } // TODO move to Kernel and use isTypeTree directly with a cast - def isTypeTreeNotTerm(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[TypeTree] = termOrTypeTree match { + def matchTypeTreeNotTerm(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[TypeTree] = termOrTypeTree match { case _: tpd.TypeBoundsTree => None case _ => if (termOrTypeTree.isType) Some(termOrTypeTree) else None } @@ -738,7 +738,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_Inferred = tpd.TypeTree - def isTypeTree_Inferred(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Inferred] = tpt match { + def matchTypeTree_Inferred(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Inferred] = tpt match { case tpt: tpd.TypeTree if !tpt.tpe.isInstanceOf[Types.TypeBounds] => Some(tpt) case _ => None } @@ -747,7 +747,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_Ident = tpd.Ident - def isTypeTree_Ident(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Ident] = tpt match { + def matchTypeTree_Ident(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Ident] = tpt match { case tpt: tpd.Ident if tpt.isType => Some(tpt) case _ => None } @@ -759,7 +759,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_Select = tpd.Select - def isTypeTree_Select(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Select] = tpt match { + def matchTypeTree_Select(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Select] = tpt match { case tpt: tpd.Select if tpt.isType && tpt.qualifier.isTerm => Some(tpt) case _ => None } @@ -776,7 +776,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_Projection = tpd.Select - def isTypeTree_Projection(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Projection] = tpt match { + def matchTypeTree_Projection(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Projection] = tpt match { case tpt: tpd.Select if tpt.isType && tpt.qualifier.isType => Some(tpt) case _ => None } @@ -789,7 +789,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_Singleton = tpd.SingletonTypeTree - def isTypeTree_Singleton(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Singleton] = tpt match { + def matchTypeTree_Singleton(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Singleton] = tpt match { case tpt: tpd.SingletonTypeTree => Some(tpt) case _ => None } @@ -804,7 +804,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_Refined = tpd.RefinedTypeTree - def isTypeTree_Refined(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Refined] = tpt match { + def matchTypeTree_Refined(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Refined] = tpt match { case tpt: tpd.RefinedTypeTree => Some(tpt) case _ => None } @@ -817,7 +817,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_Applied = tpd.AppliedTypeTree - def isTypeTree_Applied(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Applied] = tpt match { + def matchTypeTree_Applied(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Applied] = tpt match { case tpt: tpd.AppliedTypeTree => Some(tpt) case _ => None } @@ -833,7 +833,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_Annotated = tpd.Annotated - def isTypeTree_Annotated(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Annotated] = tpt match { + def matchTypeTree_Annotated(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Annotated] = tpt match { case tpt: tpd.Annotated => Some(tpt) case _ => None } @@ -849,7 +849,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_MatchType = tpd.MatchTypeTree - def isTypeTree_MatchType(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_MatchType] = tpt match { + def matchTypeTree_MatchType(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_MatchType] = tpt match { case tpt: tpd.MatchTypeTree => Some(tpt) case _ => None } @@ -866,7 +866,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_ByName = tpd.ByNameTypeTree - def isTypeTree_ByName(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_ByName] = tpt match { + def matchTypeTree_ByName(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_ByName] = tpt match { case tpt: tpd.ByNameTypeTree => Some(tpt) case _ => None } @@ -881,7 +881,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_LambdaTypeTree = tpd.LambdaTypeTree - def isTypeTree_LambdaTypeTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_LambdaTypeTree] = tpt match { + def matchTypeTree_LambdaTypeTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_LambdaTypeTree] = tpt match { case tpt: tpd.LambdaTypeTree => Some(tpt) case _ => None } @@ -897,7 +897,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_TypeBind = tpd.Bind - def isTypeTree_TypeBind(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBind] = tpt match { + def matchTypeTree_TypeBind(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBind] = tpt match { case tpt: tpd.Bind if tpt.name.isTypeName => Some(tpt) case _ => None } @@ -910,7 +910,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeTree_TypeBlock = tpd.Block - def isTypeTree_TypeBlock(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBlock] = tpt match { + def matchTypeTree_TypeBlock(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBlock] = tpt match { case tpt: tpd.Block => Some(tpt) case _ => None } @@ -926,7 +926,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeBoundsTree = tpd.TypeBoundsTree - def isTypeBoundsTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] = x match { + def matchTypeBoundsTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] = x match { case x: tpd.TypeBoundsTree => Some(x) case x @ Trees.TypeTree() => // TODO only enums generate this kind of type bounds. Is this possible without enums? If not generate tpd.TypeBoundsTree for enums instead @@ -944,7 +944,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type WildcardTypeTree = tpd.Ident - def isWildcardTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] = x match { + def matchWildcardTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] = x match { case x @ Trees.Ident(nme.WILDCARD) => Some(x) case _ => None } @@ -957,12 +957,12 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type NoPrefix = Types.NoPrefix.type - def isNoPrefix(x: TypeOrBounds)(implicit ctx: Context): Option[NoPrefix] = + def matchNoPrefix(x: TypeOrBounds)(implicit ctx: Context): Option[NoPrefix] = if (x == Types.NoPrefix) Some(Types.NoPrefix) else None type TypeBounds = Types.TypeBounds - def isTypeBounds(x: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] = x match { + def matchTypeBounds(x: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] = x match { case x: Types.TypeBounds => Some(x) case _ => None } @@ -972,7 +972,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Type = Types.Type - def isType(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { + def matchType(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { case x: TypeBounds => None case x if x == Types.NoPrefix => None case _ => Some(x) @@ -1005,7 +1005,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ConstantType = Types.ConstantType - def isConstantType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] = tpe match { + def matchConstantType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] = tpe match { case tpe: Types.ConstantType => Some(tpe) case _ => None } @@ -1014,7 +1014,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type SymRef = Types.NamedType - def isSymRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] = tpe match { + def matchSymRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] = tpe match { case tp: Types.NamedType => tp.designator match { case sym: Symbol => Some(tp) @@ -1026,7 +1026,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def SymRef_qualifier(self: SymRef)(implicit ctx: Context): TypeOrBounds = self.prefix // TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef - def isSymRef_unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] = tpe match { + def matchSymRef_unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] = tpe match { case tpe: Types.NamedType => tpe.designator match { case sym: Symbol => Some((sym, tpe.prefix)) @@ -1037,7 +1037,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TermRef = Types.NamedType - def isTermRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] = tpe match { + def matchTermRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] = tpe match { case tpe: Types.NamedType => tpe.designator match { case name: Names.TermName => Some(tpe) @@ -1054,7 +1054,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeRef = Types.NamedType - def isTypeRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] = tpe match { + def matchTypeRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] = tpe match { case tpe: Types.NamedType => tpe.designator match { case name: Names.TypeName => Some(tpe) @@ -1068,7 +1068,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type SuperType = Types.SuperType - def isSuperType(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] = tpe match { + def matchSuperType(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] = tpe match { case tpe: Types.SuperType => Some(tpe) case _ => None } @@ -1078,7 +1078,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Refinement = Types.RefinedType - def isRefinement(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] = tpe match { + def matchRefinement(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] = tpe match { case tpe: Types.RefinedType => Some(tpe) case _ => None } @@ -1089,7 +1089,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type AppliedType = Types.AppliedType - def isAppliedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] = tpe match { + def matchAppliedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] = tpe match { case tpe: Types.AppliedType => Some(tpe) case _ => None } @@ -1099,7 +1099,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type AnnotatedType = Types.AnnotatedType - def isAnnotatedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] = tpe match { + def matchAnnotatedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] = tpe match { case tpe: Types.AnnotatedType => Some(tpe) case _ => None } @@ -1109,7 +1109,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type AndType = Types.AndType - def isAndType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] = tpe match { + def matchAndType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] = tpe match { case tpe: Types.AndType => Some(tpe) case _ => None } @@ -1119,7 +1119,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type OrType = Types.OrType - def isOrType(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] = tpe match { + def matchOrType(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] = tpe match { case tpe: Types.OrType => Some(tpe) case _ => None } @@ -1129,7 +1129,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type MatchType = Types.MatchType - def isMatchType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] = tpe match { + def matchMatchType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] = tpe match { case tpe: Types.MatchType => Some(tpe) case _ => None } @@ -1140,7 +1140,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ByNameType = Types.ExprType - def isByNameType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] = tpe match { + def matchByNameType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] = tpe match { case tpe: Types.ExprType => Some(tpe) case _ => None } @@ -1149,7 +1149,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ParamRef = Types.ParamRef - def isParamRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] = tpe match { + def matchParamRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] = tpe match { case tpe: Types.TypeParamRef => Some(tpe) case tpe: Types.TermParamRef => Some(tpe) case _ => None @@ -1161,7 +1161,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ThisType = Types.ThisType - def isThisType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] = tpe match { + def matchThisType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] = tpe match { case tpe: Types.ThisType => Some(tpe) case _ => None } @@ -1170,7 +1170,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type RecursiveThis = Types.RecThis - def isRecursiveThis(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] = tpe match { + def matchRecursiveThis(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] = tpe match { case tpe: Types.RecThis => Some(tpe) case _ => None } @@ -1179,7 +1179,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type RecursiveType = Types.RecType - def isRecursiveType(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = tpe match { + def matchRecursiveType(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = tpe match { case tpe: Types.RecType => Some(tpe) case _ => None } @@ -1190,7 +1190,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type MethodType = Types.MethodType - def isMethodType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] = tpe match { + def matchMethodType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] = tpe match { case tpe: Types.MethodType => Some(tpe) case _ => None } @@ -1203,7 +1203,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type PolyType = Types.PolyType - def isPolyType(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] = tpe match { + def matchPolyType(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] = tpe match { case tpe: Types.PolyType => Some(tpe) case _ => None } @@ -1214,7 +1214,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeLambda = Types.TypeLambda - def isTypeLambda(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] = tpe match { + def matchTypeLambda(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] = tpe match { case tpe: Types.TypeLambda => Some(tpe) case _ => None } @@ -1231,7 +1231,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type SimpleSelector = untpd.Ident - def isSimpleSelector(self: ImportSelector)(implicit ctx: Context): Option[SimpleSelector] = self match { + def matchSimpleSelector(self: ImportSelector)(implicit ctx: Context): Option[SimpleSelector] = self match { case self: untpd.Ident => Some(self) case _ => None } @@ -1240,7 +1240,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type RenameSelector = untpd.Thicket - def isRenameSelector(self: ImportSelector)(implicit ctx: Context): Option[RenameSelector] = self match { + def matchRenameSelector(self: ImportSelector)(implicit ctx: Context): Option[RenameSelector] = self match { case self @ Trees.Thicket((id1: untpd.Ident) :: (id2: untpd.Ident) :: Nil) if id2.name != nme.WILDCARD => Some(self) case _ => None } @@ -1252,7 +1252,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type OmitSelector = untpd.Thicket - def isOmitSelector(self: ImportSelector)(implicit ctx: Context): Option[OmitSelector] = self match { + def matchOmitSelector(self: ImportSelector)(implicit ctx: Context): Option[OmitSelector] = self match { case self @ Trees.Thicket((id: untpd.Ident) :: Trees.Ident(nme.WILDCARD) :: Nil) => Some(self) case _ => None } @@ -1321,29 +1321,29 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Constant_value(const: Constant): Any = const.value - def isConstant_Unit(x: Constant): Boolean = x.tag == Constants.UnitTag - def isConstant_Null(x: Constant): Boolean = x.tag == Constants.NullTag - def isConstant_Boolean(x: Constant): Option[Boolean] = + def matchConstant_Unit(x: Constant): Boolean = x.tag == Constants.UnitTag + def matchConstant_Null(x: Constant): Boolean = x.tag == Constants.NullTag + def matchConstant_Boolean(x: Constant): Option[Boolean] = if (x.tag == Constants.BooleanTag) Some(x.booleanValue) else None - def isConstant_Byte(x: Constant): Option[Byte] = + def matchConstant_Byte(x: Constant): Option[Byte] = if (x.tag == Constants.ByteTag) Some(x.byteValue) else None - def isConstant_Short(x: Constant): Option[Short] = + def matchConstant_Short(x: Constant): Option[Short] = if (x.tag == Constants.ShortTag) Some(x.shortValue) else None - def isConstant_Char(x: Constant): Option[Char] = + def matchConstant_Char(x: Constant): Option[Char] = if (x.tag == Constants.CharTag) Some(x.charValue) else None - def isConstant_Int(x: Constant): Option[Int] = + def matchConstant_Int(x: Constant): Option[Int] = if (x.tag == Constants.IntTag) Some(x.intValue) else None - def isConstant_Long(x: Constant): Option[Long] = + def matchConstant_Long(x: Constant): Option[Long] = if (x.tag == Constants.LongTag) Some(x.longValue) else None - def isConstant_Float(x: Constant): Option[Float] = + def matchConstant_Float(x: Constant): Option[Float] = if (x.tag == Constants.FloatTag) Some(x.floatValue) else None - def isConstant_Double(x: Constant): Option[Double] = + def matchConstant_Double(x: Constant): Option[Double] = if (x.tag == Constants.DoubleTag) Some(x.doubleValue) else None - def isConstant_String(x: Constant): Option[String] = + def matchConstant_String(x: Constant): Option[String] = if (x.tag == Constants.StringTag) Some(x.stringValue) else None - def isConstant_ClassTag(x: Constant): Option[Type] = + def matchConstant_ClassTag(x: Constant): Option[Type] = if (x.tag == Constants.ClazzTag) Some(x.typeValue) else None - def isConstant_Symbol(x: Constant): Option[scala.Symbol] = + def matchConstant_Symbol(x: Constant): Option[scala.Symbol] = if (x.tag == Constants.ScalaSymbolTag) Some(x.scalaSymbolValue) else None def Constant_Unit_apply(): Constant = Constants.Constant(()) @@ -1422,7 +1422,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type PackageSymbol = core.Symbols.Symbol - def isPackageSymbol(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] = + def matchPackageSymbol(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] = if (symbol.is(core.Flags.Package)) Some(symbol) else None def PackageSymbol_tree(self: PackageSymbol)(implicit ctx: Context): PackageDef = @@ -1430,7 +1430,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ClassSymbol = core.Symbols.ClassSymbol - def isClassSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] = + def matchClassSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] = if (symbol.isClass) Some(symbol.asClass) else None def ClassSymbol_tree(self: ClassSymbol)(implicit ctx: Context): ClassDef = @@ -1499,7 +1499,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type TypeSymbol = core.Symbols.TypeSymbol - def isTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] = + def matchTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] = if (symbol.isType) Some(symbol.asType) else None def TypeSymbol_tree(self: TypeSymbol)(implicit ctx: Context): TypeDef = @@ -1509,7 +1509,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type DefSymbol = core.Symbols.TermSymbol - def isDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] = + def matchDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] = if (symbol.isTerm && symbol.is(core.Flags.Method)) Some(symbol.asTerm) else None def DefSymbol_tree(self: DefSymbol)(implicit ctx: Context): DefDef = @@ -1520,7 +1520,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type ValSymbol = core.Symbols.TermSymbol - def isValSymbol(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] = + def matchValSymbol(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] = if (symbol.isTerm && !symbol.is(core.Flags.Method) && !symbol.is(core.Flags.Case)) Some(symbol.asTerm) else None def ValSymbol_tree(self: ValSymbol)(implicit ctx: Context): ValDef = @@ -1538,7 +1538,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type BindSymbol = core.Symbols.TermSymbol - def isBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] = + def matchBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] = if (symbol.isTerm && symbol.is(core.Flags.Case)) Some(symbol.asTerm) else None def BindSymbol_tree(self: BindSymbol)(implicit ctx: Context): Bind = @@ -1546,7 +1546,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type NoSymbol = core.Symbols.NoSymbol.type - def isNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean = symbol ne core.Symbols.NoSymbol + def matchNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean = symbol ne core.Symbols.NoSymbol // // FLAGS diff --git a/library/src/scala/tasty/reflect/ConstantOps.scala b/library/src/scala/tasty/reflect/ConstantOps.scala index 7668a0326a70..75bd46a70287 100644 --- a/library/src/scala/tasty/reflect/ConstantOps.scala +++ b/library/src/scala/tasty/reflect/ConstantOps.scala @@ -18,7 +18,7 @@ trait ConstantOps extends Core { /** Extractor for Unit literals */ def unapply(constant: Constant): Boolean = - kernel.isConstant_Unit(constant) + kernel.matchConstant_Unit(constant) } /** Module of Null literals */ @@ -29,7 +29,7 @@ trait ConstantOps extends Core { /** Extractor for Null literals */ def unapply(constant: Constant): Boolean = - kernel.isConstant_Null(constant) + kernel.matchConstant_Null(constant) } /** Module of Boolean literals */ @@ -40,7 +40,7 @@ trait ConstantOps extends Core { /** Extractor for Boolean literals */ def unapply(constant: Constant): Option[Boolean] = - kernel.isConstant_Boolean(constant) + kernel.matchConstant_Boolean(constant) } /** Module of Byte literals */ @@ -51,7 +51,7 @@ trait ConstantOps extends Core { /** Extractor for Byte literals */ def unapply(constant: Constant): Option[Byte] = - kernel.isConstant_Byte(constant) + kernel.matchConstant_Byte(constant) } /** Module of Short literals */ @@ -62,7 +62,7 @@ trait ConstantOps extends Core { /** Extractor for Short literals */ def unapply(constant: Constant): Option[Short] = - kernel.isConstant_Short(constant) + kernel.matchConstant_Short(constant) } /** Module of Char literals */ @@ -73,7 +73,7 @@ trait ConstantOps extends Core { /** Extractor for Char literals */ def unapply(constant: Constant): Option[Char] = - kernel.isConstant_Char(constant) + kernel.matchConstant_Char(constant) } /** Module of Int literals */ @@ -84,7 +84,7 @@ trait ConstantOps extends Core { /** Extractor for Int literals */ def unapply(constant: Constant): Option[Int] = - kernel.isConstant_Int(constant) + kernel.matchConstant_Int(constant) } /** Module of Long literals */ @@ -95,7 +95,7 @@ trait ConstantOps extends Core { /** Extractor for Long literals */ def unapply(constant: Constant): Option[Long] = - kernel.isConstant_Long(constant) + kernel.matchConstant_Long(constant) } /** Module of Float literals */ @@ -106,7 +106,7 @@ trait ConstantOps extends Core { /** Extractor for Float literals */ def unapply(constant: Constant): Option[Float] = - kernel.isConstant_Float(constant) + kernel.matchConstant_Float(constant) } /** Module of Double literals */ @@ -117,7 +117,7 @@ trait ConstantOps extends Core { /** Extractor for Double literals */ def unapply(constant: Constant): Option[Double] = - kernel.isConstant_Double(constant) + kernel.matchConstant_Double(constant) } /** Module of String literals */ @@ -128,7 +128,7 @@ trait ConstantOps extends Core { /** Extractor for String literals */ def unapply(constant: Constant): Option[String] = - kernel.isConstant_String(constant) + kernel.matchConstant_String(constant) } /** Module of ClassTag literals */ @@ -139,7 +139,7 @@ trait ConstantOps extends Core { /** Extractor for ClassTag literals */ def unapply(constant: Constant): Option[Type] = - kernel.isConstant_ClassTag(constant) + kernel.matchConstant_ClassTag(constant) } /** Module of scala.Symbol literals */ @@ -150,7 +150,7 @@ trait ConstantOps extends Core { /** Extractor for scala.Symbol literals */ def unapply(constant: Constant): Option[scala.Symbol] = - kernel.isConstant_Symbol(constant) + kernel.matchConstant_Symbol(constant) } } } diff --git a/library/src/scala/tasty/reflect/ImportSelectorOps.scala b/library/src/scala/tasty/reflect/ImportSelectorOps.scala index 8007afc838fa..19e244fded4b 100644 --- a/library/src/scala/tasty/reflect/ImportSelectorOps.scala +++ b/library/src/scala/tasty/reflect/ImportSelectorOps.scala @@ -10,7 +10,7 @@ trait ImportSelectorOps extends Core { object SimpleSelector { def unapply(importSelector: ImportSelector)(implicit ctx: Context): Option[Id] = - kernel.isSimpleSelector(importSelector).map(_.selection) + kernel.matchSimpleSelector(importSelector).map(_.selection) } implicit class RenameSelectorAPI(self: RenameSelector) { @@ -23,7 +23,7 @@ trait ImportSelectorOps extends Core { object RenameSelector { def unapply(importSelector: ImportSelector)(implicit ctx: Context): Option[(Id, Id)] = - kernel.isRenameSelector(importSelector).map(x => (x.from, x.to)) + kernel.matchRenameSelector(importSelector).map(x => (x.from, x.to)) } implicit class OmitSelectorAPI(self: OmitSelector) { @@ -33,7 +33,7 @@ trait ImportSelectorOps extends Core { object OmitSelector { def unapply(importSelector: ImportSelector)(implicit ctx: Context): Option[Id] = - kernel.isOmitSelector(importSelector).map(_.omitted) + kernel.matchOmitSelector(importSelector).map(_.omitted) } } diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 7ea348655fea..fc3192a5df98 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -164,7 +164,7 @@ trait Kernel { /** Tree representing a pacakage clause in the source code */ type PackageClause <: Tree - def isPackageClause(tree: Tree)(implicit ctx: Context): Option[PackageClause] + def matchPackageClause(tree: Tree)(implicit ctx: Context): Option[PackageClause] def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Term_Ref def PackageClause_stats(self: PackageClause)(implicit ctx: Context): List[Tree] @@ -176,12 +176,12 @@ trait Kernel { /** Tree representing a statement in the source code */ type Statement <: Tree - def isStatement(tree: Tree)(implicit ctx: Context): Option[Statement] + def matchStatement(tree: Tree)(implicit ctx: Context): Option[Statement] /** Tree representing an import in the source code */ type Import <: Statement - def isImport(tree: Tree)(implicit ctx: Context): Option[Import] + def matchImport(tree: Tree)(implicit ctx: Context): Option[Import] def Import_impliedOnly(self: Import): Boolean def Import_expr(self: Import)(implicit ctx: Context): Term @@ -194,14 +194,14 @@ trait Kernel { /** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef` */ type Definition <: Statement - def isDefinition(tree: Tree)(implicit ctx: Context): Option[Definition] + def matchDefinition(tree: Tree)(implicit ctx: Context): Option[Definition] def Definition_name(self: Definition)(implicit ctx: Context): String /** Tree representing a package definition. This includes definitions in all source files */ type PackageDef <: Definition - def isPackageDef(tree: Tree)(implicit ctx: Context): Option[PackageDef] + def matchPackageDef(tree: Tree)(implicit ctx: Context): Option[PackageDef] def PackageDef_owner(self: PackageDef)(implicit ctx: Context): PackageDef def PackageDef_members(self: PackageDef)(implicit ctx: Context): List[Statement] @@ -210,7 +210,7 @@ trait Kernel { /** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */ type ClassDef <: Definition - def isClassDef(tree: Tree)(implicit ctx: Context): Option[ClassDef] + def matchClassDef(tree: Tree)(implicit ctx: Context): Option[ClassDef] def ClassDef_constructor(self: ClassDef)(implicit ctx: Context): DefDef def ClassDef_parents(self: ClassDef)(implicit ctx: Context): List[TermOrTypeTree] @@ -224,7 +224,7 @@ trait Kernel { /** Tree representing a type (paramter or member) definition in the source code */ type TypeDef <: Definition - def isTypeDef(tree: Tree)(implicit ctx: Context): Option[TypeDef] + def matchTypeDef(tree: Tree)(implicit ctx: Context): Option[TypeDef] def TypeDef_rhs(self: TypeDef)(implicit ctx: Context): TypeOrBoundsTree def TypeDef_symbol(self: TypeDef)(implicit ctx: Context): TypeSymbol @@ -235,7 +235,7 @@ trait Kernel { /** Tree representing a method definition in the source code */ type DefDef <: Definition - def isDefDef(tree: Tree)(implicit ctx: Context): Option[DefDef] + def matchDefDef(tree: Tree)(implicit ctx: Context): Option[DefDef] def DefDef_typeParams(self: DefDef)(implicit ctx: Context): List[TypeDef] def DefDef_paramss(self: DefDef)(implicit ctx: Context): List[List[ValDef]] @@ -249,7 +249,7 @@ trait Kernel { /** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */ type ValDef <: Definition - def isValDef(tree: Tree)(implicit ctx: Context): Option[ValDef] + def matchValDef(tree: Tree)(implicit ctx: Context): Option[ValDef] def ValDef_tpt(self: ValDef)(implicit ctx: Context): TypeTree def ValDef_rhs(self: ValDef)(implicit ctx: Context): Option[Term] @@ -261,9 +261,9 @@ trait Kernel { /** Tree representing an expression in the source code */ type Term <: Statement - def isTerm(tree: Tree)(implicit ctx: Context): Option[Term] + def matchTerm(tree: Tree)(implicit ctx: Context): Option[Term] - def isTermNotTypeTree(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[Term] + def matchTermNotTypeTree(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[Term] def Term_pos(self: Term)(implicit ctx: Context): Position def Term_tpe(self: Term)(implicit ctx: Context): Type @@ -278,7 +278,7 @@ trait Kernel { /** Tree representing a reference to definition with a given name */ type Term_Ident <: Term_Ref - def isTerm_Ident(tree: Tree)(implicit ctx: Context): Option[Term_Ident] + def matchTerm_Ident(tree: Tree)(implicit ctx: Context): Option[Term_Ident] def Term_Ident_name(self: Term_Ident)(implicit ctx: Context): String @@ -288,7 +288,7 @@ trait Kernel { /** Tree representing a selection of definition with a given name on a given prefix */ type Term_Select <: Term_Ref - def isTerm_Select(tree: Tree)(implicit ctx: Context): Option[Term_Select] + def matchTerm_Select(tree: Tree)(implicit ctx: Context): Option[Term_Select] def Term_Select_qualifier(self: Term_Select)(implicit ctx: Context): Term def Term_Select_name(self: Term_Select)(implicit ctx: Context): String @@ -302,7 +302,7 @@ trait Kernel { /** Tree representing a literal value in the source code */ type Term_Literal <: Term - def isTerm_Literal(tree: Tree)(implicit ctx: Context): Option[Term_Literal] + def matchTerm_Literal(tree: Tree)(implicit ctx: Context): Option[Term_Literal] def Term_Literal_constant(self: Term_Literal)(implicit ctx: Context): Constant @@ -312,7 +312,7 @@ trait Kernel { /** Tree representing `this` in the source code */ type Term_This <: Term - def isTerm_This(tree: Tree)(implicit ctx: Context): Option[Term_This] + def matchTerm_This(tree: Tree)(implicit ctx: Context): Option[Term_This] def Term_This_id(self: Term_This)(implicit ctx: Context): Option[Id] @@ -322,7 +322,7 @@ trait Kernel { /** Tree representing `new` in the source code */ type Term_New <: Term - def isTerm_New(tree: Tree)(implicit ctx: Context): Option[Term_New] + def matchTerm_New(tree: Tree)(implicit ctx: Context): Option[Term_New] def Term_New_tpt(self: Term_New)(implicit ctx: Context): TypeTree @@ -332,7 +332,7 @@ trait Kernel { /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ type Term_NamedArg <: Term - def isTerm_NamedArg(tree: Tree)(implicit ctx: Context): Option[Term_NamedArg] + def matchTerm_NamedArg(tree: Tree)(implicit ctx: Context): Option[Term_NamedArg] def Term_NamedArg_name(self: Term_NamedArg)(implicit ctx: Context): String def Term_NamedArg_value(self: Term_NamedArg)(implicit ctx: Context): Term @@ -343,7 +343,7 @@ trait Kernel { /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ type Term_Apply <: Term - def isTerm_Apply(tree: Tree)(implicit ctx: Context): Option[Term_Apply] + def matchTerm_Apply(tree: Tree)(implicit ctx: Context): Option[Term_Apply] def Term_Apply_fun(self: Term_Apply)(implicit ctx: Context): Term def Term_Apply_args(self: Term_Apply)(implicit ctx: Context): List[Term] @@ -354,7 +354,7 @@ trait Kernel { /** Tree an application of type arguments */ type Term_TypeApply <: Term - def isTerm_TypeApply(tree: Tree)(implicit ctx: Context): Option[Term_TypeApply] + def matchTerm_TypeApply(tree: Tree)(implicit ctx: Context): Option[Term_TypeApply] def Term_TypeApply_fun(self: Term_TypeApply)(implicit ctx: Context): Term def Term_TypeApply_args(self: Term_TypeApply)(implicit ctx: Context): List[TypeTree] @@ -365,7 +365,7 @@ trait Kernel { /** Tree representing `super` in the source code */ type Term_Super <: Term - def isTerm_Super(tree: Tree)(implicit ctx: Context): Option[Term_Super] + def matchTerm_Super(tree: Tree)(implicit ctx: Context): Option[Term_Super] def Term_Super_qualifier(self: Term_Super)(implicit ctx: Context): Term def Term_Super_id(self: Term_Super)(implicit ctx: Context): Option[Id] @@ -376,7 +376,7 @@ trait Kernel { /** Tree representing a type ascription `x: T` in the source code */ type Term_Typed <: Term - def isTerm_Typed(tree: Tree)(implicit ctx: Context): Option[Term_Typed] + def matchTerm_Typed(tree: Tree)(implicit ctx: Context): Option[Term_Typed] def Term_Typed_expr(self: Term_Typed)(implicit ctx: Context): Term def Term_Typed_tpt(self: Term_Typed)(implicit ctx: Context): TypeTree @@ -387,7 +387,7 @@ trait Kernel { /** Tree representing an assignment `x = y` in the source code */ type Term_Assign <: Term - def isTerm_Assign(tree: Tree)(implicit ctx: Context): Option[Term_Assign] + def matchTerm_Assign(tree: Tree)(implicit ctx: Context): Option[Term_Assign] def Term_Assign_lhs(self: Term_Assign)(implicit ctx: Context): Term def Term_Assign_rhs(self: Term_Assign)(implicit ctx: Context): Term @@ -398,7 +398,7 @@ trait Kernel { /** Tree representing a block `{ ... }` in the source code */ type Term_Block <: Term - def isTerm_Block(tree: Tree)(implicit ctx: Context): Option[Term_Block] + def matchTerm_Block(tree: Tree)(implicit ctx: Context): Option[Term_Block] def Term_Block_statements(self: Term_Block)(implicit ctx: Context): List[Statement] def Term_Block_expr(self: Term_Block)(implicit ctx: Context): Term @@ -409,7 +409,7 @@ trait Kernel { /** Tree representing a lambda `(...) => ...` in the source code */ type Term_Lambda <: Term - def isTerm_Lambda(tree: Tree)(implicit ctx: Context): Option[Term_Lambda] + def matchTerm_Lambda(tree: Tree)(implicit ctx: Context): Option[Term_Lambda] def Term_Lambda_meth(self: Term_Lambda)(implicit ctx: Context): Term def Term_Lambda_tptOpt(self: Term_Lambda)(implicit ctx: Context): Option[TypeTree] @@ -420,7 +420,7 @@ trait Kernel { /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ type Term_If <: Term - def isTerm_If(tree: Tree)(implicit ctx: Context): Option[Term_If] + def matchTerm_If(tree: Tree)(implicit ctx: Context): Option[Term_If] def Term_If_cond(self: Term_If)(implicit ctx: Context): Term def Term_If_thenp(self: Term_If)(implicit ctx: Context): Term @@ -432,7 +432,7 @@ trait Kernel { /** Tree representing a pattern match `x match { ... }` in the source code */ type Term_Match <: Term - def isTerm_Match(tree: Tree)(implicit ctx: Context): Option[Term_Match] + def matchTerm_Match(tree: Tree)(implicit ctx: Context): Option[Term_Match] def Term_Match_scrutinee(self: Term_Match)(implicit ctx: Context): Term def Term_Match_cases(self: Term_Match)(implicit ctx: Context): List[CaseDef] @@ -443,7 +443,7 @@ trait Kernel { /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ type Term_Try <: Term - def isTerm_Try(tree: Tree)(implicit ctx: Context): Option[Term_Try] + def matchTerm_Try(tree: Tree)(implicit ctx: Context): Option[Term_Try] def Term_Try_body(self: Term_Try)(implicit ctx: Context): Term def Term_Try_cases(self: Term_Try)(implicit ctx: Context): List[CaseDef] @@ -455,7 +455,7 @@ trait Kernel { /** Tree representing a `return` in the source code */ type Term_Return <: Term - def isTerm_Return(tree: Tree)(implicit ctx: Context): Option[Term_Return] + def matchTerm_Return(tree: Tree)(implicit ctx: Context): Option[Term_Return] def Term_Return_expr(self: Term_Return)(implicit ctx: Context): Term @@ -465,7 +465,7 @@ trait Kernel { /** Tree representing a variable argument list in the source code */ type Term_Repeated <: Term - def isTerm_Repeated(tree: Tree)(implicit ctx: Context): Option[Term_Repeated] + def matchTerm_Repeated(tree: Tree)(implicit ctx: Context): Option[Term_Repeated] def Term_Repeated_elems(self: Term_Repeated)(implicit ctx: Context): List[Term] def Term_Repeated_elemtpt(self: Term_Repeated)(implicit ctx: Context): TypeTree @@ -476,7 +476,7 @@ trait Kernel { /** Tree representing the scope of an inlined tree */ type Term_Inlined <: Term - def isTerm_Inlined(tree: Tree)(implicit ctx: Context): Option[Term_Inlined] + def matchTerm_Inlined(tree: Tree)(implicit ctx: Context): Option[Term_Inlined] def Term_Inlined_call(self: Term_Inlined)(implicit ctx: Context): Option[TermOrTypeTree] def Term_Inlined_bindings(self: Term_Inlined)(implicit ctx: Context): List[Definition] @@ -488,7 +488,7 @@ trait Kernel { /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ type Term_SelectOuter <: Term - def isTerm_SelectOuter(tree: Tree)(implicit ctx: Context): Option[Term_SelectOuter] + def matchTerm_SelectOuter(tree: Tree)(implicit ctx: Context): Option[Term_SelectOuter] def Term_SelectOuter_qualifier(self: Term_SelectOuter)(implicit ctx: Context): Term def Term_SelectOuter_level(self: Term_SelectOuter)(implicit ctx: Context): Int @@ -500,7 +500,7 @@ trait Kernel { /** Tree representing a while loop */ type Term_While <: Term - def isTerm_While(tree: Tree)(implicit ctx: Context): Option[Term_While] + def matchTerm_While(tree: Tree)(implicit ctx: Context): Option[Term_While] def Term_While_cond(self: Term_While)(implicit ctx: Context): Term def Term_While_body(self: Term_While)(implicit ctx: Context): Term @@ -545,7 +545,7 @@ trait Kernel { /** Pattern representing a value. This includes `1`, ```x``` and `_` */ type Value <: Pattern - def isPattern_Value(pattern: Pattern): Option[Value] + def matchPattern_Value(pattern: Pattern): Option[Value] def Pattern_Value_value(self: Value)(implicit ctx: Context): Term @@ -555,7 +555,7 @@ trait Kernel { /** Pattern representing a `_ @ _` binding. */ type Bind <: Pattern - def isPattern_Bind(x: Pattern)(implicit ctx: Context): Option[Bind] + def matchPattern_Bind(x: Pattern)(implicit ctx: Context): Option[Bind] def Pattern_Bind_name(self: Bind)(implicit ctx: Context): String @@ -566,7 +566,7 @@ trait Kernel { /** Pattern representing a `Xyz(...)` unapply. */ type Unapply <: Pattern - def isPattern_Unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] + def matchPattern_Unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] def Pattern_Unapply_fun(self: Unapply)(implicit ctx: Context): Term @@ -579,7 +579,7 @@ trait Kernel { /** Pattern representing `X | Y | ...` alternatives. */ type Alternatives <: Pattern - def isPattern_Alternatives(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] + def matchPattern_Alternatives(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] def Pattern_Alternatives_patterns(self: Alternatives)(implicit ctx: Context): List[Pattern] @@ -589,7 +589,7 @@ trait Kernel { /** Pattern representing a `x: Y` type test. */ type TypeTest <: Pattern - def isPattern_TypeTest(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] + def matchPattern_TypeTest(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] def Pattern_TypeTest_tpt(self: TypeTest)(implicit ctx: Context): TypeTree @@ -608,8 +608,8 @@ trait Kernel { /** Type tree representing a type written in the source */ type TypeTree <: TypeOrBoundsTree - def isTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] - def isTypeTreeNotTerm(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[TypeTree] + def matchTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] + def matchTypeTreeNotTerm(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context): Option[TypeTree] def TypeTree_pos(self: TypeTree)(implicit ctx: Context): Position def TypeTree_symbol(self: TypeTree)(implicit ctx: Context): Symbol @@ -618,14 +618,14 @@ trait Kernel { /** Type tree representing an inferred type */ type TypeTree_Inferred <: TypeTree - def isTypeTree_Inferred(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Inferred] + def matchTypeTree_Inferred(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Inferred] def TypeTree_Inferred_apply(tpe: Type)(implicit ctx: Context): TypeTree_Inferred /** Type tree representing a reference to definition with a given name */ type TypeTree_Ident <: TypeTree - def isTypeTree_Ident(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Ident] + def matchTypeTree_Ident(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Ident] def TypeTree_Ident_name(self: TypeTree_Ident)(implicit ctx: Context): String @@ -634,7 +634,7 @@ trait Kernel { /** Type tree representing a selection of definition with a given name on a given term prefix */ type TypeTree_Select <: TypeTree - def isTypeTree_Select(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Select] + def matchTypeTree_Select(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Select] def TypeTree_Select_qualifier(self: TypeTree_Select)(implicit ctx: Context): Term def TypeTree_Select_name(self: TypeTree_Select)(implicit ctx: Context): String @@ -645,7 +645,7 @@ trait Kernel { /** Type tree representing a selection of definition with a given name on a given type prefix */ type TypeTree_Projection <: TypeTree - def isTypeTree_Projection(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Projection] + def matchTypeTree_Projection(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Projection] def TypeTree_Projection_qualifier(self: TypeTree_Projection)(implicit ctx: Context): TypeTree def TypeTree_Projection_name(self: TypeTree_Projection)(implicit ctx: Context): String @@ -655,7 +655,7 @@ trait Kernel { /** Type tree representing a singleton type */ type TypeTree_Singleton <: TypeTree - def isTypeTree_Singleton(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Singleton] + def matchTypeTree_Singleton(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Singleton] def TypeTree_Singleton_ref(self: TypeTree_Singleton)(implicit ctx: Context): Term @@ -665,7 +665,7 @@ trait Kernel { /** Type tree representing a type refinement */ type TypeTree_Refined <: TypeTree - def isTypeTree_Refined(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Refined] + def matchTypeTree_Refined(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Refined] def TypeTree_Refined_tpt(self: TypeTree_Refined)(implicit ctx: Context): TypeTree def TypeTree_Refined_refinements(self: TypeTree_Refined)(implicit ctx: Context): List[Definition] @@ -675,7 +675,7 @@ trait Kernel { /** Type tree representing a type application */ type TypeTree_Applied <: TypeTree - def isTypeTree_Applied(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Applied] + def matchTypeTree_Applied(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Applied] def TypeTree_Applied_tpt(self: TypeTree_Applied)(implicit ctx: Context): TypeTree def TypeTree_Applied_args(self: TypeTree_Applied)(implicit ctx: Context): List[TypeOrBoundsTree] @@ -686,7 +686,7 @@ trait Kernel { /** Type tree representing an annotated type */ type TypeTree_Annotated <: TypeTree - def isTypeTree_Annotated(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Annotated] + def matchTypeTree_Annotated(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_Annotated] def TypeTree_Annotated_arg(self: TypeTree_Annotated)(implicit ctx: Context): TypeTree def TypeTree_Annotated_annotation(self: TypeTree_Annotated)(implicit ctx: Context): Term @@ -697,7 +697,7 @@ trait Kernel { /** Type tree representing a type match */ type TypeTree_MatchType <: TypeTree - def isTypeTree_MatchType(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_MatchType] + def matchTypeTree_MatchType(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_MatchType] def TypeTree_MatchType_bound(self: TypeTree_MatchType)(implicit ctx: Context): Option[TypeTree] def TypeTree_MatchType_selector(self: TypeTree_MatchType)(implicit ctx: Context): TypeTree @@ -711,7 +711,7 @@ trait Kernel { def TypeTree_ByName_result(self: TypeTree_ByName)(implicit ctx: Context): TypeTree - def isTypeTree_ByName(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_ByName] + def matchTypeTree_ByName(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_ByName] def TypeTree_ByName_apply(result: TypeTree)(implicit ctx: Context): TypeTree_ByName def TypeTree_ByName_copy(original: TypeTree_ByName)(result: TypeTree)(implicit ctx: Context): TypeTree_ByName @@ -719,7 +719,7 @@ trait Kernel { /** Type tree representing a lambda abstraction type */ type TypeTree_LambdaTypeTree <: TypeTree - def isTypeTree_LambdaTypeTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_LambdaTypeTree] + def matchTypeTree_LambdaTypeTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_LambdaTypeTree] def TypeTree_LambdaTypeTree_tparams(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): List[TypeDef] def TypeTree_LambdaTypeTree_body(self: TypeTree_LambdaTypeTree)(implicit ctx: Context): TypeOrBoundsTree @@ -730,7 +730,7 @@ trait Kernel { /** Type tree representing a type binding */ type TypeTree_TypeBind <: TypeTree - def isTypeTree_TypeBind(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBind] + def matchTypeTree_TypeBind(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBind] def TypeTree_TypeBind_name(self: TypeTree_TypeBind)(implicit ctx: Context): String def TypeTree_TypeBind_body(self: TypeTree_TypeBind)(implicit ctx: Context): TypeOrBoundsTree @@ -740,7 +740,7 @@ trait Kernel { /** Type tree within a block with aliases `{ type U1 = ... ; T[U1, U2] }` */ type TypeTree_TypeBlock <: TypeTree - def isTypeTree_TypeBlock(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBlock] + def matchTypeTree_TypeBlock(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree_TypeBlock] def TypeTree_TypeBlock_aliases(self: TypeTree_TypeBlock)(implicit ctx: Context): List[TypeDef] def TypeTree_TypeBlock_tpt(self: TypeTree_TypeBlock)(implicit ctx: Context): TypeTree @@ -751,7 +751,7 @@ trait Kernel { /** Type tree representing a type bound written in the source */ type TypeBoundsTree <: TypeOrBoundsTree - def isTypeBoundsTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] + def matchTypeBoundsTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] def TypeBoundsTree_tpe(self: TypeBoundsTree)(implicit ctx: Context): TypeBounds def TypeBoundsTree_low(self: TypeBoundsTree)(implicit ctx: Context): TypeTree @@ -763,7 +763,7 @@ trait Kernel { */ type WildcardTypeTree <: TypeOrBoundsTree - def isWildcardTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] + def matchWildcardTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] // // TYPES @@ -775,12 +775,12 @@ trait Kernel { /** NoPrefix for a type selection */ type NoPrefix <: TypeOrBounds - def isNoPrefix(x: TypeOrBounds)(implicit ctx: Context): Option[NoPrefix] + def matchNoPrefix(x: TypeOrBounds)(implicit ctx: Context): Option[NoPrefix] /** Type bounds */ type TypeBounds <: TypeOrBounds - def isTypeBounds(x: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] + def matchTypeBounds(x: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] def TypeBounds_low(self: TypeBounds)(implicit ctx: Context): Type def TypeBounds_hi(self: TypeBounds)(implicit ctx: Context): Type @@ -788,7 +788,7 @@ trait Kernel { /** A type */ type Type <: TypeOrBounds - def isType(x: TypeOrBounds)(implicit ctx: Context): Option[Type] + def matchType(x: TypeOrBounds)(implicit ctx: Context): Option[Type] def `Type_=:=`(self: Type)(that: Type)(implicit ctx: Context): Boolean def `Type_<:<`(self: Type)(that: Type)(implicit ctx: Context): Boolean @@ -815,24 +815,24 @@ trait Kernel { /** A singleton type representing a known constant value */ type ConstantType <: Type - def isConstantType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] + def matchConstantType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] def ConstantType_constant(self: ConstantType)(implicit ctx: Context): Constant /** Type of a reference to a symbol */ type SymRef <: Type - def isSymRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] + def matchSymRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] // TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef - def isSymRef_unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] + def matchSymRef_unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] def SymRef_qualifier(self: SymRef)(implicit ctx: Context): TypeOrBounds /** Type of a reference to a term */ type TermRef <: Type - def isTermRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] + def matchTermRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] def TermRef_name(self: TermRef)(implicit ctx: Context): String def TermRef_qualifier(self: TermRef)(implicit ctx: Context): TypeOrBounds @@ -842,7 +842,7 @@ trait Kernel { /** Type of a reference to a type */ type TypeRef <: Type - def isTypeRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] + def matchTypeRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] def TypeRef_name(self: TypeRef)(implicit ctx: Context): String def TypeRef_qualifier(self: TypeRef)(implicit ctx: Context): TypeOrBounds @@ -850,7 +850,7 @@ trait Kernel { /** Type of a `super` refernce */ type SuperType <: Type - def isSuperType(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] + def matchSuperType(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] def SuperType_thistpe(self: SuperType)(implicit ctx: Context): Type def SuperType_supertpe(self: SuperType)(implicit ctx: Context): Type @@ -858,7 +858,7 @@ trait Kernel { /** A type with a type refinement `T { type U }` */ type Refinement <: Type - def isRefinement(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] + def matchRefinement(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] def Refinement_parent(self: Refinement)(implicit ctx: Context): Type def Refinement_name(self: Refinement)(implicit ctx: Context): String @@ -867,7 +867,7 @@ trait Kernel { /** A higher kinded type applied to some types `T[U]` */ type AppliedType <: Type - def isAppliedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] + def matchAppliedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] def AppliedType_tycon(self: AppliedType)(implicit ctx: Context): Type def AppliedType_args(self: AppliedType)(implicit ctx: Context): List[TypeOrBounds] @@ -875,7 +875,7 @@ trait Kernel { /** A type with an anottation `T @foo` */ type AnnotatedType <: Type - def isAnnotatedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] + def matchAnnotatedType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] def AnnotatedType_underlying(self: AnnotatedType)(implicit ctx: Context): Type def AnnotatedType_annot(self: AnnotatedType)(implicit ctx: Context): Term @@ -883,7 +883,7 @@ trait Kernel { /** Intersection type `T & U` */ type AndType <: Type - def isAndType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] + def matchAndType(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] def AndType_left(self: AndType)(implicit ctx: Context): Type def AndType_right(self: AndType)(implicit ctx: Context): Type @@ -891,7 +891,7 @@ trait Kernel { /** Union type `T | U` */ type OrType <: Type - def isOrType(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] + def matchOrType(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] def OrType_left(self: OrType)(implicit ctx: Context): Type def OrType_right(self: OrType)(implicit ctx: Context): Type @@ -899,7 +899,7 @@ trait Kernel { /** Type match `T match { case U => ... }` */ type MatchType <: Type - def isMatchType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] + def matchMatchType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] def MatchType_bound(self: MatchType)(implicit ctx: Context): Type def MatchType_scrutinee(self: MatchType)(implicit ctx: Context): Type @@ -908,14 +908,14 @@ trait Kernel { /** Type of a by by name parameter */ type ByNameType <: Type - def isByNameType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] + def matchByNameType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] def ByNameType_underlying(self: ByNameType)(implicit ctx: Context): Type /** Type of a parameter reference */ type ParamRef <: Type - def isParamRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] + def matchParamRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] def ParamRef_binder(self: ParamRef)(implicit ctx: Context): LambdaType[TypeOrBounds] def ParamRef_paramNum(self: ParamRef)(implicit ctx: Context): Int @@ -923,21 +923,21 @@ trait Kernel { /** Type of `this` */ type ThisType <: Type - def isThisType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] + def matchThisType(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] def ThisType_tref(self: ThisType)(implicit ctx: Context): Type /** A type that is recursively defined `this` */ type RecursiveThis <: Type - def isRecursiveThis(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] + def matchRecursiveThis(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] def RecursiveThis_binder(self: RecursiveThis)(implicit ctx: Context): RecursiveType /** A type that is recursively defined */ type RecursiveType <: Type - def isRecursiveType(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] + def matchRecursiveType(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] def RecursiveType_underlying(self: RecursiveType)(implicit ctx: Context): Type @@ -949,7 +949,7 @@ trait Kernel { /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ type MethodType <: LambdaType[Type] - def isMethodType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] + def matchMethodType(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] def MethodType_isErased(self: MethodType): Boolean def MethodType_isImplicit(self: MethodType): Boolean @@ -960,7 +960,7 @@ trait Kernel { /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ type PolyType <: LambdaType[TypeBounds] - def isPolyType(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] + def matchPolyType(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] def PolyType_paramNames(self: PolyType)(implicit ctx: Context): List[String] def PolyType_paramBounds(self: PolyType)(implicit ctx: Context): List[TypeBounds] @@ -969,7 +969,7 @@ trait Kernel { /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ type TypeLambda <: LambdaType[TypeBounds] - def isTypeLambda(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] + def matchTypeLambda(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] def TypeLambda_paramNames(self: TypeLambda)(implicit ctx: Context): List[String] def TypeLambda_paramBounds(self: TypeLambda)(implicit ctx: Context): List[TypeBounds] @@ -988,20 +988,20 @@ trait Kernel { type SimpleSelector <: ImportSelector - def isSimpleSelector(self: ImportSelector)(implicit ctx: Context): Option[SimpleSelector] + def matchSimpleSelector(self: ImportSelector)(implicit ctx: Context): Option[SimpleSelector] def SimpleSelector_selection(self: SimpleSelector)(implicit ctx: Context): Id type RenameSelector <: ImportSelector - def isRenameSelector(self: ImportSelector)(implicit ctx: Context): Option[RenameSelector] + def matchRenameSelector(self: ImportSelector)(implicit ctx: Context): Option[RenameSelector] def RenameSelector_from(self: RenameSelector)(implicit ctx: Context): Id def RenameSelector_to(self: RenameSelector)(implicit ctx: Context): Id type OmitSelector <: ImportSelector - def isOmitSelector(self: ImportSelector)(implicit ctx: Context): Option[OmitSelector] + def matchOmitSelector(self: ImportSelector)(implicit ctx: Context): Option[OmitSelector] def SimpleSelector_omited(self: OmitSelector)(implicit ctx: Context): Id @@ -1081,19 +1081,19 @@ trait Kernel { def Constant_value(const: Constant): Any - def isConstant_Unit(constant: Constant): Boolean - def isConstant_Null(constant: Constant): Boolean - def isConstant_Boolean(constant: Constant): Option[Boolean] - def isConstant_Byte(constant: Constant): Option[Byte] - def isConstant_Short(constant: Constant): Option[Short] - def isConstant_Char(constant: Constant): Option[Char] - def isConstant_Int(constant: Constant): Option[Int] - def isConstant_Long(constant: Constant): Option[Long] - def isConstant_Float(constant: Constant): Option[Float] - def isConstant_Double(constant: Constant): Option[Double] - def isConstant_String(constant: Constant): Option[String] - def isConstant_ClassTag(constant: Constant): Option[Type] - def isConstant_Symbol(constant: Constant): Option[scala.Symbol] + def matchConstant_Unit(constant: Constant): Boolean + def matchConstant_Null(constant: Constant): Boolean + def matchConstant_Boolean(constant: Constant): Option[Boolean] + def matchConstant_Byte(constant: Constant): Option[Byte] + def matchConstant_Short(constant: Constant): Option[Short] + def matchConstant_Char(constant: Constant): Option[Char] + def matchConstant_Int(constant: Constant): Option[Int] + def matchConstant_Long(constant: Constant): Option[Long] + def matchConstant_Float(constant: Constant): Option[Float] + def matchConstant_Double(constant: Constant): Option[Double] + def matchConstant_String(constant: Constant): Option[String] + def matchConstant_ClassTag(constant: Constant): Option[Type] + def matchConstant_Symbol(constant: Constant): Option[scala.Symbol] def Constant_Unit_apply(): Constant def Constant_Null_apply(): Constant @@ -1166,14 +1166,14 @@ trait Kernel { /** Symbol of a package definition */ type PackageSymbol <: Symbol - def isPackageSymbol(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] + def matchPackageSymbol(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] def PackageSymbol_tree(self: PackageSymbol)(implicit ctx: Context): PackageDef /** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */ type ClassSymbol <: Symbol - def isClassSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] + def matchClassSymbol(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] /** ClassDef tree of this defintion */ def ClassSymbol_tree(self: ClassSymbol)(implicit ctx: Context): ClassDef @@ -1213,7 +1213,7 @@ trait Kernel { /** Symbol of a type (parameter or member) definition. */ type TypeSymbol <: Symbol - def isTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] + def matchTypeSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] def TypeSymbol_isTypeParam(self: TypeSymbol)(implicit ctx: Context): Boolean @@ -1223,7 +1223,7 @@ trait Kernel { /** Symbol representing a method definition. */ type DefSymbol <: Symbol - def isDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] + def matchDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] /** DefDef tree of this defintion */ def DefSymbol_tree(self: DefSymbol)(implicit ctx: Context): DefDef @@ -1234,7 +1234,7 @@ trait Kernel { /** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */ type ValSymbol <: Symbol - def isValSymbol(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] + def matchValSymbol(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] /** ValDef tree of this defintion */ def ValSymbol_tree(self: ValSymbol)(implicit ctx: Context): ValDef @@ -1247,7 +1247,7 @@ trait Kernel { /** Symbol representing a bind definition. */ type BindSymbol <: Symbol - def isBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] + def matchBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] /** Bind pattern of this definition */ def BindSymbol_tree(self: BindSymbol)(implicit ctx: Context): Bind @@ -1255,7 +1255,7 @@ trait Kernel { /** No symbol available. */ type NoSymbol <: Symbol - def isNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean + def matchNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean // // FLAGS diff --git a/library/src/scala/tasty/reflect/PatternOps.scala b/library/src/scala/tasty/reflect/PatternOps.scala index 97e9cced26af..35fe8eb4e765 100644 --- a/library/src/scala/tasty/reflect/PatternOps.scala +++ b/library/src/scala/tasty/reflect/PatternOps.scala @@ -39,7 +39,7 @@ trait PatternOps extends Core { object IsValue { def unapply(pattern: Pattern)(implicit ctx: Context): Option[Value] = - kernel.isPattern_Value(pattern) + kernel.matchPattern_Value(pattern) } object Value { @@ -48,12 +48,12 @@ trait PatternOps extends Core { def copy(original: Value)(tpt: Term)(implicit ctx: Context): Value = kernel.Pattern_Value_module_copy(original)(tpt) def unapply(pattern: Pattern)(implicit ctx: Context): Option[Term] = - kernel.isPattern_Value(pattern).map(_.value) + kernel.matchPattern_Value(pattern).map(_.value) } object IsBind { def unapply(pattern: Pattern)(implicit ctx: Context): Option[Bind] = - kernel.isPattern_Bind(pattern) + kernel.matchPattern_Bind(pattern) } object Bind { @@ -61,12 +61,12 @@ trait PatternOps extends Core { def copy(original: Bind)(name: String, pattern: Pattern)(implicit ctx: Context): Bind = kernel.Pattern_Bind_module_copy(original)(name, pattern) def unapply(pattern: Pattern)(implicit ctx: Context): Option[(String, Pattern)] = - kernel.isPattern_Bind(pattern).map(x => (x.name, x.pattern)) + kernel.matchPattern_Bind(pattern).map(x => (x.name, x.pattern)) } object IsUnapply { def unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] = - kernel.isPattern_Unapply(pattern) + kernel.matchPattern_Unapply(pattern) } object Unapply { @@ -74,12 +74,12 @@ trait PatternOps extends Core { def copy(original: Unapply)(fun: Term, implicits: List[Term], patterns: List[Pattern])(implicit ctx: Context): Unapply = kernel.Pattern_Unapply_module_copy(original)(fun, implicits, patterns) def unapply(pattern: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] = - kernel.isPattern_Unapply(pattern).map(x => (x.fun, x.implicits, x.patterns)) + kernel.matchPattern_Unapply(pattern).map(x => (x.fun, x.implicits, x.patterns)) } object IsAlternatives { def unapply(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] = - kernel.isPattern_Alternatives(pattern) + kernel.matchPattern_Alternatives(pattern) } object Alternatives { @@ -88,12 +88,12 @@ trait PatternOps extends Core { def copy(original: Alternatives)(patterns: List[Pattern])(implicit ctx: Context): Alternatives = kernel.Pattern_Alternatives_module_copy(original)(patterns) def unapply(pattern: Pattern)(implicit ctx: Context): Option[List[Pattern]] = - kernel.isPattern_Alternatives(pattern).map(_.patterns) + kernel.matchPattern_Alternatives(pattern).map(_.patterns) } object IsTypeTest { def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] = - kernel.isPattern_TypeTest(pattern) + kernel.matchPattern_TypeTest(pattern) } object TypeTest { @@ -102,7 +102,7 @@ trait PatternOps extends Core { def copy(original: TypeTest)(tpt: TypeTree)(implicit ctx: Context): TypeTest = kernel.Pattern_TypeTest_module_copy(original)(tpt) def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTree] = - kernel.isPattern_TypeTest(pattern).map(_.tpt) + kernel.matchPattern_TypeTest(pattern).map(_.tpt) } } diff --git a/library/src/scala/tasty/reflect/SymbolOps.scala b/library/src/scala/tasty/reflect/SymbolOps.scala index e71d8878ec99..5848f22fe53a 100644 --- a/library/src/scala/tasty/reflect/SymbolOps.scala +++ b/library/src/scala/tasty/reflect/SymbolOps.scala @@ -88,7 +88,7 @@ trait SymbolOps extends Core { object IsPackageSymbol { def unapply(symbol: Symbol)(implicit ctx: Context): Option[PackageSymbol] = - kernel.isPackageSymbol(symbol) + kernel.matchPackageSymbol(symbol) } implicit class PackageSymbolAPI(self: PackageSymbol) { @@ -100,7 +100,7 @@ trait SymbolOps extends Core { object IsClassSymbol { def unapply(symbol: Symbol)(implicit ctx: Context): Option[ClassSymbol] = - kernel.isClassSymbol(symbol) + kernel.matchClassSymbol(symbol) } object ClassSymbol { @@ -159,7 +159,7 @@ trait SymbolOps extends Core { object IsTypeSymbol { def unapply(symbol: Symbol)(implicit ctx: Context): Option[TypeSymbol] = - kernel.isTypeSymbol(symbol) + kernel.matchTypeSymbol(symbol) } implicit class TypeSymbolAPI(self: TypeSymbol) { @@ -175,7 +175,7 @@ trait SymbolOps extends Core { object IsDefSymbol { def unapply(symbol: Symbol)(implicit ctx: Context): Option[DefSymbol] = - kernel.isDefSymbol(symbol) + kernel.matchDefSymbol(symbol) } implicit class DefSymbolAPI(self: DefSymbol) { @@ -192,7 +192,7 @@ trait SymbolOps extends Core { object IsValSymbol { def unapply(symbol: Symbol)(implicit ctx: Context): Option[ValSymbol] = - kernel.isValSymbol(symbol) + kernel.matchValSymbol(symbol) } implicit class ValSymbolAPI(self: ValSymbol) { @@ -212,7 +212,7 @@ trait SymbolOps extends Core { object IsBindSymbol { def unapply(symbol: Symbol)(implicit ctx: Context): Option[BindSymbol] = - kernel.isBindSymbol(symbol) + kernel.matchBindSymbol(symbol) } implicit class BindSymbolAPI(self: BindSymbol) { @@ -225,6 +225,6 @@ trait SymbolOps extends Core { object NoSymbol { def unapply(symbol: Symbol)(implicit ctx: Context): Boolean = - kernel.isNoSymbol(symbol) + kernel.matchNoSymbol(symbol) } } diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index 3467cbe1c620..3c4091693ce8 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -18,7 +18,7 @@ trait TreeOps extends Core { object IsPackageClause { def unapply(tree: Tree)(implicit ctx: Context): Option[PackageClause] = - kernel.isPackageClause(tree) + kernel.matchPackageClause(tree) } object PackageClause { @@ -27,7 +27,7 @@ trait TreeOps extends Core { def copy(original: PackageClause)(pid: Term.Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = kernel.PackageClause_copy(original)(pid, stats) def unapply(tree: Tree)(implicit ctx: Context): Option[(Term.Ref, List[Tree])] = - kernel.isPackageClause(tree).map(x => (x.pid, x.stats)) + kernel.matchPackageClause(tree).map(x => (x.pid, x.stats)) } implicit class PackageClauseAPI(self: PackageClause) { @@ -37,7 +37,7 @@ trait TreeOps extends Core { object IsImport { def unapply(tree: Tree)(implicit ctx: Context): Option[Import] = - kernel.isImport(tree) + kernel.matchImport(tree) } object Import { @@ -46,7 +46,7 @@ trait TreeOps extends Core { def copy(original: Import)(impliedOnly: Boolean, expr: Term, selectors: List[ImportSelector])(implicit ctx: Context): Import = kernel.Import_copy(original)(impliedOnly, expr, selectors) def unapply(tree: Tree)(implicit ctx: Context): Option[(Boolean, Term, List[ImportSelector])] = - kernel.isImport(tree).map(x => (x.impliedOnly, x.expr, x.selectors)) + kernel.matchImport(tree).map(x => (x.impliedOnly, x.expr, x.selectors)) } implicit class ImportAPI(self: Import) { @@ -58,13 +58,13 @@ trait TreeOps extends Core { object IsStatement { /** Matches any Statement and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Statement] = kernel.isStatement(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Statement] = kernel.matchStatement(tree) } // ----- Definitions ---------------------------------------------- object IsDefinition { - def unapply(tree: Tree)(implicit ctx: Context): Option[Definition] = kernel.isDefinition(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Definition] = kernel.matchDefinition(tree) } implicit class DefinitionAPI(self: Definition) { @@ -74,7 +74,7 @@ trait TreeOps extends Core { // ClassDef object IsClassDef { - def unapply(tree: Tree)(implicit ctx: Context): Option[ClassDef] = kernel.isClassDef(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[ClassDef] = kernel.matchClassDef(tree) } object ClassDef { @@ -82,7 +82,7 @@ trait TreeOps extends Core { def copy(original: ClassDef)(name: String, constr: DefDef, parents: List[TermOrTypeTree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement])(implicit ctx: Context): ClassDef = kernel.ClassDef_copy(original)(name, constr, parents, derived, selfOpt, body) def unapply(tree: Tree)(implicit ctx: Context): Option[(String, DefDef, List[TermOrTypeTree], List[TypeTree], Option[ValDef], List[Statement])] = - kernel.isClassDef(tree).map(x => (x.name, x.constructor, x.parents, x.derived, x.self, x.body)) + kernel.matchClassDef(tree).map(x => (x.name, x.constructor, x.parents, x.derived, x.self, x.body)) } implicit class ClassDefAPI(self: ClassDef) { @@ -97,7 +97,7 @@ trait TreeOps extends Core { // DefDef object IsDefDef { - def unapply(tree: Tree)(implicit ctx: Context): Option[DefDef] = kernel.isDefDef(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[DefDef] = kernel.matchDefDef(tree) } object DefDef { @@ -106,7 +106,7 @@ trait TreeOps extends Core { def copy(original: DefDef)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): DefDef = kernel.DefDef_copy(original)(name, typeParams, paramss, tpt, rhs) def unapply(tree: Tree)(implicit ctx: Context): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] = - kernel.isDefDef(tree).map(x => (x.name, x.typeParams, x.paramss, x.returnTpt, x.rhs)) + kernel.matchDefDef(tree).map(x => (x.name, x.typeParams, x.paramss, x.returnTpt, x.rhs)) } implicit class DefDefAPI(self: DefDef) { @@ -120,7 +120,7 @@ trait TreeOps extends Core { // ValDef object IsValDef { - def unapply(tree: Tree)(implicit ctx: Context): Option[ValDef] = kernel.isValDef(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[ValDef] = kernel.matchValDef(tree) } object ValDef { @@ -129,7 +129,7 @@ trait TreeOps extends Core { def copy(original: ValDef)(name: String, tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): ValDef = kernel.ValDef_copy(original)(name, tpt, rhs) def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeTree, Option[Term])] = - kernel.isValDef(tree).map(x => (x.name, x.tpt, x.rhs)) + kernel.matchValDef(tree).map(x => (x.name, x.tpt, x.rhs)) } implicit class ValDefAPI(self: ValDef) { @@ -141,7 +141,7 @@ trait TreeOps extends Core { // TypeDef object IsTypeDef { - def unapply(tree: Tree)(implicit ctx: Context): Option[TypeDef] = kernel.isTypeDef(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[TypeDef] = kernel.matchTypeDef(tree) } object TypeDef { @@ -150,7 +150,7 @@ trait TreeOps extends Core { def copy(original: TypeDef)(name: String, rhs: TypeOrBoundsTree)(implicit ctx: Context): TypeDef = kernel.TypeDef_copy(original)(name, rhs) def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree /* TypeTree | TypeBoundsTree */)] = - kernel.isTypeDef(tree).map(x => (x.name, x.rhs)) + kernel.matchTypeDef(tree).map(x => (x.name, x.rhs)) } implicit class TypeDefAPI(self: TypeDef) { @@ -162,7 +162,7 @@ trait TreeOps extends Core { object IsPackageDef { def unapply(tree: Tree)(implicit ctx: Context): Option[PackageDef] = - kernel.isPackageDef(tree) + kernel.matchPackageDef(tree) } implicit class PackageDefAPI(self: PackageDef) { @@ -173,7 +173,7 @@ trait TreeOps extends Core { object PackageDef { def unapply(tree: Tree)(implicit ctx: Context): Option[(String, PackageDef)] = - kernel.isPackageDef(tree).map(x => (x.name, x.owner)) + kernel.matchPackageDef(tree).map(x => (x.name, x.owner)) } // ----- Terms ---------------------------------------------------- @@ -188,11 +188,11 @@ trait TreeOps extends Core { object IsTerm { /** Matches any term */ def unapply(tree: Tree)(implicit ctx: Context): Option[Term] = - kernel.isTerm(tree) + kernel.matchTerm(tree) /** Matches any term */ def unapply(parent: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[Term] = - kernel.isTermNotTypeTree(parent) + kernel.matchTermNotTypeTree(parent) } /** Scala term. Any tree that can go in expression position. */ @@ -200,7 +200,7 @@ trait TreeOps extends Core { object IsIdent { /** Matches any Ident and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Ident] = kernel.isTerm_Ident(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Ident] = kernel.matchTerm_Ident(tree) } object Ref { @@ -223,12 +223,12 @@ trait TreeOps extends Core { /** Matches a term identifier and returns its name */ def unapply(tree: Tree)(implicit ctx: Context): Option[String] = - kernel.isTerm_Ident(tree).map(_.name) + kernel.matchTerm_Ident(tree).map(_.name) } object IsSelect { /** Matches any Select and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Select] = kernel.isTerm_Select(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Select] = kernel.matchTerm_Select(tree) } /** Scala term selection */ @@ -252,12 +252,12 @@ trait TreeOps extends Core { /** Matches `.` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, String)] = - kernel.isTerm_Select(tree).map(x => (x.qualifier, x.name)) + kernel.matchTerm_Select(tree).map(x => (x.qualifier, x.name)) } object IsLiteral { /** Matches any Literal and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Literal] = kernel.isTerm_Literal(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Literal] = kernel.matchTerm_Literal(tree) } /** Scala literal constant */ @@ -272,12 +272,12 @@ trait TreeOps extends Core { /** Matches a literal constant */ def unapply(tree: Tree)(implicit ctx: Context): Option[Constant] = - kernel.isTerm_Literal(tree).map(_.constant) + kernel.matchTerm_Literal(tree).map(_.constant) } object IsThis { /** Matches any This and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[This] = kernel.isTerm_This(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[This] = kernel.matchTerm_This(tree) } /** Scala `this` or `this[id]` */ @@ -292,13 +292,13 @@ trait TreeOps extends Core { /** Matches `this[` */ def unapply(tree: Tree)(implicit ctx: Context): Option[Option[Id]] = - kernel.isTerm_This(tree).map(_.id) + kernel.matchTerm_This(tree).map(_.id) } object IsNew { /** Matches any New and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[New] = kernel.isTerm_New(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[New] = kernel.matchTerm_New(tree) } /** Scala `new` */ @@ -313,12 +313,12 @@ trait TreeOps extends Core { /** Matches a `new ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[TypeTree] = - kernel.isTerm_New(tree).map(_.tpt) + kernel.matchTerm_New(tree).map(_.tpt) } object IsNamedArg { /** Matches any NamedArg and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[NamedArg] = kernel.isTerm_NamedArg(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[NamedArg] = kernel.matchTerm_NamedArg(tree) } /** Scala named argument `x = y` in argument position */ @@ -333,13 +333,13 @@ trait TreeOps extends Core { /** Matches a named argument ` = ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(String, Term)] = - kernel.isTerm_NamedArg(tree).map(x => (x.name, x.value)) + kernel.matchTerm_NamedArg(tree).map(x => (x.name, x.value)) } object IsApply { /** Matches any Apply and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Apply] = kernel.isTerm_Apply(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Apply] = kernel.matchTerm_Apply(tree) } /** Scala parameter application */ @@ -354,13 +354,13 @@ trait TreeOps extends Core { /** Matches a function application `()` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[Term])] = - kernel.isTerm_Apply(tree).map(x => (x.fun, x.args)) + kernel.matchTerm_Apply(tree).map(x => (x.fun, x.args)) } object IsTypeApply { /** Matches any TypeApply and returns it */ def unapply(tree: Tree)(implicit ctx: Context): Option[TypeApply] = - kernel.isTerm_TypeApply(tree) + kernel.matchTerm_TypeApply(tree) } /** Scala type parameter application */ @@ -375,13 +375,13 @@ trait TreeOps extends Core { /** Matches a function type application `[]` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[TypeTree])] = - kernel.isTerm_TypeApply(tree).map(x => (x.fun, x.args)) + kernel.matchTerm_TypeApply(tree).map(x => (x.fun, x.args)) } object IsSuper { /** Matches any Super and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Super] = kernel.isTerm_Super(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Super] = kernel.matchTerm_Super(tree) } /** Scala `x.super` or `x.super[id]` */ @@ -396,12 +396,12 @@ trait TreeOps extends Core { /** Matches a `.super[` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Option[Id])] = - kernel.isTerm_Super(tree).map(x => (x.qualifier, x.id)) + kernel.matchTerm_Super(tree).map(x => (x.qualifier, x.id)) } object IsTyped { /** Matches any Typed and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Typed] = kernel.isTerm_Typed(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Typed] = kernel.matchTerm_Typed(tree) } /** Scala ascription `x: T` */ @@ -416,13 +416,13 @@ trait TreeOps extends Core { /** Matches `: ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, TypeTree)] = - kernel.isTerm_Typed(tree).map(x => (x.expr, x.tpt)) + kernel.matchTerm_Typed(tree).map(x => (x.expr, x.tpt)) } object IsAssign { /** Matches any Assign and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Assign] = kernel.isTerm_Assign(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Assign] = kernel.matchTerm_Assign(tree) } /** Scala assign `x = y` */ @@ -437,12 +437,12 @@ trait TreeOps extends Core { /** Matches an assignment ` = ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term)] = - kernel.isTerm_Assign(tree).map(x => (x.lhs, x.rhs)) + kernel.matchTerm_Assign(tree).map(x => (x.lhs, x.rhs)) } object IsBlock { /** Matches any Block and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Block] = kernel.isTerm_Block(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Block] = kernel.matchTerm_Block(tree) } /** Scala code block `{ stat0; ...; statN; expr }` term */ @@ -457,12 +457,12 @@ trait TreeOps extends Core { /** Matches a block `{ ; }` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Statement], Term)] = - kernel.isTerm_Block(tree).map(x => (x.statements, x.expr)) + kernel.matchTerm_Block(tree).map(x => (x.statements, x.expr)) } object IsLambda { /** Matches any Lambda and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Lambda] = kernel.isTerm_Lambda(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Lambda] = kernel.matchTerm_Lambda(tree) } object Lambda { @@ -474,12 +474,12 @@ trait TreeOps extends Core { kernel.Term_Lambda_copy(original)(meth, tpt) def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Option[TypeTree])] = - kernel.isTerm_Lambda(tree).map(x => (x.meth, x.tptOpt)) + kernel.matchTerm_Lambda(tree).map(x => (x.meth, x.tptOpt)) } object IsIf { /** Matches any If and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[If] = kernel.isTerm_If(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[If] = kernel.matchTerm_If(tree) } /** Scala `if`/`else` term */ @@ -494,13 +494,13 @@ trait TreeOps extends Core { /** Matches an if/then/else `if () else ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term, Term)] = - kernel.isTerm_If(tree).map(x => (x.cond, x.thenp, x.elsep)) + kernel.matchTerm_If(tree).map(x => (x.cond, x.thenp, x.elsep)) } object IsMatch { /** Matches any Match and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Match] = kernel.isTerm_Match(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Match] = kernel.matchTerm_Match(tree) } /** Scala `match` term */ @@ -515,13 +515,13 @@ trait TreeOps extends Core { /** Matches a pattern match ` match { }` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[CaseDef])] = - kernel.isTerm_Match(tree).map(x => (x.scrutinee, x.cases)) + kernel.matchTerm_Match(tree).map(x => (x.scrutinee, x.cases)) } object IsTry { /** Matches any Try and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Try] = kernel.isTerm_Try(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Try] = kernel.matchTerm_Try(tree) } /** Scala `try`/`catch`/`finally` term */ @@ -536,13 +536,13 @@ trait TreeOps extends Core { /** Matches a try/catch `try catch { } finally ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[CaseDef], Option[Term])] = - kernel.isTerm_Try(tree).map(x => (x.body, x.cases, x.finalizer)) + kernel.matchTerm_Try(tree).map(x => (x.body, x.cases, x.finalizer)) } object IsReturn { /** Matches any Return and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Return] = kernel.isTerm_Return(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Return] = kernel.matchTerm_Return(tree) } /** Scala local `return` */ @@ -557,13 +557,13 @@ trait TreeOps extends Core { /** Matches `return ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[Term] = - kernel.isTerm_Return(tree).map(_.expr) + kernel.matchTerm_Return(tree).map(_.expr) } object IsRepeated { /** Matches any Repeated and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Repeated] = kernel.isTerm_Repeated(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Repeated] = kernel.matchTerm_Repeated(tree) } object Repeated { @@ -575,13 +575,13 @@ trait TreeOps extends Core { kernel.Term_Repeated_copy(original)(elems, tpt) def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Term], TypeTree)] = - kernel.isTerm_Repeated(tree).map(x => (x.elems, x.elemtpt)) + kernel.matchTerm_Repeated(tree).map(x => (x.elems, x.elemtpt)) } object IsInlined { /** Matches any Inlined and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Inlined] = kernel.isTerm_Inlined(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Inlined] = kernel.matchTerm_Inlined(tree) } object Inlined { @@ -593,13 +593,13 @@ trait TreeOps extends Core { kernel.Term_Inlined_copy(original)(call, bindings, expansion) def unapply(tree: Tree)(implicit ctx: Context): Option[(Option[TermOrTypeTree], List[Definition], Term)] = - kernel.isTerm_Inlined(tree).map(x => (x.call, x.bindings, x.body)) + kernel.matchTerm_Inlined(tree).map(x => (x.call, x.bindings, x.body)) } object IsSelectOuter { /** Matches any SelectOuter and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[SelectOuter] = kernel.isTerm_SelectOuter(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[SelectOuter] = kernel.matchTerm_SelectOuter(tree) } object SelectOuter { @@ -611,13 +611,13 @@ trait TreeOps extends Core { kernel.Term_SelectOuter_copy(original)(qualifier, name, levels) def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Int, Type)] = // TODO homogenize order of parameters - kernel.isTerm_SelectOuter(tree).map(x => (x.qualifier, x.level, x.tpe)) + kernel.matchTerm_SelectOuter(tree).map(x => (x.qualifier, x.level, x.tpe)) } object IsWhile { /** Matches any While and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[While] = kernel.isTerm_While(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[While] = kernel.matchTerm_While(tree) } object While { @@ -631,7 +631,7 @@ trait TreeOps extends Core { /** Extractor for while loops. Matches `while () ` and returns (, ) */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term)] = - kernel.isTerm_While(tree).map(x => (x.cond, x.body)) + kernel.matchTerm_While(tree).map(x => (x.cond, x.body)) } } diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala index 97cdf53126a6..f6f175ab9bc8 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala @@ -19,7 +19,7 @@ trait TypeOrBoundsOps extends Core { object IsType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = - kernel.isType(typeOrBounds) + kernel.matchType(typeOrBounds) } object Type { @@ -27,29 +27,29 @@ trait TypeOrBoundsOps extends Core { object IsConstantType { /** Matches any ConstantType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] = - kernel.isConstantType(tpe) + kernel.matchConstantType(tpe) } object ConstantType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Constant] = - kernel.isConstantType(typeOrBounds).map(_.constant) + kernel.matchConstantType(typeOrBounds).map(_.constant) } object IsSymRef { /** Matches any SymRef and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] = - kernel.isSymRef(tpe) + kernel.matchSymRef(tpe) } object SymRef { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] = - kernel.isSymRef_unapply(typeOrBounds) + kernel.matchSymRef_unapply(typeOrBounds) } object IsTermRef { /** Matches any TermRef and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] = - kernel.isTermRef(tpe) + kernel.matchTermRef(tpe) } object TermRef { @@ -57,183 +57,183 @@ trait TypeOrBoundsOps extends Core { def apply(qual: TypeOrBounds, name: String)(implicit ctx: Context): TermRef = kernel.TermRef_apply(qual, name) def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] = - kernel.isTermRef(typeOrBounds).map(x => (x.name, x.qualifier)) + kernel.matchTermRef(typeOrBounds).map(x => (x.name, x.qualifier)) } object IsTypeRef { /** Matches any TypeRef and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] = - kernel.isTypeRef(tpe) + kernel.matchTypeRef(tpe) } object TypeRef { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] = - kernel.isTypeRef(typeOrBounds).map(x => (x.name, x.qualifier)) + kernel.matchTypeRef(typeOrBounds).map(x => (x.name, x.qualifier)) } object IsSuperType { /** Matches any SuperType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] = - kernel.isSuperType(tpe) + kernel.matchSuperType(tpe) } object SuperType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = - kernel.isSuperType(typeOrBounds).map(x => (x.thistpe, x.supertpe)) + kernel.matchSuperType(typeOrBounds).map(x => (x.thistpe, x.supertpe)) } object IsRefinement { /** Matches any Refinement and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] = - kernel.isRefinement(tpe) + kernel.matchRefinement(tpe) } object Refinement { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] = - kernel.isRefinement(typeOrBounds).map(x => (x.parent, x.name, x.info)) + kernel.matchRefinement(typeOrBounds).map(x => (x.parent, x.name, x.info)) } object IsAppliedType { /** Matches any AppliedType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] = - kernel.isAppliedType(tpe) + kernel.matchAppliedType(tpe) } object AppliedType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] = - kernel.isAppliedType(typeOrBounds).map(x => (x.tycon, x.args)) + kernel.matchAppliedType(typeOrBounds).map(x => (x.tycon, x.args)) } object IsAnnotatedType { /** Matches any AnnotatedType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] = - kernel.isAnnotatedType(tpe) + kernel.matchAnnotatedType(tpe) } object AnnotatedType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Term)] = - kernel.isAnnotatedType(typeOrBounds).map(x => (x.underlying, x.annot)) + kernel.matchAnnotatedType(typeOrBounds).map(x => (x.underlying, x.annot)) } object IsAndType { /** Matches any AndType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] = - kernel.isAndType(tpe) + kernel.matchAndType(tpe) } object AndType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = - kernel.isAndType(typeOrBounds).map(x => (x.left, x.right)) + kernel.matchAndType(typeOrBounds).map(x => (x.left, x.right)) } object IsOrType { /** Matches any OrType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] = - kernel.isOrType(tpe) + kernel.matchOrType(tpe) } object OrType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = - kernel.isOrType(typeOrBounds).map(x => (x.left, x.right)) + kernel.matchOrType(typeOrBounds).map(x => (x.left, x.right)) } object IsMatchType { /** Matches any MatchType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] = - kernel.isMatchType(tpe) + kernel.matchMatchType(tpe) } object MatchType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type, List[Type])] = - kernel.isMatchType(typeOrBounds).map(x => (x.bound, x.scrutinee, x.cases)) + kernel.matchMatchType(typeOrBounds).map(x => (x.bound, x.scrutinee, x.cases)) } object IsByNameType { /** Matches any ByNameType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] = - kernel.isByNameType(tpe) + kernel.matchByNameType(tpe) } object ByNameType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = - kernel.isByNameType(typeOrBounds).map(_.underlying) + kernel.matchByNameType(typeOrBounds).map(_.underlying) } object IsParamRef { /** Matches any ParamRef and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] = - kernel.isParamRef(tpe) + kernel.matchParamRef(tpe) } object ParamRef { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] = - kernel.isParamRef(typeOrBounds).map(x => (x.binder, x.paramNum)) + kernel.matchParamRef(typeOrBounds).map(x => (x.binder, x.paramNum)) } object IsThisType { /** Matches any ThisType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] = - kernel.isThisType(tpe) + kernel.matchThisType(tpe) } object ThisType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = - kernel.isThisType(typeOrBounds).map(_.tref) + kernel.matchThisType(typeOrBounds).map(_.tref) } object IsRecursiveThis { /** Matches any RecursiveThis and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] = - kernel.isRecursiveThis(tpe) + kernel.matchRecursiveThis(tpe) } object RecursiveThis { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = - kernel.isRecursiveThis(typeOrBounds).map(_.binder) + kernel.matchRecursiveThis(typeOrBounds).map(_.binder) } object IsRecursiveType { /** Matches any RecursiveType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = - kernel.isRecursiveType(tpe) + kernel.matchRecursiveType(tpe) } object RecursiveType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = - kernel.isRecursiveType(typeOrBounds).map(_.underlying) + kernel.matchRecursiveType(typeOrBounds).map(_.underlying) } object IsMethodType { /** Matches any MethodType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] = - kernel.isMethodType(tpe) + kernel.matchMethodType(tpe) } object MethodType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[Type], Type)] = - kernel.isMethodType(typeOrBounds).map(x => (x.paramNames, x.paramTypes, x.resType)) + kernel.matchMethodType(typeOrBounds).map(x => (x.paramNames, x.paramTypes, x.resType)) } object IsPolyType { /** Matches any PolyType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] = - kernel.isPolyType(tpe) + kernel.matchPolyType(tpe) } object PolyType { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] = - kernel.isPolyType(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) + kernel.matchPolyType(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) } object IsTypeLambda { /** Matches any TypeLambda and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] = - kernel.isTypeLambda(tpe) + kernel.matchTypeLambda(tpe) } object TypeLambda { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] = - kernel.isTypeLambda(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) + kernel.matchTypeLambda(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) } } @@ -338,12 +338,12 @@ trait TypeOrBoundsOps extends Core { object IsTypeBounds { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] = - kernel.isTypeBounds(typeOrBounds) + kernel.matchTypeBounds(typeOrBounds) } object TypeBounds { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = - kernel.isTypeBounds(typeOrBounds).map(x => (x.low, x.hi)) + kernel.matchTypeBounds(typeOrBounds).map(x => (x.low, x.hi)) } implicit class TypeBoundsAPI(self: TypeBounds) { @@ -355,7 +355,7 @@ trait TypeOrBoundsOps extends Core { object NoPrefix { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Boolean = - kernel.isNoPrefix(typeOrBounds).isDefined + kernel.matchNoPrefix(typeOrBounds).isDefined } } diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala index 72685bb4dbfb..7a57529e8728 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala @@ -24,9 +24,9 @@ trait TypeOrBoundsTreeOps extends Core { object IsTypeTree { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] = - kernel.isTypeTree(tpt) + kernel.matchTypeTree(tpt) def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] = - kernel.isTypeTreeNotTerm(termOrTypeTree) + kernel.matchTypeTreeNotTerm(termOrTypeTree) } object TypeTree extends TypeTreeCoreModule { @@ -34,7 +34,7 @@ trait TypeOrBoundsTreeOps extends Core { object IsInferred { /** Matches any Inferred and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Inferred] = - kernel.isTypeTree_Inferred(tpt) + kernel.matchTypeTree_Inferred(tpt) } /** TypeTree containing an inferred type */ @@ -43,13 +43,13 @@ trait TypeOrBoundsTreeOps extends Core { kernel.TypeTree_Inferred_apply(tpe) /** Matches a TypeTree containing an inferred type */ def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean = - kernel.isTypeTree_Inferred(typeOrBoundsTree).isDefined + kernel.matchTypeTree_Inferred(typeOrBoundsTree).isDefined } object IsIdent { /** Matches any Ident and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Ident] = - kernel.isTypeTree_Ident(tpt) + kernel.matchTypeTree_Ident(tpt) } object Ident { @@ -57,13 +57,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: Ident)(name: String)(implicit ctx: Context): Ident = kernel.TypeTree_Ident_copy(original)(name) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[String] = - kernel.isTypeTree_Ident(typeOrBoundsTree).map(_.name) + kernel.matchTypeTree_Ident(typeOrBoundsTree).map(_.name) } object IsSelect { /** Matches any Select and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Select] = - kernel.isTypeTree_Select(tpt) + kernel.matchTypeTree_Select(tpt) } object Select { @@ -72,13 +72,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: Select)(qualifier: Term, name: String)(implicit ctx: Context): Select = kernel.TypeTree_Select_copy(original)(qualifier, name) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(Term, String)] = - kernel.isTypeTree_Select(typeOrBoundsTree).map(x => (x.qualifier, x.name)) + kernel.matchTypeTree_Select(typeOrBoundsTree).map(x => (x.qualifier, x.name)) } object IsProjection { /** Matches any Projection and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Projection] = - kernel.isTypeTree_Projection(tpt) + kernel.matchTypeTree_Projection(tpt) } object Projection { @@ -86,13 +86,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: Projection)(qualifier: TypeTree, name: String)(implicit ctx: Context): Projection = kernel.TypeTree_Projection_copy(original)(qualifier, name) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, String)] = - kernel.isTypeTree_Projection(typeOrBoundsTree).map(x => (x.qualifier, x.name)) + kernel.matchTypeTree_Projection(typeOrBoundsTree).map(x => (x.qualifier, x.name)) } object IsSingleton { /** Matches any Singleton and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Singleton] = - kernel.isTypeTree_Singleton(tpt) + kernel.matchTypeTree_Singleton(tpt) } object Singleton { @@ -101,13 +101,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: Singleton)(ref: Term)(implicit ctx: Context): Singleton = kernel.TypeTree_Singleton_copy(original)(ref) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[Term] = - kernel.isTypeTree_Singleton(typeOrBoundsTree).map(_.ref) + kernel.matchTypeTree_Singleton(typeOrBoundsTree).map(_.ref) } object IsRefined { /** Matches any Refined and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Refined] = - kernel.isTypeTree_Refined(tpt) + kernel.matchTypeTree_Refined(tpt) } object Refined { @@ -115,13 +115,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: Refined)(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): Refined = kernel.TypeTree_Refined_copy(original)(tpt, refinements) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, List[Definition])] = - kernel.isTypeTree_Refined(typeOrBoundsTree).map(x => (x.tpt, x.refinements)) + kernel.matchTypeTree_Refined(typeOrBoundsTree).map(x => (x.tpt, x.refinements)) } object IsApplied { /** Matches any Applied and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Applied] = - kernel.isTypeTree_Applied(tpt) + kernel.matchTypeTree_Applied(tpt) } object Applied { @@ -130,13 +130,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: Applied)(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied = kernel.TypeTree_Applied_copy(original)(tpt, args) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] = - kernel.isTypeTree_Applied(typeOrBoundsTree).map(x => (x.tpt, x.args)) + kernel.matchTypeTree_Applied(typeOrBoundsTree).map(x => (x.tpt, x.args)) } object IsAnnotated { /** Matches any Annotated and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Annotated] = - kernel.isTypeTree_Annotated(tpt) + kernel.matchTypeTree_Annotated(tpt) } object Annotated { @@ -145,13 +145,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: Annotated)(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated = kernel.TypeTree_Annotated_copy(original)(arg, annotation) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, Term)] = - kernel.isTypeTree_Annotated(typeOrBoundsTree).map(x => (x.arg, x.annotation)) + kernel.matchTypeTree_Annotated(typeOrBoundsTree).map(x => (x.arg, x.annotation)) } object IsMatchType { /** Matches any MatchType and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[MatchType] = - kernel.isTypeTree_MatchType(tpt) + kernel.matchTypeTree_MatchType(tpt) } object MatchType { @@ -160,13 +160,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: MatchType)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType = kernel.TypeTree_MatchType_copy(original)(bound, selector, cases) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] = - kernel.isTypeTree_MatchType(typeOrBoundsTree).map(x => (x.bound, x.selector, x.cases)) + kernel.matchTypeTree_MatchType(typeOrBoundsTree).map(x => (x.bound, x.selector, x.cases)) } object IsByName { /** Matches any ByName and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[ByName] = - kernel.isTypeTree_ByName(tpt) + kernel.matchTypeTree_ByName(tpt) } object ByName { @@ -175,13 +175,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: ByName)(result: TypeTree)(implicit ctx: Context): ByName = kernel.TypeTree_ByName_copy(original)(result) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] = - kernel.isTypeTree_ByName(typeOrBoundsTree).map(_.result) + kernel.matchTypeTree_ByName(typeOrBoundsTree).map(_.result) } object IsLambdaTypeTree { /** Matches any LambdaTypeTree and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[LambdaTypeTree] = - kernel.isTypeTree_LambdaTypeTree(tpt) + kernel.matchTypeTree_LambdaTypeTree(tpt) } object LambdaTypeTree { @@ -190,13 +190,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: LambdaTypeTree)(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree = kernel.TypeTree_LambdaTypeTree_copy(original)(tparams, body) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(List[TypeDef], TypeOrBoundsTree)] = - kernel.isTypeTree_LambdaTypeTree(typeOrBoundsTree).map(x => (x.tparams, x.body)) + kernel.matchTypeTree_LambdaTypeTree(typeOrBoundsTree).map(x => (x.tparams, x.body)) } object IsTypeBind { /** Matches any TypeBind and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBind] = - kernel.isTypeTree_TypeBind(tpt) + kernel.matchTypeTree_TypeBind(tpt) } object TypeBind { @@ -204,13 +204,13 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: TypeBind)(name: String, tpt: TypeOrBoundsTree)(implicit ctx: Context): TypeBind = kernel.TypeTree_TypeBind_copy(original)(name, tpt) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree)] = - kernel.isTypeTree_TypeBind(typeOrBoundsTree).map(x => (x.name, x.body)) + kernel.matchTypeTree_TypeBind(typeOrBoundsTree).map(x => (x.name, x.body)) } object IsTypeBlock { /** Matches any TypeBlock and returns it */ def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBlock] = - kernel.isTypeTree_TypeBlock(tpt) + kernel.matchTypeTree_TypeBlock(tpt) } object TypeBlock { @@ -219,7 +219,7 @@ trait TypeOrBoundsTreeOps extends Core { def copy(original: TypeBlock)(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock = kernel.TypeTree_TypeBlock_copy(original)(aliases, tpt) def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(List[TypeDef], TypeTree)] = - kernel.isTypeTree_TypeBlock(typeOrBoundsTree).map(x => (x.aliases, x.tpt)) + kernel.matchTypeTree_TypeBlock(typeOrBoundsTree).map(x => (x.aliases, x.tpt)) } } @@ -291,24 +291,24 @@ trait TypeOrBoundsTreeOps extends Core { object IsTypeBoundsTree { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] = - kernel.isTypeBoundsTree(tpt) + kernel.matchTypeBoundsTree(tpt) } object TypeBoundsTree { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] = - kernel.isTypeBoundsTree(typeOrBoundsTree).map(x => (x.low, x.hi)) + kernel.matchTypeBoundsTree(typeOrBoundsTree).map(x => (x.low, x.hi)) } object IsWildcardTypeTree { def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] = - kernel.isWildcardTypeTree(tpt) + kernel.matchWildcardTypeTree(tpt) } /** TypeBoundsTree containing wildcard type bounds */ object WildcardTypeTree { /** Matches a TypeBoundsTree containing wildcard type bounds */ def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean = - kernel.isWildcardTypeTree(typeOrBoundsTree).isDefined + kernel.matchWildcardTypeTree(typeOrBoundsTree).isDefined } } From d8a3b6f8caa3d2e2066bd363c079f9fd0ceae535 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 5 Mar 2019 16:59:08 +0100 Subject: [PATCH 15/17] Update docs --- library/src/scala/tasty/reflect/Kernel.scala | 68 ++++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index fc3192a5df98..85bb22966e61 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -12,43 +12,43 @@ package scala.tasty.reflect * | +- DefDef * | +- ValDef * | - * +- Term --------+- Ref -+- Ident - * | +- Select + * +- Term --------+- Term_Ref -+- Term_Ident + * | +- Term_Select * | - * +- Literal - * +- This - * +- New - * +- NamedArg - * +- Apply - * +- TypeApply - * +- Super - * +- Typed - * +- Assign - * +- Block - * +- Lambda - * +- If - * +- Match - * +- Try - * +- Return - * +- Repeated - * +- Inlined - * +- SelectOuter - * +- While + * +- Term_Literal + * +- Term_This + * +- Term_New + * +- Term_NamedArg + * +- Term_Apply + * +- Term_TypeApply + * +- Term_Super + * +- Term_Typed + * +- Term_Assign + * +- Term_Block + * +- Term_Lambda + * +- Term_If + * +- Term_Match + * +- Term_Try + * +- Term_Return + * +- Term_Repeated + * +- Term_Inlined + * +- Term_SelectOuter + * +- Term_While * * - * +- TypeTree ----+- Inferred - * | +- Ident - * | +- Select - * | +- Project - * | +- Singleton - * +- TypeOrBoundsTree ---+ +- Refined - * | +- Applied - * | +- Annotated - * | +- MatchType - * | +- ByName - * | +- LambdaTypeTree - * | +- TypeBind - * | +- TypeBlock + * +- TypeTree ----+- TypeTree_Inferred + * | +- TypeTree_Ident + * | +- TypeTree_Select + * | +- TypeTree_Project + * | +- TypeTree_Singleton + * +- TypeOrBoundsTree ---+ +- TypeTree_Refined + * | +- TypeTree_Applied + * | +- TypeTree_Annotated + * | +- TypeTree_MatchType + * | +- TypeTree_ByName + * | +- TypeTree_LambdaTypeTree + * | +- TypeTree_TypeBind + * | +- TypeTree_TypeBlock * | * +- TypeBoundsTree * +- WildcardTypeTree From 80028d9bc0d17120f715d03a9872fcd64d0fa630 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 5 Mar 2019 17:10:52 +0100 Subject: [PATCH 16/17] Remove unnecessary `Term_` prefix --- .../tools/dotc/tastyreflect/KernelImpl.scala | 266 +++++++-------- library/src/scala/tasty/reflect/Core.scala | 44 +-- library/src/scala/tasty/reflect/Kernel.scala | 306 +++++++++--------- library/src/scala/tasty/reflect/TreeOps.scala | 298 ++++++++--------- 4 files changed, 457 insertions(+), 457 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 113477f6d099..e6526f415a68 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -55,13 +55,13 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. case _ => None } - def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Term_Ref = self.pid + def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Ref = self.pid def PackageClause_stats(self: PackageClause)(implicit ctx: Context): List[Tree] = self.stats - def PackageClause_apply(pid: Term_Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = + def PackageClause_apply(pid: Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = withDefaultPos(ctx => tpd.PackageDef(pid.asInstanceOf[tpd.RefTree], stats)(ctx)) - def PackageClause_copy(original: PackageClause)(pid: Term_Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = + def PackageClause_copy(original: PackageClause)(pid: Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = tpd.cpy.PackageDef(original)(pid, stats) type Statement = tpd.Tree @@ -201,196 +201,196 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Term_underlyingArgument(self: Term)(implicit ctx: Context): Term = self.underlyingArgument def Term_underlying(self: Term)(implicit ctx: Context): Term = self.underlying - type Term_Ref = tpd.RefTree + type Ref = tpd.RefTree - def Term_Ref_apply(sym: Symbol)(implicit ctx: Context): Term_Ref = + def Ref_apply(sym: Symbol)(implicit ctx: Context): Ref = withDefaultPos(ctx => tpd.ref(sym)(ctx).asInstanceOf[tpd.RefTree]) - type Term_Ident = tpd.Ident + type Ident = tpd.Ident - def matchTerm_Ident(x: Term)(implicit ctx: Context): Option[Term_Ident] = x match { + def matchIdent(x: Term)(implicit ctx: Context): Option[Ident] = x match { case x: tpd.Ident if x.isTerm => Some(x) case _ => None } - def Term_Ident_name(self: Term_Ident)(implicit ctx: Context): String = self.name.show + def Ident_name(self: Ident)(implicit ctx: Context): String = self.name.show - def Term_Ident_apply(tmref: TermRef)(implicit ctx: Context): Term = + def Ident_apply(tmref: TermRef)(implicit ctx: Context): Term = withDefaultPos(implicit ctx => tpd.ref(tmref).asInstanceOf[Term]) - def Term_Ident_copy(original: Tree)(name: String)(implicit ctx: Context): Term_Ident = + def Ident_copy(original: Tree)(name: String)(implicit ctx: Context): Ident = tpd.cpy.Ident(original)(name.toTermName) - type Term_Select = tpd.Select + type Select = tpd.Select - def matchTerm_Select(x: Term)(implicit ctx: Context): Option[Term_Select] = x match { + def matchSelect(x: Term)(implicit ctx: Context): Option[Select] = x match { case x: tpd.Select if x.isTerm => Some(x) case _ => None } - def Term_Select_qualifier(self: Term_Select)(implicit ctx: Context): Term = self.qualifier - def Term_Select_name(self: Term_Select)(implicit ctx: Context): String = self.name.toString - def Term_Select_signature(self: Term_Select)(implicit ctx: Context): Option[Signature] = + def Select_qualifier(self: Select)(implicit ctx: Context): Term = self.qualifier + def Select_name(self: Select)(implicit ctx: Context): String = self.name.toString + def Select_signature(self: Select)(implicit ctx: Context): Option[Signature] = if (self.symbol.signature == core.Signature.NotAMethod) None else Some(self.symbol.signature) - def Term_Select_unique(qualifier: Term, name: String)(implicit ctx: Context): Term_Select = { + def Select_unique(qualifier: Term, name: String)(implicit ctx: Context): Select = { val denot = qualifier.tpe.member(name.toTermName) assert(!denot.isOverloaded, s"The symbol `$name` is overloaded. The method Select.unique can only be used for non-overloaded symbols.") withDefaultPos(implicit ctx => tpd.Select(qualifier, name.toTermName)) } // TODO rename, this returns an Apply and not a Select - def Term_Select_overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Term_Apply = - withDefaultPos(implicit ctx => tpd.applyOverloaded(qualifier, name.toTermName, args, targs, Types.WildcardType).asInstanceOf[Term_Apply]) + def Select_overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Apply = + withDefaultPos(implicit ctx => tpd.applyOverloaded(qualifier, name.toTermName, args, targs, Types.WildcardType).asInstanceOf[Apply]) - def Term_Select_copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Term_Select = + def Select_copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Select = tpd.cpy.Select(original)(qualifier, name.toTermName) - type Term_Literal = tpd.Literal + type Literal = tpd.Literal - def matchTerm_Literal(x: Term)(implicit ctx: Context): Option[Term_Literal] = x match { + def matchLiteral(x: Term)(implicit ctx: Context): Option[Literal] = x match { case x: tpd.Literal => Some(x) case _ => None } - def Term_Literal_constant(self: Term_Literal)(implicit ctx: Context): Constant = self.const + def Literal_constant(self: Literal)(implicit ctx: Context): Constant = self.const - def Term_Literal_apply(constant: Constant)(implicit ctx: Context): Term_Literal = + def Literal_apply(constant: Constant)(implicit ctx: Context): Literal = withDefaultPos(ctx => tpd.Literal(constant)(ctx)) - def Term_Literal_copy(original: Tree)(constant: Constant)(implicit ctx: Context): Term_Literal = + def Literal_copy(original: Tree)(constant: Constant)(implicit ctx: Context): Literal = tpd.cpy.Literal(original)(constant) - type Term_This = tpd.This + type This = tpd.This - def matchTerm_This(x: Term)(implicit ctx: Context): Option[Term_This] = x match { + def matchThis(x: Term)(implicit ctx: Context): Option[This] = x match { case x: tpd.This => Some(x) case _ => None } - def Term_This_id(self: Term_This)(implicit ctx: Context): Option[Id] = optional(self.qual) + def This_id(self: This)(implicit ctx: Context): Option[Id] = optional(self.qual) - def Term_This_apply(cls: ClassSymbol)(implicit ctx: Context): Term_This = + def This_apply(cls: ClassSymbol)(implicit ctx: Context): This = withDefaultPos(ctx => tpd.This(cls)(ctx)) - def Term_This_copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): Term_This = + def This_copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): This = tpd.cpy.This(original)(qual.getOrElse(untpd.EmptyTypeIdent)) - type Term_New = tpd.New + type New = tpd.New - def matchTerm_New(x: Term)(implicit ctx: Context): Option[Term_New] = x match { + def matchNew(x: Term)(implicit ctx: Context): Option[New] = x match { case x: tpd.New => Some(x) case _ => None } - def Term_New_tpt(self: Term_New)(implicit ctx: Context): TypeTree = self.tpt + def New_tpt(self: New)(implicit ctx: Context): TypeTree = self.tpt - def Term_New_apply(tpt: TypeTree)(implicit ctx: Context): Term_New = withDefaultPos(ctx => tpd.New(tpt)(ctx)) + def New_apply(tpt: TypeTree)(implicit ctx: Context): New = withDefaultPos(ctx => tpd.New(tpt)(ctx)) - def Term_New_copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): Term_New = + def New_copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): New = tpd.cpy.New(original)(tpt) - type Term_NamedArg = tpd.NamedArg + type NamedArg = tpd.NamedArg - def matchTerm_NamedArg(x: Term)(implicit ctx: Context): Option[Term_NamedArg] = x match { + def matchNamedArg(x: Term)(implicit ctx: Context): Option[NamedArg] = x match { case x: tpd.NamedArg if x.name.isInstanceOf[core.Names.TermName] => Some(x) // TODO: Now, the name should alwas be a term name case _ => None } - def Term_NamedArg_name(self: Term_NamedArg)(implicit ctx: Context): String = self.name.toString - def Term_NamedArg_value(self: Term_NamedArg)(implicit ctx: Context): Term = self.arg + def NamedArg_name(self: NamedArg)(implicit ctx: Context): String = self.name.toString + def NamedArg_value(self: NamedArg)(implicit ctx: Context): Term = self.arg - def Term_NamedArg_apply(name: String, arg: Term)(implicit ctx: Context): Term_NamedArg = + def NamedArg_apply(name: String, arg: Term)(implicit ctx: Context): NamedArg = withDefaultPos(ctx => tpd.NamedArg(name.toTermName, arg)(ctx)) - def Term_NamedArg_copy(tree: Term_NamedArg)(name: String, arg: Term)(implicit ctx: Context): Term_NamedArg = + def NamedArg_copy(tree: NamedArg)(name: String, arg: Term)(implicit ctx: Context): NamedArg = tpd.cpy.NamedArg(tree)(name.toTermName, arg) - type Term_Apply = tpd.Apply + type Apply = tpd.Apply - def matchTerm_Apply(x: Term)(implicit ctx: Context): Option[Term_Apply] = x match { + def matchApply(x: Term)(implicit ctx: Context): Option[Apply] = x match { case x: tpd.Apply => Some(x) case _ => None } - def Term_Apply_fun(self: Term_Apply)(implicit ctx: Context): Term = self.fun - def Term_Apply_args(self: Term_Apply)(implicit ctx: Context): List[Term] = self.args + def Apply_fun(self: Apply)(implicit ctx: Context): Term = self.fun + def Apply_args(self: Apply)(implicit ctx: Context): List[Term] = self.args - def Term_Apply_apply(fn: Term, args: List[Term])(implicit ctx: Context): Term_Apply = + def Apply_apply(fn: Term, args: List[Term])(implicit ctx: Context): Apply = withDefaultPos(ctx => tpd.Apply(fn, args)(ctx)) - def Term_Apply_copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Term_Apply = + def Apply_copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Apply = tpd.cpy.Apply(original)(fun, args) - type Term_TypeApply = tpd.TypeApply + type TypeApply = tpd.TypeApply - def matchTerm_TypeApply(x: Term)(implicit ctx: Context): Option[Term_TypeApply] = x match { + def matchTypeApply(x: Term)(implicit ctx: Context): Option[TypeApply] = x match { case x: tpd.TypeApply => Some(x) case _ => None } - def Term_TypeApply_fun(self: Term_TypeApply)(implicit ctx: Context): Term = self.fun - def Term_TypeApply_args(self: Term_TypeApply)(implicit ctx: Context): List[TypeTree] = self.args + def TypeApply_fun(self: TypeApply)(implicit ctx: Context): Term = self.fun + def TypeApply_args(self: TypeApply)(implicit ctx: Context): List[TypeTree] = self.args - def Term_TypeApply_apply(fn: Term, args: List[TypeTree])(implicit ctx: Context): Term_TypeApply = + def TypeApply_apply(fn: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = withDefaultPos(ctx => tpd.TypeApply(fn, args)(ctx)) - def Term_TypeApply_copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): Term_TypeApply = + def TypeApply_copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = tpd.cpy.TypeApply(original)(fun, args) - type Term_Super = tpd.Super + type Super = tpd.Super - def matchTerm_Super(x: Term)(implicit ctx: Context): Option[Term_Super] = x match { + def matchSuper(x: Term)(implicit ctx: Context): Option[Super] = x match { case x: tpd.Super => Some(x) case _ => None } - def Term_Super_qualifier(self: Term_Super)(implicit ctx: Context): Term = self.qual - def Term_Super_id(self: Term_Super)(implicit ctx: Context): Option[Id] = optional(self.mix) + def Super_qualifier(self: Super)(implicit ctx: Context): Term = self.qual + def Super_id(self: Super)(implicit ctx: Context): Option[Id] = optional(self.mix) - def Term_Super_apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Term_Super = + def Super_apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = withDefaultPos(ctx => tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), false, NoSymbol)(ctx)) - def Term_Super_copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Term_Super = + def Super_copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = tpd.cpy.Super(original)(qual, mix.getOrElse(untpd.EmptyTypeIdent)) - type Term_Typed = tpd.Typed + type Typed = tpd.Typed - def matchTerm_Typed(x: Term)(implicit ctx: Context): Option[Term_Typed] = x match { + def matchTyped(x: Term)(implicit ctx: Context): Option[Typed] = x match { case x: tpd.Typed => Some(x) case _ => None } - def Term_Typed_expr(self: Term_Typed)(implicit ctx: Context): Term = self.expr - def Term_Typed_tpt(self: Term_Typed)(implicit ctx: Context): TypeTree = self.tpt + def Typed_expr(self: Typed)(implicit ctx: Context): Term = self.expr + def Typed_tpt(self: Typed)(implicit ctx: Context): TypeTree = self.tpt - def Term_Typed_apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Term_Typed = + def Typed_apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = withDefaultPos(ctx => tpd.Typed(expr, tpt)(ctx)) - def Term_Typed_copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Term_Typed = + def Typed_copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = tpd.cpy.Typed(original)(expr, tpt) - type Term_Assign = tpd.Assign + type Assign = tpd.Assign - def matchTerm_Assign(x: Term)(implicit ctx: Context): Option[Term_Assign] = x match { + def matchAssign(x: Term)(implicit ctx: Context): Option[Assign] = x match { case x: tpd.Assign => Some(x) case _ => None } - def Term_Assign_lhs(self: Term_Assign)(implicit ctx: Context): Term = self.lhs - def Term_Assign_rhs(self: Term_Assign)(implicit ctx: Context): Term = self.rhs + def Assign_lhs(self: Assign)(implicit ctx: Context): Term = self.lhs + def Assign_rhs(self: Assign)(implicit ctx: Context): Term = self.rhs - def Term_Assign_apply(lhs: Term, rhs: Term)(implicit ctx: Context): Term_Assign = + def Assign_apply(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = withDefaultPos(ctx => tpd.Assign(lhs, rhs)(ctx)) - def Term_Assign_copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Term_Assign = + def Assign_copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = tpd.cpy.Assign(original)(lhs, rhs) - type Term_Block = tpd.Block + type Block = tpd.Block - def matchTerm_Block(x: Term)(implicit ctx: Context): Option[Term_Block] = normalizedLoops(x) match { + def matchBlock(x: Term)(implicit ctx: Context): Option[Block] = normalizedLoops(x) match { case x: tpd.Block => Some(x) case _ => None } @@ -424,132 +424,132 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. case _ => false } - def Term_Block_statements(self: Term_Block)(implicit ctx: Context): List[Statement] = self.stats - def Term_Block_expr(self: Term_Block)(implicit ctx: Context): Term = self.expr + def Block_statements(self: Block)(implicit ctx: Context): List[Statement] = self.stats + def Block_expr(self: Block)(implicit ctx: Context): Term = self.expr - def Term_Block_apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Term_Block = + def Block_apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = withDefaultPos(ctx => tpd.Block(stats, expr)(ctx)) - def Term_Block_copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Term_Block = + def Block_copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = tpd.cpy.Block(original)(stats, expr) - type Term_Inlined = tpd.Inlined + type Inlined = tpd.Inlined - def matchTerm_Inlined(x: Term)(implicit ctx: Context): Option[Term_Inlined] = x match { + def matchInlined(x: Term)(implicit ctx: Context): Option[Inlined] = x match { case x: tpd.Inlined => Some(x) case _ => None } - def Term_Inlined_call(self: Term_Inlined)(implicit ctx: Context): Option[TermOrTypeTree] = optional(self.call) - def Term_Inlined_bindings(self: Term_Inlined)(implicit ctx: Context): List[Definition] = self.bindings - def Term_Inlined_body(self: Term_Inlined)(implicit ctx: Context): Term = self.expansion + def Inlined_call(self: Inlined)(implicit ctx: Context): Option[TermOrTypeTree] = optional(self.call) + def Inlined_bindings(self: Inlined)(implicit ctx: Context): List[Definition] = self.bindings + def Inlined_body(self: Inlined)(implicit ctx: Context): Term = self.expansion - def Term_Inlined_apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Term_Inlined = + def Inlined_apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined = withDefaultPos(ctx => tpd.Inlined(call.getOrElse(tpd.EmptyTree), bindings.map { case b: tpd.MemberDef => b }, expansion)(ctx)) - def Term_Inlined_copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Term_Inlined = + def Inlined_copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined = tpd.cpy.Inlined(original)(call.getOrElse(tpd.EmptyTree), bindings.asInstanceOf[List[tpd.MemberDef]], expansion) - type Term_Lambda = tpd.Closure + type Lambda = tpd.Closure - def matchTerm_Lambda(x: Term)(implicit ctx: Context): Option[Term_Lambda] = x match { + def matchLambda(x: Term)(implicit ctx: Context): Option[Lambda] = x match { case x: tpd.Closure => Some(x) case _ => None } - def Term_Lambda_meth(self: Term_Lambda)(implicit ctx: Context): Term = self.meth - def Term_Lambda_tptOpt(self: Term_Lambda)(implicit ctx: Context): Option[TypeTree] = optional(self.tpt) + def Lambda_meth(self: Lambda)(implicit ctx: Context): Term = self.meth + def Lambda_tptOpt(self: Lambda)(implicit ctx: Context): Option[TypeTree] = optional(self.tpt) - def Term_Lambda_apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Term_Lambda = + def Lambda_apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Lambda = withDefaultPos(ctx => tpd.Closure(Nil, meth, tpt.getOrElse(tpd.EmptyTree))(ctx)) - def Term_Lambda_copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Term_Lambda = + def Lambda_copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Lambda = tpd.cpy.Closure(original)(Nil, meth, tpt.getOrElse(tpd.EmptyTree)) - type Term_If = tpd.If + type If = tpd.If - def matchTerm_If(x: Term)(implicit ctx: Context): Option[Term_If] = x match { + def matchIf(x: Term)(implicit ctx: Context): Option[If] = x match { case x: tpd.If => Some(x) case _ => None } - def Term_If_cond(self: Term_If)(implicit ctx: Context): Term = self.cond - def Term_If_thenp(self: Term_If)(implicit ctx: Context): Term = self.thenp - def Term_If_elsep(self: Term_If)(implicit ctx: Context): Term = self.elsep + def If_cond(self: If)(implicit ctx: Context): Term = self.cond + def If_thenp(self: If)(implicit ctx: Context): Term = self.thenp + def If_elsep(self: If)(implicit ctx: Context): Term = self.elsep - def Term_If_apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): Term_If = + def If_apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = withDefaultPos(ctx => tpd.If(cond, thenp, elsep)(ctx)) - def Term_If_copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): Term_If = + def If_copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = tpd.cpy.If(original)(cond, thenp, elsep) - type Term_Match = tpd.Match + type Match = tpd.Match - def matchTerm_Match(x: Term)(implicit ctx: Context): Option[Term_Match] = x match { + def matchMatch(x: Term)(implicit ctx: Context): Option[Match] = x match { case x: tpd.Match => Some(x) case _ => None } - def Term_Match_scrutinee(self: Term_Match)(implicit ctx: Context): Term = self.selector - def Term_Match_cases(self: Term_Match)(implicit ctx: Context): List[CaseDef] = self.cases + def Match_scrutinee(self: Match)(implicit ctx: Context): Term = self.selector + def Match_cases(self: Match)(implicit ctx: Context): List[CaseDef] = self.cases - def Term_Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Term_Match = + def Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = withDefaultPos(ctx => tpd.Match(selector, cases)(ctx)) - def Term_Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Term_Match = + def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = tpd.cpy.Match(original)(selector, cases) - type Term_Try = tpd.Try + type Try = tpd.Try - def matchTerm_Try(x: Term)(implicit ctx: Context): Option[Term_Try] = x match { + def matchTry(x: Term)(implicit ctx: Context): Option[Try] = x match { case x: tpd.Try => Some(x) case _ => None } - def Term_Try_body(self: Term_Try)(implicit ctx: Context): Term = self.expr - def Term_Try_cases(self: Term_Try)(implicit ctx: Context): List[CaseDef] = self.cases - def Term_Try_finalizer(self: Term_Try)(implicit ctx: Context): Option[Term] = optional(self.finalizer) + def Try_body(self: Try)(implicit ctx: Context): Term = self.expr + def Try_cases(self: Try)(implicit ctx: Context): List[CaseDef] = self.cases + def Try_finalizer(self: Try)(implicit ctx: Context): Option[Term] = optional(self.finalizer) - def Term_Try_apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Term_Try = + def Try_apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try = withDefaultPos(ctx => tpd.Try(expr, cases, finalizer.getOrElse(tpd.EmptyTree))(ctx)) - def Term_Try_copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Term_Try = + def Try_copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try = tpd.cpy.Try(original)(expr, cases, finalizer.getOrElse(tpd.EmptyTree)) - type Term_Return = tpd.Return + type Return = tpd.Return - def matchTerm_Return(x: Term)(implicit ctx: Context): Option[Term_Return] = x match { + def matchReturn(x: Term)(implicit ctx: Context): Option[Return] = x match { case x: tpd.Return => Some(x) case _ => None } - def Term_Return_expr(self: Term_Return)(implicit ctx: Context): Term = self.expr + def Return_expr(self: Return)(implicit ctx: Context): Term = self.expr - def Term_Return_apply(expr: Term)(implicit ctx: Context): Term_Return = + def Return_apply(expr: Term)(implicit ctx: Context): Return = withDefaultPos(ctx => tpd.Return(expr, ctx.owner)(ctx)) - def Term_Return_copy(original: Tree)(expr: Term)(implicit ctx: Context): Term_Return = + def Return_copy(original: Tree)(expr: Term)(implicit ctx: Context): Return = tpd.cpy.Return(original)(expr, tpd.ref(ctx.owner)) - type Term_Repeated = tpd.SeqLiteral + type Repeated = tpd.SeqLiteral - def matchTerm_Repeated(x: Term)(implicit ctx: Context): Option[Term_Repeated] = x match { + def matchRepeated(x: Term)(implicit ctx: Context): Option[Repeated] = x match { case x: tpd.SeqLiteral => Some(x) case _ => None } - def Term_Repeated_elems(self: Term_Repeated)(implicit ctx: Context): List[Term] = self.elems - def Term_Repeated_elemtpt(self: Term_Repeated)(implicit ctx: Context): TypeTree = self.elemtpt + def Repeated_elems(self: Repeated)(implicit ctx: Context): List[Term] = self.elems + def Repeated_elemtpt(self: Repeated)(implicit ctx: Context): TypeTree = self.elemtpt - def Term_Repeated_apply(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Term_Repeated = + def Repeated_apply(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Repeated = withDefaultPos(ctx => tpd.SeqLiteral(elems, elemtpt)(ctx)) - def Term_Repeated_copy(original: Tree)(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Term_Repeated = + def Repeated_copy(original: Tree)(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Repeated = tpd.cpy.SeqLiteral(original)(elems, elemtpt) - type Term_SelectOuter = tpd.Select + type SelectOuter = tpd.Select - def matchTerm_SelectOuter(x: Term)(implicit ctx: Context): Option[Term_SelectOuter] = x match { + def matchSelectOuter(x: Term)(implicit ctx: Context): Option[SelectOuter] = x match { case x: tpd.Select => x.name match { case NameKinds.OuterSelectName(_, _) => Some(x) @@ -558,33 +558,33 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. case _ => None } - def Term_SelectOuter_qualifier(self: Term_SelectOuter)(implicit ctx: Context): Term = self.qualifier - def Term_SelectOuter_level(self: Term_SelectOuter)(implicit ctx: Context): Int = { + def SelectOuter_qualifier(self: SelectOuter)(implicit ctx: Context): Term = self.qualifier + def SelectOuter_level(self: SelectOuter)(implicit ctx: Context): Int = { val NameKinds.OuterSelectName(_, levels) = self.name levels } - def Term_SelectOuter_tpe(self: Term_SelectOuter)(implicit ctx: Context): Type = self.tpe.stripTypeVar + def SelectOuter_tpe(self: SelectOuter)(implicit ctx: Context): Type = self.tpe.stripTypeVar - def Term_SelectOuter_apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): Term_SelectOuter = + def SelectOuter_apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter = withDefaultPos(ctx => tpd.Select(qualifier, NameKinds.OuterSelectName(name.toTermName, levels))(ctx)) - def Term_SelectOuter_copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): Term_SelectOuter = + def SelectOuter_copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter = tpd.cpy.Select(original)(qualifier, NameKinds.OuterSelectName(name.toTermName, levels)) - type Term_While = tpd.WhileDo + type While = tpd.WhileDo - def matchTerm_While(x: Term)(implicit ctx: Context): Option[Term_While] = x match { + def matchWhile(x: Term)(implicit ctx: Context): Option[While] = x match { case x: tpd.WhileDo => Some(x) case _ => None } - def Term_While_cond(self: Term_While)(implicit ctx: Context): Term = self.cond - def Term_While_body(self: Term_While)(implicit ctx: Context): Term = self.body + def While_cond(self: While)(implicit ctx: Context): Term = self.cond + def While_body(self: While)(implicit ctx: Context): Term = self.body - def Term_While_apply(cond: Term, body: Term)(implicit ctx: Context): Term_While = + def While_apply(cond: Term, body: Term)(implicit ctx: Context): While = withDefaultPos(ctx => tpd.WhileDo(cond, body)(ctx)) - def Term_While_copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): Term_While = + def While_copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): While = tpd.cpy.WhileDo(original)(cond, body) // diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index 49b2b0d0f408..bd5f00c5654a 100644 --- a/library/src/scala/tasty/reflect/Core.scala +++ b/library/src/scala/tasty/reflect/Core.scala @@ -170,70 +170,70 @@ trait Core { trait TermCoreModule { /** Tree representing a reference to definition */ - type Ref = kernel.Term_Ref + type Ref = kernel.Ref /** Tree representing a reference to definition with a given name */ - type Ident = kernel.Term_Ident + type Ident = kernel.Ident /** Tree representing a selection of definition with a given name on a given prefix */ - type Select = kernel.Term_Select + type Select = kernel.Select /** Tree representing a literal value in the source code */ - type Literal = kernel.Term_Literal + type Literal = kernel.Literal /** Tree representing `this` in the source code */ - type This = kernel.Term_This + type This = kernel.This /** Tree representing `new` in the source code */ - type New = kernel.Term_New + type New = kernel.New /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ - type NamedArg = kernel.Term_NamedArg + type NamedArg = kernel.NamedArg /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ - type Apply = kernel.Term_Apply + type Apply = kernel.Apply /** Tree an application of type arguments */ - type TypeApply = kernel.Term_TypeApply + type TypeApply = kernel.TypeApply /** Tree representing `super` in the source code */ - type Super = kernel.Term_Super + type Super = kernel.Super /** Tree representing a type ascription `x: T` in the source code */ - type Typed = kernel.Term_Typed + type Typed = kernel.Typed /** Tree representing an assignment `x = y` in the source code */ - type Assign = kernel.Term_Assign + type Assign = kernel.Assign /** Tree representing a block `{ ... }` in the source code */ - type Block = kernel.Term_Block + type Block = kernel.Block /** Tree representing a lambda `(...) => ...` in the source code */ - type Lambda = kernel.Term_Lambda + type Lambda = kernel.Lambda /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ - type If = kernel.Term_If + type If = kernel.If /** Tree representing a pattern match `x match { ... }` in the source code */ - type Match = kernel.Term_Match + type Match = kernel.Match /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ - type Try = kernel.Term_Try + type Try = kernel.Try /** Tree representing a `return` in the source code */ - type Return = kernel.Term_Return + type Return = kernel.Return /** Tree representing a variable argument list in the source code */ - type Repeated = kernel.Term_Repeated + type Repeated = kernel.Repeated /** Tree representing the scope of an inlined tree */ - type Inlined = kernel.Term_Inlined + type Inlined = kernel.Inlined /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ - type SelectOuter = kernel.Term_SelectOuter + type SelectOuter = kernel.SelectOuter /** Tree representing a while loop */ - type While = kernel.Term_While + type While = kernel.While } diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 85bb22966e61..ecedb5d6f7e7 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -12,28 +12,28 @@ package scala.tasty.reflect * | +- DefDef * | +- ValDef * | - * +- Term --------+- Term_Ref -+- Term_Ident - * | +- Term_Select + * +- Term --------+- Ref -+- Ident + * | +- Select * | - * +- Term_Literal - * +- Term_This - * +- Term_New - * +- Term_NamedArg - * +- Term_Apply - * +- Term_TypeApply - * +- Term_Super - * +- Term_Typed - * +- Term_Assign - * +- Term_Block - * +- Term_Lambda - * +- Term_If - * +- Term_Match - * +- Term_Try - * +- Term_Return - * +- Term_Repeated - * +- Term_Inlined - * +- Term_SelectOuter - * +- Term_While + * +- Literal + * +- This + * +- New + * +- NamedArg + * +- Apply + * +- TypeApply + * +- Super + * +- Typed + * +- Assign + * +- Block + * +- Lambda + * +- If + * +- Match + * +- Try + * +- Return + * +- Repeated + * +- Inlined + * +- SelectOuter + * +- While * * * +- TypeTree ----+- TypeTree_Inferred @@ -166,12 +166,12 @@ trait Kernel { def matchPackageClause(tree: Tree)(implicit ctx: Context): Option[PackageClause] - def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Term_Ref + def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Ref def PackageClause_stats(self: PackageClause)(implicit ctx: Context): List[Tree] - def PackageClause_apply(pid: Term_Ref, stats: List[Tree])(implicit ctx: Context): PackageClause + def PackageClause_apply(pid: Ref, stats: List[Tree])(implicit ctx: Context): PackageClause - def PackageClause_copy(original: PackageClause)(pid: Term_Ref, stats: List[Tree])(implicit ctx: Context): PackageClause + def PackageClause_copy(original: PackageClause)(pid: Ref, stats: List[Tree])(implicit ctx: Context): PackageClause /** Tree representing a statement in the source code */ type Statement <: Tree @@ -271,242 +271,242 @@ trait Kernel { def Term_underlying(self: Term)(implicit ctx: Context): Term /** Tree representing a reference to definition */ - type Term_Ref <: Term + type Ref <: Term - def Term_Ref_apply(sym: Symbol)(implicit ctx: Context): Term_Ref + def Ref_apply(sym: Symbol)(implicit ctx: Context): Ref /** Tree representing a reference to definition with a given name */ - type Term_Ident <: Term_Ref + type Ident <: Ref - def matchTerm_Ident(tree: Tree)(implicit ctx: Context): Option[Term_Ident] + def matchIdent(tree: Tree)(implicit ctx: Context): Option[Ident] - def Term_Ident_name(self: Term_Ident)(implicit ctx: Context): String + def Ident_name(self: Ident)(implicit ctx: Context): String - def Term_Ident_apply(tmref: TermRef)(implicit ctx: Context): Term - def Term_Ident_copy(original: Tree)(name: String)(implicit ctx: Context): Term_Ident + def Ident_apply(tmref: TermRef)(implicit ctx: Context): Term + def Ident_copy(original: Tree)(name: String)(implicit ctx: Context): Ident /** Tree representing a selection of definition with a given name on a given prefix */ - type Term_Select <: Term_Ref + type Select <: Ref - def matchTerm_Select(tree: Tree)(implicit ctx: Context): Option[Term_Select] + def matchSelect(tree: Tree)(implicit ctx: Context): Option[Select] - def Term_Select_qualifier(self: Term_Select)(implicit ctx: Context): Term - def Term_Select_name(self: Term_Select)(implicit ctx: Context): String - def Term_Select_signature(self: Term_Select)(implicit ctx: Context): Option[Signature] + def Select_qualifier(self: Select)(implicit ctx: Context): Term + def Select_name(self: Select)(implicit ctx: Context): String + def Select_signature(self: Select)(implicit ctx: Context): Option[Signature] - def Term_Select_unique(qualifier: Term, name: String)(implicit ctx: Context): Term_Select + def Select_unique(qualifier: Term, name: String)(implicit ctx: Context): Select // TODO rename, this returns an Apply and not a Select - def Term_Select_overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Term_Apply - def Term_Select_copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Term_Select + def Select_overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Apply + def Select_copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Select /** Tree representing a literal value in the source code */ - type Term_Literal <: Term + type Literal <: Term - def matchTerm_Literal(tree: Tree)(implicit ctx: Context): Option[Term_Literal] + def matchLiteral(tree: Tree)(implicit ctx: Context): Option[Literal] - def Term_Literal_constant(self: Term_Literal)(implicit ctx: Context): Constant + def Literal_constant(self: Literal)(implicit ctx: Context): Constant - def Term_Literal_apply(constant: Constant)(implicit ctx: Context): Term_Literal - def Term_Literal_copy(original: Tree)(constant: Constant)(implicit ctx: Context): Term_Literal + def Literal_apply(constant: Constant)(implicit ctx: Context): Literal + def Literal_copy(original: Tree)(constant: Constant)(implicit ctx: Context): Literal /** Tree representing `this` in the source code */ - type Term_This <: Term + type This <: Term - def matchTerm_This(tree: Tree)(implicit ctx: Context): Option[Term_This] + def matchThis(tree: Tree)(implicit ctx: Context): Option[This] - def Term_This_id(self: Term_This)(implicit ctx: Context): Option[Id] + def This_id(self: This)(implicit ctx: Context): Option[Id] - def Term_This_apply(cls: ClassSymbol)(implicit ctx: Context): Term_This - def Term_This_copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): Term_This + def This_apply(cls: ClassSymbol)(implicit ctx: Context): This + def This_copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): This /** Tree representing `new` in the source code */ - type Term_New <: Term + type New <: Term - def matchTerm_New(tree: Tree)(implicit ctx: Context): Option[Term_New] + def matchNew(tree: Tree)(implicit ctx: Context): Option[New] - def Term_New_tpt(self: Term_New)(implicit ctx: Context): TypeTree + def New_tpt(self: New)(implicit ctx: Context): TypeTree - def Term_New_apply(tpt: TypeTree)(implicit ctx: Context): Term_New - def Term_New_copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): Term_New + def New_apply(tpt: TypeTree)(implicit ctx: Context): New + def New_copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): New /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ - type Term_NamedArg <: Term + type NamedArg <: Term - def matchTerm_NamedArg(tree: Tree)(implicit ctx: Context): Option[Term_NamedArg] + def matchNamedArg(tree: Tree)(implicit ctx: Context): Option[NamedArg] - def Term_NamedArg_name(self: Term_NamedArg)(implicit ctx: Context): String - def Term_NamedArg_value(self: Term_NamedArg)(implicit ctx: Context): Term + def NamedArg_name(self: NamedArg)(implicit ctx: Context): String + def NamedArg_value(self: NamedArg)(implicit ctx: Context): Term - def Term_NamedArg_apply(name: String, arg: Term)(implicit ctx: Context): Term_NamedArg - def Term_NamedArg_copy(tree: Term_NamedArg)(name: String, arg: Term)(implicit ctx: Context): Term_NamedArg + def NamedArg_apply(name: String, arg: Term)(implicit ctx: Context): NamedArg + def NamedArg_copy(tree: NamedArg)(name: String, arg: Term)(implicit ctx: Context): NamedArg /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ - type Term_Apply <: Term + type Apply <: Term - def matchTerm_Apply(tree: Tree)(implicit ctx: Context): Option[Term_Apply] + def matchApply(tree: Tree)(implicit ctx: Context): Option[Apply] - def Term_Apply_fun(self: Term_Apply)(implicit ctx: Context): Term - def Term_Apply_args(self: Term_Apply)(implicit ctx: Context): List[Term] + def Apply_fun(self: Apply)(implicit ctx: Context): Term + def Apply_args(self: Apply)(implicit ctx: Context): List[Term] - def Term_Apply_apply(fn: Term, args: List[Term])(implicit ctx: Context): Term_Apply - def Term_Apply_copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Term_Apply + def Apply_apply(fn: Term, args: List[Term])(implicit ctx: Context): Apply + def Apply_copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Apply /** Tree an application of type arguments */ - type Term_TypeApply <: Term + type TypeApply <: Term - def matchTerm_TypeApply(tree: Tree)(implicit ctx: Context): Option[Term_TypeApply] + def matchTypeApply(tree: Tree)(implicit ctx: Context): Option[TypeApply] - def Term_TypeApply_fun(self: Term_TypeApply)(implicit ctx: Context): Term - def Term_TypeApply_args(self: Term_TypeApply)(implicit ctx: Context): List[TypeTree] + def TypeApply_fun(self: TypeApply)(implicit ctx: Context): Term + def TypeApply_args(self: TypeApply)(implicit ctx: Context): List[TypeTree] - def Term_TypeApply_apply(fn: Term, args: List[TypeTree])(implicit ctx: Context): Term_TypeApply - def Term_TypeApply_copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): Term_TypeApply + def TypeApply_apply(fn: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply + def TypeApply_copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply /** Tree representing `super` in the source code */ - type Term_Super <: Term + type Super <: Term - def matchTerm_Super(tree: Tree)(implicit ctx: Context): Option[Term_Super] + def matchSuper(tree: Tree)(implicit ctx: Context): Option[Super] - def Term_Super_qualifier(self: Term_Super)(implicit ctx: Context): Term - def Term_Super_id(self: Term_Super)(implicit ctx: Context): Option[Id] + def Super_qualifier(self: Super)(implicit ctx: Context): Term + def Super_id(self: Super)(implicit ctx: Context): Option[Id] - def Term_Super_apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Term_Super - def Term_Super_copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Term_Super + def Super_apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Super + def Super_copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Super /** Tree representing a type ascription `x: T` in the source code */ - type Term_Typed <: Term + type Typed <: Term - def matchTerm_Typed(tree: Tree)(implicit ctx: Context): Option[Term_Typed] + def matchTyped(tree: Tree)(implicit ctx: Context): Option[Typed] - def Term_Typed_expr(self: Term_Typed)(implicit ctx: Context): Term - def Term_Typed_tpt(self: Term_Typed)(implicit ctx: Context): TypeTree + def Typed_expr(self: Typed)(implicit ctx: Context): Term + def Typed_tpt(self: Typed)(implicit ctx: Context): TypeTree - def Term_Typed_apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Term_Typed - def Term_Typed_copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Term_Typed + def Typed_apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed + def Typed_copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed /** Tree representing an assignment `x = y` in the source code */ - type Term_Assign <: Term + type Assign <: Term - def matchTerm_Assign(tree: Tree)(implicit ctx: Context): Option[Term_Assign] + def matchAssign(tree: Tree)(implicit ctx: Context): Option[Assign] - def Term_Assign_lhs(self: Term_Assign)(implicit ctx: Context): Term - def Term_Assign_rhs(self: Term_Assign)(implicit ctx: Context): Term + def Assign_lhs(self: Assign)(implicit ctx: Context): Term + def Assign_rhs(self: Assign)(implicit ctx: Context): Term - def Term_Assign_apply(lhs: Term, rhs: Term)(implicit ctx: Context): Term_Assign - def Term_Assign_copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Term_Assign + def Assign_apply(lhs: Term, rhs: Term)(implicit ctx: Context): Assign + def Assign_copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Assign /** Tree representing a block `{ ... }` in the source code */ - type Term_Block <: Term + type Block <: Term - def matchTerm_Block(tree: Tree)(implicit ctx: Context): Option[Term_Block] + def matchBlock(tree: Tree)(implicit ctx: Context): Option[Block] - def Term_Block_statements(self: Term_Block)(implicit ctx: Context): List[Statement] - def Term_Block_expr(self: Term_Block)(implicit ctx: Context): Term + def Block_statements(self: Block)(implicit ctx: Context): List[Statement] + def Block_expr(self: Block)(implicit ctx: Context): Term - def Term_Block_apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Term_Block - def Term_Block_copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Term_Block + def Block_apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Block + def Block_copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Block /** Tree representing a lambda `(...) => ...` in the source code */ - type Term_Lambda <: Term + type Lambda <: Term - def matchTerm_Lambda(tree: Tree)(implicit ctx: Context): Option[Term_Lambda] + def matchLambda(tree: Tree)(implicit ctx: Context): Option[Lambda] - def Term_Lambda_meth(self: Term_Lambda)(implicit ctx: Context): Term - def Term_Lambda_tptOpt(self: Term_Lambda)(implicit ctx: Context): Option[TypeTree] + def Lambda_meth(self: Lambda)(implicit ctx: Context): Term + def Lambda_tptOpt(self: Lambda)(implicit ctx: Context): Option[TypeTree] - def Term_Lambda_apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Term_Lambda - def Term_Lambda_copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Term_Lambda + def Lambda_apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Lambda + def Lambda_copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Lambda /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ - type Term_If <: Term + type If <: Term - def matchTerm_If(tree: Tree)(implicit ctx: Context): Option[Term_If] + def matchIf(tree: Tree)(implicit ctx: Context): Option[If] - def Term_If_cond(self: Term_If)(implicit ctx: Context): Term - def Term_If_thenp(self: Term_If)(implicit ctx: Context): Term - def Term_If_elsep(self: Term_If)(implicit ctx: Context): Term + def If_cond(self: If)(implicit ctx: Context): Term + def If_thenp(self: If)(implicit ctx: Context): Term + def If_elsep(self: If)(implicit ctx: Context): Term - def Term_If_apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): Term_If - def Term_If_copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): Term_If + def If_apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If + def If_copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If /** Tree representing a pattern match `x match { ... }` in the source code */ - type Term_Match <: Term + type Match <: Term - def matchTerm_Match(tree: Tree)(implicit ctx: Context): Option[Term_Match] + def matchMatch(tree: Tree)(implicit ctx: Context): Option[Match] - def Term_Match_scrutinee(self: Term_Match)(implicit ctx: Context): Term - def Term_Match_cases(self: Term_Match)(implicit ctx: Context): List[CaseDef] + def Match_scrutinee(self: Match)(implicit ctx: Context): Term + def Match_cases(self: Match)(implicit ctx: Context): List[CaseDef] - def Term_Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Term_Match - def Term_Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Term_Match + def Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match + def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ - type Term_Try <: Term + type Try <: Term - def matchTerm_Try(tree: Tree)(implicit ctx: Context): Option[Term_Try] + def matchTry(tree: Tree)(implicit ctx: Context): Option[Try] - def Term_Try_body(self: Term_Try)(implicit ctx: Context): Term - def Term_Try_cases(self: Term_Try)(implicit ctx: Context): List[CaseDef] - def Term_Try_finalizer(self: Term_Try)(implicit ctx: Context): Option[Term] + def Try_body(self: Try)(implicit ctx: Context): Term + def Try_cases(self: Try)(implicit ctx: Context): List[CaseDef] + def Try_finalizer(self: Try)(implicit ctx: Context): Option[Term] - def Term_Try_apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Term_Try - def Term_Try_copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Term_Try + def Try_apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try + def Try_copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try /** Tree representing a `return` in the source code */ - type Term_Return <: Term + type Return <: Term - def matchTerm_Return(tree: Tree)(implicit ctx: Context): Option[Term_Return] + def matchReturn(tree: Tree)(implicit ctx: Context): Option[Return] - def Term_Return_expr(self: Term_Return)(implicit ctx: Context): Term + def Return_expr(self: Return)(implicit ctx: Context): Term - def Term_Return_apply(expr: Term)(implicit ctx: Context): Term_Return - def Term_Return_copy(original: Tree)(expr: Term)(implicit ctx: Context): Term_Return + def Return_apply(expr: Term)(implicit ctx: Context): Return + def Return_copy(original: Tree)(expr: Term)(implicit ctx: Context): Return /** Tree representing a variable argument list in the source code */ - type Term_Repeated <: Term + type Repeated <: Term - def matchTerm_Repeated(tree: Tree)(implicit ctx: Context): Option[Term_Repeated] + def matchRepeated(tree: Tree)(implicit ctx: Context): Option[Repeated] - def Term_Repeated_elems(self: Term_Repeated)(implicit ctx: Context): List[Term] - def Term_Repeated_elemtpt(self: Term_Repeated)(implicit ctx: Context): TypeTree + def Repeated_elems(self: Repeated)(implicit ctx: Context): List[Term] + def Repeated_elemtpt(self: Repeated)(implicit ctx: Context): TypeTree - def Term_Repeated_apply(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Term_Repeated - def Term_Repeated_copy(original: Tree)(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Term_Repeated + def Repeated_apply(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Repeated + def Repeated_copy(original: Tree)(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Repeated /** Tree representing the scope of an inlined tree */ - type Term_Inlined <: Term + type Inlined <: Term - def matchTerm_Inlined(tree: Tree)(implicit ctx: Context): Option[Term_Inlined] + def matchInlined(tree: Tree)(implicit ctx: Context): Option[Inlined] - def Term_Inlined_call(self: Term_Inlined)(implicit ctx: Context): Option[TermOrTypeTree] - def Term_Inlined_bindings(self: Term_Inlined)(implicit ctx: Context): List[Definition] - def Term_Inlined_body(self: Term_Inlined)(implicit ctx: Context): Term + def Inlined_call(self: Inlined)(implicit ctx: Context): Option[TermOrTypeTree] + def Inlined_bindings(self: Inlined)(implicit ctx: Context): List[Definition] + def Inlined_body(self: Inlined)(implicit ctx: Context): Term - def Term_Inlined_apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Term_Inlined - def Term_Inlined_copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Term_Inlined + def Inlined_apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined + def Inlined_copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ - type Term_SelectOuter <: Term + type SelectOuter <: Term - def matchTerm_SelectOuter(tree: Tree)(implicit ctx: Context): Option[Term_SelectOuter] + def matchSelectOuter(tree: Tree)(implicit ctx: Context): Option[SelectOuter] - def Term_SelectOuter_qualifier(self: Term_SelectOuter)(implicit ctx: Context): Term - def Term_SelectOuter_level(self: Term_SelectOuter)(implicit ctx: Context): Int - def Term_SelectOuter_tpe(self: Term_SelectOuter)(implicit ctx: Context): Type + def SelectOuter_qualifier(self: SelectOuter)(implicit ctx: Context): Term + def SelectOuter_level(self: SelectOuter)(implicit ctx: Context): Int + def SelectOuter_tpe(self: SelectOuter)(implicit ctx: Context): Type - def Term_SelectOuter_apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): Term_SelectOuter - def Term_SelectOuter_copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): Term_SelectOuter + def SelectOuter_apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter + def SelectOuter_copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter /** Tree representing a while loop */ - type Term_While <: Term + type While <: Term - def matchTerm_While(tree: Tree)(implicit ctx: Context): Option[Term_While] + def matchWhile(tree: Tree)(implicit ctx: Context): Option[While] - def Term_While_cond(self: Term_While)(implicit ctx: Context): Term - def Term_While_body(self: Term_While)(implicit ctx: Context): Term + def While_cond(self: While)(implicit ctx: Context): Term + def While_body(self: While)(implicit ctx: Context): Term - def Term_While_apply(cond: Term, body: Term)(implicit ctx: Context): Term_While - def Term_While_copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): Term_While + def While_apply(cond: Term, body: Term)(implicit ctx: Context): While + def While_copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): While // // CASES diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index 3c4091693ce8..d0436d84961a 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -200,14 +200,14 @@ trait TreeOps extends Core { object IsIdent { /** Matches any Ident and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Ident] = kernel.matchTerm_Ident(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Ident] = kernel.matchIdent(tree) } object Ref { /** Create a reference tree */ def apply(sym: Symbol)(implicit ctx: Context): Ref = - kernel.Term_Ref_apply(sym) + kernel.Ref_apply(sym) // TODO def copy(original: Tree)(name: String)(implicit ctx: Context): Ref @@ -216,19 +216,19 @@ trait TreeOps extends Core { /** Scala term identifier */ object Ident { def apply(tmref: TermRef)(implicit ctx: Context): Term = - kernel.Term_Ident_apply(tmref) + kernel.Ident_apply(tmref) def copy(original: Tree)(name: String)(implicit ctx: Context): Ident = - kernel.Term_Ident_copy(original)(name) + kernel.Ident_copy(original)(name) /** Matches a term identifier and returns its name */ def unapply(tree: Tree)(implicit ctx: Context): Option[String] = - kernel.matchTerm_Ident(tree).map(_.name) + kernel.matchIdent(tree).map(_.name) } object IsSelect { /** Matches any Select and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Select] = kernel.matchTerm_Select(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Select] = kernel.matchSelect(tree) } /** Scala term selection */ @@ -240,24 +240,24 @@ trait TreeOps extends Core { * in that case. */ def unique(qualifier: Term, name: String)(implicit ctx: Context): Select = - kernel.Term_Select_unique(qualifier, name) + kernel.Select_unique(qualifier, name) // TODO rename, this returns an Apply and not a Select /** Call an overloaded method with the given type and term parameters */ def overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term])(implicit ctx: Context): Apply = - kernel.Term_Select_overloaded(qualifier, name, targs, args) + kernel.Select_overloaded(qualifier, name, targs, args) def copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Select = - kernel.Term_Select_copy(original)(qualifier, name) + kernel.Select_copy(original)(qualifier, name) /** Matches `.` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, String)] = - kernel.matchTerm_Select(tree).map(x => (x.qualifier, x.name)) + kernel.matchSelect(tree).map(x => (x.qualifier, x.name)) } object IsLiteral { /** Matches any Literal and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Literal] = kernel.matchTerm_Literal(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Literal] = kernel.matchLiteral(tree) } /** Scala literal constant */ @@ -265,19 +265,19 @@ trait TreeOps extends Core { /** Create a literal constant */ def apply(constant: Constant)(implicit ctx: Context): Literal = - kernel.Term_Literal_apply(constant) + kernel.Literal_apply(constant) def copy(original: Tree)(constant: Constant)(implicit ctx: Context): Literal = - kernel.Term_Literal_copy(original)(constant) + kernel.Literal_copy(original)(constant) /** Matches a literal constant */ def unapply(tree: Tree)(implicit ctx: Context): Option[Constant] = - kernel.matchTerm_Literal(tree).map(_.constant) + kernel.matchLiteral(tree).map(_.constant) } object IsThis { /** Matches any This and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[This] = kernel.matchTerm_This(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[This] = kernel.matchThis(tree) } /** Scala `this` or `this[id]` */ @@ -285,20 +285,20 @@ trait TreeOps extends Core { /** Create a `this[` */ def apply(cls: ClassSymbol)(implicit ctx: Context): This = - kernel.Term_This_apply(cls) + kernel.This_apply(cls) def copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): This = - kernel.Term_This_copy(original)(qual) + kernel.This_copy(original)(qual) /** Matches `this[` */ def unapply(tree: Tree)(implicit ctx: Context): Option[Option[Id]] = - kernel.matchTerm_This(tree).map(_.id) + kernel.matchThis(tree).map(_.id) } object IsNew { /** Matches any New and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[New] = kernel.matchTerm_New(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[New] = kernel.matchNew(tree) } /** Scala `new` */ @@ -306,19 +306,19 @@ trait TreeOps extends Core { /** Create a `new ` */ def apply(tpt: TypeTree)(implicit ctx: Context): New = - kernel.Term_New_apply(tpt) + kernel.New_apply(tpt) def copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): New = - kernel.Term_New_copy(original)(tpt) + kernel.New_copy(original)(tpt) /** Matches a `new ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[TypeTree] = - kernel.matchTerm_New(tree).map(_.tpt) + kernel.matchNew(tree).map(_.tpt) } object IsNamedArg { /** Matches any NamedArg and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[NamedArg] = kernel.matchTerm_NamedArg(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[NamedArg] = kernel.matchNamedArg(tree) } /** Scala named argument `x = y` in argument position */ @@ -326,20 +326,20 @@ trait TreeOps extends Core { /** Create a named argument ` = ` */ def apply(name: String, arg: Term)(implicit ctx: Context): NamedArg = - kernel.Term_NamedArg_apply(name, arg) + kernel.NamedArg_apply(name, arg) def copy(original: NamedArg)(name: String, arg: Term)(implicit ctx: Context): NamedArg = - kernel.Term_NamedArg_copy(original)(name, arg) + kernel.NamedArg_copy(original)(name, arg) /** Matches a named argument ` = ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(String, Term)] = - kernel.matchTerm_NamedArg(tree).map(x => (x.name, x.value)) + kernel.matchNamedArg(tree).map(x => (x.name, x.value)) } object IsApply { /** Matches any Apply and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Apply] = kernel.matchTerm_Apply(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Apply] = kernel.matchApply(tree) } /** Scala parameter application */ @@ -347,20 +347,20 @@ trait TreeOps extends Core { /** Create a function application `()` */ def apply(fun: Term, args: List[Term])(implicit ctx: Context): Apply = - kernel.Term_Apply_apply(fun, args) + kernel.Apply_apply(fun, args) def copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Apply = - kernel.Term_Apply_copy(original)(fun, args) + kernel.Apply_copy(original)(fun, args) /** Matches a function application `()` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[Term])] = - kernel.matchTerm_Apply(tree).map(x => (x.fun, x.args)) + kernel.matchApply(tree).map(x => (x.fun, x.args)) } object IsTypeApply { /** Matches any TypeApply and returns it */ def unapply(tree: Tree)(implicit ctx: Context): Option[TypeApply] = - kernel.matchTerm_TypeApply(tree) + kernel.matchTypeApply(tree) } /** Scala type parameter application */ @@ -368,20 +368,20 @@ trait TreeOps extends Core { /** Create a function type application `[]` */ def apply(fun: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = - kernel.Term_TypeApply_apply(fun, args) + kernel.TypeApply_apply(fun, args) def copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = - kernel.Term_TypeApply_copy(original)(fun, args) + kernel.TypeApply_copy(original)(fun, args) /** Matches a function type application `[]` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[TypeTree])] = - kernel.matchTerm_TypeApply(tree).map(x => (x.fun, x.args)) + kernel.matchTypeApply(tree).map(x => (x.fun, x.args)) } object IsSuper { /** Matches any Super and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Super] = kernel.matchTerm_Super(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Super] = kernel.matchSuper(tree) } /** Scala `x.super` or `x.super[id]` */ @@ -389,19 +389,19 @@ trait TreeOps extends Core { /** Creates a `.super[` */ def apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = - kernel.Term_Super_apply(qual, mix) + kernel.Super_apply(qual, mix) def copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = - kernel.Term_Super_copy(original)(qual, mix) + kernel.Super_copy(original)(qual, mix) /** Matches a `.super[` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Option[Id])] = - kernel.matchTerm_Super(tree).map(x => (x.qualifier, x.id)) + kernel.matchSuper(tree).map(x => (x.qualifier, x.id)) } object IsTyped { /** Matches any Typed and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Typed] = kernel.matchTerm_Typed(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Typed] = kernel.matchTyped(tree) } /** Scala ascription `x: T` */ @@ -409,20 +409,20 @@ trait TreeOps extends Core { /** Create a type ascription `: ` */ def apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = - kernel.Term_Typed_apply(expr, tpt) + kernel.Typed_apply(expr, tpt) def copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = - kernel.Term_Typed_copy(original)(expr, tpt) + kernel.Typed_copy(original)(expr, tpt) /** Matches `: ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, TypeTree)] = - kernel.matchTerm_Typed(tree).map(x => (x.expr, x.tpt)) + kernel.matchTyped(tree).map(x => (x.expr, x.tpt)) } object IsAssign { /** Matches any Assign and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Assign] = kernel.matchTerm_Assign(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Assign] = kernel.matchAssign(tree) } /** Scala assign `x = y` */ @@ -430,19 +430,19 @@ trait TreeOps extends Core { /** Create an assignment ` = ` */ def apply(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = - kernel.Term_Assign_apply(lhs, rhs) + kernel.Assign_apply(lhs, rhs) def copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = - kernel.Term_Assign_copy(original)(lhs, rhs) + kernel.Assign_copy(original)(lhs, rhs) /** Matches an assignment ` = ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term)] = - kernel.matchTerm_Assign(tree).map(x => (x.lhs, x.rhs)) + kernel.matchAssign(tree).map(x => (x.lhs, x.rhs)) } object IsBlock { /** Matches any Block and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Block] = kernel.matchTerm_Block(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Block] = kernel.matchBlock(tree) } /** Scala code block `{ stat0; ...; statN; expr }` term */ @@ -450,36 +450,36 @@ trait TreeOps extends Core { /** Creates a block `{ ; }` */ def apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = - kernel.Term_Block_apply(stats, expr) + kernel.Block_apply(stats, expr) def copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = - kernel.Term_Block_copy(original)(stats, expr) + kernel.Block_copy(original)(stats, expr) /** Matches a block `{ ; }` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Statement], Term)] = - kernel.matchTerm_Block(tree).map(x => (x.statements, x.expr)) + kernel.matchBlock(tree).map(x => (x.statements, x.expr)) } object IsLambda { /** Matches any Lambda and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Lambda] = kernel.matchTerm_Lambda(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Lambda] = kernel.matchLambda(tree) } object Lambda { def apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Lambda = - kernel.Term_Lambda_apply(meth, tpt) + kernel.Lambda_apply(meth, tpt) def copy(original: Tree)(meth: Tree, tpt: Option[TypeTree])(implicit ctx: Context): Lambda = - kernel.Term_Lambda_copy(original)(meth, tpt) + kernel.Lambda_copy(original)(meth, tpt) def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Option[TypeTree])] = - kernel.matchTerm_Lambda(tree).map(x => (x.meth, x.tptOpt)) + kernel.matchLambda(tree).map(x => (x.meth, x.tptOpt)) } object IsIf { /** Matches any If and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[If] = kernel.matchTerm_If(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[If] = kernel.matchIf(tree) } /** Scala `if`/`else` term */ @@ -487,20 +487,20 @@ trait TreeOps extends Core { /** Create an if/then/else `if () else ` */ def apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = - kernel.Term_If_apply(cond, thenp, elsep) + kernel.If_apply(cond, thenp, elsep) def copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = - kernel.Term_If_copy(original)(cond, thenp, elsep) + kernel.If_copy(original)(cond, thenp, elsep) /** Matches an if/then/else `if () else ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term, Term)] = - kernel.matchTerm_If(tree).map(x => (x.cond, x.thenp, x.elsep)) + kernel.matchIf(tree).map(x => (x.cond, x.thenp, x.elsep)) } object IsMatch { /** Matches any Match and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Match] = kernel.matchTerm_Match(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Match] = kernel.matchMatch(tree) } /** Scala `match` term */ @@ -508,20 +508,20 @@ trait TreeOps extends Core { /** Creates a pattern match ` match { }` */ def apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = - kernel.Term_Match_apply(selector, cases) + kernel.Match_apply(selector, cases) def copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = - kernel.Term_Match_copy(original)(selector, cases) + kernel.Match_copy(original)(selector, cases) /** Matches a pattern match ` match { }` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[CaseDef])] = - kernel.matchTerm_Match(tree).map(x => (x.scrutinee, x.cases)) + kernel.matchMatch(tree).map(x => (x.scrutinee, x.cases)) } object IsTry { /** Matches any Try and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Try] = kernel.matchTerm_Try(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Try] = kernel.matchTry(tree) } /** Scala `try`/`catch`/`finally` term */ @@ -529,20 +529,20 @@ trait TreeOps extends Core { /** Create a try/catch `try catch { } finally ` */ def apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try = - kernel.Term_Try_apply(expr, cases, finalizer) + kernel.Try_apply(expr, cases, finalizer) def copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term])(implicit ctx: Context): Try = - kernel.Term_Try_copy(original)(expr, cases, finalizer) + kernel.Try_copy(original)(expr, cases, finalizer) /** Matches a try/catch `try catch { } finally ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, List[CaseDef], Option[Term])] = - kernel.matchTerm_Try(tree).map(x => (x.body, x.cases, x.finalizer)) + kernel.matchTry(tree).map(x => (x.body, x.cases, x.finalizer)) } object IsReturn { /** Matches any Return and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Return] = kernel.matchTerm_Return(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Return] = kernel.matchReturn(tree) } /** Scala local `return` */ @@ -550,195 +550,195 @@ trait TreeOps extends Core { /** Creates `return ` */ def apply(expr: Term)(implicit ctx: Context): Return = - kernel.Term_Return_apply(expr) + kernel.Return_apply(expr) def copy(original: Tree)(expr: Term)(implicit ctx: Context): Return = - kernel.Term_Return_copy(original)(expr) + kernel.Return_copy(original)(expr) /** Matches `return ` */ def unapply(tree: Tree)(implicit ctx: Context): Option[Term] = - kernel.matchTerm_Return(tree).map(_.expr) + kernel.matchReturn(tree).map(_.expr) } object IsRepeated { /** Matches any Repeated and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Repeated] = kernel.matchTerm_Repeated(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Repeated] = kernel.matchRepeated(tree) } object Repeated { def apply(elems: List[Term], tpt: TypeTree)(implicit ctx: Context): Repeated = - kernel.Term_Repeated_apply(elems, tpt) + kernel.Repeated_apply(elems, tpt) def copy(original: Tree)(elems: List[Term], tpt: TypeTree)(implicit ctx: Context): Repeated = - kernel.Term_Repeated_copy(original)(elems, tpt) + kernel.Repeated_copy(original)(elems, tpt) def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Term], TypeTree)] = - kernel.matchTerm_Repeated(tree).map(x => (x.elems, x.elemtpt)) + kernel.matchRepeated(tree).map(x => (x.elems, x.elemtpt)) } object IsInlined { /** Matches any Inlined and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[Inlined] = kernel.matchTerm_Inlined(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[Inlined] = kernel.matchInlined(tree) } object Inlined { def apply(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined = - kernel.Term_Inlined_apply(call, bindings, expansion) + kernel.Inlined_apply(call, bindings, expansion) def copy(original: Tree)(call: Option[TermOrTypeTree], bindings: List[Definition], expansion: Term)(implicit ctx: Context): Inlined = - kernel.Term_Inlined_copy(original)(call, bindings, expansion) + kernel.Inlined_copy(original)(call, bindings, expansion) def unapply(tree: Tree)(implicit ctx: Context): Option[(Option[TermOrTypeTree], List[Definition], Term)] = - kernel.matchTerm_Inlined(tree).map(x => (x.call, x.bindings, x.body)) + kernel.matchInlined(tree).map(x => (x.call, x.bindings, x.body)) } object IsSelectOuter { /** Matches any SelectOuter and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[SelectOuter] = kernel.matchTerm_SelectOuter(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[SelectOuter] = kernel.matchSelectOuter(tree) } object SelectOuter { def apply(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter = - kernel.Term_SelectOuter_apply(qualifier, name, levels) + kernel.SelectOuter_apply(qualifier, name, levels) def copy(original: Tree)(qualifier: Term, name: String, levels: Int)(implicit ctx: Context): SelectOuter = - kernel.Term_SelectOuter_copy(original)(qualifier, name, levels) + kernel.SelectOuter_copy(original)(qualifier, name, levels) def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Int, Type)] = // TODO homogenize order of parameters - kernel.matchTerm_SelectOuter(tree).map(x => (x.qualifier, x.level, x.tpe)) + kernel.matchSelectOuter(tree).map(x => (x.qualifier, x.level, x.tpe)) } object IsWhile { /** Matches any While and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[While] = kernel.matchTerm_While(tree) + def unapply(tree: Tree)(implicit ctx: Context): Option[While] = kernel.matchWhile(tree) } object While { /** Creates a while loop `while () ` and returns (, ) */ def apply(cond: Term, body: Term)(implicit ctx: Context): While = - kernel.Term_While_apply(cond, body) + kernel.While_apply(cond, body) def copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): While = - kernel.Term_While_copy(original)(cond, body) + kernel.While_copy(original)(cond, body) /** Extractor for while loops. Matches `while () ` and returns (, ) */ def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Term)] = - kernel.matchTerm_While(tree).map(x => (x.cond, x.body)) + kernel.matchWhile(tree).map(x => (x.cond, x.body)) } } - implicit class Term_IdentAPI(self: Term.Ident) { - def name(implicit ctx: Context): String = kernel.Term_Ident_name(self) + implicit class IdentAPI(self: Term.Ident) { + def name(implicit ctx: Context): String = kernel.Ident_name(self) } - implicit class Term_SelectAPI(self: Term.Select) { - def qualifier(implicit ctx: Context): Term = kernel.Term_Select_qualifier(self) - def name(implicit ctx: Context): String = kernel.Term_Select_name(self) - def signature(implicit ctx: Context): Option[Signature] = kernel.Term_Select_signature(self) + implicit class SelectAPI(self: Term.Select) { + def qualifier(implicit ctx: Context): Term = kernel.Select_qualifier(self) + def name(implicit ctx: Context): String = kernel.Select_name(self) + def signature(implicit ctx: Context): Option[Signature] = kernel.Select_signature(self) } - implicit class Term_LiteralAPI(self: Term.Literal) { - def constant(implicit ctx: Context): Constant = kernel.Term_Literal_constant(self) + implicit class LiteralAPI(self: Term.Literal) { + def constant(implicit ctx: Context): Constant = kernel.Literal_constant(self) } - implicit class Term_ThisAPI(self: Term.This) { - def id(implicit ctx: Context): Option[Id] = kernel.Term_This_id(self) + implicit class ThisAPI(self: Term.This) { + def id(implicit ctx: Context): Option[Id] = kernel.This_id(self) } - implicit class Term_NewAPI(self: Term.New) { - def tpt(implicit ctx: Context): TypeTree = kernel.Term_New_tpt(self) + implicit class NewAPI(self: Term.New) { + def tpt(implicit ctx: Context): TypeTree = kernel.New_tpt(self) } - implicit class Term_NamedArgAPI(self: Term.NamedArg) { - def name(implicit ctx: Context): String = kernel.Term_NamedArg_name(self) - def value(implicit ctx: Context): Term = kernel.Term_NamedArg_value(self) + implicit class NamedArgAPI(self: Term.NamedArg) { + def name(implicit ctx: Context): String = kernel.NamedArg_name(self) + def value(implicit ctx: Context): Term = kernel.NamedArg_value(self) } - implicit class Term_ApplyAPI(self: Term.Apply) { - def fun(implicit ctx: Context): Term = kernel.Term_Apply_fun(self) - def args(implicit ctx: Context): List[Term] = kernel.Term_Apply_args(self) + implicit class ApplyAPI(self: Term.Apply) { + def fun(implicit ctx: Context): Term = kernel.Apply_fun(self) + def args(implicit ctx: Context): List[Term] = kernel.Apply_args(self) } - implicit class Term_TypeApplyAPI(self: Term.TypeApply) { - def fun(implicit ctx: Context): Term = kernel.Term_TypeApply_fun(self) - def args(implicit ctx: Context): List[TypeTree] = kernel.Term_TypeApply_args(self) + implicit class TypeApplyAPI(self: Term.TypeApply) { + def fun(implicit ctx: Context): Term = kernel.TypeApply_fun(self) + def args(implicit ctx: Context): List[TypeTree] = kernel.TypeApply_args(self) } - implicit class Term_SuperAPI(self: Term.Super) { - def qualifier(implicit ctx: Context): Term = kernel.Term_Super_qualifier(self) - def id(implicit ctx: Context): Option[Id] = kernel.Term_Super_id(self) + implicit class SuperAPI(self: Term.Super) { + def qualifier(implicit ctx: Context): Term = kernel.Super_qualifier(self) + def id(implicit ctx: Context): Option[Id] = kernel.Super_id(self) } - implicit class Term_TypedAPI(self: Term.Typed) { - def expr(implicit ctx: Context): Term = kernel.Term_Typed_expr(self) - def tpt(implicit ctx: Context): TypeTree = kernel.Term_Typed_tpt(self) + implicit class TypedAPI(self: Term.Typed) { + def expr(implicit ctx: Context): Term = kernel.Typed_expr(self) + def tpt(implicit ctx: Context): TypeTree = kernel.Typed_tpt(self) } - implicit class Term_AssignAPI(self: Term.Assign) { - def lhs(implicit ctx: Context): Term = kernel.Term_Assign_lhs(self) - def rhs(implicit ctx: Context): Term = kernel.Term_Assign_rhs(self) + implicit class AssignAPI(self: Term.Assign) { + def lhs(implicit ctx: Context): Term = kernel.Assign_lhs(self) + def rhs(implicit ctx: Context): Term = kernel.Assign_rhs(self) } - implicit class Term_BlockAPI(self: Term.Block) { - def statements(implicit ctx: Context): List[Statement] = kernel.Term_Block_statements(self) - def expr(implicit ctx: Context): Term = kernel.Term_Block_expr(self) + implicit class BlockAPI(self: Term.Block) { + def statements(implicit ctx: Context): List[Statement] = kernel.Block_statements(self) + def expr(implicit ctx: Context): Term = kernel.Block_expr(self) } - implicit class Term_LambdaAPI(self: Term.Lambda) { - def meth(implicit ctx: Context): Term = kernel.Term_Lambda_meth(self) - def tptOpt(implicit ctx: Context): Option[TypeTree] = kernel.Term_Lambda_tptOpt(self) + implicit class LambdaAPI(self: Term.Lambda) { + def meth(implicit ctx: Context): Term = kernel.Lambda_meth(self) + def tptOpt(implicit ctx: Context): Option[TypeTree] = kernel.Lambda_tptOpt(self) } - implicit class Term_IfAPI(self: Term.If) { - def cond(implicit ctx: Context): Term = kernel.Term_If_cond(self) - def thenp(implicit ctx: Context): Term = kernel.Term_If_thenp(self) - def elsep(implicit ctx: Context): Term = kernel.Term_If_elsep(self) + implicit class IfAPI(self: Term.If) { + def cond(implicit ctx: Context): Term = kernel.If_cond(self) + def thenp(implicit ctx: Context): Term = kernel.If_thenp(self) + def elsep(implicit ctx: Context): Term = kernel.If_elsep(self) } - implicit class Term_MatchAPI(self: Term.Match) { - def scrutinee(implicit ctx: Context): Term = kernel.Term_Match_scrutinee(self) - def cases(implicit ctx: Context): List[CaseDef] = kernel.Term_Match_cases(self) + implicit class MatchAPI(self: Term.Match) { + def scrutinee(implicit ctx: Context): Term = kernel.Match_scrutinee(self) + def cases(implicit ctx: Context): List[CaseDef] = kernel.Match_cases(self) } - implicit class Term_TryAPI(self: Term.Try) { - def body(implicit ctx: Context): Term = kernel.Term_Try_body(self) - def cases(implicit ctx: Context): List[CaseDef] = kernel.Term_Try_cases(self) - def finalizer(implicit ctx: Context): Option[Term] = kernel.Term_Try_finalizer(self) + implicit class TryAPI(self: Term.Try) { + def body(implicit ctx: Context): Term = kernel.Try_body(self) + def cases(implicit ctx: Context): List[CaseDef] = kernel.Try_cases(self) + def finalizer(implicit ctx: Context): Option[Term] = kernel.Try_finalizer(self) } - implicit class Term_ReturnAPI(self: Term.Return) { - def expr(implicit ctx: Context): Term = kernel.Term_Return_expr(self) + implicit class ReturnAPI(self: Term.Return) { + def expr(implicit ctx: Context): Term = kernel.Return_expr(self) } - implicit class Term_RepeatedAPI(self: Term.Repeated) { - def elems(implicit ctx: Context): List[Term] = kernel.Term_Repeated_elems(self) - def elemtpt(implicit ctx: Context): TypeTree = kernel.Term_Repeated_elemtpt(self) + implicit class RepeatedAPI(self: Term.Repeated) { + def elems(implicit ctx: Context): List[Term] = kernel.Repeated_elems(self) + def elemtpt(implicit ctx: Context): TypeTree = kernel.Repeated_elemtpt(self) } - implicit class Term_InlinedAPI(self: Term.Inlined) { - def call(implicit ctx: Context): Option[TermOrTypeTree] = kernel.Term_Inlined_call(self) - def bindings(implicit ctx: Context): List[Definition] = kernel.Term_Inlined_bindings(self) - def body(implicit ctx: Context): Term = kernel.Term_Inlined_body(self) + implicit class InlinedAPI(self: Term.Inlined) { + def call(implicit ctx: Context): Option[TermOrTypeTree] = kernel.Inlined_call(self) + def bindings(implicit ctx: Context): List[Definition] = kernel.Inlined_bindings(self) + def body(implicit ctx: Context): Term = kernel.Inlined_body(self) } - implicit class Term_SelectOuterAPI(self: Term.SelectOuter) { - def qualifier(implicit ctx: Context): Term = kernel.Term_SelectOuter_qualifier(self) - def level(implicit ctx: Context): Int = kernel.Term_SelectOuter_level(self) - def tpe(implicit ctx: Context): Type = kernel.Term_SelectOuter_tpe(self) + implicit class SelectOuterAPI(self: Term.SelectOuter) { + def qualifier(implicit ctx: Context): Term = kernel.SelectOuter_qualifier(self) + def level(implicit ctx: Context): Int = kernel.SelectOuter_level(self) + def tpe(implicit ctx: Context): Type = kernel.SelectOuter_tpe(self) } - implicit class Term_WhileAPI(self: Term.While) { - def cond(implicit ctx: Context): Term = kernel.Term_While_cond(self) - def body(implicit ctx: Context): Term = kernel.Term_While_body(self) + implicit class WhileAPI(self: Term.While) { + def cond(implicit ctx: Context): Term = kernel.While_cond(self) + def body(implicit ctx: Context): Term = kernel.While_body(self) } } From cf304cb81d65d7e7d69b7b9441dc22aa2a545b5b Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 6 Mar 2019 12:16:51 +0100 Subject: [PATCH 17/17] Implement CommentOps in kernel --- .../dotty/tools/dotc/tastyreflect/CommentOpsImpl.scala | 10 ---------- .../src/dotty/tools/dotc/tastyreflect/CoreImpl.scala | 8 -------- .../src/dotty/tools/dotc/tastyreflect/KernelImpl.scala | 4 ++++ .../dotty/tools/dotc/tastyreflect/ReflectionImpl.scala | 2 +- library/src/scala/tasty/reflect/CommentOps.scala | 9 ++++----- library/src/scala/tasty/reflect/Kernel.scala | 4 ++++ 6 files changed, 13 insertions(+), 24 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/CommentOpsImpl.scala delete mode 100644 compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/CommentOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CommentOpsImpl.scala deleted file mode 100644 index 6c6fdebd4524..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CommentOpsImpl.scala +++ /dev/null @@ -1,10 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -trait CommentOpsImpl extends scala.tasty.reflect.CommentOps with CoreImpl { - - implicit def CommentDeco(com: Comment): CommentAPI = new CommentAPI { - override def raw: String = com.raw - override def expanded: Option[String] = com.expanded - override def usecases: List[(String, Option[DefDef])] = com.usecases.map { uc => (uc.code, uc.tpdCode) } - } -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala deleted file mode 100644 index 7fab0b9f03c2..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala +++ /dev/null @@ -1,8 +0,0 @@ -package dotty.tools.dotc -package tastyreflect - -trait CoreImpl extends scala.tasty.reflect.Core { - - val kernel: KernelImpl - -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index e6526f415a68..6fe0505f1db0 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -1313,6 +1313,10 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Comment = core.Comments.Comment + def Comment_raw(self: Comment): String = self.raw + def Comment_expanded(self: Comment): Option[String] = self.expanded + def Comment_usecases(self: Comment): List[(String, Option[DefDef])] = self.usecases.map { uc => (uc.code, uc.tpdCode) } + // // CONSTANTS // diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index e496ed2e01c5..6ccf711ad9fc 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -9,7 +9,7 @@ object ReflectionImpl { apply(rootContext, SourcePosition(rootContext.source, Spans.NoSpan)) def apply(rootContext: Contexts.Context, rootPosition: SourcePosition): scala.tasty.Reflection { val kernel: KernelImpl } = { - class ReflectionImpl(val kernel: KernelImpl) extends scala.tasty.Reflection with CoreImpl with CommentOpsImpl + class ReflectionImpl(val kernel: KernelImpl) extends scala.tasty.Reflection new ReflectionImpl(new KernelImpl(rootContext, rootPosition)) } diff --git a/library/src/scala/tasty/reflect/CommentOps.scala b/library/src/scala/tasty/reflect/CommentOps.scala index 9ba18317e85f..beec35df382c 100644 --- a/library/src/scala/tasty/reflect/CommentOps.scala +++ b/library/src/scala/tasty/reflect/CommentOps.scala @@ -2,18 +2,17 @@ package scala.tasty.reflect trait CommentOps extends Core { - trait CommentAPI { + implicit class CommentAPI(self: Comment) { /** Raw comment string */ - def raw: String + def raw: String = kernel.Comment_raw(self) /** Expanded comment string, if any */ - def expanded: Option[String] + def expanded: Option[String] = kernel.Comment_expanded(self) /** List of usecases and their corresponding trees, if any */ - def usecases: List[(String, Option[DefDef])] + def usecases: List[(String, Option[DefDef])] = kernel.Comment_usecases(self) } - implicit def CommentDeco(comment: Comment): CommentAPI } diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index ecedb5d6f7e7..4d6a6d031bbf 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -1072,6 +1072,10 @@ trait Kernel { /** Comment */ type Comment <: AnyRef + def Comment_raw(self: Comment): String + def Comment_expanded(self: Comment): Option[String] + def Comment_usecases(self: Comment): List[(String, Option[DefDef])] + // // CONSTANTS //