1 /* 2 * Copyright (C) 2025 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 com.android.platform.test.ravenwood.ravenhelper.policytoannot 18 19 import com.android.hoststubgen.filters.FilterPolicy 20 21 22 /** 23 * This class knows about the Ravenwood annotations. 24 */ 25 class Annotations { 26 enum class Target { 27 Class, 28 Field, 29 Method, 30 } 31 getnull32 fun get(policy: FilterPolicy, target: Target): String? { 33 return when (policy) { 34 FilterPolicy.Keep -> 35 if (target == Target.Class) { 36 "@android.ravenwood.annotation.RavenwoodKeepPartialClass" 37 } else { 38 "@android.ravenwood.annotation.RavenwoodKeep" 39 } 40 FilterPolicy.KeepClass -> 41 "@android.ravenwood.annotation.RavenwoodKeepWholeClass" 42 FilterPolicy.Substitute -> 43 "@android.ravenwood.annotation.RavenwoodReplace" 44 FilterPolicy.Redirect -> 45 "@android.ravenwood.annotation.RavenwoodRedirect" 46 FilterPolicy.Throw -> 47 "@android.ravenwood.annotation.RavenwoodThrow" 48 FilterPolicy.Ignore -> 49 "@android.ravenwood.annotation.RavenwoodIgnore" 50 FilterPolicy.Remove -> 51 "@android.ravenwood.annotation.RavenwoodRemove" 52 FilterPolicy.AnnotationAllowed -> null // Can't convert to an annotation. 53 } 54 } 55 withArgnull56 private fun withArg(annot: String, arg: String): String { 57 return "@$annot(\"$arg\")" 58 } 59 getClassLoadHookAnnotationnull60 fun getClassLoadHookAnnotation(arg: String): String { 61 return withArg("android.ravenwood.annotation.RavenwoodClassLoadHook", arg) 62 } 63 getRedirectionClassAnnotationnull64 fun getRedirectionClassAnnotation(arg: String): String { 65 return withArg("android.ravenwood.annotation.RavenwoodRedirectionClass", arg) 66 } 67 } 68 69