[FIR] Rename annotations in plugin prototype so they have meaningful names

This commit is contained in:
Dmitriy Novozhilov
2021-12-01 15:20:35 +03:00
committed by TeamCityServer
parent a760c31b22
commit 974150a9d8
28 changed files with 58 additions and 63 deletions
@@ -6,17 +6,12 @@
package org.jetbrains.kotlin.fir.plugin package org.jetbrains.kotlin.fir.plugin
annotation class AllOpen annotation class AllOpen
annotation class WithGenerated
annotation class WithHello
annotation class WithNestedFoo
annotation class A annotation class DummyFunction
annotation class B annotation class ExternalClassWithNested
annotation class C annotation class NestedClassAndMaterializeMember
annotation class D annotation class MyInterfaceSupertype
annotation class E annotation class CompanionWithFoo
annotation class F
annotation class G
annotation class AllPublic(val visibility: Visibility) annotation class AllPublic(val visibility: Visibility)
@@ -21,12 +21,12 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
/* /*
* Adds MyInterface supertype for all classes annotated with @D * Adds MyInterface supertype for all classes annotated with @MyInterfaceSupertype
*/ */
class SomeAdditionalSupertypeGenerator(session: FirSession) : FirSupertypeGenerationExtension(session) { class SomeAdditionalSupertypeGenerator(session: FirSession) : FirSupertypeGenerationExtension(session) {
companion object { companion object {
private val myInterfaceClassId = ClassId(FqName("foo"), Name.identifier("MyInterface")) private val myInterfaceClassId = ClassId(FqName("foo"), Name.identifier("MyInterface"))
private val PREDICATE: DeclarationPredicate = has("D".fqn()) private val PREDICATE: DeclarationPredicate = has("MyInterfaceSupertype".fqn())
} }
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.name.SpecialNames
/* /*
* For each class annotated with @C generates * For each class annotated with @NestedClassAndMaterializeMember generates
* - member fun materialize(): ClassName * - member fun materialize(): ClassName
* - nested class Nested with default constructor * - nested class Nested with default constructor
*/ */
@@ -37,7 +37,7 @@ class AdditionalMembersGenerator(session: FirSession) : FirDeclarationGeneration
private val MATERIALIZE_NAME = Name.identifier("materialize") private val MATERIALIZE_NAME = Name.identifier("materialize")
private val NESTED_NAME = Name.identifier("Nested") private val NESTED_NAME = Name.identifier("Nested")
private val PREDICATE: DeclarationPredicate = has("C".fqn()) private val PREDICATE: DeclarationPredicate = has("NestedClassAndMaterializeMember".fqn())
} }
private val predicateBasedProvider = session.predicateBasedProvider private val predicateBasedProvider = session.predicateBasedProvider
@@ -33,11 +33,11 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.name.SpecialNames
/* /*
* Generates companion object with fun foo(): Int for each class annotated with @E * Generates companion object with fun foo(): Int for each class annotated with @CompanionWithFoo
*/ */
class CompanionGenerator(session: FirSession) : FirDeclarationGenerationExtension(session) { class CompanionGenerator(session: FirSession) : FirDeclarationGenerationExtension(session) {
companion object { companion object {
private val PREDICATE = has("E".fqn()) private val PREDICATE = has("CompanionWithFoo".fqn())
private val FOO_NAME = Name.identifier("foo") private val FOO_NAME = Name.identifier("foo")
} }
@@ -29,8 +29,8 @@ import org.jetbrains.kotlin.name.*
/* /*
* Generates class /foo.AllOpenGenerated with * Generates class /foo.AllOpenGenerated with
* - empty public constructor * - empty public constructor
* - testClassName() functions for all classes annotated with @B * - testClassName() functions for all classes annotated with @ExternalClassWithNested
* - NestedClassName nested classes for all classes annotated with @B * - NestedClassName nested classes for all classes annotated with @ExternalClassWithNested
* - function `materialize: ClassName` in those nested classes * - function `materialize: ClassName` in those nested classes
* *
* If there are no annotated classes then AllOpenGenerated class is not generated * If there are no annotated classes then AllOpenGenerated class is not generated
@@ -41,7 +41,7 @@ class ExternalClassGenerator(session: FirSession) : FirDeclarationGenerationExte
private val GENERATED_CLASS_ID = ClassId(FOO_PACKAGE, Name.identifier("AllOpenGenerated")) private val GENERATED_CLASS_ID = ClassId(FOO_PACKAGE, Name.identifier("AllOpenGenerated"))
private val MATERIALIZE_NAME = Name.identifier("materialize") private val MATERIALIZE_NAME = Name.identifier("materialize")
private val PREDICATE: DeclarationPredicate = has("B".fqn()) private val PREDICATE: DeclarationPredicate = has("ExternalClassWithNested".fqn())
} }
object Key : FirPluginKey() { object Key : FirPluginKey() {
@@ -28,11 +28,11 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
/* /*
* Generates `dummyClassName(value: ClassName): String` function for each class annotated with @A * Generates `dummyClassName(value: ClassName): String` function for each class annotated with @DummyFunction
*/ */
class TopLevelDeclarationsGenerator(session: FirSession) : FirDeclarationGenerationExtension(session) { class TopLevelDeclarationsGenerator(session: FirSession) : FirDeclarationGenerationExtension(session) {
companion object { companion object {
private val PREDICATE: DeclarationPredicate = has("A".fqn()) private val PREDICATE: DeclarationPredicate = has("DummyFunction".fqn())
} }
private val predicateBasedProvider = session.predicateBasedProvider private val predicateBasedProvider = session.predicateBasedProvider
@@ -1,7 +1,7 @@
FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt
CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any] CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]
annotations: annotations:
B ExternalClassWithNested
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:bar.Foo $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:bar.Foo
CONSTRUCTOR visibility:public <> () returnType:bar.Foo [primary] CONSTRUCTOR visibility:public <> () returnType:bar.Foo [primary]
BLOCK_BODY BLOCK_BODY
@@ -1,7 +1,7 @@
FILE: generatedClassWithMembersAndNestedClasses.kt FILE: generatedClassWithMembersAndNestedClasses.kt
package bar package bar
@R|org/jetbrains/kotlin/fir/plugin/B|() public final class Foo : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/ExternalClassWithNested|() public final class Foo : R|kotlin/Any| {
public constructor(): R|bar/Foo| { public constructor(): R|bar/Foo| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -2,9 +2,9 @@
package bar package bar
import foo.AllOpenGenerated import foo.AllOpenGenerated
import org.jetbrains.kotlin.fir.plugin.B import org.jetbrains.kotlin.fir.plugin.ExternalClassWithNested
@B @ExternalClassWithNested
class Foo { class Foo {
fun box(): String { fun box(): String {
return "OK" return "OK"
@@ -1,5 +1,5 @@
FILE: classWithCompanionObject.kt FILE: classWithCompanionObject.kt
@R|org/jetbrains/kotlin/fir/plugin/E|() public final class SomeClass : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/CompanionWithFoo|() public final class SomeClass : R|kotlin/Any| {
public constructor(): R|SomeClass| { public constructor(): R|SomeClass| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -1,6 +1,6 @@
import org.jetbrains.kotlin.fir.plugin.E import org.jetbrains.kotlin.fir.plugin.CompanionWithFoo
@E @CompanionWithFoo
class SomeClass class SomeClass
fun takeInt(x: Int) {} fun takeInt(x: Int) {}
@@ -1,5 +1,5 @@
FILE: classWithGeneratedMembersAndNestedClass.kt FILE: classWithGeneratedMembersAndNestedClass.kt
@R|org/jetbrains/kotlin/fir/plugin/C|() public final class Foo : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/NestedClassAndMaterializeMember|() public final class Foo : R|kotlin/Any| {
public constructor(): R|Foo| { public constructor(): R|Foo| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -1,6 +1,6 @@
import org.jetbrains.kotlin.fir.plugin.C import org.jetbrains.kotlin.fir.plugin.NestedClassAndMaterializeMember
@C @NestedClassAndMaterializeMember
class Foo { class Foo {
class MyNested class MyNested
} }
@@ -1,7 +1,7 @@
FILE: generatedClassWithMembersAndNestedClasses.kt FILE: generatedClassWithMembersAndNestedClasses.kt
package bar package bar
@R|org/jetbrains/kotlin/fir/plugin/B|() public final class Foo : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/ExternalClassWithNested|() public final class Foo : R|kotlin/Any| {
public constructor(): R|bar/Foo| { public constructor(): R|bar/Foo| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -10,7 +10,7 @@ FILE: generatedClassWithMembersAndNestedClasses.kt
} }
} }
@R|org/jetbrains/kotlin/fir/plugin/B|() public final class Bar : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/ExternalClassWithNested|() public final class Bar : R|kotlin/Any| {
public constructor(): R|bar/Bar| { public constructor(): R|bar/Bar| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -1,14 +1,14 @@
package bar package bar
import foo.AllOpenGenerated import foo.AllOpenGenerated
import org.jetbrains.kotlin.fir.plugin.B import org.jetbrains.kotlin.fir.plugin.ExternalClassWithNested
@B @ExternalClassWithNested
class Foo { class Foo {
fun foo() {} fun foo() {}
} }
@B @ExternalClassWithNested
class Bar { class Bar {
fun bar() {} fun bar() {}
} }
@@ -1,7 +1,7 @@
FILE: topLevelCallables.kt FILE: topLevelCallables.kt
package foo package foo
@R|org/jetbrains/kotlin/fir/plugin/A|() public final class MySuperClass : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/DummyFunction|() public final class MySuperClass : R|kotlin/Any| {
public constructor(): R|foo/MySuperClass| { public constructor(): R|foo/MySuperClass| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -1,8 +1,8 @@
package foo package foo
import org.jetbrains.kotlin.fir.plugin.A import org.jetbrains.kotlin.fir.plugin.DummyFunction
@A @DummyFunction
class MySuperClass { class MySuperClass {
fun test() { fun test() {
val s = dummyMySuperClass(this) val s = dummyMySuperClass(this)
@@ -5,13 +5,13 @@ FILE: simple.kt
public abstract fun foo(): R|kotlin/Unit| public abstract fun foo(): R|kotlin/Unit|
} }
@R|org/jetbrains/kotlin/fir/plugin/D|() public abstract class AbstractClass : R|kotlin/Any|, R|foo/MyInterface| { @R|org/jetbrains/kotlin/fir/plugin/MyInterfaceSupertype|() public abstract class AbstractClass : R|kotlin/Any|, R|foo/MyInterface| {
public constructor(): R|foo/AbstractClass| { public constructor(): R|foo/AbstractClass| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
} }
@R|org/jetbrains/kotlin/fir/plugin/D|() public final class FinalClassWithOverride : R|kotlin/Any|, R|foo/MyInterface| { @R|org/jetbrains/kotlin/fir/plugin/MyInterfaceSupertype|() public final class FinalClassWithOverride : R|kotlin/Any|, R|foo/MyInterface| {
public constructor(): R|foo/FinalClassWithOverride| { public constructor(): R|foo/FinalClassWithOverride| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -20,7 +20,7 @@ FILE: simple.kt
} }
} }
@R|org/jetbrains/kotlin/fir/plugin/D|() public final class FinalClassWithoutOverride : R|kotlin/Any|, R|foo/MyInterface| { @R|org/jetbrains/kotlin/fir/plugin/MyInterfaceSupertype|() public final class FinalClassWithoutOverride : R|kotlin/Any|, R|foo/MyInterface| {
public constructor(): R|foo/FinalClassWithoutOverride| { public constructor(): R|foo/FinalClassWithoutOverride| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -35,7 +35,7 @@ FILE: simple.kt
} }
} }
@R|org/jetbrains/kotlin/fir/plugin/D|() public final class AnnotatedClassWithExplicitInheritance : R|foo/MyInterface| { @R|org/jetbrains/kotlin/fir/plugin/MyInterfaceSupertype|() public final class AnnotatedClassWithExplicitInheritance : R|foo/MyInterface| {
public constructor(): R|foo/AnnotatedClassWithExplicitInheritance| { public constructor(): R|foo/AnnotatedClassWithExplicitInheritance| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -1,20 +1,20 @@
package foo package foo
import org.jetbrains.kotlin.fir.plugin.D import org.jetbrains.kotlin.fir.plugin.MyInterfaceSupertype
interface MyInterface { interface MyInterface {
fun foo() fun foo()
} }
@D @MyInterfaceSupertype
abstract class AbstractClass abstract class AbstractClass
@D @MyInterfaceSupertype
class FinalClassWithOverride { class FinalClassWithOverride {
override fun foo() {} override fun foo() {}
} }
@D @MyInterfaceSupertype
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class FinalClassWithoutOverride<!> { <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class FinalClassWithoutOverride<!> {
// should be error // should be error
} }
@@ -24,7 +24,7 @@ class NotAnnotatedWithOverride {
<!NOTHING_TO_OVERRIDE!>override<!> fun foo() {} <!NOTHING_TO_OVERRIDE!>override<!> fun foo() {}
} }
@D @MyInterfaceSupertype
class AnnotatedClassWithExplicitInheritance : MyInterface { class AnnotatedClassWithExplicitInheritance : MyInterface {
override fun foo() {} override fun foo() {}
} }
@@ -1,7 +1,7 @@
FILE fqName:<root> fileName:/classWithGeneratedMembersAndNestedClass.kt FILE fqName:<root> fileName:/classWithGeneratedMembersAndNestedClass.kt
CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any] CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]
annotations: annotations:
C NestedClassAndMaterializeMember
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Foo $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Foo
CONSTRUCTOR visibility:public <> () returnType:<root>.Foo [primary] CONSTRUCTOR visibility:public <> () returnType:<root>.Foo [primary]
BLOCK_BODY BLOCK_BODY
@@ -1,5 +1,5 @@
FILE: classWithGeneratedMembersAndNestedClass.kt FILE: classWithGeneratedMembersAndNestedClass.kt
@R|org/jetbrains/kotlin/fir/plugin/C|() public final class Foo : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/NestedClassAndMaterializeMember|() public final class Foo : R|kotlin/Any| {
public constructor(): R|Foo| { public constructor(): R|Foo| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -1,6 +1,6 @@
import org.jetbrains.kotlin.fir.plugin.C import org.jetbrains.kotlin.fir.plugin.NestedClassAndMaterializeMember
@C @NestedClassAndMaterializeMember
class Foo { class Foo {
class MyNested class MyNested
} }
@@ -1,7 +1,7 @@
FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt
CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any] CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]
annotations: annotations:
B ExternalClassWithNested
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:bar.Foo $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:bar.Foo
CONSTRUCTOR visibility:public <> () returnType:bar.Foo [primary] CONSTRUCTOR visibility:public <> () returnType:bar.Foo [primary]
BLOCK_BODY BLOCK_BODY
@@ -25,7 +25,7 @@ FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt
$this: VALUE_PARAMETER name:<this> type:kotlin.Any $this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any] CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any]
annotations: annotations:
B ExternalClassWithNested
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:bar.Bar $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:bar.Bar
CONSTRUCTOR visibility:public <> () returnType:bar.Bar [primary] CONSTRUCTOR visibility:public <> () returnType:bar.Bar [primary]
BLOCK_BODY BLOCK_BODY
@@ -1,7 +1,7 @@
FILE: generatedClassWithMembersAndNestedClasses.kt FILE: generatedClassWithMembersAndNestedClasses.kt
package bar package bar
@R|org/jetbrains/kotlin/fir/plugin/B|() public final class Foo : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/ExternalClassWithNested|() public final class Foo : R|kotlin/Any| {
public constructor(): R|bar/Foo| { public constructor(): R|bar/Foo| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -10,7 +10,7 @@ FILE: generatedClassWithMembersAndNestedClasses.kt
} }
} }
@R|org/jetbrains/kotlin/fir/plugin/B|() public final class Bar : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/ExternalClassWithNested|() public final class Bar : R|kotlin/Any| {
public constructor(): R|bar/Bar| { public constructor(): R|bar/Bar| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -1,14 +1,14 @@
package bar package bar
import foo.AllOpenGenerated import foo.AllOpenGenerated
import org.jetbrains.kotlin.fir.plugin.B import org.jetbrains.kotlin.fir.plugin.ExternalClassWithNested
@B @ExternalClassWithNested
class Foo { class Foo {
fun foo() {} fun foo() {}
} }
@B @ExternalClassWithNested
class Bar { class Bar {
fun bar() {} fun bar() {}
} }
@@ -1,7 +1,7 @@
FILE fqName:foo fileName:/topLevelCallables.kt FILE fqName:foo fileName:/topLevelCallables.kt
CLASS CLASS name:MySuperClass modality:FINAL visibility:public superTypes:[kotlin.Any] CLASS CLASS name:MySuperClass modality:FINAL visibility:public superTypes:[kotlin.Any]
annotations: annotations:
A DummyFunction
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.MySuperClass $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.MySuperClass
CONSTRUCTOR visibility:public <> () returnType:foo.MySuperClass [primary] CONSTRUCTOR visibility:public <> () returnType:foo.MySuperClass [primary]
BLOCK_BODY BLOCK_BODY
@@ -1,7 +1,7 @@
FILE: topLevelCallables.kt FILE: topLevelCallables.kt
package foo package foo
@R|org/jetbrains/kotlin/fir/plugin/A|() public final class MySuperClass : R|kotlin/Any| { @R|org/jetbrains/kotlin/fir/plugin/DummyFunction|() public final class MySuperClass : R|kotlin/Any| {
public constructor(): R|foo/MySuperClass| { public constructor(): R|foo/MySuperClass| {
super<R|kotlin/Any|>() super<R|kotlin/Any|>()
} }
@@ -1,8 +1,8 @@
package foo package foo
import org.jetbrains.kotlin.fir.plugin.A import org.jetbrains.kotlin.fir.plugin.DummyFunction
@A @DummyFunction
class MySuperClass { class MySuperClass {
fun test() { fun test() {
val s = dummyMySuperClass(this) val s = dummyMySuperClass(this)