Skip to content

Commit f5bf7fc

Browse files
committed
Move TypeOrBoundsTreeOps into TreeOps
1 parent dd19452 commit f5bf7fc

File tree

6 files changed

+310
-319
lines changed

6 files changed

+310
-319
lines changed

library/src/scala/tasty/Reflection.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ abstract class Reflection
2323
with SymbolOps
2424
with TreeOps
2525
with TreeUtils
26-
with TypeOrBoundsTreeOps
2726
with TypeOrBoundsOps { self =>
2827

2928
def typeOf[T: scala.quoted.Type]: Type =

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ trait Printers
2020
with StandardDefinitions
2121
with SymbolOps
2222
with TreeOps
23-
with TypeOrBoundsTreeOps
2423
with TypeOrBoundsOps {
2524

2625
/** Adds `show` as an extension method of a `Tree` */

library/src/scala/tasty/reflect/TreeOps.scala

Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ trait TreeOps extends Core {
66
// Decorators
77

88
implicit def termAsTermOrTypeTree(term: Term): TermOrTypeTree = term.asInstanceOf[TermOrTypeTree]
9+
implicit def typeTreeAsTermOrTypeTree(term: TypeTree): TermOrTypeTree = term.asInstanceOf[TermOrTypeTree]
910

1011
// ----- Tree -----------------------------------------------------
1112

@@ -741,4 +742,312 @@ trait TreeOps extends Core {
741742
def body(implicit ctx: Context): Term = kernel.While_body(self)
742743
}
743744

745+
// ----- TypeOrBoundsTree ------------------------------------------------
746+
747+
implicit class TypeOrBoundsTreeAPI(self: TypeOrBoundsTree) {
748+
def tpe(implicit ctx: Context): TypeOrBounds = kernel.TypeOrBoundsTree_tpe(self)
749+
}
750+
751+
// ----- TypeTrees ------------------------------------------------
752+
753+
implicit class TypeTreeAPI(self: TypeTree) {
754+
/** Position in the source code */
755+
def pos(implicit ctx: Context): Position = kernel.TypeTree_pos(self)
756+
757+
/** Type of this type tree */
758+
def tpe(implicit ctx: Context): Type = kernel.TypeTree_tpe(self)
759+
760+
/** Symbol of this type tree */
761+
def symbol(implicit ctx: Context): Symbol = kernel.TypeTree_symbol(self)
762+
}
763+
764+
object IsTypeTree {
765+
def unapply(tpt: Tree)(implicit ctx: Context): Option[TypeTree] =
766+
kernel.matchTypeTree(tpt)
767+
def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] =
768+
kernel.matchTypeTreeNotTerm(termOrTypeTree)
769+
}
770+
771+
object TypeTree extends TypeTreeCoreModule {
772+
773+
object IsInferred {
774+
/** Matches any Inferred and returns it */
775+
def unapply(tree: Tree)(implicit ctx: Context): Option[Inferred] =
776+
kernel.matchTypeTree_Inferred(tree)
777+
}
778+
779+
/** TypeTree containing an inferred type */
780+
object Inferred {
781+
def apply(tpe: Type)(implicit ctx: Context): Inferred =
782+
kernel.TypeTree_Inferred_apply(tpe)
783+
/** Matches a TypeTree containing an inferred type */
784+
def unapply(tree: Tree)(implicit ctx: Context): Boolean =
785+
kernel.matchTypeTree_Inferred(tree).isDefined
786+
}
787+
788+
object IsIdent {
789+
/** Matches any Ident and returns it */
790+
def unapply(tree: Tree)(implicit ctx: Context): Option[Ident] =
791+
kernel.matchTypeTree_Ident(tree)
792+
}
793+
794+
object Ident {
795+
// TODO def apply(name: String)(implicit ctx: Context): Ident
796+
def copy(original: Ident)(name: String)(implicit ctx: Context): Ident =
797+
kernel.TypeTree_Ident_copy(original)(name)
798+
def unapply(tree: Tree)(implicit ctx: Context): Option[String] =
799+
kernel.matchTypeTree_Ident(tree).map(_.name)
800+
}
801+
802+
object IsSelect {
803+
/** Matches any Select and returns it */
804+
def unapply(tree: Tree)(implicit ctx: Context): Option[Select] =
805+
kernel.matchTypeTree_Select(tree)
806+
}
807+
808+
object Select {
809+
def apply(qualifier: Term, name: String)(implicit ctx: Context): Select =
810+
kernel.TypeTree_Select_apply(qualifier, name)
811+
def copy(original: Select)(qualifier: Term, name: String)(implicit ctx: Context): Select =
812+
kernel.TypeTree_Select_copy(original)(qualifier, name)
813+
def unapply(tree: Tree)(implicit ctx: Context): Option[(Term, String)] =
814+
kernel.matchTypeTree_Select(tree).map(x => (x.qualifier, x.name))
815+
}
816+
817+
object IsProjection {
818+
/** Matches any Projection and returns it */
819+
def unapply(tree: Tree)(implicit ctx: Context): Option[Projection] =
820+
kernel.matchTypeTree_Projection(tree)
821+
}
822+
823+
object Projection {
824+
// TODO def apply(qualifier: TypeTree, name: String)(implicit ctx: Context): Project
825+
def copy(original: Projection)(qualifier: TypeTree, name: String)(implicit ctx: Context): Projection =
826+
kernel.TypeTree_Projection_copy(original)(qualifier, name)
827+
def unapply(tree: Tree)(implicit ctx: Context): Option[(TypeTree, String)] =
828+
kernel.matchTypeTree_Projection(tree).map(x => (x.qualifier, x.name))
829+
}
830+
831+
object IsSingleton {
832+
/** Matches any Singleton and returns it */
833+
def unapply(tree: Tree)(implicit ctx: Context): Option[Singleton] =
834+
kernel.matchTypeTree_Singleton(tree)
835+
}
836+
837+
object Singleton {
838+
def apply(ref: Term)(implicit ctx: Context): Singleton =
839+
kernel.TypeTree_Singleton_apply(ref)
840+
def copy(original: Singleton)(ref: Term)(implicit ctx: Context): Singleton =
841+
kernel.TypeTree_Singleton_copy(original)(ref)
842+
def unapply(tree: Tree)(implicit ctx: Context): Option[Term] =
843+
kernel.matchTypeTree_Singleton(tree).map(_.ref)
844+
}
845+
846+
object IsRefined {
847+
/** Matches any Refined and returns it */
848+
def unapply(tree: Tree)(implicit ctx: Context): Option[Refined] =
849+
kernel.matchTypeTree_Refined(tree)
850+
}
851+
852+
object Refined {
853+
// TODO def apply(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): Refined
854+
def copy(original: Refined)(tpt: TypeTree, refinements: List[Definition])(implicit ctx: Context): Refined =
855+
kernel.TypeTree_Refined_copy(original)(tpt, refinements)
856+
def unapply(tree: Tree)(implicit ctx: Context): Option[(TypeTree, List[Definition])] =
857+
kernel.matchTypeTree_Refined(tree).map(x => (x.tpt, x.refinements))
858+
}
859+
860+
object IsApplied {
861+
/** Matches any Applied and returns it */
862+
def unapply(tree: Tree)(implicit ctx: Context): Option[Applied] =
863+
kernel.matchTypeTree_Applied(tree)
864+
}
865+
866+
object Applied {
867+
def apply(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied =
868+
kernel.TypeTree_Applied_apply(tpt, args)
869+
def copy(original: Applied)(tpt: TypeTree, args: List[TypeOrBoundsTree])(implicit ctx: Context): Applied =
870+
kernel.TypeTree_Applied_copy(original)(tpt, args)
871+
def unapply(tree: Tree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] =
872+
kernel.matchTypeTree_Applied(tree).map(x => (x.tpt, x.args))
873+
}
874+
875+
object IsAnnotated {
876+
/** Matches any Annotated and returns it */
877+
def unapply(tree: Tree)(implicit ctx: Context): Option[Annotated] =
878+
kernel.matchTypeTree_Annotated(tree)
879+
}
880+
881+
object Annotated {
882+
def apply(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated =
883+
kernel.TypeTree_Annotated_apply(arg, annotation)
884+
def copy(original: Annotated)(arg: TypeTree, annotation: Term)(implicit ctx: Context): Annotated =
885+
kernel.TypeTree_Annotated_copy(original)(arg, annotation)
886+
def unapply(tree: Tree)(implicit ctx: Context): Option[(TypeTree, Term)] =
887+
kernel.matchTypeTree_Annotated(tree).map(x => (x.arg, x.annotation))
888+
}
889+
890+
object IsMatchType {
891+
/** Matches any MatchType and returns it */
892+
def unapply(tree: Tree)(implicit ctx: Context): Option[MatchType] =
893+
kernel.matchTypeTree_MatchType(tree)
894+
}
895+
896+
object MatchType {
897+
def apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType =
898+
kernel.TypeTree_MatchType_apply(bound, selector, cases)
899+
def copy(original: MatchType)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(implicit ctx: Context): MatchType =
900+
kernel.TypeTree_MatchType_copy(original)(bound, selector, cases)
901+
def unapply(tree: Tree)(implicit ctx: Context): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] =
902+
kernel.matchTypeTree_MatchType(tree).map(x => (x.bound, x.selector, x.cases))
903+
}
904+
905+
object IsByName {
906+
/** Matches any ByName and returns it */
907+
def unapply(tree: Tree)(implicit ctx: Context): Option[ByName] =
908+
kernel.matchTypeTree_ByName(tree)
909+
}
910+
911+
object ByName {
912+
def apply(result: TypeTree)(implicit ctx: Context): ByName =
913+
kernel.TypeTree_ByName_apply(result)
914+
def copy(original: ByName)(result: TypeTree)(implicit ctx: Context): ByName =
915+
kernel.TypeTree_ByName_copy(original)(result)
916+
def unapply(tree: Tree)(implicit ctx: Context): Option[TypeTree] =
917+
kernel.matchTypeTree_ByName(tree).map(_.result)
918+
}
919+
920+
object IsLambdaTypeTree {
921+
/** Matches any LambdaTypeTree and returns it */
922+
def unapply(tree: Tree)(implicit ctx: Context): Option[LambdaTypeTree] =
923+
kernel.matchTypeTree_LambdaTypeTree(tree)
924+
}
925+
926+
object LambdaTypeTree {
927+
def apply(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree =
928+
kernel.TypeTree_LambdaTypeTree_apply(tparams, body)
929+
def copy(original: LambdaTypeTree)(tparams: List[TypeDef], body: TypeOrBoundsTree)(implicit ctx: Context): LambdaTypeTree =
930+
kernel.TypeTree_LambdaTypeTree_copy(original)(tparams, body)
931+
def unapply(tree: Tree)(implicit ctx: Context): Option[(List[TypeDef], TypeOrBoundsTree)] =
932+
kernel.matchTypeTree_LambdaTypeTree(tree).map(x => (x.tparams, x.body))
933+
}
934+
935+
object IsTypeBind {
936+
/** Matches any TypeBind and returns it */
937+
def unapply(tree: Tree)(implicit ctx: Context): Option[TypeBind] =
938+
kernel.matchTypeTree_TypeBind(tree)
939+
}
940+
941+
object TypeBind {
942+
// TODO def apply(name: String, tree: Tree)(implicit ctx: Context): TypeBind
943+
def copy(original: TypeBind)(name: String, tpt: TypeOrBoundsTree)(implicit ctx: Context): TypeBind =
944+
kernel.TypeTree_TypeBind_copy(original)(name, tpt)
945+
def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree)] =
946+
kernel.matchTypeTree_TypeBind(tree).map(x => (x.name, x.body))
947+
}
948+
949+
object IsTypeBlock {
950+
/** Matches any TypeBlock and returns it */
951+
def unapply(tree: Tree)(implicit ctx: Context): Option[TypeBlock] =
952+
kernel.matchTypeTree_TypeBlock(tree)
953+
}
954+
955+
object TypeBlock {
956+
def apply(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock =
957+
kernel.TypeTree_TypeBlock_apply(aliases, tpt)
958+
def copy(original: TypeBlock)(aliases: List[TypeDef], tpt: TypeTree)(implicit ctx: Context): TypeBlock =
959+
kernel.TypeTree_TypeBlock_copy(original)(aliases, tpt)
960+
def unapply(tree: Tree)(implicit ctx: Context): Option[(List[TypeDef], TypeTree)] =
961+
kernel.matchTypeTree_TypeBlock(tree).map(x => (x.aliases, x.tpt))
962+
}
963+
}
964+
965+
implicit class TypeTree_IdentAPI(self: TypeTree.Ident) {
966+
def name(implicit ctx: Context): String = kernel.TypeTree_Ident_name(self)
967+
}
968+
969+
implicit class TypeTree_SelectAPI(self: TypeTree.Select) {
970+
def qualifier(implicit ctx: Context): Term = kernel.TypeTree_Select_qualifier(self)
971+
def name(implicit ctx: Context): String = kernel.TypeTree_Select_name(self)
972+
}
973+
974+
implicit class TypeTree_ProjectionAPI(self: TypeTree.Projection) {
975+
def qualifier(implicit ctx: Context): TypeTree = kernel.TypeTree_Projection_qualifier(self)
976+
def name(implicit ctx: Context): String = kernel.TypeTree_Projection_name(self)
977+
}
978+
979+
implicit class TypeTree_SingletonAPI(self: TypeTree.Singleton) {
980+
def ref(implicit ctx: Context): Term = kernel.TypeTree_Singleton_ref(self)
981+
}
982+
983+
implicit class TypeTree_RefinedAPI(self: TypeTree.Refined) {
984+
def tpt(implicit ctx: Context): TypeTree = kernel.TypeTree_Refined_tpt(self)
985+
def refinements(implicit ctx: Context): List[Definition] = kernel.TypeTree_Refined_refinements(self)
986+
}
987+
988+
implicit class TypeTree_AppliedAPI(self: TypeTree.Applied) {
989+
def tpt(implicit ctx: Context): TypeTree = kernel.TypeTree_Applied_tpt(self)
990+
def args(implicit ctx: Context): List[TypeOrBoundsTree] = kernel.TypeTree_Applied_args(self)
991+
}
992+
993+
implicit class TypeTree_AnnotatedAPI(self: TypeTree.Annotated) {
994+
def arg(implicit ctx: Context): TypeTree = kernel.TypeTree_Annotated_arg(self)
995+
def annotation(implicit ctx: Context): Term = kernel.TypeTree_Annotated_annotation(self)
996+
}
997+
998+
implicit class TypeTree_MatchTypeAPI(self: TypeTree.MatchType) {
999+
def bound(implicit ctx: Context): Option[TypeTree] = kernel.TypeTree_MatchType_bound(self)
1000+
def selector(implicit ctx: Context): TypeTree = kernel.TypeTree_MatchType_selector(self)
1001+
def cases(implicit ctx: Context): List[TypeCaseDef] = kernel.TypeTree_MatchType_cases(self)
1002+
}
1003+
1004+
implicit class TypeTree_ByNameAPI(self: TypeTree.ByName) {
1005+
def result(implicit ctx: Context): TypeTree = kernel.TypeTree_ByName_result(self)
1006+
}
1007+
1008+
implicit class TypeTree_LambdaTypeTreeAPI(self: TypeTree.LambdaTypeTree) {
1009+
def tparams(implicit ctx: Context): List[TypeDef] = kernel.TypeTree_LambdaTypeTree_tparams(self)
1010+
def body(implicit ctx: Context): TypeOrBoundsTree = kernel.TypeTree_LambdaTypeTree_body(self)
1011+
}
1012+
1013+
implicit class TypeTree_TypeBindAPI(self: TypeTree.TypeBind) {
1014+
def name(implicit ctx: Context): String = kernel.TypeTree_TypeBind_name(self)
1015+
def body(implicit ctx: Context): TypeOrBoundsTree = kernel.TypeTree_TypeBind_body(self)
1016+
}
1017+
1018+
implicit class TypeTree_TypeBlockAPI(self: TypeTree.TypeBlock) {
1019+
def aliases(implicit ctx: Context): List[TypeDef] = kernel.TypeTree_TypeBlock_aliases(self)
1020+
def tpt(implicit ctx: Context): TypeTree = kernel.TypeTree_TypeBlock_tpt(self)
1021+
}
1022+
1023+
// ----- TypeBoundsTrees ------------------------------------------------
1024+
1025+
implicit class TypeBoundsTreeAPI(self: TypeBoundsTree) {
1026+
def tpe(implicit ctx: Context): TypeBounds = kernel.TypeBoundsTree_tpe(self)
1027+
def low(implicit ctx: Context): TypeTree = kernel.TypeBoundsTree_low(self)
1028+
def hi(implicit ctx: Context): TypeTree = kernel.TypeBoundsTree_hi(self)
1029+
}
1030+
1031+
object IsTypeBoundsTree {
1032+
def unapply(tree: Tree)(implicit ctx: Context): Option[TypeBoundsTree] =
1033+
kernel.matchTypeBoundsTree(tree)
1034+
}
1035+
1036+
object TypeBoundsTree {
1037+
def unapply(tree: Tree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] =
1038+
kernel.matchTypeBoundsTree(tree).map(x => (x.low, x.hi))
1039+
}
1040+
1041+
object IsWildcardTypeTree {
1042+
def unapply(tree: Tree)(implicit ctx: Context): Option[WildcardTypeTree] =
1043+
kernel.matchWildcardTypeTree(tree)
1044+
}
1045+
1046+
/** TypeBoundsTree containing wildcard type bounds */
1047+
object WildcardTypeTree {
1048+
/** Matches a TypeBoundsTree containing wildcard type bounds */
1049+
def unapply(tree: Tree)(implicit ctx: Context): Boolean =
1050+
kernel.matchWildcardTypeTree(tree).isDefined
1051+
}
1052+
7441053
}

library/src/scala/tasty/reflect/TreeUtils.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ trait TreeUtils
77
with CaseDefOps
88
with PatternOps
99
with SymbolOps
10-
with TreeOps
11-
with TypeOrBoundsTreeOps {
10+
with TreeOps {
1211

1312
abstract class TreeAccumulator[X] {
1413

0 commit comments

Comments
 (0)