1 /* 2 * Copyright (C) 2025 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.text 18 19 import com.android.tools.metalava.model.Codebase 20 import com.android.tools.metalava.reporter.Issues 21 22 /** 23 * Provides support for reporting recoverable errors while parsing signature files. 24 * 25 * A recoverable error is one that is not caused by syntax issues and there is an obvious way of 26 * moving past after reporting the problem, e.g. not the invalid information in the [Codebase]. 27 * 28 * This is primarily for testing and reading historical versions which may not quite match the 29 * expected format. In normal use signature files are always generated by Metalava and so should 30 * always be readable by Metalava. 31 */ 32 internal interface SignatureErrorReporter { 33 /** Report recoverable errors encountered while parsing. */ reportnull34 fun report(issue: Issues.Issue, message: String) 35 36 /** Report recoverable errors encountered while parsing, using [Issues.SIGNATURE_FILE_ERROR]. */ 37 fun report(message: String) = report(Issues.SIGNATURE_FILE_ERROR, message) 38 39 companion object { 40 /** A [SignatureErrorReporter] that throws an exception at the first error it encounters. */ 41 val THROWING = 42 object : SignatureErrorReporter { 43 override fun report(issue: Issues.Issue, message: String) { 44 throw ApiParseException("$message [$issue]") 45 } 46 } 47 } 48 } 49