[FIR IDE] Add unwrapping substitution overrides which doesn't affect function's signature

Also, do not use PSI to restore SUBSTITUTION_OVERRIDE function/property
symbols
This commit is contained in:
Roman Golyshev
2021-10-28 13:16:33 +03:00
committed by teamcityserver
parent 2766dc938b
commit fa8bb47bdf
51 changed files with 1291 additions and 33 deletions
@@ -0,0 +1,47 @@
/*
* Copyright 2010-2021 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.impl.base.test.scopes
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.impl.barebone.test.FrontendApiTestConfiguratorService
import org.jetbrains.kotlin.analysis.api.impl.barebone.test.expressionMarkerProvider
import org.jetbrains.kotlin.analysis.api.impl.base.test.symbols.AbstractSymbolTest
import org.jetbrains.kotlin.analysis.api.symbols.DebugSymbolRenderer
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
import org.jetbrains.kotlin.psi.KtClassLikeDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.ConfigurationDirectives
import org.jetbrains.kotlin.test.services.TestServices
abstract class AbstractSubstitutionOverridesUnwrappingTest(
configurator: FrontendApiTestConfiguratorService
) : AbstractSymbolTest(configurator) {
override fun KtAnalysisSession.collectSymbols(ktFile: KtFile, testServices: TestServices): List<KtSymbol> {
val declarationUnderCaret = testServices.expressionMarkerProvider.getElementOfTypAtCaret<KtClassLikeDeclaration>(ktFile)
val classSymbolUnderCaret = declarationUnderCaret.getSymbol() as KtClassLikeSymbol
require(classSymbolUnderCaret is KtSymbolWithMembers)
return classSymbolUnderCaret.getMemberScope().getAllSymbols().toList()
}
override fun KtAnalysisSession.renderSymbolForComparison(symbol: KtSymbol): String {
return with(DebugSymbolRenderer) { renderForSubstitutionOverrideUnwrappingTest(symbol) }
}
override fun configureTest(builder: TestConfigurationBuilder) {
super.configureTest(builder)
with(builder) {
defaultDirectives {
+ConfigurationDirectives.WITH_STDLIB
}
}
}
}
@@ -35,7 +35,7 @@ abstract class AbstractSymbolTest(configurator: FrontendApiTestConfiguratorServi
collectSymbols(ktFile, testServices).map { symbol ->
PointerWithRenderedSymbol(
if (createPointers) symbol.createPointer() else null,
with(DebugSymbolRenderer) { renderExtra(symbol) }
renderSymbolForComparison(symbol)
)
}
}
@@ -66,12 +66,17 @@ abstract class AbstractSymbolTest(configurator: FrontendApiTestConfiguratorServi
pointersWithRendered.map { (pointer, expectedRender) ->
val restored = pointer!!.restoreSymbol()
?: error("Symbol $expectedRender was not restored")
with(DebugSymbolRenderer) { renderExtra(restored) }
renderSymbolForComparison(restored)
}
}
val actual = restored.joinToString(separator = "\n\n")
testServices.assertions.assertEqualsToTestDataFileSibling(actual)
}
protected open fun KtAnalysisSession.renderSymbolForComparison(symbol: KtSymbol): String {
return with(DebugSymbolRenderer) { renderExtra(symbol) }
}
}
private object SymbolTestDirectives : SimpleDirectivesContainer() {