Skip to content

Commit

Permalink
Move logic of CaseDefOps into TreeOps
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Mar 10, 2019
1 parent 3c34dbc commit ae252e1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 58 deletions.
1 change: 0 additions & 1 deletion library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import scala.tasty.reflect._

abstract class Reflection
extends Core
with CaseDefOps
with ConstantOps
with ContextOps
with CommentOps
Expand Down
50 changes: 0 additions & 50 deletions library/src/scala/tasty/reflect/CaseDefOps.scala

This file was deleted.

1 change: 0 additions & 1 deletion library/src/scala/tasty/reflect/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import scala.tasty.util.Chars

trait Printers
extends Core
with CaseDefOps
with ConstantOps
with FlagsOps
with IdOps
Expand Down
44 changes: 44 additions & 0 deletions library/src/scala/tasty/reflect/TreeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1037,4 +1037,48 @@ trait TreeOps extends Core {
kernel.matchWildcardTypeTree(tree).isDefined
}

// ----- CaseDefs ------------------------------------------------

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)
}

object IsCaseDef {
def unapply(self: Tree)(implicit ctx: Context): Option[CaseDef] =
kernel.matchCaseDef(self)
}

object CaseDef {
def apply(pattern: Pattern, guard: Option[Term], rhs: Term)(implicit ctx: Context): CaseDef =
kernel.CaseDef_module_apply(pattern, guard, rhs)

def copy(original: CaseDef)(pattern: Pattern, guard: Option[Term], rhs: Term)(implicit ctx: Context): CaseDef =
kernel.CaseDef_module_copy(original)(pattern, guard, rhs)

def unapply(tree: Tree)(implicit ctx: Context): Option[(Pattern, Option[Term], Term)] =
kernel.matchCaseDef(tree).map( x => (x.pattern, x.guard, x.rhs))
}

implicit class TypeCaseDefAPI(caseDef: TypeCaseDef) {
def pattern(implicit ctx: Context): TypeTree = kernel.TypeCaseDef_pattern(caseDef)
def rhs(implicit ctx: Context): TypeTree = kernel.TypeCaseDef_rhs(caseDef)
}

object IsTypeCaseDef {
def unapply(self: Tree)(implicit ctx: Context): Option[TypeCaseDef] =
kernel.matchTypeCaseDef(self)
}

object TypeCaseDef {
def apply(pattern: TypeTree, rhs: TypeTree)(implicit ctx: Context): TypeCaseDef =
kernel.TypeCaseDef_module_apply(pattern, rhs)

def copy(original: TypeCaseDef)(pattern: TypeTree, rhs: TypeTree)(implicit ctx: Context): TypeCaseDef =
kernel.TypeCaseDef_module_copy(original)(pattern, rhs)

def unapply(tree: Tree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] =
kernel.matchTypeCaseDef(tree).map( x => (x.pattern, x.rhs))
}
}
1 change: 0 additions & 1 deletion library/src/scala/tasty/reflect/TreeUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package reflect
/** Tasty reflect case definition */
trait TreeUtils
extends Core
with CaseDefOps
with PatternOps
with SymbolOps
with TreeOps {
Expand Down
5 changes: 0 additions & 5 deletions semanticdb/src/dotty/semanticdb/SemanticdbConsumer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ class SemanticdbConsumer(sourceFilePath: java.nio.file.Path) extends TastyConsum
def traverseTypeTree(tree: Tree /*TypeTree | TypeBoundsTree*/)(
implicit ctx: Context): Unit =
childrenType = tree :: childrenType
override def traverseCaseDef(tree: CaseDef)(implicit ctx: Context): Unit =
()
override def traverseTypeCaseDef(tree: TypeCaseDef)(
implicit ctx: Context): Unit =
()

def getChildren(tree: Tree)(implicit ctx: Context): List[Tree] = {
children = Nil
Expand Down

0 comments on commit ae252e1

Please sign in to comment.