1 /* 2 * Copyright 2022 The Android Open Source Project 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 17 package sample.kotlin.foo; 18 19 import kotlin.OptIn; 20 import sample.kotlin.ExperimentalJavaAnnotation; 21 22 /** 23 * Regression test for b/218798815 where the lint check yields false positives on usages within an 24 * annotated package. 25 */ 26 @SuppressWarnings("unused") 27 public class RegressionTestJava218798815 { 28 29 /** 30 * Safe call into a method on a class within the same experimental package. 31 */ safeMethodInExperimentalPackage()32 void safeMethodInExperimentalPackage() { 33 AnnotatedJavaPackage experimentalObject = new AnnotatedJavaPackage(); 34 experimentalObject.method(); 35 } 36 37 /** 38 * Safe call with redundant propagation of experimental marker. 39 */ 40 @ExperimentalJavaAnnotation safePropagateMarker()41 void safePropagateMarker() { 42 AnnotatedJavaPackage experimentalObject = new AnnotatedJavaPackage(); 43 experimentalObject.method(); 44 } 45 46 /** 47 * Safe call with unnecessary and invalid opt-in to experimental marker. 48 */ 49 @OptIn(markerClass = ExperimentalJavaAnnotation.class) safeOptInMarker()50 void safeOptInMarker() { 51 AnnotatedJavaPackage experimentalObject = new AnnotatedJavaPackage(); 52 experimentalObject.method(); 53 } 54 55 /** 56 * Safe call into a method with an safe call. This should not be flagged, as the 57 * called method itself is not experimental. 58 */ safeSelfExperimental()59 void safeSelfExperimental() { 60 safeMethodInExperimentalPackage(); 61 } 62 63 /** 64 * Safe call into a redundantly-annotated experimental method within the same experimetnal 65 * package. 66 */ safeSelfPropagateMarker()67 void safeSelfPropagateMarker() { 68 safePropagateMarker(); 69 } 70 } 71