Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ReflectionUtils - use at your own peril #196

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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