From 12a3b4c5ffe61ad646c33c59a666386e11429316 Mon Sep 17 00:00:00 2001 From: michelou Date: Fri, 2 Mar 2007 13:35:59 +0000 Subject: added test for @BeanProperty annotation --- test/files/jvm5/annotations.check | 2 ++ test/files/jvm5/annotations.scala | 32 ++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/files/jvm5/annotations.check b/test/files/jvm5/annotations.check index 06d35ddb48..efdd54a237 100644 --- a/test/files/jvm5/annotations.check +++ b/test/files/jvm5/annotations.check @@ -4,3 +4,5 @@ class java.io.IOException @test.SourceAnnotation(mail=scala@lists.epfl.ch, value=http://scala.epfl.ch) @test.SourceAnnotation(mail=you@bloodsuckers.com, value=http://bloodsuckers.com) @test.SourceAnnotation(mail=bill.gates@bloodsuckers.com, value=http://bloodsuckers.com) +0 +99 diff --git a/test/files/jvm5/annotations.scala b/test/files/jvm5/annotations.scala index fa5ab1476b..e81aa863a8 100644 --- a/test/files/jvm5/annotations.scala +++ b/test/files/jvm5/annotations.scala @@ -5,7 +5,7 @@ object Test1 { @remote def foo: Unit = () } - def run: Unit = { + def run { val method = classOf[Foo].getMethod("foo", Array()) method.getExceptionTypes foreach Console.println } @@ -19,7 +19,7 @@ object Test2 { @throws(classOf[IOException]) def read() = in.read() } - def run: Unit = { + def run { val method = classOf[Reader].getMethod("read", Array()) method.getExceptionTypes foreach Console.println } @@ -41,7 +41,7 @@ object Test3 { @Deprecated def foo: Unit = () } - def run: Unit = { + def run { val method = classOf[Foo].getMethod("foo", Array()) val annotation = method.getAnnotation(classOf[Deprecated]) Console.println(annotation) @@ -74,18 +74,42 @@ object Test4 { class Foo2 @SourceAnnotation("http://bloodsuckers.com") class Foo3 - def run: Unit = { + def run { classOf[Foo1].getAnnotations foreach Console.println classOf[Foo2].getAnnotations foreach Console.println classOf[Foo3].getAnnotations foreach Console.println } } +object Test5 { + import scala.reflect.BeanProperty + 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]()) + private val setter = + getClass().getMethod("setCount", Array[java.lang.Class](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 + Console.println(count.get) + count.set(99) + Console.println(count.get) + } +} + object Test { def main(args: Array[String]): Unit = { Test1.run Test2.run Test3.run // requires the use of -target:jvm-1.5 Test4.run + Test5.run } } -- cgit v1.2.3