Move RequireKotlinNames to 'descriptors'

Also move version string regex there and rename the class to
RequireKotlinConstants. This allows to get rid of dependency of
'serialization' on 'frontend'.
This commit is contained in:
Alexander Udalov
2020-03-15 14:21:42 +01:00
committed by Alexander Udalov
parent 844b0078ba
commit d70271b6aa
5 changed files with 33 additions and 51 deletions
+1 -5
View File
@@ -1,14 +1,10 @@
plugins {
kotlin("jvm")
id("jps-compatible")
}
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
compile(project(":core:descriptors"))
compile(project(":core:deserialization"))
compile(project(":compiler:resolution"))
}
sourceSets {
@@ -25,9 +25,8 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry
import org.jetbrains.kotlin.resolve.MemberComparator
import org.jetbrains.kotlin.resolve.RequireKotlinNames
import org.jetbrains.kotlin.resolve.RequireKotlinConstants
import org.jetbrains.kotlin.resolve.calls.components.isActualParameterWithAnyExpectedDefault
import org.jetbrains.kotlin.resolve.checkers.KotlinVersionStringAnnotationValueChecker
import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.resolve.constants.IntValue
import org.jetbrains.kotlin.resolve.constants.NullValue
@@ -672,15 +671,15 @@ class DescriptorSerializer private constructor(
// Returns a list of indices into versionRequirementTable, or empty list if there's no @RequireKotlin on the descriptor
private fun MutableVersionRequirementTable.serializeVersionRequirements(descriptor: DeclarationDescriptor): List<Int> =
descriptor.annotations
.filter { it.fqName == RequireKotlinNames.FQ_NAME }
.filter { it.fqName == RequireKotlinConstants.FQ_NAME }
.mapNotNull(::serializeVersionRequirementFromRequireKotlin)
.map(::get)
private fun serializeVersionRequirementFromRequireKotlin(annotation: AnnotationDescriptor): ProtoBuf.VersionRequirement.Builder? {
val args = annotation.allValueArguments
val versionString = (args[RequireKotlinNames.VERSION] as? StringValue)?.value ?: return null
val matchResult = KotlinVersionStringAnnotationValueChecker.VERSION_REGEX.matchEntire(versionString) ?: return null
val versionString = (args[RequireKotlinConstants.VERSION] as? StringValue)?.value ?: return null
val matchResult = RequireKotlinConstants.VERSION_REGEX.matchEntire(versionString) ?: return null
val major = matchResult.groupValues.getOrNull(1)?.toIntOrNull() ?: return null
val minor = matchResult.groupValues.getOrNull(2)?.toIntOrNull() ?: 0
@@ -692,12 +691,12 @@ class DescriptorSerializer private constructor(
writeVersionFull = { proto.versionFull = it }
)
val message = (args[RequireKotlinNames.MESSAGE] as? StringValue)?.value
val message = (args[RequireKotlinConstants.MESSAGE] as? StringValue)?.value
if (message != null) {
proto.message = stringTable.getStringIndex(message)
}
when ((args[RequireKotlinNames.LEVEL] as? EnumValue)?.enumEntryName?.asString()) {
when ((args[RequireKotlinConstants.LEVEL] as? EnumValue)?.enumEntryName?.asString()) {
DeprecationLevel.ERROR.name -> {
// ERROR is the default level
}
@@ -705,7 +704,7 @@ class DescriptorSerializer private constructor(
DeprecationLevel.HIDDEN.name -> proto.level = ProtoBuf.VersionRequirement.Level.HIDDEN
}
when ((args[RequireKotlinNames.VERSION_KIND] as? EnumValue)?.enumEntryName?.asString()) {
when ((args[RequireKotlinConstants.VERSION_KIND] as? EnumValue)?.enumEntryName?.asString()) {
ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION.name -> {
// LANGUAGE_VERSION is the default kind
}
@@ -715,7 +714,7 @@ class DescriptorSerializer private constructor(
proto.versionKind = ProtoBuf.VersionRequirement.VersionKind.API_VERSION
}
val errorCode = (args[RequireKotlinNames.ERROR_CODE] as? IntValue)?.value
val errorCode = (args[RequireKotlinConstants.ERROR_CODE] as? IntValue)?.value
if (errorCode != null && errorCode != -1) {
proto.errorCode = errorCode
}