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.reporter 18 19 /** An issue configuration is a set of overrides for severities for various [Issues.Issue] */ 20 class IssueConfiguration { 21 private val overrides = mutableMapOf<Issues.Issue, Severity>() 22 23 /** Returns the severity of the given issue */ getSeveritynull24 fun getSeverity(issue: Issues.Issue): Severity { 25 overrides[issue]?.let { 26 return it 27 } 28 if (issue.defaultLevel == Severity.INHERIT) { 29 return getSeverity(issue.parent!!) 30 } 31 return issue.defaultLevel 32 } 33 setSeveritynull34 fun setSeverity(issue: Issues.Issue, severity: Severity) { 35 check(severity != Severity.INHERIT) 36 overrides[issue] = severity 37 } 38 39 /** Set the severity of the given issue to [Severity.ERROR] */ errornull40 fun error(issue: Issues.Issue) { 41 setSeverity(issue, Severity.ERROR) 42 } 43 44 /** Set the severity of the given issue to [Severity.HIDDEN] */ hidenull45 fun hide(issue: Issues.Issue) { 46 setSeverity(issue, Severity.HIDDEN) 47 } 48 } 49