diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala index 123c1816e8e2..a21974b5e17d 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala @@ -78,6 +78,7 @@ trait CoreImpl extends scala.tasty.reflect.Core { type ByName = tpd.ByNameTypeTree type LambdaTypeTree = tpd.LambdaTypeTree type Bind = tpd.Bind + type Block = tpd.Block } type TypeBoundsTree = tpd.TypeBoundsTree type WildcardType = tpd.TypeTree @@ -86,11 +87,26 @@ trait CoreImpl extends scala.tasty.reflect.Core { type NoPrefix = Types.NoPrefix.type type TypeBounds = Types.TypeBounds type Type = Types.Type - 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 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 diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala index 5edac2829ad6..d2b7a909779d 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsOpsImpl.scala @@ -1,6 +1,6 @@ package dotty.tools.dotc.tastyreflect -import dotty.tools.dotc.core.{Names, Types} +import dotty.tools.dotc.core.{Contexts, Names, Types} trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreImpl { @@ -41,6 +41,17 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI 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 + } + } + + def ConstantTypeDeco(x: ConstantType): ConstantTypeAPI = new ConstantTypeAPI { + def value(implicit ctx: Context): Any = x.value + } + object ConstantType extends ConstantTypeExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[Constant] = x match { case Types.ConstantType(value) => Some(value) @@ -48,6 +59,21 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + 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 + } + } + + def SymRefDeco(x: SymRef): SymRefAPI = new SymRefAPI { + def qualifier(implicit ctx: Context): TypeOrBounds = x.prefix + } + object SymRef extends SymRefExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] = x match { case tp: Types.NamedType => @@ -59,6 +85,21 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + 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 + } + } + + def TermRefDeco(x: TermRef): TermRefAPI = new TermRefAPI { + def qualifier(implicit ctx: Context): TypeOrBounds = x.prefix + } + object TermRef extends TermRefExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] = x match { case tp: Types.NamedType => @@ -70,6 +111,22 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + 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 + } + } + + def TypeRefDeco(x: TypeRef): TypeRefAPI = new TypeRefAPI { + def name(implicit ctx: Context): String = x.name.toString + def qualifier(implicit ctx: Context): TypeOrBounds = x.prefix + } + object TypeRef extends TypeRefExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] = x match { case tp: Types.NamedType => @@ -81,6 +138,18 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsSuperType extends IsSuperTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[SuperType] = tpe match { + case tpe: Types.SuperType => Some(tpe) + case _ => None + } + } + + def SuperTypeDeco(x: SuperType): SuperTypeAPI = new SuperTypeAPI { + def thistpe(implicit ctx: Context): Type = x.thistpe + def supertpe(implicit ctx: Context): Type = x.supertpe + } + object SuperType extends SuperTypeExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = x match { case Types.SuperType(thistpe, supertpe) => Some(thistpe, supertpe) @@ -88,6 +157,19 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsRefinement extends IsRefinementModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[Refinement] = tpe match { + case tpe: Types.RefinedType => Some(tpe) + case _ => None + } + } + + def RefinementDeco(x: Refinement): RefinementAPI = new 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 + } + object Refinement extends RefinementExtractor { 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) @@ -95,6 +177,18 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsAppliedType extends IsAppliedTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] = tpe match { + case tpe: Types.AppliedType => Some(tpe) + case _ => None + } + } + + def AppliedTypeDeco(x: AppliedType): AppliedTypeAPI = new AppliedTypeAPI { + def tycon(implicit ctx: Context): Type = x.tycon + def args(implicit ctx: Context): List[TypeOrBounds] = x.args + } + object AppliedType extends AppliedTypeExtractor { 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))) @@ -102,6 +196,18 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsAnnotatedType extends IsAnnotatedTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AnnotatedType] = tpe match { + case tpe: Types.AnnotatedType => Some(tpe) + case _ => None + } + } + + def AnnotatedTypeDeco(x: AnnotatedType): AnnotatedTypeAPI = new AnnotatedTypeAPI { + def underlying(implicit ctx: Context): Type = x.underlying.stripTypeVar + def annot(implicit ctx: Context): Term = x.annot.tree + } + object AnnotatedType extends AnnotatedTypeExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Term)] = x match { case Types.AnnotatedType(underlying, annot) => Some((underlying.stripTypeVar, annot.tree)) @@ -109,6 +215,18 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsAndType extends IsAndTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AndType] = tpe match { + case tpe: Types.AndType => Some(tpe) + case _ => None + } + } + + def AndTypeDeco(x: AndType): AndTypeAPI = new AndTypeAPI { + def left(implicit ctx: Context): Type = x.tp1.stripTypeVar + def right(implicit ctx: Context): Type = x.tp2.stripTypeVar + } + object AndType extends AndTypeExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = x match { case Types.AndType(left, right) => Some(left.stripTypeVar, right.stripTypeVar) @@ -116,6 +234,18 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsOrType extends IsOrTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] = tpe match { + case tpe: Types.OrType => Some(tpe) + case _ => None + } + } + + def OrTypeDeco(x: OrType): OrTypeAPI = new OrTypeAPI { + def left(implicit ctx: Context): Type = x.tp1 + def right(implicit ctx: Context): Type = x.tp2 + } + object OrType extends OrTypeExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] = x match { case Types.OrType(left, right) => Some(left.stripTypeVar, right.stripTypeVar) @@ -123,6 +253,19 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsMatchType extends IsMatchTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MatchType] = tpe match { + case tpe: Types.MatchType => Some(tpe) + case _ => None + } + } + + def MatchTypeDeco(x: MatchType): MatchTypeAPI = new 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 + } + object MatchType extends MatchTypeExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type, List[Type])] = x match { case Types.MatchType(bound, scrutinee, cases) => Some((bound, scrutinee, cases)) @@ -130,6 +273,17 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsByNameType extends IsByNameTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] = tpe match { + case tpe: Types.ExprType => Some(tpe) + case _ => None + } + } + + def ByNameTypeDeco(x: ByNameType): ByNameTypeAPI = new ByNameTypeAPI { + def underlying(implicit ctx: Context): Type = x.resType.stripTypeVar + } + object ByNameType extends ByNameTypeExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { case Types.ExprType(resType) => Some(resType.stripTypeVar) @@ -137,6 +291,20 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + 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 + } + } + + def ParamRefDeco(x: ParamRef): ParamRefAPI = new ParamRefAPI { + def binder(implicit ctx: Context): LambdaType[TypeOrBounds] = + x.binder.asInstanceOf[LambdaType[TypeOrBounds]] // Cast to tpd + def paramNum(implicit ctx: Context): Int = x.paramNum + } + object ParamRef extends ParamRefExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] = x match { case Types.TypeParamRef(binder, idx) => @@ -148,6 +316,17 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsThisType extends IsThisTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] = tpe match { + case tpe: Types.ThisType => Some(tpe) + case _ => None + } + } + + def ThisTypeDeco(x: ThisType): ThisTypeAPI = new ThisTypeAPI { + def underlying(implicit ctx: Context): Type = x.underlying + } + object ThisType extends ThisTypeExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { case Types.ThisType(tp) => Some(tp) @@ -155,6 +334,17 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsRecursiveThis extends IsRecursiveThisModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] = tpe match { + case tpe: Types.RecThis => Some(tpe) + case _ => None + } + } + + def RecursiveThisDeco(x: RecursiveThis): RecursiveThisAPI = new RecursiveThisAPI { + def binder(implicit ctx: Context): RecursiveType = x.binder + } + object RecursiveThis extends RecursiveThisExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = x match { case Types.RecThis(binder) => Some(binder) @@ -162,6 +352,17 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsRecursiveType extends IsRecursiveTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] = tpe match { + case tpe: Types.RecType => Some(tpe) + case _ => None + } + } + + def RecursiveTypeDeco(x: RecursiveType): RecursiveTypeAPI = new RecursiveTypeAPI { + def underlying(implicit ctx: Context): Type = x.underlying.stripTypeVar + } + object RecursiveType extends RecursiveTypeExtractor { def unapply(x: TypeOrBounds)(implicit ctx: Context): Option[Type] = x match { case tp: Types.RecType => Some(tp.underlying.stripTypeVar) @@ -169,6 +370,19 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsMethodType extends IsMethodTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] = tpe match { + case tpe: Types.MethodType => Some(tpe) + case _ => None + } + } + + def MethodTypeDeco(x: MethodType): MethodTypeAPI = new MethodTypeAPI { + 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 + } + object MethodType extends MethodTypeExtractor { 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) @@ -176,6 +390,19 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsPolyType extends IsPolyTypeModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[PolyType] = tpe match { + case tpe: Types.PolyType => Some(tpe) + case _ => None + } + } + + def PolyTypeDeco(x: PolyType): PolyTypeAPI = new 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 + } + object PolyType extends PolyTypeExtractor { 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) @@ -183,6 +410,19 @@ trait TypeOrBoundsOpsImpl extends scala.tasty.reflect.TypeOrBoundsOps with CoreI } } + object IsTypeLambda extends IsTypeLambdaModule { + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] = tpe match { + case tpe: Types.TypeLambda => Some(tpe) + case _ => None + } + } + + def TypeLambdaDeco(x: TypeLambda): TypeLambdaAPI = new 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 + } + object TypeLambda extends TypeLambdaExtractor { 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) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala index b569a1d436cf..d2f5754d80e7 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala @@ -3,7 +3,7 @@ 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.Types +import dotty.tools.dotc.core.{Contexts, Types} trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps with CoreImpl { @@ -31,6 +31,17 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w 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 + } + } + + def InferredDeco(x: Inferred): InferredAPI = new InferredAPI { + + } + object Inferred extends InferredExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Boolean = x match { case x @ Trees.TypeTree() => !x.tpe.isInstanceOf[Types.TypeBounds] @@ -38,6 +49,17 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + 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 + } + } + + def IdentDeco(x: Ident): IdentAPI = new IdentAPI { + def name(implicit ctx: Contexts.Context): String = x.name.toString + } + object Ident extends IdentExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Option[String] = x match { case x: tpd.Ident if x.isType => Some(x.name.toString) @@ -45,6 +67,18 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + 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 + } + } + + def SelectDeco(x: Select): SelectAPI = new SelectAPI { + def qualifier(implicit ctx: Contexts.Context): Term = x.qualifier + def name(implicit ctx: Contexts.Context): String = x.name.toString + } + object Select extends SelectExtractor { 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) @@ -52,6 +86,18 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsProject extends IsProjectModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Project] = tpt match { + case tpt: tpd.Select if tpt.isType && tpt.qualifier.isType => Some(tpt) + case _ => None + } + } + + def ProjectDeco(x: Project): ProjectAPI = new ProjectAPI { + def qualifier(implicit ctx: Contexts.Context): TypeTree = x.qualifier + def name(implicit ctx: Contexts.Context): String = x.name.toString + } + object Project extends ProjectExtractor { 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) @@ -59,6 +105,17 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsSingleton extends IsSingletonModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Singleton] = tpt match { + case tpt: tpd.SingletonTypeTree => Some(tpt) + case _ => None + } + } + + def SingletonDeco(x: Singleton): SingletonAPI = new SingletonAPI { + def ref(implicit ctx: Contexts.Context): Term = x.ref + } + object Singleton extends SingletonExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Option[Term] = x match { case x: tpd.SingletonTypeTree => Some(x.ref) @@ -66,6 +123,18 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsRefined extends IsRefinedModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Refined] = tpt match { + case tpt: tpd.RefinedTypeTree => Some(tpt) + case _ => None + } + } + + def RefinedDeco(x: Refined): RefinedAPI = new RefinedAPI { + def tpt(implicit ctx: Contexts.Context): TypeTree = x.tpt + def refinements(implicit ctx: Contexts.Context): List[Definition] = x.refinements + } + object Refined extends RefinedExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[Definition])] = x match { case x: tpd.RefinedTypeTree => Some(x.tpt, x.refinements) @@ -73,6 +142,18 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsApplied extends IsAppliedModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Applied] = tpt match { + case tpt: tpd.AppliedTypeTree => Some(tpt) + case _ => None + } + } + + def AppliedDeco(x: Applied): AppliedAPI = new AppliedAPI { + def tpt(implicit ctx: Contexts.Context): TypeTree = x.tpt + def args(implicit ctx: Contexts.Context): List[TypeOrBoundsTree] = x.args + } + object Applied extends AppliedExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] = x match { case x: tpd.AppliedTypeTree => Some(x.tpt, x.args) @@ -80,6 +161,18 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsAnnotated extends IsAnnotatedModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Annotated] = tpt match { + case tpt: tpd.Annotated => Some(tpt) + case _ => None + } + } + + def AnnotatedDeco(x: Annotated): AnnotatedAPI = new AnnotatedAPI { + def arg(implicit ctx: Contexts.Context): TypeTree = x.arg + def annotation(implicit ctx: Contexts.Context): Term = x.annot + } + object Annotated extends AnnotatedExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, Term)] = x match { case x: tpd.Annotated => Some(x.arg, x.annot) @@ -87,6 +180,18 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsAnd extends IsAndModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[And] = tpt match { + case tpt: tpd.AndTypeTree => Some(tpt) + case _ => None + } + } + + def AndDeco(x: And): OrAPI = new OrAPI { + def left(implicit ctx: Contexts.Context): TypeTree = x.left + def right(implicit ctx: Contexts.Context): TypeTree = x.right + } + object And extends AndExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] = x match { case x: tpd.AndTypeTree => Some(x.left, x.right) @@ -94,6 +199,18 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsOr extends IsOrModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Or] = tpt match { + case tpt: tpd.OrTypeTree => Some(tpt) + case _ => None + } + } + + def OrDeco(x: Or): OrAPI = new OrAPI { + def left(implicit ctx: Contexts.Context): TypeTree = x.left + def right(implicit ctx: Contexts.Context): TypeTree = x.right + } + object Or extends OrExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] = x match { case x: tpd.OrTypeTree => Some(x.left, x.right) @@ -101,6 +218,19 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsMatchType extends IsMatchTypeModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[MatchType] = tpt match { + case tpt: tpd.MatchTypeTree => Some(tpt) + case _ => None + } + } + + def MatchTypeDeco(x: MatchType): MatchTypeAPI = new 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 + } + object MatchType extends MatchTypeExtractor { 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)) @@ -108,6 +238,17 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsByName extends IsByNameModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[ByName] = tpt match { + case tpt: tpd.ByNameTypeTree => Some(tpt) + case _ => None + } + } + + def ByNameDeco(x: ByName): ByNameAPI = new ByNameAPI { + def result(implicit ctx: Contexts.Context): TypeTree = x.result + } + object ByName extends ByNameExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Option[TypeTree] = x match { case x: tpd.ByNameTypeTree => Some(x.result) @@ -115,13 +256,37 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } - object TypeLambdaTree extends TypeLambdaTreeExtractor { + object IsLambdaTypeTree extends IsLambdaTypeTreeModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[LambdaTypeTree] = tpt match { + case tpt: tpd.LambdaTypeTree => Some(tpt) + case _ => None + } + } + + def LambdaTypeTreeDeco(x: LambdaTypeTree): LambdaTypeTreeAPI = new LambdaTypeTreeAPI { + def tparams(implicit ctx: Contexts.Context): List[TypeDef] = x.tparams + def body(implicit ctx: Contexts.Context): TypeOrBoundsTree = x.body + } + + object LambdaTypeTree extends LambdaTypeTreeExtractor { def unapply(x: TypeTree)(implicit ctx: Context): Option[(List[TypeDef], TypeOrBoundsTree)] = x match { case Trees.LambdaTypeTree(tparams, body) => Some((tparams, body)) case _ => None } } + object IsBind extends IsBindModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Bind] = tpt match { + case tpt: tpd.Bind if tpt.name.isTypeName => Some(tpt) + case _ => None + } + } + + def BindDeco(x: Bind): BindAPI = new BindAPI { + def name(implicit ctx: Contexts.Context): String = x.name.toString + def body(implicit ctx: Contexts.Context): TypeOrBoundsTree = x.body + } + object Bind extends BindExtractor { 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)) @@ -129,6 +294,18 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + object IsBlock extends IsBlockModule { + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Block] = tpt match { + case tpt: tpd.Block => Some(tpt) + case _ => None + } + } + + def BlockDeco(x: Block): BlockAPI = new BlockAPI { + def aliases(implicit ctx: Contexts.Context): List[TypeDef] = x.stats.map { case alias: TypeDef => alias } + def tpt(implicit ctx: Contexts.Context): TypeTree = x.expr + } + object Block extends BlockExtractor { 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)) diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index b9f7bf6d0c57..5ee4b9cd126a 100644 --- a/library/src/scala/tasty/reflect/Core.scala +++ b/library/src/scala/tasty/reflect/Core.scala @@ -33,7 +33,6 @@ package scala.tasty.reflect * +- Inlined * +- SelectOuter * +- While - * +- DoWhile * * * +- TypeTree ----+- Inferred @@ -50,6 +49,7 @@ package scala.tasty.reflect * | +- ByName * | +- LambdaTypeTree * | +- Bind + * | +- Block * | * +- TypeBoundsTree * +- WildcardTypeTree @@ -306,6 +306,9 @@ trait Core { /** Type tree representing a type binding */ type Bind <: TypeTree + /** Type tree within a block with aliases `{ type U1 = ... ; T[U1, U2] }` */ + type Block <: TypeTree + } /** Type tree representing a type bound written in the source */ @@ -329,22 +332,67 @@ trait Core { /** A type */ type Type <: TypeOrBounds - /** A type that is recursively defined */ - type RecursiveType <: Type + /** A singleton type representing a known constant value */ + type ConstantType <: Type + + /** Type of a reference to a symbol */ + type SymRef <: Type + + /** Type of a reference to a term */ + type TermRef <: Type + + /** Type of a reference to a type */ + type TypeRef <: Type + + /** Type of a `super` refernce */ + type SuperType <: Type + + /** A type with a type refinement `T { type U }` */ + type Refinement <: Type + + /** A higher kinded type applied to some types `T[U]` */ + type AppliedType <: Type + + /** A type with an anottation `T @foo` */ + type AnnotatedType <: Type + + /** Intersection type `T & U` */ + type AndType <: Type + + /** Union type `T | U` */ + type OrType <: Type + + /** Type match `T match { case U => ... }` */ + type MatchType <: Type + + /** Type of a by by name parameter */ + type ByNameType <: Type + + /** Type of a parameter reference */ + type ParamRef <: Type + + /** Type of `this` */ + type ThisType <: Type + + /** A type that is recursively defined `this` */ + type RecursiveThis <: Type + + /** A type that is recursively defined */ + type RecursiveType <: Type - // TODO can we add the bound back without an cake? - // TODO is LambdaType really needed? ParamRefExtractor could be split into more precise extractors - /** Common abstraction for lambda types (MethodType, PolyType and TypeLambda). */ - type LambdaType[ParamInfo /*<: TypeOrBounds*/] <: Type + // TODO can we add the bound back without an cake? + // TODO is LambdaType really needed? ParamRefExtractor could be split into more precise extractors + /** Common abstraction for lambda types (MethodType, PolyType and TypeLambda). */ + type LambdaType[ParamInfo /*<: TypeOrBounds*/] <: Type - /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ - type MethodType <: LambdaType[Type] + /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ + type MethodType <: LambdaType[Type] - /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ - type PolyType <: LambdaType[TypeBounds] + /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ + type PolyType <: LambdaType[TypeBounds] - /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ - type TypeLambda <: LambdaType[TypeBounds] + /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ + type TypeLambda <: LambdaType[TypeBounds] /** Import selectors: diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index 99fd55a68db2..e4a216349bc0 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -182,7 +182,7 @@ trait Printers this += "TypeTree.ByName(" += result += ")" case TypeTree.Annotated(arg, annot) => this += "TypeTree.Annotated(" += arg += ", " += annot += ")" - case TypeTree.TypeLambdaTree(tparams, body) => + case TypeTree.LambdaTypeTree(tparams, body) => this += "TypeTree.LambdaTypeTree(" ++= tparams += ", " += body += ")" case TypeTree.Bind(name, bounds) => this += "TypeTree.Bind(" += name += ", " += bounds += ")" @@ -998,7 +998,7 @@ trait Printers case IsTypeBoundsTree(rhs) => printBoundsTree(rhs) case rhs @ WildcardTypeTree() => printTypeOrBound(rhs.tpe) - case rhs @ TypeTree.TypeLambdaTree(tparams, body) => + case rhs @ TypeTree.LambdaTypeTree(tparams, body) => def printParam(t: TypeOrBoundsTree): Unit = t match { case IsTypeBoundsTree(t) => printBoundsTree(t) case IsTypeTree(t) => printTypeTree(t) @@ -1264,7 +1264,7 @@ trait Printers this += highlightTypeDef("=> ", color) printTypeTree(result) - case TypeTree.TypeLambdaTree(tparams, body) => + case TypeTree.LambdaTypeTree(tparams, body) => printTargsDefs(tparams) this += highlightTypeDef(" => ", color) printTypeOrBoundsTree(body) diff --git a/library/src/scala/tasty/reflect/TreeUtils.scala b/library/src/scala/tasty/reflect/TreeUtils.scala index 2cdef500d10a..fb7884b60c0c 100644 --- a/library/src/scala/tasty/reflect/TreeUtils.scala +++ b/library/src/scala/tasty/reflect/TreeUtils.scala @@ -99,7 +99,7 @@ trait TreeUtils case TypeTree.Applied(tpt, args) => foldTypeTrees(foldTypeTree(x, tpt), args) case TypeTree.ByName(result) => foldTypeTree(x, result) case TypeTree.Annotated(arg, annot) => foldTree(foldTypeTree(x, arg), annot) - case TypeTree.TypeLambdaTree(typedefs, arg) => foldTypeTree(foldTrees(x, typedefs), arg) + case TypeTree.LambdaTypeTree(typedefs, arg) => foldTypeTree(foldTrees(x, typedefs), arg) case TypeTree.Bind(_, tbt) => foldTypeTree(x, tbt) case TypeTree.Block(typedefs, tpt) => foldTypeTree(foldTrees(x, typedefs), tpt) case TypeTree.MatchType(boundopt, selector, cases) => diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala index 3b0fbec6d09f..5e1a320b4f86 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala @@ -42,96 +42,322 @@ trait TypeOrBoundsOps extends Core { val Type: TypeModule abstract class TypeModule { + val IsConstantType: IsConstantTypeModule + abstract class IsConstantTypeModule { + /** Matches any ConstantType and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] + } + + trait ConstantTypeAPI { + def value(implicit ctx: Context): Any + } + implicit def ConstantTypeDeco(x: ConstantType): ConstantTypeAPI + val ConstantType: ConstantTypeExtractor abstract class ConstantTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Constant] } + val IsSymRef: IsSymRefModule + abstract class IsSymRefModule { + /** 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 */ + } + implicit def SymRefDeco(x: SymRef): SymRefAPI + val SymRef: SymRefExtractor abstract class SymRefExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] } + val IsTermRef: IsTermRefModule + abstract class IsTermRefModule { + /** 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 */ + } + implicit def TermRefDeco(x: TermRef): TermRefAPI + val TermRef: TermRefExtractor abstract class TermRefExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] } + val IsTypeRef: IsTypeRefModule + abstract class IsTypeRefModule { + /** Matches any TypeRef and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeRef] + } + + trait TypeRefAPI { + def name(implicit ctx: Context): String + def qualifier(implicit ctx: Context): TypeOrBounds /* Type | NoPrefix */ + } + implicit def TypeRefDeco(x: TypeRef): TypeRefAPI + val TypeRef: TypeRefExtractor abstract class TypeRefExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] } + val IsSuperType: IsSuperTypeModule + abstract class IsSuperTypeModule { + /** 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 + } + implicit def SuperTypeDeco(x: SuperType): SuperTypeAPI + val SuperType: SuperTypeExtractor abstract class SuperTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] } + val IsRefinement: IsRefinementModule + abstract class IsRefinementModule { + /** 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 + } + implicit def RefinementDeco(x: Refinement): RefinementAPI + val Refinement: RefinementExtractor abstract class RefinementExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] } + val IsAppliedType: IsAppliedTypeModule + abstract class IsAppliedTypeModule { + /** Matches any AppliedType and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[AppliedType] + } + + trait AppliedTypeAPI { + def tycon(implicit ctx: Context): Type + def args(implicit ctx: Context): List[TypeOrBounds /* Type | TypeBounds */] + } + implicit def AppliedTypeDeco(x: AppliedType): AppliedTypeAPI + val AppliedType: AppliedTypeExtractor abstract class AppliedTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] } + val IsAnnotatedType: IsAnnotatedTypeModule + abstract class IsAnnotatedTypeModule { + /** 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 + } + implicit def AnnotatedTypeDeco(x: AnnotatedType): AnnotatedTypeAPI + val AnnotatedType: AnnotatedTypeExtractor abstract class AnnotatedTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Term)] } + val IsAndType: IsAndTypeModule + abstract class IsAndTypeModule { + /** 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 + } + implicit def AndTypeDeco(x: AndType): AndTypeAPI + val AndType: AndTypeExtractor abstract class AndTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] } + val IsOrType: IsOrTypeModule + abstract class IsOrTypeModule { + /** Matches any OrType and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[OrType] + } + + trait OrTypeAPI { + def left(implicit ctx: Context): Type + def right(implicit ctx: Context): Type + } + implicit def OrTypeDeco(x: OrType): OrTypeAPI + val OrType: OrTypeExtractor abstract class OrTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type)] } + val IsMatchType: IsMatchTypeModule + abstract class IsMatchTypeModule { + /** 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] + } + implicit def MatchTypeDeco(x: MatchType): MatchTypeAPI + val MatchType: MatchTypeExtractor abstract class MatchTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(Type, Type, List[Type])] } + val IsByNameType: IsByNameTypeModule + abstract class IsByNameTypeModule { + /** Matches any ByNameType and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ByNameType] + } + + trait ByNameTypeAPI { + def underlying(implicit ctx: Context): Type + } + implicit def ByNameTypeDeco(x: ByNameType): ByNameTypeAPI + val ByNameType: ByNameTypeExtractor abstract class ByNameTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] } + val IsParamRef: IsParamRefModule + abstract class IsParamRefModule { + /** Matches any ParamRef and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ParamRef] + } + + trait ParamRefAPI { + def binder(implicit ctx: Context): LambdaType[TypeOrBounds] + def paramNum(implicit ctx: Context): Int + } + implicit def ParamRefDeco(x: ParamRef): ParamRefAPI + val ParamRef: ParamRefExtractor abstract class ParamRefExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] } + val IsThisType: IsThisTypeModule + abstract class IsThisTypeModule { + /** Matches any ThisType and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ThisType] + } + + trait ThisTypeAPI { + def underlying(implicit ctx: Context): Type + } + implicit def ThisTypeDeco(x: ThisType): ThisTypeAPI + val ThisType: ThisTypeExtractor abstract class ThisTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] } + val IsRecursiveThis: IsRecursiveThisModule + abstract class IsRecursiveThisModule { + /** Matches any RecursiveThis and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveThis] + } + + trait RecursiveThisAPI { + def binder(implicit ctx: Context): RecursiveType + } + implicit def RecursiveThisDeco(x: RecursiveThis): RecursiveThisAPI + val RecursiveThis: RecursiveThisExtractor abstract class RecursiveThisExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] } + val IsRecursiveType: IsRecursiveTypeModule + abstract class IsRecursiveTypeModule { + /** Matches any RecursiveType and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[RecursiveType] + } + + trait RecursiveTypeAPI { + def underlying(implicit ctx: Context): Type + } + implicit def RecursiveTypeDeco(x: RecursiveType): RecursiveTypeAPI + val RecursiveType: RecursiveTypeExtractor abstract class RecursiveTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[Type] } + val IsMethodType: IsMethodTypeModule + abstract class IsMethodTypeModule { + /** Matches any MethodType and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[MethodType] + } + + trait MethodTypeAPI { + def paramNames(implicit ctx: Context): List[String] + def paramTypes(implicit ctx: Context): List[Type] + def resType(implicit ctx: Context): Type + } + implicit def MethodTypeDeco(x: MethodType): MethodTypeAPI + val MethodType: MethodTypeExtractor abstract class MethodTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[Type], Type)] } + val IsPolyType: IsPolyTypeModule + abstract class IsPolyTypeModule { + /** 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 + } + implicit def PolyTypeDeco(x: PolyType): PolyTypeAPI + val PolyType: PolyTypeExtractor abstract class PolyTypeExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] } + val IsTypeLambda: IsTypeLambdaModule + abstract class IsTypeLambdaModule { + /** Matches any TypeLambda and returns it */ + def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[TypeLambda] + } + + trait TypeLambdaAPI { + def paramNames(implicit ctx: Context): List[String] + def paramBounds(implicit ctx: Context): List[TypeBounds] + def resType(implicit ctx: Context): Type + } + implicit def TypeLambdaDeco(x: TypeLambda): TypeLambdaAPI + val TypeLambda: TypeLambdaExtractor abstract class TypeLambdaExtractor { def unapply(typeOrBounds: TypeOrBounds)(implicit ctx: Context): Option[(List[String], List[TypeBounds], Type)] diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala index ed52f2c5f8c9..6f552d92a41c 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala @@ -28,6 +28,15 @@ trait TypeOrBoundsTreeOps extends Core { val TypeTree: TypeTreeModule abstract class TypeTreeModule extends TypeTreeCoreModule { + val IsInferred: IsInferredModule + abstract class IsInferredModule { + /** Matches any Inferred and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Inferred] + } + + trait InferredAPI { + } + implicit def InferredDeco(x: Inferred): InferredAPI /** TypeTree containing an inferred type */ val Inferred: InferredExtractor @@ -36,73 +45,239 @@ trait TypeOrBoundsTreeOps extends Core { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean } + val IsIdent: IsIdentModule + abstract class IsIdentModule { + /** Matches any Ident and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Ident] + } + + trait IdentAPI { + def name(implicit ctx: Context): String + } + implicit def IdentDeco(x: Ident): IdentAPI + val Ident: IdentExtractor abstract class IdentExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[String] } + val IsSelect: IsSelectModule + abstract class IsSelectModule { + /** Matches any Select and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Select] + } + + trait SelectAPI { + def qualifier(implicit ctx: Context): Term + def name(implicit ctx: Context): String + } + implicit def SelectDeco(x: Select): SelectAPI + val Select: SelectExtractor abstract class SelectExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(Term, String)] } + val IsProject: IsProjectModule + abstract class IsProjectModule { + /** Matches any Project and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Project] + } + + trait ProjectAPI { + def qualifier(implicit ctx: Context): TypeTree + def name(implicit ctx: Context): String + } + implicit def ProjectDeco(x: Project): ProjectAPI + val Project: ProjectExtractor abstract class ProjectExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, String)] } + val IsSingleton: IsSingletonModule + abstract class IsSingletonModule { + /** Matches any Singleton and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Singleton] + } + + trait SingletonAPI { + def ref(implicit ctx: Context): Term + } + implicit def SingletonDeco(x: Singleton): SingletonAPI + val Singleton: SingletonExtractor abstract class SingletonExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[Term] } + val IsRefined: IsRefinedModule + abstract class IsRefinedModule { + /** 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] + } + implicit def RefinedDeco(x: Refined): RefinedAPI + val Refined: RefinedExtractor abstract class RefinedExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, List[Definition])] } + val IsApplied: IsAppliedModule + abstract class IsAppliedModule { + /** 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] + } + implicit def AppliedDeco(x: Applied): AppliedAPI + val Applied: AppliedExtractor abstract class AppliedExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] } + val IsAnnotated: IsAnnotatedModule + abstract class IsAnnotatedModule { + /** Matches any Annotated and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Annotated] + } + + trait AnnotatedAPI { + def arg(implicit ctx: Context): TypeTree + def annotation(implicit ctx: Context): Term + } + implicit def AnnotatedDeco(x: Annotated): AnnotatedAPI + val Annotated: AnnotatedExtractor abstract class AnnotatedExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, Term)] } + val IsAnd: IsAndModule + abstract class IsAndModule { + /** Matches any And and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[And] + } + + trait AndAPI { + def left(implicit ctx: Context): TypeTree + def right(implicit ctx: Context): TypeTree + } + implicit def AndDeco(x: And): OrAPI + val And: AndExtractor abstract class AndExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] } + val IsOr: IsOrModule + abstract class IsOrModule { + /** Matches any Or and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Or] + } + + trait OrAPI { + def left(implicit ctx: Context): TypeTree + def right(implicit ctx: Context): TypeTree + } + implicit def OrDeco(x: Or): OrAPI + val Or: OrExtractor abstract class OrExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] } + val IsMatchType: IsMatchTypeModule + abstract class IsMatchTypeModule { + /** 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] + } + implicit def MatchTypeDeco(x: MatchType): MatchTypeAPI + val MatchType: MatchTypeExtractor abstract class MatchTypeExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] } + val IsByName: IsByNameModule + abstract class IsByNameModule { + /** Matches any ByName and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[ByName] + } + + trait ByNameAPI { + def result(implicit ctx: Context): TypeTree + } + implicit def ByNameDeco(x: ByName): ByNameAPI + val ByName: ByNameExtractor abstract class ByNameExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] } - val TypeLambdaTree: TypeLambdaTreeExtractor - abstract class TypeLambdaTreeExtractor { + val IsLambdaTypeTree: IsLambdaTypeTreeModule + abstract class IsLambdaTypeTreeModule { + /** 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 + } + implicit def LambdaTypeTreeDeco(x: LambdaTypeTree): LambdaTypeTreeAPI + + val LambdaTypeTree: LambdaTypeTreeExtractor + abstract class LambdaTypeTreeExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(List[TypeDef], TypeOrBoundsTree)] } + val IsBind: IsBindModule + abstract class IsBindModule { + /** Matches any Bind and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Bind] + } + + trait BindAPI { + def name(implicit ctx: Context): String + def body(implicit ctx: Context): TypeOrBoundsTree + } + implicit def BindDeco(x: Bind): BindAPI + val Bind: BindExtractor - abstract class BindExtractor{ + abstract class BindExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree)] } + val IsBlock: IsBlockModule + abstract class IsBlockModule { + /** Matches any Block and returns it */ + def unapply(tpt: TypeOrBoundsTree)(implicit ctx: Context): Option[Block] + } + + trait BlockAPI { + def aliases(implicit ctx: Context): List[TypeDef] + def tpt(implicit ctx: Context): TypeTree + } + implicit def BlockDeco(x: Block): BlockAPI + val Block: BlockExtractor - abstract class BlockExtractor{ + abstract class BlockExtractor { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(List[TypeDef], TypeTree)] } }