From 799253256cb0f5ab604d5abee711c1a5866de877 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 12 May 2020 11:13:42 +0300 Subject: [PATCH] [FIR-PLUGIN] Add additional checker to prototype plugin --- .../fir/fir-plugin-prototype/build.gradle.kts | 1 + .../fir/plugin/AllOpenAdditionalCheckers.kt | 22 +++++++++++++++++++ .../plugin/FirAllOpenComponentRegistrar.kt | 1 + .../fir/plugin/checkers/DummyNameChecker.kt | 22 +++++++++++++++++++ .../testData/checkers/simple.kt | 13 +++++++++++ .../testData/checkers/simple.txt | 21 ++++++++++++++++++ .../FirAllOpenDiagnosticTestGenerated.java | 18 +++++++++++++++ 7 files changed, 98 insertions(+) create mode 100644 plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/AllOpenAdditionalCheckers.kt create mode 100644 plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/checkers/DummyNameChecker.kt create mode 100644 plugins/fir/fir-plugin-prototype/testData/checkers/simple.kt create mode 100644 plugins/fir/fir-plugin-prototype/testData/checkers/simple.txt diff --git a/plugins/fir/fir-plugin-prototype/build.gradle.kts b/plugins/fir/fir-plugin-prototype/build.gradle.kts index d70623d8694..aff5b8dac74 100644 --- a/plugins/fir/fir-plugin-prototype/build.gradle.kts +++ b/plugins/fir/fir-plugin-prototype/build.gradle.kts @@ -7,6 +7,7 @@ dependencies { compile(project(":compiler:fir:cones")) compile(project(":compiler:fir:tree")) compile(project(":compiler:fir:resolve")) + compile(project(":compiler:fir:checkers")) compile(project(":compiler:frontend")) compileOnly(project(":kotlin-reflect-api")) diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/AllOpenAdditionalCheckers.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/AllOpenAdditionalCheckers.kt new file mode 100644 index 00000000000..e50c36a97d5 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/AllOpenAdditionalCheckers.kt @@ -0,0 +1,22 @@ +/* + * 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.plugin + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.analysis.checkers.declaration.DeclarationCheckers +import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirMemberDeclarationChecker +import org.jetbrains.kotlin.fir.analysis.extensions.FirAdditionalCheckersExtension +import org.jetbrains.kotlin.fir.declarations.FirPluginKey +import org.jetbrains.kotlin.fir.plugin.checkers.DummyNameChecker + +class AllOpenAdditionalCheckers(session: FirSession) : FirAdditionalCheckersExtension(session) { + override val key: FirPluginKey + get() = AllOpenPluginKey + + override val declarationCheckers: DeclarationCheckers = object : DeclarationCheckers() { + override val memberDeclarationCheckers: List = listOf(DummyNameChecker) + } +} \ No newline at end of file diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirAllOpenComponentRegistrar.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirAllOpenComponentRegistrar.kt index 1a6bcfd8e42..b50fdccbe1f 100644 --- a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirAllOpenComponentRegistrar.kt +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirAllOpenComponentRegistrar.kt @@ -11,5 +11,6 @@ class FirAllOpenComponentRegistrar : FirExtensionRegistrar() { override fun ExtensionRegistrarContext.configurePlugin() { +::AllOpenStatusTransformer +::AllOpenClassGenerator + +::AllOpenAdditionalCheckers } } \ No newline at end of file diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/checkers/DummyNameChecker.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/checkers/DummyNameChecker.kt new file mode 100644 index 00000000000..2ee78d6bbf2 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/checkers/DummyNameChecker.kt @@ -0,0 +1,22 @@ +/* + * 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.plugin.checkers + +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirMemberDeclarationChecker +import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration +import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction + +object DummyNameChecker : FirMemberDeclarationChecker() { + override fun check(declaration: FirMemberDeclaration, context: CheckerContext, reporter: DiagnosticReporter) { + if (declaration !is FirSimpleFunction) return + if (declaration.name.asString() == "dummy") { + declaration.source?.let { reporter.report(FirErrors.SYNTAX_ERROR.on(it)) } + } + } +} \ No newline at end of file diff --git a/plugins/fir/fir-plugin-prototype/testData/checkers/simple.kt b/plugins/fir/fir-plugin-prototype/testData/checkers/simple.kt new file mode 100644 index 00000000000..4e874e967a7 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/checkers/simple.kt @@ -0,0 +1,13 @@ +fun dummy(x: Int) { + +} + +class A { + fun dummy() { + + } +} + +class B { + val dummy: Int = 1 +} \ No newline at end of file diff --git a/plugins/fir/fir-plugin-prototype/testData/checkers/simple.txt b/plugins/fir/fir-plugin-prototype/testData/checkers/simple.txt new file mode 100644 index 00000000000..3ea85c53abc --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/checkers/simple.txt @@ -0,0 +1,21 @@ +FILE: simple.kt + public final fun dummy(x: R|kotlin/Int|): R|kotlin/Unit| { + } + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final fun dummy(): R|kotlin/Unit| { + } + + } + public final class B : R|kotlin/Any| { + public constructor(): R|B| { + super() + } + + public final val dummy: R|kotlin/Int| = Int(1) + public get(): R|kotlin/Int| + + } diff --git a/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java b/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java index 19f6398605f..836dcc5e4a1 100644 --- a/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java +++ b/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java @@ -28,6 +28,24 @@ public class FirAllOpenDiagnosticTestGenerated extends AbstractFirAllOpenDiagnos KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @TestMetadata("plugins/fir/fir-plugin-prototype/testData/checkers") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Checkers extends AbstractFirAllOpenDiagnosticTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInCheckers() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/checkers"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("plugins/fir/fir-plugin-prototype/testData/checkers/simple.kt"); + } + } + @TestMetadata("plugins/fir/fir-plugin-prototype/testData/classGen") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)