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..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(new 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 ae4541865c80..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 = new 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 e63ab7a09ad4..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) - new 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/CaseDefOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala deleted file mode 100644 index 60b566c9fae8..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CaseDefOpsImpl.scala +++ /dev/null @@ -1,37 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -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) - - 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) - } - - 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) - - 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/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/ConstantOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala deleted file mode 100644 index b467f60d04ce..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ConstantOpsImpl.scala +++ /dev/null @@ -1,113 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -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 { - 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/ContextOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala deleted file mode 100644 index 256389aa4aa6..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ContextOpsImpl.scala +++ /dev/null @@ -1,13 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -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/CoreImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala deleted file mode 100644 index 83220030ac55..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala +++ /dev/null @@ -1,132 +0,0 @@ -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 - - type Flags = core.Flags.FlagSet -} 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 ce422cd4a376..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala +++ /dev/null @@ -1,54 +0,0 @@ -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/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 17330bae1a6b..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/IdOpsImpl.scala +++ /dev/null @@ -1,16 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -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/ImportSelectorOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala deleted file mode 100644 index 8300b213d93f..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ImportSelectorOpsImpl.scala +++ /dev/null @@ -1,30 +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 { - - 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 new file mode 100644 index 000000000000..6fe0505f1db0 --- /dev/null +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -0,0 +1,1732 @@ +package dotty.tools.dotc +package tastyreflect + +import dotty.tools.dotc.ast.{Trees, tpd, untpd} +import dotty.tools.dotc.ast.tpd.TreeOps +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 +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(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 + // + + 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 + + def Settings_color(self: Settings): Boolean = self.color.value(rootContext) == "always" + + // + // 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 matchPackageClause(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): Ref = self.pid + def PackageClause_stats(self: PackageClause)(implicit ctx: Context): List[Tree] = self.stats + + 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: Ref, stats: List[Tree])(implicit ctx: Context): PackageClause = + tpd.cpy.PackageDef(original)(pid, stats) + + type Statement = tpd.Tree + + def matchStatement(tree: Tree)(implicit ctx: Context): Option[Statement] = tree match { + case tree if tree.isTerm => Some(tree) + case _ => matchDefinition(tree) + } + + type Import = tpd.Import + + def matchImport(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 matchDefinition(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 matchPackageDef(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] = { + 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 matchClassDef(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]] + 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] + + 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 matchTypeDef(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 matchDefDef(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 matchValDef(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 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 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 + 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 Ref = tpd.RefTree + + def Ref_apply(sym: Symbol)(implicit ctx: Context): Ref = + withDefaultPos(ctx => tpd.ref(sym)(ctx).asInstanceOf[tpd.RefTree]) + + type Ident = tpd.Ident + + def matchIdent(x: Term)(implicit ctx: Context): Option[Ident] = x match { + case x: tpd.Ident if x.isTerm => Some(x) + case _ => None + } + + def Ident_name(self: Ident)(implicit ctx: Context): String = self.name.show + + def Ident_apply(tmref: TermRef)(implicit ctx: Context): Term = + withDefaultPos(implicit ctx => tpd.ref(tmref).asInstanceOf[Term]) + + def Ident_copy(original: Tree)(name: String)(implicit ctx: Context): Ident = + tpd.cpy.Ident(original)(name.toTermName) + + type Select = tpd.Select + + def matchSelect(x: Term)(implicit ctx: Context): Option[Select] = x match { + case x: tpd.Select if x.isTerm => Some(x) + case _ => None + } + + 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 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 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 Select_copy(original: Tree)(qualifier: Term, name: String)(implicit ctx: Context): Select = + tpd.cpy.Select(original)(qualifier, name.toTermName) + + type Literal = tpd.Literal + + def matchLiteral(x: Term)(implicit ctx: Context): Option[Literal] = x match { + case x: tpd.Literal => Some(x) + case _ => None + } + + def Literal_constant(self: Literal)(implicit ctx: Context): Constant = self.const + + def Literal_apply(constant: Constant)(implicit ctx: Context): Literal = + withDefaultPos(ctx => tpd.Literal(constant)(ctx)) + + def Literal_copy(original: Tree)(constant: Constant)(implicit ctx: Context): Literal = + tpd.cpy.Literal(original)(constant) + + type This = tpd.This + + def matchThis(x: Term)(implicit ctx: Context): Option[This] = x match { + case x: tpd.This => Some(x) + case _ => None + } + + def This_id(self: This)(implicit ctx: Context): Option[Id] = optional(self.qual) + + def This_apply(cls: ClassSymbol)(implicit ctx: Context): This = + withDefaultPos(ctx => tpd.This(cls)(ctx)) + + def This_copy(original: Tree)(qual: Option[Id])(implicit ctx: Context): This = + tpd.cpy.This(original)(qual.getOrElse(untpd.EmptyTypeIdent)) + + type New = tpd.New + + def matchNew(x: Term)(implicit ctx: Context): Option[New] = x match { + case x: tpd.New => Some(x) + case _ => None + } + + def New_tpt(self: New)(implicit ctx: Context): TypeTree = self.tpt + + def New_apply(tpt: TypeTree)(implicit ctx: Context): New = withDefaultPos(ctx => tpd.New(tpt)(ctx)) + + def New_copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): New = + tpd.cpy.New(original)(tpt) + + type NamedArg = tpd.NamedArg + + 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 NamedArg_name(self: NamedArg)(implicit ctx: Context): String = self.name.toString + def NamedArg_value(self: NamedArg)(implicit ctx: Context): Term = self.arg + + def NamedArg_apply(name: String, arg: Term)(implicit ctx: Context): NamedArg = + withDefaultPos(ctx => tpd.NamedArg(name.toTermName, arg)(ctx)) + + def NamedArg_copy(tree: NamedArg)(name: String, arg: Term)(implicit ctx: Context): NamedArg = + tpd.cpy.NamedArg(tree)(name.toTermName, arg) + + type Apply = tpd.Apply + + def matchApply(x: Term)(implicit ctx: Context): Option[Apply] = x match { + case x: tpd.Apply => Some(x) + case _ => None + } + + def Apply_fun(self: Apply)(implicit ctx: Context): Term = self.fun + def Apply_args(self: Apply)(implicit ctx: Context): List[Term] = self.args + + + def Apply_apply(fn: Term, args: List[Term])(implicit ctx: Context): Apply = + withDefaultPos(ctx => tpd.Apply(fn, args)(ctx)) + + def Apply_copy(original: Tree)(fun: Term, args: List[Term])(implicit ctx: Context): Apply = + tpd.cpy.Apply(original)(fun, args) + + type TypeApply = tpd.TypeApply + + def matchTypeApply(x: Term)(implicit ctx: Context): Option[TypeApply] = x match { + case x: tpd.TypeApply => Some(x) + case _ => None + } + + def TypeApply_fun(self: TypeApply)(implicit ctx: Context): Term = self.fun + def TypeApply_args(self: TypeApply)(implicit ctx: Context): List[TypeTree] = self.args + + def TypeApply_apply(fn: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = + withDefaultPos(ctx => tpd.TypeApply(fn, args)(ctx)) + + def TypeApply_copy(original: Tree)(fun: Term, args: List[TypeTree])(implicit ctx: Context): TypeApply = + tpd.cpy.TypeApply(original)(fun, args) + + type Super = tpd.Super + + def matchSuper(x: Term)(implicit ctx: Context): Option[Super] = x match { + case x: tpd.Super => Some(x) + case _ => None + } + + 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 Super_apply(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = + withDefaultPos(ctx => tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), false, NoSymbol)(ctx)) + + def Super_copy(original: Tree)(qual: Term, mix: Option[Id])(implicit ctx: Context): Super = + tpd.cpy.Super(original)(qual, mix.getOrElse(untpd.EmptyTypeIdent)) + + type Typed = tpd.Typed + + def matchTyped(x: Term)(implicit ctx: Context): Option[Typed] = x match { + case x: tpd.Typed => Some(x) + case _ => None + } + + def Typed_expr(self: Typed)(implicit ctx: Context): Term = self.expr + def Typed_tpt(self: Typed)(implicit ctx: Context): TypeTree = self.tpt + + def Typed_apply(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = + withDefaultPos(ctx => tpd.Typed(expr, tpt)(ctx)) + + def Typed_copy(original: Tree)(expr: Term, tpt: TypeTree)(implicit ctx: Context): Typed = + tpd.cpy.Typed(original)(expr, tpt) + + type Assign = tpd.Assign + + def matchAssign(x: Term)(implicit ctx: Context): Option[Assign] = x match { + case x: tpd.Assign => Some(x) + case _ => None + } + + def Assign_lhs(self: Assign)(implicit ctx: Context): Term = self.lhs + def Assign_rhs(self: Assign)(implicit ctx: Context): Term = self.rhs + + def Assign_apply(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = + withDefaultPos(ctx => tpd.Assign(lhs, rhs)(ctx)) + + def Assign_copy(original: Tree)(lhs: Term, rhs: Term)(implicit ctx: Context): Assign = + tpd.cpy.Assign(original)(lhs, rhs) + + type Block = tpd.Block + + def matchBlock(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 + } + + def Block_statements(self: Block)(implicit ctx: Context): List[Statement] = self.stats + def Block_expr(self: Block)(implicit ctx: Context): Term = self.expr + + def Block_apply(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = + withDefaultPos(ctx => tpd.Block(stats, expr)(ctx)) + + def Block_copy(original: Tree)(stats: List[Statement], expr: Term)(implicit ctx: Context): Block = + tpd.cpy.Block(original)(stats, expr) + + type Inlined = tpd.Inlined + + def matchInlined(x: Term)(implicit ctx: Context): Option[Inlined] = x match { + case x: tpd.Inlined => Some(x) + case _ => None + } + + 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 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 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 Lambda = tpd.Closure + + def matchLambda(x: Term)(implicit ctx: Context): Option[Lambda] = x match { + case x: tpd.Closure => Some(x) + case _ => None + } + + 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 Lambda_apply(meth: Term, tpt: Option[TypeTree])(implicit ctx: Context): Lambda = + withDefaultPos(ctx => tpd.Closure(Nil, meth, tpt.getOrElse(tpd.EmptyTree))(ctx)) + + 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 If = tpd.If + + def matchIf(x: Term)(implicit ctx: Context): Option[If] = x match { + case x: tpd.If => Some(x) + case _ => None + } + + 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 If_apply(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = + withDefaultPos(ctx => tpd.If(cond, thenp, elsep)(ctx)) + + def If_copy(original: Tree)(cond: Term, thenp: Term, elsep: Term)(implicit ctx: Context): If = + tpd.cpy.If(original)(cond, thenp, elsep) + + type Match = tpd.Match + + def matchMatch(x: Term)(implicit ctx: Context): Option[Match] = x match { + case x: tpd.Match => Some(x) + case _ => None + } + + def Match_scrutinee(self: Match)(implicit ctx: Context): Term = self.selector + def Match_cases(self: Match)(implicit ctx: Context): List[CaseDef] = self.cases + + def Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = + withDefaultPos(ctx => tpd.Match(selector, cases)(ctx)) + + def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = + tpd.cpy.Match(original)(selector, cases) + + type Try = tpd.Try + + def matchTry(x: Term)(implicit ctx: Context): Option[Try] = x match { + case x: tpd.Try => Some(x) + case _ => None + } + + 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 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 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 Return = tpd.Return + + def matchReturn(x: Term)(implicit ctx: Context): Option[Return] = x match { + case x: tpd.Return => Some(x) + case _ => None + } + + def Return_expr(self: Return)(implicit ctx: Context): Term = self.expr + + def Return_apply(expr: Term)(implicit ctx: Context): Return = + withDefaultPos(ctx => tpd.Return(expr, ctx.owner)(ctx)) + + def Return_copy(original: Tree)(expr: Term)(implicit ctx: Context): Return = + tpd.cpy.Return(original)(expr, tpd.ref(ctx.owner)) + + type Repeated = tpd.SeqLiteral + + def matchRepeated(x: Term)(implicit ctx: Context): Option[Repeated] = x match { + case x: tpd.SeqLiteral => Some(x) + case _ => None + } + + def Repeated_elems(self: Repeated)(implicit ctx: Context): List[Term] = self.elems + def Repeated_elemtpt(self: Repeated)(implicit ctx: Context): TypeTree = self.elemtpt + + def Repeated_apply(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Repeated = + withDefaultPos(ctx => tpd.SeqLiteral(elems, elemtpt)(ctx)) + + def Repeated_copy(original: Tree)(elems: List[Term], elemtpt: TypeTree)(implicit ctx: Context): Repeated = + tpd.cpy.SeqLiteral(original)(elems, elemtpt) + + type SelectOuter = tpd.Select + + def matchSelectOuter(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 + } + + 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 SelectOuter_tpe(self: SelectOuter)(implicit ctx: Context): Type = self.tpe.stripTypeVar + + 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 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 While = tpd.WhileDo + + def matchWhile(x: Term)(implicit ctx: Context): Option[While] = x match { + case x: tpd.WhileDo => Some(x) + case _ => None + } + + def While_cond(self: While)(implicit ctx: Context): Term = self.cond + def While_body(self: While)(implicit ctx: Context): Term = self.body + + def While_apply(cond: Term, body: Term)(implicit ctx: Context): While = + withDefaultPos(ctx => tpd.WhileDo(cond, body)(ctx)) + + def While_copy(original: Tree)(cond: Term, body: Term)(implicit ctx: Context): While = + tpd.cpy.WhileDo(original)(cond, 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 + + 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 + // + + 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 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) + 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 matchPattern_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 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 + } + + 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 + } + + type Alternatives = tpd.Alternative + + def matchPattern_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 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 + } + + 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 + // + + type TypeOrBoundsTree = tpd.Tree + + def TypeOrBoundsTree_tpe(self: TypeOrBoundsTree)(implicit ctx: Context): Type = self.tpe.stripTypeVar + + type TypeTree = tpd.Tree + + 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 matchTypeTreeNotTerm(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 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 + } + + def TypeTree_Inferred_apply(tpe: Type)(implicit ctx: Context): TypeTree_Inferred = withDefaultPos(ctx => tpd.TypeTree(tpe)(ctx)) + + type TypeTree_Ident = tpd.Ident + + def matchTypeTree_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 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 + } + + 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 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 + } + + 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 matchTypeTree_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 matchTypeTree_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 matchTypeTree_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 matchTypeTree_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 matchTypeTree_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 matchTypeTree_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 matchTypeTree_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 matchTypeTree_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 matchTypeTree_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 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 + 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 WildcardTypeTree = tpd.Ident + + def matchWildcardTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] = x match { + case x @ Trees.Ident(nme.WILDCARD) => Some(x) + case _ => None + } + + // + // TYPES + // + + type TypeOrBounds = Types.Type + + type NoPrefix = Types.NoPrefix.type + + def matchNoPrefix(x: TypeOrBounds)(implicit ctx: Context): Option[NoPrefix] = + if (x == Types.NoPrefix) Some(Types.NoPrefix) else None + + type TypeBounds = Types.TypeBounds + + def matchTypeBounds(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 matchType(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 + + /** 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 matchConstantType(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 matchSymRef(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 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)) + case _ => None + } + case _ => None + } + + type TermRef = Types.NamedType + + def matchTermRef(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 matchTypeRef(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 matchSuperType(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 matchRefinement(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 matchAppliedType(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 matchAnnotatedType(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 matchAndType(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 matchOrType(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 matchMatchType(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 matchByNameType(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 matchParamRef(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 matchThisType(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 matchRecursiveThis(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 matchRecursiveType(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 matchMethodType(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) + 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 matchPolyType(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 matchTypeLambda(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 + + // + // IMPORT SELECTORS + // + + type ImportSelector = untpd.Tree + + type SimpleSelector = untpd.Ident + + def matchSimpleSelector(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 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 + } + + 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 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 + } + + def SimpleSelector_omited(self: OmitSelector)(implicit ctx: Context): Id = + self.trees.head.asInstanceOf[untpd.Ident] + + // + // 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 + + 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 + // + + type Constant = Constants.Constant + + def Constant_value(const: Constant): Any = const.value + + 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 matchConstant_Byte(x: Constant): Option[Byte] = + if (x.tag == Constants.ByteTag) Some(x.byteValue) else None + def matchConstant_Short(x: Constant): Option[Short] = + if (x.tag == Constants.ShortTag) Some(x.shortValue) else None + def matchConstant_Char(x: Constant): Option[Char] = + if (x.tag == Constants.CharTag) Some(x.charValue) else None + def matchConstant_Int(x: Constant): Option[Int] = + if (x.tag == Constants.IntTag) Some(x.intValue) else None + def matchConstant_Long(x: Constant): Option[Long] = + if (x.tag == Constants.LongTag) Some(x.longValue) else None + def matchConstant_Float(x: Constant): Option[Float] = + if (x.tag == Constants.FloatTag) Some(x.floatValue) else None + def matchConstant_Double(x: Constant): Option[Double] = + if (x.tag == Constants.DoubleTag) Some(x.doubleValue) else None + def matchConstant_String(x: Constant): Option[String] = + if (x.tag == Constants.StringTag) Some(x.stringValue) else None + def matchConstant_ClassTag(x: Constant): Option[Type] = + if (x.tag == Constants.ClazzTag) Some(x.typeValue) else None + 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(()) + 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 + // + + 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 + + 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 = + FromSymbol.packageDefFromSym(self) + + type ClassSymbol = core.Symbols.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 = + 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 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 = + FromSymbol.typeDefFromSym(self) + def TypeSymbol_isTypeParam(self: TypeSymbol)(implicit ctx: Context): Boolean = + self.isTypeParam + + type DefSymbol = core.Symbols.TermSymbol + + 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 = + FromSymbol.defDefFromSym(self) + + def DefSymbol_signature(self: DefSymbol)(implicit ctx: Context): Signature = + self.signature + + type ValSymbol = core.Symbols.TermSymbol + + 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 = + 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 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 = + FromSymbol.bindFromSym(self) + + type NoSymbol = core.Symbols.NoSymbol.type + + def matchNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean = symbol ne core.Symbols.NoSymbol + + // + // 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)) + } + + // + // 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 + // + + 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 deleted file mode 100644 index cd2cd58efde6..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/PatternOpsImpl.scala +++ /dev/null @@ -1,148 +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 { - - 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 - def symbol(implicit ctx: Context): Symbol = pattern.symbol - } - - 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, UnapplyDeco(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/PositionOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala deleted file mode 100644 index 26b401dc90e3..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala +++ /dev/null @@ -1,21 +0,0 @@ -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/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/QuotedOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala deleted file mode 100644 index b527e12f44e8..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala +++ /dev/null @@ -1,58 +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 { - - 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/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index bd689b7ee70a..6ccf711ad9fc 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -1,26 +1,16 @@ package dotty.tools.dotc.tastyreflect import dotty.tools.dotc.core._ +import dotty.tools.dotc.util.{SourcePosition, Spans} -class ReflectionImpl(val rootContext: Contexts.Context) - 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 - with TypeOrBoundsOpsImpl +object 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): scala.tasty.Reflection { val kernel: KernelImpl } = { + class ReflectionImpl(val kernel: KernelImpl) extends scala.tasty.Reflection + new ReflectionImpl(new KernelImpl(rootContext, rootPosition)) + } + +} 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 3e21bd0449f4..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/RootPositionImpl.scala +++ /dev/null @@ -1,13 +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 { - - 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/tastyreflect/SettingsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala deleted file mode 100644 index 9847660aebad..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 8eeb857adbcb..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SignatureOpsImpl.scala +++ /dev/null @@ -1,16 +0,0 @@ -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)) - } - } - - 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/StandardDefinitions.scala b/compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala deleted file mode 100644 index 667df17c025a..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/StandardDefinitions.scala +++ /dev/null @@ -1,83 +0,0 @@ -package dotty.tools.dotc.tastyreflect - -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 deleted file mode 100644 index 58bfb03289eb..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala +++ /dev/null @@ -1,240 +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 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 - } - - 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) - - def isTypeParam(implicit ctx: Context): Boolean = symbol.isTypeParam - } - - object ClassSymbol extends ClassSymbolModule { - 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) - - 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) - } - - 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) - - def signature(implicit ctx: Context): Signature = { - symbol.signature - } - } - - 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) - - 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 - } - } - - 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 deleted file mode 100644 index 5f86ea0dd0f1..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala +++ /dev/null @@ -1,875 +0,0 @@ -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._ -import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFromSym} - -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 { - 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 ---------------------------------------------------- - - 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 - def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[Term] = - if (termOrTypeTree.isTerm) Some(termOrTypeTree) else None - } - - object Term extends TermModule with TermCoreModuleImpl { - - 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 - } - } - - 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 - 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/TypeOrBoundsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala deleted file mode 100644 index 6dd3e134aa79..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala +++ /dev/null @@ -1,470 +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 { - - 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 { - 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 - } - } - - 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 { - def unapply(x: TypeOrBounds)(implicit ctx: Context): Boolean = x == Types.NoPrefix - } - -} 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 7541f6d820be..000000000000 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala +++ /dev/null @@ -1,382 +0,0 @@ -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 { - - 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 { - 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 TypeTreeCoreModuleImpl { - - 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 ------------------------------------------------ - - 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) - 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 - } - } - - def typeTreeAsParent(typeTree: TypeTree): TermOrTypeTree = typeTree -} 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/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/CaseDefOps.scala b/library/src/scala/tasty/reflect/CaseDefOps.scala index 866179aa8c3f..5b595f4e337e 100644 --- a/library/src/scala/tasty/reflect/CaseDefOps.scala +++ b/library/src/scala/tasty/reflect/CaseDefOps.scala @@ -4,36 +4,37 @@ 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 { + 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)) } - - 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 { - 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/CommentOps.scala b/library/src/scala/tasty/reflect/CommentOps.scala index 97480f7160e6..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(com: Comment): CommentAPI } diff --git a/library/src/scala/tasty/reflect/ConstantOps.scala b/library/src/scala/tasty/reflect/ConstantOps.scala index 920a07ad64a8..75bd46a70287 100644 --- a/library/src/scala/tasty/reflect/ConstantOps.scala +++ b/library/src/scala/tasty/reflect/ConstantOps.scala @@ -3,144 +3,154 @@ 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 - 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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_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.matchConstant_Symbol(constant) } } } diff --git a/library/src/scala/tasty/reflect/ContextOps.scala b/library/src/scala/tasty/reflect/ContextOps.scala index 7f2c85715c31..bb8703e4c505 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 - implicit def rootContext: Context + /** Context of the macro expansion */ + implicit def rootContext: Context = kernel.rootContext } diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index 3da2cea1a533..bd5f00c5654a 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.Ref /** Tree representing a reference to definition with a given name */ - type Ident <: Ref + type Ident = kernel.Ident /** Tree representing a selection of definition with a given name on a given prefix */ - type Select <: Ref + type Select = kernel.Select /** Tree representing a literal value in the source code */ - type Literal <: Term + type Literal = kernel.Literal /** Tree representing `this` in the source code */ - type This <: Term + type This = kernel.This /** Tree representing `new` in the source code */ - type New <: Term + type New = kernel.New /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ - type NamedArg <: Term + 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 <: Term + type Apply = kernel.Apply /** Tree an application of type arguments */ - type TypeApply <: Term + type TypeApply = kernel.TypeApply /** Tree representing `super` in the source code */ - type Super <: Term + type Super = kernel.Super /** Tree representing a type ascription `x: T` in the source code */ - type Typed <: Term + type Typed = kernel.Typed /** Tree representing an assignment `x = y` in the source code */ - type Assign <: Term + type Assign = kernel.Assign /** Tree representing a block `{ ... }` in the source code */ - type Block <: Term + type Block = kernel.Block /** Tree representing a lambda `(...) => ...` in the source code */ - type Lambda <: Term + type Lambda = kernel.Lambda /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ - type If <: Term + type If = kernel.If /** Tree representing a pattern match `x match { ... }` in the source code */ - type Match <: Term + type Match = kernel.Match /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ - type Try <: Term + type Try = kernel.Try /** Tree representing a `return` in the source code */ - type Return <: Term + type Return = kernel.Return /** Tree representing a variable argument list in the source code */ - type Repeated <: Term + type Repeated = kernel.Repeated /** Tree representing the scope of an inlined tree */ - type Inlined <: Term + 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 <: Term + type SelectOuter = kernel.SelectOuter /** Tree representing a while loop */ - type While <: Term + type While = kernel.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 WildcardTypeTree = kernel.WildcardTypeTree /** 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,52 @@ trait Core { * * RenameSelector: `.{bar => baz}` in `import foo.{bar => baz}` * * OmitSelector: `.{bar => _}` in `import foo.{bar => _}` */ - type ImportSelector <: AnyRef + type ImportSelector = kernel.ImportSelector + type SimpleSelector = kernel.SimpleSelector + type RenameSelector = kernel.RenameSelector + type OmitSelector = kernel.OmitSelector /** 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/FlagsOps.scala b/library/src/scala/tasty/reflect/FlagsOps.scala index 6eff5e459a4f..4b5422fbc4af 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..b7f79340840d 100644 --- a/library/src/scala/tasty/reflect/IdOps.scala +++ b/library/src/scala/tasty/reflect/IdOps.scala @@ -3,16 +3,18 @@ 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 { - 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..19e244fded4b 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.matchSimpleSelector(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.matchRenameSelector(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.matchOmitSelector(importSelector).map(_.omitted) } } diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala new file mode 100644 index 000000000000..4d6a6d031bbf --- /dev/null +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -0,0 +1,1402 @@ +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 ----+- 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 + * + * +- 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 of the macro expansion */ + def rootContext: Context + + /** Root position of this tasty context. For macros it corresponds to the expansion site. */ + def rootPosition: Position + + def settings: Settings + + // + // CONTEXT + // + + /** 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 + // + + /** Settings */ + type Settings <: AnyRef + + def Settings_color(self: Settings): Boolean + + // + // 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 + + 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 matchPackageClause(tree: Tree)(implicit ctx: Context): Option[PackageClause] + + def PackageClause_pid(self: PackageClause)(implicit ctx: Context): Ref + def PackageClause_stats(self: PackageClause)(implicit ctx: Context): List[Tree] + + def PackageClause_apply(pid: 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 + + def matchStatement(tree: Tree)(implicit ctx: Context): Option[Statement] + + /** Tree representing an import in the source code */ + type Import <: Statement + + def matchImport(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 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 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] + 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 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] + 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 + + 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 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 + + 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 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]] + 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 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] + 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 matchTerm(tree: Tree)(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 + 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 Ref <: Term + + def Ref_apply(sym: Symbol)(implicit ctx: Context): Ref + + /** Tree representing a reference to definition with a given name */ + type Ident <: Ref + + def matchIdent(tree: Tree)(implicit ctx: Context): Option[Ident] + + def Ident_name(self: Ident)(implicit ctx: Context): String + + 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 Select <: Ref + + def matchSelect(tree: Tree)(implicit ctx: Context): Option[Select] + + 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 Select_unique(qualifier: Term, name: String)(implicit ctx: Context): Select + // TODO rename, this returns an Apply and not a 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 Literal <: Term + + def matchLiteral(tree: Tree)(implicit ctx: Context): Option[Literal] + + def Literal_constant(self: Literal)(implicit ctx: Context): Constant + + 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 This <: Term + + def matchThis(tree: Tree)(implicit ctx: Context): Option[This] + + def This_id(self: This)(implicit ctx: Context): Option[Id] + + 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 New <: Term + + def matchNew(tree: Tree)(implicit ctx: Context): Option[New] + + def New_tpt(self: New)(implicit ctx: Context): TypeTree + + 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 NamedArg <: Term + + def matchNamedArg(tree: Tree)(implicit ctx: Context): Option[NamedArg] + + def NamedArg_name(self: NamedArg)(implicit ctx: Context): String + def NamedArg_value(self: NamedArg)(implicit ctx: Context): Term + + 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 Apply <: Term + + def matchApply(tree: Tree)(implicit ctx: Context): Option[Apply] + + def Apply_fun(self: Apply)(implicit ctx: Context): Term + def Apply_args(self: Apply)(implicit ctx: Context): List[Term] + + 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 TypeApply <: Term + + def matchTypeApply(tree: Tree)(implicit ctx: Context): Option[TypeApply] + + def TypeApply_fun(self: TypeApply)(implicit ctx: Context): Term + def TypeApply_args(self: TypeApply)(implicit ctx: Context): List[TypeTree] + + 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 Super <: Term + + def matchSuper(tree: Tree)(implicit ctx: Context): Option[Super] + + def Super_qualifier(self: Super)(implicit ctx: Context): Term + def Super_id(self: Super)(implicit ctx: Context): Option[Id] + + 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 Typed <: Term + + def matchTyped(tree: Tree)(implicit ctx: Context): Option[Typed] + + def Typed_expr(self: Typed)(implicit ctx: Context): Term + def Typed_tpt(self: Typed)(implicit ctx: Context): TypeTree + + 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 Assign <: Term + + def matchAssign(tree: Tree)(implicit ctx: Context): Option[Assign] + + def Assign_lhs(self: Assign)(implicit ctx: Context): Term + def Assign_rhs(self: Assign)(implicit ctx: Context): Term + + 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 Block <: Term + + def matchBlock(tree: Tree)(implicit ctx: Context): Option[Block] + + def Block_statements(self: Block)(implicit ctx: Context): List[Statement] + def Block_expr(self: Block)(implicit ctx: Context): Term + + 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 Lambda <: Term + + def matchLambda(tree: Tree)(implicit ctx: Context): Option[Lambda] + + def Lambda_meth(self: Lambda)(implicit ctx: Context): Term + def Lambda_tptOpt(self: Lambda)(implicit ctx: Context): Option[TypeTree] + + 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 If <: Term + + def matchIf(tree: Tree)(implicit ctx: Context): Option[If] + + 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 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 Match <: Term + + def matchMatch(tree: Tree)(implicit ctx: Context): Option[Match] + + def Match_scrutinee(self: Match)(implicit ctx: Context): Term + def Match_cases(self: Match)(implicit ctx: Context): List[CaseDef] + + 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 Try <: Term + + def matchTry(tree: Tree)(implicit ctx: Context): Option[Try] + + 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 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 Return <: Term + + def matchReturn(tree: Tree)(implicit ctx: Context): Option[Return] + + def Return_expr(self: Return)(implicit ctx: Context): Term + + 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 Repeated <: Term + + def matchRepeated(tree: Tree)(implicit ctx: Context): Option[Repeated] + + def Repeated_elems(self: Repeated)(implicit ctx: Context): List[Term] + def Repeated_elemtpt(self: Repeated)(implicit ctx: Context): TypeTree + + 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 Inlined <: Term + + def matchInlined(tree: Tree)(implicit ctx: Context): Option[Inlined] + + 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 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 SelectOuter <: Term + + def matchSelectOuter(tree: Tree)(implicit ctx: Context): Option[SelectOuter] + + 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 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 While <: Term + + def matchWhile(tree: Tree)(implicit ctx: Context): Option[While] + + def While_cond(self: While)(implicit ctx: Context): Term + def While_body(self: While)(implicit ctx: Context): Term + + 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 + // + + /** 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 + + 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 + // + + /** 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 + + def matchPattern_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 matchPattern_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 matchPattern_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 matchPattern_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 matchPattern_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 + // + + /** 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 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 + def TypeTree_tpe(self: TypeTree)(implicit ctx: Context): Type + + /** Type tree representing an inferred type */ + type TypeTree_Inferred <: TypeTree + + 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 matchTypeTree_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 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 + + 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 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 + + 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 matchTypeTree_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 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] + + 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 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] + + 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 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 + + 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 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 + 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 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 + + /** Type tree representing a lambda abstraction type */ + type TypeTree_LambdaTypeTree <: TypeTree + + 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 + + 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 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 + + 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 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 + + 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 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 + 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. + */ + type WildcardTypeTree <: TypeOrBoundsTree + + def matchWildcardTypeTree(x: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] + + // + // TYPES + // + + /** Type or bounds */ + type TypeOrBounds <: AnyRef + + /** NoPrefix for a type selection */ + type NoPrefix <: TypeOrBounds + + def matchNoPrefix(x: TypeOrBounds)(implicit ctx: Context): Option[NoPrefix] + + /** Type bounds */ + type TypeBounds <: TypeOrBounds + + 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 + + /** A type */ + type Type <: TypeOrBounds + + 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 + + /** 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 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 matchSymRef(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] + + // TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef + 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 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 + + def TermRef_apply(qual: TypeOrBounds, name: String)(implicit ctx: Context): TermRef + + /** Type of a reference to a type */ + type TypeRef <: Type + + 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 + + /** Type of a `super` refernce */ + type SuperType <: Type + + 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 + + /** A type with a type refinement `T { type U }` */ + type Refinement <: Type + + 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 + def Refinement_info(self: Refinement)(implicit ctx: Context): TypeOrBounds + + /** A higher kinded type applied to some types `T[U]` */ + type AppliedType <: Type + + 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] + + /** A type with an anottation `T @foo` */ + type AnnotatedType <: Type + + 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 + + /** Intersection type `T & U` */ + type AndType <: Type + + 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 + + /** Union type `T | U` */ + type OrType <: Type + + 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 + + /** Type match `T match { case U => ... }` */ + type MatchType <: Type + + 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 + def MatchType_cases(self: MatchType)(implicit ctx: Context): List[Type] + + /** Type of a by by name parameter */ + type ByNameType <: Type + + 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 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 + + /** Type of `this` */ + type ThisType <: Type + + 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 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 matchRecursiveType(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? + // 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] + + def matchMethodType(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] + 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 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] + 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 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] + def TypeLambda_resType(self: TypeLambda)(implicit ctx: Context): Type + + // + // 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 + + type SimpleSelector <: ImportSelector + + def matchSimpleSelector(self: ImportSelector)(implicit ctx: Context): Option[SimpleSelector] + + def SimpleSelector_selection(self: SimpleSelector)(implicit ctx: Context): Id + + type RenameSelector <: ImportSelector + + 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 matchOmitSelector(self: ImportSelector)(implicit ctx: Context): Option[OmitSelector] + + def SimpleSelector_omited(self: OmitSelector)(implicit ctx: Context): Id + + // + // IDENTIFIERS + // + + /** 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 + // + + /** 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 + // + + /** 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 + // + + /** 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 + // + + /** Constant value represented as the constant itself */ + type Constant <: AnyRef + + def Constant_value(const: Constant): Any + + 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 + 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 + // + + /** Symbol of a definition. + * Then can be compared with == to know if the definition is the same. + */ + 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 + + 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 matchClassSymbol(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 matchTypeSymbol(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 matchDefSymbol(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 matchValSymbol(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 matchBindSymbol(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 + + def matchNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean + + // + // FLAGS + // + + /** 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[_] + + // + // 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 dd43db40f035..35fe8eb4e765 100644 --- a/library/src/scala/tasty/reflect/PatternOps.scala +++ b/library/src/scala/tasty/reflect/PatternOps.scala @@ -3,106 +3,106 @@ 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) + } - trait PatternAPI { - /** Position in the source code */ - def pos(implicit ctx: Context): Position + 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) + } - def tpe(implicit ctx: Context): Type + 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) + } - def symbol(implicit ctx: Context): Symbol + implicit class AlternativesAPI(alternatives: Alternatives) { + def patterns(implicit ctx: Context): List[Pattern] = kernel.Pattern_Alternatives_patterns(alternatives) } - implicit def PatternDeco(pattern: Pattern): PatternAPI - val Pattern: PatternModule - abstract class PatternModule { + implicit class TypeTestAPI(typeTest: TypeTest) { + def tpt(implicit ctx: Context): TypeTree = kernel.Pattern_TypeTest_tpt(typeTest) + } - val IsValue: IsValueModule - abstract class IsValueModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Value] - } + implicit class PatternAPI(self: Pattern) { + /** Position in the source code */ + def pos(implicit ctx: Context): Position = kernel.Pattern_pos(self) - 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] - } + def tpe(implicit ctx: Context): Type = kernel.Pattern_tpe(self) - trait ValueAPI { - def value(implicit ctx: Context): Term - } - - val IsBind: IsBindModule - abstract class IsBindModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Bind] - } + def symbol(implicit ctx: Context): Symbol = kernel.Pattern_symbol(self) + } - val Bind: BindModule - abstract class BindModule { - // 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)] - } + object Pattern { - trait BindAPI { - def name(implicit ctx: Context): String - def pattern(implicit ctx: Context): Pattern + object IsValue { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[Value] = + kernel.matchPattern_Value(pattern) } - val IsUnapply: IsUnapplyModule - abstract class IsUnapplyModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] + 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.matchPattern_Value(pattern).map(_.value) } - val Unapply: UnapplyModule - abstract class UnapplyModule { - // 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])] + object IsBind { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[Bind] = + kernel.matchPattern_Bind(pattern) } - trait UnapplyAPI { - def fun(implicit ctx: Context): Term - def implicits(implicit ctx: Context): List[Term] - def patterns(implicit ctx: Context): List[Pattern] + 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 = + kernel.Pattern_Bind_module_copy(original)(name, pattern) + def unapply(pattern: Pattern)(implicit ctx: Context): Option[(String, Pattern)] = + kernel.matchPattern_Bind(pattern).map(x => (x.name, x.pattern)) } - val IsAlternatives: IsAlternativesModule - abstract class IsAlternativesModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] + object IsUnapply { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[Unapply] = + kernel.matchPattern_Unapply(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 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 = + kernel.Pattern_Unapply_module_copy(original)(fun, implicits, patterns) + def unapply(pattern: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] = + kernel.matchPattern_Unapply(pattern).map(x => (x.fun, x.implicits, x.patterns)) } - trait AlternativesAPI { - def patterns(implicit ctx: Context): List[Pattern] + object IsAlternatives { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[Alternatives] = + kernel.matchPattern_Alternatives(pattern) } - val IsTypeTest: IsTypeTestModule - abstract class IsTypeTestModule { - def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] + 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.matchPattern_Alternatives(pattern).map(_.patterns) } - 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 IsTypeTest { + def unapply(pattern: Pattern)(implicit ctx: Context): Option[TypeTest] = + kernel.matchPattern_TypeTest(pattern) } - trait TypeTestAPI { - def tpt(implicit ctx: Context): 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.matchPattern_TypeTest(pattern).map(_.tpt) } } 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/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 { 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/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 } 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 7ddf56461bc9..7620b2bd6a2a 100644 --- a/library/src/scala/tasty/reflect/SignatureOps.scala +++ b/library/src/scala/tasty/reflect/SignatureOps.scala @@ -3,18 +3,20 @@ 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)) } - 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/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 d2aec1152da0..5848f22fe53a 100644 --- a/library/src/scala/tasty/reflect/SymbolOps.scala +++ b/library/src/scala/tasty/reflect/SymbolOps.scala @@ -6,192 +6,225 @@ trait SymbolOps extends Core { // Symbol - trait SymbolAPI { + implicit class SymbolAPI(self: Symbol) { - /** Owner of this symbol. The owner is the symbol in which this symbol is defined. */ - def owner(implicit ctx: Context): Symbol + /** 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 + def flags(implicit ctx: Context): Flags = kernel.Symbol_flags(self) - 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 + /** This symbol is private within the resulting type */ + def privateWithin(implicit ctx: Context): Option[Type] = kernel.Symbol_privateWithin(self) - /** This symbol is private within the resulting type. */ - def privateWithin(implicit ctx: Context): Option[Type] + /** This symbol is protected within the resulting type */ + def protectedWithin(implicit ctx: Context): Option[Type] = kernel.Symbol_protectedWithin(self) - /** This symbol is protected within the resulting type. */ - def protectedWithin(implicit ctx: Context): Option[Type] + /** The name of this symbol */ + def name(implicit ctx: Context): String = kernel.Symbol_name(self) - /** The name of this symbol. */ - def name(implicit ctx: Context): String - - /** The full name of this symbol up to the root package. */ - def fullName(implicit ctx: Context): String + /** 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 */ - 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 - 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.matchPackageSymbol(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 - 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.matchClassSymbol(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 - 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.matchTypeSymbol(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 - 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.matchDefSymbol(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 - 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.matchValSymbol(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 - 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.matchBindSymbol(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 - 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.matchNoSymbol(symbol) } } diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index 89f12ae03ba4..d0436d84961a 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -2,754 +2,743 @@ 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 - - implicit def termAsTermOrTypeTree(term: Term): TermOrTypeTree + implicit def termAsTermOrTypeTree(term: Term): TermOrTypeTree = term.asInstanceOf[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 - abstract class IsPackageClauseModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[PackageClause] + object IsPackageClause { + def unapply(tree: Tree)(implicit ctx: Context): Option[PackageClause] = + kernel.matchPackageClause(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.matchPackageClause(tree).map(x => (x.pid, x.stats)) } - 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 - abstract class IsImportModule { - def unapply(tree: Tree)(implicit ctx: Context): Option[Import] + object IsImport { + def unapply(tree: Tree)(implicit ctx: Context): Option[Import] = + kernel.matchImport(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.matchImport(tree).map(x => (x.impliedOnly, x.expr, x.selectors)) } - 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 - 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.matchStatement(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.matchDefinition(tree) } - trait DefinitionAPI { - def name(implicit ctx: Context): String + implicit class DefinitionAPI(self: Definition) { + def name(implicit ctx: Context): String = kernel.Definition_name(self) } // 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.matchClassDef(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.matchClassDef(tree).map(x => (x.name, x.constructor, x.parents, x.derived, x.self, x.body)) } - 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 - 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.matchDefDef(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.matchDefDef(tree).map(x => (x.name, x.typeParams, x.paramss, x.returnTpt, x.rhs)) } - 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) // 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.matchValDef(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.matchValDef(tree).map(x => (x.name, x.tpt, x.rhs)) } - 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 - 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.matchTypeDef(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.matchTypeDef(tree).map(x => (x.name, x.rhs)) } - 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 - 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.matchPackageDef(tree) } - 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 - 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.matchPackageDef(tree).map(x => (x.name, x.owner)) } // ----- 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 - 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.matchTerm(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.matchTermNotTypeTree(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] - } - - trait IdentAPI { - def name(implicit ctx: Context): String + def unapply(tree: Tree)(implicit ctx: Context): Option[Ident] = kernel.matchIdent(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.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.Ident_apply(tmref) - def copy(original: Tree)(name: String)(implicit ctx: Context): Ident + def copy(original: Tree)(name: String)(implicit ctx: Context): Ident = + kernel.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.matchIdent(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] - } - - trait SelectAPI { - def qualifier(implicit ctx: Context): Term - def name(implicit ctx: Context): String - def signature(implicit ctx: Context): Option[Signature] + def unapply(tree: Tree)(implicit ctx: Context): Option[Select] = kernel.matchSelect(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.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.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.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.matchSelect(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] - } - - trait LiteralAPI { - def constant(implicit ctx: Context): Constant + def unapply(tree: Tree)(implicit ctx: Context): Option[Literal] = kernel.matchLiteral(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.Literal_apply(constant) - def copy(original: Tree)(constant: Constant)(implicit ctx: Context): Literal + def copy(original: Tree)(constant: Constant)(implicit ctx: Context): Literal = + kernel.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.matchLiteral(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] - } - - trait ThisAPI { - def id(implicit ctx: Context): Option[Id] + def unapply(tree: Tree)(implicit ctx: Context): Option[This] = kernel.matchThis(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.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.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.matchThis(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] - } - - trait NewAPI { - def tpt(implicit ctx: Context): TypeTree + def unapply(tree: Tree)(implicit ctx: Context): Option[New] = kernel.matchNew(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.New_apply(tpt) - def copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): New + def copy(original: Tree)(tpt: TypeTree)(implicit ctx: Context): New = + kernel.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.matchNew(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] - } - - trait NamedArgAPI { - def name(implicit ctx: Context): String - def value(implicit ctx: Context): Term + def unapply(tree: Tree)(implicit ctx: Context): Option[NamedArg] = kernel.matchNamedArg(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.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.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.matchNamedArg(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] - } - - trait ApplyAPI { - def fun(implicit ctx: Context): Term - def args(implicit ctx: Context): List[Term] + def unapply(tree: Tree)(implicit ctx: Context): Option[Apply] = kernel.matchApply(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.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.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.matchApply(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] - } - - trait TypeApplyAPI { - def fun(implicit ctx: Context): Term - def args(implicit ctx: Context): List[TypeTree] + def unapply(tree: Tree)(implicit ctx: Context): Option[TypeApply] = + kernel.matchTypeApply(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.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.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.matchTypeApply(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] - } - - trait SuperAPI { - def qualifier(implicit ctx: Context): Term - def id(implicit ctx: Context): Option[Id] + def unapply(tree: Tree)(implicit ctx: Context): Option[Super] = kernel.matchSuper(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.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.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.matchSuper(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] - } - - trait TypedAPI { - def expr(implicit ctx: Context): Term - def tpt(implicit ctx: Context): Term + def unapply(tree: Tree)(implicit ctx: Context): Option[Typed] = kernel.matchTyped(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.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.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.matchTyped(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] - } - - trait AssignAPI { - def lhs(implicit ctx: Context): Term - def rhs(implicit ctx: Context): Term + def unapply(tree: Tree)(implicit ctx: Context): Option[Assign] = kernel.matchAssign(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.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.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.matchAssign(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] - } - - trait BlockAPI { - def statements(implicit ctx: Context): List[Statement] - def expr(implicit ctx: Context): Term + def unapply(tree: Tree)(implicit ctx: Context): Option[Block] = kernel.matchBlock(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.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.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.matchBlock(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] - } - - trait LambdaAPI { - def meth(implicit ctx: Context): Term - def tptOpt(implicit ctx: Context): Option[TypeTree] + def unapply(tree: Tree)(implicit ctx: Context): Option[Lambda] = kernel.matchLambda(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.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.Lambda_copy(original)(meth, tpt) + def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, Option[TypeTree])] = + kernel.matchLambda(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] - } - - trait IfAPI { - def cond(implicit ctx: Context): Term - def thenp(implicit ctx: Context): Term - def elsep(implicit ctx: Context): Term + def unapply(tree: Tree)(implicit ctx: Context): Option[If] = kernel.matchIf(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.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.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.matchIf(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] - } - - trait MatchAPI { - def scrutinee(implicit ctx: Context): Term - def cases(implicit ctx: Context): List[CaseDef] + def unapply(tree: Tree)(implicit ctx: Context): Option[Match] = kernel.matchMatch(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.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.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.matchMatch(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] - } - - trait TryAPI { - def body(implicit ctx: Context): Term - def cases(implicit ctx: Context): List[CaseDef] - def finalizer(implicit ctx: Context): Option[Term] + def unapply(tree: Tree)(implicit ctx: Context): Option[Try] = kernel.matchTry(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.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.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.matchTry(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] - } - - trait ReturnAPI { - def expr(implicit ctx: Context): Term + def unapply(tree: Tree)(implicit ctx: Context): Option[Return] = kernel.matchReturn(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.Return_apply(expr) - def copy(original: Tree)(expr: Term)(implicit ctx: Context): Return + def copy(original: Tree)(expr: Term)(implicit ctx: Context): Return = + kernel.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.matchReturn(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] - } - - trait RepeatedAPI { - def elems(implicit ctx: Context): List[Term] - def elemtpt(implicit ctx: Context): TypeTree + def unapply(tree: Tree)(implicit ctx: Context): Option[Repeated] = kernel.matchRepeated(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.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.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.matchRepeated(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.matchInlined(tree) } - 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 { + 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.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.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.matchInlined(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] - } - - trait SelectOuterAPI { - def qualifier(implicit ctx: Context): Term - def level(implicit ctx: Context): Int - def tpe(implicit ctx: Context): Type + def unapply(tree: Tree)(implicit ctx: Context): Option[SelectOuter] = kernel.matchSelectOuter(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.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.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.matchSelectOuter(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] - } - - trait WhileAPI { - def cond(implicit ctx: Context): Term - def body(implicit ctx: Context): Term + def unapply(tree: Tree)(implicit ctx: Context): Option[While] = kernel.matchWhile(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.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.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.matchWhile(tree).map(x => (x.cond, x.body)) } } + implicit class IdentAPI(self: Term.Ident) { + def name(implicit ctx: Context): String = kernel.Ident_name(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 LiteralAPI(self: Term.Literal) { + def constant(implicit ctx: Context): Constant = kernel.Literal_constant(self) + } + + implicit class ThisAPI(self: Term.This) { + def id(implicit ctx: Context): Option[Id] = kernel.This_id(self) + } + + implicit class NewAPI(self: Term.New) { + def tpt(implicit ctx: Context): TypeTree = kernel.New_tpt(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 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 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 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 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 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 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 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 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 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 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 ReturnAPI(self: Term.Return) { + def expr(implicit ctx: Context): Term = kernel.Return_expr(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 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 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 WhileAPI(self: Term.While) { + def cond(implicit ctx: Context): Term = kernel.While_cond(self) + def body(implicit ctx: Context): Term = kernel.While_body(self) + } + } diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala index 9e3beb602f37..f6f175ab9bc8 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala @@ -3,399 +3,359 @@ 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 - abstract class IsTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] + object IsType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = + kernel.matchType(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.matchConstantType(tpe) } - trait ConstantTypeAPI { - def value(implicit ctx: Context): Any + object ConstantType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Constant] = + kernel.matchConstantType(typeOrBounds).map(_.constant) } - val ConstantType: ConstantTypeModule - abstract class ConstantTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Constant] - } - - val IsSymRef: IsSymRefModule - abstract class IsSymRefModule { + object IsSymRef { /** Matches any SymRef and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] - } - - trait SymRefAPI { - def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SymRef] = + kernel.matchSymRef(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.matchSymRef_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] - } - - trait TermRefAPI { - def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TermRef] = + kernel.matchTermRef(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.matchTermRef(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.matchTypeRef(tpe) } - trait TypeRefAPI { - def name(implicit ctx: Context): String - def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ + object TypeRef { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] = + kernel.matchTypeRef(typeOrBounds).map(x => (x.name, x.qualifier)) } - val TypeRef: TypeRefModule - abstract class TypeRefModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] - } - - val IsSuperType: IsSuperTypeModule - abstract class IsSuperTypeModule { + object IsSuperType { /** Matches any SuperType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] - } - - trait SuperTypeAPI { - def thistpe(implicit ctx: Context): Type - def supertpe(implicit ctx: Context): Type + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] = + kernel.matchSuperType(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.matchSuperType(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] - } - - trait RefinementAPI { - def parent(implicit ctx: Context): Type - def name(implicit ctx: Context): String - def info(implicit ctx: Context): TypeOrBounds + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] = + kernel.matchRefinement(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.matchRefinement(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.matchAppliedType(tpe) } - trait AppliedTypeAPI { - def tycon(implicit ctx: Context): Type - def args(implicit ctx: Context): List[TypeOrBounds /* Type | TypeBounds */] + object AppliedType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] = + kernel.matchAppliedType(typeOrBounds).map(x => (x.tycon, x.args)) } - val AppliedType: AppliedTypeModule - abstract class AppliedTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] - } - - val IsAnnotatedType: IsAnnotatedTypeModule - abstract class IsAnnotatedTypeModule { + object IsAnnotatedType { /** Matches any AnnotatedType and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] - } - - trait AnnotatedTypeAPI { - def underlying(implicit ctx: Context): Type - def annot(implicit ctx: Context): Term + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] = + kernel.matchAnnotatedType(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.matchAnnotatedType(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] - } - - trait AndTypeAPI { - def left(implicit ctx: Context): Type - def right(implicit ctx: Context): Type + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] = + kernel.matchAndType(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.matchAndType(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.matchOrType(tpe) } - trait OrTypeAPI { - def left(implicit ctx: Context): Type - def right(implicit ctx: Context): Type + object OrType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = + kernel.matchOrType(typeOrBounds).map(x => (x.left, x.right)) } - val OrType: OrTypeModule - abstract class OrTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] - } - - val IsMatchType: IsMatchTypeModule - abstract class IsMatchTypeModule { + object IsMatchType { /** Matches any MatchType and returns it */ - 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] + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] = + kernel.matchMatchType(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.matchMatchType(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] - } - - trait ByNameTypeAPI { - def underlying(implicit ctx: Context): Type + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] = + kernel.matchByNameType(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.matchByNameType(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.matchParamRef(tpe) } - trait ParamRefAPI { - def binder(implicit ctx: Context): LambdaType[TypeOrBounds] - def paramNum(implicit ctx: Context): Int + object ParamRef { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] = + kernel.matchParamRef(typeOrBounds).map(x => (x.binder, x.paramNum)) } - val ParamRef: ParamRefModule - abstract class ParamRefModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] - } - - 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.matchThisType(tpe) } - trait ThisTypeAPI { - def underlying(implicit ctx: Context): Type + object ThisType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = + kernel.matchThisType(typeOrBounds).map(_.tref) } - val ThisType: ThisTypeModule - abstract class ThisTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] - } - - val IsRecursiveThis: IsRecursiveThisModule - abstract class IsRecursiveThisModule { + object IsRecursiveThis { /** Matches any RecursiveThis and returns it */ - def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] - } - - trait RecursiveThisAPI { - def binder(implicit ctx: Context): RecursiveType + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] = + kernel.matchRecursiveThis(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.matchRecursiveThis(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.matchRecursiveType(tpe) } - trait RecursiveTypeAPI { - def underlying(implicit ctx: Context): Type + object RecursiveType { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] = + kernel.matchRecursiveType(typeOrBounds).map(_.underlying) } - val RecursiveType: RecursiveTypeModule - abstract class RecursiveTypeModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] - } - - val IsMethodType: IsMethodTypeModule - abstract class IsMethodTypeModule { + object IsMethodType { /** Matches any MethodType and returns it */ - 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 + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] = + kernel.matchMethodType(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.matchMethodType(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] - } - - trait PolyTypeAPI { - def paramNames(implicit ctx: Context): List[String] - def paramBounds(implicit ctx: Context): List[TypeBounds] - def resType(implicit ctx: Context): Type + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] = + kernel.matchPolyType(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.matchPolyType(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.matchTypeLambda(tpe) } - trait TypeLambdaAPI { - def paramNames(implicit ctx: Context): List[String] - def paramBounds(implicit ctx: Context): List[TypeBounds] - def resType(implicit ctx: Context): Type + object TypeLambda { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] = + kernel.matchTypeLambda(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) } - val TypeLambda: TypeLambdaModule - abstract class TypeLambdaModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] - } + } + + implicit class Type_ConstantTypeAPI(self: ConstantType) { + def constant(implicit ctx: Context): Constant = kernel.ConstantType_constant(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 name(implicit ctx: Context): String = kernel.TermRef_name(self) + 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 tref(implicit ctx: Context): Type = kernel.ThisType_tref(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 - abstract class IsTypeBoundsModule { - def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] + object IsTypeBounds { + def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[TypeBounds] = + kernel.matchTypeBounds(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.matchTypeBounds(typeOrBounds).map(x => (x.low, x.hi)) } - 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 ------------------------------------------------- - 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.matchNoPrefix(typeOrBounds).isDefined } } diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala index 35a1d8125080..7a57529e8728 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala @@ -3,305 +3,312 @@ 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 def typeTreeAsParent(term: TypeTree): TermOrTypeTree = term.asInstanceOf[TermOrTypeTree] + + 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 - 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.matchTypeTree(tpt) + def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] = + kernel.matchTypeTreeNotTerm(termOrTypeTree) } - val TypeTree: TypeTreeModule - abstract class TypeTreeModule extends TypeTreeCoreModule { + object TypeTree 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] - } - - trait InferredAPI { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Inferred] = + kernel.matchTypeTree_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.matchTypeTree_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.matchTypeTree_Ident(tpt) } - trait IdentAPI { - def name(implicit ctx: Context): String - } - - 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.matchTypeTree_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.matchTypeTree_Select(tpt) } - trait SelectAPI { - def qualifier(implicit ctx: Context): Term - def name(implicit ctx: Context): 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.matchTypeTree_Select(typeOrBoundsTree).map(x => (x.qualifier, x.name)) } - 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)] - } - - val IsProjection: IsProjectionModule - abstract class IsProjectionModule { + object IsProjection { /** Matches any Projection and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Projection] - } - - trait ProjectionAPI { - def qualifier(implicit ctx: Context): TypeTree - def name(implicit ctx: Context): String + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Projection] = + kernel.matchTypeTree_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.matchTypeTree_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.matchTypeTree_Singleton(tpt) } - trait SingletonAPI { - def ref(implicit ctx: Context): 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.matchTypeTree_Singleton(typeOrBoundsTree).map(_.ref) } - 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] - } - - val IsRefined: IsRefinedModule - abstract class IsRefinedModule { + object IsRefined { /** Matches any Refined and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Refined] - } - - trait RefinedAPI { - def tpt(implicit ctx: Context): TypeTree - def refinements(implicit ctx: Context): List[Definition] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Refined] = + kernel.matchTypeTree_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.matchTypeTree_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] - } - - trait AppliedAPI { - def tpt(implicit ctx: Context): TypeTree - def args(implicit ctx: Context): List[TypeOrBoundsTree] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Applied] = + kernel.matchTypeTree_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.matchTypeTree_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.matchTypeTree_Annotated(tpt) } - trait AnnotatedAPI { - def arg(implicit ctx: Context): TypeTree - def annotation(implicit ctx: Context): 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.matchTypeTree_Annotated(typeOrBoundsTree).map(x => (x.arg, x.annotation)) } - 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)] - } - - val IsMatchType: IsMatchTypeModule - abstract class IsMatchTypeModule { + object IsMatchType { /** Matches any MatchType and returns it */ - 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] + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[MatchType] = + kernel.matchTypeTree_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.matchTypeTree_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.matchTypeTree_ByName(tpt) } - trait ByNameAPI { - def result(implicit ctx: Context): 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.matchTypeTree_ByName(typeOrBoundsTree).map(_.result) } - 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] - } - - val IsLambdaTypeTree: IsLambdaTypeTreeModule - abstract class IsLambdaTypeTreeModule { + object IsLambdaTypeTree { /** Matches any LambdaTypeTree and returns it */ - def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[LambdaTypeTree] - } - - trait LambdaTypeTreeAPI { - def tparams(implicit ctx: Context): List[TypeDef] - def body(implicit ctx: Context): TypeOrBoundsTree + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[LambdaTypeTree] = + kernel.matchTypeTree_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.matchTypeTree_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] - } - - trait TypeBindAPI { - def name(implicit ctx: Context): String - def body(implicit ctx: Context): TypeOrBoundsTree + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBind] = + kernel.matchTypeTree_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.matchTypeTree_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.matchTypeTree_TypeBlock(tpt) } - trait TypeBlockAPI { - def aliases(implicit ctx: Context): List[TypeDef] - def tpt(implicit ctx: Context): 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.matchTypeTree_TypeBlock(typeOrBoundsTree).map(x => (x.aliases, x.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)] - } + 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) + } + + object IsTypeBoundsTree { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] = + kernel.matchTypeBoundsTree(tpt) } - val IsTypeBoundsTree: IsTypeBoundsTreeModule - abstract class IsTypeBoundsTreeModule { - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] + object TypeBoundsTree { + def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] = + kernel.matchTypeBoundsTree(typeOrBoundsTree).map(x => (x.low, x.hi)) } - val TypeBoundsTree: TypeBoundsTreeModule - abstract class TypeBoundsTreeModule { - def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] + object IsWildcardTypeTree { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[WildcardTypeTree] = + kernel.matchWildcardTypeTree(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.matchWildcardTypeTree(typeOrBoundsTree).isDefined } }