K2: prefer base class sources for JVM mapped functions
This commit is a follow-up to 3cb9396b20
"K2: prefer derived class sources for callable copies (e.g. fake overrides)"
#KT-64044 Fixed
This commit is contained in:
committed by
Space Team
parent
c80854eb7c
commit
f5453690a6
+6
@@ -118,6 +118,12 @@ public class Fe10IdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exte
|
|||||||
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("CollectionStream.kt")
|
||||||
|
public void testCollectionStream() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/CollectionStream.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("CompanionObjectWithName1.kt")
|
@TestMetadata("CompanionObjectWithName1.kt")
|
||||||
public void testCompanionObjectWithName1() throws Exception {
|
public void testCompanionObjectWithName1() throws Exception {
|
||||||
|
|||||||
+6
@@ -118,6 +118,12 @@ public class FirIdeDependentAnalysisSourceModuleReferenceResolveTestGenerated ex
|
|||||||
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("CollectionStream.kt")
|
||||||
|
public void testCollectionStream() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/CollectionStream.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("CompanionObjectWithName1.kt")
|
@TestMetadata("CompanionObjectWithName1.kt")
|
||||||
public void testCompanionObjectWithName1() throws Exception {
|
public void testCompanionObjectWithName1() throws Exception {
|
||||||
|
|||||||
+6
@@ -118,6 +118,12 @@ public class FirIdeNormalAnalysisLibrarySourceModuleReferenceResolveTestGenerate
|
|||||||
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("CollectionStream.kt")
|
||||||
|
public void testCollectionStream() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/CollectionStream.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("CompanionObjectWithName1.kt")
|
@TestMetadata("CompanionObjectWithName1.kt")
|
||||||
public void testCompanionObjectWithName1() throws Exception {
|
public void testCompanionObjectWithName1() throws Exception {
|
||||||
|
|||||||
+6
@@ -118,6 +118,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exten
|
|||||||
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("CollectionStream.kt")
|
||||||
|
public void testCollectionStream() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/CollectionStream.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("CompanionObjectWithName1.kt")
|
@TestMetadata("CompanionObjectWithName1.kt")
|
||||||
public void testCompanionObjectWithName1() throws Exception {
|
public void testCompanionObjectWithName1() throws Exception {
|
||||||
|
|||||||
+7
-2
@@ -78,8 +78,9 @@ abstract class AbstractReferenceResolveTest : AbstractAnalysisApiBasedTest() {
|
|||||||
val resolvedTo = analyzeReferenceElement(ktReferences.first().element, mainModule) {
|
val resolvedTo = analyzeReferenceElement(ktReferences.first().element, mainModule) {
|
||||||
val symbols = ktReferences.flatMap { it.resolveToSymbols() }
|
val symbols = ktReferences.flatMap { it.resolveToSymbols() }
|
||||||
checkReferenceResultForValidity(ktReferences, mainModule, testServices, symbols)
|
checkReferenceResultForValidity(ktReferences, mainModule, testServices, symbols)
|
||||||
renderResolvedTo(symbols, renderingOptions) { getAdditionalSymbolInfo(it) }
|
val renderPsiClassName = Directives.RENDER_PSI_CLASS_NAME in mainModule.directives
|
||||||
}
|
renderResolvedTo(symbols, renderPsiClassName, renderingOptions) { getAdditionalSymbolInfo(it) }
|
||||||
|
}
|
||||||
|
|
||||||
if (Directives.UNRESOLVED_REFERENCE in mainModule.directives) {
|
if (Directives.UNRESOLVED_REFERENCE in mainModule.directives) {
|
||||||
return
|
return
|
||||||
@@ -119,6 +120,10 @@ abstract class AbstractReferenceResolveTest : AbstractAnalysisApiBasedTest() {
|
|||||||
val UNRESOLVED_REFERENCE by directive(
|
val UNRESOLVED_REFERENCE by directive(
|
||||||
"Reference should be unresolved",
|
"Reference should be unresolved",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val RENDER_PSI_CLASS_NAME by directive(
|
||||||
|
"Render also PSI class name for resolved reference"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val renderingOptions = KtDeclarationRendererForDebug.WITH_QUALIFIED_NAMES.with {
|
private val renderingOptions = KtDeclarationRendererForDebug.WITH_QUALIFIED_NAMES.with {
|
||||||
|
|||||||
+9
-2
@@ -17,16 +17,18 @@ import org.jetbrains.kotlin.types.Variance
|
|||||||
object TestReferenceResolveResultRenderer {
|
object TestReferenceResolveResultRenderer {
|
||||||
fun KtAnalysisSession.renderResolvedTo(
|
fun KtAnalysisSession.renderResolvedTo(
|
||||||
symbols: List<KtSymbol>,
|
symbols: List<KtSymbol>,
|
||||||
|
renderPsiClassName: Boolean = false,
|
||||||
renderer: KtDeclarationRenderer = KtDeclarationRendererForDebug.WITH_QUALIFIED_NAMES,
|
renderer: KtDeclarationRenderer = KtDeclarationRendererForDebug.WITH_QUALIFIED_NAMES,
|
||||||
additionalInfo: KtAnalysisSession.(KtSymbol) -> String? = { null }
|
additionalInfo: KtAnalysisSession.(KtSymbol) -> String? = { null }
|
||||||
) =
|
) =
|
||||||
symbols.map { renderResolveResult(it, renderer, additionalInfo) }
|
symbols.map { renderResolveResult(it, renderPsiClassName, renderer, additionalInfo) }
|
||||||
.sorted()
|
.sorted()
|
||||||
.withIndex()
|
.withIndex()
|
||||||
.joinToString(separator = "\n") { "${it.index}: ${it.value}" }
|
.joinToString(separator = "\n") { "${it.index}: ${it.value}" }
|
||||||
|
|
||||||
private fun KtAnalysisSession.renderResolveResult(
|
private fun KtAnalysisSession.renderResolveResult(
|
||||||
symbol: KtSymbol,
|
symbol: KtSymbol,
|
||||||
|
renderPsiClassName: Boolean,
|
||||||
renderer: KtDeclarationRenderer,
|
renderer: KtDeclarationRenderer,
|
||||||
additionalInfo: KtAnalysisSession.(KtSymbol) -> String?
|
additionalInfo: KtAnalysisSession.(KtSymbol) -> String?
|
||||||
): String {
|
): String {
|
||||||
@@ -35,7 +37,12 @@ object TestReferenceResolveResultRenderer {
|
|||||||
append("(in $fqName) ")
|
append("(in $fqName) ")
|
||||||
}
|
}
|
||||||
when (symbol) {
|
when (symbol) {
|
||||||
is KtDeclarationSymbol -> append(symbol.render(renderer))
|
is KtDeclarationSymbol -> {
|
||||||
|
append(symbol.render(renderer))
|
||||||
|
if (renderPsiClassName) {
|
||||||
|
append(" (psi: ${symbol.psi?.let { it::class.simpleName }})")
|
||||||
|
}
|
||||||
|
}
|
||||||
is KtPackageSymbol -> append("package ${symbol.fqName}")
|
is KtPackageSymbol -> append("package ${symbol.fqName}")
|
||||||
is KtReceiverParameterSymbol -> {
|
is KtReceiverParameterSymbol -> {
|
||||||
append("extension receiver with type ")
|
append("extension receiver with type ")
|
||||||
|
|||||||
+6
@@ -118,6 +118,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceResolveTestGenerate
|
|||||||
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/ClassReferenceInImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("CollectionStream.kt")
|
||||||
|
public void testCollectionStream() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/CollectionStream.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("CompanionObjectWithName1.kt")
|
@TestMetadata("CompanionObjectWithName1.kt")
|
||||||
public void testCompanionObjectWithName1() throws Exception {
|
public void testCompanionObjectWithName1() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// ISSUE: KT-64044
|
||||||
|
// IGNORE_FE10
|
||||||
|
// (stream call is unresolved for some reason)
|
||||||
|
// FULL_JDK
|
||||||
|
// RENDER_PSI_CLASS_NAME
|
||||||
|
|
||||||
|
fun f(collection: Collection<String>) {
|
||||||
|
collection.strea<caret>m()
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Resolved to:
|
||||||
|
0: (in kotlin.collections.Collection) fun stream(): java.util.stream.Stream<E> (psi: ClsMethodImpl)
|
||||||
@@ -223,6 +223,7 @@ class JvmMappedScope(
|
|||||||
newDispatchReceiverType = kotlinDispatchReceiverType,
|
newDispatchReceiverType = kotlinDispatchReceiverType,
|
||||||
newParameterTypes = oldFunction.valueParameters.map { substitutor.substituteOrSelf(it.returnTypeRef.coneType) },
|
newParameterTypes = oldFunction.valueParameters.map { substitutor.substituteOrSelf(it.returnTypeRef.coneType) },
|
||||||
newReturnType = substitutor.substituteOrSelf(oldFunction.returnTypeRef.coneType),
|
newReturnType = substitutor.substituteOrSelf(oldFunction.returnTypeRef.coneType),
|
||||||
|
newSource = symbol.fir.source,
|
||||||
).apply {
|
).apply {
|
||||||
if (jdkMemberStatus == JDKMemberStatus.HIDDEN) {
|
if (jdkMemberStatus == JDKMemberStatus.HIDDEN) {
|
||||||
isHiddenEverywhereBesideSuperCalls = true
|
isHiddenEverywhereBesideSuperCalls = true
|
||||||
@@ -295,7 +296,8 @@ class JvmMappedScope(
|
|||||||
newTypeParameters = null,
|
newTypeParameters = null,
|
||||||
newContextReceiverTypes = emptyList(),
|
newContextReceiverTypes = emptyList(),
|
||||||
isExpect = false,
|
isExpect = false,
|
||||||
callableCopySubstitutionForTypeUpdater = null
|
callableCopySubstitutionForTypeUpdater = null,
|
||||||
|
newSource = oldConstructor.source,
|
||||||
)
|
)
|
||||||
return newSymbol
|
return newSymbol
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -120,8 +120,9 @@ object FirFakeOverrideGenerator {
|
|||||||
newModality: Modality? = null,
|
newModality: Modality? = null,
|
||||||
newVisibility: Visibility? = null,
|
newVisibility: Visibility? = null,
|
||||||
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null,
|
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution? = null,
|
||||||
|
newSource: KtSourceElement? = null,
|
||||||
): FirSimpleFunction = buildSimpleFunction {
|
): FirSimpleFunction = buildSimpleFunction {
|
||||||
source = derivedClassLookupTag?.toSymbol(session)?.source ?: baseFunction.source
|
source = newSource ?: derivedClassLookupTag?.toSymbol(session)?.source ?: baseFunction.source
|
||||||
moduleData = session.nullableModuleData ?: baseFunction.moduleData
|
moduleData = session.nullableModuleData ?: baseFunction.moduleData
|
||||||
this.origin = origin
|
this.origin = origin
|
||||||
name = baseFunction.name
|
name = baseFunction.name
|
||||||
@@ -153,11 +154,12 @@ object FirFakeOverrideGenerator {
|
|||||||
newTypeParameters: List<FirTypeParameterRef>?,
|
newTypeParameters: List<FirTypeParameterRef>?,
|
||||||
isExpect: Boolean,
|
isExpect: Boolean,
|
||||||
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution?,
|
callableCopySubstitutionForTypeUpdater: CallableCopySubstitution?,
|
||||||
|
newSource: KtSourceElement? = null,
|
||||||
): FirConstructor = buildConstructor {
|
): FirConstructor = buildConstructor {
|
||||||
// TODO: consider using here some light-weight functions instead of pseudo-real FirMemberFunctionImpl
|
// TODO: consider using here some light-weight functions instead of pseudo-real FirMemberFunctionImpl
|
||||||
// As second alternative, we can invent some light-weight kind of FirRegularClass
|
// As second alternative, we can invent some light-weight kind of FirRegularClass
|
||||||
annotations += baseConstructor.annotations
|
annotations += baseConstructor.annotations
|
||||||
source = derivedClassLookupTag?.toSymbol(session)?.source ?: baseConstructor.source
|
source = newSource ?: derivedClassLookupTag?.toSymbol(session)?.source ?: baseConstructor.source
|
||||||
moduleData = session.nullableModuleData ?: baseConstructor.moduleData
|
moduleData = session.nullableModuleData ?: baseConstructor.moduleData
|
||||||
this.origin = origin
|
this.origin = origin
|
||||||
receiverParameter = baseConstructor.receiverParameter?.let { receiverParameter ->
|
receiverParameter = baseConstructor.receiverParameter?.let { receiverParameter ->
|
||||||
|
|||||||
Reference in New Issue
Block a user