Refactoring: AnnotationTarget / AnnotationRetention renamed to KotlinTarget / KotlinRetention

(for not clashing with the same built-in classes)
This commit is contained in:
Mikhail Glukhikh
2015-07-22 18:56:36 +03:00
parent 414c44ade5
commit f551d64ea2
7 changed files with 75 additions and 75 deletions
@@ -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<AnnotationTarget>? {
public fun possibleTargetSet(classDescriptor: ClassDescriptor): Set<KotlinTarget>? {
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<EnumValue>().map {
AnnotationTarget.valueOrNull(it.value.getName().asString())
KotlinTarget.valueOrNull(it.value.getName().asString())
}.filterNotNull().toSet()
}
private fun possibleTargetSet(entry: JetAnnotationEntry, trace: BindingTrace): Set<AnnotationTarget> {
val descriptor = trace.get(BindingContext.ANNOTATION, entry) ?: return AnnotationTarget.DEFAULT_TARGET_SET
private fun possibleTargetSet(entry: JetAnnotationEntry, trace: BindingTrace): Set<KotlinTarget> {
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<AnnotationTarget>, trace: BindingTrace) {
private fun checkAnnotationEntry(entry: JetAnnotationEntry, actualTargets: List<KotlinTarget>, 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<AnnotationTarget> {
private fun getActualTargetList(annotated: JetAnnotated, descriptor: ClassDescriptor?): List<KotlinTarget> {
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()
}
}