From eb9f0e682d55bc6e7599966b35b746ebc293f3e5 Mon Sep 17 00:00:00 2001 From: Sergey Patrikeev Date: Mon, 30 Sep 2019 16:09:16 +0300 Subject: [PATCH] UnstableApiUsageInspection: do not run the inspection if no unstable annotation is found in the project. GitOrigin-RevId: 78b4bfe94f550a5bf92211f90e3e18eb19b1b2b5 --- .../UnstableApiUsageInspection.kt | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/UnstableApiUsageInspection.kt b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/UnstableApiUsageInspection.kt index aa97ea17fc31..c035e5a9881e 100644 --- a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/UnstableApiUsageInspection.kt +++ b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/UnstableApiUsageInspection.kt @@ -51,15 +51,23 @@ class UnstableApiUsageInspection : LocalInspectionTool() { @JvmField var myIgnoreInsideImports: Boolean = true - override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = - ApiUsageUastVisitor.createPsiElementVisitor( - UnstableApiUsageProcessor( - holder, - myIgnoreInsideImports, - unstableApiAnnotations.toList(), - knownAnnotationMessageProviders + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { + val annotations = unstableApiAnnotations.toList() + val psiFacade = JavaPsiFacade.getInstance(holder.project) + val resolveScope = holder.file.resolveScope + return if (annotations.any { psiFacade.findClass(it, resolveScope) != null }) { + ApiUsageUastVisitor.createPsiElementVisitor( + UnstableApiUsageProcessor( + holder, + myIgnoreInsideImports, + annotations, + knownAnnotationMessageProviders + ) ) - ) + } else { + PsiElementVisitor.EMPTY_VISITOR + } + } override fun createOptionsPanel(): JPanel { val checkboxPanel = SingleCheckboxOptionsPanel(