summaryrefslogtreecommitdiff
path: root/test/files/run/reify_copypaste1.scala
blob: c597b7af19c2909ec945ceaabaa3ab366f9b85b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import scala.reflect.runtime._
import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe.definitions._
import scala.reflect.runtime.universe.Flag._
import scala.tools.reflect.ToolBox

object Test extends App {
  val stdout = System.out
  val output = new java.io.ByteArrayOutputStream()
  System.setOut(new java.io.PrintStream(output))
  val toolBox = currentMirror.mkToolBox(options = "-Yreify-copypaste")
  val reify = Select(Select(Select(Select(Ident(ScalaPackage), newTermName("reflect")), newTermName("runtime")), newTermName("universe")), newTermName("reify"))
  val reifee = Block(List(ValDef(Modifiers(LAZY), newTermName("x"), TypeTree(), Apply(Ident(ListModule), List(Literal(Constant(1)), Literal(Constant(2)))))), Ident(newTermName("x")))
  toolBox.eval(Apply(reify, List(reifee)))
  val Block(List(tpeCopypaste), exprCopypaste @ ModuleDef(_, _, Template(_, _, (_ :: stats) :+ expr))) = toolBox.parse(output.toString())
  output.reset()
  toolBox.eval(Block(stats, expr))
  stdout.println(output.toString)
}