Skip to content

Rename TASTy Reflect showCode to show #6284

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

Merged
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
8 changes: 4 additions & 4 deletions library/src-bootstrapped/scala/internal/quoted/Matcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ object Matcher {
println(
s""">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|Scrutinee
| ${scrutinee.showCode}
| ${scrutinee.show}
|
|${scrutinee.showExtractors}
|
|did not match pattern
| ${pattern.showCode}
| ${pattern.show}
|
|${pattern.showExtractors}
|
Expand Down Expand Up @@ -251,12 +251,12 @@ object Matcher {
println(
s""">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|Scrutinee
| ${scrutinee.showCode}
| ${scrutinee.show}
|
|${scrutinee.showExtractors}
|
|did not match pattern
| ${pattern.showCode}
| ${pattern.show}
|
|${pattern.showExtractors}
|
Expand Down
4 changes: 2 additions & 2 deletions library/src-bootstrapped/scala/tasty/reflect/QuotedOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait QuotedOps extends Core { self: Printers =>

/** Show a source code like representation of this expression */
def show(implicit ctx: Context): String =
unseal.showCode
unseal.show
}

implicit class QuotedTypeAPI[T <: AnyKind](tpe: scala.quoted.Type[T]) {
Expand All @@ -24,7 +24,7 @@ trait QuotedOps extends Core { self: Printers =>

/** Show a source code like representation of this type */
def show(implicit ctx: Context): String =
unseal.showCode
unseal.show
}

implicit class TermToQuotedAPI(term: Term) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ trait QuotedOps extends Core { self: Printers =>
/** Show a source code like representation of this expression.
* Will print Ansi colors if ctx.printColors is enabled.
*/
def show(implicit ctx: Context): String =
unseal.showCode
def show(implicit ctx: Context): String = unseal.show
}

implicit class QuotedTypeAPI[T](tpe: scala.quoted.Type[T]) {
Expand All @@ -27,8 +26,7 @@ trait QuotedOps extends Core { self: Printers =>
/** Show a source code like representation of this type
* Will print Ansi colors if ctx.printColors is enabled.
*/
def show(implicit ctx: Context): String =
unseal.showCode
def show(implicit ctx: Context): String = unseal.show
}

implicit class TermToQuotedAPI(term: Term) {
Expand Down
34 changes: 22 additions & 12 deletions library/src/scala/tasty/reflect/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,58 @@ trait Printers
implicit class TreeShowDeco(tree: Tree) {
/** Shows the tree as extractors */
def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showTree(tree)
/** Shows the tree as source code */
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showTree(tree)
/** Shows the tree as fully typed source code.
* Will print Ansi colors if ctx.printColors is enabled.
*/
def show(implicit ctx: Context): String = new SourceCodePrinter().showTree(tree)
}

/** Adds `show` as an extension method of a `TypeOrBounds` */
implicit class TypeOrBoundsShowDeco(tpe: TypeOrBounds) {
/** Shows the tree as extractors */
def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showTypeOrBounds(tpe)
/** Shows the tree as source code */
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showTypeOrBounds(tpe)
/** Shows the tree as fully typed source code.
* Will print Ansi colors if ctx.printColors is enabled.
*/
def show(implicit ctx: Context): String = new SourceCodePrinter().showTypeOrBounds(tpe)
}

/** Adds `show` as an extension method of a `Pattern` */
implicit class PatternShowDeco(pattern: Pattern) {
/** Shows the tree as extractors */
def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showPattern(pattern)
/** Shows the tree as source code */
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showPattern(pattern)
/** Shows the tree as fully typed source code.
* Will print Ansi colors if ctx.printColors is enabled.
*/
def show(implicit ctx: Context): String = new SourceCodePrinter().showPattern(pattern)
}

/** Adds `show` as an extension method of a `Constant` */
implicit class ConstantShowDeco(const: Constant) {
/** Shows the tree as extractors */
def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showConstant(const)
/** Shows the tree as source code */
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showConstant(const)
/** Shows the tree as fully typed source code.
* Will print Ansi colors if ctx.printColors is enabled.
*/
def show(implicit ctx: Context): String = new SourceCodePrinter().showConstant(const)
}

/** Adds `show` as an extension method of a `Symbol` */
implicit class SymbolShowDeco(symbol: Symbol) {
/** Shows the tree as extractors */
def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showSymbol(symbol)
/** Shows the tree as source code */
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showSymbol(symbol)
/** Shows the tree as fully typed source code */
def show(implicit ctx: Context): String = new SourceCodePrinter().showSymbol(symbol)
}

/** Adds `show` as an extension method of a `Flags` */
implicit class FlagsShowDeco(flags: Flags) {
/** Shows the tree as extractors */
def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showFlags(flags)
/** Shows the tree as source code */
def showCode(implicit ctx: Context): String = new SourceCodePrinter().showFlags(flags)
/** Shows the tree as fully typed source code.
* Will print Ansi colors if ctx.printColors is enabled.
*/
def show(implicit ctx: Context): String = new SourceCodePrinter().showFlags(flags)
}

abstract class Printer {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/tasty-macro-error/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Macros {

def impl(x: Expr[Any])(implicit reflect: Reflection): Expr[Unit] = {
import reflect._
error("here is the the argument is " + x.unseal.underlyingArgument.showCode, x.unseal.underlyingArgument.pos)
error("here is the the argument is " + x.unseal.underlyingArgument.show, x.unseal.underlyingArgument.pos)
'{}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/neg/tasty-macro-positions/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ object Macros {
def impl(x: Expr[Any])(implicit reflect: Reflection): Expr[Unit] = {
import reflect._
val pos = x.unseal.underlyingArgument.pos
error("here is the the argument is " + x.unseal.underlyingArgument.showCode, pos)
error("here (+5) is the the argument is " + x.unseal.underlyingArgument.showCode, pos.sourceFile, pos.start + 5, pos.end + 5)
error("here is the the argument is " + x.unseal.underlyingArgument.show, pos)
error("here (+5) is the the argument is " + x.unseal.underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5)
'{}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
if (LOG)
println(
s"""#> $tag:
|${tree.showCode}
|${tree.show}
|${tree.showExtractors}
|
|""".stripMargin)
Expand Down
8 changes: 4 additions & 4 deletions tests/run-with-compiler/quote-matcher-runtime/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ object Macros {
val res = scala.internal.quoted.Matcher.unapply[Tuple](a)(b, reflect).map { tup =>
tup.toArray.toList.map {
case r: Expr[_] =>
s"Expr(${r.unseal.showCode})"
s"Expr(${r.unseal.show})"
case r: quoted.Type[_] =>
s"Type(${r.unseal.showCode})"
s"Type(${r.unseal.show})"
}
}

'{
println("Scrutinee: " + ${a.unseal.showCode.toExpr})
println("Pattern: " + ${b.unseal.showCode.toExpr})
println("Scrutinee: " + ${a.unseal.show.toExpr})
println("Pattern: " + ${b.unseal.show.toExpr})
println("Result: " + ${res.toString.toExpr})
println()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run/f-interpolation-1/FQuote_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object FQuote {

for ((arg, part) <- allArgs.zip(parts.tail)) {
if (part.startsWith("%d") && !(arg.tpe <:< definitions.IntType)) {
return '{s"`${${arg.showCode}}` is not of type Int"}
return '{s"`${${arg.show}}` is not of type Int"}
}

}
Expand Down
2 changes: 1 addition & 1 deletion tests/run/gestalt-type-toolbox-reflect/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object TypeToolbox {
inline def typeTag[T](x: T): String = ${typeTagImpl('[T])}
private def typeTagImpl(tp: Type[_])(implicit reflect: Reflection): Expr[String] = {
import reflect._
val res = tp.unseal.tpe.showCode
val res = tp.unseal.tpe.show
res.toExpr
}

Expand Down
4 changes: 2 additions & 2 deletions tests/run/inferred-repeated-result/test_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ object Macros {

val methods =
tree.tpe.classSymbol.get.classMethods.map { m =>
val name = m.showCode
val returnType = m.tree.returnTpt.tpe.showCode
val name = m.show
val returnType = m.tree.returnTpt.tpe.show
s"$name : $returnType"
}.sorted

Expand Down
2 changes: 1 addition & 1 deletion tests/run/tasty-dealias/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ object Macros {

def impl[T](x: quoted.Type[T])(implicit reflect: Reflection): Expr[String] = {
import reflect._
x.unseal.tpe.dealias.showCode.toExpr
x.unseal.tpe.dealias.show.toExpr
}
}
4 changes: 2 additions & 2 deletions tests/run/tasty-macro-positions/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Macros {
def impl(x: Expr[Any])(implicit reflect: Reflection): Expr[Unit] = {
import reflect._
val pos = x.unseal.underlyingArgument.pos
val code = x.unseal.underlyingArgument.showCode
val code = x.unseal.underlyingArgument.show
'{
println(${posStr(reflect)(pos)})
println(${code.toExpr})
Expand All @@ -23,7 +23,7 @@ object Macros {
def impl2[T](x: quoted.Type[T])(implicit reflect: Reflection): Expr[Unit] = {
import reflect._
val pos = x.unseal.pos
val code = x.unseal.showCode
val code = x.unseal.show
'{
println(${posStr(reflect)(pos)})
println(${code.toExpr})
Expand Down
6 changes: 3 additions & 3 deletions tests/run/tasty-typeof/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ object Macros {
assert(${(typeOf[Object] =:= definitions.ObjectType)}, "Object")
assert(${(typeOf[Nothing] =:= definitions.NothingType)}, "Nothing")

println(${typeOf[List[Int]].showCode})
println(${typeOf[Macros].showCode})
println(${typeOf[Macros.type].showCode})
println(${typeOf[List[Int]].show})
println(${typeOf[Macros].show})
println(${typeOf[Macros.type].show})
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run/xml-interpolation-1/XmlQuote_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object XmlQuote {
// for debugging purpose
def pp(tree: Tree): Unit = {
println(tree.showExtractors)
println(tree.showCode)
println(tree.show)
}

def liftListOfAny(lst: List[Term]): Expr[List[Any]] = lst match {
Expand Down
2 changes: 1 addition & 1 deletion tests/run/xml-interpolation-2/XmlQuote_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object XmlQuote {
// for debugging purpose
def pp(tree: Tree): Unit = {
println(tree.showExtractors)
println(tree.showCode)
println(tree.show)
}

def isSCOpsConversion(tree: Term) =
Expand Down