Skip to content

Commit

Permalink
add scala-styled lambdas rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivoyaa committed Feb 6, 2023
1 parent 001a7d4 commit e68a045
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,31 @@ object LTTRenderables {
override def prefixSplitter: String = "."
}

object ScalaStyledLambdas extends LTTRenderables {
override def r_SymName(sym: SymName, hasPrefix: Boolean): String = {
Long.r_SymName(sym, hasPrefix)
}

override implicit lazy val r_Lambda: Renderable[Lambda] = new Renderable[Lambda] {
override def render(value: Lambda): String = {
s"${value.output.render()}"
}
}

override implicit lazy val r_LambdaParameter: Renderable[LambdaParameter] = new Renderable[LambdaParameter] {
override def render(value: LambdaParameter): String = {
s"_"
}
}

override implicit lazy val r_TypeParam: Renderable[TypeParam] = new Renderable[TypeParam] {
override def render(value: TypeParam): String =
value.ref match {
case n: NameReference if n.symName.name.forall(_.isDigit) =>
s"${value.variance.render()}_"
case other =>
other.render()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ abstract class LightTypeTag private[reflect] (
ref.longNameInternalSymbol
}

/**
* Fully-qualified rendering of a type, including packages and prefix types.
* Traditional Scala notation for lambdas, e.g. scala.util.Either[Int,+_]
*/
def scalaStyledName: String = {
ref.scalaStyledName
}

@deprecated(
"Produces Scala version dependent output, with incorrect prefixes for types with value prefixes. Use `longNameWithPrefix` instead, or `longNameInternalSymbol` for old behavior",
"2.2.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ sealed trait LightTypeTagRef extends Serializable {
getName(r => LTTRenderables.Long.r_SymName(r.symName, hasPrefix = false))
}

final def scalaStyledName: String = {
import izumi.reflect.macrortti.LTTRenderables.ScalaStyledLambdas._
(this: LightTypeTagRef).render()
}

@deprecated(
"Produces Scala version dependent output, with incorrect prefixes for types with value prefixes. Use `longNameWithPrefix` instead, or `longNameInternalSymbol` for old behavior",
"2.2.2"
Expand Down

0 comments on commit e68a045

Please sign in to comment.