Skip to content

Commit

Permalink
Use extensions for show* in Reflection
Browse files Browse the repository at this point in the history
Workaround scala#8188 by renaming on of the `show` to `showWith`
  • Loading branch information
nicolasstucki committed Feb 4, 2020
1 parent c48a598 commit e7bf627
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions library/src/scala/quoted/QuoteContext.scala
Expand Up @@ -14,12 +14,12 @@ class QuoteContext(val tasty: scala.tasty.Reflection) {

def show(expr: Expr[_], syntaxHighlight: SyntaxHighlight): String = {
import tasty.{_, given}
expr.unseal.show(syntaxHighlight)
expr.unseal.showWith(syntaxHighlight)
}

def show(tpe: Type[_], syntaxHighlight: SyntaxHighlight): String = {
import tasty.{_, given}
tpe.unseal.show(syntaxHighlight)
tpe.unseal.showWith(syntaxHighlight)
}

/** Report an error at the position of the macro expansion */
Expand Down
33 changes: 18 additions & 15 deletions library/src/scala/tasty/Reflection.scala
Expand Up @@ -2641,75 +2641,78 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
//////////////

/** Adds `show` as an extension method of a `Tree` */
implicit class TreeShowDeco(tree: Tree) {
extension TreeShowDeco on (tree: Tree) {
/** Shows the tree as extractors */
def showExtractors(given ctx: Context): String =
new ExtractorsPrinter[self.type](self).showTree(tree)

/** Shows the tree as fully typed source code */
def show(given ctx: Context): String =
show(SyntaxHighlight.plain)
tree.showWith(SyntaxHighlight.plain)

/** Shows the tree as fully typed source code */
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
def showWith(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
new SourceCodePrinter[self.type](self)(syntaxHighlight).showTree(tree)

}

/** Adds `show` as an extension method of a `TypeOrBounds` */
implicit class TypeOrBoundsShowDeco(tpe: TypeOrBounds) {
extension TypeOrBoundsShowDeco on (tpe: TypeOrBounds) {
/** Shows the tree as extractors */
def showExtractors(given ctx: Context): String =
new ExtractorsPrinter[self.type](self).showTypeOrBounds(tpe)

/** Shows the tree as fully typed source code */
def show(given ctx: Context): String =
show(SyntaxHighlight.plain)
tpe.showWith(SyntaxHighlight.plain)

/** Shows the tree as fully typed source code */
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
def showWith(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
new SourceCodePrinter[self.type](self)(syntaxHighlight).showTypeOrBounds(tpe)
}

/** Adds `show` as an extension method of a `Constant` */
implicit class ConstantShowDeco(const: Constant) {
extension ConstantShowDeco on (const: Constant) {
/** Shows the tree as extractors */
def showExtractors(given ctx: Context): String =
new ExtractorsPrinter[self.type](self).showConstant(const)

/** Shows the tree as fully typed source code */
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
def show(given ctx: Context): String =
const.showWith(SyntaxHighlight.plain)

/** Shows the tree as fully typed source code */
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
def showWith(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
new SourceCodePrinter[self.type](self)(syntaxHighlight).showConstant(const)
}

/** Adds `show` as an extension method of a `Symbol` */
implicit class SymbolShowDeco(symbol: Symbol) {
extension SymbolShowDeco on (symbol: Symbol) {
/** Shows the tree as extractors */
def showExtractors(given ctx: Context): String =
new ExtractorsPrinter[self.type](self).showSymbol(symbol)

/** Shows the tree as fully typed source code */
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
def show(given ctx: Context): String =
symbol.showWith(SyntaxHighlight.plain)

/** Shows the tree as fully typed source code */
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
def showWith(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
new SourceCodePrinter[self.type](self)(syntaxHighlight).showSymbol(symbol)
}

/** Adds `show` as an extension method of a `Flags` */
implicit class FlagsShowDeco(flags: Flags) {
extension FlagsShowDeco on (flags: Flags) {
/** Shows the tree as extractors */
def showExtractors(given ctx: Context): String =
new ExtractorsPrinter[self.type](self).showFlags(flags)

/** Shows the tree as fully typed source code */
def show(given ctx: Context): String = show(SyntaxHighlight.plain)
def show(given ctx: Context): String =
flags.showWith(SyntaxHighlight.plain)

/** Shows the tree as fully typed source code */
def show(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
def showWith(syntaxHighlight: SyntaxHighlight)(given ctx: Context): String =
new SourceCodePrinter[self.type](self)(syntaxHighlight).showFlags(flags)
}

Expand Down

0 comments on commit e7bf627

Please sign in to comment.