mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] J2K: Add a getter use-site target on annotated annotation methods
Unless it's a type use annotation. The use site target enum is adapted from org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget. ^KTIJ-8880 Fixed GitOrigin-RevId: 619925a52c6e9e5cb26f6fe38e9f06027b5e7e8e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d2618da5bb
commit
b2e183537b
+2
-1
@@ -6,6 +6,7 @@ import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||
import org.jetbrains.kotlin.nj2k.toExpression
|
||||
import org.jetbrains.kotlin.nj2k.tree.*
|
||||
import org.jetbrains.kotlin.nj2k.tree.JKAnnotation.UseSiteTarget.PROPERTY_GETTER
|
||||
|
||||
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
||||
import org.jetbrains.kotlin.nj2k.types.isArrayType
|
||||
@@ -54,7 +55,7 @@ class AnnotationClassConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
||||
) {
|
||||
JKKtAnnotationArrayInitializerExpression(initializer)
|
||||
} else initializer,
|
||||
annotationList = this::annotationList.detached(),
|
||||
annotationList = ::annotationList.detached().also { it.annotations.forEach { ann -> ann.useSiteTarget = PROPERTY_GETTER } },
|
||||
).also { parameter ->
|
||||
parameter.trailingComments += trailingComments
|
||||
parameter.leadingComments += leadingComments
|
||||
|
||||
@@ -802,6 +802,7 @@ internal class JKCodeBuilder(context: NewJ2kConverterContext) {
|
||||
|
||||
override fun visitAnnotationRaw(annotation: JKAnnotation) {
|
||||
printer.print("@")
|
||||
annotation.useSiteTarget?.let { printer.print("${it.renderName}:") }
|
||||
printer.renderSymbol(annotation.classSymbol, annotation)
|
||||
if (annotation.arguments.isNotEmpty()) {
|
||||
printer.par {
|
||||
|
||||
@@ -4,7 +4,6 @@ package org.jetbrains.kotlin.nj2k.tree
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||
|
||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
||||
import org.jetbrains.kotlin.nj2k.types.JKType
|
||||
|
||||
@@ -157,10 +156,26 @@ class JKAnnotationList(annotations: List<JKAnnotation> = emptyList()) : JKTreeEl
|
||||
|
||||
class JKAnnotation(
|
||||
var classSymbol: JKClassSymbol,
|
||||
arguments: List<JKAnnotationParameter> = emptyList()
|
||||
arguments: List<JKAnnotationParameter> = emptyList(),
|
||||
var useSiteTarget: UseSiteTarget? = null
|
||||
) : JKAnnotationMemberValue() {
|
||||
var arguments: List<JKAnnotationParameter> by children(arguments)
|
||||
override fun accept(visitor: JKVisitor) = visitor.visitAnnotation(this)
|
||||
|
||||
@Suppress("unused")
|
||||
enum class UseSiteTarget(renderName: String? = null) {
|
||||
FIELD,
|
||||
FILE,
|
||||
PROPERTY,
|
||||
PROPERTY_GETTER("get"),
|
||||
PROPERTY_SETTER("set"),
|
||||
RECEIVER,
|
||||
CONSTRUCTOR_PARAMETER("param"),
|
||||
SETTER_PARAMETER("setparam"),
|
||||
PROPERTY_DELEGATE_FIELD("delegate");
|
||||
|
||||
val renderName: String = renderName ?: name.lowercase()
|
||||
}
|
||||
}
|
||||
|
||||
class JKTypeArgumentList(typeArguments: List<JKTypeElement> = emptyList()) : JKTreeElement(), PsiOwner by PsiOwnerImpl() {
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
@interface NonNls {}
|
||||
@interface Ann {}
|
||||
|
||||
@interface Foo {
|
||||
@NonNls String value();
|
||||
@NonNls String value2() default "test";
|
||||
@Ann String value();
|
||||
@Ann String value2() default "test";
|
||||
}
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
internal annotation class NonNls
|
||||
internal annotation class Foo(@NonNls val value: String, @NonNls val value2: String = "test")
|
||||
internal annotation class Ann
|
||||
internal annotation class Foo(@get:Ann val value: String, @get:Ann val value2: String = "test")
|
||||
|
||||
Reference in New Issue
Block a user