From 1b887be0a16c53e6e01b523abf5b963672b82861 Mon Sep 17 00:00:00 2001 From: mihaylov Date: Sun, 24 Jun 2007 19:53:39 +0000 Subject: Added annotations tests for fields and methods --- test/files/jvm5/annotations.check | 15 +++++++++++++++ test/files/jvm5/annotations.scala | 34 +++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) (limited to 'test/files/jvm5') diff --git a/test/files/jvm5/annotations.check b/test/files/jvm5/annotations.check index 9219c7bdb5..449d3d9ab8 100644 --- a/test/files/jvm5/annotations.check +++ b/test/files/jvm5/annotations.check @@ -2,7 +2,22 @@ class java.rmi.RemoteException class java.io.IOException @java.lang.Deprecated() @test.SourceAnnotation(mails={scala@lists.epfl.ch,scala-lounge@lists.epfl.ch}, value=http://scala-lang.org) +class Test4$Foo1 + @test.SourceAnnotation(mails={you@bloodsuckers.com}, value=http://bloodsuckers.com) +class Test4$Foo2 + @test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://bloodsuckers.com) +class Test4$Foo3 + +@test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=file:///dev/null) +private int Test4$Foo4.x + +@test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=file:///dev/null) +public int Test4$Foo4.x() + +@test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=file:///dev/zero) +public int Test4$Foo4.bar() + 0 99 diff --git a/test/files/jvm5/annotations.scala b/test/files/jvm5/annotations.scala index 121cb152b8..c850796e59 100644 --- a/test/files/jvm5/annotations.scala +++ b/test/files/jvm5/annotations.scala @@ -74,15 +74,35 @@ object Test4 { class Foo2 @SourceAnnotation("http://bloodsuckers.com") class Foo3 + class Foo4 { + @SourceAnnotation("file:///dev/null") + val x = 1 + @SourceAnnotation("file:///dev/zero") + def bar: Int = 0 + } def run { - def printSourceAnnotation(a: Any) { - val ann = a.asInstanceOf[SourceAnnotation] - Console.println("@test.SourceAnnotation(mails=" + ann.mails.deepMkString("{", ",", "}") + - ", value=" + ann.value + ")") + 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] + Console.println("@test.SourceAnnotation(mails=" + ann.mails.deepMkString("{", ",", "}") + + ", value=" + ann.value + ")") + } + val anns = target.getAnnotations() + anns foreach printSourceAnnotation + if (anns.length > 0) { + Console.println(target) + Console.println + } } - classOf[Foo1].getAnnotations foreach printSourceAnnotation - classOf[Foo2].getAnnotations foreach printSourceAnnotation - classOf[Foo3].getAnnotations foreach printSourceAnnotation + printSourceAnnotations(classOf[Foo1]) + printSourceAnnotations(classOf[Foo2]) + printSourceAnnotations(classOf[Foo3]) + classOf[Foo4].getDeclaredFields foreach printSourceAnnotations + classOf[Foo4].getDeclaredMethods foreach printSourceAnnotations } } -- cgit v1.2.3