From 7ceeb1e609598bd89df1c462855625ed266cd154 Mon Sep 17 00:00:00 2001 From: Geoffrey Washburn Date: Fri, 11 Jan 2008 08:45:47 +0000 Subject: Had to create a test/pending/jvm5 directory. Moved tests that are failing, but no present fixes into pending. --- test/files/jvm/serialization.check | 146 -------------- test/files/jvm/serialization.scala | 345 -------------------------------- test/files/jvm/typerep.check | 47 ----- test/files/jvm/typerep.scala | 374 ----------------------------------- test/files/jvm5/annotations.scala | 159 --------------- test/files/run/classof.check | 1 - test/files/run/classof.scala | 8 - test/pending/jvm/serialization.check | 146 ++++++++++++++ test/pending/jvm/serialization.scala | 345 ++++++++++++++++++++++++++++++++ test/pending/jvm/typerep.check | 47 +++++ test/pending/jvm/typerep.scala | 374 +++++++++++++++++++++++++++++++++++ test/pending/jvm5/annotations.scala | 159 +++++++++++++++ test/pending/run/classof.check | 1 + test/pending/run/classof.scala | 8 + 14 files changed, 1080 insertions(+), 1080 deletions(-) delete mode 100644 test/files/jvm/serialization.check delete mode 100644 test/files/jvm/serialization.scala delete mode 100644 test/files/jvm/typerep.check delete mode 100644 test/files/jvm/typerep.scala delete mode 100644 test/files/jvm5/annotations.scala delete mode 100644 test/files/run/classof.check delete mode 100644 test/files/run/classof.scala create mode 100644 test/pending/jvm/serialization.check create mode 100644 test/pending/jvm/serialization.scala create mode 100644 test/pending/jvm/typerep.check create mode 100644 test/pending/jvm/typerep.scala create mode 100644 test/pending/jvm5/annotations.scala create mode 100644 test/pending/run/classof.check create mode 100644 test/pending/run/classof.scala diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check deleted file mode 100644 index 144e31603f..0000000000 --- a/test/files/jvm/serialization.check +++ /dev/null @@ -1,146 +0,0 @@ -x1 = List() -y1 = List() -x1 eq y1: true - y1 eq x1: true - -x2 = None -y2 = None -x2 eq y2: true - y2 eq x2: true - -x3 = Array[1,2,3] -y3 = Array[1,2,3] -arrayEquals(x3, y3): true - -x4 = -y4 = -x4(2): 4 - y4(2): 4 - -x = List((buffers,20), (layers,2), (title,3)) -y = List((buffers,20), (layers,2), (title,3)) -x equals y: true - y equals x: true - -x = Map(buffers -> 20, layers -> 2, title -> 3) -y = Map(buffers -> 20, layers -> 2, title -> 3) -x equals y: true - y equals x: true - -x = Set(2, 3) -y = Set(2, 3) -x equals y: true - y equals x: true - -x = Set(5, 3) -y = Set(5, 3) -x equals y: true - y equals x: true - -x = Queue(a,b,c) -y = Queue(a,b,c) -x equals y: true - y equals x: true - -x = Stack(c, b, a) -y = Stack(c, b, a) -x equals y: true - y equals x: true - -x = Map(42 -> FortyTwo) -y = Map(42 -> FortyTwo) -x equals y: true - y equals x: true - -x = Set(0, 2) -y = Set(0, 2) -x equals y: true - y equals x: true - -x = ArrayBuffer(one, two) -y = ArrayBuffer(one, two) -x equals y: true - y equals x: true - -x = Map(title -> 3, buffers -> 20, layers -> 2) -y = Map(title -> 3, buffers -> 20, layers -> 2) -x equals y: true - y equals x: true - -x = Set(0, 8, 9) -y = Set(0, 8, 9) -x equals y: true - y equals x: true - -x = Set(layers, buffers, title) -y = Set(layers, buffers, title) -x equals y: true - y equals x: true - -x = LinkedList(2, 3) -y = LinkedList(2, 3) -x equals y: true - y equals x: true - -x = Queue(20, 2, 3) -y = Queue(20, 2, 3) -x equals y: true - y equals x: true - -x = Stack(20, 2, 3) -y = Stack(20, 2, 3) -x equals y: true - y equals x: true - -x = ListBuffer(white, black) -y = ListBuffer(white, black) -x equals y: true - y equals x: true - -x = title -y = title -x equals y: true - y equals x: true - -x = - - - - - - - - - - - - - - - - -
Last NameFirst Name
Tom 20
Bob 22
James 19
- - -y = - - - - - - - - - - - - - - - - -
Last NameFirst Name
Tom 20
Bob 22
James 19
- - -x equals y: true - y equals x: true - -x = Tim -y = Tim -x equals y: true - y equals x: true - -x = Bob -y = Bob -x equals y: true - y equals x: true - -x = John -y = John -x equals y: true - y equals x: true - -x = Bill -y = Bill -x equals y: true - y equals x: true - -x = Paul -y = Paul -x equals y: true - y equals x: true - diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala deleted file mode 100644 index 589e82c4c1..0000000000 --- a/test/files/jvm/serialization.scala +++ /dev/null @@ -1,345 +0,0 @@ -//############################################################################ -// Serialization -//############################################################################ -// $Id$ - -import java.lang.System - -object EqualityTest { - def check[A, B](x: A, y: B) { - println("x = " + x) - println("y = " + y) - println("x equals y: " + (x equals y) + " - y equals x: " + (y equals x)) - println() - } -} - -object Serialize { - @throws(classOf[java.io.IOException]) - def write[A](o: A): Array[Byte] = { - val ba = new java.io.ByteArrayOutputStream(512) - val out = new java.io.ObjectOutputStream(ba) - out.writeObject(o) - out.close() - ba.toByteArray() - } - @throws(classOf[java.io.IOException]) - @throws(classOf[ClassNotFoundException]) - def read[A](buffer: Array[Byte]): A = { - val in = - new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) - in.readObject().asInstanceOf[A] - } -} - -//############################################################################ -// Test classes in package "scala" - -@serializable -object Test1_scala { - - private def arrayToString[A](arr: Array[A]): String = - List.fromArray(arr).mkString("Array[",",","]") - - private def arrayEquals[A, B](a1: Array[A], a2: Array[B]) = - (a1.length == a2.length) && - (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) - - val x1 = Nil - val x2 = None - val x3 = Array(1, 2, 3) - val x4 = { x: Int => 2 * x } - - try { - val y1: List[Nothing] = Serialize.read(Serialize.write(x1)) - val y2: Option[Nothing] = Serialize.read(Serialize.write(x2)) - val y3: Array[Int] = Serialize.read(Serialize.write(x3)) - val y4: Function[Int, Int] = Serialize.read(Serialize.write(x4)) - - println("x1 = " + x1) - println("y1 = " + y1) - println("x1 eq y1: " + (x1 eq y1) + " - y1 eq x1: " + (y1 eq x1)) - println - println("x2 = " + x2) - println("y2 = " + y2) - println("x2 eq y2: " + (x2 eq y2) + " - y2 eq x2: " + (y2 eq x2)) - println - println("x3 = " + arrayToString(x3)) - println("y3 = " + arrayToString(y3)) - println("arrayEquals(x3, y3): " + arrayEquals(x3, y3)) - println - println("x4 = ") - println("y4 = ") - println("x4(2): " + x4(2) + " - y4(2): " + y4(2)) - println - } - catch { - case e: Exception => - e.printStackTrace() - println("Error in Test1_scala: " + e) - } -} - -//############################################################################ -// Test classes in package "scala.collection.immutable" - -@serializable -object Test2_immutable { - import scala.collection.immutable.{ - BitSet, ListMap, ListSet, Queue, Stack, TreeSet, TreeMap} - - val x1 = List( - Pair("buffers", 20), - Pair("layers", 2), - Pair("title", 3) - ) - - val x2 = new ListMap[String, Int] - .incl(Pair("buffers", 20)) - .incl(Pair("layers", 2)) - .incl(Pair("title", 3)) - - val x3 = { - val bs = new collection.mutable.BitSet() - bs += 2; bs += 3 - bs.toImmutable - } - - val x4 = new ListSet[Int]().incl(3).incl(5) - - val x5 = new Queue("a", "b", "c") - - val x6 = new Stack().push("a", "b", "c") - - val x7 = new TreeMap[Int, String] + 42 -> "FortyTwo" - - val x8 = new TreeSet[Int]().incl(2).incl(0) - - try { - val y1: List[Pair[String, Int]] = Serialize.read(Serialize.write(x1)) - val y2: ListMap[String, Int] = Serialize.read(Serialize.write(x2)) - val y3: BitSet = Serialize.read(Serialize.write(x3)) - val y4: ListSet[Int] = Serialize.read(Serialize.write(x4)) - val y5: Queue[String] = Serialize.read(Serialize.write(x5)) - val y6: Stack[String] = Serialize.read(Serialize.write(x6)) - val y7: TreeMap[Int, String] = Serialize.read(Serialize.write(x7)) - val y8: TreeSet[Int] = Serialize.read(Serialize.write(x8)) - - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - EqualityTest.check(x3, y3) - EqualityTest.check(x4, y4) - EqualityTest.check(x5, y5) - EqualityTest.check(x6, y6) - EqualityTest.check(x7, y7) - EqualityTest.check(x8, y8) - } - catch { - case e: Exception => - println("Error in Test2_immutable: " + e) - throw e - } -} - -//############################################################################ -// Test classes in package "scala.collection.mutable" - -object Test3_mutable { - import scala.collection.mutable.{ - ArrayBuffer, BitSet, HashMap, HashSet, History, LinkedList, ListBuffer, - Publisher, Queue, RevertableHistory, Stack} - - val x0 = new ArrayBuffer[String] - x0 ++= List("one", "two") - - val x2 = new BitSet() - x2 += 0 - x2 += 8 - x2 += 9 - - val x1 = new HashMap[String, Int] - x1 ++= Test2_immutable.x1 - - val x3 = new HashSet[String] - x3 ++= Test2_immutable.x1.map(p => p._1) - - @serializable - class Feed extends Publisher[String, Feed] - - val x8 = new History[String, Feed] - - val x4 = new LinkedList[Int](2, null) - x4.append(new LinkedList(3, null)) - - val x7 = new ListBuffer[String] - x7 ++= List("white", "black") - - val x5 = new Queue[Int] - x5 ++= Test2_immutable.x1.map(p => p._2) - - val x6 = new Stack[Int] - x6 ++= x5 - - try { - val y0: ArrayBuffer[String] = Serialize.read(Serialize.write(x0)) - val y1: HashMap[String, Int] = Serialize.read(Serialize.write(x1)) - val y2: BitSet = Serialize.read(Serialize.write(x2)) - val y3: HashSet[String] = Serialize.read(Serialize.write(x3)) - val y4: LinkedList[Int] = Serialize.read(Serialize.write(x4)) - val y5: Queue[Int] = Serialize.read(Serialize.write(x5)) - val y6: Stack[Int] = Serialize.read(Serialize.write(x6)) - val y7: ListBuffer[String] = Serialize.read(Serialize.write(x7)) - val y8: History[String, Feed] = Serialize.read(Serialize.write(x8)) - - EqualityTest.check(x0, y0) - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - EqualityTest.check(x3, y3) - EqualityTest.check(x4, y4) - EqualityTest.check(x5, y5) - EqualityTest.check(x6, y6) - EqualityTest.check(x7, y7) - //EqualityTest.check(x8, y8) //todo - } - catch { - case e: Exception => - println("Error in Test3_mutable: " + e) - } -} - -//############################################################################ -// Test classes in package "scala.xml" - -object Test4_xml { - import scala.xml.Elem - - val x1 = title; - - case class Person(name: String, age: Int) - - class AddressBook(a: Person*) { - private val people: List[Person] = a.toList - def toXHTML = - - - - - - { for (val p <- people) yield - - - - } -
Last NameFirst Name
{ p.name } { p.age.toString() }
; - } - - val people = new AddressBook( - Person("Tom", 20), - Person("Bob", 22), - Person("James", 19)) - - val x2 = - - - { people.toXHTML } - - ; - - try { - val y1: scala.xml.Elem = Serialize.read(Serialize.write(x1)) - val y2: scala.xml.Elem = Serialize.read(Serialize.write(x2)) - - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - } - catch { - case e: Exception => - println("Error in Test4_xml: " + e) - } -} - -//############################################################################ -// Test user-defined classes WITHOUT nesting - -@serializable -class Person(_name: String) { - private var name = _name - override def toString() = name - override def equals(that: Any): Boolean = - that.isInstanceOf[Person] && - (name == that.asInstanceOf[Person].name) -} - -@serializable -class Employee(_name: String) { - private var name = _name - override def toString() = name -} -@serializable -object bob extends Employee("Bob") - -object Test5 { - val x1 = new Person("Tim") - val x2 = bob - - try { - val y1: Person = Serialize.read(Serialize.write(x1)) - val y2: Employee = Serialize.read(Serialize.write(x2)) - - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - } - catch { - case e: Exception => - println("Error in Test5: " + e) - } -} - -//############################################################################ -// Test user-defined classes WITH nesting - -@serializable -object Test6 { - @serializable - object bill extends Employee("Bill") { - val x = paul - } - @serializable - object paul extends Person("Paul") { - val x = 4 // bill; => StackOverflowException !!! - } - val x1 = new Person("John") - val x2 = bill - val x3 = paul - - try { - val y1: Person = Serialize.read(Serialize.write(x1)) - val y2: Employee = Serialize.read(Serialize.write(x2)) - val y3: Person = Serialize.read(Serialize.write(x3)) - - EqualityTest.check(x1, y1) - EqualityTest.check(x2, y2) - EqualityTest.check(x3, y3) - } - catch { - case e: Exception => - println("Error in Test6: " + e) - } -} - -//############################################################################ -// Test code - -object Test { - def main(args: Array[String]) { - Test1_scala - Test2_immutable - Test3_mutable - Test4_xml - Test5 - Test6 - } -} - -//############################################################################ - diff --git a/test/files/jvm/typerep.check b/test/files/jvm/typerep.check deleted file mode 100644 index ff98348304..0000000000 --- a/test/files/jvm/typerep.check +++ /dev/null @@ -1,47 +0,0 @@ -Boolean -Boolean -true -Byte -Char -Int -Long -Float -Double -String -Unit - -Some[Int] -Some[Int] -Some[Some[Int]] -None -None - -List[Int] -List[Int] -List[List[Int]] -Nil -List[Any] - -Array[Int] -Array[Array[Int]] -Array[Int] -Array[Int] -Array[Int] -Array[Int] - -Tuple2[Int, String] -Tuple3[Char, Char, String] -Tuple2[Tuple2[Int, String], Tuple2[Int, String]] -Tuple2[Tuple2[Some[Char], Int], Tuple2[Some[Char], Int]] - -Function1[Int, Int] -Int -Function1[Int, Int] -Int -Function1[Int, Function1[Int, Int]] -Function1[Int, Int] -Int -Function3[Boolean, List[Char], Int, Int] -Function2[Function1[Int, Int], Int, Int] -Int - diff --git a/test/files/jvm/typerep.scala b/test/files/jvm/typerep.scala deleted file mode 100644 index b133d7ce99..0000000000 --- a/test/files/jvm/typerep.scala +++ /dev/null @@ -1,374 +0,0 @@ -//############################################################################ -// Type Representation at runtime -//############################################################################ -// $Id: $ - -import TypeRep._ - -object Test extends Application { - testPrimitives - testOptions - testLists - testArrays - testTuples - testFuncs - testClasses -} - -object serialize { - import java.io._ - - @throws(classOf[IOException]) - def write[A](o: A): Array[Byte] = { - val ba = new ByteArrayOutputStream(512) - val out = new ObjectOutputStream(ba) - out.writeObject(o) - out.close() - ba.toByteArray() - } - @throws(classOf[IOException]) - @throws(classOf[ClassNotFoundException]) - def read[A](buffer: Array[Byte]): A = { - val in = - new ObjectInputStream(new ByteArrayInputStream(buffer)) - in.readObject().asInstanceOf[A] - } -} - -object testPrimitives { - println(getType(true)) - val b = false; val bt = getType(b) - println(bt) - val bt1: TypeRep[Boolean] = serialize.read(serialize.write(bt)) - println(bt1 == bt) - println(getType(16.toByte)) - println(getType('a')) - println(getType(3)) - println(getType(3l)) - println(getType(0.0f)) - println(getType(0.0d)) - println(getType("abc")) - println(getType(())) // Unit -// println(getType(classOf[Int])) // Class - println -} - -object testOptions { - println(getType(Some(2))) - val x: Option[Int] = Some(2) - println(getType(x)) - println(getType(Some(Some(3)))) - println(getType(None)) - val y: Option[Int] = None - println(getType(y)) - println -} - -object testLists { - println(getType(List(3))) - println(getType(3 :: Nil)) - println(getType(List(List(3)))) - println(getType(Nil)) - println(getType(List(1, "abc"))) - println -} - -object testArrays { - println(getType(Array(3))) - println(getType(Array(Array(3), Array(4)))) - println(getType(new Array[Int](0))) - println(getType(List(1).toArray)) - println(getType(List[Int]().toArray)) - println(getType(Array(3).drop(1).toArray)) // empty - println -} - -object testTuples { - println(getType((3, "abc"))) - println(getType(Triple('a', 'b', "c"))) - println(getType(((3, "abc"), (4, "xyz")))) - println(getType(((Some('b'), 3), (Some('a'), 4)))) - //println(getType(((Some('b'), 3), (None, 4)))) - println -} - -object testFuncs { - def f1(x: Int): Int = 2 * x - println(getType(f1 _)) - println(getType(f1(2))) - val f2 = (x: Int) => 2 * x - println(getType(f2)) - println(getType(f2(2))) - val f3 = (x: Int) => (y: Int) => x + y - println(getType(f3)) - println(getType(f3(2))) - println(getType(f3(2)(2))) - def f4(b: Boolean, c: List[Char], i: Int): Int = i - println(getType(f4 _)) - def f5(f: Int => Int, x: Int) = f(x) - println(getType(f5 _)) - println(getType(f5(f1, 1))) - println -} - -class Foo { - class Bar(x: Int) -} - - -object foo extends Foo - -package pkg1 { - class C1 - object c1 extends C1 -} - -object testClasses { - /* - case object FooRep extends TypeRep[Foo] { - override def toString = "Foo" - } - implicit def fooRep[A](x: A)(implicit rep: TypeRep[foo.type]): TypeRep[foo.type] = rep - println(getType(foo)) - println(getType(new foo.Bar(0))) - val foo2 = new Foo - println(getType(foo2)) - println(getType(new foo2.Bar(1))) - println - - println(getType(pkg1.c1)) - val c1 = new pkg1.C1 - println(getType(c1)) - println - */ -} - - -/** - * @author Stephane Micheloud - * @version 1.0 - */ -abstract class TypeRep[A] - -object TypeRep { - - def getType[A](x: A)(implicit rep: TypeRep[A]): TypeRep[A] = rep - - def getType[A](x: Option[A])(implicit rep: TypeRep[A]): TypeRep[Option[A]] = (x match { - case Some(v) => SomeRep(rep) - case None => NoneRep // or NoneRep(rep) - }).asInstanceOf[TypeRep[Option[A]]] - - def getType[A](x: List[A])(implicit rep: TypeRep[A]): TypeRep[List[A]] = (x match { - case h :: t => ListRep(getType(h)) - case Nil => NilRep - }).asInstanceOf[TypeRep[List[A]]] - - implicit def boolRep: TypeRep[Boolean] = BooleanRep - implicit def byteRep: TypeRep[Byte] = ByteRep - implicit def charRep: TypeRep[Char] = CharRep - implicit def shortRep: TypeRep[Short] = ShortRep - implicit def intRep: TypeRep[Int] = IntRep - implicit def longRep: TypeRep[Long] = LongRep - implicit def floatRep: TypeRep[Float] = FloatRep - implicit def doubleRep: TypeRep[Double] = DoubleRep - - implicit def unitRep: TypeRep[Unit] = UnitRep -// implicit def classRep: TypeRep[Class] = ClassRep - implicit def stringRep: TypeRep[String] = StringRep - implicit def noneRep: TypeRep[Option[Nothing]] = NoneRep[Nothing](NothingRep.asInstanceOf[TypeRep[Nothing]]) - implicit def anyRep: TypeRep[Any] = AnyRep - implicit def nothingRep: TypeRep[Nothing] = NothingRep - - implicit def someRep[A](implicit elemrep: TypeRep[A]): TypeRep[Some[A]] = - SomeRep(elemrep) - - implicit def listRep[A](implicit elemrep: TypeRep[A]): TypeRep[List[A]] = - ListRep(elemrep) - - implicit def arrayRep[A](implicit elemrep: TypeRep[A]): TypeRep[Array[A]] = - ArrayRep(elemrep) - - implicit def tuple2Rep[A1, A2](implicit _1: TypeRep[A1], _2: TypeRep[A2]): TypeRep[Tuple2[A1, A2]] = - Tuple2Rep(_1, _2) - implicit def tuple3Rep[A1, A2, A3](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3]): TypeRep[Tuple3[A1, A2, A3]] = - Tuple3Rep(_1, _2, _3) - implicit def tuple4Rep[A1, A2, A3, A4](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4]): TypeRep[Tuple4[A1, A2, A3, A4]] = - Tuple4Rep(_1, _2, _3, _4) - implicit def tuple5Rep[A1, A2, A3, A4, A5](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5]): TypeRep[Tuple5[A1, A2, A3, A4, A5]] = - Tuple5Rep(_1, _2, _3, _4, _5) - implicit def tuple6Rep[A1, A2, A3, A4, A5, A6](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5], _6: TypeRep[A6]): TypeRep[Tuple6[A1, A2, A3, A4, A5, A6]] = - Tuple6Rep(_1, _2, _3, _4, _5, _6) - implicit def tuple7Rep[A1, A2, A3, A4, A5, A6, A7](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5], _6: TypeRep[A6], _7: TypeRep[A7]): TypeRep[Tuple7[A1, A2, A3, A4, A5, A6, A7]] = - Tuple7Rep(_1, _2, _3, _4, _5, _6, _7) - implicit def tuple8Rep[A1, A2, A3, A4, A5, A6, A7, A8](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5], _6: TypeRep[A6], _7: TypeRep[A7], _8: TypeRep[A8]): TypeRep[Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] = - Tuple8Rep(_1, _2, _3, _4, _5, _6, _7, _8) - implicit def tuple9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5], _6: TypeRep[A6], _7: TypeRep[A7], _8: TypeRep[A8], _9: TypeRep[A9]): TypeRep[Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] = - Tuple9Rep(_1, _2, _3, _4, _5, _6, _7, _8, _9) - - implicit def func1Rep[A1, B](implicit a1: TypeRep[A1], b: TypeRep[B]): TypeRep[Function1[A1, B]] = - Function1Rep(a1, b) - implicit def func2Rep[A1, A2, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], b: TypeRep[B]): TypeRep[Function2[A1, A2, B]] = - Function2Rep(a1, a2, b) - implicit def func3Rep[A1, A2, A3, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], b: TypeRep[B]): TypeRep[Function3[A1, A2, A3, B]] = - Function3Rep(a1, a2, a3, b) - implicit def func4Rep[A1, A2, A3, A4, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], b: TypeRep[B]): TypeRep[Function4[A1, A2, A3, A4, B]] = - Function4Rep(a1, a2, a3, a4, b) - implicit def func5Rep[A1, A2, A3, A4, A5, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], b: TypeRep[B]): TypeRep[Function5[A1, A2, A3, A4, A5, B]] = - Function5Rep(a1, a2, a3, a4, a5, b) - implicit def func6Rep[A1, A2, A3, A4, A5, A6, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], b: TypeRep[B]): TypeRep[Function6[A1, A2, A3, A4, A5, A6, B]] = - Function6Rep(a1, a2, a3, a4, a5, a6, b) - implicit def func7Rep[A1, A2, A3, A4, A5, A6, A7, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], b: TypeRep[B]): TypeRep[Function7[A1, A2, A3, A4, A5, A6, A7, B]] = - Function7Rep(a1, a2, a3, a4, a5, a6, a7, b) - implicit def func8Rep[A1, A2, A3, A4, A5, A6, A7, A8, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], b: TypeRep[B]): TypeRep[Function8[A1, A2, A3, A4, A5, A6, A7, A8, B]] = - Function8Rep(a1, a2, a3, a4, a5, a6, a7, a8, b) - implicit def func9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], a9: TypeRep[A9], b: TypeRep[B]): TypeRep[Function9[A1, A2, A3, A4, A5, A6, A7, A8, A9, B]] = - Function9Rep(a1, a2, a3, a4, a5, a6, a7, a8, a9, b) -/* - implicit def objectRep[A <: AnyRef](obj: A)(implicit rep: TypeRep[A]): TypeRep[AnyClass] = - ObjectRep(obj.getClass) -*/ - - case object BooleanRep extends TypeRep[Boolean] { - override def toString = "Boolean" - } - case object ByteRep extends TypeRep[Byte] { - override def toString = "Byte" - } - case object CharRep extends TypeRep[Char] { - override def toString = "Char" - } - case object ShortRep extends TypeRep[Short] { - override def toString = "Short" - } - case object IntRep extends TypeRep[Int] { - override def toString = "Int" - } - case object LongRep extends TypeRep[Long] { - override def toString = "Long" - } - case object FloatRep extends TypeRep[Float] { - override def toString = "Float" - } - case object DoubleRep extends TypeRep[Double] { - override def toString = "Double" - } - - case object UnitRep extends TypeRep[Unit] { - override def toString = "Unit" - } -// case object ClassRep extends TypeRep[AnyClass] { -// override def toString = "Class" -// } - case object StringRep extends TypeRep[String] { - override def toString = "String" - } - case object NoneRep extends TypeRep[Option[Nothing]] { - override def toString = "None" - } - case object NilRep extends TypeRep[Nil.type] { - override def toString = "Nil" - } - case object AnyRep extends TypeRep[Any] { - override def toString = "Any" - } - case object NothingRep extends TypeRep[Nothing] { - override def toString = "Nothing" - } - - @serializable - case class SomeRep[A](elemRep: TypeRep[A]) extends TypeRep[Some[A]] { - override def toString = "Some[" + elemRep + "]" - } - @serializable - case class NoneRep[A](elemRep: TypeRep[A]) extends TypeRep[Option[A]] { - override def toString = "None[" + elemRep + "]" - } - - @serializable - case class ListRep[A](elemRep: TypeRep[A]) extends TypeRep[List[A]] { - override def toString = "List[" + elemRep + "]" - } - - @serializable - case class ArrayRep[A](elemRep: TypeRep[A]) extends TypeRep[Array[A]] { - override def toString = "Array[" + elemRep + "]" - } - - @serializable - case class Tuple2Rep[A1, A2](_1: TypeRep[A1], _2: TypeRep[A2]) extends TypeRep[Tuple2[A1, A2]] { - override def toString = "Tuple2[" + _1 + ", " + _2 + "]" - } - @serializable - case class Tuple3Rep[A1, A2, A3](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3]) extends TypeRep[Tuple3[A1, A2, A3]] { - override def toString = "Tuple3[" + _1 + ", " + _2 + ", " + _3 + "]" - } - @serializable - case class Tuple4Rep[A1, A2, A3, A4](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4]) extends TypeRep[Tuple4[A1, A2, A3, A4]] { - override def toString = "Tuple4[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + "]" - } - @serializable - case class Tuple5Rep[A1, A2, A3, A4, A5](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5]) extends TypeRep[Tuple5[A1, A2, A3, A4, A5]] { - override def toString = "Tuple5[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + "]" - } - @serializable - case class Tuple6Rep[A1, A2, A3, A4, A5, A6](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6]) extends TypeRep[Tuple6[A1, A2, A3, A4, A5, A6]] { - override def toString = "Tuple6[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + "]" - } - @serializable - case class Tuple7Rep[A1, A2, A3, A4, A5, A6, A7](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7]) extends TypeRep[Tuple7[A1, A2, A3, A4, A5, A6, A7]] { - override def toString = "Tuple7[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + "]" - } - @serializable - case class Tuple8Rep[A1, A2, A3, A4, A5, A6, A7, A8](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7], val _8: TypeRep[A8]) extends TypeRep[Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] { - override def toString = "Tuple8[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + "]" - } - @serializable - case class Tuple9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7], val _8: TypeRep[A8], val _9: TypeRep[A9]) extends TypeRep[Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] { - override def toString = "Tuple9[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + "]" - } - - @serializable - case class Function1Rep[A1, B](a1: TypeRep[A1], b: TypeRep[B]) extends TypeRep[Function1[A1, B]] { - override def toString = "Function1[" + a1 + ", " + b + "]" - } - @serializable - case class Function2Rep[A1, A2, B](a1: TypeRep[A1], a2: TypeRep[A2], b: TypeRep[B]) extends TypeRep[Function2[A1, A2, B]] { - override def toString = "Function2[" + a1 + ", " + a2 + ", " + b + "]" - } - @serializable - case class Function3Rep[A1, A2, A3, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], b: TypeRep[B]) extends TypeRep[Function3[A1, A2, A3, B]] { - override def toString = "Function3[" + a1 + ", " + a2 + ", " + a3 + ", " + b + "]" - } - @serializable - case class Function4Rep[A1, A2, A3, A4, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], b: TypeRep[B]) extends TypeRep[Function4[A1, A2, A3, A4, B]] { - override def toString = "Function4[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + b + "]" - } - @serializable - case class Function5Rep[A1, A2, A3, A4, A5, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], b: TypeRep[B]) extends TypeRep[Function5[A1, A2, A3, A4, A5, B]] { - override def toString = "Function5[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + b + "]" - } - @serializable - case class Function6Rep[A1, A2, A3, A4, A5, A6, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], b: TypeRep[B]) extends TypeRep[Function6[A1, A2, A3, A4, A5, A6, B]] { - override def toString = "Function6[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + b + "]" - } - @serializable - case class Function7Rep[A1, A2, A3, A4, A5, A6, A7, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], b: TypeRep[B]) extends TypeRep[Function7[A1, A2, A3, A4, A5, A6, A7, B]] { - override def toString = "Function7[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + b + "]" - } - @serializable - case class Function8Rep[A1, A2, A3, A4, A5, A6, A7, A8, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], b: TypeRep[B]) extends TypeRep[Function8[A1, A2, A3, A4, A5, A6, A7, A8, B]] { - override def toString = "Function8[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + a8 + b + "]" - } - @serializable - case class Function9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], a9: TypeRep[A9], b: TypeRep[B]) extends TypeRep[Function9[A1, A2, A3, A4, A5, A6, A7, A8, A9, B]] { - override def toString = "Function9[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + a8 + ", " + b + "]" - } -/* - @serializable - case class ObjectRep[A](c: Class) extends TypeRep[A] { - override def toString = c.getName - } -*/ -} - diff --git a/test/files/jvm5/annotations.scala b/test/files/jvm5/annotations.scala deleted file mode 100644 index 98b82edad4..0000000000 --- a/test/files/jvm5/annotations.scala +++ /dev/null @@ -1,159 +0,0 @@ -object Test1 { - class Foo { - @remote - def foo: Unit = () - } - def run { - val method = classOf[Foo].getMethod("foo", Array()) - method.getExceptionTypes foreach println - } -} - -object Test2 { - import java.io.{BufferedReader,FileReader, IOException} - class Reader(fname: String) { - private val in = new BufferedReader(new FileReader(fname)) - - @throws(classOf[IOException]) - def read() = in.read() - } - def run { - val method = classOf[Reader].getMethod("read", Array()) - method.getExceptionTypes foreach println - } -} - -/* Java: -public class Main { - @Deprecated - public void foo() {} - public static void main(String[] args) throws Exception { - Method method = Class.forName("test.Main").getMethod("foo", new Class[]{}); - Annotation annotation = method.getAnnotation(Deprecated.class); - System.out.println(annotation); // @java.lang.Deprecated() - } -} -*/ -object Test3 { - import java.lang.Deprecated - class Foo { - @Deprecated - def foo: Unit = () - } - def run { - val method = classOf[Foo].getMethod("foo", Array()) - val annotation = method.getAnnotation(classOf[Deprecated]) - println(annotation) - } -} - -/* Java: -@Retention(value=RetentionPolicy.RUNTIME) -@interface Source { - public String url(); - public String mail(); -} -@Source(url="http://scala.epfl.ch", mail="scala@lists.epfl.ch") -class Foo {} -public class Main { - public static void main(String[] args) throws Exception { - Class clazz = Class.forName("test.Foo"); - Annotation[] annotations = clazz.getAnnotations(); - for (int i = 0; i < annotations.length; i++) - System.out.println(annotations[i]); - // @test.Main$Source(url=http://scala-lang.org, mail=scala@lists.epfl.ch) - } -} -*/ -object Test4 { - import test.SourceAnnotation // defined in SourceAnnotation.java - @SourceAnnotation{val value = "http://scala-lang.org", - val mails = Array("scala@lists.epfl.ch", "scala-lounge@lists.epfl.ch")} - class Foo1 - @SourceAnnotation("http://bloodsuckers.com") { val mails = Array("you@bloodsuckers.com") } - class Foo2 - @SourceAnnotation("http://bloodsuckers.com") - class Foo3 - class Foo4 { - @SourceAnnotation("file:///dev/null") - val x = 1 - } - class Foo5 { - @SourceAnnotation("file:///dev/zero") - def bar: Int = 0 - } - class Foo6 @SourceAnnotation("primary constructor")(s: String) { - // to guarantee that primary constructor annotations - // are not applied to secondary constructors - def this() = this("") - } - class Foo7(s: String) { - @SourceAnnotation("secondary constructor") - def this() = this("") - } - class Foo8(@SourceAnnotation("constructor val") val n: Int) {} - def run { - import java.lang.annotation.Annotation - import java.lang.reflect.AnnotatedElement - def printSourceAnnotations(target: AnnotatedElement) { - //print SourceAnnotation in a predefined way to insure - // against difference in the JVMs (e.g. Sun's vs IBM's) - def printSourceAnnotation(a: Annotation) { - val ann = a.asInstanceOf[SourceAnnotation] - println("@test.SourceAnnotation(mails=" + ann.mails.deepMkString("{", ",", "}") + - ", value=" + ann.value + ")") - } - val anns = target.getAnnotations() - anns foreach printSourceAnnotation - if (anns.length > 0) { - println(target) - println - } - } - printSourceAnnotations(classOf[Foo1]) - printSourceAnnotations(classOf[Foo2]) - printSourceAnnotations(classOf[Foo3]) - classOf[Foo4].getDeclaredFields foreach printSourceAnnotations - classOf[Foo4].getDeclaredMethods foreach printSourceAnnotations - classOf[Foo5].getDeclaredMethods foreach printSourceAnnotations - classOf[Foo6].getDeclaredConstructors foreach printSourceAnnotations - classOf[Foo7].getDeclaredConstructors foreach printSourceAnnotations - classOf[Foo8].getDeclaredFields foreach printSourceAnnotations - classOf[Foo8].getDeclaredMethods foreach printSourceAnnotations - } -} - -object Test5 { - import scala.reflect.BeanProperty - import java.lang.Integer - - class Count { - // we use "Integer" instead of "Int" because of Java reflection - @BeanProperty - private var count: Integer = 0 - - private val getter = - getClass().getMethod("getCount", Array[java.lang.Class[T] forSome { type T }]()) - private val setter = - getClass().getMethod("setCount", Array(classOf[Integer])) - - def get = getter.invoke(this, Array()).asInstanceOf[Integer].intValue - def set(n: Int) = setter.invoke(this, Array(new Integer(n))) - } - def run { - val count = new Count - println(count.get) - count.set(99) - println(count.get) - } -} - -object Test { - def main(args: Array[String]) { - Test1.run - Test2.run - Test3.run // requires the use of -target:jvm-1.5 - Test4.run - Test5.run - } -} diff --git a/test/files/run/classof.check b/test/files/run/classof.check deleted file mode 100644 index e9a8fd6b76..0000000000 --- a/test/files/run/classof.check +++ /dev/null @@ -1 +0,0 @@ -SomeClass diff --git a/test/files/run/classof.scala b/test/files/run/classof.scala deleted file mode 100644 index b547e5c8c3..0000000000 --- a/test/files/run/classof.scala +++ /dev/null @@ -1,8 +0,0 @@ -class SomeClass - -object Test { - def main(args: Array[String]): Unit = { - val cls: Class[SomeClass] = classOf[SomeClass] - Console.println(cls.getName()) - } -} diff --git a/test/pending/jvm/serialization.check b/test/pending/jvm/serialization.check new file mode 100644 index 0000000000..144e31603f --- /dev/null +++ b/test/pending/jvm/serialization.check @@ -0,0 +1,146 @@ +x1 = List() +y1 = List() +x1 eq y1: true - y1 eq x1: true + +x2 = None +y2 = None +x2 eq y2: true - y2 eq x2: true + +x3 = Array[1,2,3] +y3 = Array[1,2,3] +arrayEquals(x3, y3): true + +x4 = +y4 = +x4(2): 4 - y4(2): 4 + +x = List((buffers,20), (layers,2), (title,3)) +y = List((buffers,20), (layers,2), (title,3)) +x equals y: true - y equals x: true + +x = Map(buffers -> 20, layers -> 2, title -> 3) +y = Map(buffers -> 20, layers -> 2, title -> 3) +x equals y: true - y equals x: true + +x = Set(2, 3) +y = Set(2, 3) +x equals y: true - y equals x: true + +x = Set(5, 3) +y = Set(5, 3) +x equals y: true - y equals x: true + +x = Queue(a,b,c) +y = Queue(a,b,c) +x equals y: true - y equals x: true + +x = Stack(c, b, a) +y = Stack(c, b, a) +x equals y: true - y equals x: true + +x = Map(42 -> FortyTwo) +y = Map(42 -> FortyTwo) +x equals y: true - y equals x: true + +x = Set(0, 2) +y = Set(0, 2) +x equals y: true - y equals x: true + +x = ArrayBuffer(one, two) +y = ArrayBuffer(one, two) +x equals y: true - y equals x: true + +x = Map(title -> 3, buffers -> 20, layers -> 2) +y = Map(title -> 3, buffers -> 20, layers -> 2) +x equals y: true - y equals x: true + +x = Set(0, 8, 9) +y = Set(0, 8, 9) +x equals y: true - y equals x: true + +x = Set(layers, buffers, title) +y = Set(layers, buffers, title) +x equals y: true - y equals x: true + +x = LinkedList(2, 3) +y = LinkedList(2, 3) +x equals y: true - y equals x: true + +x = Queue(20, 2, 3) +y = Queue(20, 2, 3) +x equals y: true - y equals x: true + +x = Stack(20, 2, 3) +y = Stack(20, 2, 3) +x equals y: true - y equals x: true + +x = ListBuffer(white, black) +y = ListBuffer(white, black) +x equals y: true - y equals x: true + +x = title +y = title +x equals y: true - y equals x: true + +x = + + + + + + + + + + + + + + + + +
Last NameFirst Name
Tom 20
Bob 22
James 19
+ + +y = + + + + + + + + + + + + + + + + +
Last NameFirst Name
Tom 20
Bob 22
James 19
+ + +x equals y: true - y equals x: true + +x = Tim +y = Tim +x equals y: true - y equals x: true + +x = Bob +y = Bob +x equals y: true - y equals x: true + +x = John +y = John +x equals y: true - y equals x: true + +x = Bill +y = Bill +x equals y: true - y equals x: true + +x = Paul +y = Paul +x equals y: true - y equals x: true + diff --git a/test/pending/jvm/serialization.scala b/test/pending/jvm/serialization.scala new file mode 100644 index 0000000000..589e82c4c1 --- /dev/null +++ b/test/pending/jvm/serialization.scala @@ -0,0 +1,345 @@ +//############################################################################ +// Serialization +//############################################################################ +// $Id$ + +import java.lang.System + +object EqualityTest { + def check[A, B](x: A, y: B) { + println("x = " + x) + println("y = " + y) + println("x equals y: " + (x equals y) + " - y equals x: " + (y equals x)) + println() + } +} + +object Serialize { + @throws(classOf[java.io.IOException]) + def write[A](o: A): Array[Byte] = { + val ba = new java.io.ByteArrayOutputStream(512) + val out = new java.io.ObjectOutputStream(ba) + out.writeObject(o) + out.close() + ba.toByteArray() + } + @throws(classOf[java.io.IOException]) + @throws(classOf[ClassNotFoundException]) + def read[A](buffer: Array[Byte]): A = { + val in = + new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) + in.readObject().asInstanceOf[A] + } +} + +//############################################################################ +// Test classes in package "scala" + +@serializable +object Test1_scala { + + private def arrayToString[A](arr: Array[A]): String = + List.fromArray(arr).mkString("Array[",",","]") + + private def arrayEquals[A, B](a1: Array[A], a2: Array[B]) = + (a1.length == a2.length) && + (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) + + val x1 = Nil + val x2 = None + val x3 = Array(1, 2, 3) + val x4 = { x: Int => 2 * x } + + try { + val y1: List[Nothing] = Serialize.read(Serialize.write(x1)) + val y2: Option[Nothing] = Serialize.read(Serialize.write(x2)) + val y3: Array[Int] = Serialize.read(Serialize.write(x3)) + val y4: Function[Int, Int] = Serialize.read(Serialize.write(x4)) + + println("x1 = " + x1) + println("y1 = " + y1) + println("x1 eq y1: " + (x1 eq y1) + " - y1 eq x1: " + (y1 eq x1)) + println + println("x2 = " + x2) + println("y2 = " + y2) + println("x2 eq y2: " + (x2 eq y2) + " - y2 eq x2: " + (y2 eq x2)) + println + println("x3 = " + arrayToString(x3)) + println("y3 = " + arrayToString(y3)) + println("arrayEquals(x3, y3): " + arrayEquals(x3, y3)) + println + println("x4 = ") + println("y4 = ") + println("x4(2): " + x4(2) + " - y4(2): " + y4(2)) + println + } + catch { + case e: Exception => + e.printStackTrace() + println("Error in Test1_scala: " + e) + } +} + +//############################################################################ +// Test classes in package "scala.collection.immutable" + +@serializable +object Test2_immutable { + import scala.collection.immutable.{ + BitSet, ListMap, ListSet, Queue, Stack, TreeSet, TreeMap} + + val x1 = List( + Pair("buffers", 20), + Pair("layers", 2), + Pair("title", 3) + ) + + val x2 = new ListMap[String, Int] + .incl(Pair("buffers", 20)) + .incl(Pair("layers", 2)) + .incl(Pair("title", 3)) + + val x3 = { + val bs = new collection.mutable.BitSet() + bs += 2; bs += 3 + bs.toImmutable + } + + val x4 = new ListSet[Int]().incl(3).incl(5) + + val x5 = new Queue("a", "b", "c") + + val x6 = new Stack().push("a", "b", "c") + + val x7 = new TreeMap[Int, String] + 42 -> "FortyTwo" + + val x8 = new TreeSet[Int]().incl(2).incl(0) + + try { + val y1: List[Pair[String, Int]] = Serialize.read(Serialize.write(x1)) + val y2: ListMap[String, Int] = Serialize.read(Serialize.write(x2)) + val y3: BitSet = Serialize.read(Serialize.write(x3)) + val y4: ListSet[Int] = Serialize.read(Serialize.write(x4)) + val y5: Queue[String] = Serialize.read(Serialize.write(x5)) + val y6: Stack[String] = Serialize.read(Serialize.write(x6)) + val y7: TreeMap[Int, String] = Serialize.read(Serialize.write(x7)) + val y8: TreeSet[Int] = Serialize.read(Serialize.write(x8)) + + EqualityTest.check(x1, y1) + EqualityTest.check(x2, y2) + EqualityTest.check(x3, y3) + EqualityTest.check(x4, y4) + EqualityTest.check(x5, y5) + EqualityTest.check(x6, y6) + EqualityTest.check(x7, y7) + EqualityTest.check(x8, y8) + } + catch { + case e: Exception => + println("Error in Test2_immutable: " + e) + throw e + } +} + +//############################################################################ +// Test classes in package "scala.collection.mutable" + +object Test3_mutable { + import scala.collection.mutable.{ + ArrayBuffer, BitSet, HashMap, HashSet, History, LinkedList, ListBuffer, + Publisher, Queue, RevertableHistory, Stack} + + val x0 = new ArrayBuffer[String] + x0 ++= List("one", "two") + + val x2 = new BitSet() + x2 += 0 + x2 += 8 + x2 += 9 + + val x1 = new HashMap[String, Int] + x1 ++= Test2_immutable.x1 + + val x3 = new HashSet[String] + x3 ++= Test2_immutable.x1.map(p => p._1) + + @serializable + class Feed extends Publisher[String, Feed] + + val x8 = new History[String, Feed] + + val x4 = new LinkedList[Int](2, null) + x4.append(new LinkedList(3, null)) + + val x7 = new ListBuffer[String] + x7 ++= List("white", "black") + + val x5 = new Queue[Int] + x5 ++= Test2_immutable.x1.map(p => p._2) + + val x6 = new Stack[Int] + x6 ++= x5 + + try { + val y0: ArrayBuffer[String] = Serialize.read(Serialize.write(x0)) + val y1: HashMap[String, Int] = Serialize.read(Serialize.write(x1)) + val y2: BitSet = Serialize.read(Serialize.write(x2)) + val y3: HashSet[String] = Serialize.read(Serialize.write(x3)) + val y4: LinkedList[Int] = Serialize.read(Serialize.write(x4)) + val y5: Queue[Int] = Serialize.read(Serialize.write(x5)) + val y6: Stack[Int] = Serialize.read(Serialize.write(x6)) + val y7: ListBuffer[String] = Serialize.read(Serialize.write(x7)) + val y8: History[String, Feed] = Serialize.read(Serialize.write(x8)) + + EqualityTest.check(x0, y0) + EqualityTest.check(x1, y1) + EqualityTest.check(x2, y2) + EqualityTest.check(x3, y3) + EqualityTest.check(x4, y4) + EqualityTest.check(x5, y5) + EqualityTest.check(x6, y6) + EqualityTest.check(x7, y7) + //EqualityTest.check(x8, y8) //todo + } + catch { + case e: Exception => + println("Error in Test3_mutable: " + e) + } +} + +//############################################################################ +// Test classes in package "scala.xml" + +object Test4_xml { + import scala.xml.Elem + + val x1 = title; + + case class Person(name: String, age: Int) + + class AddressBook(a: Person*) { + private val people: List[Person] = a.toList + def toXHTML = + + + + + + { for (val p <- people) yield + + + + } +
Last NameFirst Name
{ p.name } { p.age.toString() }
; + } + + val people = new AddressBook( + Person("Tom", 20), + Person("Bob", 22), + Person("James", 19)) + + val x2 = + + + { people.toXHTML } + + ; + + try { + val y1: scala.xml.Elem = Serialize.read(Serialize.write(x1)) + val y2: scala.xml.Elem = Serialize.read(Serialize.write(x2)) + + EqualityTest.check(x1, y1) + EqualityTest.check(x2, y2) + } + catch { + case e: Exception => + println("Error in Test4_xml: " + e) + } +} + +//############################################################################ +// Test user-defined classes WITHOUT nesting + +@serializable +class Person(_name: String) { + private var name = _name + override def toString() = name + override def equals(that: Any): Boolean = + that.isInstanceOf[Person] && + (name == that.asInstanceOf[Person].name) +} + +@serializable +class Employee(_name: String) { + private var name = _name + override def toString() = name +} +@serializable +object bob extends Employee("Bob") + +object Test5 { + val x1 = new Person("Tim") + val x2 = bob + + try { + val y1: Person = Serialize.read(Serialize.write(x1)) + val y2: Employee = Serialize.read(Serialize.write(x2)) + + EqualityTest.check(x1, y1) + EqualityTest.check(x2, y2) + } + catch { + case e: Exception => + println("Error in Test5: " + e) + } +} + +//############################################################################ +// Test user-defined classes WITH nesting + +@serializable +object Test6 { + @serializable + object bill extends Employee("Bill") { + val x = paul + } + @serializable + object paul extends Person("Paul") { + val x = 4 // bill; => StackOverflowException !!! + } + val x1 = new Person("John") + val x2 = bill + val x3 = paul + + try { + val y1: Person = Serialize.read(Serialize.write(x1)) + val y2: Employee = Serialize.read(Serialize.write(x2)) + val y3: Person = Serialize.read(Serialize.write(x3)) + + EqualityTest.check(x1, y1) + EqualityTest.check(x2, y2) + EqualityTest.check(x3, y3) + } + catch { + case e: Exception => + println("Error in Test6: " + e) + } +} + +//############################################################################ +// Test code + +object Test { + def main(args: Array[String]) { + Test1_scala + Test2_immutable + Test3_mutable + Test4_xml + Test5 + Test6 + } +} + +//############################################################################ + diff --git a/test/pending/jvm/typerep.check b/test/pending/jvm/typerep.check new file mode 100644 index 0000000000..ff98348304 --- /dev/null +++ b/test/pending/jvm/typerep.check @@ -0,0 +1,47 @@ +Boolean +Boolean +true +Byte +Char +Int +Long +Float +Double +String +Unit + +Some[Int] +Some[Int] +Some[Some[Int]] +None +None + +List[Int] +List[Int] +List[List[Int]] +Nil +List[Any] + +Array[Int] +Array[Array[Int]] +Array[Int] +Array[Int] +Array[Int] +Array[Int] + +Tuple2[Int, String] +Tuple3[Char, Char, String] +Tuple2[Tuple2[Int, String], Tuple2[Int, String]] +Tuple2[Tuple2[Some[Char], Int], Tuple2[Some[Char], Int]] + +Function1[Int, Int] +Int +Function1[Int, Int] +Int +Function1[Int, Function1[Int, Int]] +Function1[Int, Int] +Int +Function3[Boolean, List[Char], Int, Int] +Function2[Function1[Int, Int], Int, Int] +Int + diff --git a/test/pending/jvm/typerep.scala b/test/pending/jvm/typerep.scala new file mode 100644 index 0000000000..b133d7ce99 --- /dev/null +++ b/test/pending/jvm/typerep.scala @@ -0,0 +1,374 @@ +//############################################################################ +// Type Representation at runtime +//############################################################################ +// $Id: $ + +import TypeRep._ + +object Test extends Application { + testPrimitives + testOptions + testLists + testArrays + testTuples + testFuncs + testClasses +} + +object serialize { + import java.io._ + + @throws(classOf[IOException]) + def write[A](o: A): Array[Byte] = { + val ba = new ByteArrayOutputStream(512) + val out = new ObjectOutputStream(ba) + out.writeObject(o) + out.close() + ba.toByteArray() + } + @throws(classOf[IOException]) + @throws(classOf[ClassNotFoundException]) + def read[A](buffer: Array[Byte]): A = { + val in = + new ObjectInputStream(new ByteArrayInputStream(buffer)) + in.readObject().asInstanceOf[A] + } +} + +object testPrimitives { + println(getType(true)) + val b = false; val bt = getType(b) + println(bt) + val bt1: TypeRep[Boolean] = serialize.read(serialize.write(bt)) + println(bt1 == bt) + println(getType(16.toByte)) + println(getType('a')) + println(getType(3)) + println(getType(3l)) + println(getType(0.0f)) + println(getType(0.0d)) + println(getType("abc")) + println(getType(())) // Unit +// println(getType(classOf[Int])) // Class + println +} + +object testOptions { + println(getType(Some(2))) + val x: Option[Int] = Some(2) + println(getType(x)) + println(getType(Some(Some(3)))) + println(getType(None)) + val y: Option[Int] = None + println(getType(y)) + println +} + +object testLists { + println(getType(List(3))) + println(getType(3 :: Nil)) + println(getType(List(List(3)))) + println(getType(Nil)) + println(getType(List(1, "abc"))) + println +} + +object testArrays { + println(getType(Array(3))) + println(getType(Array(Array(3), Array(4)))) + println(getType(new Array[Int](0))) + println(getType(List(1).toArray)) + println(getType(List[Int]().toArray)) + println(getType(Array(3).drop(1).toArray)) // empty + println +} + +object testTuples { + println(getType((3, "abc"))) + println(getType(Triple('a', 'b', "c"))) + println(getType(((3, "abc"), (4, "xyz")))) + println(getType(((Some('b'), 3), (Some('a'), 4)))) + //println(getType(((Some('b'), 3), (None, 4)))) + println +} + +object testFuncs { + def f1(x: Int): Int = 2 * x + println(getType(f1 _)) + println(getType(f1(2))) + val f2 = (x: Int) => 2 * x + println(getType(f2)) + println(getType(f2(2))) + val f3 = (x: Int) => (y: Int) => x + y + println(getType(f3)) + println(getType(f3(2))) + println(getType(f3(2)(2))) + def f4(b: Boolean, c: List[Char], i: Int): Int = i + println(getType(f4 _)) + def f5(f: Int => Int, x: Int) = f(x) + println(getType(f5 _)) + println(getType(f5(f1, 1))) + println +} + +class Foo { + class Bar(x: Int) +} + + +object foo extends Foo + +package pkg1 { + class C1 + object c1 extends C1 +} + +object testClasses { + /* + case object FooRep extends TypeRep[Foo] { + override def toString = "Foo" + } + implicit def fooRep[A](x: A)(implicit rep: TypeRep[foo.type]): TypeRep[foo.type] = rep + println(getType(foo)) + println(getType(new foo.Bar(0))) + val foo2 = new Foo + println(getType(foo2)) + println(getType(new foo2.Bar(1))) + println + + println(getType(pkg1.c1)) + val c1 = new pkg1.C1 + println(getType(c1)) + println + */ +} + + +/** + * @author Stephane Micheloud + * @version 1.0 + */ +abstract class TypeRep[A] + +object TypeRep { + + def getType[A](x: A)(implicit rep: TypeRep[A]): TypeRep[A] = rep + + def getType[A](x: Option[A])(implicit rep: TypeRep[A]): TypeRep[Option[A]] = (x match { + case Some(v) => SomeRep(rep) + case None => NoneRep // or NoneRep(rep) + }).asInstanceOf[TypeRep[Option[A]]] + + def getType[A](x: List[A])(implicit rep: TypeRep[A]): TypeRep[List[A]] = (x match { + case h :: t => ListRep(getType(h)) + case Nil => NilRep + }).asInstanceOf[TypeRep[List[A]]] + + implicit def boolRep: TypeRep[Boolean] = BooleanRep + implicit def byteRep: TypeRep[Byte] = ByteRep + implicit def charRep: TypeRep[Char] = CharRep + implicit def shortRep: TypeRep[Short] = ShortRep + implicit def intRep: TypeRep[Int] = IntRep + implicit def longRep: TypeRep[Long] = LongRep + implicit def floatRep: TypeRep[Float] = FloatRep + implicit def doubleRep: TypeRep[Double] = DoubleRep + + implicit def unitRep: TypeRep[Unit] = UnitRep +// implicit def classRep: TypeRep[Class] = ClassRep + implicit def stringRep: TypeRep[String] = StringRep + implicit def noneRep: TypeRep[Option[Nothing]] = NoneRep[Nothing](NothingRep.asInstanceOf[TypeRep[Nothing]]) + implicit def anyRep: TypeRep[Any] = AnyRep + implicit def nothingRep: TypeRep[Nothing] = NothingRep + + implicit def someRep[A](implicit elemrep: TypeRep[A]): TypeRep[Some[A]] = + SomeRep(elemrep) + + implicit def listRep[A](implicit elemrep: TypeRep[A]): TypeRep[List[A]] = + ListRep(elemrep) + + implicit def arrayRep[A](implicit elemrep: TypeRep[A]): TypeRep[Array[A]] = + ArrayRep(elemrep) + + implicit def tuple2Rep[A1, A2](implicit _1: TypeRep[A1], _2: TypeRep[A2]): TypeRep[Tuple2[A1, A2]] = + Tuple2Rep(_1, _2) + implicit def tuple3Rep[A1, A2, A3](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3]): TypeRep[Tuple3[A1, A2, A3]] = + Tuple3Rep(_1, _2, _3) + implicit def tuple4Rep[A1, A2, A3, A4](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4]): TypeRep[Tuple4[A1, A2, A3, A4]] = + Tuple4Rep(_1, _2, _3, _4) + implicit def tuple5Rep[A1, A2, A3, A4, A5](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5]): TypeRep[Tuple5[A1, A2, A3, A4, A5]] = + Tuple5Rep(_1, _2, _3, _4, _5) + implicit def tuple6Rep[A1, A2, A3, A4, A5, A6](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5], _6: TypeRep[A6]): TypeRep[Tuple6[A1, A2, A3, A4, A5, A6]] = + Tuple6Rep(_1, _2, _3, _4, _5, _6) + implicit def tuple7Rep[A1, A2, A3, A4, A5, A6, A7](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5], _6: TypeRep[A6], _7: TypeRep[A7]): TypeRep[Tuple7[A1, A2, A3, A4, A5, A6, A7]] = + Tuple7Rep(_1, _2, _3, _4, _5, _6, _7) + implicit def tuple8Rep[A1, A2, A3, A4, A5, A6, A7, A8](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5], _6: TypeRep[A6], _7: TypeRep[A7], _8: TypeRep[A8]): TypeRep[Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] = + Tuple8Rep(_1, _2, _3, _4, _5, _6, _7, _8) + implicit def tuple9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9](implicit _1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5], _6: TypeRep[A6], _7: TypeRep[A7], _8: TypeRep[A8], _9: TypeRep[A9]): TypeRep[Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] = + Tuple9Rep(_1, _2, _3, _4, _5, _6, _7, _8, _9) + + implicit def func1Rep[A1, B](implicit a1: TypeRep[A1], b: TypeRep[B]): TypeRep[Function1[A1, B]] = + Function1Rep(a1, b) + implicit def func2Rep[A1, A2, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], b: TypeRep[B]): TypeRep[Function2[A1, A2, B]] = + Function2Rep(a1, a2, b) + implicit def func3Rep[A1, A2, A3, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], b: TypeRep[B]): TypeRep[Function3[A1, A2, A3, B]] = + Function3Rep(a1, a2, a3, b) + implicit def func4Rep[A1, A2, A3, A4, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], b: TypeRep[B]): TypeRep[Function4[A1, A2, A3, A4, B]] = + Function4Rep(a1, a2, a3, a4, b) + implicit def func5Rep[A1, A2, A3, A4, A5, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], b: TypeRep[B]): TypeRep[Function5[A1, A2, A3, A4, A5, B]] = + Function5Rep(a1, a2, a3, a4, a5, b) + implicit def func6Rep[A1, A2, A3, A4, A5, A6, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], b: TypeRep[B]): TypeRep[Function6[A1, A2, A3, A4, A5, A6, B]] = + Function6Rep(a1, a2, a3, a4, a5, a6, b) + implicit def func7Rep[A1, A2, A3, A4, A5, A6, A7, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], b: TypeRep[B]): TypeRep[Function7[A1, A2, A3, A4, A5, A6, A7, B]] = + Function7Rep(a1, a2, a3, a4, a5, a6, a7, b) + implicit def func8Rep[A1, A2, A3, A4, A5, A6, A7, A8, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], b: TypeRep[B]): TypeRep[Function8[A1, A2, A3, A4, A5, A6, A7, A8, B]] = + Function8Rep(a1, a2, a3, a4, a5, a6, a7, a8, b) + implicit def func9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9, B](implicit a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], a9: TypeRep[A9], b: TypeRep[B]): TypeRep[Function9[A1, A2, A3, A4, A5, A6, A7, A8, A9, B]] = + Function9Rep(a1, a2, a3, a4, a5, a6, a7, a8, a9, b) +/* + implicit def objectRep[A <: AnyRef](obj: A)(implicit rep: TypeRep[A]): TypeRep[AnyClass] = + ObjectRep(obj.getClass) +*/ + + case object BooleanRep extends TypeRep[Boolean] { + override def toString = "Boolean" + } + case object ByteRep extends TypeRep[Byte] { + override def toString = "Byte" + } + case object CharRep extends TypeRep[Char] { + override def toString = "Char" + } + case object ShortRep extends TypeRep[Short] { + override def toString = "Short" + } + case object IntRep extends TypeRep[Int] { + override def toString = "Int" + } + case object LongRep extends TypeRep[Long] { + override def toString = "Long" + } + case object FloatRep extends TypeRep[Float] { + override def toString = "Float" + } + case object DoubleRep extends TypeRep[Double] { + override def toString = "Double" + } + + case object UnitRep extends TypeRep[Unit] { + override def toString = "Unit" + } +// case object ClassRep extends TypeRep[AnyClass] { +// override def toString = "Class" +// } + case object StringRep extends TypeRep[String] { + override def toString = "String" + } + case object NoneRep extends TypeRep[Option[Nothing]] { + override def toString = "None" + } + case object NilRep extends TypeRep[Nil.type] { + override def toString = "Nil" + } + case object AnyRep extends TypeRep[Any] { + override def toString = "Any" + } + case object NothingRep extends TypeRep[Nothing] { + override def toString = "Nothing" + } + + @serializable + case class SomeRep[A](elemRep: TypeRep[A]) extends TypeRep[Some[A]] { + override def toString = "Some[" + elemRep + "]" + } + @serializable + case class NoneRep[A](elemRep: TypeRep[A]) extends TypeRep[Option[A]] { + override def toString = "None[" + elemRep + "]" + } + + @serializable + case class ListRep[A](elemRep: TypeRep[A]) extends TypeRep[List[A]] { + override def toString = "List[" + elemRep + "]" + } + + @serializable + case class ArrayRep[A](elemRep: TypeRep[A]) extends TypeRep[Array[A]] { + override def toString = "Array[" + elemRep + "]" + } + + @serializable + case class Tuple2Rep[A1, A2](_1: TypeRep[A1], _2: TypeRep[A2]) extends TypeRep[Tuple2[A1, A2]] { + override def toString = "Tuple2[" + _1 + ", " + _2 + "]" + } + @serializable + case class Tuple3Rep[A1, A2, A3](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3]) extends TypeRep[Tuple3[A1, A2, A3]] { + override def toString = "Tuple3[" + _1 + ", " + _2 + ", " + _3 + "]" + } + @serializable + case class Tuple4Rep[A1, A2, A3, A4](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4]) extends TypeRep[Tuple4[A1, A2, A3, A4]] { + override def toString = "Tuple4[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + "]" + } + @serializable + case class Tuple5Rep[A1, A2, A3, A4, A5](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5]) extends TypeRep[Tuple5[A1, A2, A3, A4, A5]] { + override def toString = "Tuple5[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + "]" + } + @serializable + case class Tuple6Rep[A1, A2, A3, A4, A5, A6](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6]) extends TypeRep[Tuple6[A1, A2, A3, A4, A5, A6]] { + override def toString = "Tuple6[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + "]" + } + @serializable + case class Tuple7Rep[A1, A2, A3, A4, A5, A6, A7](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7]) extends TypeRep[Tuple7[A1, A2, A3, A4, A5, A6, A7]] { + override def toString = "Tuple7[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + "]" + } + @serializable + case class Tuple8Rep[A1, A2, A3, A4, A5, A6, A7, A8](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7], val _8: TypeRep[A8]) extends TypeRep[Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] { + override def toString = "Tuple8[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + "]" + } + @serializable + case class Tuple9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7], val _8: TypeRep[A8], val _9: TypeRep[A9]) extends TypeRep[Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] { + override def toString = "Tuple9[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + "]" + } + + @serializable + case class Function1Rep[A1, B](a1: TypeRep[A1], b: TypeRep[B]) extends TypeRep[Function1[A1, B]] { + override def toString = "Function1[" + a1 + ", " + b + "]" + } + @serializable + case class Function2Rep[A1, A2, B](a1: TypeRep[A1], a2: TypeRep[A2], b: TypeRep[B]) extends TypeRep[Function2[A1, A2, B]] { + override def toString = "Function2[" + a1 + ", " + a2 + ", " + b + "]" + } + @serializable + case class Function3Rep[A1, A2, A3, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], b: TypeRep[B]) extends TypeRep[Function3[A1, A2, A3, B]] { + override def toString = "Function3[" + a1 + ", " + a2 + ", " + a3 + ", " + b + "]" + } + @serializable + case class Function4Rep[A1, A2, A3, A4, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], b: TypeRep[B]) extends TypeRep[Function4[A1, A2, A3, A4, B]] { + override def toString = "Function4[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + b + "]" + } + @serializable + case class Function5Rep[A1, A2, A3, A4, A5, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], b: TypeRep[B]) extends TypeRep[Function5[A1, A2, A3, A4, A5, B]] { + override def toString = "Function5[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + b + "]" + } + @serializable + case class Function6Rep[A1, A2, A3, A4, A5, A6, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], b: TypeRep[B]) extends TypeRep[Function6[A1, A2, A3, A4, A5, A6, B]] { + override def toString = "Function6[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + b + "]" + } + @serializable + case class Function7Rep[A1, A2, A3, A4, A5, A6, A7, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], b: TypeRep[B]) extends TypeRep[Function7[A1, A2, A3, A4, A5, A6, A7, B]] { + override def toString = "Function7[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + b + "]" + } + @serializable + case class Function8Rep[A1, A2, A3, A4, A5, A6, A7, A8, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], b: TypeRep[B]) extends TypeRep[Function8[A1, A2, A3, A4, A5, A6, A7, A8, B]] { + override def toString = "Function8[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + a8 + b + "]" + } + @serializable + case class Function9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], a9: TypeRep[A9], b: TypeRep[B]) extends TypeRep[Function9[A1, A2, A3, A4, A5, A6, A7, A8, A9, B]] { + override def toString = "Function9[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + a8 + ", " + b + "]" + } +/* + @serializable + case class ObjectRep[A](c: Class) extends TypeRep[A] { + override def toString = c.getName + } +*/ +} + diff --git a/test/pending/jvm5/annotations.scala b/test/pending/jvm5/annotations.scala new file mode 100644 index 0000000000..98b82edad4 --- /dev/null +++ b/test/pending/jvm5/annotations.scala @@ -0,0 +1,159 @@ +object Test1 { + class Foo { + @remote + def foo: Unit = () + } + def run { + val method = classOf[Foo].getMethod("foo", Array()) + method.getExceptionTypes foreach println + } +} + +object Test2 { + import java.io.{BufferedReader,FileReader, IOException} + class Reader(fname: String) { + private val in = new BufferedReader(new FileReader(fname)) + + @throws(classOf[IOException]) + def read() = in.read() + } + def run { + val method = classOf[Reader].getMethod("read", Array()) + method.getExceptionTypes foreach println + } +} + +/* Java: +public class Main { + @Deprecated + public void foo() {} + public static void main(String[] args) throws Exception { + Method method = Class.forName("test.Main").getMethod("foo", new Class[]{}); + Annotation annotation = method.getAnnotation(Deprecated.class); + System.out.println(annotation); // @java.lang.Deprecated() + } +} +*/ +object Test3 { + import java.lang.Deprecated + class Foo { + @Deprecated + def foo: Unit = () + } + def run { + val method = classOf[Foo].getMethod("foo", Array()) + val annotation = method.getAnnotation(classOf[Deprecated]) + println(annotation) + } +} + +/* Java: +@Retention(value=RetentionPolicy.RUNTIME) +@interface Source { + public String url(); + public String mail(); +} +@Source(url="http://scala.epfl.ch", mail="scala@lists.epfl.ch") +class Foo {} +public class Main { + public static void main(String[] args) throws Exception { + Class clazz = Class.forName("test.Foo"); + Annotation[] annotations = clazz.getAnnotations(); + for (int i = 0; i < annotations.length; i++) + System.out.println(annotations[i]); + // @test.Main$Source(url=http://scala-lang.org, mail=scala@lists.epfl.ch) + } +} +*/ +object Test4 { + import test.SourceAnnotation // defined in SourceAnnotation.java + @SourceAnnotation{val value = "http://scala-lang.org", + val mails = Array("scala@lists.epfl.ch", "scala-lounge@lists.epfl.ch")} + class Foo1 + @SourceAnnotation("http://bloodsuckers.com") { val mails = Array("you@bloodsuckers.com") } + class Foo2 + @SourceAnnotation("http://bloodsuckers.com") + class Foo3 + class Foo4 { + @SourceAnnotation("file:///dev/null") + val x = 1 + } + class Foo5 { + @SourceAnnotation("file:///dev/zero") + def bar: Int = 0 + } + class Foo6 @SourceAnnotation("primary constructor")(s: String) { + // to guarantee that primary constructor annotations + // are not applied to secondary constructors + def this() = this("") + } + class Foo7(s: String) { + @SourceAnnotation("secondary constructor") + def this() = this("") + } + class Foo8(@SourceAnnotation("constructor val") val n: Int) {} + def run { + import java.lang.annotation.Annotation + import java.lang.reflect.AnnotatedElement + def printSourceAnnotations(target: AnnotatedElement) { + //print SourceAnnotation in a predefined way to insure + // against difference in the JVMs (e.g. Sun's vs IBM's) + def printSourceAnnotation(a: Annotation) { + val ann = a.asInstanceOf[SourceAnnotation] + println("@test.SourceAnnotation(mails=" + ann.mails.deepMkString("{", ",", "}") + + ", value=" + ann.value + ")") + } + val anns = target.getAnnotations() + anns foreach printSourceAnnotation + if (anns.length > 0) { + println(target) + println + } + } + printSourceAnnotations(classOf[Foo1]) + printSourceAnnotations(classOf[Foo2]) + printSourceAnnotations(classOf[Foo3]) + classOf[Foo4].getDeclaredFields foreach printSourceAnnotations + classOf[Foo4].getDeclaredMethods foreach printSourceAnnotations + classOf[Foo5].getDeclaredMethods foreach printSourceAnnotations + classOf[Foo6].getDeclaredConstructors foreach printSourceAnnotations + classOf[Foo7].getDeclaredConstructors foreach printSourceAnnotations + classOf[Foo8].getDeclaredFields foreach printSourceAnnotations + classOf[Foo8].getDeclaredMethods foreach printSourceAnnotations + } +} + +object Test5 { + import scala.reflect.BeanProperty + import java.lang.Integer + + class Count { + // we use "Integer" instead of "Int" because of Java reflection + @BeanProperty + private var count: Integer = 0 + + private val getter = + getClass().getMethod("getCount", Array[java.lang.Class[T] forSome { type T }]()) + private val setter = + getClass().getMethod("setCount", Array(classOf[Integer])) + + def get = getter.invoke(this, Array()).asInstanceOf[Integer].intValue + def set(n: Int) = setter.invoke(this, Array(new Integer(n))) + } + def run { + val count = new Count + println(count.get) + count.set(99) + println(count.get) + } +} + +object Test { + def main(args: Array[String]) { + Test1.run + Test2.run + Test3.run // requires the use of -target:jvm-1.5 + Test4.run + Test5.run + } +} diff --git a/test/pending/run/classof.check b/test/pending/run/classof.check new file mode 100644 index 0000000000..e9a8fd6b76 --- /dev/null +++ b/test/pending/run/classof.check @@ -0,0 +1 @@ +SomeClass diff --git a/test/pending/run/classof.scala b/test/pending/run/classof.scala new file mode 100644 index 0000000000..b547e5c8c3 --- /dev/null +++ b/test/pending/run/classof.scala @@ -0,0 +1,8 @@ +class SomeClass + +object Test { + def main(args: Array[String]): Unit = { + val cls: Class[SomeClass] = classOf[SomeClass] + Console.println(cls.getName()) + } +} -- cgit v1.2.3