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 SuperTypeVariableUnspec { implicitlyObjectBounded( Lib<? super @NullnessUnspecified T> lib, T t, @NullnessUnspecified T tUnspec, @Nullable T tUnionNull)22 <T> void implicitlyObjectBounded( 23 Lib<? super @NullnessUnspecified T> lib, 24 T t, 25 @NullnessUnspecified T tUnspec, 26 @Nullable T tUnionNull) { 27 lib.useT(t); 28 29 // jspecify_nullness_not_enough_information 30 lib.useT(tUnspec); 31 32 // jspecify_nullness_not_enough_information 33 lib.useT(tUnionNull); 34 35 // 36 37 lib.useTUnspec(t); 38 39 // jspecify_nullness_not_enough_information 40 lib.useTUnspec(tUnspec); 41 42 // jspecify_nullness_not_enough_information 43 lib.useTUnspec(tUnionNull); 44 45 // 46 47 lib.useTUnionNull(t); 48 49 lib.useTUnionNull(tUnspec); 50 51 lib.useTUnionNull(tUnionNull); 52 } 53 explicitlyObjectBounded( Lib<? super @NullnessUnspecified T> lib, T t, @NullnessUnspecified T tUnspec, @Nullable T tUnionNull)54 <T extends Object> void explicitlyObjectBounded( 55 Lib<? super @NullnessUnspecified T> lib, 56 T t, 57 @NullnessUnspecified T tUnspec, 58 @Nullable T tUnionNull) { 59 lib.useT(t); 60 61 // jspecify_nullness_not_enough_information 62 lib.useT(tUnspec); 63 64 // jspecify_nullness_not_enough_information 65 lib.useT(tUnionNull); 66 67 // 68 69 lib.useTUnspec(t); 70 71 // jspecify_nullness_not_enough_information 72 lib.useTUnspec(tUnspec); 73 74 // jspecify_nullness_not_enough_information 75 lib.useTUnspec(tUnionNull); 76 77 // 78 79 lib.useTUnionNull(t); 80 81 lib.useTUnionNull(tUnspec); 82 83 lib.useTUnionNull(tUnionNull); 84 } 85 unspecBounded( Lib<? super @NullnessUnspecified T> lib, T t, @NullnessUnspecified T tUnspec, @Nullable T tUnionNull)86 <T extends @NullnessUnspecified Object> void unspecBounded( 87 Lib<? super @NullnessUnspecified T> lib, 88 T t, 89 @NullnessUnspecified T tUnspec, 90 @Nullable T tUnionNull) { 91 lib.useT(t); 92 93 // jspecify_nullness_not_enough_information 94 lib.useT(tUnspec); 95 96 // jspecify_nullness_not_enough_information 97 lib.useT(tUnionNull); 98 99 // 100 101 lib.useTUnspec(t); 102 103 // jspecify_nullness_not_enough_information 104 lib.useTUnspec(tUnspec); 105 106 // jspecify_nullness_not_enough_information 107 lib.useTUnspec(tUnionNull); 108 109 // 110 111 lib.useTUnionNull(t); 112 113 lib.useTUnionNull(tUnspec); 114 115 lib.useTUnionNull(tUnionNull); 116 } 117 nullableBounded( Lib<? super @NullnessUnspecified T> lib, T t, @NullnessUnspecified T tUnspec, @Nullable T tUnionNull)118 <T extends @Nullable Object> void nullableBounded( 119 Lib<? super @NullnessUnspecified T> lib, 120 T t, 121 @NullnessUnspecified T tUnspec, 122 @Nullable T tUnionNull) { 123 lib.useT(t); 124 125 // jspecify_nullness_not_enough_information 126 lib.useT(tUnspec); 127 128 // jspecify_nullness_not_enough_information 129 lib.useT(tUnionNull); 130 131 // 132 133 lib.useTUnspec(t); 134 135 // jspecify_nullness_not_enough_information 136 lib.useTUnspec(tUnspec); 137 138 // jspecify_nullness_not_enough_information 139 lib.useTUnspec(tUnionNull); 140 141 // 142 143 lib.useTUnionNull(t); 144 145 lib.useTUnionNull(tUnspec); 146 147 lib.useTUnionNull(tUnionNull); 148 } 149 150 interface Lib<T extends @Nullable Object> { useT(T t)151 void useT(T t); 152 useTUnspec(@ullnessUnspecified T t)153 void useTUnspec(@NullnessUnspecified T t); 154 useTUnionNull(@ullable T t)155 void useTUnionNull(@Nullable T t); 156 } 157 } 158