summaryrefslogtreecommitdiff
path: root/test/files/jvm/throws-annot.scala
blob: 90b58b99767c7c0e0f4c9fd2a7b10ec45a0fbf2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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)
    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"))
  }
}