[LL FIR] rework FirDesignation collector
The main change – now we collect not only `FirRegularClass`, but also `FirScript`. This allows us to have a proper context collector for diagnostics for scripts. Also, this change fixes dangling files for scripts in `IGNORE_SELF` as now we have the correct patcher for this case, so we won't resolve the copied script ^KT-65345 ^KT-62841 Fixed
This commit is contained in:
committed by
Space Team
parent
f06b17cbb2
commit
39131a7f30
+55
-50
@@ -32,7 +32,9 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirScriptSymbol
|
|||||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.KtScript
|
||||||
import org.jetbrains.kotlin.utils.exceptions.ExceptionAttachmentBuilder
|
import org.jetbrains.kotlin.utils.exceptions.ExceptionAttachmentBuilder
|
||||||
import org.jetbrains.kotlin.utils.exceptions.checkWithAttachment
|
import org.jetbrains.kotlin.utils.exceptions.checkWithAttachment
|
||||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||||
@@ -104,15 +106,6 @@ class FirDesignation(
|
|||||||
* This property exists only for compatibility and should be dropped after KT-65345
|
* This property exists only for compatibility and should be dropped after KT-65345
|
||||||
*/
|
*/
|
||||||
val classPath: List<FirRegularClass> get() = path.filterIsInstance<FirRegularClass>()
|
val classPath: List<FirRegularClass> get() = path.filterIsInstance<FirRegularClass>()
|
||||||
|
|
||||||
/**
|
|
||||||
* This constructor exists only for compatibility and should be dropped after KT-65345
|
|
||||||
*/
|
|
||||||
constructor(
|
|
||||||
firFile: FirFile,
|
|
||||||
path: List<FirRegularClass>,
|
|
||||||
target: FirElementWithResolveState,
|
|
||||||
) : this(listOf(firFile) + path, target)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ExceptionAttachmentBuilder.withFirDesignationEntry(name: String, designation: FirDesignation) {
|
fun ExceptionAttachmentBuilder.withFirDesignationEntry(name: String, designation: FirDesignation) {
|
||||||
@@ -130,7 +123,7 @@ fun FirDesignation.toSequence(includeTarget: Boolean): Sequence<FirElementWithRe
|
|||||||
if (includeTarget) yield(target)
|
if (includeTarget) yield(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun collectDesignationPath(target: FirElementWithResolveState): List<FirRegularClass>? {
|
private fun collectDesignationPath(target: FirElementWithResolveState): List<FirDeclaration>? {
|
||||||
when (target) {
|
when (target) {
|
||||||
is FirSimpleFunction,
|
is FirSimpleFunction,
|
||||||
is FirProperty,
|
is FirProperty,
|
||||||
@@ -148,7 +141,7 @@ private fun collectDesignationPath(target: FirElementWithResolveState): List<Fir
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val containingClassId = target.containingClassLookupTag()?.classId ?: return emptyList()
|
val containingClassId = target.containingClassLookupTag()?.classId
|
||||||
return collectDesignationPathWithContainingClass(target, containingClassId)
|
return collectDesignationPathWithContainingClass(target, containingClassId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,26 +150,29 @@ private fun collectDesignationPath(target: FirElementWithResolveState): List<Fir
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val containingClassId = target.symbol.classId.outerClassId ?: return emptyList()
|
val containingClassId = target.symbol.classId.outerClassId
|
||||||
return collectDesignationPathWithContainingClass(target, containingClassId)
|
return collectDesignationPathWithContainingClass(target, containingClassId)
|
||||||
}
|
}
|
||||||
|
|
||||||
is FirDanglingModifierList -> {
|
is FirDanglingModifierList -> {
|
||||||
val containingClassId = target.containingClass()?.classId ?: return emptyList()
|
val containingClassId = target.containingClass()?.classId
|
||||||
return collectDesignationPathWithContainingClass(target, containingClassId)
|
return collectDesignationPathWithContainingClass(target, containingClassId)
|
||||||
}
|
}
|
||||||
|
|
||||||
is FirAnonymousInitializer -> {
|
is FirAnonymousInitializer -> {
|
||||||
val containingClassId = (target.containingDeclarationSymbol as? FirClassSymbol<*>)?.classId
|
val containingDeclarationSymbol = target.containingDeclarationSymbol
|
||||||
if (containingClassId == null || containingClassId.isLocal) return null
|
return when (containingDeclarationSymbol) {
|
||||||
return collectDesignationPathWithContainingClass(target, containingClassId)
|
is FirScriptSymbol -> listOf(containingDeclarationSymbol.fir)
|
||||||
|
is FirClassSymbol<*> -> collectDesignationPathWithContainingClass(target, containingDeclarationSymbol.classId)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is FirErrorProperty -> {
|
is FirErrorProperty -> {
|
||||||
return if (target.diagnostic == ConeDestructuringDeclarationsOnTopLevel) emptyList() else null
|
return if (target.diagnostic == ConeDestructuringDeclarationsOnTopLevel) emptyList() else null
|
||||||
}
|
}
|
||||||
|
|
||||||
is FirScript, is FirCodeFragment -> {
|
is FirScript, is FirCodeFragment, is FirFileAnnotationsContainer -> {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,31 +184,37 @@ private fun collectDesignationPath(target: FirElementWithResolveState): List<Fir
|
|||||||
|
|
||||||
private fun collectDesignationPathWithContainingClassByFirFile(
|
private fun collectDesignationPathWithContainingClassByFirFile(
|
||||||
firFile: FirFile,
|
firFile: FirFile,
|
||||||
containingClassId: ClassId,
|
containingClassId: ClassId?,
|
||||||
target: FirDeclaration,
|
target: FirDeclaration,
|
||||||
): List<FirRegularClass>? = FirElementFinder.findClassPathToDeclaration(
|
): List<FirDeclaration>? = FirElementFinder.findClassPathToDeclaration(
|
||||||
firFile = firFile,
|
firFile = firFile,
|
||||||
declarationContainerClassId = containingClassId,
|
declarationContainerClassId = containingClassId,
|
||||||
targetMemberDeclaration = target,
|
targetMemberDeclaration = target,
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun collectDesignationPathWithContainingClass(target: FirDeclaration, containingClassId: ClassId): List<FirRegularClass>? {
|
private fun collectDesignationPathWithContainingClass(target: FirDeclaration, containingClassId: ClassId?): List<FirDeclaration>? {
|
||||||
if (containingClassId.isLocal) {
|
if (containingClassId?.isLocal == true) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val firFile = target.getContainingFile()
|
val firFile = target.getContainingFile()
|
||||||
if (firFile != null && firFile.packageFqName == containingClassId.packageFqName) {
|
if (firFile != null && (containingClassId == null || firFile.packageFqName == containingClassId.packageFqName)) {
|
||||||
val designationPath = collectDesignationPathWithContainingClassByFirFile(firFile, containingClassId, target)
|
val designationPath = collectDesignationPathWithContainingClassByFirFile(firFile, containingClassId, target)
|
||||||
if (designationPath != null) {
|
if (designationPath != null) {
|
||||||
return designationPath
|
return designationPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collectDesignationPathWithContainingClassFallback(target, containingClassId)
|
val fallbackClassPath = collectDesignationPathWithContainingClassFallback(target, containingClassId)
|
||||||
|
val firScript = firFile?.declarations?.singleOrNull() as? FirScript
|
||||||
|
val fallbackPath = listOfNotNull(firScript) + fallbackClassPath.orEmpty()
|
||||||
|
return patchDesignationPathIfNeeded(target, fallbackPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun collectDesignationPathWithContainingClassFallback(target: FirDeclaration, containingClassId: ClassId): List<FirRegularClass>? {
|
private fun collectDesignationPathWithContainingClassFallback(
|
||||||
|
target: FirDeclaration,
|
||||||
|
containingClassId: ClassId?,
|
||||||
|
): List<FirDeclaration>? {
|
||||||
val useSiteSession = getTargetSession(target)
|
val useSiteSession = getTargetSession(target)
|
||||||
|
|
||||||
fun resolveChunk(classId: ClassId): FirRegularClass {
|
fun resolveChunk(classId: ClassId): FirRegularClass {
|
||||||
@@ -244,7 +246,7 @@ private fun collectDesignationPathWithContainingClassFallback(target: FirDeclara
|
|||||||
if (chunks.any { it.shortClassName.isSpecial }) {
|
if (chunks.any { it.shortClassName.isSpecial }) {
|
||||||
val fallbackResult = collectDesignationPathWithTreeTraversal(target)
|
val fallbackResult = collectDesignationPathWithTreeTraversal(target)
|
||||||
if (fallbackResult != null) {
|
if (fallbackResult != null) {
|
||||||
return patchDesignationPathIfNeeded(target, fallbackResult)
|
return fallbackResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +255,7 @@ private fun collectDesignationPathWithContainingClassFallback(target: FirDeclara
|
|||||||
.map { resolveChunk(it) }
|
.map { resolveChunk(it) }
|
||||||
.asReversed()
|
.asReversed()
|
||||||
|
|
||||||
return patchDesignationPathIfNeeded(target, result)
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -263,9 +265,7 @@ private fun collectDesignationPathWithContainingClassFallback(target: FirDeclara
|
|||||||
private fun collectDesignationPathWithTreeTraversal(target: FirDeclaration): List<FirRegularClass>? {
|
private fun collectDesignationPathWithTreeTraversal(target: FirDeclaration): List<FirRegularClass>? {
|
||||||
val containingFile = target.getContainingFile() ?: return null
|
val containingFile = target.getContainingFile() ?: return null
|
||||||
|
|
||||||
val path = ArrayDeque<FirElement>()
|
val path = mutableListOf<FirRegularClass>()
|
||||||
path.addLast(containingFile)
|
|
||||||
|
|
||||||
var result: List<FirRegularClass>? = null
|
var result: List<FirRegularClass>? = null
|
||||||
|
|
||||||
val visitor = object : FirVisitorVoid() {
|
val visitor = object : FirVisitorVoid() {
|
||||||
@@ -273,13 +273,18 @@ private fun collectDesignationPathWithTreeTraversal(target: FirDeclaration): Lis
|
|||||||
if (result != null) {
|
if (result != null) {
|
||||||
return
|
return
|
||||||
} else if (element === target) {
|
} else if (element === target) {
|
||||||
result = path.filterIsInstance<FirRegularClass>()
|
result = path
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
path.addLast(element)
|
if (element is FirRegularClass) {
|
||||||
|
path += element
|
||||||
|
}
|
||||||
|
|
||||||
element.acceptChildren(this)
|
element.acceptChildren(this)
|
||||||
} finally {
|
} finally {
|
||||||
path.removeLast()
|
if (element is FirRegularClass) {
|
||||||
|
path.removeLast()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,29 +334,24 @@ fun FirElementWithResolveState.collectDesignationWithFile(): FirDesignation =
|
|||||||
|
|
||||||
fun FirElementWithResolveState.tryCollectDesignation(firFile: FirFile): FirDesignation? =
|
fun FirElementWithResolveState.tryCollectDesignation(firFile: FirFile): FirDesignation? =
|
||||||
collectDesignationPath(this)?.let {
|
collectDesignationPath(this)?.let {
|
||||||
FirDesignation(firFile, it, this)
|
FirDesignation(path = listOf(firFile) + it, target = this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirElementWithResolveState.tryCollectDesignation(): FirDesignation? =
|
fun FirElementWithResolveState.tryCollectDesignation(): FirDesignation? =
|
||||||
collectDesignationPath(this)?.let {
|
collectDesignationPath(this)?.let {
|
||||||
FirDesignation(it, this)
|
FirDesignation(path = it, target = this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirElementWithResolveState.tryCollectDesignationWithFile(): FirDesignation? {
|
fun FirElementWithResolveState.tryCollectDesignationWithFile(): FirDesignation? {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is FirScript, is FirCodeFragment, is FirFileAnnotationsContainer -> {
|
|
||||||
val firFile = getContainingFile() ?: return null
|
|
||||||
FirDesignation(firFile, path = emptyList(), this)
|
|
||||||
}
|
|
||||||
|
|
||||||
is FirSyntheticProperty, is FirSyntheticPropertyAccessor -> unexpectedElementError<FirElementWithResolveState>(this)
|
is FirSyntheticProperty, is FirSyntheticPropertyAccessor -> unexpectedElementError<FirElementWithResolveState>(this)
|
||||||
is FirDeclaration -> {
|
is FirFileAnnotationsContainer, is FirDeclaration -> {
|
||||||
val scriptDesignation = scriptDesignation()
|
val scriptDesignation = (this as? FirDeclaration)?.scriptDesignation()
|
||||||
if (scriptDesignation != null) return scriptDesignation
|
if (scriptDesignation != null) return scriptDesignation
|
||||||
|
|
||||||
val path = collectDesignationPath(this) ?: return null
|
val path = collectDesignationPath(this) ?: return null
|
||||||
val firFile = path.lastOrNull()?.getContainingFile() ?: getContainingFile() ?: return null
|
val firFile = path.lastOrNull()?.getContainingFile() ?: getContainingFile() ?: return null
|
||||||
FirDesignation(firFile, path, this)
|
FirDesignation(path = listOf(firFile) + path, target = this)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> unexpectedElementError<FirElementWithResolveState>(this)
|
else -> unexpectedElementError<FirElementWithResolveState>(this)
|
||||||
@@ -363,22 +363,22 @@ private fun FirDeclaration.scriptDesignation(): FirDesignation? {
|
|||||||
this is FirAnonymousInitializer -> {
|
this is FirAnonymousInitializer -> {
|
||||||
val firScriptSymbol = (containingDeclarationSymbol as? FirScriptSymbol) ?: return null
|
val firScriptSymbol = (containingDeclarationSymbol as? FirScriptSymbol) ?: return null
|
||||||
val firFile = firScriptSymbol.fir.getContainingFile() ?: return null
|
val firFile = firScriptSymbol.fir.getContainingFile() ?: return null
|
||||||
FirDesignation(firFile, path = emptyList(), firScriptSymbol.fir)
|
FirDesignation(path = listOf(firFile), target = firScriptSymbol.fir)
|
||||||
}
|
}
|
||||||
isScriptDependentDeclaration -> {
|
isScriptDependentDeclaration -> {
|
||||||
val firFile = getContainingFile() ?: return null
|
val firFile = getContainingFile() ?: return null
|
||||||
val firScript = firFile.declarations.singleOrNull() as? FirScript ?: return null
|
val firScript = firFile.declarations.singleOrNull() as? FirScript ?: return null
|
||||||
FirDesignation(firFile, path = emptyList(), firScript)
|
FirDesignation(path = listOf(firFile), target = firScript)
|
||||||
}
|
}
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun patchDesignationPathIfNeeded(target: FirElementWithResolveState, targetPath: List<FirRegularClass>): List<FirRegularClass> {
|
internal fun patchDesignationPathIfNeeded(target: FirElementWithResolveState, targetPath: List<FirDeclaration>): List<FirDeclaration> {
|
||||||
return patchDesignationPathForCopy(target, targetPath) ?: targetPath
|
return patchDesignationPathForCopy(target, targetPath) ?: targetPath
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun patchDesignationPathForCopy(target: FirElementWithResolveState, targetPath: List<FirRegularClass>): List<FirRegularClass>? {
|
private fun patchDesignationPathForCopy(target: FirElementWithResolveState, targetPath: List<FirDeclaration>): List<FirDeclaration>? {
|
||||||
val targetModule = target.llFirModuleData.ktModule
|
val targetModule = target.llFirModuleData.ktModule
|
||||||
|
|
||||||
if (targetModule is KtDanglingFileModule && targetModule.resolutionMode == DanglingFileResolutionMode.IGNORE_SELF) {
|
if (targetModule is KtDanglingFileModule && targetModule.resolutionMode == DanglingFileResolutionMode.IGNORE_SELF) {
|
||||||
@@ -388,11 +388,16 @@ private fun patchDesignationPathForCopy(target: FirElementWithResolveState, targ
|
|||||||
val contextResolveSession = contextModule.getFirResolveSession(contextModule.project)
|
val contextResolveSession = contextModule.getFirResolveSession(contextModule.project)
|
||||||
|
|
||||||
return buildList {
|
return buildList {
|
||||||
for (targetPathClass in targetPath) {
|
for (targetPathDeclaration in targetPath) {
|
||||||
val targetPathPsi = targetPathClass.psi as? KtDeclaration ?: return null
|
val targetPathPsi = targetPathDeclaration.psi as? KtDeclaration ?: return null
|
||||||
val originalPathPsi = targetPathPsi.unwrapCopy(targetPsiFile) ?: return null
|
val originalPathPsi = targetPathPsi.unwrapCopy(targetPsiFile) ?: return null
|
||||||
val originalPathClass = originalPathPsi.getOrBuildFirSafe<FirRegularClass>(contextResolveSession) ?: return null
|
val originalPathDeclaration = when (originalPathPsi) {
|
||||||
add(originalPathClass)
|
is KtClassOrObject -> originalPathPsi.getOrBuildFirSafe<FirRegularClass>(contextResolveSession)
|
||||||
|
is KtScript -> originalPathPsi.getOrBuildFirSafe<FirScript>(contextResolveSession)
|
||||||
|
else -> null
|
||||||
|
} ?: return null
|
||||||
|
|
||||||
|
add(originalPathDeclaration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-8
@@ -123,12 +123,7 @@ object ContextCollector {
|
|||||||
if (contextKtDeclaration != null) {
|
if (contextKtDeclaration != null) {
|
||||||
val designationPath = FirElementFinder.collectDesignationPath(file, contextKtDeclaration)
|
val designationPath = FirElementFinder.collectDesignationPath(file, contextKtDeclaration)
|
||||||
if (designationPath != null) {
|
if (designationPath != null) {
|
||||||
val script = file.declarations.singleOrNull() as? FirScript
|
return designationPath
|
||||||
return if (script == null || script === designationPath.target) {
|
|
||||||
FirDesignation(designationPath.path, designationPath.target)
|
|
||||||
} else {
|
|
||||||
FirDesignation(listOf(script) + designationPath.path, designationPath.target)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +158,7 @@ object ContextCollector {
|
|||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
designation: FirDesignation?,
|
designation: FirDesignation?,
|
||||||
shouldCollectBodyContext: Boolean,
|
shouldCollectBodyContext: Boolean,
|
||||||
filter: (PsiElement) -> FilterResponse
|
filter: (PsiElement) -> FilterResponse,
|
||||||
): ContextProvider {
|
): ContextProvider {
|
||||||
val interceptor = designation?.let(::DesignationInterceptor) ?: { null }
|
val interceptor = designation?.let(::DesignationInterceptor) ?: { null }
|
||||||
val visitor = ContextCollectorVisitor(holder, shouldCollectBodyContext, filter, interceptor)
|
val visitor = ContextCollectorVisitor(holder, shouldCollectBodyContext, filter, interceptor)
|
||||||
@@ -192,7 +187,7 @@ private class ContextCollectorVisitor(
|
|||||||
private val holder: SessionHolder,
|
private val holder: SessionHolder,
|
||||||
private val shouldCollectBodyContext: Boolean,
|
private val shouldCollectBodyContext: Boolean,
|
||||||
private val filter: (PsiElement) -> FilterResponse,
|
private val filter: (PsiElement) -> FilterResponse,
|
||||||
private val designationPathInterceptor: () -> FirElement?
|
private val designationPathInterceptor: () -> FirElement?,
|
||||||
) : FirDefaultVisitorVoid() {
|
) : FirDefaultVisitorVoid() {
|
||||||
private data class ContextKey(val element: PsiElement, val kind: ContextKind)
|
private data class ContextKey(val element: PsiElement, val kind: ContextKind)
|
||||||
|
|
||||||
|
|||||||
+25
-19
@@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2024 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.
|
* 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.analysis.low.level.api.fir.util
|
package org.jetbrains.kotlin.analysis.low.level.api.fir.util
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignation
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.patchDesignationPathIfNeeded
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.patchDesignationPathIfNeeded
|
||||||
import org.jetbrains.kotlin.utils.exceptions.requireWithAttachment
|
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.packageFqName
|
import org.jetbrains.kotlin.fir.packageFqName
|
||||||
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
|||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
|
import org.jetbrains.kotlin.utils.exceptions.requireWithAttachment
|
||||||
import org.jetbrains.kotlin.utils.ifEmpty
|
import org.jetbrains.kotlin.utils.ifEmpty
|
||||||
|
|
||||||
internal object FirElementFinder {
|
internal object FirElementFinder {
|
||||||
@@ -29,9 +30,9 @@ internal object FirElementFinder {
|
|||||||
|
|
||||||
fun findClassPathToDeclaration(
|
fun findClassPathToDeclaration(
|
||||||
firFile: FirFile,
|
firFile: FirFile,
|
||||||
declarationContainerClassId: ClassId,
|
declarationContainerClassId: ClassId?,
|
||||||
targetMemberDeclaration: FirDeclaration,
|
targetMemberDeclaration: FirDeclaration,
|
||||||
): List<FirRegularClass>? = collectDesignationPath(
|
): List<FirDeclaration>? = collectDesignationPath(
|
||||||
firFile = firFile,
|
firFile = firFile,
|
||||||
containerClassId = declarationContainerClassId,
|
containerClassId = declarationContainerClassId,
|
||||||
expectedDeclarationAcceptor = { it == targetMemberDeclaration },
|
expectedDeclarationAcceptor = { it == targetMemberDeclaration },
|
||||||
@@ -40,7 +41,7 @@ internal object FirElementFinder {
|
|||||||
fun findDeclaration(firFile: FirFile, nonLocalDeclaration: KtDeclaration): FirDeclaration? = collectDesignationPath(
|
fun findDeclaration(firFile: FirFile, nonLocalDeclaration: KtDeclaration): FirDeclaration? = collectDesignationPath(
|
||||||
firFile = firFile,
|
firFile = firFile,
|
||||||
nonLocalDeclaration = nonLocalDeclaration,
|
nonLocalDeclaration = nonLocalDeclaration,
|
||||||
)?.target
|
)?.declarationTarget
|
||||||
|
|
||||||
fun findPathToDeclarationWithTarget(
|
fun findPathToDeclarationWithTarget(
|
||||||
firFile: FirFile,
|
firFile: FirFile,
|
||||||
@@ -48,29 +49,32 @@ internal object FirElementFinder {
|
|||||||
): List<FirDeclaration>? = collectDesignationPath(
|
): List<FirDeclaration>? = collectDesignationPath(
|
||||||
firFile = firFile,
|
firFile = firFile,
|
||||||
nonLocalDeclaration = nonLocalDeclaration,
|
nonLocalDeclaration = nonLocalDeclaration,
|
||||||
)?.pathWithTarget
|
)?.let { it.path + it.declarationTarget }
|
||||||
|
|
||||||
class FirDeclarationDesignation(
|
|
||||||
val path: List<FirRegularClass>,
|
|
||||||
val target: FirDeclaration,
|
|
||||||
) {
|
|
||||||
val pathWithTarget: List<FirDeclaration> get() = path + target
|
|
||||||
}
|
|
||||||
|
|
||||||
fun collectDesignationPath(
|
fun collectDesignationPath(
|
||||||
firFile: FirFile,
|
firFile: FirFile,
|
||||||
nonLocalDeclaration: KtDeclaration,
|
nonLocalDeclaration: KtDeclaration,
|
||||||
): FirDeclarationDesignation? = collectDesignationPath(
|
): FirDesignation? = collectDesignationPath(
|
||||||
firFile = firFile,
|
firFile = firFile,
|
||||||
containerClassId = nonLocalDeclaration.containingClassOrObject?.getClassId(),
|
containerClassId = nonLocalDeclaration.containingClassOrObject?.getClassId(),
|
||||||
expectedDeclarationAcceptor = { it.psi == nonLocalDeclaration },
|
expectedDeclarationAcceptor = { it.psi == nonLocalDeclaration },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see collectDesignationPath
|
||||||
|
*/
|
||||||
|
private val FirDesignation.declarationTarget: FirDeclaration get() = target as FirDeclaration
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return [FirDesignation] where [FirDesignation.target] is [FirDeclaration]
|
||||||
|
*
|
||||||
|
* @see declarationTarget
|
||||||
|
*/
|
||||||
private fun collectDesignationPath(
|
private fun collectDesignationPath(
|
||||||
firFile: FirFile,
|
firFile: FirFile,
|
||||||
containerClassId: ClassId?,
|
containerClassId: ClassId?,
|
||||||
expectedDeclarationAcceptor: (FirDeclaration) -> Boolean,
|
expectedDeclarationAcceptor: (FirDeclaration) -> Boolean,
|
||||||
): FirDeclarationDesignation? {
|
): FirDesignation? {
|
||||||
if (containerClassId != null) {
|
if (containerClassId != null) {
|
||||||
requireWithAttachment(!containerClassId.isLocal, { "ClassId should not be local" }) {
|
requireWithAttachment(!containerClassId.isLocal, { "ClassId should not be local" }) {
|
||||||
withEntry("classId", containerClassId) { it.asString() }
|
withEntry("classId", containerClassId) { it.asString() }
|
||||||
@@ -86,7 +90,7 @@ internal object FirElementFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val classIdPathSegment = containerClassId?.relativeClassName?.pathSegments().orEmpty()
|
val classIdPathSegment = containerClassId?.relativeClassName?.pathSegments().orEmpty()
|
||||||
val path = ArrayList<FirRegularClass>(classIdPathSegment.size)
|
val path = ArrayList<FirDeclaration>(classIdPathSegment.size + 1)
|
||||||
var result: FirDeclaration? = null
|
var result: FirDeclaration? = null
|
||||||
|
|
||||||
fun find(declarations: Iterable<FirDeclaration>, classIdPathIndex: Int): Boolean {
|
fun find(declarations: Iterable<FirDeclaration>, classIdPathIndex: Int): Boolean {
|
||||||
@@ -99,11 +103,13 @@ internal object FirElementFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subDeclaration is FirScript -> {
|
subDeclaration is FirScript -> {
|
||||||
val scriptDeclarations = subDeclaration.declarations.asSequence().filterNot { it is FirAnonymousInitializer }
|
path += subDeclaration
|
||||||
if (find(scriptDeclarations.asIterable(), classIdPathIndex)) {
|
val scriptDeclarations = subDeclaration.declarations
|
||||||
|
if (find(scriptDeclarations, classIdPathIndex)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path.removeLast()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +144,7 @@ internal object FirElementFinder {
|
|||||||
|
|
||||||
// K1 doesn't perform smart-casts on 'result'
|
// K1 doesn't perform smart-casts on 'result'
|
||||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||||
return FirDeclarationDesignation(
|
return FirDesignation(
|
||||||
path = patchDesignationPathIfNeeded(result!!, path).ifEmpty { emptyList() },
|
path = patchDesignationPathIfNeeded(result!!, path).ifEmpty { emptyList() },
|
||||||
target = result!!,
|
target = result!!,
|
||||||
)
|
)
|
||||||
|
|||||||
+4
-4
@@ -14,7 +14,7 @@ Tower Data Context:
|
|||||||
Element 6
|
Element 6
|
||||||
Scope: FirScriptDeclarationsScope
|
Scope: FirScriptDeclarationsScope
|
||||||
Classifiers:
|
Classifiers:
|
||||||
FirRegularClassSymbol public final? class Foo : R|kotlin/Any|
|
FirRegularClassSymbol public final class Foo : R|kotlin/Any|
|
||||||
Element 7
|
Element 7
|
||||||
Scope: FirLocalScope
|
Scope: FirLocalScope
|
||||||
Classifiers:
|
Classifiers:
|
||||||
@@ -27,7 +27,7 @@ Tower Data Context:
|
|||||||
SCRIPT: <script-insideClassBody.kts>
|
SCRIPT: <script-insideClassBody.kts>
|
||||||
lval args: R|kotlin/Array<kotlin/String>|
|
lval args: R|kotlin/Array<kotlin/String>|
|
||||||
|
|
||||||
public final? class Foo : R|kotlin/Any|
|
public final class Foo : R|kotlin/Any|
|
||||||
Type: kotlin.script.templates.standard.ScriptTemplateWithArgs
|
Type: kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||||
Label: <script>
|
Label: <script>
|
||||||
Element 9
|
Element 9
|
||||||
@@ -38,8 +38,8 @@ Tower Data Context:
|
|||||||
Scope: FirLocalScope
|
Scope: FirLocalScope
|
||||||
|
|
||||||
FILE: [ResolvedTo(IMPORTS)] insideClassBody.kts
|
FILE: [ResolvedTo(IMPORTS)] insideClassBody.kts
|
||||||
context(<script>@R|kotlin/script/templates/standard/ScriptTemplateWithArgs|)
|
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||||
SCRIPT: [ResolvedTo(TYPES)] <script-insideClassBody.kts>
|
SCRIPT: [ResolvedTo(RAW_FIR)] <script-insideClassBody.kts>
|
||||||
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||||
|
|
||||||
public final? [ResolvedTo(RAW_FIR)] class Foo : R|kotlin/Any| {
|
public final? [ResolvedTo(RAW_FIR)] class Foo : R|kotlin/Any| {
|
||||||
|
|||||||
+12
-12
@@ -16,15 +16,15 @@ Tower Data Context:
|
|||||||
Classifiers:
|
Classifiers:
|
||||||
FirRegularClassSymbol public final? class After_OtherClass : R|kotlin/Any|
|
FirRegularClassSymbol public final? class After_OtherClass : R|kotlin/Any|
|
||||||
FirRegularClassSymbol public final? class Before_OtherClass : R|kotlin/Any|
|
FirRegularClassSymbol public final? class Before_OtherClass : R|kotlin/Any|
|
||||||
FirRegularClassSymbol public final? class MyClass : R|kotlin/Any|
|
FirRegularClassSymbol public final class MyClass : R|kotlin/Any|
|
||||||
Functions
|
Functions
|
||||||
FirNamedFunctionSymbol public? final? fun after_Fun(): R|kotlin/Unit|
|
FirNamedFunctionSymbol public? final? fun after_Fun(): R|kotlin/Unit|
|
||||||
FirNamedFunctionSymbol public? final? fun before_Fun(): R|kotlin/Unit|
|
FirNamedFunctionSymbol public? final? fun before_Fun(): R|kotlin/Unit|
|
||||||
Properties:
|
Properties:
|
||||||
FirPropertySymbol public? final? val after_Val: <implicit>
|
FirPropertySymbol public final val after_Val: R|kotlin/Int|
|
||||||
public? get(): <implicit>
|
public get(): R|kotlin/Int|
|
||||||
FirPropertySymbol public? final? val before_Val: <implicit>
|
FirPropertySymbol public final val before_Val: R|kotlin/Int|
|
||||||
public? get(): <implicit>
|
public get(): R|kotlin/Int|
|
||||||
Element 7
|
Element 7
|
||||||
Scope: FirLocalScope
|
Scope: FirLocalScope
|
||||||
Classifiers:
|
Classifiers:
|
||||||
@@ -38,14 +38,14 @@ Tower Data Context:
|
|||||||
lval args: R|kotlin/Array<kotlin/String>|
|
lval args: R|kotlin/Array<kotlin/String>|
|
||||||
|
|
||||||
public? final? fun before_Fun(): R|kotlin/Unit|
|
public? final? fun before_Fun(): R|kotlin/Unit|
|
||||||
public? final? val before_Val: <implicit>
|
public final val before_Val: R|kotlin/Int|
|
||||||
public? get(): <implicit>
|
public get(): R|kotlin/Int|
|
||||||
|
|
||||||
public final? class Before_OtherClass : R|kotlin/Any|
|
public final? class Before_OtherClass : R|kotlin/Any|
|
||||||
public final? class MyClass : R|kotlin/Any|
|
public final class MyClass : R|kotlin/Any|
|
||||||
public? final? fun after_Fun(): R|kotlin/Unit|
|
public? final? fun after_Fun(): R|kotlin/Unit|
|
||||||
public? final? val after_Val: <implicit>
|
public final val after_Val: R|kotlin/Int|
|
||||||
public? get(): <implicit>
|
public get(): R|kotlin/Int|
|
||||||
|
|
||||||
public final? class After_OtherClass : R|kotlin/Any|
|
public final? class After_OtherClass : R|kotlin/Any|
|
||||||
Type: kotlin.script.templates.standard.ScriptTemplateWithArgs
|
Type: kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||||
@@ -60,8 +60,8 @@ Tower Data Context:
|
|||||||
Scope: FirLocalScope
|
Scope: FirLocalScope
|
||||||
|
|
||||||
FILE: [ResolvedTo(IMPORTS)] insideClassMember.kts
|
FILE: [ResolvedTo(IMPORTS)] insideClassMember.kts
|
||||||
context(<script>@R|kotlin/script/templates/standard/ScriptTemplateWithArgs|)
|
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||||
SCRIPT: [ResolvedTo(TYPES)] <script-insideClassMember.kts>
|
SCRIPT: [ResolvedTo(RAW_FIR)] <script-insideClassMember.kts>
|
||||||
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||||
|
|
||||||
public? final? [ResolvedTo(RAW_FIR)] fun before_Fun(): R|kotlin/Unit| { LAZY_BLOCK }
|
public? final? [ResolvedTo(RAW_FIR)] fun before_Fun(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||||
|
|||||||
Vendored
+91
@@ -0,0 +1,91 @@
|
|||||||
|
Tower Data Context:
|
||||||
|
Element 0
|
||||||
|
Scope: FirDefaultStarImportingScope
|
||||||
|
Element 1
|
||||||
|
Scope: FirExplicitStarImportingScope
|
||||||
|
Element 2
|
||||||
|
Scope: FirDefaultSimpleImportingScope
|
||||||
|
Element 3
|
||||||
|
Scope: FirDefaultSimpleImportingScope
|
||||||
|
Element 4
|
||||||
|
Scope: FirPackageMemberScope
|
||||||
|
Element 5
|
||||||
|
Scope: FirExplicitSimpleImportingScope
|
||||||
|
Element 6
|
||||||
|
Scope: FirScriptDeclarationsScope
|
||||||
|
Classifiers:
|
||||||
|
FirRegularClassSymbol public final? class After_OtherClass : R|kotlin/Any|
|
||||||
|
FirRegularClassSymbol public final? class Before_OtherClass : R|kotlin/Any|
|
||||||
|
Functions
|
||||||
|
FirNamedFunctionSymbol public? final? fun after_Fun(): R|kotlin/Unit|
|
||||||
|
FirNamedFunctionSymbol public? final? fun before_Fun(): R|kotlin/Unit|
|
||||||
|
FirNamedFunctionSymbol public final fun usage(foo: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
Properties:
|
||||||
|
FirPropertySymbol public final val after_Val: R|kotlin/Int|
|
||||||
|
public get(): R|kotlin/Int|
|
||||||
|
FirPropertySymbol public final val before_Val: R|kotlin/Int|
|
||||||
|
public get(): R|kotlin/Int|
|
||||||
|
Element 7
|
||||||
|
Scope: FirLocalScope
|
||||||
|
Functions
|
||||||
|
FirNamedFunctionSymbol public final fun usage(foo: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
Properties:
|
||||||
|
FirPropertySymbol lval args: R|kotlin/Array<kotlin/String>|
|
||||||
|
Element 8
|
||||||
|
Context receivers:
|
||||||
|
FirScriptSymbol context(<script>@R|kotlin/script/templates/standard/ScriptTemplateWithArgs|)
|
||||||
|
SCRIPT: <script-insideTopLevelFunction.kts>
|
||||||
|
lval args: R|kotlin/Array<kotlin/String>|
|
||||||
|
|
||||||
|
public? final? fun before_Fun(): R|kotlin/Unit|
|
||||||
|
public final val before_Val: R|kotlin/Int|
|
||||||
|
public get(): R|kotlin/Int|
|
||||||
|
|
||||||
|
public final? class Before_OtherClass : R|kotlin/Any|
|
||||||
|
public final fun usage(foo: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
public? final? fun after_Fun(): R|kotlin/Unit|
|
||||||
|
public final val after_Val: R|kotlin/Int|
|
||||||
|
public get(): R|kotlin/Int|
|
||||||
|
|
||||||
|
public final? class After_OtherClass : R|kotlin/Any|
|
||||||
|
Type: kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||||
|
Label: <script>
|
||||||
|
Element 9
|
||||||
|
Scope: FirLocalScope
|
||||||
|
Properties:
|
||||||
|
FirValueParameterSymbol foo: R|kotlin/Int|
|
||||||
|
Element 10
|
||||||
|
Scope: FirLocalScope
|
||||||
|
|
||||||
|
FILE: [ResolvedTo(IMPORTS)] insideTopLevelFunction.kts
|
||||||
|
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||||
|
SCRIPT: [ResolvedTo(RAW_FIR)] <script-insideTopLevelFunction.kts>
|
||||||
|
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||||
|
|
||||||
|
public? final? [ResolvedTo(RAW_FIR)] fun before_Fun(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||||
|
|
||||||
|
public? final? [ResolvedTo(RAW_FIR)] val before_Val: <implicit> = LAZY_EXPRESSION
|
||||||
|
public? [ResolvedTo(RAW_FIR)] get(): <implicit>
|
||||||
|
|
||||||
|
public final? [ResolvedTo(RAW_FIR)] class Before_OtherClass : R|kotlin/Any| {
|
||||||
|
public? [ResolvedTo(RAW_FIR)] constructor(): R|Before_OtherClass| {
|
||||||
|
LAZY_super<R|kotlin/Any|>
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public final [ResolvedTo(BODY_RESOLVE)] fun usage([ResolvedTo(BODY_RESOLVE)] foo: R|kotlin/Int|): R|kotlin/Unit| {
|
||||||
|
R|<local>/foo|
|
||||||
|
}
|
||||||
|
|
||||||
|
public? final? [ResolvedTo(RAW_FIR)] fun after_Fun(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||||
|
|
||||||
|
public? final? [ResolvedTo(RAW_FIR)] val after_Val: <implicit> = LAZY_EXPRESSION
|
||||||
|
public? [ResolvedTo(RAW_FIR)] get(): <implicit>
|
||||||
|
|
||||||
|
public final? [ResolvedTo(RAW_FIR)] class After_OtherClass : R|kotlin/Any| {
|
||||||
|
public? [ResolvedTo(RAW_FIR)] constructor(): R|After_OtherClass| {
|
||||||
|
LAZY_super<R|kotlin/Any|>
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,335 +0,0 @@
|
|||||||
digraph NestedInnerClass_ll_kts {
|
|
||||||
graph [nodesep=3]
|
|
||||||
node [shape=box penwidth=2]
|
|
||||||
edge [penwidth=2]
|
|
||||||
|
|
||||||
subgraph cluster_0 {
|
|
||||||
color=red
|
|
||||||
0 [label="Enter file NestedInnerClass.ll.kts [1]" style="filled" fillcolor=red];
|
|
||||||
1 [label="Exit file NestedInnerClass.ll.kts [1]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
0 -> {1} [color=green];
|
|
||||||
|
|
||||||
subgraph cluster_1 {
|
|
||||||
color=red
|
|
||||||
2 [label="Enter class <script-NestedInnerClass.ll.kts> [2]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_2 {
|
|
||||||
color=blue
|
|
||||||
3 [label="Enter property [3]" style="filled" fillcolor=red];
|
|
||||||
4 [label="Const: String() [3]"];
|
|
||||||
5 [label="Exit property [3]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
6 [label="Exit class <script-NestedInnerClass.ll.kts> [2]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
2 -> {3} [color=green];
|
|
||||||
2 -> {6} [style=dotted];
|
|
||||||
2 -> {3} [style=dashed];
|
|
||||||
3 -> {4};
|
|
||||||
4 -> {5};
|
|
||||||
5 -> {6} [color=green];
|
|
||||||
|
|
||||||
subgraph cluster_3 {
|
|
||||||
color=red
|
|
||||||
7 [label="Enter function function [3]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_4 {
|
|
||||||
color=blue
|
|
||||||
8 [label="Enter block [3]"];
|
|
||||||
9 [label="Const: Int(42) [3]"];
|
|
||||||
10 [label="Jump: ^function Int(42) [3]"];
|
|
||||||
11 [label="Stub [3]" style="filled" fillcolor=gray];
|
|
||||||
12 [label="Exit block [3]" style="filled" fillcolor=gray];
|
|
||||||
}
|
|
||||||
13 [label="Exit function function [3]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
7 -> {8};
|
|
||||||
8 -> {9};
|
|
||||||
9 -> {10};
|
|
||||||
10 -> {13};
|
|
||||||
10 -> {11} [style=dotted];
|
|
||||||
11 -> {12} [style=dotted];
|
|
||||||
12 -> {13} [style=dotted];
|
|
||||||
|
|
||||||
subgraph cluster_5 {
|
|
||||||
color=red
|
|
||||||
14 [label="Enter class Nested [3]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_6 {
|
|
||||||
color=blue
|
|
||||||
15 [label="Enter function <init> [4]" style="filled" fillcolor=red];
|
|
||||||
16 [label="Delegated constructor call: super<R|kotlin/Any|>() [4]" style="filled" fillcolor=yellow];
|
|
||||||
17 [label="Exit function <init> [4]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
18 [label="Exit class Nested [3]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
14 -> {15} [color=green];
|
|
||||||
14 -> {18} [style=dotted];
|
|
||||||
14 -> {15} [style=dashed];
|
|
||||||
15 -> {16};
|
|
||||||
16 -> {17};
|
|
||||||
17 -> {18} [color=green];
|
|
||||||
|
|
||||||
subgraph cluster_7 {
|
|
||||||
color=red
|
|
||||||
19 [label="Enter function f [4]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_8 {
|
|
||||||
color=blue
|
|
||||||
20 [label="Enter block [4]"];
|
|
||||||
subgraph cluster_9 {
|
|
||||||
color=blue
|
|
||||||
21 [label="Function call arguments enter [4]"];
|
|
||||||
22 [label="Function call arguments exit [4]"];
|
|
||||||
}
|
|
||||||
23 [label="Function call: R|/function|() [4]" style="filled" fillcolor=yellow];
|
|
||||||
24 [label="Jump: ^f R|/function|() [4]"];
|
|
||||||
25 [label="Stub [4]" style="filled" fillcolor=gray];
|
|
||||||
26 [label="Exit block [4]" style="filled" fillcolor=gray];
|
|
||||||
}
|
|
||||||
27 [label="Exit function f [4]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
19 -> {20};
|
|
||||||
20 -> {21};
|
|
||||||
21 -> {22};
|
|
||||||
22 -> {23};
|
|
||||||
23 -> {24};
|
|
||||||
24 -> {27};
|
|
||||||
24 -> {25} [style=dotted];
|
|
||||||
25 -> {26} [style=dotted];
|
|
||||||
26 -> {27} [style=dotted];
|
|
||||||
|
|
||||||
subgraph cluster_10 {
|
|
||||||
color=red
|
|
||||||
28 [label="Enter function g [4]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_11 {
|
|
||||||
color=blue
|
|
||||||
29 [label="Enter block [4]"];
|
|
||||||
30 [label="Access variable R|/property| [4]"];
|
|
||||||
31 [label="Jump: ^g R|/property| [4]"];
|
|
||||||
32 [label="Stub [4]" style="filled" fillcolor=gray];
|
|
||||||
33 [label="Exit block [4]" style="filled" fillcolor=gray];
|
|
||||||
}
|
|
||||||
34 [label="Exit function g [4]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
28 -> {29};
|
|
||||||
29 -> {30};
|
|
||||||
30 -> {31};
|
|
||||||
31 -> {34};
|
|
||||||
31 -> {32} [style=dotted];
|
|
||||||
32 -> {33} [style=dotted];
|
|
||||||
33 -> {34} [style=dotted];
|
|
||||||
|
|
||||||
subgraph cluster_12 {
|
|
||||||
color=red
|
|
||||||
35 [label="Enter class Inner [3]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_13 {
|
|
||||||
color=blue
|
|
||||||
36 [label="Enter function <init> [4]" style="filled" fillcolor=red];
|
|
||||||
37 [label="Delegated constructor call: super<R|kotlin/Any|>() [4]" style="filled" fillcolor=yellow];
|
|
||||||
38 [label="Exit function <init> [4]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
subgraph cluster_14 {
|
|
||||||
color=blue
|
|
||||||
39 [label="Enter property [4]" style="filled" fillcolor=red];
|
|
||||||
40 [label="Access variable R|/property| [4]"];
|
|
||||||
41 [label="Exit property [4]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
subgraph cluster_15 {
|
|
||||||
color=blue
|
|
||||||
42 [label="Enter property [4]" style="filled" fillcolor=red];
|
|
||||||
43 [label="Access variable this@NestedInnerClass# [4]"];
|
|
||||||
44 [label="Access variable <Unresolved name: property># [4]"];
|
|
||||||
45 [label="Exit property [4]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
46 [label="Exit class Inner [3]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
35 -> {36} [color=green];
|
|
||||||
35 -> {46} [style=dotted];
|
|
||||||
35 -> {36 39 42} [style=dashed];
|
|
||||||
36 -> {37};
|
|
||||||
37 -> {38};
|
|
||||||
38 -> {39} [color=green];
|
|
||||||
39 -> {40};
|
|
||||||
40 -> {41};
|
|
||||||
41 -> {42} [color=green];
|
|
||||||
42 -> {43};
|
|
||||||
43 -> {44};
|
|
||||||
44 -> {45};
|
|
||||||
45 -> {46} [color=green];
|
|
||||||
|
|
||||||
subgraph cluster_16 {
|
|
||||||
color=red
|
|
||||||
47 [label="Enter function innerFun [4]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_17 {
|
|
||||||
color=blue
|
|
||||||
48 [label="Enter block [4]"];
|
|
||||||
subgraph cluster_18 {
|
|
||||||
color=blue
|
|
||||||
49 [label="Function call arguments enter [4]"];
|
|
||||||
50 [label="Function call arguments exit [4]"];
|
|
||||||
}
|
|
||||||
51 [label="Function call: R|/function|() [4]" style="filled" fillcolor=yellow];
|
|
||||||
52 [label="Jump: ^innerFun R|/function|() [4]"];
|
|
||||||
53 [label="Stub [4]" style="filled" fillcolor=gray];
|
|
||||||
54 [label="Exit block [4]" style="filled" fillcolor=gray];
|
|
||||||
}
|
|
||||||
55 [label="Exit function innerFun [4]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
47 -> {48};
|
|
||||||
48 -> {49};
|
|
||||||
49 -> {50};
|
|
||||||
50 -> {51};
|
|
||||||
51 -> {52};
|
|
||||||
52 -> {55};
|
|
||||||
52 -> {53} [style=dotted];
|
|
||||||
53 -> {54} [style=dotted];
|
|
||||||
54 -> {55} [style=dotted];
|
|
||||||
|
|
||||||
subgraph cluster_19 {
|
|
||||||
color=red
|
|
||||||
56 [label="Enter function innerThisFun [4]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_20 {
|
|
||||||
color=blue
|
|
||||||
57 [label="Enter block [4]"];
|
|
||||||
subgraph cluster_21 {
|
|
||||||
color=blue
|
|
||||||
58 [label="Function call arguments enter [4]"];
|
|
||||||
59 [label="Access variable this@NestedInnerClass# [4]"];
|
|
||||||
60 [label="Function call arguments exit [4]"];
|
|
||||||
}
|
|
||||||
61 [label="Function call: this@NestedInnerClass#.<Unresolved name: function>#() [4]" style="filled" fillcolor=yellow];
|
|
||||||
62 [label="Jump: ^innerThisFun this@NestedInnerClass#.<Unresolved name: function>#() [4]"];
|
|
||||||
63 [label="Stub [4]" style="filled" fillcolor=gray];
|
|
||||||
64 [label="Exit block [4]" style="filled" fillcolor=gray];
|
|
||||||
}
|
|
||||||
65 [label="Exit function innerThisFun [4]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
56 -> {57};
|
|
||||||
57 -> {58};
|
|
||||||
58 -> {59};
|
|
||||||
59 -> {60};
|
|
||||||
60 -> {61};
|
|
||||||
61 -> {62};
|
|
||||||
62 -> {65};
|
|
||||||
62 -> {63} [style=dotted];
|
|
||||||
63 -> {64} [style=dotted];
|
|
||||||
64 -> {65} [style=dotted];
|
|
||||||
|
|
||||||
subgraph cluster_22 {
|
|
||||||
color=red
|
|
||||||
66 [label="Enter class InnerInner [4]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_23 {
|
|
||||||
color=blue
|
|
||||||
67 [label="Enter function <init> [5]" style="filled" fillcolor=red];
|
|
||||||
68 [label="Delegated constructor call: super<R|kotlin/Any|>() [5]" style="filled" fillcolor=yellow];
|
|
||||||
69 [label="Exit function <init> [5]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
70 [label="Exit class InnerInner [4]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
66 -> {67} [color=green];
|
|
||||||
66 -> {70} [style=dotted];
|
|
||||||
66 -> {67} [style=dashed];
|
|
||||||
67 -> {68};
|
|
||||||
68 -> {69};
|
|
||||||
69 -> {70} [color=green];
|
|
||||||
|
|
||||||
subgraph cluster_24 {
|
|
||||||
color=red
|
|
||||||
71 [label="Enter function f [5]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_25 {
|
|
||||||
color=blue
|
|
||||||
72 [label="Enter block [5]"];
|
|
||||||
subgraph cluster_26 {
|
|
||||||
color=blue
|
|
||||||
73 [label="Function call arguments enter [5]"];
|
|
||||||
74 [label="Function call arguments exit [5]"];
|
|
||||||
}
|
|
||||||
75 [label="Function call: this@R|/Inner|.R|/Inner.innerFun|() [5]" style="filled" fillcolor=yellow];
|
|
||||||
76 [label="Jump: ^f this@R|/Inner|.R|/Inner.innerFun|() [5]"];
|
|
||||||
77 [label="Stub [5]" style="filled" fillcolor=gray];
|
|
||||||
78 [label="Exit block [5]" style="filled" fillcolor=gray];
|
|
||||||
}
|
|
||||||
79 [label="Exit function f [5]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
71 -> {72};
|
|
||||||
72 -> {73};
|
|
||||||
73 -> {74};
|
|
||||||
74 -> {75};
|
|
||||||
75 -> {76};
|
|
||||||
76 -> {79};
|
|
||||||
76 -> {77} [style=dotted];
|
|
||||||
77 -> {78} [style=dotted];
|
|
||||||
78 -> {79} [style=dotted];
|
|
||||||
|
|
||||||
subgraph cluster_27 {
|
|
||||||
color=red
|
|
||||||
80 [label="Enter function g [5]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_28 {
|
|
||||||
color=blue
|
|
||||||
81 [label="Enter block [5]"];
|
|
||||||
82 [label="Access variable R|/Inner.innerProp| [5]"];
|
|
||||||
83 [label="Jump: ^g this@R|/Inner|.R|/Inner.innerProp| [5]"];
|
|
||||||
84 [label="Stub [5]" style="filled" fillcolor=gray];
|
|
||||||
85 [label="Exit block [5]" style="filled" fillcolor=gray];
|
|
||||||
}
|
|
||||||
86 [label="Exit function g [5]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
80 -> {81};
|
|
||||||
81 -> {82};
|
|
||||||
82 -> {83};
|
|
||||||
83 -> {86};
|
|
||||||
83 -> {84} [style=dotted];
|
|
||||||
84 -> {85} [style=dotted];
|
|
||||||
85 -> {86} [style=dotted];
|
|
||||||
|
|
||||||
subgraph cluster_29 {
|
|
||||||
color=red
|
|
||||||
87 [label="Enter function h [5]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_30 {
|
|
||||||
color=blue
|
|
||||||
88 [label="Enter block [5]"];
|
|
||||||
subgraph cluster_31 {
|
|
||||||
color=blue
|
|
||||||
89 [label="Function call arguments enter [5]"];
|
|
||||||
90 [label="Access variable this@R|/Inner| [5]"];
|
|
||||||
91 [label="Function call arguments exit [5]"];
|
|
||||||
}
|
|
||||||
92 [label="Function call: this@R|/Inner|.R|/Inner.innerFun|() [5]" style="filled" fillcolor=yellow];
|
|
||||||
93 [label="Jump: ^h this@R|/Inner|.R|/Inner.innerFun|() [5]"];
|
|
||||||
94 [label="Stub [5]" style="filled" fillcolor=gray];
|
|
||||||
95 [label="Exit block [5]" style="filled" fillcolor=gray];
|
|
||||||
}
|
|
||||||
96 [label="Exit function h [5]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
87 -> {88};
|
|
||||||
88 -> {89};
|
|
||||||
89 -> {90};
|
|
||||||
90 -> {91};
|
|
||||||
91 -> {92};
|
|
||||||
92 -> {93};
|
|
||||||
93 -> {96};
|
|
||||||
93 -> {94} [style=dotted];
|
|
||||||
94 -> {95} [style=dotted];
|
|
||||||
95 -> {96} [style=dotted];
|
|
||||||
|
|
||||||
subgraph cluster_32 {
|
|
||||||
color=red
|
|
||||||
97 [label="Enter function i [5]" style="filled" fillcolor=red];
|
|
||||||
subgraph cluster_33 {
|
|
||||||
color=blue
|
|
||||||
98 [label="Enter block [5]"];
|
|
||||||
99 [label="Access variable this@R|/Inner| [5]"];
|
|
||||||
100 [label="Access variable R|/Inner.innerProp| [5]"];
|
|
||||||
101 [label="Jump: ^i this@R|/Inner|.R|/Inner.innerProp| [5]"];
|
|
||||||
102 [label="Stub [5]" style="filled" fillcolor=gray];
|
|
||||||
103 [label="Exit block [5]" style="filled" fillcolor=gray];
|
|
||||||
}
|
|
||||||
104 [label="Exit function i [5]" style="filled" fillcolor=red];
|
|
||||||
}
|
|
||||||
97 -> {98};
|
|
||||||
98 -> {99};
|
|
||||||
99 -> {100};
|
|
||||||
100 -> {101};
|
|
||||||
101 -> {104};
|
|
||||||
101 -> {102} [style=dotted];
|
|
||||||
102 -> {103} [style=dotted];
|
|
||||||
103 -> {104} [style=dotted];
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
// LL_FIR_DIVERGENCE
|
|
||||||
// KT-62841
|
|
||||||
// LL_FIR_DIVERGENCE
|
|
||||||
// !WITH_NEW_INFERENCE
|
|
||||||
// documents inconsistency between scripts and classes, see DeclarationScopeProviderImpl
|
|
||||||
// DUMP_CFG: LEVELS
|
|
||||||
|
|
||||||
fun function() = 42
|
|
||||||
val property = ""
|
|
||||||
|
|
||||||
class Nested {
|
|
||||||
fun f() = function()
|
|
||||||
fun g() = property
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
<!WRONG_MODIFIER_CONTAINING_DECLARATION!>inner<!> class Inner {
|
|
||||||
fun innerFun() = function()
|
|
||||||
val innerProp = property
|
|
||||||
fun innerThisFun() = this<!UNRESOLVED_LABEL!>@NestedInnerClass<!>.function()
|
|
||||||
val innerThisProp = this<!UNRESOLVED_LABEL!>@NestedInnerClass<!>.property
|
|
||||||
|
|
||||||
inner class InnerInner {
|
|
||||||
fun f() = innerFun()
|
|
||||||
fun g() = innerProp
|
|
||||||
fun h() = this@Inner.innerFun()
|
|
||||||
fun i() = this@Inner.innerProp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// LL_FIR_DIVERGENCE
|
|
||||||
// KT-62841
|
|
||||||
// LL_FIR_DIVERGENCE
|
|
||||||
// TARGET_BACKEND: JVM_IR
|
|
||||||
// !LANGUAGE: +ProhibitScriptTopLevelInnerClasses
|
|
||||||
|
|
||||||
<!WRONG_MODIFIER_CONTAINING_DECLARATION!>inner<!> class A
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// LL_FIR_DIVERGENCE
|
|
||||||
// KT-62841
|
|
||||||
// LL_FIR_DIVERGENCE
|
|
||||||
// TARGET_BACKEND: JVM_IR
|
|
||||||
// !LANGUAGE: -ProhibitScriptTopLevelInnerClasses
|
|
||||||
|
|
||||||
<!WRONG_MODIFIER_CONTAINING_DECLARATION!>inner<!> class A
|
|
||||||
Reference in New Issue
Block a user