Skip to content

Commit

Permalink
Expose ReflectionUtils - use at your own peril (#196)
Browse files Browse the repository at this point in the history
It's still in the internal package, but public.
Made everything inside it private except for `Mirror`.
  • Loading branch information
joroKr21 authored Jan 10, 2024
1 parent f6fdde9 commit 9ccd0eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import scala.annotation.tailrec
import scala.deriving.*
import scala.quoted.*

private[shapeless3] class ReflectionUtils[Q <: Quotes & Singleton](val q: Q):
private given q.type = q
class ReflectionUtils[Q <: Quotes & Singleton](val q: Q):
given q.type = q
import q.reflect.*

case class Mirror(
Expand Down Expand Up @@ -51,17 +51,17 @@ private[shapeless3] class ReflectionUtils[Q <: Quotes & Singleton](val q: Q):
case _: ImplicitSearchFailure => None
instance.flatMap(Mirror(_))

def tupleTypeElements(tp: TypeRepr): List[TypeRepr] =
private def tupleTypeElements(tp: TypeRepr): List[TypeRepr] =
@tailrec def loop(tp: TypeRepr, acc: List[TypeRepr]): List[TypeRepr] = tp match
case AppliedType(_, List(hd: TypeRepr, tl: TypeRepr)) => loop(tl, hd :: acc)
case _ => acc
loop(tp, Nil).reverse

def low(tp: TypeRepr): TypeRepr = tp match
private def low(tp: TypeRepr): TypeRepr = tp match
case tp: TypeBounds => tp.low
case tp => tp

def findMemberType(tp: TypeRepr, name: String): Option[TypeRepr] = tp match
private def findMemberType(tp: TypeRepr, name: String): Option[TypeRepr] = tp match
case Refinement(_, `name`, tp) => Some(low(tp))
case Refinement(parent, _, _) => findMemberType(parent, name)
case AndType(left, right) => findMemberType(left, name).orElse(findMemberType(right, name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ class ReflectionUtils[Q <: Quotes & Singleton](val q: Q):
case _: ImplicitSearchFailure => None
instance.flatMap(Mirror(_))

def tupleTypeElements(tp: TypeRepr): List[TypeRepr] =
private def tupleTypeElements(tp: TypeRepr): List[TypeRepr] =
@tailrec def loop(tp: TypeRepr, acc: List[TypeRepr]): List[TypeRepr] = tp match
case AppliedType(_, List(hd: TypeRepr, tl: TypeRepr)) => loop(tl, hd :: acc)
case _ => acc
loop(tp, Nil).reverse

def low(tp: TypeRepr): TypeRepr = tp match
private def low(tp: TypeRepr): TypeRepr = tp match
case tp: TypeBounds => tp.low
case tp => tp

def findMemberType(tp: TypeRepr, name: String): Option[TypeRepr] = tp match
private def findMemberType(tp: TypeRepr, name: String): Option[TypeRepr] = tp match
case Refinement(_, `name`, tp) => Some(low(tp))
case Refinement(parent, _, _) => findMemberType(parent, name)
case AndType(left, right) => findMemberType(left, name).orElse(findMemberType(right, name))
Expand Down

0 comments on commit 9ccd0eb

Please sign in to comment.