Review fixes:

Use `StorageManager.createLazyValue` instead of default lazy delegate
Introduce `initialize` method instead of exposing type parameters
This commit is contained in:
Leonid Startsev
2018-04-19 18:28:47 +03:00
committed by Leonid Startsev
parent 666553e413
commit 01b40d4d02
2 changed files with 13 additions and 5 deletions
@@ -50,15 +50,21 @@ class SyntheticClassOrObjectDescriptor(
val syntheticDeclaration: KtPureClassOrObject = SyntheticDeclaration(parentClassOrObject, name.asString())
private val thisDescriptor: SyntheticClassOrObjectDescriptor get() = this // code readability
var typeParameters: List<TypeParameterDescriptor> = emptyList()
private lateinit var typeParameters: List<TypeParameterDescriptor>
private val typeConstructor = SyntheticTypeConstructor(c.storageManager)
private val resolutionScopesSupport = ClassResolutionScopesSupport(thisDescriptor, c.storageManager, c.languageVersionSettings, { outerScope })
private val syntheticSupertypes =
mutableListOf<KotlinType>().apply { c.syntheticResolveExtension.addSyntheticSupertypes(thisDescriptor, this) }
private val unsubstitutedMemberScope =
LazyClassMemberScope(c, SyntheticClassMemberDeclarationProvider(syntheticDeclaration), this, c.trace)
private val _unsubstitutedPrimaryConstructor by lazy { createUnsubstitutedPrimaryConstructor(constructorVisibility) }
private val _unsubstitutedPrimaryConstructor =
c.storageManager.createLazyValue { createUnsubstitutedPrimaryConstructor(constructorVisibility) }
@JvmOverloads
fun initialize(typeParameters: List<TypeParameterDescriptor> = emptyList()) {
this.typeParameters = typeParameters
}
override val annotations: Annotations get() = Annotations.EMPTY
@@ -74,8 +80,8 @@ class SyntheticClassOrObjectDescriptor(
override fun getCompanionObjectDescriptor(): ClassDescriptorWithResolutionScopes? = null
override fun getTypeConstructor(): TypeConstructor = typeConstructor
override fun getUnsubstitutedPrimaryConstructor() = _unsubstitutedPrimaryConstructor
override fun getConstructors() = listOf(_unsubstitutedPrimaryConstructor)
override fun getUnsubstitutedPrimaryConstructor() = _unsubstitutedPrimaryConstructor()
override fun getConstructors() = listOf(_unsubstitutedPrimaryConstructor())
override fun getDeclaredTypeParameters() = typeParameters
override fun getStaticScope() = MemberScope.Empty
override fun getUnsubstitutedMemberScope() = unsubstitutedMemberScope
@@ -435,11 +435,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
Name syntheticCompanionName = c.getSyntheticResolveExtension().getSyntheticCompanionObjectNameIfNeeded(this);
if (syntheticCompanionName == null)
return null;
return new SyntheticClassOrObjectDescriptor(c,
SyntheticClassOrObjectDescriptor companionDescriptor = new SyntheticClassOrObjectDescriptor(c,
/* parentClassOrObject= */ classOrObject,
this, syntheticCompanionName, getSource(),
/* outerScope= */ getOuterScope(),
Modality.FINAL, PUBLIC, PRIVATE, ClassKind.OBJECT, true);
companionDescriptor.initialize();
return companionDescriptor;
}
@Nullable