Skip to content

Rename TASTy reflect show to showExtractors #6228

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
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
26 changes: 13 additions & 13 deletions library/src/scala/tasty/reflect/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,47 @@ trait Printers
/** Adds `show` as an extension method of a `Tree` */
implicit class TreeShowDeco(tree: Tree) {
/** Shows the tree as extractors */
def show(implicit ctx: Context): String = new ExtractorsPrinter().showTree(tree)
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)
}

/** Adds `show` as an extension method of a `TypeOrBounds` */
implicit class TypeOrBoundsShowDeco(tpe: TypeOrBounds) {
/** Shows the tree as extractors */
def show(implicit ctx: Context): String = new ExtractorsPrinter().showTypeOrBounds(tpe)
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)
}

/** Adds `show` as an extension method of a `Pattern` */
implicit class PatternShowDeco(pattern: Pattern) {
/** Shows the tree as extractors */
def show(implicit ctx: Context): String = new ExtractorsPrinter().showPattern(pattern)
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)
}

/** Adds `show` as an extension method of a `Constant` */
implicit class ConstantShowDeco(const: Constant) {
/** Shows the tree as extractors */
def show(implicit ctx: Context): String = new ExtractorsPrinter().showConstant(const)
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)
}

/** Adds `show` as an extension method of a `Symbol` */
implicit class SymbolShowDeco(symbol: Symbol) {
/** Shows the tree as extractors */
def show(implicit ctx: Context): String = new ExtractorsPrinter().showSymbol(symbol)
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)
}

/** Adds `show` as an extension method of a `Flags` */
implicit class FlagsShowDeco(flags: Flags) {
/** Shows the tree as extractors */
def show(implicit ctx: Context): String = new ExtractorsPrinter().showFlags(flags)
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)
}
Expand Down Expand Up @@ -598,7 +598,7 @@ trait Printers
case IsTerm(Select(IsNew(newTree), _)) =>
printType(newTree.tpe)(Some(cdef.symbol))
case IsTerm(parent) =>
throw new MatchError(parent.show)
throw new MatchError(parent.showExtractors)
}

def printSeparated(list: List[Tree /* Term | TypeTree */]): Unit = list match {
Expand Down Expand Up @@ -937,7 +937,7 @@ trait Printers
printTypeTree(tpt)

case _ =>
throw new MatchError(tree.show)
throw new MatchError(tree.showExtractors)

}

Expand Down Expand Up @@ -1320,7 +1320,7 @@ trait Printers
case Ident("unapply" | "unapplySeq") =>
this += fun.symbol.owner.fullName.stripSuffix("$")
case _ =>
throw new MatchError(fun.show)
throw new MatchError(fun.showExtractors)
}
inParens(printPatterns(patterns, ", "))

Expand All @@ -1332,7 +1332,7 @@ trait Printers
printTypeOrBoundsTree(tpt)

case _ =>
throw new MatchError(pattern.show)
throw new MatchError(pattern.showExtractors)

}

Expand Down Expand Up @@ -1457,7 +1457,7 @@ trait Printers
}

case _ =>
throw new MatchError(tree.show)
throw new MatchError(tree.showExtractors)

}

Expand Down Expand Up @@ -1612,7 +1612,7 @@ trait Printers
this += highlightTypeDef("this", color)

case _ =>
throw new MatchError(tpe.show)
throw new MatchError(tpe.showExtractors)
}

