1 /*
2  * Copyright (C) 2018 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.model
18 
19 import com.android.tools.metalava.Severity
20 import com.android.tools.metalava.doclava1.Issues
21 
22 /** An issue configuration is a set of overrides for severities for various [Issues.Issue] */
23 class IssueConfiguration {
24     private val overrides = mutableMapOf<Issues.Issue, Severity>()
25 
26     /** Returns the severity of the given issue */
getSeveritynull27     fun getSeverity(issue: Issues.Issue): Severity {
28         overrides[issue]?.let { return it }
29         if (issue.defaultLevel == Severity.INHERIT) {
30             return getSeverity(issue.parent!!)
31         }
32         return issue.defaultLevel
33     }
34 
setSeveritynull35     fun setSeverity(issue: Issues.Issue, severity: Severity) {
36         check(severity != Severity.INHERIT)
37         overrides[issue] = severity
38     }
39 
40     /** Set the severity of the given issue to [Severity.ERROR] */
errornull41     fun error(issue: Issues.Issue) {
42         setSeverity(issue, Severity.ERROR)
43     }
44 
45     /** Set the severity of the given issue to [Severity.HIDDEN] */
hidenull46     fun hide(issue: Issues.Issue) {
47         setSeverity(issue, Severity.HIDDEN)
48     }
49 
resetnull50     fun reset() {
51         overrides.clear()
52     }
53 }
54 
55 /** Default error configuration: uses the severities as configured in [Options] */
56 val defaultConfiguration = IssueConfiguration()
57 
58 /** Current configuration to apply when reporting errors */
59 var configuration = defaultConfiguration
60