HL API: render local fqNames in reference resolve tests

This commit is contained in:
Ilya Kirillov
2021-07-22 15:47:31 +02:00
committed by teamcityserver
parent 77fcb12af8
commit 91ecaa32e3
26 changed files with 45 additions and 40 deletions
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor() 0: (in test.Annotation) constructor()
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor(message: kotlin.String, replaceWith: kotlin.ReplaceWith = ..., level: kotlin.DeprecationLevel = ...) 0: (in kotlin.Deprecated) constructor(message: kotlin.String, replaceWith: kotlin.ReplaceWith = ..., level: kotlin.DeprecationLevel = ...)
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor(message: kotlin.String, replaceWith: kotlin.ReplaceWith = ..., level: kotlin.DeprecationLevel = ...) 0: (in kotlin.Deprecated) constructor(message: kotlin.String, replaceWith: kotlin.ReplaceWith = ..., level: kotlin.DeprecationLevel = ...)
@@ -1,4 +1,3 @@
// IGNORE_FIR
package t package t
class A { class A {
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor() 0: (in test.A) constructor()
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor() 0: (in test.A) constructor()
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor(value: java.lang.annotation.RetentionPolicy) 0: (in java.lang.annotation.Retention) constructor(value: java.lang.annotation.RetentionPolicy)
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor(s: kotlin.String) 0: (in JavaClass) constructor(s: kotlin.String)
@@ -2,7 +2,7 @@ package test
class Conflict class Conflict
fun test() { fun testFoo() {
class Conflict class Conflict
<caret>Conflict() <caret>Conflict()
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor() 0: (in test.Conflict) constructor()
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor() 0: (in test.Conflict) constructor()
@@ -2,7 +2,7 @@ package test
class Conflict class Conflict
fun test() { fun testFoo() {
class Conflict class Conflict
<caret>Conflict <caret>Conflict
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: class Conflict 0: (in <local>: testFoo) class Conflict
@@ -11,5 +11,3 @@ fun test() {
<caret>Conflict <caret>Conflict
} }
// REF: companion object of (test).Conflict
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: class Conflict 0: (in <local>: test) class Conflict
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor() 0: (in test.Conflict) constructor()
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor() 0: (in test.Conflict) constructor()
@@ -2,10 +2,8 @@ package test
object Conflict object Conflict
fun test() { fun testFoo() {
class Conflict class Conflict
<caret>Conflict() <caret>Conflict()
} }
// REF: (in test.test).Conflict
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor() 0: (in test.Conflict) constructor()
@@ -4,7 +4,7 @@ object Conflict {
operator fun invoke() {} operator fun invoke() {}
} }
fun test() { fun testFoo() {
class Conflict class Conflict
<caret>Conflict() <caret>Conflict()
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor() 0: (in test.Conflict) constructor()
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: class Conflict 0: (in <local>: test) class Conflict
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor(a: kotlin.Int) 0: (in A) constructor(a: kotlin.Int)
@@ -1,2 +1,2 @@
Resolved to: Resolved to:
0: constructor(b: kotlin.String) 0: (in A) constructor(b: kotlin.String)
@@ -13,10 +13,9 @@ import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
import org.jetbrains.kotlin.idea.frontend.api.analyse import org.jetbrains.kotlin.idea.frontend.api.analyse
import org.jetbrains.kotlin.idea.frontend.api.components.KtDeclarationRendererOptions import org.jetbrains.kotlin.idea.frontend.api.components.KtDeclarationRendererOptions
import org.jetbrains.kotlin.idea.frontend.api.components.RendererModifier import org.jetbrains.kotlin.idea.frontend.api.components.RendererModifier
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtCallableSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.*
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassLikeSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtNamedSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtConstructorSymbol import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithKind
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
import org.jetbrains.kotlin.idea.references.KtReference import org.jetbrains.kotlin.idea.references.KtReference
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
@@ -86,7 +85,7 @@ abstract class AbstractReferenceResolveTest : AbstractHLApiSingleModuleTest() {
private fun KtAnalysisSession.renderResolveResult(symbol: KtSymbol): String { private fun KtAnalysisSession.renderResolveResult(symbol: KtSymbol): String {
return buildString { return buildString {
symbolFqName(symbol)?.let { fqName -> symbolContainerFqName(symbol)?.let { fqName ->
append("(in $fqName) ") append("(in $fqName) ")
} }
append(symbol.render(renderingOptions)) append(symbol.render(renderingOptions))
@@ -94,12 +93,23 @@ abstract class AbstractReferenceResolveTest : AbstractHLApiSingleModuleTest() {
} }
@Suppress("unused")// KtAnalysisSession receiver @Suppress("unused")// KtAnalysisSession receiver
private fun KtAnalysisSession.symbolFqName(symbol: KtSymbol): String? = when (symbol) { private fun KtAnalysisSession.symbolContainerFqName(symbol: KtSymbol): String? {
is KtCallableSymbol -> symbol.callableIdIfNonLocal?.asSingleFqName()?.parent() if (symbol is KtPackageSymbol || symbol is KtValueParameterSymbol) return null
is KtClassLikeSymbol -> symbol.classIdIfNonLocal?.asSingleFqName()?.parent() val nonLocalFqName = when (symbol) {
is KtConstructorSymbol -> symbol.containingClassIdIfNonLocal?.asSingleFqName() is KtConstructorSymbol -> symbol.containingClassIdIfNonLocal?.asSingleFqName()
else -> null is KtCallableSymbol -> symbol.callableIdIfNonLocal?.asSingleFqName()?.parent()
}?.let { if (it == FqName.ROOT) "ROOT" else it.asString()} is KtClassLikeSymbol -> symbol.classIdIfNonLocal?.asSingleFqName()?.parent()
else -> null
}
when (nonLocalFqName) {
null -> Unit
FqName.ROOT -> return "ROOT"
else -> return nonLocalFqName.asString()
}
val container = (symbol as? KtSymbolWithKind)?.getContainingSymbol() ?: return null
val parents = generateSequence(container) { it.getContainingSymbol() }
return "<local>: " + parents.joinToString(separator = ".") { (it as? KtNamedSymbol)?.name?.asString() ?: "<no name>" }
}
private object Directives : SimpleDirectivesContainer() { private object Directives : SimpleDirectivesContainer() {
val UNRESOLVED_REFERENCE by directive( val UNRESOLVED_REFERENCE by directive(