xref: /aosp_15_r20/external/jspecify/samples/DereferenceIntersection.java (revision 2167191df2fa07300797f1ac5b707370b5f38c48)
1*2167191dSAndroid Build Coastguard Worker /*
2*2167191dSAndroid Build Coastguard Worker  * Copyright 2020 The JSpecify Authors.
3*2167191dSAndroid Build Coastguard Worker  *
4*2167191dSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*2167191dSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*2167191dSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*2167191dSAndroid Build Coastguard Worker  *
8*2167191dSAndroid Build Coastguard Worker  *     http://www.apache.org/licenses/LICENSE-2.0
9*2167191dSAndroid Build Coastguard Worker  *
10*2167191dSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*2167191dSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*2167191dSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*2167191dSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*2167191dSAndroid Build Coastguard Worker  * limitations under the License.
15*2167191dSAndroid Build Coastguard Worker  */
16*2167191dSAndroid Build Coastguard Worker import org.jspecify.annotations.NullMarked;
17*2167191dSAndroid Build Coastguard Worker import org.jspecify.annotations.Nullable;
18*2167191dSAndroid Build Coastguard Worker import org.jspecify.annotations.NullnessUnspecified;
19*2167191dSAndroid Build Coastguard Worker 
20*2167191dSAndroid Build Coastguard Worker @NullMarked
21*2167191dSAndroid Build Coastguard Worker class DereferenceIntersection {
x0(ImplicitlyObjectBounded<? extends Lib> x)22*2167191dSAndroid Build Coastguard Worker   void x0(ImplicitlyObjectBounded<? extends Lib> x) {
23*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
24*2167191dSAndroid Build Coastguard Worker     }
25*2167191dSAndroid Build Coastguard Worker   }
26*2167191dSAndroid Build Coastguard Worker 
x1(ImplicitlyObjectBounded<? extends @NullnessUnspecified Lib> x)27*2167191dSAndroid Build Coastguard Worker   void x1(ImplicitlyObjectBounded<? extends @NullnessUnspecified Lib> x) {
28*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
29*2167191dSAndroid Build Coastguard Worker     }
30*2167191dSAndroid Build Coastguard Worker   }
31*2167191dSAndroid Build Coastguard Worker 
x2(ImplicitlyObjectBounded<? extends @Nullable Lib> x)32*2167191dSAndroid Build Coastguard Worker   void x2(ImplicitlyObjectBounded<? extends @Nullable Lib> x) {
33*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
34*2167191dSAndroid Build Coastguard Worker     }
35*2167191dSAndroid Build Coastguard Worker   }
36*2167191dSAndroid Build Coastguard Worker 
x3(ExplicitlyObjectBounded<? extends Lib> x)37*2167191dSAndroid Build Coastguard Worker   void x3(ExplicitlyObjectBounded<? extends Lib> x) {
38*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
39*2167191dSAndroid Build Coastguard Worker     }
40*2167191dSAndroid Build Coastguard Worker   }
41*2167191dSAndroid Build Coastguard Worker 
x4(ExplicitlyObjectBounded<? extends @NullnessUnspecified Lib> x)42*2167191dSAndroid Build Coastguard Worker   void x4(ExplicitlyObjectBounded<? extends @NullnessUnspecified Lib> x) {
43*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
44*2167191dSAndroid Build Coastguard Worker     }
45*2167191dSAndroid Build Coastguard Worker   }
46*2167191dSAndroid Build Coastguard Worker 
x5(ExplicitlyObjectBounded<? extends @Nullable Lib> x)47*2167191dSAndroid Build Coastguard Worker   void x5(ExplicitlyObjectBounded<? extends @Nullable Lib> x) {
48*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
49*2167191dSAndroid Build Coastguard Worker     }
50*2167191dSAndroid Build Coastguard Worker   }
51*2167191dSAndroid Build Coastguard Worker 
x6(UnspecBounded<? extends Lib> x)52*2167191dSAndroid Build Coastguard Worker   void x6(UnspecBounded<? extends Lib> x) {
53*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
54*2167191dSAndroid Build Coastguard Worker     }
55*2167191dSAndroid Build Coastguard Worker   }
56*2167191dSAndroid Build Coastguard Worker 
x7(UnspecBounded<? extends @NullnessUnspecified Lib> x)57*2167191dSAndroid Build Coastguard Worker   void x7(UnspecBounded<? extends @NullnessUnspecified Lib> x) {
58*2167191dSAndroid Build Coastguard Worker     // jspecify_nullness_not_enough_information
59*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
60*2167191dSAndroid Build Coastguard Worker     }
61*2167191dSAndroid Build Coastguard Worker   }
62*2167191dSAndroid Build Coastguard Worker 
x8(UnspecBounded<? extends @Nullable Lib> x)63*2167191dSAndroid Build Coastguard Worker   void x8(UnspecBounded<? extends @Nullable Lib> x) {
64*2167191dSAndroid Build Coastguard Worker     // jspecify_nullness_not_enough_information
65*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
66*2167191dSAndroid Build Coastguard Worker     }
67*2167191dSAndroid Build Coastguard Worker   }
68*2167191dSAndroid Build Coastguard Worker 
x9(NullableBounded<? extends Lib> x)69*2167191dSAndroid Build Coastguard Worker   void x9(NullableBounded<? extends Lib> x) {
70*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
71*2167191dSAndroid Build Coastguard Worker     }
72*2167191dSAndroid Build Coastguard Worker   }
73*2167191dSAndroid Build Coastguard Worker 
x10(NullableBounded<? extends @NullnessUnspecified Lib> x)74*2167191dSAndroid Build Coastguard Worker   void x10(NullableBounded<? extends @NullnessUnspecified Lib> x) {
75*2167191dSAndroid Build Coastguard Worker     // jspecify_nullness_not_enough_information
76*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
77*2167191dSAndroid Build Coastguard Worker     }
78*2167191dSAndroid Build Coastguard Worker   }
79*2167191dSAndroid Build Coastguard Worker 
x11(NullableBounded<? extends @Nullable Lib> x)80*2167191dSAndroid Build Coastguard Worker   void x11(NullableBounded<? extends @Nullable Lib> x) {
81*2167191dSAndroid Build Coastguard Worker     // jspecify_nullness_mismatch
82*2167191dSAndroid Build Coastguard Worker     synchronized (x.get()) {
83*2167191dSAndroid Build Coastguard Worker     }
84*2167191dSAndroid Build Coastguard Worker   }
85*2167191dSAndroid Build Coastguard Worker 
86*2167191dSAndroid Build Coastguard Worker   interface ImplicitlyObjectBounded<T> {
get()87*2167191dSAndroid Build Coastguard Worker     T get();
88*2167191dSAndroid Build Coastguard Worker   }
89*2167191dSAndroid Build Coastguard Worker 
90*2167191dSAndroid Build Coastguard Worker   interface ExplicitlyObjectBounded<T extends Object> {
get()91*2167191dSAndroid Build Coastguard Worker     T get();
92*2167191dSAndroid Build Coastguard Worker   }
93*2167191dSAndroid Build Coastguard Worker 
94*2167191dSAndroid Build Coastguard Worker   interface UnspecBounded<T extends @NullnessUnspecified Object> {
get()95*2167191dSAndroid Build Coastguard Worker     T get();
96*2167191dSAndroid Build Coastguard Worker   }
97*2167191dSAndroid Build Coastguard Worker 
98*2167191dSAndroid Build Coastguard Worker   interface NullableBounded<T extends @Nullable Object> {
get()99*2167191dSAndroid Build Coastguard Worker     T get();
100*2167191dSAndroid Build Coastguard Worker   }
101*2167191dSAndroid Build Coastguard Worker 
102*2167191dSAndroid Build Coastguard Worker   interface Lib {}
103*2167191dSAndroid Build Coastguard Worker }
104