[FIR] Introduce extended checkers for inspection-like diagnostics
This commit is contained in:
committed by
Mikhail Glukhikh
parent
4643d483a0
commit
be684c784f
Generated
+35
@@ -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");
|
||||
}
|
||||
}
|
||||
Generated
-18
@@ -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)
|
||||
|
||||
-18
@@ -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)
|
||||
|
||||
+1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
|
||||
abstract class FirDeclarationChecker<in D : FirDeclaration> {
|
||||
abstract fun check(declaration: D, context: CheckerContext, reporter: DiagnosticReporter)
|
||||
open val isExtended = false
|
||||
}
|
||||
|
||||
typealias FirBasicDeclarationChecker = FirDeclarationChecker<FirDeclaration>
|
||||
|
||||
+2
-4
@@ -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
|
||||
|
||||
+2
-2
@@ -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),
|
||||
|
||||
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
+10
@@ -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
|
||||
}
|
||||
@@ -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<FirFile>) {
|
||||
@@ -359,4 +359,6 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal open fun useExtendedCheckersIfNeeded() = false
|
||||
}
|
||||
|
||||
@@ -633,5 +633,11 @@ fun main(args: Array<String>) {
|
||||
model("uncommonCases/testFiles", testMethod = "doUncommonCasesTest")
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("compiler/fir/analysis-tests/tests", "compiler/fir/analysis-tests/testData") {
|
||||
testClass<AbstractExtendedFirDiagnosticsTest> {
|
||||
model("extendedCheckers", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user