1 /* 2 * Copyright 2019 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 18 19 import androidx.annotation.OptIn 20 import sample.optin.foo.AnnotatedJavaPackage 21 22 @Suppress("unused", "MemberVisibilityCanBePrivate") 23 class UseJavaPackageFromKt { 24 25 /** Unsafe call into a method on a class within an experimental package. */ callPackageUnsafenull26 fun callPackageUnsafe() { 27 val experimentalObject = AnnotatedJavaPackage() 28 experimentalObject.method() 29 } 30 31 /** Safe call due to propagation of experimental marker. */ 32 @ExperimentalJavaAnnotation callPackageExperimentalnull33 fun callPackageExperimental() { 34 val experimentalObject = AnnotatedJavaPackage() 35 experimentalObject.method() 36 } 37 38 /** Safe call due to opt-in to experimental marker. */ 39 @OptIn(ExperimentalJavaAnnotation::class) callPackageUseExperimentalnull40 fun callPackageUseExperimental() { 41 val experimentalObject = AnnotatedJavaPackage() 42 experimentalObject.method() 43 } 44 45 /** 46 * Unsafe call into a method with an unsafe call. This should not be flagged, as the called 47 * method itself is not experimental. 48 */ callSelfUnsafenull49 fun callSelfUnsafe() { 50 callPackageUnsafe() 51 } 52 53 /** Unsafe call into an experimental method within this class. */ callSelfExperimentalnull54 fun callSelfExperimental() { 55 callPackageExperimental() 56 } 57 58 /** Safe call into an opted-in method within this class. */ callSelfUseExperimentalnull59 fun callSelfUseExperimental() { 60 callPackageUseExperimental() 61 } 62 } 63