Replace usages of blocking lazy to LazyThreadSafetyMode.PUBLICATION in light classes to prevent potential deadlocks

This commit is contained in:
Pavel V. Talanov
2016-05-24 18:38:31 +03:00
parent 65e55f045f
commit 695653c447
4 changed files with 12 additions and 12 deletions
@@ -36,7 +36,7 @@ class KtLightAnnotation(
private val owner: PsiAnnotationOwner
) : PsiAnnotation by clsDelegate, KtLightElement<KtAnnotationEntry, PsiAnnotation> {
inner class LightExpressionValue(private val delegate: PsiExpression) : PsiAnnotationMemberValue, PsiExpression by delegate {
val originalExpression: PsiElement? by lazy {
val originalExpression: PsiElement? by lazy(LazyThreadSafetyMode.PUBLICATION) {
val nameAndValue = getStrictParentOfType<PsiNameValuePair>() ?: return@lazy null
val annotationEntry = this@KtLightAnnotation.kotlinOrigin
val context = LightClassGenerationSupport.getInstance(project).analyze(annotationEntry)
@@ -79,7 +79,7 @@ class KtLightAnnotation(
}
inner class LightArrayInitializerValue(private val delegate: PsiArrayInitializerMemberValue) : PsiArrayInitializerMemberValue by delegate {
private val _initializers by lazy { delegate.initializers.map { wrapAnnotationValue(it) }.toTypedArray() }
private val _initializers by lazy(LazyThreadSafetyMode.PUBLICATION) { delegate.initializers.map { wrapAnnotationValue(it) }.toTypedArray() }
override fun getInitializers() = _initializers
override fun getLanguage() = KotlinLanguage.INSTANCE
@@ -129,7 +129,7 @@ open class KtLightClassForExplicitDeclaration(
return null
}
private val _parent: PsiElement? by lazy {
private val _parent: PsiElement? by lazy(LazyThreadSafetyMode.PUBLICATION) {
if (classOrObject.isLocal())
getLocalClassParent()
else if (classOrObject.isTopLevel())
@@ -177,7 +177,7 @@ open class KtLightClassForExplicitDeclaration(
return lightClassData as OutermostKotlinClassLightClassData
}
private val _containingFile: PsiFile by lazy {
private val _containingFile: PsiFile by lazy(LazyThreadSafetyMode.PUBLICATION) {
val virtualFile = classOrObject.containingFile.virtualFile
assert(virtualFile != null) { "No virtual file for " + classOrObject.text }
@@ -245,7 +245,7 @@ open class KtLightClassForExplicitDeclaration(
override fun getParent(): PsiElement? = _parent
private val _typeParameterList: PsiTypeParameterList by lazy {
private val _typeParameterList: PsiTypeParameterList by lazy(LazyThreadSafetyMode.PUBLICATION) {
LightClassUtil.buildLightTypeParameterList(this, classOrObject)
}
@@ -257,7 +257,7 @@ open class KtLightClassForExplicitDeclaration(
override fun getQualifiedName(): String = classFqName.asString()
private val _modifierList : PsiModifierList by lazy {
private val _modifierList : PsiModifierList by lazy(LazyThreadSafetyMode.PUBLICATION) {
object : KtLightModifierListWithExplicitModifiers(this@KtLightClassForExplicitDeclaration, computeModifiers()) {
override val delegate: PsiAnnotationOwner
get() = this@KtLightClassForExplicitDeclaration.getDelegate().modifierList!!
@@ -35,7 +35,7 @@ sealed class KtLightFieldImpl(
override val clsDelegate: PsiField,
private val containingClass: KtLightClass
) : LightElement(clsDelegate.manager, KotlinLanguage.INSTANCE), KtLightField {
private val lightIdentifier by lazy { KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration) }
private val lightIdentifier by lazy(LazyThreadSafetyMode.PUBLICATION) { KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration) }
@Throws(IncorrectOperationException::class)
override fun setInitializer(initializer: PsiExpression?) = throw IncorrectOperationException("Not supported")
@@ -72,7 +72,7 @@ sealed class KtLightFieldImpl(
return this
}
private val _modifierList by lazy {
private val _modifierList by lazy(LazyThreadSafetyMode.PUBLICATION) {
if (lightMemberOrigin is LightMemberOriginForDeclaration)
clsDelegate.modifierList?.let { KtLightModifierList(it, this) }
else clsDelegate.modifierList
@@ -39,11 +39,11 @@ sealed class KtLightMethodImpl(
) : LightMethod(clsDelegate.manager, clsDelegate, containingClass), KtLightMethod {
override val kotlinOrigin: KtDeclaration? get() = lightMethodOrigin?.originalElement as? KtDeclaration
private val lightIdentifier by lazy { KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration) }
private val lightIdentifier by lazy(LazyThreadSafetyMode.PUBLICATION) { KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration) }
override fun getContainingClass(): KtLightClass = super.getContainingClass() as KtLightClass
private val paramsList: CachedValue<PsiParameterList> by lazy {
private val paramsList: CachedValue<PsiParameterList> by lazy(LazyThreadSafetyMode.PUBLICATION) {
val cacheManager = CachedValuesManager.getManager(clsDelegate.project)
cacheManager.createCachedValue<PsiParameterList>({
val parameterBuilder = LightParameterListBuilder(manager, KotlinLanguage.INSTANCE, this)
@@ -56,7 +56,7 @@ sealed class KtLightMethodImpl(
}, false)
}
private val typeParamsList: CachedValue<PsiTypeParameterList> by lazy {
private val typeParamsList: CachedValue<PsiTypeParameterList> by lazy(LazyThreadSafetyMode.PUBLICATION) {
val cacheManager = CachedValuesManager.getManager(clsDelegate.project)
cacheManager.createCachedValue<PsiTypeParameterList>({
val origin = (lightMethodOrigin as? LightMemberOriginForDeclaration)?.originalElement
@@ -111,7 +111,7 @@ sealed class KtLightMethodImpl(
throw IncorrectOperationException(JavaCoreBundle.message("psi.error.attempt.to.edit.class.file"))
}
private val _modifierList by lazy {
private val _modifierList by lazy(LazyThreadSafetyMode.PUBLICATION) {
if (lightMethodOrigin is LightMemberOriginForDeclaration)
KtLightModifierList(clsDelegate.modifierList, this)
else clsDelegate.modifierList