Reformat VersionRequirement and move to 'metadata'
This commit is contained in:
+1
-1
@@ -19,9 +19,9 @@ package org.jetbrains.kotlin.serialization.deserialization
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.metadata.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.metadata.deserialization.VersionRequirementTable
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.VersionRequirementTable
|
||||
|
||||
class ClassDeserializer(private val components: DeserializationComponents) {
|
||||
private val classes: (ClassKey) -> ClassDescriptor? =
|
||||
|
||||
+1
-1
@@ -26,11 +26,11 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.metadata.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.metadata.deserialization.VersionRequirementTable
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.VersionRequirementTable
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
class DeserializationComponents(
|
||||
|
||||
+1
-4
@@ -13,10 +13,7 @@ import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.incremental.record
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.metadata.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.metadata.deserialization.supertypes
|
||||
import org.jetbrains.kotlin.metadata.deserialization.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.NonReportingOverrideStrategy
|
||||
|
||||
+1
-3
@@ -20,9 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.*
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.metadata.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.metadata.deserialization.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData
|
||||
|
||||
+1
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.incremental.record
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.metadata.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.metadata.deserialization.VersionRequirementTable
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
|
||||
-124
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.serialization.deserialization.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.protobuf.MessageLite
|
||||
|
||||
class VersionRequirementTable private constructor(private val infos: List<ProtoBuf.VersionRequirement>) {
|
||||
operator fun get(id: Int): ProtoBuf.VersionRequirement? = infos.getOrNull(id)
|
||||
|
||||
companion object {
|
||||
val EMPTY = VersionRequirementTable(emptyList())
|
||||
|
||||
fun create(table: ProtoBuf.VersionRequirementTable): VersionRequirementTable =
|
||||
if (table.requirementCount == 0) EMPTY else VersionRequirementTable(table.requirementList)
|
||||
}
|
||||
}
|
||||
|
||||
class VersionRequirement(
|
||||
val version: Version,
|
||||
val kind: ProtoBuf.VersionRequirement.VersionKind,
|
||||
val level: DeprecationLevel,
|
||||
val errorCode: Int?,
|
||||
val message: String?
|
||||
) {
|
||||
data class Version(val major: Int, val minor: Int, val patch: Int = 0) {
|
||||
fun asString(): String =
|
||||
if (patch == 0) "$major.$minor" else "$major.$minor.$patch"
|
||||
|
||||
fun encode(
|
||||
writeVersion: (Int) -> Unit,
|
||||
writeVersionFull: (Int) -> Unit
|
||||
) = when {
|
||||
this == INFINITY -> {
|
||||
// Do nothing: absence of version means INFINITY
|
||||
}
|
||||
major > MAJOR_MASK || minor > MINOR_MASK || patch > PATCH_MASK -> {
|
||||
writeVersionFull(major or (minor shl 8) or (patch shl 16))
|
||||
}
|
||||
else -> {
|
||||
writeVersion(major or (minor shl MAJOR_BITS) or (patch shl (MAJOR_BITS + MINOR_BITS)))
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = asString()
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val INFINITY = Version(256, 256, 256)
|
||||
|
||||
// Number of bits used for major, minor and patch components in "version" field
|
||||
private const val MAJOR_BITS = 3
|
||||
private const val MINOR_BITS = 4
|
||||
private const val PATCH_BITS = 7
|
||||
private const val MAJOR_MASK = (1 shl MAJOR_BITS) - 1
|
||||
private const val MINOR_MASK = (1 shl MINOR_BITS) - 1
|
||||
private const val PATCH_MASK = (1 shl PATCH_BITS) - 1
|
||||
|
||||
fun decode(version: Int?, versionFull: Int?): Version = when {
|
||||
versionFull != null -> Version(
|
||||
major = versionFull and 255,
|
||||
minor = (versionFull shr 8) and 255,
|
||||
patch = (versionFull shr 16) and 255
|
||||
)
|
||||
version != null -> Version(
|
||||
major = version and MAJOR_MASK,
|
||||
minor = (version shr MAJOR_BITS) and MINOR_MASK,
|
||||
patch = (version shr (MAJOR_BITS + MINOR_BITS)) and PATCH_MASK
|
||||
)
|
||||
else -> Version.INFINITY
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String =
|
||||
"since $version $level" + (if (errorCode != null) " error $errorCode" else "") + (if (message != null) ": $message" else "")
|
||||
|
||||
companion object {
|
||||
fun create(proto: MessageLite, nameResolver: NameResolver, table: VersionRequirementTable): VersionRequirement? {
|
||||
val id = when (proto) {
|
||||
is ProtoBuf.Class -> if (proto.hasVersionRequirement()) proto.versionRequirement else return null
|
||||
is ProtoBuf.Constructor -> if (proto.hasVersionRequirement()) proto.versionRequirement else return null
|
||||
is ProtoBuf.Function -> if (proto.hasVersionRequirement()) proto.versionRequirement else return null
|
||||
is ProtoBuf.Property -> if (proto.hasVersionRequirement()) proto.versionRequirement else return null
|
||||
is ProtoBuf.TypeAlias -> if (proto.hasVersionRequirement()) proto.versionRequirement else return null
|
||||
else -> throw IllegalStateException("Unexpected declaration: ${proto::class.java}")
|
||||
}
|
||||
|
||||
val info = table[id] ?: return null
|
||||
|
||||
val version = Version.decode(
|
||||
if (info.hasVersion()) info.version else null,
|
||||
if (info.hasVersionFull()) info.versionFull else null
|
||||
)
|
||||
|
||||
val level = when (info.level!!) {
|
||||
ProtoBuf.VersionRequirement.Level.WARNING -> DeprecationLevel.WARNING
|
||||
ProtoBuf.VersionRequirement.Level.ERROR -> DeprecationLevel.ERROR
|
||||
ProtoBuf.VersionRequirement.Level.HIDDEN -> DeprecationLevel.HIDDEN
|
||||
}
|
||||
|
||||
val errorCode = if (info.hasErrorCode()) info.errorCode else null
|
||||
|
||||
val message = if (info.hasMessage()) nameResolver.getString(info.message) else null
|
||||
|
||||
return VersionRequirement(version, info.versionKind, level, errorCode, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user