Implement raw types (de)serialization via special TypeCapabilities
This commit is contained in:
@@ -88,6 +88,7 @@ extend org.jetbrains.kotlin.serialization.Callable {
|
||||
|
||||
extend org.jetbrains.kotlin.serialization.Type {
|
||||
repeated Annotation type_annotation = 100;
|
||||
optional bool is_raw = 101;
|
||||
}
|
||||
|
||||
extend org.jetbrains.kotlin.serialization.Callable.ValueParameter {
|
||||
|
||||
+2
-2
@@ -259,8 +259,8 @@ class LazyJavaTypeResolver(
|
||||
}
|
||||
}
|
||||
|
||||
override fun computeCustomSubstitution() = if (isRaw()) RawSubstitution else null
|
||||
|
||||
override fun getCapabilities(): TypeCapabilities = if (isRaw()) RawTypeCapabilities else TypeCapabilities.NONE
|
||||
|
||||
private val nullable = c.storageManager.createLazyValue l@ {
|
||||
when (attr.flexibility) {
|
||||
FLEXIBLE_LOWER_BOUND -> return@l false
|
||||
|
||||
+16
-1
@@ -22,6 +22,20 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||
import org.jetbrains.kotlin.types.*
|
||||
|
||||
public object RawTypeCapabilities : TypeCapabilities {
|
||||
private object RawSubstitutionCapability : CustomSubstitutionCapability {
|
||||
override val substitution = RawSubstitution
|
||||
}
|
||||
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||
@suppress("UNCHECKED_CAST")
|
||||
return when(capabilityClass) {
|
||||
javaClass<CustomSubstitutionCapability>() -> RawSubstitutionCapability as T
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object RawSubstitution : TypeSubstitution() {
|
||||
override fun get(key: JetType) = TypeProjectionImpl(eraseType(key))
|
||||
|
||||
@@ -64,7 +78,8 @@ private object RawSubstitution : TypeSubstitution() {
|
||||
computeProjection(parameter, attr)
|
||||
},
|
||||
RawSubstitution,
|
||||
declaration.getMemberScope(RawSubstitution)
|
||||
declaration.getMemberScope(RawSubstitution),
|
||||
RawTypeCapabilities
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -110,7 +110,8 @@ private fun JetType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers, i
|
||||
newSubstitution,
|
||||
if (enhancedClassifier is ClassDescriptor)
|
||||
enhancedClassifier.getMemberScope(newSubstitution)
|
||||
else enhancedClassifier.getDefaultType().getMemberScope()
|
||||
else enhancedClassifier.getDefaultType().getMemberScope(),
|
||||
capabilities
|
||||
)
|
||||
return Result(enhancedType, globalArgIndex - index)
|
||||
}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class DeserializationComponentsForJava(
|
||||
val localClassResolver = LocalClassResolverImpl()
|
||||
components = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, classDataFinder, annotationAndConstantLoader, packageFragmentProvider,
|
||||
localClassResolver, JavaFlexibleTypeCapabilitiesDeserializer, ClassDescriptorFactory.EMPTY
|
||||
localClassResolver, JavaFlexibleTypeCapabilitiesDeserializer, ClassDescriptorFactory.EMPTY, JavaTypeCapabilitiesLoader
|
||||
)
|
||||
localClassResolver.setDeserializationComponents(components)
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.load.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.RawTypeCapabilities
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeCapabilitiesLoader
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
|
||||
import org.jetbrains.kotlin.types.TypeCapabilities
|
||||
|
||||
public object JavaTypeCapabilitiesLoader : TypeCapabilitiesLoader() {
|
||||
override fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities =
|
||||
if (type.hasExtension(JvmProtoBuf.isRaw)) RawTypeCapabilities else TypeCapabilities.NONE
|
||||
}
|
||||
+16
@@ -11,6 +11,7 @@ public final class JvmProtoBuf {
|
||||
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.propertySignature);
|
||||
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.implClassName);
|
||||
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.typeAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.isRaw);
|
||||
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.index);
|
||||
registry.add(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf.classAnnotation);
|
||||
}
|
||||
@@ -2866,6 +2867,21 @@ public final class JvmProtoBuf {
|
||||
100,
|
||||
com.google.protobuf.WireFormat.FieldType.MESSAGE,
|
||||
false);
|
||||
public static final int IS_RAW_FIELD_NUMBER = 101;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Type { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Type,
|
||||
java.lang.Boolean> isRaw = com.google.protobuf.GeneratedMessageLite
|
||||
.newSingularGeneratedExtension(
|
||||
org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance(),
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
101,
|
||||
com.google.protobuf.WireFormat.FieldType.BOOL);
|
||||
public static final int INDEX_FIELD_NUMBER = 100;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.serialization.Callable.ValueParameter { ... }</code>
|
||||
|
||||
Reference in New Issue
Block a user