KT-11588 Type aliases
Type alias descriptor serialization Types with type aliases serialization
This commit is contained in:
@@ -39,6 +39,8 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
|
||||
if (!checkEqualsPackageProperty(old, new)) return false
|
||||
|
||||
if (!checkEqualsPackageTypeAlias(old, new)) return false
|
||||
|
||||
if (old.hasTypeTable() != new.hasTypeTable()) return false
|
||||
if (old.hasTypeTable()) {
|
||||
if (!checkEquals(old.typeTable, new.typeTable)) return false
|
||||
@@ -54,6 +56,7 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
enum class ProtoBufPackageKind {
|
||||
FUNCTION_LIST,
|
||||
PROPERTY_LIST,
|
||||
TYPE_ALIAS_LIST,
|
||||
TYPE_TABLE,
|
||||
PACKAGE_MODULE_NAME
|
||||
}
|
||||
@@ -65,6 +68,8 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
|
||||
if (!checkEqualsPackageProperty(old, new)) result.add(ProtoBufPackageKind.PROPERTY_LIST)
|
||||
|
||||
if (!checkEqualsPackageTypeAlias(old, new)) result.add(ProtoBufPackageKind.TYPE_ALIAS_LIST)
|
||||
|
||||
if (old.hasTypeTable() != new.hasTypeTable()) result.add(ProtoBufPackageKind.TYPE_TABLE)
|
||||
if (old.hasTypeTable()) {
|
||||
if (!checkEquals(old.typeTable, new.typeTable)) result.add(ProtoBufPackageKind.TYPE_TABLE)
|
||||
@@ -105,6 +110,8 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
|
||||
if (!checkEqualsClassProperty(old, new)) return false
|
||||
|
||||
if (!checkEqualsClassTypeAlias(old, new)) return false
|
||||
|
||||
if (!checkEqualsClassEnumEntry(old, new)) return false
|
||||
|
||||
if (old.hasTypeTable() != new.hasTypeTable()) return false
|
||||
@@ -130,6 +137,7 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
CONSTRUCTOR_LIST,
|
||||
FUNCTION_LIST,
|
||||
PROPERTY_LIST,
|
||||
TYPE_ALIAS_LIST,
|
||||
ENUM_ENTRY_LIST,
|
||||
TYPE_TABLE,
|
||||
CLASS_MODULE_NAME
|
||||
@@ -164,6 +172,8 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
|
||||
if (!checkEqualsClassProperty(old, new)) result.add(ProtoBufClassKind.PROPERTY_LIST)
|
||||
|
||||
if (!checkEqualsClassTypeAlias(old, new)) result.add(ProtoBufClassKind.TYPE_ALIAS_LIST)
|
||||
|
||||
if (!checkEqualsClassEnumEntry(old, new)) result.add(ProtoBufClassKind.ENUM_ENTRY_LIST)
|
||||
|
||||
if (old.hasTypeTable() != new.hasTypeTable()) result.add(ProtoBufClassKind.TYPE_TABLE)
|
||||
@@ -287,6 +297,39 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEquals(old: ProtoBuf.TypeAlias, new: ProtoBuf.TypeAlias): Boolean {
|
||||
if (old.hasFlags() != new.hasFlags()) return false
|
||||
if (old.hasFlags()) {
|
||||
if (old.flags != new.flags) return false
|
||||
}
|
||||
|
||||
if (!checkStringEquals(old.name, new.name)) return false
|
||||
|
||||
if (!checkEqualsTypeAliasTypeParameter(old, new)) return false
|
||||
|
||||
if (old.hasUnderlyingType() != new.hasUnderlyingType()) return false
|
||||
if (old.hasUnderlyingType()) {
|
||||
if (!checkEquals(old.underlyingType, new.underlyingType)) return false
|
||||
}
|
||||
|
||||
if (old.hasUnderlyingTypeId() != new.hasUnderlyingTypeId()) return false
|
||||
if (old.hasUnderlyingTypeId()) {
|
||||
if (old.underlyingTypeId != new.underlyingTypeId) return false
|
||||
}
|
||||
|
||||
if (old.hasExpandedType() != new.hasExpandedType()) return false
|
||||
if (old.hasExpandedType()) {
|
||||
if (!checkEquals(old.expandedType, new.expandedType)) return false
|
||||
}
|
||||
|
||||
if (old.hasExpandedTypeId() != new.hasExpandedTypeId()) return false
|
||||
if (old.hasExpandedTypeId()) {
|
||||
if (old.expandedTypeId != new.expandedTypeId) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEquals(old: ProtoBuf.TypeTable, new: ProtoBuf.TypeTable): Boolean {
|
||||
if (!checkEqualsTypeTableType(old, new)) return false
|
||||
|
||||
@@ -364,6 +407,11 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
if (!checkStringEquals(old.typeParameterName, new.typeParameterName)) return false
|
||||
}
|
||||
|
||||
if (old.hasTypeAliasName() != new.hasTypeAliasName()) return false
|
||||
if (old.hasTypeAliasName()) {
|
||||
if (!checkStringEquals(old.typeAliasName, new.typeAliasName)) return false
|
||||
}
|
||||
|
||||
if (old.hasOuterType() != new.hasOuterType()) return false
|
||||
if (old.hasOuterType()) {
|
||||
if (!checkEquals(old.outerType, new.outerType)) return false
|
||||
@@ -374,6 +422,16 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
if (old.outerTypeId != new.outerTypeId) return false
|
||||
}
|
||||
|
||||
if (old.hasAbbreviatedType() != new.hasAbbreviatedType()) return false
|
||||
if (old.hasAbbreviatedType()) {
|
||||
if (!checkEquals(old.abbreviatedType, new.abbreviatedType)) return false
|
||||
}
|
||||
|
||||
if (old.hasAbbreviatedTypeId() != new.hasAbbreviatedTypeId()) return false
|
||||
if (old.hasAbbreviatedTypeId()) {
|
||||
if (old.abbreviatedTypeId != new.abbreviatedTypeId) return false
|
||||
}
|
||||
|
||||
if (old.getExtensionCount(JvmProtoBuf.typeAnnotation) != new.getExtensionCount(JvmProtoBuf.typeAnnotation)) return false
|
||||
|
||||
for(i in 0..old.getExtensionCount(JvmProtoBuf.typeAnnotation) - 1) {
|
||||
@@ -597,6 +655,16 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsPackageTypeAlias(old: ProtoBuf.Package, new: ProtoBuf.Package): Boolean {
|
||||
if (old.typeAliasCount != new.typeAliasCount) return false
|
||||
|
||||
for(i in 0..old.typeAliasCount - 1) {
|
||||
if (!checkEquals(old.getTypeAlias(i), new.getTypeAlias(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsClassTypeParameter(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||
if (old.typeParameterCount != new.typeParameterCount) return false
|
||||
|
||||
@@ -667,6 +735,16 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsClassTypeAlias(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||
if (old.typeAliasCount != new.typeAliasCount) return false
|
||||
|
||||
for(i in 0..old.typeAliasCount - 1) {
|
||||
if (!checkEquals(old.getTypeAlias(i), new.getTypeAlias(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsClassEnumEntry(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||
if (old.enumEntryCount != new.enumEntryCount) return false
|
||||
|
||||
@@ -707,6 +785,16 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsTypeAliasTypeParameter(old: ProtoBuf.TypeAlias, new: ProtoBuf.TypeAlias): Boolean {
|
||||
if (old.typeParameterCount != new.typeParameterCount) return false
|
||||
|
||||
for(i in 0..old.typeParameterCount - 1) {
|
||||
if (!checkEquals(old.getTypeParameter(i), new.getTypeParameter(i))) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
open fun checkEqualsTypeTableType(old: ProtoBuf.TypeTable, new: ProtoBuf.TypeTable): Boolean {
|
||||
if (old.typeCount != new.typeCount) return false
|
||||
|
||||
@@ -819,6 +907,10 @@ fun ProtoBuf.Package.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int)
|
||||
hashCode = 31 * hashCode + getProperty(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
for(i in 0..typeAliasCount - 1) {
|
||||
hashCode = 31 * hashCode + getTypeAlias(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
if (hasTypeTable()) {
|
||||
hashCode = 31 * hashCode + typeTable.hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
@@ -871,6 +963,10 @@ fun ProtoBuf.Class.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) ->
|
||||
hashCode = 31 * hashCode + getProperty(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
for(i in 0..typeAliasCount - 1) {
|
||||
hashCode = 31 * hashCode + getTypeAlias(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
for(i in 0..enumEntryCount - 1) {
|
||||
hashCode = 31 * hashCode + getEnumEntry(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
@@ -986,6 +1082,38 @@ fun ProtoBuf.Property.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int)
|
||||
return hashCode
|
||||
}
|
||||
|
||||
fun ProtoBuf.TypeAlias.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||
var hashCode = 1
|
||||
|
||||
if (hasFlags()) {
|
||||
hashCode = 31 * hashCode + flags
|
||||
}
|
||||
|
||||
hashCode = 31 * hashCode + stringIndexes(name)
|
||||
|
||||
for(i in 0..typeParameterCount - 1) {
|
||||
hashCode = 31 * hashCode + getTypeParameter(i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
if (hasUnderlyingType()) {
|
||||
hashCode = 31 * hashCode + underlyingType.hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
if (hasUnderlyingTypeId()) {
|
||||
hashCode = 31 * hashCode + underlyingTypeId
|
||||
}
|
||||
|
||||
if (hasExpandedType()) {
|
||||
hashCode = 31 * hashCode + expandedType.hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
if (hasExpandedTypeId()) {
|
||||
hashCode = 31 * hashCode + expandedTypeId
|
||||
}
|
||||
|
||||
return hashCode
|
||||
}
|
||||
|
||||
fun ProtoBuf.TypeTable.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||
var hashCode = 1
|
||||
|
||||
@@ -1065,6 +1193,10 @@ fun ProtoBuf.Type.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) ->
|
||||
hashCode = 31 * hashCode + stringIndexes(typeParameterName)
|
||||
}
|
||||
|
||||
if (hasTypeAliasName()) {
|
||||
hashCode = 31 * hashCode + stringIndexes(typeAliasName)
|
||||
}
|
||||
|
||||
if (hasOuterType()) {
|
||||
hashCode = 31 * hashCode + outerType.hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
@@ -1073,6 +1205,14 @@ fun ProtoBuf.Type.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) ->
|
||||
hashCode = 31 * hashCode + outerTypeId
|
||||
}
|
||||
|
||||
if (hasAbbreviatedType()) {
|
||||
hashCode = 31 * hashCode + abbreviatedType.hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
if (hasAbbreviatedTypeId()) {
|
||||
hashCode = 31 * hashCode + abbreviatedTypeId
|
||||
}
|
||||
|
||||
for(i in 0..getExtensionCount(JvmProtoBuf.typeAnnotation) - 1) {
|
||||
hashCode = 31 * hashCode + getExtension(JvmProtoBuf.typeAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -112,10 +113,15 @@ public class PackagePartCodegen extends MemberCodegen<KtFile> {
|
||||
if (declaration instanceof KtNamedFunction) {
|
||||
SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
|
||||
members.add(functionDescriptor);
|
||||
} else if (declaration instanceof KtProperty) {
|
||||
}
|
||||
else if (declaration instanceof KtProperty) {
|
||||
VariableDescriptor property = bindingContext.get(BindingContext.VARIABLE, declaration);
|
||||
members.add(property);
|
||||
}
|
||||
else if (declaration instanceof KtTypeAlias) {
|
||||
TypeAliasDescriptor typeAlias = bindingContext.get(BindingContext.TYPE_ALIAS, declaration);
|
||||
members.add(typeAlias);
|
||||
}
|
||||
}
|
||||
|
||||
final DescriptorSerializer serializer =
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.codegen.serialization
|
||||
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmNameResolver
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -53,7 +54,7 @@ class JvmStringTable(private val typeMapper: KotlinTypeMapper) : StringTable {
|
||||
return !hasPredefinedIndex() && !hasOperation() && substringIndexCount == 0 && replaceCharCount == 0
|
||||
}
|
||||
|
||||
override fun getFqNameIndex(descriptor: ClassDescriptor): Int {
|
||||
override fun getFqNameIndex(descriptor: ClassifierDescriptorWithTypeParameters): Int {
|
||||
if (ErrorUtils.isError(descriptor)) {
|
||||
throw IllegalStateException("Cannot get FQ name of error class: " + descriptor)
|
||||
}
|
||||
@@ -109,7 +110,7 @@ class JvmStringTable(private val typeMapper: KotlinTypeMapper) : StringTable {
|
||||
return index
|
||||
}
|
||||
|
||||
private val ClassDescriptor.classId: ClassId
|
||||
private val ClassifierDescriptorWithTypeParameters.classId: ClassId
|
||||
get() {
|
||||
val container = containingDeclaration
|
||||
return when (container) {
|
||||
|
||||
@@ -91,6 +91,7 @@ public interface BindingContext {
|
||||
WritableSlice<KtExpression, CompileTimeConstant<?>> COMPILE_TIME_VALUE = Slices.createSimpleSlice();
|
||||
|
||||
WritableSlice<KtTypeReference, KotlinType> TYPE = Slices.createSimpleSlice();
|
||||
WritableSlice<KtTypeReference, KotlinType> ABBREVIATED_TYPE = Slices.createSimpleSlice();
|
||||
WritableSlice<KtExpression, KotlinTypeInfo> EXPRESSION_TYPE_INFO = new BasicWritableSlice<KtExpression, KotlinTypeInfo>(DO_NOTHING);
|
||||
WritableSlice<KtExpression, KotlinType> EXPECTED_EXPRESSION_TYPE = new BasicWritableSlice<KtExpression, KotlinType>(DO_NOTHING);
|
||||
WritableSlice<KtFunction, KotlinType> EXPECTED_RETURN_TYPE = new BasicWritableSlice<KtFunction, KotlinType>(DO_NOTHING);
|
||||
@@ -216,7 +217,7 @@ public interface BindingContext {
|
||||
WritableSlice<KtParameter, VariableDescriptor> VALUE_PARAMETER = Slices.createSimpleSlice();
|
||||
WritableSlice<KtPropertyAccessor, PropertyAccessorDescriptor> PROPERTY_ACCESSOR = Slices.createSimpleSlice();
|
||||
WritableSlice<PsiElement, PropertyDescriptor> PRIMARY_CONSTRUCTOR_PARAMETER = Slices.createSimpleSlice();
|
||||
WritableSlice<KtTypeAlias, TypeAliasDescriptor> TYPE_ALIAS = Slices.createSimpleSlice();
|
||||
WritableSlice<PsiElement, TypeAliasDescriptor> TYPE_ALIAS = Slices.createSimpleSlice();
|
||||
|
||||
WritableSlice[] DECLARATIONS_TO_DESCRIPTORS = new WritableSlice[] {
|
||||
CLASS, TYPE_PARAMETER, FUNCTION, CONSTRUCTOR, VARIABLE, VALUE_PARAMETER, PROPERTY_ACCESSOR,
|
||||
|
||||
@@ -714,12 +714,21 @@ public class DescriptorResolver {
|
||||
|
||||
final KtTypeReference typeReference = typeAlias.getTypeReference();
|
||||
|
||||
typeAliasDescriptor.initialize(typeParameterDescriptors, storageManager.createLazyValue(new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace, true);
|
||||
}
|
||||
}));
|
||||
typeAliasDescriptor.initialize(
|
||||
typeParameterDescriptors,
|
||||
storageManager.createLazyValue(new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace, true);
|
||||
}
|
||||
}),
|
||||
storageManager.createLazyValue(new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
// TODO do not reparse
|
||||
return typeResolver.resolveType(scopeWithTypeParameters, typeReference, trace, true);
|
||||
}
|
||||
}));
|
||||
|
||||
trace.record(TYPE_ALIAS, typeAlias, typeAliasDescriptor);
|
||||
return typeAliasDescriptor;
|
||||
|
||||
@@ -371,7 +371,7 @@ class QualifiedExpressionResolver(val symbolUsageValidator: SymbolUsageValidator
|
||||
val nextPackageOrClassDescriptor =
|
||||
when (currentDescriptor) {
|
||||
is TypeAliasDescriptor -> // TODO type aliases as qualifiers? (would break some assumptions in TypeResolver)
|
||||
currentDescriptor.underlyingClassDescriptor.getContributedClassifier(qualifierPart)
|
||||
currentDescriptor.classDescriptor?.getContributedClassifier(qualifierPart)
|
||||
is ClassDescriptor ->
|
||||
currentDescriptor.getContributedClassifier(qualifierPart)
|
||||
is PackageViewDescriptor -> {
|
||||
|
||||
@@ -81,9 +81,11 @@ class TypeResolver(
|
||||
val cachedType = c.trace.getBindingContext().get(BindingContext.TYPE, typeReference)
|
||||
if (cachedType != null) return type(cachedType)
|
||||
|
||||
val resolvedTypeSlice = if (c.abbreviated) BindingContext.ABBREVIATED_TYPE else BindingContext.TYPE
|
||||
|
||||
val debugType = typeReference.debugTypeInfo
|
||||
if (debugType != null) {
|
||||
c.trace.record(BindingContext.TYPE, typeReference, debugType)
|
||||
c.trace.record(resolvedTypeSlice, typeReference, debugType)
|
||||
return type(debugType)
|
||||
}
|
||||
|
||||
@@ -100,13 +102,13 @@ class TypeResolver(
|
||||
}
|
||||
|
||||
val lazyKotlinType = LazyKotlinType()
|
||||
c.trace.record(BindingContext.TYPE, typeReference, lazyKotlinType)
|
||||
c.trace.record(resolvedTypeSlice, typeReference, lazyKotlinType)
|
||||
return type(lazyKotlinType)
|
||||
}
|
||||
|
||||
val type = doResolvePossiblyBareType(c, typeReference)
|
||||
if (!type.isBare()) {
|
||||
c.trace.record(BindingContext.TYPE, typeReference, type.getActualType())
|
||||
c.trace.record(resolvedTypeSlice, typeReference, type.getActualType())
|
||||
}
|
||||
return type
|
||||
}
|
||||
|
||||
+22
-10
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
@@ -40,24 +41,35 @@ class TypeAliasDescriptorImpl(
|
||||
TypeAliasDescriptor {
|
||||
|
||||
// TODO kotlinize some interfaces
|
||||
private lateinit var fDeclaredTypeParameters: List<TypeParameterDescriptor>
|
||||
private lateinit var lazyUnderlyingType: NotNullLazyValue<KotlinType>
|
||||
private lateinit var declaredTypeParametersImpl: List<TypeParameterDescriptor>
|
||||
private lateinit var underlyingTypeImpl: NotNullLazyValue<KotlinType>
|
||||
private lateinit var expandedTypeImpl: NotNullLazyValue<KotlinType>
|
||||
|
||||
override val underlyingType: KotlinType get() = lazyUnderlyingType()
|
||||
override val underlyingType: KotlinType get() = underlyingTypeImpl()
|
||||
override val expandedType: KotlinType get() = expandedTypeImpl()
|
||||
|
||||
fun initialize(declaredTypeParameters: List<TypeParameterDescriptor>, lazyUnderlyingType: NotNullLazyValue<KotlinType>) {
|
||||
this.fDeclaredTypeParameters = declaredTypeParameters
|
||||
this.lazyUnderlyingType = lazyUnderlyingType
|
||||
fun initialize(
|
||||
declaredTypeParameters: List<TypeParameterDescriptor>,
|
||||
lazyUnderlyingType: NotNullLazyValue<KotlinType>,
|
||||
lazyExpandedType: NotNullLazyValue<KotlinType>
|
||||
) {
|
||||
this.declaredTypeParametersImpl = declaredTypeParameters
|
||||
this.underlyingTypeImpl = lazyUnderlyingType
|
||||
this.expandedTypeImpl = lazyExpandedType
|
||||
}
|
||||
|
||||
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypeAliasDescriptor(this, data)
|
||||
|
||||
override fun getDeclaredTypeParameters(): List<TypeParameterDescriptor> =
|
||||
fDeclaredTypeParameters
|
||||
override fun isInner(): Boolean = false // TODO treat all nested type aliases as inner?
|
||||
|
||||
override val underlyingClassDescriptor: ClassDescriptor
|
||||
get() = underlyingType.constructor.declarationDescriptor as ClassDescriptor // TODO
|
||||
override fun getDeclaredTypeParameters(): List<TypeParameterDescriptor> =
|
||||
declaredTypeParametersImpl
|
||||
|
||||
override val classDescriptor: ClassDescriptor?
|
||||
get() = expandedType.let { expandedType ->
|
||||
if (expandedType.isError) null else expandedType.constructor.declarationDescriptor as ClassDescriptor
|
||||
}
|
||||
|
||||
override fun getModality() = Modality.FINAL
|
||||
|
||||
|
||||
+44
-3
@@ -135,7 +135,7 @@ public class DescriptorSerializer {
|
||||
builder.setFlags(flags);
|
||||
}
|
||||
|
||||
builder.setFqName(getClassId(classDescriptor));
|
||||
builder.setFqName(getClassifierId(classDescriptor));
|
||||
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getDeclaredTypeParameters()) {
|
||||
builder.addTypeParameter(typeParameter(typeParameterDescriptor));
|
||||
@@ -357,6 +357,32 @@ public class DescriptorSerializer {
|
||||
return builder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ProtoBuf.TypeAlias.Builder typeAliasProto(@NotNull TypeAliasDescriptor descriptor) {
|
||||
ProtoBuf.TypeAlias.Builder builder = ProtoBuf.TypeAlias.newBuilder();
|
||||
|
||||
int flags = Flags.getTypeAliasFlags(hasAnnotations(descriptor), descriptor.getVisibility());
|
||||
if (flags != builder.getFlags()) {
|
||||
builder.setFlags(flags);
|
||||
}
|
||||
|
||||
builder.setName(getSimpleNameIndex(descriptor.getName()));
|
||||
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : descriptor.getDeclaredTypeParameters()) {
|
||||
builder.addTypeParameter(typeParameter(typeParameterDescriptor));
|
||||
}
|
||||
|
||||
KotlinType underlyingType = descriptor.getUnderlyingType();
|
||||
if (useTypeTable()) {
|
||||
builder.setUnderlyingTypeId(typeId(underlyingType));
|
||||
}
|
||||
else {
|
||||
builder.setUnderlyingType(type(underlyingType));
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ProtoBuf.EnumEntry.Builder enumEntryProto(@NotNull ClassDescriptor descriptor) {
|
||||
ProtoBuf.EnumEntry.Builder builder = ProtoBuf.EnumEntry.newBuilder();
|
||||
@@ -499,6 +525,11 @@ public class DescriptorSerializer {
|
||||
|
||||
assert type.getArguments().isEmpty() : "Found arguments for type constructor build on type parameter: " + descriptor;
|
||||
}
|
||||
if (descriptor instanceof TypeAliasDescriptor) {
|
||||
PossiblyInnerType possiblyInnerType = TypeParameterUtilsKt.buildPossiblyInnerType(type);
|
||||
assert possiblyInnerType != null : "possiblyInnerType should not be null in case of type alias";
|
||||
fillFromPossiblyInnerType(builder, possiblyInnerType);
|
||||
}
|
||||
|
||||
if (type.isMarkedNullable() != builder.getNullable()) {
|
||||
builder.setNullable(type.isMarkedNullable());
|
||||
@@ -513,7 +544,14 @@ public class DescriptorSerializer {
|
||||
@NotNull ProtoBuf.Type.Builder builder,
|
||||
@NotNull PossiblyInnerType type
|
||||
) {
|
||||
builder.setClassName(getClassId(type.getClassDescriptor()));
|
||||
ClassifierDescriptorWithTypeParameters classifierDescriptor = type.getClassifierDescriptor();
|
||||
int classifierId = getClassifierId(classifierDescriptor);
|
||||
if (classifierDescriptor instanceof ClassDescriptor) {
|
||||
builder.setClassName(classifierId);
|
||||
}
|
||||
else {
|
||||
builder.setTypeAliasName(classifierId);
|
||||
}
|
||||
|
||||
for (TypeProjection projection : type.getArguments()) {
|
||||
builder.addArgument(typeArgument(projection));
|
||||
@@ -606,6 +644,9 @@ public class DescriptorSerializer {
|
||||
else if (declaration instanceof FunctionDescriptor) {
|
||||
builder.addFunction(functionProto((FunctionDescriptor) declaration));
|
||||
}
|
||||
else if (declaration instanceof TypeAliasDescriptor) {
|
||||
builder.addTypeAlias(typeAliasProto((TypeAliasDescriptor) declaration));
|
||||
}
|
||||
}
|
||||
|
||||
ProtoBuf.TypeTable typeTableProto = typeTable.serialize();
|
||||
@@ -631,7 +672,7 @@ public class DescriptorSerializer {
|
||||
throw new IllegalStateException("Unknown projectionKind: " + projectionKind);
|
||||
}
|
||||
|
||||
private int getClassId(@NotNull ClassDescriptor descriptor) {
|
||||
private int getClassifierId(@NotNull ClassifierDescriptorWithTypeParameters descriptor) {
|
||||
return getStringTable().getFqNameIndex(descriptor);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,14 @@ package org.jetbrains.kotlin.serialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface StringTable {
|
||||
int getStringIndex(@NotNull String string);
|
||||
|
||||
int getFqNameIndex(@NotNull ClassDescriptor descriptor);
|
||||
int getFqNameIndex(@NotNull ClassifierDescriptorWithTypeParameters descriptor);
|
||||
|
||||
void serializeTo(@NotNull OutputStream output);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.serialization;
|
||||
import kotlin.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
@@ -73,7 +74,7 @@ public class StringTableImpl implements StringTable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFqNameIndex(@NotNull ClassDescriptor descriptor) {
|
||||
public int getFqNameIndex(@NotNull ClassifierDescriptorWithTypeParameters descriptor) {
|
||||
if (ErrorUtils.isError(descriptor)) {
|
||||
throw new IllegalStateException("Cannot get FQ name of error class: " + descriptor);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public val x: WithVariance<kotlin.Int, kotlin.Int> [= kotlin.Int] = 0
|
||||
public typealias WithBounds1</*0*/ T : [ERROR : Cyclic upper bounds]> = kotlin.Int
|
||||
public typealias WithBounds2</*0*/ X : [ERROR : Cyclic upper bounds], /*1*/ Y : [ERROR : Cyclic upper bounds]> = kotlin.Int
|
||||
public typealias WithVariance</*0*/ in X, /*1*/ out Y> = kotlin.Int
|
||||
public val x: WithVariance<kotlin.Int, kotlin.Int> [= kotlin.Int] = 0
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package
|
||||
|
||||
public typealias CA</*0*/ T> = C<T>
|
||||
public val ca1: CA<kotlin.Int> [= C<kotlin.Int>]
|
||||
public val ca2: CA<CA<kotlin.Int> [= C<kotlin.Int>]> [= C<CA<kotlin.Int> [= C<kotlin.Int>]>]
|
||||
public val ca3: CA<C<kotlin.Int>> [= C<C<kotlin.Int>>]
|
||||
@@ -11,4 +12,3 @@ public final class C</*0*/ T> {
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
public typealias CA</*0*/ T> = C<T>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package
|
||||
|
||||
public val x: [ERROR : Recursive type alias: A]
|
||||
public typealias A = B
|
||||
public typealias B = A
|
||||
public val x: [ERROR : Recursive type alias: A]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package
|
||||
|
||||
public typealias S = kotlin.String
|
||||
public typealias SS = S
|
||||
public typealias SSS = SS
|
||||
public val s1: SSS [= kotlin.String] = ""
|
||||
public val s2: SSS [= kotlin.String?] = null
|
||||
public val s3: kotlin.collections.List<SSS [= kotlin.String]>? = null
|
||||
public val s4: kotlin.collections.List<kotlin.collections.List<SSS [= kotlin.String]>?>? = null
|
||||
public typealias S = kotlin.String
|
||||
public typealias SS = S
|
||||
public typealias SSS = SS
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
package
|
||||
|
||||
public typealias In1</*0*/ T> = In<T>
|
||||
public typealias In2</*0*/ T> = In<in T>
|
||||
public typealias In3</*0*/ T> = In<out T>
|
||||
public typealias In4</*0*/ T> = In<*>
|
||||
public typealias Inv1</*0*/ T> = Inv<T>
|
||||
public typealias Inv2</*0*/ T> = Inv<in T>
|
||||
public typealias Inv3</*0*/ T> = Inv<out T>
|
||||
public typealias Inv4</*0*/ T> = Inv<*>
|
||||
public typealias Out1</*0*/ T> = Out<T>
|
||||
public typealias Out2</*0*/ T> = Out<in T>
|
||||
public typealias Out3</*0*/ T> = Out<out T>
|
||||
public typealias Out4</*0*/ T> = Out<*>
|
||||
public val inv1: Inv1<kotlin.Int> [= Inv<kotlin.Int>]
|
||||
|
||||
public final class In</*0*/ in T> {
|
||||
@@ -22,15 +34,3 @@ public final class Out</*0*/ out T> {
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
public typealias In1</*0*/ T> = In<T>
|
||||
public typealias In2</*0*/ T> = In<in T>
|
||||
public typealias In3</*0*/ T> = In<out T>
|
||||
public typealias In4</*0*/ T> = In<*>
|
||||
public typealias Inv1</*0*/ T> = Inv<T>
|
||||
public typealias Inv2</*0*/ T> = Inv<in T>
|
||||
public typealias Inv3</*0*/ T> = Inv<out T>
|
||||
public typealias Inv4</*0*/ T> = Inv<*>
|
||||
public typealias Out1</*0*/ T> = Out<T>
|
||||
public typealias Out2</*0*/ T> = Out<in T>
|
||||
public typealias Out3</*0*/ T> = Out<out T>
|
||||
public typealias Out4</*0*/ T> = Out<*>
|
||||
|
||||
@@ -80,11 +80,6 @@ public interface ClassDescriptor extends ClassifierDescriptorWithTypeParameters,
|
||||
@NotNull
|
||||
Visibility getVisibility();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if this class contains a reference to its outer class (as opposed to static nested class)
|
||||
*/
|
||||
boolean isInner();
|
||||
|
||||
boolean isCompanionObject();
|
||||
|
||||
boolean isData();
|
||||
|
||||
+5
@@ -22,6 +22,11 @@ import org.jetbrains.annotations.ReadOnly;
|
||||
import java.util.List;
|
||||
|
||||
public interface ClassifierDescriptorWithTypeParameters extends ClassifierDescriptor {
|
||||
/**
|
||||
* @return <code>true</code> if this class contains a reference to its outer class (as opposed to static nested class)
|
||||
*/
|
||||
boolean isInner();
|
||||
|
||||
@ReadOnly
|
||||
@NotNull
|
||||
List<TypeParameterDescriptor> getDeclaredTypeParameters();
|
||||
|
||||
@@ -22,7 +22,9 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
interface TypeAliasDescriptor : ClassifierDescriptorWithTypeParameters, MemberDescriptor {
|
||||
val underlyingType: KotlinType
|
||||
|
||||
val underlyingClassDescriptor: ClassDescriptor
|
||||
val expandedType: KotlinType
|
||||
|
||||
val classDescriptor: ClassDescriptor?
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor): TypeAliasDescriptor
|
||||
}
|
||||
|
||||
@@ -60,17 +60,21 @@ private class CapturedTypeParameterDescriptor(
|
||||
}
|
||||
|
||||
class PossiblyInnerType(
|
||||
val classDescriptor: ClassDescriptor,
|
||||
val classifierDescriptor: ClassifierDescriptorWithTypeParameters,
|
||||
val arguments: List<TypeProjection>,
|
||||
val outerType: PossiblyInnerType?) {
|
||||
val outerType: PossiblyInnerType?
|
||||
) {
|
||||
val classDescriptor: ClassDescriptor
|
||||
get() = classifierDescriptor as ClassDescriptor
|
||||
|
||||
fun segments(): List<PossiblyInnerType> = outerType?.segments().orEmpty() + this
|
||||
}
|
||||
|
||||
fun KotlinType.buildPossiblyInnerType(): PossiblyInnerType? {
|
||||
return buildPossiblyInnerType(constructor.declarationDescriptor as? ClassDescriptor, 0)
|
||||
return buildPossiblyInnerType(constructor.declarationDescriptor as? ClassifierDescriptorWithTypeParameters, 0)
|
||||
}
|
||||
|
||||
private fun KotlinType.buildPossiblyInnerType(classDescriptor: ClassDescriptor?, index: Int): PossiblyInnerType? {
|
||||
private fun KotlinType.buildPossiblyInnerType(classDescriptor: ClassifierDescriptorWithTypeParameters?, index: Int): PossiblyInnerType? {
|
||||
if (classDescriptor == null || ErrorUtils.isError(classDescriptor)) return null
|
||||
|
||||
val toIndex = classDescriptor.declaredTypeParameters.size + index
|
||||
@@ -85,5 +89,5 @@ private fun KotlinType.buildPossiblyInnerType(classDescriptor: ClassDescriptor?,
|
||||
val argumentsSubList = arguments.subList(index, toIndex)
|
||||
return PossiblyInnerType(
|
||||
classDescriptor, argumentsSubList,
|
||||
buildPossiblyInnerType(classDescriptor.containingDeclaration as? ClassDescriptor, toIndex))
|
||||
buildPossiblyInnerType(classDescriptor.containingDeclaration as? ClassifierDescriptorWithTypeParameters, toIndex))
|
||||
}
|
||||
|
||||
@@ -273,8 +273,8 @@ internal class DescriptorRendererImpl(
|
||||
possiblyInnerType.outerType?.let {
|
||||
append(renderPossiblyInnerType(it))
|
||||
append('.')
|
||||
append(renderName(possiblyInnerType.classDescriptor.name))
|
||||
} ?: append(renderTypeConstructor(possiblyInnerType.classDescriptor.typeConstructor))
|
||||
append(renderName(possiblyInnerType.classifierDescriptor.name))
|
||||
} ?: append(renderTypeConstructor(possiblyInnerType.classifierDescriptor.typeConstructor))
|
||||
|
||||
append(renderTypeArguments(possiblyInnerType.arguments))
|
||||
}
|
||||
|
||||
@@ -48,7 +48,10 @@ public class MemberComparator implements Comparator<DeclarationDescriptor> {
|
||||
}
|
||||
|
||||
private static int getDeclarationPriority(DeclarationDescriptor descriptor) {
|
||||
if (isEnumEntry(descriptor)) {
|
||||
if (descriptor instanceof TypeAliasDescriptor) {
|
||||
return 8;
|
||||
}
|
||||
else if (isEnumEntry(descriptor)) {
|
||||
return 7;
|
||||
}
|
||||
else if (descriptor instanceof ConstructorDescriptor) {
|
||||
@@ -92,7 +95,17 @@ public class MemberComparator implements Comparator<DeclarationDescriptor> {
|
||||
return namesCompareTo;
|
||||
}
|
||||
|
||||
if (o1 instanceof CallableDescriptor && o2 instanceof CallableDescriptor) {
|
||||
if (o1 instanceof TypeAliasDescriptor && o2 instanceof TypeAliasDescriptor) {
|
||||
TypeAliasDescriptor ta1 = (TypeAliasDescriptor) o1;
|
||||
TypeAliasDescriptor ta2 = (TypeAliasDescriptor) o2;
|
||||
String r1 = RENDERER.renderType(ta1.getUnderlyingType());
|
||||
String r2 = RENDERER.renderType(ta2.getUnderlyingType());
|
||||
int underlyingTypesCompareTo = r1.compareTo(r2);
|
||||
if (underlyingTypesCompareTo != 0) {
|
||||
return underlyingTypesCompareTo;
|
||||
}
|
||||
}
|
||||
else if (o1 instanceof CallableDescriptor && o2 instanceof CallableDescriptor) {
|
||||
CallableDescriptor c1 = (CallableDescriptor) o1;
|
||||
CallableDescriptor c2 = (CallableDescriptor) o2;
|
||||
|
||||
|
||||
@@ -128,10 +128,14 @@ message Type {
|
||||
optional int32 type_parameter = 7; // id of the type parameter
|
||||
// Name of the type parameter in the immediate owner
|
||||
optional int32 type_parameter_name = 9 [(name_id_in_table) = true];
|
||||
optional int32 type_alias_name = 12 [(name_id_in_table) = true];
|
||||
|
||||
optional Type outer_type = 10;
|
||||
optional int32 outer_type_id = 11;
|
||||
|
||||
optional Type abbreviated_type = 13;
|
||||
optional int32 abbreviated_type_id = 14;
|
||||
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
@@ -191,6 +195,7 @@ message Class {
|
||||
repeated Constructor constructor = 8;
|
||||
repeated Function function = 9;
|
||||
repeated Property property = 10;
|
||||
repeated TypeAlias type_alias = 11;
|
||||
|
||||
repeated EnumEntry enum_entry = 13;
|
||||
|
||||
@@ -202,6 +207,7 @@ message Class {
|
||||
message Package {
|
||||
repeated Function function = 3;
|
||||
repeated Property property = 4;
|
||||
repeated TypeAlias type_alias = 5;
|
||||
|
||||
optional TypeTable type_table = 30;
|
||||
|
||||
@@ -322,6 +328,26 @@ message ValueParameter {
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
message TypeAlias {
|
||||
/*
|
||||
hasAnnotations
|
||||
Visibility
|
||||
*/
|
||||
optional int32 flags = 1 [default = 0];
|
||||
|
||||
required int32 name = 2 [(name_id_in_table) = true];
|
||||
|
||||
repeated TypeParameter type_parameter = 3;
|
||||
|
||||
optional Type underlying_type = 4;
|
||||
optional int32 underlying_type_id = 5;
|
||||
|
||||
optional Type expanded_type = 6;
|
||||
optional int32 expanded_type_id = 7;
|
||||
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
message EnumEntry {
|
||||
optional int32 name = 1 [(name_id_in_table) = true];
|
||||
|
||||
|
||||
@@ -252,6 +252,12 @@ public class Flags {
|
||||
;
|
||||
}
|
||||
|
||||
public static int getTypeAliasFlags(boolean hasAnnotations, Visibility visibility) {
|
||||
return HAS_ANNOTATIONS.toFlags(hasAnnotations)
|
||||
| VISIBILITY.toFlags(visibility(visibility))
|
||||
;
|
||||
}
|
||||
|
||||
// Infrastructure
|
||||
|
||||
public static abstract class FlagField<E> {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user