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:
committed by
Alexander Udalov
parent
844b0078ba
commit
d70271b6aa
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
object RequireKotlinNames {
|
||||
val FQ_NAME = FqName("kotlin.internal.RequireKotlin")
|
||||
|
||||
val VERSION = Name.identifier("version")
|
||||
val MESSAGE = Name.identifier("message")
|
||||
val LEVEL = Name.identifier("level")
|
||||
val VERSION_KIND = Name.identifier("versionKind")
|
||||
val ERROR_CODE = Name.identifier("errorCode")
|
||||
}
|
||||
+3
-7
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.RequireKotlinNames
|
||||
import org.jetbrains.kotlin.resolve.RequireKotlinConstants
|
||||
import org.jetbrains.kotlin.resolve.SINCE_KOTLIN_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
|
||||
@@ -34,7 +34,7 @@ abstract class KotlinVersionStringAnnotationValueChecker(
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
val annotation = descriptor.annotations.findAnnotation(annotationFqName) ?: return
|
||||
val version = annotation.allValueArguments.values.singleOrNull()?.value as? String ?: return
|
||||
if (!version.matches(VERSION_REGEX)) {
|
||||
if (!version.matches(RequireKotlinConstants.VERSION_REGEX)) {
|
||||
context.trace.report(Errors.ILLEGAL_KOTLIN_VERSION_STRING_VALUE.on(annotation.source.getPsi() ?: declaration, annotationFqName))
|
||||
return
|
||||
}
|
||||
@@ -50,10 +50,6 @@ abstract class KotlinVersionStringAnnotationValueChecker(
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val VERSION_REGEX: Regex = "(0|[1-9][0-9]*)".let { number -> Regex("$number\\.$number(\\.$number)?") }
|
||||
}
|
||||
}
|
||||
|
||||
object SinceKotlinAnnotationValueChecker : KotlinVersionStringAnnotationValueChecker(SINCE_KOTLIN_FQ_NAME) {
|
||||
@@ -77,4 +73,4 @@ object SinceKotlinAnnotationValueChecker : KotlinVersionStringAnnotationValueChe
|
||||
}
|
||||
}
|
||||
|
||||
object RequireKotlinAnnotationValueChecker : KotlinVersionStringAnnotationValueChecker(RequireKotlinNames.FQ_NAME)
|
||||
object RequireKotlinAnnotationValueChecker : KotlinVersionStringAnnotationValueChecker(RequireKotlinConstants.FQ_NAME)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+8
-9
@@ -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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.resolve
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
object RequireKotlinConstants {
|
||||
val FQ_NAME = FqName("kotlin.internal.RequireKotlin")
|
||||
|
||||
val VERSION = Name.identifier("version")
|
||||
val MESSAGE = Name.identifier("message")
|
||||
val LEVEL = Name.identifier("level")
|
||||
val VERSION_KIND = Name.identifier("versionKind")
|
||||
val ERROR_CODE = Name.identifier("errorCode")
|
||||
|
||||
val VERSION_REGEX: Regex = "(0|[1-9][0-9]*)".let { number -> Regex("$number\\.$number(\\.$number)?") }
|
||||
}
|
||||
Reference in New Issue
Block a user