xref: /aosp_15_r20/external/ksp/test-utils/testData/api/throwList.kt (revision af87fb4bb8e3042070d2a054e912924f599b22b7)
1 /*
2  * Copyright 2021 Google LLC
3  * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 
19 // TEST PROCESSOR: ThrowListProcessor
20 // EXPECTED:
21 // java.io.IOException,java.util.NoSuchElementException
22 // java.io.IOException,java.lang.IndexOutOfBoundsException
23 // java.io.IOException,java.util.NoSuchElementException
24 // java.lang.IndexOutOfBoundsException
25 // java.io.IOException
26 // java.io.IOException,java.lang.IndexOutOfBoundsException
27 // java.lang.IndexOutOfBoundsException
28 // java.lang.IllegalArgumentException
29 // java.lang.IllegalStateException
30 // java.io.IOException
31 // java.lang.IllegalStateException,java.lang.IllegalArgumentException
32 // java.io.IOException
33 // java.lang.IndexOutOfBoundsException
34 // java.io.IOException,java.lang.IndexOutOfBoundsException
35 // java.io.IOException
36 // END
37 // MODULE: lib
38 // FILE: JavaLib.java
39 import java.io.IOException;
40 import java.lang.IndexOutOfBoundsException;
41 public class JavaLib {
42     public JavaLib() throws IOException {
43 
44     }
45 
46     public void foo() throws IOException {
47         throw new IOException();
48     }
49     public void foo(int i) throws IndexOutOfBoundsException {
50         throw new IndexOutOfBoundsException();
51     }
52     public void foo(String[] s) throws IOException, IndexOutOfBoundsException {
53         throw new IOException();
54     }
55 }
56 // FILE: KtLib.kt
57 import java.io.IOException
58 import java.lang.IllegalArgumentException
59 import java.lang.IllegalStateException
60 
61 class KtLib {
62     @Throws(java.io.IOException::class)
throwsLibKtnull63     fun throwsLibKt() {
64         throw java.io.IOException()
65     }
66     @Throws(java.lang.IndexOutOfBoundsException::class)
throwsLibKtnull67     fun throwsLibKt(i: Int) {
68         throw java.lang.IndexOutOfBoundsException()
69     }
70     @Throws(java.io.IOException::class, java.lang.IndexOutOfBoundsException::class)
throwsLibKtnull71     fun throwsLibKt(s: Array<String>) {
72         throw java.io.IOException()
73     }
74 
75     @get:Throws(IllegalArgumentException::class)
76     val getterThrows: Int = 3
77     @set:Throws(IllegalStateException::class)
78     var setterThrows: Int = 3
79     @get:Throws(IOException::class)
80     @set:Throws(IllegalStateException::class, IllegalArgumentException::class)
81     var bothThrows: Int = 3
82 }
83 // MODULE: main(lib)
84 // FILE: ThrowsException.java
85 import java.io.IOException;
86 import java.lang.IndexOutOfBoundsException;
87 
88 public class ThrowsException {
89     public int foo() throws IOException, IndexOutOfBoundsException{
90         return 1;
91     }
92 }
93 // FILE: a.kt
94 class ThrowsKt {
95     @Throws(java.io.IOException::class, java.util.NoSuchElementException::class)
throwsKTnull96     fun throwsKT()
97 
98     @set:Throws(java.lang.IndexOutOfBoundsException::class)
99     var a: Int
100     @Throws(java.io.IOException::class, java.util.NoSuchElementException::class)
101     get() {
102         return 1
103     }
104     set(a: Int) {
105 
106     }
107 }
108