def printImportSelector(sel: ImportSelector): Buffer = sel match {
Expand Down Expand Up @@ -1647,7 +1647,7 @@ trait Printers
case Type.TypeRef("forceInline", Types.ScalaPackage()) => false
case _ => true
}
case x => throw new MatchError(x.show)
case x => throw new MatchError(x.showExtractors)
}
printAnnotations(annots)
if (annots.nonEmpty) this += " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ object Foo {
def inspectBodyImpl(x: Expr[Int])(implicit reflect: Reflection): Expr[String] = {
import reflect._
def definitionString(tree: Tree): Expr[String] = tree.symbol match {
case IsDefDefSymbol(sym) => sym.tree.show
case IsValDefSymbol(sym) => sym.tree.show
case IsBindSymbol(sym) => sym.tree.show
case IsDefDefSymbol(sym) => sym.tree.showExtractors
case IsValDefSymbol(sym) => sym.tree.showExtractors
case IsBindSymbol(sym) => sym.tree.showExtractors
}
x.unseal match {
case Inlined(None, Nil, arg) => definitionString(arg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ object Foo {
def inspectBodyImpl(x: Expr[Int])(implicit reflect: Reflection): Expr[String] = {
import reflect._
def definitionString(tree: Tree): Expr[String] = tree.symbol match {
case IsDefDefSymbol(sym) => sym.tree.show
case IsValDefSymbol(sym) => sym.tree.show
case IsBindSymbol(sym) => sym.tree.show
case IsDefDefSymbol(sym) => sym.tree.showExtractors
case IsValDefSymbol(sym) => sym.tree.showExtractors
case IsBindSymbol(sym) => sym.tree.showExtractors
}
x.unseal match {
case Inlined(None, Nil, arg) => definitionString(arg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ object Macros {
case IsDefinition(tree @ DefDef(name, _, _, _, _)) =>
buff.append(name)
buff.append("\n")
buff.append(tree.symbol.owner.treeOpt.get.show)
buff.append(tree.symbol.owner.treeOpt.get.showExtractors)
buff.append("\n\n")
case IsDefinition(tree @ ValDef(name, _, _)) =>
buff.append(name)
buff.append("\n")
buff.append(tree.symbol.owner.treeOpt.get.show)
buff.append(tree.symbol.owner.treeOpt.get.showExtractors)
buff.append("\n\n")
case _ =>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ object Foo {
import reflect._

def definitionString(tree: Tree): Expr[String] = tree.symbol match {
case IsClassDefSymbol(sym) => sym.tree.show.toExpr
case IsDefDefSymbol(sym) => sym.tree.show.toExpr
case IsValDefSymbol(sym) => sym.tree.show.toExpr
case IsClassDefSymbol(sym) => sym.tree.showExtractors.toExpr
case IsDefDefSymbol(sym) => sym.tree.showExtractors.toExpr
case IsValDefSymbol(sym) => sym.tree.showExtractors.toExpr
case _ => '{"NO DEFINTION"}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ object Foo {
import reflect._

def definitionString(tree: Tree): Expr[String] = tree.symbol match {
case IsClassDefSymbol(sym) => sym.tree.show.toExpr
case IsDefDefSymbol(sym) => sym.tree.show.toExpr
case IsValDefSymbol(sym) => sym.tree.show.toExpr
case IsClassDefSymbol(sym) => sym.tree.showExtractors.toExpr
case IsDefDefSymbol(sym) => sym.tree.showExtractors.toExpr
case IsValDefSymbol(sym) => sym.tree.showExtractors.toExpr
case _ => '{"NO DEFINTION"}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
case Typed(expr, _) => log("<interpretTyped>", tree)(eval(expr))
case Repeated(elems, _) => log("<interpretRepeated>", tree)(interpretRepeated(elems.map(elem => eval(elem))))

case _ => throw new MatchError(tree.show)
case _ => throw new MatchError(tree.showExtractors)
}
}

Expand All @@ -161,7 +161,7 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
println(
s"""#> $tag:
|${tree.showCode}
|${tree.show}
|${tree.showExtractors}
|
|""".stripMargin)
thunk
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/tasty-consumer/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DBConsumer extends TastyConsumer {

override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match {
case IsDefinition(tree) =>
println(tree.show)
println(tree.showExtractors)
super.traverseTree(tree)
case tree =>
super.traverseTree(tree)
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 @@ -40,7 +40,7 @@ object FQuote {
values.forall(isStringConstant) =>
values.collect { case Literal(Constant.String(value)) => value }
case tree =>
throw new QuoteError(s"String literal expected, but ${tree.show} found")
throw new QuoteError(s"String literal expected, but ${tree.showExtractors} found")
}

// [a0, ...]: Any*
Expand Down
2 changes: 1 addition & 1 deletion tests/run/i5119/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ object Macro {
implicit inline def XmlQuote(sc: => StringContext): StringContextOps = new StringContextOps(sc)
def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(implicit reflect: Reflection): Expr[String] = {
import reflect._
(sc.unseal.underlyingArgument.show + "\n" + args.unseal.underlyingArgument.show)
(sc.unseal.underlyingArgument.showExtractors + "\n" + args.unseal.underlyingArgument.showExtractors)
}
}
2 changes: 1 addition & 1 deletion tests/run/i5119b/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Macro {

def impl(arg1: Expr[Any], arg2: Expr[Any])(implicit reflect: Reflection): Expr[String] = {
import reflect._
(arg1.unseal.underlyingArgument.show + "\n" + arg2.unseal.underlyingArgument.show)
(arg1.unseal.underlyingArgument.showExtractors + "\n" + arg2.unseal.underlyingArgument.showExtractors)
}

}
4 changes: 2 additions & 2 deletions tests/run/tasty-argument-tree-1/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ object Macros {
val tree = x.unseal
'{
println()
println("tree: " + ${tree.show})
println("tree deref. vals: " + ${tree.underlying.show})
println("tree: " + ${tree.showExtractors})
println("tree deref. vals: " + ${tree.underlying.showExtractors})
}
}
}
30 changes: 15 additions & 15 deletions tests/run/tasty-definitions-1/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ object Macros {
printout(definitions.ScalaPrimitiveValueClasses.map(_.name).toString)
printout(definitions.ScalaNumericValueClasses.map(_.name).toString)

printout(definitions.UnitType.show)
printout(definitions.ByteType.show)
printout(definitions.CharType.show)
printout(definitions.IntType.show)
printout(definitions.LongType.show)
printout(definitions.FloatType.show)
printout(definitions.DoubleType.show)
printout(definitions.BooleanType.show)
printout(definitions.AnyType.show)
printout(definitions.AnyValType.show)
printout(definitions.AnyRefType.show)
printout(definitions.ObjectType.show)
printout(definitions.NothingType.show)
printout(definitions.NullType.show)
printout(definitions.StringType.show)
printout(definitions.UnitType.showExtractors)
printout(definitions.ByteType.showExtractors)
printout(definitions.CharType.showExtractors)
printout(definitions.IntType.showExtractors)
printout(definitions.LongType.showExtractors)
printout(definitions.FloatType.showExtractors)
printout(definitions.DoubleType.showExtractors)
printout(definitions.BooleanType.showExtractors)
printout(definitions.AnyType.showExtractors)
printout(definitions.AnyValType.showExtractors)
printout(definitions.AnyRefType.showExtractors)
printout(definitions.ObjectType.showExtractors)
printout(definitions.NothingType.showExtractors)
printout(definitions.NullType.showExtractors)
printout(definitions.StringType.showExtractors)


'{println(${buff.result().mkString("\n")})}
Expand Down
4 changes: 2 additions & 2 deletions tests/run/tasty-extractors-1/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ object Macros {
import reflect._

val tree = x.unseal
val treeStr = tree.show
val treeTpeStr = tree.tpe.show
val treeStr = tree.showExtractors
val treeTpeStr = tree.tpe.showExtractors

'{
println(${treeStr})
Expand Down
4 changes: 2 additions & 2 deletions tests/run/tasty-extractors-2/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ object Macros {

val tree = x.unseal

val treeStr = tree.show
val treeTpeStr = tree.tpe.show
val treeStr = tree.showExtractors
val treeTpeStr = tree.tpe.showExtractors

'{
println(${treeStr})
Expand Down
4 changes: 2 additions & 2 deletions tests/run/tasty-extractors-3/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ object Macros {
val traverser = new TreeTraverser {
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match {
case IsTypeBoundsTree(tree) =>
buff.append(tree.tpe.show)
buff.append(tree.tpe.showExtractors)
buff.append("\n\n")
traverseTreeChildren(tree)
case IsTypeTree(tree) =>
buff.append(tree.tpe.show)
buff.append(tree.tpe.showExtractors)
buff.append("\n\n")
traverseTreeChildren(tree)
case _ =>
Expand Down
4 changes: 2 additions & 2 deletions tests/run/tasty-extractors-types/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ object Macros {

val tree = x.unseal
'{
println(${tree.show})
println(${tree.tpe.show})
println(${tree.showExtractors})
println(${tree.tpe.showExtractors})
println()
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run/xml-interpolation-1/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.show)
println(tree.showExtractors)
println(tree.showCode)
}

Expand Down Expand Up @@ -53,7 +53,7 @@ object XmlQuote {
values.forall(isStringConstant) =>
values.collect { case Literal(Constant.String(value)) => value }
case tree =>
abort(s"String literal expected, but ${tree.show} found")
abort(s"String literal expected, but ${tree.showExtractors} found")
}

// [a0, ...]: Any*
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 @@ -21,7 +21,7 @@ object XmlQuote {

// for debugging purpose
def pp(tree: Tree): Unit = {
println(tree.show)
println(tree.showExtractors)
println(tree.showCode)
}

Expand Down