[Analysis Api] Expose klibSourceFile via KtKlibSourceFileProviderMixIn
This `klibSourceFile` information is deserialized from klibs to retain the information of the original SourceFile location of a declaration. ^KT-66271 Fixed
This commit is contained in:
committed by
Space Team
parent
6d8a4a28af
commit
6b98602afc
@@ -93,7 +93,8 @@ public abstract class KtAnalysisSession(final override val token: KtLifetimeToke
|
||||
KtCompilerFacilityMixIn,
|
||||
KtMetadataCalculatorMixIn,
|
||||
KtSubstitutorProviderMixIn,
|
||||
KtDataFlowInfoProviderMixin {
|
||||
KtDataFlowInfoProviderMixin,
|
||||
KtKlibSourceFileProviderMixIn {
|
||||
|
||||
public abstract val useSiteModule: KtModule
|
||||
|
||||
@@ -219,6 +220,9 @@ public abstract class KtAnalysisSession(final override val token: KtLifetimeToke
|
||||
internal val dataFlowInfoProvider: KtDataFlowInfoProvider get() = dataFlowInfoProviderImpl
|
||||
@KtAnalysisNonPublicApi
|
||||
protected abstract val dataFlowInfoProviderImpl: KtDataFlowInfoProvider
|
||||
|
||||
internal val klibSourceFileProvider: KtKlibSourceFileNameProvider get() = klibSourceFileProviderImpl
|
||||
protected abstract val klibSourceFileProviderImpl: KtKlibSourceFileNameProvider
|
||||
}
|
||||
|
||||
public fun KtAnalysisSession.getModule(element: PsiElement): KtModule {
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisNonPublicApi
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.descriptors.SourceFile
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
|
||||
@KtAnalysisNonPublicApi
|
||||
public abstract class KtKlibSourceFileNameProvider : KtAnalysisSessionComponent() {
|
||||
public abstract fun getKlibSourceFileName(declaration: KtDeclarationSymbol): String?
|
||||
}
|
||||
|
||||
@KtAnalysisNonPublicApi
|
||||
public interface KtKlibSourceFileProviderMixIn : KtAnalysisSessionMixIn {
|
||||
/**
|
||||
* If [KtDeclaration] is a deserialized, klib based symbol, then information about the original
|
||||
* [SourceFile] might be retained.
|
||||
*/
|
||||
public fun KtDeclarationSymbol.getKlibSourceFileName(): String? =
|
||||
withValidityAssertion { analysisSession.klibSourceFileProvider.getKlibSourceFileName(this) }
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// TARGET_PLATFORM: JS
|
||||
// MODULE_KIND: LibraryBinary
|
||||
|
||||
// FILE: Some.kt
|
||||
package some
|
||||
class Foo
|
||||
|
||||
// FILE: Other.kt
|
||||
package other
|
||||
class Bar
|
||||
analysis/analysis-api/testData/components/klibSourceFileNameProvider/getKlibSourceFileName/class.txt
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
klib declarations:
|
||||
Classifier: other/Bar; klibSourceFile: Other.kt
|
||||
Classifier: some/Foo; klibSourceFile: Some.kt
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// TARGET_PLATFORM: JS
|
||||
// MODULE_KIND: LibraryBinary
|
||||
|
||||
// FILE: Some.kt
|
||||
package some
|
||||
fun foo() = 42
|
||||
|
||||
// FILE: Other.kt
|
||||
package other
|
||||
fun bar() = 42
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
klib declarations:
|
||||
Callable: other/bar; klibSourceFile: Other.kt
|
||||
Callable: some/foo; klibSourceFile: Some.kt
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// TARGET_PLATFORM: JS
|
||||
// MODULE_KIND: LibraryBinary
|
||||
|
||||
// FILE: Some.kt
|
||||
package some
|
||||
val foo = 42
|
||||
|
||||
// FILE: Other.kt
|
||||
package other
|
||||
val bar = 42
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
klib declarations:
|
||||
Callable: other/bar; klibSourceFile: Other.kt
|
||||
Callable: some/foo; klibSourceFile: Some.kt
|
||||
Reference in New Issue
Block a user