From 1e00b1bd3b624efd8eac511d642d289715404bb6 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Fri, 1 Feb 2008 13:35:13 +0000 Subject: Fixed #377. --- test/files/jvm/throws-annot.check | 21 +++++++++++ test/files/jvm/throws-annot.scala | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 test/files/jvm/throws-annot.check create mode 100644 test/files/jvm/throws-annot.scala (limited to 'test/files') diff --git a/test/files/jvm/throws-annot.check b/test/files/jvm/throws-annot.check new file mode 100644 index 0000000000..a0ed82b106 --- /dev/null +++ b/test/files/jvm/throws-annot.check @@ -0,0 +1,21 @@ +read throws: class java.io.IOException +read annotations: +readWith2 throws: class java.lang.ClassCastException, class java.io.IOException +readWith2 annotations: +readMixed throws: class java.io.IOException, class java.lang.NullPointerException +readMixed annotations: @java.lang.Deprecated() +readMixed2 throws: class java.io.IOException, class java.lang.NullPointerException +readMixed2 annotations: @java.lang.Deprecated() +readNoEx throws: +readNoEx annotations: @java.lang.Deprecated() +Testing mirror class +read throws: class java.io.IOException +read annotations: +readWith2 throws: class java.lang.ClassCastException, class java.io.IOException +readWith2 annotations: +readMixed throws: class java.io.IOException, class java.lang.NullPointerException +readMixed annotations: @java.lang.Deprecated() +readMixed2 throws: class java.io.IOException, class java.lang.NullPointerException +readMixed2 annotations: @java.lang.Deprecated() +readNoEx throws: +readNoEx annotations: @java.lang.Deprecated() diff --git a/test/files/jvm/throws-annot.scala b/test/files/jvm/throws-annot.scala new file mode 100644 index 0000000000..5f4dac07e8 --- /dev/null +++ b/test/files/jvm/throws-annot.scala @@ -0,0 +1,74 @@ +/** Test the @throws annotation */ +import java.io.IOException + +object TestThrows { + + abstract class Foo { + + @throws(classOf[IOException]) + def read(): Int + + @throws(classOf[ClassCastException]) + @throws(classOf[IOException]) + def readWith2(): Int + + @throws(classOf[IOException]) + @Deprecated + @throws(classOf[NullPointerException]) + def readMixed(): Int + + @Deprecated + @throws(classOf[IOException]) + @throws(classOf[NullPointerException]) + def readMixed2(): Int + + @Deprecated + def readNoEx(): Int + } + + def checkMethod(cls: Class[_], name: String) { + val method = cls.getMethod(name, Array()) + println(name + " throws: " + method.getExceptionTypes.mkString("", ", ", "")) + println(name + " annotations: " + method.getDeclaredAnnotations.mkString("", ", ", "")) + } + + def run(cls: Class[_]) { + checkMethod(cls, "read") + checkMethod(cls, "readWith2") + checkMethod(cls, "readMixed") + checkMethod(cls, "readMixed2") + checkMethod(cls, "readNoEx") + } +} + +/** Test the top-level mirror that is has the annotations. */ +object TL { + + @throws(classOf[IOException]) + def read(): Int = 0 + + @throws(classOf[ClassCastException]) + @throws(classOf[IOException]) + def readWith2(): Int = 0 + + @throws(classOf[IOException]) + @Deprecated + @throws(classOf[NullPointerException]) + def readMixed(): Int = 0 + + @Deprecated + @throws(classOf[IOException]) + @throws(classOf[NullPointerException]) + def readMixed2(): Int = 0 + + @Deprecated + def readNoEx(): Int = 0 +} + +object Test { + def main(args: Array[String]) { + TestThrows.run(classOf[TestThrows.Foo]) + println("Testing mirror class") + TestThrows.run(Class.forName("TL")) + } +} -- cgit v1.2.3