diff --git a/compiler/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt b/compiler/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt new file mode 100644 index 00000000000..20530e8b6a7 --- /dev/null +++ b/compiler/light-classes-base/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.asJava.classes + +import com.intellij.openapi.util.ModificationTracker +import com.intellij.psi.PsiJavaCodeReferenceElement +import com.intellij.psi.PsiReferenceList +import com.intellij.psi.impl.light.LightElement +import com.intellij.util.IncorrectOperationException +import org.jetbrains.kotlin.analyzer.KotlinModificationTrackerService +import org.jetbrains.kotlin.psi.* + +// NOTE: avoid using blocking lazy in light classes, it leads to deadlocks +fun lazyPub(initializer: () -> T) = lazy(LazyThreadSafetyMode.PUBLICATION, initializer) + +fun LightElement.cannotModify(): Nothing { + throw IncorrectOperationException("Modification not implemented.") +} + +fun PsiReferenceList.addSuperTypeEntry( + superTypeList: KtSuperTypeList, + entry: KtSuperTypeListEntry, + reference: PsiJavaCodeReferenceElement +) { + // Only classes may be mentioned in 'extends' list, thus create super call instead simple type reference + val entryToAdd = + if ((reference.parent as? PsiReferenceList)?.role == PsiReferenceList.Role.IMPLEMENTS_LIST && role == PsiReferenceList.Role.EXTENDS_LIST) { + KtPsiFactory(this).createSuperTypeCallEntry("${entry.text}()") + } else entry + // TODO: implement KtSuperListEntry qualification/shortening when inserting reference from another context + if (entry.parent != superTypeList) { + superTypeList.addEntry(entryToAdd) + } else { + // Preserve original entry order + entry.replace(entryToAdd) + } +} + +fun KtClassOrObject.getExternalDependencies(): List { + return with(KotlinModificationTrackerService.getInstance(project)) { + if (!this@getExternalDependencies.isLocal) return listOf(outOfBlockModificationTracker) + else when (val file = containingFile) { + is KtFile -> listOf(outOfBlockModificationTracker, fileModificationTracker(file)) + else -> listOf(outOfBlockModificationTracker) + } + } +} diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt index 5660c7e6be0..45dcd23198b 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/implUtils.kt @@ -1,28 +1,17 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.asJava.classes -import com.intellij.openapi.util.ModificationTracker -import com.intellij.psi.PsiJavaCodeReferenceElement -import com.intellij.psi.PsiReferenceList -import com.intellij.psi.impl.light.LightElement -import com.intellij.util.IncorrectOperationException -import org.jetbrains.kotlin.analyzer.KotlinModificationTrackerService import org.jetbrains.kotlin.asJava.LightClassGenerationSupport -import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtSuperTypeList +import org.jetbrains.kotlin.psi.KtSuperTypeListEntry import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe -// NOTE: avoid using blocking lazy in light classes, it leads to deadlocks -fun lazyPub(initializer: () -> T) = lazy(LazyThreadSafetyMode.PUBLICATION, initializer) - -fun LightElement.cannotModify(): Nothing { - throw IncorrectOperationException("Modification not implemented.") -} - fun KtSuperTypeList.findEntry(fqNameToFind: String): KtSuperTypeListEntry? { val context = LightClassGenerationSupport.getInstance(project).analyzeWithContent(parent as KtClassOrObject) return entries.firstOrNull { @@ -30,32 +19,3 @@ fun KtSuperTypeList.findEntry(fqNameToFind: String): KtSuperTypeListEntry? { referencedType?.constructor?.declarationDescriptor?.fqNameUnsafe?.asString() == fqNameToFind } } - -fun PsiReferenceList.addSuperTypeEntry( - superTypeList: KtSuperTypeList, - entry: KtSuperTypeListEntry, - reference: PsiJavaCodeReferenceElement -) { - // Only classes may be mentioned in 'extends' list, thus create super call instead simple type reference - val entryToAdd = - if ((reference.parent as? PsiReferenceList)?.role == PsiReferenceList.Role.IMPLEMENTS_LIST && role == PsiReferenceList.Role.EXTENDS_LIST) { - KtPsiFactory(this).createSuperTypeCallEntry("${entry.text}()") - } else entry - // TODO: implement KtSuperListEntry qualification/shortening when inserting reference from another context - if (entry.parent != superTypeList) { - superTypeList.addEntry(entryToAdd) - } else { - // Preserve original entry order - entry.replace(entryToAdd) - } -} - -fun KtClassOrObject.getExternalDependencies(): List { - return with(KotlinModificationTrackerService.getInstance(project)) { - if (!this@getExternalDependencies.isLocal) return listOf(outOfBlockModificationTracker) - else when (val file = containingFile) { - is KtFile -> listOf(outOfBlockModificationTracker, fileModificationTracker(file)) - else -> listOf(outOfBlockModificationTracker) - } - } -} \ No newline at end of file