[FIR-PLUGIN] Move fir plugin prototype out from :compiler module
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(project(":compiler:fir:cones"))
|
||||
compile(project(":compiler:fir:tree"))
|
||||
compile(project(":compiler:fir:resolve"))
|
||||
compile(project(":compiler:frontend"))
|
||||
|
||||
compileOnly(project(":kotlin-reflect-api"))
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core", "guava", rootProject = rootProject) }
|
||||
|
||||
testCompile(intellijDep())
|
||||
|
||||
testCompile(commonDep("junit:junit"))
|
||||
testCompileOnly(project(":kotlin-test:kotlin-test-jvm"))
|
||||
testCompileOnly(project(":kotlin-test:kotlin-test-junit"))
|
||||
testCompile(projectTests(":compiler:tests-common"))
|
||||
testCompile(project(":compiler:fir:checkers"))
|
||||
testCompile(projectTests(":compiler:fir:analysis-tests"))
|
||||
testCompile(project(":compiler:frontend"))
|
||||
|
||||
testCompileOnly(project(":kotlin-reflect-api"))
|
||||
testRuntime(project(":kotlin-reflect"))
|
||||
testRuntime(project(":core:descriptors.runtime"))
|
||||
|
||||
Platform[192].orHigher {
|
||||
testCompileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
testRuntimeOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
projectTest(parallel = true) {
|
||||
workingDir = rootDir
|
||||
jvmArgs!!.removeIf { it.contains("-Xmx") }
|
||||
maxHeapSize = "3g"
|
||||
dependsOn(":plugins:fir:fir-plugin-prototype:plugin-annotations:jar")
|
||||
}
|
||||
|
||||
testsJar()
|
||||
@@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { none() }
|
||||
}
|
||||
|
||||
publish()
|
||||
runtimeJar()
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
annotation class AllOpen
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
annotation class WithClass
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
org.jetbrains.kotlin.fir.plugin.FirAllOpenComponentRegistrar
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.FirEffectiveVisibilityImpl
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildClassImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
||||
import org.jetbrains.kotlin.fir.extensions.AnnotationFqn
|
||||
import org.jetbrains.kotlin.fir.extensions.FirClassGenerationExtension
|
||||
import org.jetbrains.kotlin.fir.resolve.firProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class AllOpenClassGenerator(session: FirSession) : FirClassGenerationExtension(session) {
|
||||
override fun <T> generateClass(
|
||||
containingFile: FirFile,
|
||||
annotatedDeclaration: T
|
||||
): List<GeneratedClass> where T : FirDeclaration, T : FirAnnotationContainer {
|
||||
if (annotatedDeclaration !is FirRegularClass) return emptyList()
|
||||
val klass = buildClassImpl {
|
||||
session = this@AllOpenClassGenerator.session
|
||||
origin = FirDeclarationOrigin.Plugin(AllOpenPluginKey)
|
||||
status = FirResolvedDeclarationStatusImpl(Visibilities.PUBLIC, FirEffectiveVisibilityImpl.Public, Modality.FINAL)
|
||||
classKind = ClassKind.OBJECT
|
||||
scopeProvider = (session.firProvider as FirProviderImpl).kotlinScopeProvider
|
||||
name = Name.identifier("Foo${annotatedDeclaration.name.identifier}")
|
||||
symbol = FirRegularClassSymbol(ClassId(containingFile.packageFqName, name))
|
||||
superTypeRefs += session.builtinTypes.anyType
|
||||
}
|
||||
return listOf(GeneratedClass(klass, containingFile))
|
||||
}
|
||||
|
||||
override val directlyApplicableAnnotations: Set<AnnotationFqn> = setOf(FqName("org.jetbrains.kotlin.fir.plugin.WithClass"))
|
||||
|
||||
override val childrenApplicableAnnotations: Set<AnnotationFqn>
|
||||
get() = emptySet()
|
||||
|
||||
override val metaAnnotations: Map<AnnotationFqn, MetaAnnotationMode>
|
||||
get() = emptyMap()
|
||||
|
||||
override val key: FirPluginKey
|
||||
get() = AllOpenPluginKey
|
||||
}
|
||||
+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.plugin
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirPluginKey
|
||||
|
||||
object AllOpenPluginKey : FirPluginKey()
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.descriptors.Modality
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus
|
||||
import org.jetbrains.kotlin.fir.declarations.FirPluginKey
|
||||
import org.jetbrains.kotlin.fir.extensions.AnnotationFqn
|
||||
import org.jetbrains.kotlin.fir.extensions.FirStatusTransformerExtension
|
||||
import org.jetbrains.kotlin.fir.extensions.transform
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class AllOpenStatusTransformer(session: FirSession) : FirStatusTransformerExtension(session) {
|
||||
companion object {
|
||||
private val ALL_OPEN = FqName("org.jetbrains.kotlin.fir.plugin.AllOpen")
|
||||
}
|
||||
|
||||
override fun transformStatus(declaration: FirDeclaration, status: FirDeclarationStatus): FirDeclarationStatus {
|
||||
if (status.modality != null) return status
|
||||
return status.transform(modality = Modality.OPEN)
|
||||
}
|
||||
|
||||
override val mode: Mode
|
||||
get() = Mode.ANNOTATED_ELEMENT
|
||||
|
||||
override val directlyApplicableAnnotations: Set<AnnotationFqn>
|
||||
get() = setOf(ALL_OPEN)
|
||||
|
||||
override val childrenApplicableAnnotations: Set<AnnotationFqn>
|
||||
get() = setOf(ALL_OPEN)
|
||||
|
||||
override val metaAnnotations: Map<AnnotationFqn, MetaAnnotationMode>
|
||||
get() = mapOf(ALL_OPEN to MetaAnnotationMode.ANNOTATED_AND_CHILDREN)
|
||||
|
||||
override val key: FirPluginKey
|
||||
get() = AllOpenPluginKey
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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.extensions.FirExtensionRegistrar
|
||||
|
||||
class FirAllOpenComponentRegistrar : FirExtensionRegistrar() {
|
||||
override fun ExtensionRegistrarContext.configurePlugin() {
|
||||
+::AllOpenStatusTransformer
|
||||
+::AllOpenClassGenerator
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import org.jetbrains.kotlin.fir.plugin.WithClass
|
||||
import org.jetbrains.kotlin.fir.plugin.AllOpen
|
||||
|
||||
@WithClass
|
||||
class A {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
FILE: simple.kt
|
||||
@R|org/jetbrains/kotlin/fir/plugin/WithClass|() public final class A : R|kotlin/Any| {
|
||||
public constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public final object FooA : R|kotlin/Any| {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import org.jetbrains.kotlin.fir.plugin.AllOpen
|
||||
|
||||
@Open
|
||||
class A {
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Open
|
||||
class B : A() {
|
||||
override fun foo() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@AllOpen
|
||||
annotation class Open
|
||||
@@ -0,0 +1,25 @@
|
||||
FILE: metaAnnotation.kt
|
||||
@R|Open|() public open class A : R|kotlin/Any| {
|
||||
public constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public open fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
@R|Open|() public open class B : R|A| {
|
||||
public constructor(): R|B| {
|
||||
super<R|A|>()
|
||||
}
|
||||
|
||||
public open override fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
@R|org/jetbrains/kotlin/fir/plugin/AllOpen|() public open annotation class Open : R|kotlin/Annotation| {
|
||||
public constructor(): R|Open| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.jetbrains.kotlin.fir.plugin.AllOpen
|
||||
|
||||
@AllOpen
|
||||
class A {
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@AllOpen
|
||||
class B : A() {
|
||||
override fun foo() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
FILE: simpleAnnotation.kt
|
||||
@R|org/jetbrains/kotlin/fir/plugin/AllOpen|() public open class A : R|kotlin/Any| {
|
||||
public constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public open fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
@R|org/jetbrains/kotlin/fir/plugin/AllOpen|() public open class B : R|A| {
|
||||
public constructor(): R|B| {
|
||||
super<R|A|>()
|
||||
}
|
||||
|
||||
public open override fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.cli.jvm.config.addJvmClasspathRoot
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.fir.AbstractFirDiagnosticsTest
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionsService
|
||||
import org.jetbrains.kotlin.fir.extensions.registerExtensions
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractFirAllOpenDiagnosticTest : AbstractFirDiagnosticsTest() {
|
||||
override fun registerFirExtensions(service: FirExtensionsService) {
|
||||
service.registerExtensions(FirAllOpenComponentRegistrar().configure())
|
||||
}
|
||||
|
||||
override fun performCustomConfiguration(configuration: CompilerConfiguration) {
|
||||
super.performCustomConfiguration(configuration)
|
||||
configuration.addJvmClasspathRoot(File("plugins/fir/fir-plugin-prototype/plugin-annotations/build/libs/plugin-annotations-1.4.255-SNAPSHOT.jar"))
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 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("plugins/fir/fir-plugin-prototype/testData")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class FirAllOpenDiagnosticTestGenerated extends AbstractFirAllOpenDiagnosticTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInTestData() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("plugins/fir/fir-plugin-prototype/testData/classGen")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ClassGen extends AbstractFirAllOpenDiagnosticTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInClassGen() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/classGen"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("plugins/fir/fir-plugin-prototype/testData/classGen/simple.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("plugins/fir/fir-plugin-prototype/testData/status")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Status extends AbstractFirAllOpenDiagnosticTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInStatus() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/status"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("metaAnnotation.kt")
|
||||
public void testMetaAnnotation() throws Exception {
|
||||
runTest("plugins/fir/fir-plugin-prototype/testData/status/metaAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleAnnotation.kt")
|
||||
public void testSimpleAnnotation() throws Exception {
|
||||
runTest("plugins/fir/fir-plugin-prototype/testData/status/simpleAnnotation.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user