@@ -18,22 +18,16 @@ package org.jetbrains.kotlin.serialization.deserialization
18
18
19
19
import org.jetbrains.kotlin.descriptors.*
20
20
import org.jetbrains.kotlin.descriptors.annotations.Annotations
21
- import org.jetbrains.kotlin.descriptors.impl.AbstractTypeAliasDescriptor
22
21
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorBase
23
22
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
24
23
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
25
24
import org.jetbrains.kotlin.name.ClassId
26
25
import org.jetbrains.kotlin.name.FqName
27
26
import org.jetbrains.kotlin.name.Name
28
- import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
29
- import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
30
27
import org.jetbrains.kotlin.resolve.descriptorUtil.module
31
28
import org.jetbrains.kotlin.resolve.scopes.MemberScope
32
29
import org.jetbrains.kotlin.storage.StorageManager
33
- import org.jetbrains.kotlin.storage.getValue
34
30
import org.jetbrains.kotlin.types.ClassTypeConstructorImpl
35
- import org.jetbrains.kotlin.types.SimpleType
36
- import org.jetbrains.kotlin.types.TypeSubstitutor
37
31
import org.jetbrains.kotlin.types.Variance
38
32
39
33
class NotFoundClasses (private val storageManager : StorageManager , private val module : ModuleDescriptor ) {
@@ -46,28 +40,7 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
46
40
EmptyPackageFragmentDescriptor (module, fqName)
47
41
}
48
42
49
- private val classes = storageManager.createMemoizedFunction<ClassRequest , ClassDescriptor > { request ->
50
- computeClassifier(request, {
51
- owner, name, isInner, numberOfTypeParametersCount ->
52
- MockClassDescriptor (storageManager, owner, name, isInner, numberOfTypeParametersCount)
53
- })
54
- }
55
-
56
- private val typeAliases = storageManager.createMemoizedFunction<ClassRequest , TypeAliasDescriptor > { request ->
57
- computeClassifier(request, {
58
- owner, name, isInner, numberOfTypeParametersCount ->
59
- MockTypeAliasDescriptor (storageManager, owner, name, isInner, numberOfTypeParametersCount)
60
- })
61
- }
62
-
63
- // TODO: Uncomment this when KT-12871 is fixed
64
- // private typealias ConstructorFunction<D> = (DeclarationDescriptor, Name, isInner: Boolean, numberOfTypeParametersCount: Int) -> D
65
- private fun <D > computeClassifier (
66
- request : ClassRequest ,
67
- constructor : (DeclarationDescriptor , Name , isInner: Boolean , numberOfTypeParametersCount: Int ) -> D
68
- ): D {
69
- val (classId, typeParametersCount) = request
70
-
43
+ private val classes = storageManager.createMemoizedFunction<ClassRequest , ClassDescriptor > { (classId, typeParametersCount) ->
71
44
if (classId.isLocal) {
72
45
throw UnsupportedOperationException (" Unresolved local class: $classId " )
73
46
}
@@ -79,7 +52,7 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
79
52
// Treat a class with a nested ClassId as inner for simplicity, otherwise the outer type cannot have generic arguments
80
53
val isInner = classId.isNestedClass
81
54
82
- return constructor ( container, classId.shortClassName, isInner, typeParametersCount.firstOrNull() ? : 0 )
55
+ MockClassDescriptor (storageManager, container, classId.shortClassName, isInner, typeParametersCount.firstOrNull() ? : 0 )
83
56
}
84
57
85
58
class MockClassDescriptor internal constructor(
@@ -89,7 +62,11 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
89
62
private val isInner : Boolean ,
90
63
numberOfDeclaredTypeParameters : Int
91
64
) : ClassDescriptorBase(storageManager, container, name, SourceElement .NO_SOURCE , /* isExternal = */ false ) {
92
- private val typeParameters = createTypeParameters(this , numberOfDeclaredTypeParameters)
65
+ private val typeParameters = (1 .. numberOfDeclaredTypeParameters).map { index ->
66
+ TypeParameterDescriptorImpl .createWithDefaultBound(
67
+ this , Annotations .EMPTY , false , Variance .INVARIANT , Name .identifier(" T$index " ), index
68
+ )
69
+ }
93
70
94
71
private val typeConstructor = ClassTypeConstructorImpl (this , /* isFinal = */ true , typeParameters, setOf (module.builtIns.anyType))
95
72
@@ -117,57 +94,11 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
117
94
override fun toString () = " class $name (not found)"
118
95
}
119
96
120
- private class MockTypeAliasDescriptor (
121
- storageManager : StorageManager ,
122
- containingDeclaration : DeclarationDescriptor ,
123
- name : Name ,
124
- private val isInner : Boolean ,
125
- numberOfDeclaredTypeParameters : Int
126
- ) : AbstractTypeAliasDescriptor(containingDeclaration, Annotations .EMPTY , name, SourceElement .NO_SOURCE , Visibilities .PUBLIC ) {
127
- init {
128
- initialize(createTypeParameters(this , numberOfDeclaredTypeParameters))
129
- }
130
-
131
- private val constructorTypeParameters by storageManager.createLazyValue { computeConstructorTypeParameters() }
132
-
133
- override fun getTypeConstructorTypeParameters () = constructorTypeParameters
134
-
135
- // We don't have enough information about underlying type, so just take nullable Any?
136
- // Anyway it should not used extensively, because not found type aliases are only used for type abbreviations
137
- override val underlyingType: SimpleType
138
- get() = builtIns.nullableAnyType
139
- override val expandedType: SimpleType
140
- get() = builtIns.nullableAnyType
141
- override fun getDefaultType (): SimpleType =
142
- builtIns.nullableAnyType
143
- override val classDescriptor: ClassDescriptor ?
144
- get() = expandedType.constructor .declarationDescriptor as ? ClassDescriptor
145
-
146
- override fun isInner (): Boolean = isInner
147
-
148
- override fun substitute (substitutor : TypeSubstitutor ) = this
149
-
150
- override fun toString () = " MockTypeAliasDescriptor[$fqNameUnsafe ]"
151
- }
152
-
153
97
// We create different ClassDescriptor instances for types with the same ClassId but different number of type arguments.
154
98
// (This may happen when a class with the same FQ name is instantiated with different type arguments in different modules.)
155
99
// It's better than creating just one descriptor because otherwise would fail in multiple places where it's asserted that
156
100
// the number of type arguments in a type must be equal to the number of the type parameters of the class
157
101
fun getClass (classId : ClassId , typeParametersCount : List <Int >): ClassDescriptor {
158
102
return classes(ClassRequest (classId, typeParametersCount))
159
103
}
160
-
161
- fun getTypeAlias (classId : ClassId , typeParametersCount : List <Int >): TypeAliasDescriptor {
162
- return typeAliases(ClassRequest (classId, typeParametersCount))
163
- }
164
- }
165
-
166
- private fun createTypeParameters (
167
- classifierDescriptor : ClassifierDescriptor ,
168
- numberOfDeclaredTypeParameters : Int
169
- ) = (1 .. numberOfDeclaredTypeParameters).map { index ->
170
- TypeParameterDescriptorImpl .createWithDefaultBound(
171
- classifierDescriptor, Annotations .EMPTY , false , Variance .INVARIANT , Name .identifier(" T$index " ), index
172
- )
173
104
}
0 commit comments