xref: /aosp_15_r20/external/ksp/test-utils/testData/api/visibilities.kt (revision af87fb4bb8e3042070d2a054e912924f599b22b7)
1 /*
2  * Copyright 2020 Google LLC
3  * Copyright 2010-2020 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 // TEST PROCESSOR: VisibilityProcessor
19 // EXPECTED:
20 // publicFun: PUBLIC,visible in A, B, D: true, true, true
21 // packageFun: JAVA_PACKAGE,visible in A, B, D: true, false, true
22 // privateFun: PRIVATE,visible in A, B, D: false, false, false
23 // protectedFun: PROTECTED,visible in A, B, D: true, false, true
24 // <init>: PUBLIC,visible in A, B, D: true, true, true
25 // javaPackageField: JAVA_PACKAGE,visible in A, B, D: true, false, true
26 // x: INTERNAL,visible in A, B, D: false, false, false
27 // y: PROTECTED,visible in A, B, D: true, false, true
28 // y: PUBLIC,visible in A, B, D: true, true, true
29 // LibEnumJava: valueOf: PUBLIC
30 // LibEnumJava: values: PUBLIC
31 // LibEnumJava: <init>: PRIVATE
32 // LibEnum: valueOf: PUBLIC
33 // LibEnum: values: PUBLIC
34 // LibEnum: <init>: PRIVATE
35 // Enum: <init>: PRIVATE
36 // Enum: values: PUBLIC
37 // Enum: valueOf: PUBLIC
38 // KtEnum: <init>: PRIVATE
39 // KtEnumWithVal: <init>: PRIVATE
40 // END
41 
42 // MODULE: lib
43 // FILE: JavaClass.java
44 public class JavaClass {
45     int javaPackageField;
46 }
47 
48 // FILE: LibEnumJava.java
49 public enum LibEnumJava {
50     R(0),G(1),B(2);
51     private final int v;
52     LibEnumJava(int v) {
53         this.v = v;
54     }
55 }
56 
57 // FILE: lib.kt
58 open class KotlinClass {
59     open internal val x: Int = 0
60     open protected val y: Int = 0
61 }
62 
63 enum class LibEnum(val value: Int) {
64     A(0), B(1), C(2);
65 }
66 
67 // MODULE: main(lib)
68 // FILE: a.kt
69 annotation class TestA
70 annotation class TestB
71 annotation class TestD
72 
73 @TestA
74 class A : C() {
75 }
76 
77 @TestD
78 class D {}
79 
80 class KotlinSubClass : KotlinClass() {
81     public override val y = 1
82 }
83 
84 enum class KtEnum {
85     A,B,C
86 }
87 
88 enum class KtEnumWithVal(val a: Int) {
89     A(0), B(1), C(2)
90 }
91 
92 // FILE: C.java
93 class C {
<lambda>null94     public int publicFun() {
95         return 1;
96     }
97 
98     int packageFun() {
99         return 1;
100     }
101 
<lambda>null102     private int privateFun() {
103         return 1;
104     }
105 
<lambda>null106     protected int protectedFun() {
107         return 1;
108     }
109 }
110 
111 // FILE: Enum.java
112 public enum Enum {
113     Y,U,V;
114     private final int v;
115     Enum(int v) {
116         this.v = v;
117     }
118 }
119 // FILE: b.kt
120 package somePackage
121 
122 import TestB
123 
124 @TestB
125 class B
126