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 
17 package com.android.tools.metalava.reporter
18 
19 const val ERROR_WHEN_NEW_SUFFIX = " (ErrorWhenNew)"
20 
21 enum class Severity(
22     /** The name to output when reporting an issue of this [Severity]. */
23     private val displayName: String,
24 
25     /** An optional suffix to append after the issue message, but before the */
26     val messageSuffix: String = "",
27 ) {
28     INHERIT("inherit"),
29 
30     /** The issue is not reported and not included in any baseline files. */
31     HIDDEN("hidden"),
32 
33     /**
34      * Information level are for issues that are informational only; may or may not be a problem.
35      */
36     INFO("info"),
37 
38     /**
39      * Warning level means that we encountered some incompatible or inconsistent API change. These
40      * must be resolved to preserve API compatibility.
41      */
42     WARNING("warning"),
43 
44     /**
45      * An intermediate level between [WARNING] and [ERROR].
46      *
47      * The purpose of this is to ease transition between [WARNING] and [ERROR]. First, the severity
48      * is changed to this which will prevent any new cases being introduced into existing code. Then
49      * the existing cases are fixed. Finally, it is changed to [ERROR].
50      */
51     WARNING_ERROR_WHEN_NEW("warning", messageSuffix = ERROR_WHEN_NEW_SUFFIX),
52 
53     /**
54      * Error level means that we encountered severe trouble and were unable to output the requested
55      * documentation.
56      */
57     ERROR("error");
58 
59     companion object {
60         /**
61          * The default value for the `maximumSeverity` parameter in [Reporter.report] methods which
62          * is the highest [Severity], i.e. last defined.
63          */
64         val UNLIMITED = values().last()
65     }
66 
toStringnull67     override fun toString(): String = displayName
68 }
69