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 /* 21 * For the moment, we don't require support for parameter contravariance: 22 * https://github.com/jspecify/jspecify/issues/49 23 * 24 * (If we change that, we should revise our samples README to explain that this is a case in which 25 * we deviate from JLS rules: 26 * https://github.com/jspecify/jspecify/blob/e55eb43f3bc1e7493b8b28a9dadd2b9b254e3335/samples/README.md#what-sample-inputs-demonstrate) 27 */ 28 @NullMarked 29 class OverrideParameters { 30 interface Super { useObject(Object o)31 void useObject(Object o); 32 useObjectUnspec(@ullnessUnspecified Object o)33 void useObjectUnspec(@NullnessUnspecified Object o); 34 useObjectUnionNull(@ullable Object o)35 void useObjectUnionNull(@Nullable Object o); 36 } 37 38 interface SubObject extends Super { 39 @Override useObject(Object o)40 void useObject(Object o); 41 42 @Override 43 // jspecify_nullness_not_enough_information useObjectUnspec(Object o)44 void useObjectUnspec(Object o); 45 46 @Override 47 // jspecify_nullness_mismatch useObjectUnionNull(Object o)48 void useObjectUnionNull(Object o); 49 } 50 51 interface SubObjectUnspec extends Super { 52 @Override 53 // jspecify_nullness_not_enough_information useObject(@ullnessUnspecified Object o)54 void useObject(@NullnessUnspecified Object o); 55 56 @Override 57 // jspecify_nullness_not_enough_information useObjectUnspec(@ullnessUnspecified Object o)58 void useObjectUnspec(@NullnessUnspecified Object o); 59 60 @Override 61 // jspecify_nullness_not_enough_information useObjectUnionNull(@ullnessUnspecified Object o)62 void useObjectUnionNull(@NullnessUnspecified Object o); 63 } 64 65 interface SubObjectUnionNull extends Super { 66 @Override 67 // jspecify_nullness_mismatch useObject(@ullable Object o)68 void useObject(@Nullable Object o); 69 70 @Override 71 // jspecify_nullness_not_enough_information useObjectUnspec(@ullable Object o)72 void useObjectUnspec(@Nullable Object o); 73 74 @Override useObjectUnionNull(@ullable Object o)75 void useObjectUnionNull(@Nullable Object o); 76 } 77 } 78