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.Errors 21 22 /** An error configuration is a set of overrides for severities for various [Errors.Error] */ 23 class ErrorConfiguration { 24 private val overrides = mutableMapOf<Errors.Error, Severity>() 25 26 /** Returns the severity of the given issue */ getSeveritynull27 fun getSeverity(error: Errors.Error): Severity { 28 return overrides[error] ?: error.level 29 } 30 setSeveritynull31 private fun setSeverity(error: Errors.Error, severity: Severity) { 32 overrides[error] = severity 33 } 34 35 /** Set the severity of the given issue to [Severity.ERROR] */ errornull36 fun error(error: Errors.Error) { 37 setSeverity(error, Severity.ERROR) 38 } 39 40 /** Set the severity of the given issue to [Severity.HIDDEN] */ hidenull41 fun hide(error: Errors.Error) { 42 setSeverity(error, Severity.HIDDEN) 43 } 44 } 45 46 /** Default error configuration: uses all the severities initialized in the [Errors] class */ 47 val defaultConfiguration = ErrorConfiguration() 48 49 /** Current configuration to apply when reporting errors */ 50 var configuration = defaultConfiguration 51