Move common deserialization classes from :core:metadata modules
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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
|
||||
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension
|
||||
|
||||
open class SerializerExtensionProtocol(
|
||||
val extensionRegistry: ExtensionRegistryLite,
|
||||
val packageFqName: GeneratedExtension<ProtoBuf.Package, Int>,
|
||||
val constructorAnnotation: GeneratedExtension<ProtoBuf.Constructor, List<ProtoBuf.Annotation>>,
|
||||
val classAnnotation: GeneratedExtension<ProtoBuf.Class, List<ProtoBuf.Annotation>>,
|
||||
val functionAnnotation: GeneratedExtension<ProtoBuf.Function, List<ProtoBuf.Annotation>>,
|
||||
val propertyAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>,
|
||||
val propertyGetterAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>,
|
||||
val propertySetterAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>,
|
||||
val enumEntryAnnotation: GeneratedExtension<ProtoBuf.EnumEntry, List<ProtoBuf.Annotation>>,
|
||||
val compileTimeValue: GeneratedExtension<ProtoBuf.Property, ProtoBuf.Annotation.Argument.Value>,
|
||||
val parameterAnnotation: GeneratedExtension<ProtoBuf.ValueParameter, List<ProtoBuf.Annotation>>,
|
||||
val typeAnnotation: GeneratedExtension<ProtoBuf.Type, List<ProtoBuf.Annotation>>,
|
||||
val typeParameterAnnotation: GeneratedExtension<ProtoBuf.TypeParameter, List<ProtoBuf.Annotation>>
|
||||
)
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* 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.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
|
||||
data class ClassData(
|
||||
val nameResolver: NameResolver,
|
||||
val classProto: ProtoBuf.Class,
|
||||
val metadataVersion: BinaryVersion,
|
||||
val sourceElement: SourceElement
|
||||
)
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
|
||||
public interface ClassDataFinder {
|
||||
@Nullable
|
||||
ClassData findClassData(@NotNull ClassId classId);
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* 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.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
fun NameResolver.getClassId(index: Int): ClassId {
|
||||
return ClassId.fromString(getQualifiedClassName(index), isLocalClassName(index))
|
||||
}
|
||||
|
||||
fun NameResolver.getName(index: Int): Name =
|
||||
Name.guessByFirstCharacter(getString(index))
|
||||
-42
@@ -1,42 +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
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
class ProtoBasedClassDataFinder(
|
||||
proto: ProtoBuf.PackageFragment,
|
||||
private val nameResolver: NameResolver,
|
||||
private val metadataVersion: BinaryVersion,
|
||||
private val classSource: (ClassId) -> SourceElement = { SourceElement.NO_SOURCE }
|
||||
) : ClassDataFinder {
|
||||
private val classIdToProto =
|
||||
proto.class_List.associateBy { klass ->
|
||||
nameResolver.getClassId(klass.fqName)
|
||||
}
|
||||
|
||||
val allClassIds: Collection<ClassId> get() = classIdToProto.keys
|
||||
|
||||
override fun findClassData(classId: ClassId): ClassData? {
|
||||
val classProto = classIdToProto[classId] ?: return null
|
||||
return ClassData(nameResolver, classProto, metadataVersion, classSource(classId))
|
||||
}
|
||||
}
|
||||
-91
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* 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.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf.TypeParameter
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
object ProtoEnumFlags {
|
||||
fun modality(modality: ProtoBuf.Modality?): Modality = when (modality) {
|
||||
ProtoBuf.Modality.FINAL -> Modality.FINAL
|
||||
ProtoBuf.Modality.OPEN -> Modality.OPEN
|
||||
ProtoBuf.Modality.ABSTRACT -> Modality.ABSTRACT
|
||||
ProtoBuf.Modality.SEALED -> Modality.SEALED
|
||||
else -> Modality.FINAL
|
||||
}
|
||||
|
||||
fun modality(modality: Modality): ProtoBuf.Modality = when (modality) {
|
||||
Modality.FINAL -> ProtoBuf.Modality.FINAL
|
||||
Modality.OPEN -> ProtoBuf.Modality.OPEN
|
||||
Modality.ABSTRACT -> ProtoBuf.Modality.ABSTRACT
|
||||
Modality.SEALED -> ProtoBuf.Modality.SEALED
|
||||
}
|
||||
|
||||
fun visibility(visibility: ProtoBuf.Visibility?): Visibility = when (visibility) {
|
||||
ProtoBuf.Visibility.INTERNAL -> Visibilities.Internal
|
||||
ProtoBuf.Visibility.PRIVATE -> Visibilities.Private
|
||||
ProtoBuf.Visibility.PRIVATE_TO_THIS -> Visibilities.PrivateToThis
|
||||
ProtoBuf.Visibility.PROTECTED -> Visibilities.Protected
|
||||
ProtoBuf.Visibility.PUBLIC -> Visibilities.Public
|
||||
ProtoBuf.Visibility.LOCAL -> Visibilities.Local
|
||||
else -> Visibilities.Private
|
||||
}
|
||||
|
||||
fun visibility(visibility: Visibility): ProtoBuf.Visibility = when (visibility) {
|
||||
Visibilities.Internal -> ProtoBuf.Visibility.INTERNAL
|
||||
Visibilities.Public -> ProtoBuf.Visibility.PUBLIC
|
||||
Visibilities.Private -> ProtoBuf.Visibility.PRIVATE
|
||||
Visibilities.PrivateToThis -> ProtoBuf.Visibility.PRIVATE_TO_THIS
|
||||
Visibilities.Protected -> ProtoBuf.Visibility.PROTECTED
|
||||
Visibilities.Local -> ProtoBuf.Visibility.LOCAL
|
||||
else -> throw IllegalArgumentException("Unknown visibility: $visibility")
|
||||
}
|
||||
|
||||
fun classKind(kind: ProtoBuf.Class.Kind?): ClassKind = when (kind) {
|
||||
ProtoBuf.Class.Kind.CLASS -> ClassKind.CLASS
|
||||
ProtoBuf.Class.Kind.INTERFACE -> ClassKind.INTERFACE
|
||||
ProtoBuf.Class.Kind.ENUM_CLASS -> ClassKind.ENUM_CLASS
|
||||
ProtoBuf.Class.Kind.ENUM_ENTRY -> ClassKind.ENUM_ENTRY
|
||||
ProtoBuf.Class.Kind.ANNOTATION_CLASS -> ClassKind.ANNOTATION_CLASS
|
||||
ProtoBuf.Class.Kind.OBJECT, ProtoBuf.Class.Kind.COMPANION_OBJECT -> ClassKind.OBJECT
|
||||
else -> ClassKind.CLASS
|
||||
}
|
||||
|
||||
fun classKind(kind: ClassKind, isCompanionObject: Boolean): ProtoBuf.Class.Kind {
|
||||
if (isCompanionObject) return ProtoBuf.Class.Kind.COMPANION_OBJECT
|
||||
|
||||
return when (kind) {
|
||||
ClassKind.CLASS -> ProtoBuf.Class.Kind.CLASS
|
||||
ClassKind.INTERFACE -> ProtoBuf.Class.Kind.INTERFACE
|
||||
ClassKind.ENUM_CLASS -> ProtoBuf.Class.Kind.ENUM_CLASS
|
||||
ClassKind.ENUM_ENTRY -> ProtoBuf.Class.Kind.ENUM_ENTRY
|
||||
ClassKind.ANNOTATION_CLASS -> ProtoBuf.Class.Kind.ANNOTATION_CLASS
|
||||
ClassKind.OBJECT -> ProtoBuf.Class.Kind.OBJECT
|
||||
}
|
||||
}
|
||||
|
||||
fun variance(variance: TypeParameter.Variance): Variance = when (variance) {
|
||||
ProtoBuf.TypeParameter.Variance.IN -> Variance.IN_VARIANCE
|
||||
ProtoBuf.TypeParameter.Variance.OUT -> Variance.OUT_VARIANCE
|
||||
ProtoBuf.TypeParameter.Variance.INV -> Variance.INVARIANT
|
||||
}
|
||||
|
||||
fun variance(projection: ProtoBuf.Type.Argument.Projection): Variance = when (projection) {
|
||||
ProtoBuf.Type.Argument.Projection.IN -> Variance.IN_VARIANCE
|
||||
ProtoBuf.Type.Argument.Projection.OUT -> Variance.OUT_VARIANCE
|
||||
ProtoBuf.Type.Argument.Projection.INV -> Variance.INVARIANT
|
||||
ProtoBuf.Type.Argument.Projection.STAR ->
|
||||
throw IllegalArgumentException("Only IN, OUT and INV are supported. Actual argument: $projection")
|
||||
}
|
||||
|
||||
fun variance(variance: Variance): TypeParameter.Variance = when (variance) {
|
||||
Variance.IN_VARIANCE -> TypeParameter.Variance.IN
|
||||
Variance.OUT_VARIANCE -> TypeParameter.Variance.OUT
|
||||
Variance.INVARIANT -> TypeParameter.Variance.INV
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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.serialization.deserialization.builtins
|
||||
|
||||
import org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
|
||||
|
||||
object BuiltInSerializerProtocol : SerializerExtensionProtocol(
|
||||
ExtensionRegistryLite.newInstance().apply(BuiltInsProtoBuf::registerAllExtensions),
|
||||
BuiltInsProtoBuf.packageFqName,
|
||||
BuiltInsProtoBuf.constructorAnnotation,
|
||||
BuiltInsProtoBuf.classAnnotation,
|
||||
BuiltInsProtoBuf.functionAnnotation,
|
||||
BuiltInsProtoBuf.propertyAnnotation,
|
||||
BuiltInsProtoBuf.propertyGetterAnnotation,
|
||||
BuiltInsProtoBuf.propertySetterAnnotation,
|
||||
BuiltInsProtoBuf.enumEntryAnnotation,
|
||||
BuiltInsProtoBuf.compileTimeValue,
|
||||
BuiltInsProtoBuf.parameterAnnotation,
|
||||
BuiltInsProtoBuf.typeAnnotation,
|
||||
BuiltInsProtoBuf.typeParameterAnnotation
|
||||
) {
|
||||
const val BUILTINS_FILE_EXTENSION = "kotlin_builtins"
|
||||
|
||||
fun getBuiltInsFilePath(fqName: FqName): String =
|
||||
fqName.asString().replace('.', '/') + "/" + getBuiltInsFileName(
|
||||
fqName
|
||||
)
|
||||
|
||||
fun getBuiltInsFileName(fqName: FqName): String =
|
||||
shortName(fqName) + "." + BUILTINS_FILE_EXTENSION
|
||||
|
||||
private fun shortName(fqName: FqName): String =
|
||||
if (fqName.isRoot) "default-package" else fqName.shortName().asString()
|
||||
}
|
||||
Reference in New Issue
Block a user