-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathcheckOverride.kt
206 lines (172 loc) · 4.96 KB
/
checkOverride.kt
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* Copyright 2020 Google LLC
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TEST PROCESSOR: CheckOverrideProcessor
// EXPECTED:
// KotlinList.get overrides JavaList.get: false
// KotlinList.foo overrides JavaList.foo: true
// KotlinList.fooo overrides JavaList.foo: false
// KotlinList.foo overrides KotlinList.foo: false
// KotlinList.equals overrides JavaList.equals: true
// KotlinList2.baz overrides KotlinList.baz: true
// KotlinList2.baz overrides KotlinList.bazz: false
// KotlinList2.bazz overrides KotlinList.bazz: true
// KotlinList2.bazz overrides KotlinList.baz: false
// KotlinList2.baz overrides KotlinList2.baz: false
// JavaImpl.getY overrides JavaImpl.getX: false
// JavaImpl.getY overrides MyInterface.x: false
// JavaImpl.getX overrides MyInterface.x: true
// JavaImpl.setY overrides MyInterface.y: true
// JavaImpl.setX overrides MyInterface.x: false
// JavaImpl.getY overrides JavaImpl.getY: false
// MyInterface.x overrides JavaImpl.getY: false
// MyInterface.x overrides JavaImpl.getX: false
// MyInterface.y overrides JavaImpl.setY: false
// MyInterface.y overrides MyInterface.y: false
// MyInterface2.receiveList overrides MyInterface2ImplWithoutType.receiveList: false
// MyInterface2ImplWithoutType.receiveList overrides MyInterface2.receiveList: true
// MyInterface2ImplWithType.receiveList overrides MyInterface2.receiveList: true
// MyInterface2ImplWithType.receiveList overrides MyInterface2ImplWithoutType.receiveList: true
// JavaDifferentReturnType.foo overrides JavaList.foo: true
// Base.f1 overrides MyInterface3.f1: true
// Base.prop overrides MyInterface3.prop: true
// JBase.getProp overrides MyInterface3.prop: true
// pkg1.WithPackagePrivate.packagePrivateFun overrides pkg2.WithPackagePrivateBase.packagePrivateFun: false
// END
// FILE: a.kt
annotation class GetAnno
annotation class FooAnno
annotation class BarAnno
annotation class BazAnno
annotation class Baz2Anno
annotation class BazzAnno
annotation class Bazz2Anno
open class KotlinList(): JavaList() {
@GetAnno
fun get(): Double {
return 2.0
}
override fun equals(other: Any?): Boolean {
return false
}
@FooAnno
override fun foo(): Int {
return 2
}
@BarAnno
override fun fooo(): Int {
return 2
}
@Baz2Anno
open val baz: Int get() {
return 1
}
@Bazz2Anno
open val bazz: Int get() {
return 1
}
}
class KotlinList2(@BazzAnno override val bazz: Int = 2): KotlinList() {
@BazAnno
override val baz: Int get() {
return 2
}
}
interface MyInterface {
val x: Int
var y: Int
}
enum class EnumType {
FOO,
BAR;
}
interface MyInterface2<T> {
fun receiveList(argsInParent : List<T>):Unit
}
interface MyInterface2ImplWithoutType<T> : MyInterface2<T> {
override fun receiveList(argsInParent : List<T>):Unit
}
interface MyInterface2ImplWithType : MyInterface2ImplWithoutType<EnumType> {
override fun receiveList(argsInParent : List<EnumType>):Unit
}
interface MyInterface3 {
fun f1()
val prop: String
}
open class Base {
val prop: String = ""
fun f1() {
}
}
class BaseOverride: MyInterface3, Base() {
fun f2() {}
}
// FILE: JBaseOverride.java
public class JBaseOverride extends JBase implements MyInterface3 {
}
// FILE: JBase.java
public class JBase {
public String getProp() {
return "JBase";
}
}
// FILE: JavaList.java
import java.util.*;
public class JavaList extends List<String> {
@Override
public String get(int index) {
return "OK";
}
protected int foo() {
return 1;
}
}
// FILE: JavaImpl.java
public class JavaImpl implements MyInterface {
public int getX() {
return 1;
}
public int getY() {
return 1;
}
public void setY(int value) {
}
// intentional override check for a val property
public void setX(int value) {
return value;
}
}
// FILE: JavaDifferentReturnType.java
public abstract class JavaDifferentReturnType extends JavaList {
// intentional different return type
protected String foo() {
return "";
}
}
// FILE: WithPackagePrivate.java
package pkg1;
public class WithPackagePrivate extends pkg2.WithPackagePrivateBase {
int packagePrivateFun() {
return 1;
}
}
// FILE: WithPackagePrivateBase.java
package pkg2;
public class WithPackagePrivateBase {
int packagePrivateFun() {
return 0;
}
}