• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 package com.android.hoststubgen.filters
17 
18 /**
19  * How each entry should be handled on the dashboard.
20  */
21 enum class StatsLabel(val statValue: Int, val label: String) {
22     /** Entry shouldn't show up in the dashboard. */
23     Ignored(-1, ""),
24 
25     /** Entry should be shown as "not supported" */
26     NotSupported(0, "NotSupported"),
27 
28     /**
29      * Entry should be shown as "supported", but are too "boring" to show on the dashboard,
30      * e.g. annotation classes.
31      */
32     SupportedButBoring(1, "Boring"),
33 
34     /** Entry should be shown as "supported" */
35     Supported(2, "Supported");
36 
37     val isSupported: Boolean
38         get() {
39         return when (this) {
40             SupportedButBoring, Supported -> true
41             else -> false
42         }
43     }
44 }
45 
46 /**
47  * Captures a [FilterPolicy] with a human-readable reason.
48  */
49 data class FilterPolicyWithReason (
50     val policy: FilterPolicy,
51     val reason: String = "",
52     val statsLabelOverride: StatsLabel? = null
53 ) {
54     /**
55      * Return a new [FilterPolicy] with an updated reason, while keeping the original reason
56      * as an "inner-reason".
57      */
wrapReasonnull58     fun wrapReason(reason: String, statsLabelOverride: StatsLabel? = null): FilterPolicyWithReason {
59         return FilterPolicyWithReason(
60             policy,
61             "$reason [inner-reason: ${this.reason}]",
62             statsLabelOverride = statsLabelOverride ?: this.statsLabelOverride,
63         )
64     }
65 
toStringnull66     override fun toString(): String {
67         return "[$policy/$statsLabel - reason: $reason]"
68     }
69 
70     val statsLabel: StatsLabel get() {
<lambda>null71         statsLabelOverride?.let { return it }
72         if (policy.isSupported) {
73             return StatsLabel.Supported
74         }
75         return StatsLabel.NotSupported
76     }
77 }
78