Debian Codegraph @

samples/selfType/selftype/SelfType.java

raw
1 /*
2 * Copyright 2020 The JSpecify Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package selftype;
17
18 import org.jspecify.annotations.NullMarked;
19 import org.jspecify.annotations.Nullable;
20
21 @NullMarked
22 public class SelfType<T extends SelfType<T>> {
23 public void foo(T t) {}
24 }
25
26 // jspecify_nullness_not_enough_information
27 class B extends SelfType<B> {}
28
29 @NullMarked
30 class C<E extends C<E>> extends SelfType<E> {}
31
32 // jspecify_nullness_not_enough_information
33 class AK extends SelfType<AK> {}
34
35 // test:cannot-convert:AK? to SelfType!<AK!>
36 class AKN extends SelfType<@Nullable AK> {}
37
38 class BK extends B {}
39
40 // jspecify_nullness_not_enough_information
41 class CK extends C<CK> {}
42
43 @NullMarked
44 // test:cannot-convert:CK? to C!<CK!>
45 abstract class Super extends C<@Nullable CK> {
46 abstract AK ak();
47
48 abstract AKN akn();
49
50 abstract BK bk();
51
52 abstract CK ck();
53
54 abstract CKN ckn();
55 }
56
57 abstract class CKN extends Super {
58 public void main() {
59 ak().foo(ak());
60 // test:cannot-convert:null? to AK!
61 ak().foo(null);
62
63 // test:cannot-convert:null? to AK!
64 akn().foo(null);
65
66 bk().foo(bk());
67 // test:cannot-convert:null? to B!
68 bk().foo(null);
69
70 ck().foo(ck());
71 // test:cannot-convert:null? to CK!
72 ck().foo(null);
73
74 // test:cannot-convert:null? to CK!
75 ckn().foo(null);
76 }
77 }