KT-11588 Type aliases
Deserialization
This commit is contained in:
@@ -46,7 +46,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.TypeAliasDescriptorImpl;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyTypeAliasDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.scopes.*;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
@@ -688,7 +688,7 @@ public class DescriptorResolver {
|
||||
Annotations allAnnotations = annotationResolver.resolveAnnotationsWithArguments(scope, modifierList, trace);
|
||||
Name name = KtPsiUtil.safeName(typeAlias.getName());
|
||||
SourceElement sourceElement = KotlinSourceElementKt.toSourceElement(typeAlias);
|
||||
TypeAliasDescriptorImpl typeAliasDescriptor = TypeAliasDescriptorImpl.create(
|
||||
LazyTypeAliasDescriptor typeAliasDescriptor = LazyTypeAliasDescriptor.create(
|
||||
containingDeclaration, allAnnotations, name, sourceElement, visibility);
|
||||
|
||||
List<TypeParameterDescriptorImpl> typeParameterDescriptors;
|
||||
|
||||
@@ -484,15 +484,6 @@ class TypeResolver(
|
||||
}
|
||||
}
|
||||
|
||||
private class AbbreviatedTypeImpl(override val abbreviatedType: KotlinType): AbbreviatedType
|
||||
|
||||
private fun KotlinType.withAbbreviatedType(abbreviatedType: KotlinType): KotlinType =
|
||||
if (isError)
|
||||
this
|
||||
else
|
||||
replace(newCapabilities = capabilities.overrideCapability(AbbreviatedType::class.java,
|
||||
AbbreviatedTypeImpl(abbreviatedType)))
|
||||
|
||||
private class TypeAliasExpansion(
|
||||
val parent: TypeAliasExpansion?,
|
||||
val descriptor: TypeAliasDescriptor,
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.resolve.lazy.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.AbstractTypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class LazyTypeAliasDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
sourceElement: SourceElement,
|
||||
visibility: Visibility
|
||||
) : AbstractTypeAliasDescriptor(containingDeclaration, annotations, name, sourceElement, visibility),
|
||||
TypeAliasDescriptor {
|
||||
|
||||
private lateinit var underlyingTypeImpl: NotNullLazyValue<KotlinType>
|
||||
private lateinit var expandedTypeImpl: NotNullLazyValue<KotlinType>
|
||||
|
||||
override val underlyingType: KotlinType get() = underlyingTypeImpl()
|
||||
override val expandedType: KotlinType get() = expandedTypeImpl()
|
||||
|
||||
fun initialize(
|
||||
declaredTypeParameters: List<TypeParameterDescriptor>,
|
||||
lazyUnderlyingType: NotNullLazyValue<KotlinType>,
|
||||
lazyExpandedType: NotNullLazyValue<KotlinType>
|
||||
) {
|
||||
super.initialize(declaredTypeParameters)
|
||||
this.underlyingTypeImpl = lazyUnderlyingType
|
||||
this.expandedTypeImpl = lazyExpandedType
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic fun create(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
sourceElement: SourceElement,
|
||||
visibility: Visibility
|
||||
): LazyTypeAliasDescriptor =
|
||||
LazyTypeAliasDescriptor(containingDeclaration, annotations, name, sourceElement, visibility)
|
||||
}
|
||||
}
|
||||
-123
@@ -1,123 +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.resolve.lazy.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorNonRootImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
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
|
||||
|
||||
class TypeAliasDescriptorImpl(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
sourceElement: SourceElement,
|
||||
private val fVisibility: Visibility
|
||||
) : DeclarationDescriptorNonRootImpl(containingDeclaration, annotations, name, sourceElement),
|
||||
TypeAliasDescriptor {
|
||||
|
||||
// TODO kotlinize some interfaces
|
||||
private lateinit var declaredTypeParametersImpl: List<TypeParameterDescriptor>
|
||||
private lateinit var underlyingTypeImpl: NotNullLazyValue<KotlinType>
|
||||
private lateinit var expandedTypeImpl: NotNullLazyValue<KotlinType>
|
||||
|
||||
override val underlyingType: KotlinType get() = underlyingTypeImpl()
|
||||
override val expandedType: KotlinType get() = expandedTypeImpl()
|
||||
|
||||
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 isInner(): Boolean = false // TODO treat all nested type aliases as inner?
|
||||
|
||||
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
|
||||
|
||||
override fun getVisibility() = fVisibility
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor): TypeAliasDescriptor =
|
||||
if (substitutor.isEmpty) this
|
||||
else TODO("typealias doSubstitute")
|
||||
|
||||
override fun getDefaultType(): KotlinType =
|
||||
TODO("typealias getDefaultType")
|
||||
|
||||
override fun getTypeConstructor(): TypeConstructor =
|
||||
typeConstructor
|
||||
|
||||
override fun toString(): String = "typealias ${name.asString()}"
|
||||
|
||||
private val typeConstructor = object : TypeConstructor {
|
||||
override fun getDeclarationDescriptor(): TypeAliasDescriptor =
|
||||
this@TypeAliasDescriptorImpl
|
||||
|
||||
override fun getParameters(): List<TypeParameterDescriptor> =
|
||||
declarationDescriptor.declaredTypeParameters // TODO type parameters of outer class
|
||||
|
||||
override fun getSupertypes(): Collection<KotlinType> =
|
||||
declarationDescriptor.underlyingType.constructor.supertypes
|
||||
|
||||
override fun isFinal(): Boolean =
|
||||
declarationDescriptor.underlyingType.constructor.isFinal
|
||||
|
||||
override fun isDenotable(): Boolean =
|
||||
true
|
||||
|
||||
override fun getBuiltIns(): KotlinBuiltIns =
|
||||
declarationDescriptor.builtIns
|
||||
|
||||
override fun getAnnotations(): Annotations =
|
||||
declarationDescriptor.annotations
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic fun create(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
sourceElement: SourceElement,
|
||||
visibility: Visibility
|
||||
): TypeAliasDescriptorImpl =
|
||||
TypeAliasDescriptorImpl(containingDeclaration, annotations, name, sourceElement, visibility)
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -380,6 +380,14 @@ public class DescriptorSerializer {
|
||||
builder.setUnderlyingType(type(underlyingType));
|
||||
}
|
||||
|
||||
KotlinType expandedType = descriptor.getExpandedType();
|
||||
if (useTypeTable()) {
|
||||
builder.setExpandedTypeId(typeId(expandedType));
|
||||
}
|
||||
else {
|
||||
builder.setExpandedType(type(expandedType));
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -535,6 +543,16 @@ public class DescriptorSerializer {
|
||||
builder.setNullable(type.isMarkedNullable());
|
||||
}
|
||||
|
||||
KotlinType abbreviatedType = TypeCapabilitiesKt.getAbbreviatedType(type);
|
||||
if (abbreviatedType != null) {
|
||||
if (useTypeTable()) {
|
||||
builder.setAbbreviatedTypeId(typeId(abbreviatedType));
|
||||
}
|
||||
else {
|
||||
builder.setAbbreviatedType(type(abbreviatedType));
|
||||
}
|
||||
}
|
||||
|
||||
extension.serializeType(type, builder);
|
||||
|
||||
return builder;
|
||||
@@ -549,7 +567,7 @@ public class DescriptorSerializer {
|
||||
if (classifierDescriptor instanceof ClassDescriptor) {
|
||||
builder.setClassName(classifierId);
|
||||
}
|
||||
else {
|
||||
else if (classifierDescriptor instanceof TypeAliasDescriptor) {
|
||||
builder.setTypeAliasName(classifierId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user