diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt b/compiler/fir/analysis-tests/testData/extendedCheckers/RedundantVisibilityModifierChecker.kt similarity index 100% rename from compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt rename to compiler/fir/analysis-tests/testData/extendedCheckers/RedundantVisibilityModifierChecker.kt diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/ExtendedFirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/ExtendedFirDiagnosticsTestGenerated.java new file mode 100644 index 00000000000..aaf414b872b --- /dev/null +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/ExtendedFirDiagnosticsTestGenerated.java @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/fir/analysis-tests/testData/extendedCheckers") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class ExtendedFirDiagnosticsTestGenerated extends AbstractExtendedFirDiagnosticsTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInExtendedCheckers() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/extendedCheckers"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @TestMetadata("RedundantVisibilityModifierChecker.kt") + public void testRedundantVisibilityModifierChecker() throws Exception { + runTest("compiler/fir/analysis-tests/testData/extendedCheckers/RedundantVisibilityModifierChecker.kt"); + } +} diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 724661a30f4..d0e0dedef1a 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -1414,24 +1414,6 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { } } - @TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ExtendedCheckers extends AbstractFirDiagnosticsTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - public void testAllFilesPresentInExtendedCheckers() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers"), Pattern.compile("^([^.]+)\\.kt$"), null, true); - } - - @TestMetadata("RedundantVisibilityModifierChecker.kt") - public void testRedundantVisibilityModifierChecker() throws Exception { - runTest("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt"); - } - } - @TestMetadata("compiler/fir/analysis-tests/testData/resolve/fromBuilder") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 195a27c3b4f..29228cbf02c 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1414,24 +1414,6 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos } } - @TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ExtendedCheckers extends AbstractFirDiagnosticsWithLightTreeTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - public void testAllFilesPresentInExtendedCheckers() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers"), Pattern.compile("^([^.]+)\\.kt$"), null, true); - } - - @TestMetadata("RedundantVisibilityModifierChecker.kt") - public void testRedundantVisibilityModifierChecker() throws Exception { - runTest("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt"); - } - } - @TestMetadata("compiler/fir/analysis-tests/testData/resolve/fromBuilder") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDeclarationChecker.kt index c3083a15870..7634769444d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDeclarationChecker.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration abstract class FirDeclarationChecker { abstract fun check(declaration: D, context: CheckerContext, reporter: DiagnosticReporter) + open val isExtended = false } typealias FirBasicDeclarationChecker = FirDeclarationChecker diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierChecker.kt index 09c1ee84594..11f2117b197 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantVisibilityModifierChecker.kt @@ -16,14 +16,12 @@ import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirBasicDeclaratio import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.psi import org.jetbrains.kotlin.fir.toFirPsiSourceElement -import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.psi.KtModifierList import org.jetbrains.kotlin.psi.psiUtil.visibilityModifier -import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType object RedundantVisibilityModifierChecker : FirBasicDeclarationChecker() { + override val isExtended = true + override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) { if (declaration is FirPropertyAccessor && declaration.isGetter) return if (declaration !is FirMemberDeclaration) return diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt index 9d71945b1bf..4d356ff6fcd 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt @@ -196,9 +196,9 @@ abstract class AbstractDiagnosticCollector( } } -fun AbstractDiagnosticCollector.registerAllComponents() { +fun AbstractDiagnosticCollector.registerAllComponents(checkExtended: Boolean = false) { initializeComponents( - DeclarationCheckersDiagnosticComponent(this), + DeclarationCheckersDiagnosticComponent(this, checkExtended), ExpressionCheckersDiagnosticComponent(this), ErrorNodeDiagnosticCollectorComponent(this), ControlFlowAnalysisDiagnosticComponent(this), diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/FirDiagnosticsCollector.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/FirDiagnosticsCollector.kt index 9c654dca277..984b1456a8a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/FirDiagnosticsCollector.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/FirDiagnosticsCollector.kt @@ -11,10 +11,10 @@ import org.jetbrains.kotlin.fir.analysis.extensions.additionalCheckers import org.jetbrains.kotlin.fir.extensions.extensionService object FirDiagnosticsCollector { - fun create(session: FirSession): AbstractDiagnosticCollector { + fun create(session: FirSession, checkExtended: Boolean = false): AbstractDiagnosticCollector { session.registerAdditionalCheckers() val collector = SimpleDiagnosticsCollector(session) - collector.registerAllComponents() + collector.registerAllComponents(checkExtended) return collector } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/DeclarationCheckersDiagnosticComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/DeclarationCheckersDiagnosticComponent.kt index 4e5a2a35f9a..6d093e31daa 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/DeclarationCheckersDiagnosticComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/DeclarationCheckersDiagnosticComponent.kt @@ -12,7 +12,10 @@ import org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollector import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.declarations.* -class DeclarationCheckersDiagnosticComponent(collector: AbstractDiagnosticCollector) : AbstractDiagnosticCollectorComponent(collector) { +class DeclarationCheckersDiagnosticComponent( + collector: AbstractDiagnosticCollector, + private val checkExtended: Boolean +) : AbstractDiagnosticCollectorComponent(collector) { private val checkers = session.checkersComponent.declarationCheckers override fun visitProperty(property: FirProperty, data: CheckerContext) { @@ -69,7 +72,8 @@ class DeclarationCheckersDiagnosticComponent(collector: AbstractDiagnosticCollec reporter: DiagnosticReporter ) { for (checker in this) { - checker.check(declaration, context, reporter) + if (!checker.isExtended || checkExtended) + checker.check(declaration, context, reporter) } } } \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 24e974a88d7..00734e8ba90 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -6,9 +6,6 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.descriptors.DescriptorWithRelation -import org.jetbrains.kotlin.descriptors.EffectiveVisibility -import org.jetbrains.kotlin.diagnostics.DiagnosticFactory3 import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.fir.DeclarationWithRelation import org.jetbrains.kotlin.fir.FirEffectiveVisibility diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractExtendedFirDiagnosticsTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractExtendedFirDiagnosticsTest.kt new file mode 100644 index 00000000000..83568ecfe7f --- /dev/null +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractExtendedFirDiagnosticsTest.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir + +abstract class AbstractExtendedFirDiagnosticsTest : AbstractFirDiagnosticsTest() { + override fun useExtendedCheckersIfNeeded(): Boolean = true +} \ No newline at end of file diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt index df80bec70d4..5088a1ba4ff 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/fir/AbstractFirDiagnosticTest.kt @@ -276,7 +276,7 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() { } private fun createCollector(session: FirSession): AbstractDiagnosticCollector { - return FirDiagnosticsCollector.create(session) + return FirDiagnosticsCollector.create(session, useExtendedCheckersIfNeeded()) } private fun checkCfgDump(testDataFile: File, firFiles: List) { @@ -359,4 +359,6 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() { } } + + internal open fun useExtendedCheckersIfNeeded() = false } diff --git a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt index 06825289927..b19ec02d956 100644 --- a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt +++ b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt @@ -633,5 +633,11 @@ fun main(args: Array) { model("uncommonCases/testFiles", testMethod = "doUncommonCasesTest") } } + + testGroup("compiler/fir/analysis-tests/tests", "compiler/fir/analysis-tests/testData") { + testClass { + model("extendedCheckers", pattern = KT_WITHOUT_DOTS_IN_NAME) + } + } } }