1 /* 2 * Copyright 2023 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 androidx.build.lint 18 19 import com.android.tools.lint.checks.ResourceTypeDetector.Companion.RESOURCE_TYPE 20 import com.android.tools.lint.detector.api.Detector 21 import com.android.tools.lint.detector.api.Issue 22 import com.android.tools.lint.detector.api.JavaContext 23 import com.android.tools.lint.detector.api.LintFix 24 import com.android.tools.lint.detector.api.Location 25 import com.android.tools.lint.detector.api.SourceCodeScanner 26 import org.jetbrains.uast.UElement 27 28 /** 29 * Copied from com/android/tools/lint/checks/AbstractAnnotationDetector.kt in Android Studio repo. 30 */ 31 abstract class AbstractAnnotationDetector : Detector(), SourceCodeScanner { reportnull32 protected fun report( 33 context: JavaContext, 34 issue: Issue, 35 scope: UElement?, 36 location: Location, 37 message: String 38 ) { 39 report(context, issue, scope, location, message, null) 40 } 41 reportnull42 protected fun report( 43 context: JavaContext, 44 issue: Issue, 45 scope: UElement?, 46 location: Location, 47 message: String, 48 quickfixData: LintFix? 49 ) { 50 // In the IDE historically (until 2.0) many checks were covered by the 51 // ResourceTypeInspection, and when suppressed, these would all be suppressed with the 52 // id "ResourceType". 53 // 54 // Since then I've split this up into multiple separate issues, but we still want 55 // to honor the older suppress id, so explicitly check for it here: 56 val driver = context.driver 57 if (issue !== RESOURCE_TYPE) { 58 if (scope != null && driver.isSuppressed(context, RESOURCE_TYPE, scope)) { 59 return 60 } 61 } 62 63 context.report(issue, scope, location, message, quickfixData) 64 } 65 } 66