Debian Codegraph @

samples/SuperTypeVariableUnionNull.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 import org.jspecify.annotations.NullMarked;
17 import org.jspecify.annotations.Nullable;
18 import org.jspecify.annotations.NullnessUnspecified;
19
20 @NullMarked
21 class SuperTypeVariableUnionNull {
22 <T> void implicitlyObjectBounded(
23 Lib<? super @Nullable T> lib, T t, @NullnessUnspecified T tUnspec, @Nullable T tUnionNull) {
24 lib.useT(t);
25
26 lib.useT(tUnspec);
27
28 lib.useT(tUnionNull);
29
30 //
31
32 lib.useTUnspec(t);
33
34 lib.useTUnspec(tUnspec);
35
36 lib.useTUnspec(tUnionNull);
37
38 //
39
40 lib.useTUnionNull(t);
41
42 lib.useTUnionNull(tUnspec);
43
44 lib.useTUnionNull(tUnionNull);
45 }
46
47 <T extends Object> void explicitlyObjectBounded(
48 Lib<? super @Nullable T> lib, T t, @NullnessUnspecified T tUnspec, @Nullable T tUnionNull) {
49 lib.useT(t);
50
51 lib.useT(tUnspec);
52
53 lib.useT(tUnionNull);
54
55 //
56
57 lib.useTUnspec(t);
58
59 lib.useTUnspec(tUnspec);
60
61 lib.useTUnspec(tUnionNull);
62
63 //
64
65 lib.useTUnionNull(t);
66
67 lib.useTUnionNull(tUnspec);
68
69 lib.useTUnionNull(tUnionNull);
70 }
71
72 <T extends @NullnessUnspecified Object> void unspecBounded(
73 Lib<? super @Nullable T> lib, T t, @NullnessUnspecified T tUnspec, @Nullable T tUnionNull) {
74 lib.useT(t);
75
76 lib.useT(tUnspec);
77
78 lib.useT(tUnionNull);
79
80 //
81
82 lib.useTUnspec(t);
83
84 lib.useTUnspec(tUnspec);
85
86 lib.useTUnspec(tUnionNull);
87
88 //
89
90 lib.useTUnionNull(t);
91
92 lib.useTUnionNull(tUnspec);
93
94 lib.useTUnionNull(tUnionNull);
95 }
96
97 <T extends @Nullable Object> void nullableBounded(
98 Lib<? super @Nullable T> lib, T t, @NullnessUnspecified T tUnspec, @Nullable T tUnionNull) {
99 lib.useT(t);
100
101 lib.useT(tUnspec);
102
103 lib.useT(tUnionNull);
104
105 //
106
107 lib.useTUnspec(t);
108
109 lib.useTUnspec(tUnspec);
110
111 lib.useTUnspec(tUnionNull);
112
113 //
114
115 lib.useTUnionNull(t);
116
117 lib.useTUnionNull(tUnspec);
118
119 lib.useTUnionNull(tUnionNull);
120 }
121
122 interface Lib<T extends @Nullable Object> {
123 void useT(T t);
124
125 void useTUnspec(@NullnessUnspecified T t);
126
127 void useTUnionNull(@Nullable T t);
128 }
129 }