[ULC] support repeatable annotation and container

^KTIJ-19318
This commit is contained in:
Dmitry Gridin
2021-09-07 15:37:29 +07:00
committed by Space
parent a3d60f8ed2
commit 11e71e4e27
18 changed files with 290 additions and 44 deletions
@@ -0,0 +1,96 @@
/*
* Copyright 2010-2021 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.asJava.classes
import com.intellij.psi.*
import com.intellij.psi.impl.light.LightMethodBuilder
import com.intellij.psi.impl.light.LightModifierList
import com.intellij.psi.impl.light.LightParameterListBuilder
import com.intellij.util.IncorrectOperationException
import org.jetbrains.kotlin.asJava.elements.*
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.KtClassOrObject
class KtUltraLightClassForRepeatableAnnotationContainer(classOrObject: KtClassOrObject, support: KtUltraLightSupport) :
KtUltraLightClass(classOrObject, support) {
override fun getQualifiedName(): String? = containingClass?.qualifiedName?.let { "$it.${JvmAbi.REPEATABLE_ANNOTATION_CONTAINER_NAME}" }
override fun getName() = JvmAbi.REPEATABLE_ANNOTATION_CONTAINER_NAME
override fun getParent() = containingClass
override fun getTypeParameterList(): PsiTypeParameterList? = null
override fun getTypeParameters(): Array<PsiTypeParameter> = emptyArray()
override fun getContainingClass(): KtLightClassForSourceDeclaration? = create(classOrObject, jvmDefaultMode)
override fun getScope(): PsiElement? = containingClass
override fun getOwnInnerClasses() = emptyList<PsiClass>()
override fun getOwnFields(): List<KtLightField> = emptyList()
override fun getOwnMethods(): List<KtLightMethod> = _ownMethods
override fun getModifierList(): PsiModifierList? = _modifierList
override fun isInterface(): Boolean = true
override fun isDeprecated(): Boolean = false
override fun isAnnotationType(): Boolean = true
override fun isEnum(): Boolean = false
override fun isFinal(isFinalByPsi: Boolean): Boolean = false
override fun hasTypeParameters(): Boolean = false
override fun copy(): KtUltraLightClassForRepeatableAnnotationContainer = KtUltraLightClassForRepeatableAnnotationContainer(
classOrObject.copy() as KtClassOrObject,
support,
)
private val _modifierList: PsiModifierList? by lazyPub {
KtUltraLightModifierListForRepeatableAnnotationContainer(this, support)
}
override fun isInheritor(baseClass: PsiClass, checkDeep: Boolean): Boolean =
baseClass.qualifiedName == CommonClassNames.JAVA_LANG_ANNOTATION_ANNOTATION
override fun setName(name: String): PsiElement =
throw IncorrectOperationException("Impossible to rename ${JvmAbi.REPEATABLE_ANNOTATION_CONTAINER_NAME}")
private val _ownMethods: List<KtLightMethod> by lazyPub {
val lightMethodBuilder = LightMethodBuilder(
manager, language, "value",
LightParameterListBuilder(manager, language),
LightModifierList(manager, language, PsiModifier.PUBLIC, PsiModifier.ABSTRACT)
)
lightMethodBuilder.setMethodReturnType {
val qualifier = containingClass?.qualifiedName ?: return@setMethodReturnType null
JavaPsiFacade.getElementFactory(project).createTypeByFQClassName(qualifier, resolveScope).createArrayType()
}
listOf(
KtUltraLightMethodForSourceDeclaration(
delegate = lightMethodBuilder,
lightMemberOrigin = null,
support = support,
containingClass = this,
forceToSkipNullabilityAnnotation = false,
methodIndex = METHOD_INDEX_FOR_NON_ORIGIN_METHOD,
)
)
}
}
private class KtUltraLightModifierListForRepeatableAnnotationContainer(
private val containingClass: KtLightClassForSourceDeclaration,
support: KtUltraLightSupport,
) : KtUltraLightModifierList<KtLightClassForSourceDeclaration>(containingClass, support) {
override fun hasModifierProperty(name: String): Boolean = name == PsiModifier.PUBLIC
override fun copy() = KtUltraLightModifierListForRepeatableAnnotationContainer(containingClass, support)
override fun PsiAnnotation.additionalConverter(): KtLightAbstractAnnotation? = tryConvertAsRepeatableContainer(support)
override val annotationsFilter: ((KtLightAbstractAnnotation) -> Boolean) = { it.qualifiedName in allowedAnnotations }
companion object {
private val allowedAnnotations = setOf(
KOTLIN_JVM_INTERNAL_REPEATABLE_CONTAINER,
CommonClassNames.JAVA_LANG_ANNOTATION_RETENTION,
StandardNames.FqNames.retention.asString(),
CommonClassNames.JAVA_LANG_ANNOTATION_TARGET,
StandardNames.FqNames.target.asString(),
)
}
}
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2021 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -22,9 +22,9 @@ import org.jetbrains.kotlin.asJava.elements.KtUltraLightModifierList
import org.jetbrains.kotlin.backend.common.CodegenUtil import org.jetbrains.kotlin.backend.common.CodegenUtil
import org.jetbrains.kotlin.backend.common.DataClassMethodGenerator import org.jetbrains.kotlin.backend.common.DataClassMethodGenerator
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.codegen.JvmCodegenUtil import org.jetbrains.kotlin.codegen.JvmCodegenUtil
import org.jetbrains.kotlin.codegen.kotlinType import org.jetbrains.kotlin.codegen.kotlinType
import org.jetbrains.kotlin.config.AnalysisFlags
import org.jetbrains.kotlin.config.JvmAnalysisFlags import org.jetbrains.kotlin.config.JvmAnalysisFlags
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
@@ -52,10 +53,9 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
private class KtUltraLightClassModifierList( private class KtUltraLightClassModifierList(
private val containingClass: KtLightClassForSourceDeclaration, private val containingClass: KtLightClassForSourceDeclaration,
private val support: KtUltraLightSupport, support: KtUltraLightSupport,
private val computeModifiers: () -> Set<String> private val computeModifiers: () -> Set<String>
) : ) : KtUltraLightModifierList<KtLightClassForSourceDeclaration>(containingClass, support) {
KtUltraLightModifierList<KtLightClassForSourceDeclaration>(containingClass, support) {
private val modifiers by lazyPub { computeModifiers() } private val modifiers by lazyPub { computeModifiers() }
override fun hasModifierProperty(name: String): Boolean = override fun hasModifierProperty(name: String): Boolean =
@@ -103,7 +103,7 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
override fun createImplementsList(): PsiReferenceList? = createInheritanceList(forExtendsList = false) override fun createImplementsList(): PsiReferenceList? = createInheritanceList(forExtendsList = false)
private fun createInheritanceList(forExtendsList: Boolean): PsiReferenceList? { private fun createInheritanceList(forExtendsList: Boolean): PsiReferenceList {
val role = if (forExtendsList) PsiReferenceList.Role.EXTENDS_LIST else PsiReferenceList.Role.IMPLEMENTS_LIST val role = if (forExtendsList) PsiReferenceList.Role.EXTENDS_LIST else PsiReferenceList.Role.IMPLEMENTS_LIST
@@ -513,4 +513,16 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
return super.getTextRange() return super.getTextRange()
} }
override fun getOwnInnerClasses(): List<PsiClass> = super.getOwnInnerClasses().let { superOwnInnerClasses ->
if (shouldGenerateRepeatableAnnotationContainer) {
superOwnInnerClasses + KtUltraLightClassForRepeatableAnnotationContainer(classOrObject, support)
} else
superOwnInnerClasses
}
private val shouldGenerateRepeatableAnnotationContainer: Boolean
get() = isAnnotationType &&
classOrObject.hasAnnotation(StandardNames.FqNames.repeatable) &&
!classOrObject.hasAnnotation(JvmAnnotationNames.REPEATABLE_ANNOTATION)
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2021 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -17,7 +17,6 @@ import org.jetbrains.annotations.NotNull
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
import org.jetbrains.kotlin.asJava.elements.* import org.jetbrains.kotlin.asJava.elements.*
import org.jetbrains.kotlin.codegen.PropertyCodegen
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
@@ -34,7 +33,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
private class KtUltraLightFieldModifierList( private class KtUltraLightFieldModifierList(
private val support: KtUltraLightSupport, support: KtUltraLightSupport,
private val declaration: KtNamedDeclaration, private val declaration: KtNamedDeclaration,
owner: KtLightElement<KtModifierListOwner, PsiModifierListOwner>, owner: KtLightElement<KtModifierListOwner, PsiModifierListOwner>,
private val modifiers: Set<String>, private val modifiers: Set<String>,
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2021 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -25,7 +25,12 @@ abstract class KtLightModifierList<out T : KtLightElement<KtModifierListOwner, P
protected val owner: T protected val owner: T
) : KtLightElementBase(owner), PsiModifierList, KtLightElement<KtModifierList, PsiModifierList> { ) : KtLightElementBase(owner), PsiModifierList, KtLightElement<KtModifierList, PsiModifierList> {
override val clsDelegate by lazyPub { owner.clsDelegate.modifierList!! } override val clsDelegate by lazyPub { owner.clsDelegate.modifierList!! }
private val _annotations by lazyPub { computeAnnotations() } private val _annotations by lazyPub {
val annotations = computeAnnotations()
annotationsFilter?.let(annotations::filter) ?: annotations
}
protected open val annotationsFilter: ((KtLightAbstractAnnotation) -> Boolean)? = null
override val kotlinOrigin: KtModifierList? override val kotlinOrigin: KtModifierList?
get() = owner.kotlinOrigin?.modifierList get() = owner.kotlinOrigin?.modifierList
@@ -104,9 +109,11 @@ class KtUltraLightSimpleModifierList(
abstract class KtUltraLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>( abstract class KtUltraLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(
owner: T, owner: T,
private val support: KtUltraLightSupport protected val support: KtUltraLightSupport
) : KtUltraLightModifierListBase<T>(owner) { ) : KtUltraLightModifierListBase<T>(owner) {
protected open fun PsiAnnotation.additionalConverter(): KtLightAbstractAnnotation? = null
override fun nonSourceAnnotationsForAnnotationType(sourceAnnotations: List<PsiAnnotation>): List<KtLightAbstractAnnotation> { override fun nonSourceAnnotationsForAnnotationType(sourceAnnotations: List<PsiAnnotation>): List<KtLightAbstractAnnotation> {
if (sourceAnnotations.isEmpty()) return listOf(createRetentionRuntimeAnnotation(support, this)) if (sourceAnnotations.isEmpty()) return listOf(createRetentionRuntimeAnnotation(support, this))
@@ -114,12 +121,14 @@ abstract class KtUltraLightModifierList<out T : KtLightElement<KtModifierListOwn
return mutableListOf<KtLightAbstractAnnotation>().also { result -> return mutableListOf<KtLightAbstractAnnotation>().also { result ->
sourceAnnotations.mapNotNullTo(result) { sourceAnnotation -> sourceAnnotations.mapNotNullTo(result) { sourceAnnotation ->
sourceAnnotation.tryConvertAsTarget(support) sourceAnnotation.additionalConverter()
?: sourceAnnotation.tryConvertAsTarget(support)
?: sourceAnnotation.tryConvertAsRetention(support) ?: sourceAnnotation.tryConvertAsRetention(support)
?: sourceAnnotation.tryConvertAsRepeatable(support, owner)
?: sourceAnnotation.tryConvertAsMustBeDocumented(support) ?: sourceAnnotation.tryConvertAsMustBeDocumented(support)
} }
if (!result.any { it.qualifiedName == "java.lang.annotation.Retention" }) { if (!result.any { it.qualifiedName == CommonClassNames.JAVA_LANG_ANNOTATION_RETENTION }) {
result.add(createRetentionRuntimeAnnotation(support, this)) result.add(createRetentionRuntimeAnnotation(support, this))
} }
} }
@@ -1,27 +1,30 @@
/* /*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2021 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. * 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.asJava.elements package org.jetbrains.kotlin.asJava.elements
import com.intellij.psi.CommonClassNames.JAVA_LANG_ANNOTATION_RETENTION import com.intellij.psi.*
import com.intellij.psi.CommonClassNames.JAVA_LANG_ANNOTATION_TARGET import com.intellij.psi.CommonClassNames.*
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiArrayInitializerMemberValue
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiNameValuePair
import org.jetbrains.kotlin.asJava.classes.KtUltraLightSimpleAnnotation import org.jetbrains.kotlin.asJava.classes.KtUltraLightSimpleAnnotation
import org.jetbrains.kotlin.asJava.classes.KtUltraLightSupport import org.jetbrains.kotlin.asJava.classes.KtUltraLightSupport
import org.jetbrains.kotlin.builtins.StandardNames.FqNames import org.jetbrains.kotlin.builtins.StandardNames.FqNames
import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtModifierListOwner
import org.jetbrains.kotlin.resolve.constants.ArrayValue import org.jetbrains.kotlin.resolve.constants.ArrayValue
import org.jetbrains.kotlin.resolve.constants.EnumValue import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.resolve.constants.KClassValue
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.util.* import java.util.*
private const val JAVA_LANG_ANNOTATION_DOCUMENTED = "java.lang.annotation.Documented" internal const val KOTLIN_JVM_INTERNAL_REPEATABLE_CONTAINER = "kotlin.jvm.internal.RepeatableContainer"
private fun PsiAnnotation.extractAnnotationFqName(attributeName: String): String? { private fun PsiAnnotation.extractAnnotationFqName(attributeName: String): String? {
val targetAttribute = val targetAttribute =
@@ -52,7 +55,7 @@ private fun PsiAnnotation.extractArrayAnnotationFqNames(attributeName: String):
} }
private val targetMappings = EnumMap<JvmTarget, Map<String, EnumValue>>(JvmTarget::class.java).also { result -> private val targetMappings = EnumMap<JvmTarget, Map<String, EnumValue>>(JvmTarget::class.java).also { result ->
val javaAnnotationElementTypeId = ClassId.fromString("java.lang.annotation.ElementType") val javaAnnotationElementTypeId = ClassId.fromString(JvmAnnotationNames.ELEMENT_TYPE_ENUM.asString())
val jdk6 = hashMapOf( val jdk6 = hashMapOf(
"kotlin.annotation.AnnotationTarget.CLASS" to EnumValue(javaAnnotationElementTypeId, Name.identifier("TYPE")), "kotlin.annotation.AnnotationTarget.CLASS" to EnumValue(javaAnnotationElementTypeId, Name.identifier("TYPE")),
"kotlin.annotation.AnnotationTarget.ANNOTATION_CLASS" to EnumValue(javaAnnotationElementTypeId, Name.identifier("ANNOTATION_TYPE")), "kotlin.annotation.AnnotationTarget.ANNOTATION_CLASS" to EnumValue(javaAnnotationElementTypeId, Name.identifier("ANNOTATION_TYPE")),
@@ -95,7 +98,7 @@ internal fun PsiAnnotation.tryConvertAsTarget(support: KtUltraLightSupport): KtL
) )
} }
private val javaAnnotationRetentionPolicyId = ClassId.fromString("java.lang.annotation.RetentionPolicy") private val javaAnnotationRetentionPolicyId = ClassId.fromString(JvmAnnotationNames.RETENTION_POLICY_ENUM.asString())
private val retentionMapping = hashMapOf( private val retentionMapping = hashMapOf(
"kotlin.annotation.AnnotationRetention.SOURCE" to EnumValue(javaAnnotationRetentionPolicyId, Name.identifier("SOURCE")), "kotlin.annotation.AnnotationRetention.SOURCE" to EnumValue(javaAnnotationRetentionPolicyId, Name.identifier("SOURCE")),
"kotlin.annotation.AnnotationRetention.BINARY" to EnumValue(javaAnnotationRetentionPolicyId, Name.identifier("CLASS")), "kotlin.annotation.AnnotationRetention.BINARY" to EnumValue(javaAnnotationRetentionPolicyId, Name.identifier("CLASS")),
@@ -103,23 +106,16 @@ private val retentionMapping = hashMapOf(
) )
internal fun createRetentionRuntimeAnnotation(support: KtUltraLightSupport, parent: PsiElement) = internal fun createRetentionRuntimeAnnotation(support: KtUltraLightSupport, parent: PsiElement) = KtUltraLightSimpleAnnotation(
KtUltraLightSimpleAnnotation( JAVA_LANG_ANNOTATION_RETENTION,
JAVA_LANG_ANNOTATION_RETENTION, listOf("value" to retentionMapping["kotlin.annotation.AnnotationRetention.RUNTIME"]!!),
listOf("value" to retentionMapping["kotlin.annotation.AnnotationRetention.RUNTIME"]!!), support,
support, parent
parent )
)
internal fun PsiAnnotation.tryConvertAsRetention(support: KtUltraLightSupport): KtLightAbstractAnnotation? { internal fun PsiAnnotation.tryConvertAsRetention(support: KtUltraLightSupport): KtLightAbstractAnnotation? {
if (FqNames.retention.asString() != qualifiedName) return null if (FqNames.retention.asString() != qualifiedName) return null
val convertedValue = extractAnnotationFqName("value")?.let { retentionMapping[it] } ?: return null
val convertedValue = extractAnnotationFqName("value")
?.let { retentionMapping[it] }
convertedValue ?: return null
return KtUltraLightSimpleAnnotation( return KtUltraLightSimpleAnnotation(
JAVA_LANG_ANNOTATION_RETENTION, JAVA_LANG_ANNOTATION_RETENTION,
listOf("value" to convertedValue), listOf("value" to convertedValue),
@@ -128,14 +124,41 @@ internal fun PsiAnnotation.tryConvertAsRetention(support: KtUltraLightSupport):
) )
} }
internal fun PsiAnnotation.tryConvertAsMustBeDocumented(support: KtUltraLightSupport): KtLightAbstractAnnotation? { internal fun PsiAnnotation.tryConvertAsMustBeDocumented(support: KtUltraLightSupport): KtLightAbstractAnnotation? = tryConvertAs(
support,
FqNames.mustBeDocumented,
JvmAnnotationNames.DOCUMENTED_ANNOTATION.asString(),
)
if (FqNames.mustBeDocumented.asString() != qualifiedName) return null internal fun PsiAnnotation.tryConvertAsRepeatable(
support: KtUltraLightSupport,
owner: KtLightElement<KtModifierListOwner, PsiModifierListOwner>,
): KtLightAbstractAnnotation? {
if (FqNames.repeatable.asString() != qualifiedName) return null
val value = owner.kotlinOrigin
?.safeAs<KtClass>()
?.getClassId()
?.createNestedClassId(Name.identifier(JvmAbi.REPEATABLE_ANNOTATION_CONTAINER_NAME))
?.let { "value" to KClassValue(it, 0) }
return KtUltraLightSimpleAnnotation( return KtUltraLightSimpleAnnotation(
JAVA_LANG_ANNOTATION_DOCUMENTED, JAVA_LANG_ANNOTATION_REPEATABLE,
emptyList(), listOfNotNull(value),
support, support,
parent parent
) )
} }
internal fun PsiAnnotation.tryConvertAsRepeatableContainer(support: KtUltraLightSupport): KtLightAbstractAnnotation? = tryConvertAs(
support,
FqNames.repeatable,
KOTLIN_JVM_INTERNAL_REPEATABLE_CONTAINER,
)
private fun PsiAnnotation.tryConvertAs(
support: KtUltraLightSupport,
from: FqName,
to: String,
): KtLightAbstractAnnotation? = takeIf { from.asString() == qualifiedName }?.let {
KtUltraLightSimpleAnnotation(to, emptyList(), support, parent)
}
@@ -0,0 +1,6 @@
@java.lang.annotation.Repeatable(value = TwoContainer::class)
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
public abstract @interface Two /* Two*/ {
public abstract java.lang.String name();// name()
}
@@ -0,0 +1,7 @@
// Two
// STDLIB_JDK8
// FULL_JDK
@JvmRepeatable(TwoContainer::class)
annotation class Two(val name: String)
annotation class TwoContainer(val value: Array<Two>)
@@ -0,0 +1,7 @@
@java.lang.annotation.Repeatable(value = TwoContainer::class)
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
@kotlin.annotation.Repeatable()
public abstract @interface Two /* Two*/ {
public abstract java.lang.String name();// name()
}
@@ -0,0 +1,10 @@
// Two
// STDLIB_JDK8
// FULL_JDK
import java.lang.annotation.Repeatable as JvmRepeatable
@Repeatable
@JvmRepeatable(TwoContainer::class)
annotation class Two(val name: String)
annotation class TwoContainer(val value: Array<Two>)
@@ -0,0 +1,7 @@
@java.lang.annotation.Repeatable(value = TwoContainer::class)
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
@kotlin.annotation.Repeatable()
public abstract @interface Two /* Two*/ {
public abstract java.lang.String name();// name()
}
@@ -0,0 +1,8 @@
// Two
// STDLIB_JDK8
// FULL_JDK
@Repeatable
@JvmRepeatable(TwoContainer::class)
annotation class Two(val name: String)
annotation class TwoContainer(val value: Array<Two>)
@@ -0,0 +1,13 @@
@java.lang.annotation.Repeatable(value = simple.One.Container.class)
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
@kotlin.annotation.Repeatable()
public abstract @interface One /* simple.One*/ {
public abstract java.lang.String value();// value()
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
@kotlin.jvm.internal.RepeatableContainer()
public @interface Container /* simple.One.Container*/ {
public abstract simple.One[] value();// value()
}}
@@ -0,0 +1,7 @@
// simple.One
// FULL_JDK
package simple
@Repeatable
annotation class One(val value: String)
@@ -1,4 +1,5 @@
@java.lang.annotation.Documented() @java.lang.annotation.Documented()
@java.lang.annotation.Repeatable(value = Anno.Container.class)
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.SOURCE)
@java.lang.annotation.Target(value = {java.lang.annotation.ElementType.TYPE_PARAMETER, java.lang.annotation.ElementType.TYPE_USE}) @java.lang.annotation.Target(value = {java.lang.annotation.ElementType.TYPE_PARAMETER, java.lang.annotation.ElementType.TYPE_USE})
@kotlin.annotation.MustBeDocumented() @kotlin.annotation.MustBeDocumented()
@@ -8,4 +9,13 @@
public abstract @interface Anno /* Anno*/ { public abstract @interface Anno /* Anno*/ {
public abstract int i();// i() public abstract int i();// i()
}
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.SOURCE)
@java.lang.annotation.Target(value = {java.lang.annotation.ElementType.TYPE_PARAMETER, java.lang.annotation.ElementType.TYPE_USE})
@kotlin.annotation.Retention(value = kotlin.annotation.AnnotationRetention.SOURCE)
@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.TYPE_PARAMETER, kotlin.annotation.AnnotationTarget.TYPE})
@kotlin.jvm.internal.RepeatableContainer()
public @interface Container /* Anno.Container*/ {
public abstract Anno[] value();// value()
}}
@@ -1,4 +1,5 @@
// Anno // Anno
// FULL_JDK
@Retention(AnnotationRetention.SOURCE) @Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPE) @Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPE)
@@ -1,4 +1,5 @@
@java.lang.annotation.Documented() @java.lang.annotation.Documented()
@java.lang.annotation.Repeatable(value = Anno.Container.class)
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.SOURCE) @java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.SOURCE)
@java.lang.annotation.Target(value = {}) @java.lang.annotation.Target(value = {})
@kotlin.annotation.MustBeDocumented() @kotlin.annotation.MustBeDocumented()
@@ -8,4 +9,13 @@
public abstract @interface Anno /* Anno*/ { public abstract @interface Anno /* Anno*/ {
public abstract int i();// i() public abstract int i();// i()
}
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.SOURCE)
@java.lang.annotation.Target(value = {})
@kotlin.annotation.Retention(value = kotlin.annotation.AnnotationRetention.SOURCE)
@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.TYPE_PARAMETER, kotlin.annotation.AnnotationTarget.TYPE})
@kotlin.jvm.internal.RepeatableContainer()
public @interface Container /* Anno.Container*/ {
public abstract Anno[] value();// value()
}}
@@ -1,5 +1,6 @@
// Anno // Anno
// JVM_TARGET: 1.6 // JVM_TARGET: 1.6
// FULL_JDK
@Retention(AnnotationRetention.SOURCE) @Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPE) @Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPE)
@@ -49,6 +49,26 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
runTest("compiler/testData/asJava/lightClasses/AnnotationClass.kt"); runTest("compiler/testData/asJava/lightClasses/AnnotationClass.kt");
} }
@TestMetadata("AnnotationJvmRepeatable.kt")
public void testAnnotationJvmRepeatable() throws Exception {
runTest("compiler/testData/asJava/lightClasses/AnnotationJvmRepeatable.kt");
}
@TestMetadata("AnnotationKotlinAndJavaRepeatable.kt")
public void testAnnotationKotlinAndJavaRepeatable() throws Exception {
runTest("compiler/testData/asJava/lightClasses/AnnotationKotlinAndJavaRepeatable.kt");
}
@TestMetadata("AnnotationKotlinAndJvmRepeatable.kt")
public void testAnnotationKotlinAndJvmRepeatable() throws Exception {
runTest("compiler/testData/asJava/lightClasses/AnnotationKotlinAndJvmRepeatable.kt");
}
@TestMetadata("AnnotationRepeatable.kt")
public void testAnnotationRepeatable() throws Exception {
runTest("compiler/testData/asJava/lightClasses/AnnotationRepeatable.kt");
}
@TestMetadata("Constructors.kt") @TestMetadata("Constructors.kt")
public void testConstructors() throws Exception { public void testConstructors() throws Exception {
runTest("compiler/testData/asJava/lightClasses/Constructors.kt"); runTest("compiler/testData/asJava/lightClasses/Constructors.kt");