• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Issues
20 import com.android.tools.metalava.Options
21 import com.android.tools.metalava.Severity
22 
23 /** An issue configuration is a set of overrides for severities for various [Issues.Issue] */
24 class IssueConfiguration {
25     private val overrides = mutableMapOf<Issues.Issue, Severity>()
26 
27     /** Returns the severity of the given issue */
getSeveritynull28     fun getSeverity(issue: Issues.Issue): Severity {
29         overrides[issue]?.let { return it }
30         if (issue.defaultLevel == Severity.INHERIT) {
31             return getSeverity(issue.parent!!)
32         }
33         return issue.defaultLevel
34     }
35 
setSeveritynull36     fun setSeverity(issue: Issues.Issue, severity: Severity) {
37         check(severity != Severity.INHERIT)
38         overrides[issue] = severity
39     }
40 
41     /** Set the severity of the given issue to [Severity.ERROR] */
errornull42     fun error(issue: Issues.Issue) {
43         setSeverity(issue, Severity.ERROR)
44     }
45 
46     /** Set the severity of the given issue to [Severity.HIDDEN] */
hidenull47     fun hide(issue: Issues.Issue) {
48         setSeverity(issue, Severity.HIDDEN)
49     }
50 
resetnull51     fun reset() {
52         overrides.clear()
53     }
54 }
55 
56 /** Default error configuration: uses the severities as configured in [Options] */
57 val defaultConfiguration = IssueConfiguration()
58 
59 /** Current configuration to apply when reporting errors */
60 var configuration = defaultConfiguration
61