From 6e9ae187a05b1ca4fe748d8a7b45440a55ceb589 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 5 Dec 2011 17:00:55 +0100 Subject: Another test pack for reflection Also see https://github.com/scala/scala/pull/25. --- test/pending/run/reify_addressbook.scala | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 test/pending/run/reify_addressbook.scala (limited to 'test/pending/run/reify_addressbook.scala') diff --git a/test/pending/run/reify_addressbook.scala b/test/pending/run/reify_addressbook.scala new file mode 100644 index 0000000000..225f26b75e --- /dev/null +++ b/test/pending/run/reify_addressbook.scala @@ -0,0 +1,71 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + case class Person(name: String, age: Int) + + /** An AddressBook takes a variable number of arguments + * which are accessed as a Sequence + */ + class AddressBook(a: Person*) { + private val people: List[Person] = a.toList + + /** Serialize to XHTML. Scala supports XML literals + * which may contain Scala expressions between braces, + * which are replaced by their evaluation + */ + def toXHTML = + + + + + + { for (p <- people) yield + + + + + } +
NameAge
{ p.name } { p.age.toString() }
; + } + + /** We introduce CSS using raw strings (between triple + * quotes). Raw strings may contain newlines and special + * characters (like \) are not interpreted. + */ + val header = + + + { "My Address Book" } + + + ; + + val people = new AddressBook( + Person("Tom", 20), + Person("Bob", 22), + Person("James", 19)); + + val page = + + { header } + + { people.toXHTML } + + ; + + println(page) + }; + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + toolbox.runExpr(ttree) +} -- cgit v1.2.3