diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java index 815d0479def..860bf03620e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java @@ -168,26 +168,26 @@ public abstract class AnnotationCodegen { generateAnnotationIfNotPresent(annotationDescriptorsAlreadyPresent, annotationClass); } - private static final Map annotationTargetMap = - new EnumMap(AnnotationTarget.class); + private static final Map annotationTargetMap = + new EnumMap(KotlinTarget.class); static { - annotationTargetMap.put(AnnotationTarget.PACKAGE, ElementType.PACKAGE); - annotationTargetMap.put(AnnotationTarget.CLASSIFIER, ElementType.TYPE); - annotationTargetMap.put(AnnotationTarget.ANNOTATION_CLASS, ElementType.ANNOTATION_TYPE); - annotationTargetMap.put(AnnotationTarget.CONSTRUCTOR, ElementType.CONSTRUCTOR); - annotationTargetMap.put(AnnotationTarget.LOCAL_VARIABLE, ElementType.LOCAL_VARIABLE); - annotationTargetMap.put(AnnotationTarget.FUNCTION, ElementType.METHOD); - annotationTargetMap.put(AnnotationTarget.PROPERTY_GETTER, ElementType.METHOD); - annotationTargetMap.put(AnnotationTarget.PROPERTY_SETTER, ElementType.METHOD); - annotationTargetMap.put(AnnotationTarget.FIELD, ElementType.FIELD); - annotationTargetMap.put(AnnotationTarget.VALUE_PARAMETER, ElementType.PARAMETER); + annotationTargetMap.put(KotlinTarget.PACKAGE, ElementType.PACKAGE); + annotationTargetMap.put(KotlinTarget.CLASSIFIER, ElementType.TYPE); + annotationTargetMap.put(KotlinTarget.ANNOTATION_CLASS, ElementType.ANNOTATION_TYPE); + annotationTargetMap.put(KotlinTarget.CONSTRUCTOR, ElementType.CONSTRUCTOR); + annotationTargetMap.put(KotlinTarget.LOCAL_VARIABLE, ElementType.LOCAL_VARIABLE); + annotationTargetMap.put(KotlinTarget.FUNCTION, ElementType.METHOD); + annotationTargetMap.put(KotlinTarget.PROPERTY_GETTER, ElementType.METHOD); + annotationTargetMap.put(KotlinTarget.PROPERTY_SETTER, ElementType.METHOD); + annotationTargetMap.put(KotlinTarget.FIELD, ElementType.FIELD); + annotationTargetMap.put(KotlinTarget.VALUE_PARAMETER, ElementType.PARAMETER); } private void generateTargetAnnotation(@NotNull ClassDescriptor classDescriptor, @NotNull Set annotationDescriptorsAlreadyPresent) { String descriptor = Type.getType(Target.class).getDescriptor(); if (!annotationDescriptorsAlreadyPresent.add(descriptor)) return; - Set targets = AnnotationTargetChecker.INSTANCE$.possibleTargetSet(classDescriptor); + Set targets = AnnotationTargetChecker.INSTANCE$.possibleTargetSet(classDescriptor); Set javaTargets; if (targets == null) { javaTargets = getJavaTargetList(classDescriptor); @@ -195,7 +195,7 @@ public abstract class AnnotationCodegen { } else { javaTargets = EnumSet.noneOf(ElementType.class); - for (AnnotationTarget target : targets) { + for (KotlinTarget target : targets) { if (annotationTargetMap.get(target) == null) continue; javaTargets.add(annotationTargetMap.get(target)); } @@ -368,13 +368,13 @@ public abstract class AnnotationCodegen { value.accept(argumentVisitor, null); } - private static final Map annotationRetentionMap = - new EnumMap(AnnotationRetention.class); + private static final Map annotationRetentionMap = + new EnumMap(KotlinRetention.class); static { - annotationRetentionMap.put(AnnotationRetention.SOURCE, RetentionPolicy.SOURCE); - annotationRetentionMap.put(AnnotationRetention.BINARY, RetentionPolicy.CLASS); - annotationRetentionMap.put(AnnotationRetention.RUNTIME, RetentionPolicy.RUNTIME); + annotationRetentionMap.put(KotlinRetention.SOURCE, RetentionPolicy.SOURCE); + annotationRetentionMap.put(KotlinRetention.BINARY, RetentionPolicy.CLASS); + annotationRetentionMap.put(KotlinRetention.RUNTIME, RetentionPolicy.RUNTIME); } @Nullable @@ -415,7 +415,7 @@ public abstract class AnnotationCodegen { JetType classObjectType = getClassObjectType(enumEntry); if (classObjectType != null) { if ("kotlin/annotation/AnnotationRetention".equals(typeMapper.mapType(classObjectType).getInternalName())) { - AnnotationRetention retention = AnnotationRetention.valueOf(enumEntry.getName().asString()); + KotlinRetention retention = KotlinRetention.valueOf(enumEntry.getName().asString()); return annotationRetentionMap.get(retention); } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationTargetChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationTargetChecker.kt index 598685f938b..5ae117a54dd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationTargetChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationTargetChecker.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.TypeUtils import java.lang.annotation.ElementType import java.util.* -import org.jetbrains.kotlin.descriptors.annotations.AnnotationTarget +import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget import kotlin.annotation public object AnnotationTargetChecker { @@ -62,7 +62,7 @@ public object AnnotationTargetChecker { public fun checkExpression(expression: JetExpression, trace: BindingTrace) { for (entry in expression.getAnnotationEntries()) { - checkAnnotationEntry(entry, listOf(AnnotationTarget.EXPRESSION), trace) + checkAnnotationEntry(entry, listOf(KotlinTarget.EXPRESSION), trace) } if (expression is JetFunctionLiteralExpression) { for (parameter in expression.getValueParameters()) { @@ -71,55 +71,55 @@ public object AnnotationTargetChecker { } } - public fun possibleTargetSet(classDescriptor: ClassDescriptor): Set? { + public fun possibleTargetSet(classDescriptor: ClassDescriptor): Set? { val targetEntryDescriptor = classDescriptor.getAnnotations().findAnnotation(KotlinBuiltIns.FQ_NAMES.target) ?: return null val valueArguments = targetEntryDescriptor.getAllValueArguments() val valueArgument = valueArguments.entrySet().firstOrNull()?.getValue() as? ArrayValue ?: return null return valueArgument.value.filterIsInstance().map { - AnnotationTarget.valueOrNull(it.value.getName().asString()) + KotlinTarget.valueOrNull(it.value.getName().asString()) }.filterNotNull().toSet() } - private fun possibleTargetSet(entry: JetAnnotationEntry, trace: BindingTrace): Set { - val descriptor = trace.get(BindingContext.ANNOTATION, entry) ?: return AnnotationTarget.DEFAULT_TARGET_SET + private fun possibleTargetSet(entry: JetAnnotationEntry, trace: BindingTrace): Set { + val descriptor = trace.get(BindingContext.ANNOTATION, entry) ?: return KotlinTarget.DEFAULT_TARGET_SET // For descriptor with error type, all targets are considered as possible - if (descriptor.getType().isError()) return AnnotationTarget.ALL_TARGET_SET - val classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType()) ?: return AnnotationTarget.DEFAULT_TARGET_SET - return possibleTargetSet(classDescriptor) ?: AnnotationTarget.DEFAULT_TARGET_SET + if (descriptor.getType().isError()) return KotlinTarget.ALL_TARGET_SET + val classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType()) ?: return KotlinTarget.DEFAULT_TARGET_SET + return possibleTargetSet(classDescriptor) ?: KotlinTarget.DEFAULT_TARGET_SET } - private fun checkAnnotationEntry(entry: JetAnnotationEntry, actualTargets: List, trace: BindingTrace) { + private fun checkAnnotationEntry(entry: JetAnnotationEntry, actualTargets: List, trace: BindingTrace) { val possibleTargets = possibleTargetSet(entry, trace) if (actualTargets.any { it in possibleTargets }) return trace.report(Errors.WRONG_ANNOTATION_TARGET.on(entry, actualTargets.firstOrNull()?.description ?: "unidentified target")) } - private fun getActualTargetList(annotated: JetAnnotated, descriptor: ClassDescriptor?): List { + private fun getActualTargetList(annotated: JetAnnotated, descriptor: ClassDescriptor?): List { if (annotated is JetClassOrObject) { - if (annotated is JetEnumEntry) return listOf(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD) + if (annotated is JetEnumEntry) return listOf(KotlinTarget.PROPERTY, KotlinTarget.FIELD) return if (descriptor?.getKind() == ClassKind.ANNOTATION_CLASS) { - listOf(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASSIFIER) + listOf(KotlinTarget.ANNOTATION_CLASS, KotlinTarget.CLASSIFIER) } else { - listOf(AnnotationTarget.CLASSIFIER) + listOf(KotlinTarget.CLASSIFIER) } } if (annotated is JetProperty) { - return if (annotated.isLocal()) listOf(AnnotationTarget.LOCAL_VARIABLE) else listOf(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD) + return if (annotated.isLocal()) listOf(KotlinTarget.LOCAL_VARIABLE) else listOf(KotlinTarget.PROPERTY, KotlinTarget.FIELD) } if (annotated is JetParameter) { - return if (annotated.hasValOrVar()) listOf(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD) else listOf(AnnotationTarget.VALUE_PARAMETER) + return if (annotated.hasValOrVar()) listOf(KotlinTarget.PROPERTY, KotlinTarget.FIELD) else listOf(KotlinTarget.VALUE_PARAMETER) } - if (annotated is JetConstructor<*>) return listOf(AnnotationTarget.CONSTRUCTOR) - if (annotated is JetFunction) return listOf(AnnotationTarget.FUNCTION) + if (annotated is JetConstructor<*>) return listOf(KotlinTarget.CONSTRUCTOR) + if (annotated is JetFunction) return listOf(KotlinTarget.FUNCTION) if (annotated is JetPropertyAccessor) { - return if (annotated.isGetter()) listOf(AnnotationTarget.PROPERTY_GETTER) else listOf(AnnotationTarget.PROPERTY_SETTER) + return if (annotated.isGetter()) listOf(KotlinTarget.PROPERTY_GETTER) else listOf(KotlinTarget.PROPERTY_SETTER) } - if (annotated is JetPackageDirective) return listOf(AnnotationTarget.PACKAGE) - if (annotated is JetTypeReference) return listOf(AnnotationTarget.TYPE) - if (annotated is JetFile) return listOf(AnnotationTarget.FILE) - if (annotated is JetTypeParameter) return listOf(AnnotationTarget.TYPE_PARAMETER) + if (annotated is JetPackageDirective) return listOf(KotlinTarget.PACKAGE) + if (annotated is JetTypeReference) return listOf(KotlinTarget.TYPE) + if (annotated is JetFile) return listOf(KotlinTarget.FILE) + if (annotated is JetTypeParameter) return listOf(KotlinTarget.TYPE_PARAMETER) return listOf() } } \ No newline at end of file diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt index 2eec87e5677..de69eb392bc 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt @@ -34,10 +34,10 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue import org.jetbrains.kotlin.resolve.constants.EnumValue import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.JetType -import org.jetbrains.kotlin.descriptors.annotations.AnnotationTarget +import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.descriptors.annotations.AnnotationRetention +import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention import org.jetbrains.kotlin.storage.StorageManager import java.lang.annotation.Retention import java.lang.annotation.Target @@ -113,21 +113,21 @@ class JavaTargetAnnotationDescriptor( } public object JavaAnnotationTargetMapper { - private val targetNameLists = mapOf("PACKAGE" to EnumSet.of(AnnotationTarget.PACKAGE), - "TYPE" to EnumSet.of(AnnotationTarget.CLASSIFIER), - "ANNOTATION_TYPE" to EnumSet.of(AnnotationTarget.ANNOTATION_CLASS), - "TYPE_PARAMETER" to EnumSet.of(AnnotationTarget.TYPE_PARAMETER), - "FIELD" to EnumSet.of(AnnotationTarget.FIELD), - "LOCAL_VARIABLE" to EnumSet.of(AnnotationTarget.LOCAL_VARIABLE), - "PARAMETER" to EnumSet.of(AnnotationTarget.VALUE_PARAMETER), - "CONSTRUCTOR" to EnumSet.of(AnnotationTarget.CONSTRUCTOR), - "METHOD" to EnumSet.of(AnnotationTarget.FUNCTION, - AnnotationTarget.PROPERTY_GETTER, - AnnotationTarget.PROPERTY_SETTER), - "TYPE_USE" to EnumSet.of(AnnotationTarget.TYPE) + private val targetNameLists = mapOf("PACKAGE" to EnumSet.of(KotlinTarget.PACKAGE), + "TYPE" to EnumSet.of(KotlinTarget.CLASSIFIER), + "ANNOTATION_TYPE" to EnumSet.of(KotlinTarget.ANNOTATION_CLASS), + "TYPE_PARAMETER" to EnumSet.of(KotlinTarget.TYPE_PARAMETER), + "FIELD" to EnumSet.of(KotlinTarget.FIELD), + "LOCAL_VARIABLE" to EnumSet.of(KotlinTarget.LOCAL_VARIABLE), + "PARAMETER" to EnumSet.of(KotlinTarget.VALUE_PARAMETER), + "CONSTRUCTOR" to EnumSet.of(KotlinTarget.CONSTRUCTOR), + "METHOD" to EnumSet.of(KotlinTarget.FUNCTION, + KotlinTarget.PROPERTY_GETTER, + KotlinTarget.PROPERTY_SETTER), + "TYPE_USE" to EnumSet.of(KotlinTarget.TYPE) ) - public fun mapJavaTargetArgumentByName(argumentName: String?): Set = targetNameLists[argumentName] ?: emptySet() + public fun mapJavaTargetArgumentByName(argumentName: String?): Set = targetNameLists[argumentName] ?: emptySet() public fun mapJavaTargetArguments(arguments: List, builtIns: KotlinBuiltIns): ConstantValue<*>? { // Map arguments: java.lang.annotation.Target -> kotlin.annotation.target @@ -141,9 +141,9 @@ public object JavaAnnotationTargetMapper { return ArrayValue(kotlinTargets, parameterDescriptor?.type ?: ErrorUtils.createErrorType("Error: AnnotationTarget[]"), builtIns) } - private val retentionNameList = mapOf("RUNTIME" to AnnotationRetention.RUNTIME, - "CLASS" to AnnotationRetention.BINARY, - "SOURCE" to AnnotationRetention.SOURCE + private val retentionNameList = mapOf("RUNTIME" to KotlinRetention.RUNTIME, + "CLASS" to KotlinRetention.BINARY, + "SOURCE" to KotlinRetention.SOURCE ) public fun mapJavaRetentionArgument(element: JavaAnnotationArgument, builtIns: KotlinBuiltIns): ConstantValue<*>? { diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index ea95b2c9552..9bdda77c684 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -398,7 +398,7 @@ public class KotlinBuiltIns { } @Nullable - public ClassDescriptor getAnnotationTargetEnumEntry(@NotNull AnnotationTarget target) { + public ClassDescriptor getAnnotationTargetEnumEntry(@NotNull KotlinTarget target) { ClassifierDescriptor result = getAnnotationTargetEnum().getUnsubstitutedInnerClassesScope().getClassifier( Name.identifier(target.name()), UsageLocation.NO_LOCATION ); @@ -411,7 +411,7 @@ public class KotlinBuiltIns { } @Nullable - public ClassDescriptor getAnnotationRetentionEnumEntry(@NotNull AnnotationRetention retention) { + public ClassDescriptor getAnnotationRetentionEnumEntry(@NotNull KotlinRetention retention) { ClassifierDescriptor result = getAnnotationRetentionEnum().getUnsubstitutedInnerClassesScope().getClassifier( Name.identifier(retention.name()), UsageLocation.NO_LOCATION ); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationRetention.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinRetention.kt similarity index 94% rename from core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationRetention.kt rename to core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinRetention.kt index 42db1d70591..ae52042f77f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationRetention.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinRetention.kt @@ -16,7 +16,7 @@ package org.jetbrains.kotlin.descriptors.annotations -public enum class AnnotationRetention { +public enum class KotlinRetention { RUNTIME, BINARY, SOURCE diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationTarget.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt similarity index 74% rename from core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationTarget.kt rename to core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt index b28ae42d64e..4712af9fadb 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/AnnotationTarget.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt @@ -20,7 +20,7 @@ import java.util.* import kotlin.annotation // NOTE: this enum must have the same entries with kotlin.annotation.AnnotationTarget -public enum class AnnotationTarget(val description: String, val isDefault: Boolean = true) { +public enum class KotlinTarget(val description: String, val isDefault: Boolean = true) { PACKAGE("package"), CLASSIFIER("classifier"), ANNOTATION_CLASS("annotation class"), @@ -39,19 +39,19 @@ public enum class AnnotationTarget(val description: String, val isDefault: Boole companion object { - private val map = HashMap() + private val map = HashMap() init { - for (target in AnnotationTarget.values()) { + for (target in KotlinTarget.values()) { map[target.name()] = target } } - public fun valueOrNull(name: String): AnnotationTarget? = map[name] + public fun valueOrNull(name: String): KotlinTarget? = map[name] - public val DEFAULT_TARGET_SET: Set = values().filter { it.isDefault }.toSet() + public val DEFAULT_TARGET_SET: Set = values().filter { it.isDefault }.toSet() - public val ALL_TARGET_SET: Set = values().toSet() + public val ALL_TARGET_SET: Set = values().toSet() } } \ No newline at end of file diff --git a/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt index 0c655766d73..04d401244d8 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/AnnotationConverter.kt @@ -20,7 +20,7 @@ import com.intellij.codeInsight.NullableNotNullManager import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.* import com.intellij.psi.javadoc.PsiDocTag -import org.jetbrains.kotlin.descriptors.annotations.AnnotationTarget +import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget import org.jetbrains.kotlin.j2k.ast.* import org.jetbrains.kotlin.j2k.ast.Annotation import org.jetbrains.kotlin.load.java.components.JavaAnnotationTargetMapper @@ -96,7 +96,7 @@ class AnnotationConverter(private val converter: Converter) { PsiModifier.TRANSIENT to "transient" ) - private fun mapTargetByName(expr: PsiReferenceExpression): Set { + private fun mapTargetByName(expr: PsiReferenceExpression): Set { return expr.referenceName?.let { JavaAnnotationTargetMapper.mapJavaTargetArgumentByName(it) } ?: emptySet() } @@ -108,9 +108,9 @@ class AnnotationConverter(private val converter: Converter) { } if (qualifiedName == CommonClassNames.JAVA_LANG_ANNOTATION_TARGET) { val attributes = annotation.parameterList.attributes - val arguments: Set + val arguments: Set if (attributes.isEmpty()) { - arguments = setOf() + arguments = setOf() } else { val value = attributes[0].value @@ -119,7 +119,7 @@ class AnnotationConverter(private val converter: Converter) { .flatMap { mapTargetByName(it) } .toSet() is PsiReferenceExpression -> mapTargetByName(value) - else -> setOf() + else -> setOf() } } val deferredExpressionList = arguments.map {