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