[Analysis API] use existing test utilities for rendering
This commit is contained in:
-4
@@ -36,10 +36,6 @@ internal class KtFe10SymbolDeclarationRendererProvider(
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun render(signature: KtCallableSignature<*>, options: KtDeclarationRendererOptions): String {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun render(type: KtType, options: KtTypeRendererOptions): String {
|
||||
require(type is KtFe10Type)
|
||||
return prettyPrint { KtFe10TypeRenderer(options).render(type.type, this) }
|
||||
|
||||
-17
@@ -33,23 +33,6 @@ internal class KtFirSymbolDeclarationRendererProvider(
|
||||
return ConeTypeIdeRenderer(analysisSession.firResolveSession.useSiteFirSession, options).renderType(type.coneType)
|
||||
}
|
||||
|
||||
override fun render(signature: KtCallableSignature<*>, options: KtDeclarationRendererOptions): String = prettyPrint {
|
||||
signature.receiverType?.let {
|
||||
append(render(it, options.typeRendererOptions))
|
||||
append('.')
|
||||
}
|
||||
signature.symbol.callableIdIfNonLocal?.callableName?.asString()?.let { append(it) }
|
||||
if (signature is KtFunctionLikeSignature<*>) {
|
||||
printCollection(signature.valueParameters, ", ", "(", ")") { parameter ->
|
||||
append(parameter.name.asString())
|
||||
append(": ")
|
||||
append(render(parameter.returnType, options.typeRendererOptions))
|
||||
}
|
||||
}
|
||||
append(": ")
|
||||
append(render(signature.returnType, options.typeRendererOptions))
|
||||
}
|
||||
|
||||
override fun renderDeclaration(symbol: KtDeclarationSymbol, options: KtDeclarationRendererOptions): String {
|
||||
require(symbol is KtFirSymbol<*>)
|
||||
symbol.firSymbol.ensureResolved(FirResolvePhase.BODY_RESOLVE)
|
||||
|
||||
+3
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.signatureSubstitution
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.stringRepresentation
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.getSymbolOfType
|
||||
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiSingleFileTest
|
||||
@@ -36,12 +37,12 @@ abstract class AbstractAnalysisApiSignatureSubstitutionTest : AbstractAnalysisAp
|
||||
appendLine()
|
||||
|
||||
appendLine("Signature before substitution:")
|
||||
appendLine(signatureBeforeSubstitution.render())
|
||||
appendLine(stringRepresentation(signatureBeforeSubstitution))
|
||||
|
||||
appendLine()
|
||||
|
||||
appendLine("Signature after substitution:")
|
||||
appendLine(signatureAfterSubstitution.render())
|
||||
appendLine(stringRepresentation(signatureAfterSubstitution))
|
||||
}
|
||||
}
|
||||
testServices.assertions.assertEqualsToTestDataFileSibling(actual)
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.signatureSubstitution
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.stringRepresentation
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.getSymbolOfType
|
||||
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiSingleFileTest
|
||||
@@ -23,7 +24,7 @@ abstract class AbstractAnalysisApiSymbolAsSignatureTest : AbstractAnalysisApiSin
|
||||
val symbol = declaration.getSymbolOfType<KtCallableSymbol>()
|
||||
val signature = symbol.asSignature()
|
||||
val renderedSymbol = symbol.render()
|
||||
val renderedSignature = signature.render()
|
||||
val renderedSignature = stringRepresentation(signature)
|
||||
prettyPrint {
|
||||
appendLine("KtDeclaration: ${declaration::class.simpleName}")
|
||||
|
||||
|
||||
+3
-4
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.signatureSubstitution
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.stringRepresentation
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.getSymbolOfType
|
||||
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiSingleFileTest
|
||||
@@ -26,18 +27,16 @@ abstract class AbstractAnalysisApiSymbolSubstitutionTest : AbstractAnalysisApiSi
|
||||
val substitutor = with(SubstitutionParser) { parseSubstitutors(module, ktFile) }.single()
|
||||
|
||||
val signature = symbol.substitute(substitutor)
|
||||
val renderedSymbol = symbol.render()
|
||||
val renderedSignature = signature.render()
|
||||
prettyPrint {
|
||||
appendLine("KtDeclaration: ${declaration::class.simpleName}")
|
||||
|
||||
appendLine("Symbol:")
|
||||
appendLine(renderedSymbol)
|
||||
appendLine(symbol.render())
|
||||
|
||||
appendLine()
|
||||
|
||||
appendLine("Signature:")
|
||||
appendLine(renderedSignature)
|
||||
appendLine(stringRepresentation(signature))
|
||||
}
|
||||
}
|
||||
testServices.assertions.assertEqualsToTestDataFileSibling(actual)
|
||||
|
||||
+3
-7
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.analysis.api.components.buildClassType
|
||||
import org.jetbrains.kotlin.analysis.api.components.buildSubstitutor
|
||||
import org.jetbrains.kotlin.analysis.api.components.buildTypeParameterType
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.KtMapBackedSubstitutor
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.stringRepresentation
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.getSymbolOfType
|
||||
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiSingleFileTest
|
||||
@@ -49,17 +50,12 @@ abstract class AbstractSubstitutorBuilderTest : AbstractAnalysisApiSingleFileTes
|
||||
appendLine()
|
||||
|
||||
appendLine("Substitutor:")
|
||||
appendLine(
|
||||
(substitutor as KtMapBackedSubstitutor)
|
||||
.getAsMap()
|
||||
.entries
|
||||
.joinToString { (k, v) -> "${k.name} -> ${v.render()}" }
|
||||
)
|
||||
appendLine(stringRepresentation(substitutor))
|
||||
|
||||
appendLine()
|
||||
|
||||
appendLine("Signature after substitution:")
|
||||
appendLine(signatureAfterSubstitution.render())
|
||||
appendLine(stringRepresentation(signatureAfterSubstitution))
|
||||
}
|
||||
}
|
||||
testServices.assertions.assertEqualsToTestDataFileSibling(actual)
|
||||
|
||||
+2
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.analysis.api.impl.base.KtMapBackedSubstitutor
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtSubstitutor
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.KVisibility
|
||||
@@ -78,6 +79,7 @@ internal fun KtAnalysisSession.stringRepresentation(any: Any): String = with(any
|
||||
is KtType -> render()
|
||||
is Enum<*> -> name
|
||||
is Name -> asString()
|
||||
is CallableId -> toString()
|
||||
else -> buildString {
|
||||
val clazz = this@with::class
|
||||
val className = clazz.simpleName!!
|
||||
|
||||
-5
@@ -129,8 +129,6 @@ public enum class RendererModifier(public val includeByDefault: Boolean) {
|
||||
public abstract class KtSymbolDeclarationRendererProvider : KtAnalysisSessionComponent() {
|
||||
public abstract fun renderDeclaration(symbol: KtDeclarationSymbol, options: KtDeclarationRendererOptions): String
|
||||
|
||||
public abstract fun render(signature: KtCallableSignature<*>, options: KtDeclarationRendererOptions): String
|
||||
|
||||
public abstract fun render(type: KtType, options: KtTypeRendererOptions): String
|
||||
}
|
||||
|
||||
@@ -144,9 +142,6 @@ public interface KtSymbolDeclarationRendererMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtDeclarationSymbol.render(options: KtDeclarationRendererOptions = KtDeclarationRendererOptions.DEFAULT): String =
|
||||
withValidityAssertion { analysisSession.symbolDeclarationRendererProvider.renderDeclaration(this, options) }
|
||||
|
||||
public fun KtCallableSignature<*>.render(options: KtDeclarationRendererOptions = KtDeclarationRendererOptions.DEFAULT): String =
|
||||
withValidityAssertion { analysisSession.symbolDeclarationRendererProvider.render(this, options) }
|
||||
|
||||
/**
|
||||
* Render kotlin type into the representable Kotlin type string
|
||||
*/
|
||||
|
||||
Vendored
+50
-2
@@ -3,7 +3,55 @@ Symbol:
|
||||
fun <T, S> foo(x: kotlin.collections.List<T>, y: kotlin.collections.Map<T, kotlin.collections.List<S>>, k: kotlin.String): T
|
||||
|
||||
Signature before substitution:
|
||||
foo(x: kotlin.collections.List<T>, y: kotlin.collections.Map<T, kotlin.collections.List<S>>, k: kotlin.String): T
|
||||
KtFunctionLikeSignature:
|
||||
receiverType = null
|
||||
returnType = T
|
||||
symbol = /foo(x: kotlin.collections.List<T>, y: kotlin.collections.Map<T, kotlin.collections.List<S>>, k: kotlin.String): T
|
||||
valueParameters = [
|
||||
KtVariableLikeSignature:
|
||||
name = x
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.List<T>
|
||||
symbol = x: kotlin.collections.List<T>
|
||||
callableIdIfNonLocal = null,
|
||||
KtVariableLikeSignature:
|
||||
name = y
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.Map<T, kotlin.collections.List<S>>
|
||||
symbol = y: kotlin.collections.Map<T, kotlin.collections.List<S>>
|
||||
callableIdIfNonLocal = null,
|
||||
KtVariableLikeSignature:
|
||||
name = k
|
||||
receiverType = null
|
||||
returnType = kotlin.String
|
||||
symbol = k: kotlin.String
|
||||
callableIdIfNonLocal = null
|
||||
]
|
||||
callableIdIfNonLocal = /foo
|
||||
|
||||
Signature after substitution:
|
||||
foo(x: kotlin.collections.List<kotlin.collections.List<S>>, y: kotlin.collections.Map<kotlin.collections.List<S>, kotlin.collections.List<kotlin.Long>>, k: kotlin.String): kotlin.collections.List<S>
|
||||
KtFunctionLikeSignature:
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.List<S>
|
||||
symbol = /foo(x: kotlin.collections.List<T>, y: kotlin.collections.Map<T, kotlin.collections.List<S>>, k: kotlin.String): T
|
||||
valueParameters = [
|
||||
KtVariableLikeSignature:
|
||||
name = x
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.List<kotlin.collections.List<S>>
|
||||
symbol = x: kotlin.collections.List<T>
|
||||
callableIdIfNonLocal = null,
|
||||
KtVariableLikeSignature:
|
||||
name = y
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.Map<kotlin.collections.List<S>, kotlin.collections.List<kotlin.Long>>
|
||||
symbol = y: kotlin.collections.Map<T, kotlin.collections.List<S>>
|
||||
callableIdIfNonLocal = null,
|
||||
KtVariableLikeSignature:
|
||||
name = k
|
||||
receiverType = null
|
||||
returnType = kotlin.String
|
||||
symbol = k: kotlin.String
|
||||
callableIdIfNonLocal = null
|
||||
]
|
||||
callableIdIfNonLocal = /foo
|
||||
|
||||
Vendored
+12
-2
@@ -3,7 +3,17 @@ Symbol:
|
||||
val <T, S> kotlin.collections.Map<T, S>.value: kotlin.collections.List<S>
|
||||
|
||||
Signature before substitution:
|
||||
kotlin.collections.Map<T, S>.value: kotlin.collections.List<S>
|
||||
KtVariableLikeSignature:
|
||||
name = value
|
||||
receiverType = kotlin.collections.Map<T, S>
|
||||
returnType = kotlin.collections.List<S>
|
||||
symbol = val value: kotlin.collections.List<S>
|
||||
callableIdIfNonLocal = /value
|
||||
|
||||
Signature after substitution:
|
||||
kotlin.collections.Map<kotlin.collections.List<S>, kotlin.Long>.value: kotlin.collections.List<kotlin.Long>
|
||||
KtVariableLikeSignature:
|
||||
name = value
|
||||
receiverType = kotlin.collections.Map<kotlin.collections.List<S>, kotlin.Long>
|
||||
returnType = kotlin.collections.List<kotlin.Long>
|
||||
symbol = val value: kotlin.collections.List<S>
|
||||
callableIdIfNonLocal = /value
|
||||
|
||||
Vendored
+25
-1
@@ -3,4 +3,28 @@ Symbol:
|
||||
fun <T> foo(x: kotlin.collections.List<T>, y: kotlin.collections.Map<T, kotlin.String>, k: kotlin.String): kotlin.Int
|
||||
|
||||
Signature:
|
||||
foo(x: kotlin.collections.List<T>, y: kotlin.collections.Map<T, kotlin.String>, k: kotlin.String): kotlin.Int
|
||||
KtFunctionLikeSignature:
|
||||
receiverType = null
|
||||
returnType = kotlin.Int
|
||||
symbol = /foo(x: kotlin.collections.List<T>, y: kotlin.collections.Map<T, kotlin.String>, k: kotlin.String): kotlin.Int
|
||||
valueParameters = [
|
||||
KtVariableLikeSignature:
|
||||
name = x
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.List<T>
|
||||
symbol = x: kotlin.collections.List<T>
|
||||
callableIdIfNonLocal = null,
|
||||
KtVariableLikeSignature:
|
||||
name = y
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.Map<T, kotlin.String>
|
||||
symbol = y: kotlin.collections.Map<T, kotlin.String>
|
||||
callableIdIfNonLocal = null,
|
||||
KtVariableLikeSignature:
|
||||
name = k
|
||||
receiverType = null
|
||||
returnType = kotlin.String
|
||||
symbol = k: kotlin.String
|
||||
callableIdIfNonLocal = null
|
||||
]
|
||||
callableIdIfNonLocal = /foo
|
||||
|
||||
analysis/analysis-api/testData/components/signatureSubstitution/symbolAsSignature/propertyGetter.txt
Vendored
+6
-1
@@ -3,4 +3,9 @@ Symbol:
|
||||
get()
|
||||
|
||||
Signature:
|
||||
(): kotlin.Int
|
||||
KtFunctionLikeSignature:
|
||||
receiverType = null
|
||||
returnType = kotlin.Int
|
||||
symbol = <getter>(): kotlin.Int
|
||||
valueParameters = []
|
||||
callableIdIfNonLocal = null
|
||||
|
||||
+6
-1
@@ -3,4 +3,9 @@ Symbol:
|
||||
val foo: kotlin.Int
|
||||
|
||||
Signature:
|
||||
foo: kotlin.Int
|
||||
KtVariableLikeSignature:
|
||||
name = foo
|
||||
receiverType = null
|
||||
returnType = kotlin.Int
|
||||
symbol = val foo: kotlin.Int
|
||||
callableIdIfNonLocal = /foo
|
||||
|
||||
analysis/analysis-api/testData/components/signatureSubstitution/symbolAsSignature/propertySetter.txt
Vendored
+13
-1
@@ -3,4 +3,16 @@ Symbol:
|
||||
set(value: kotlin.Int)
|
||||
|
||||
Signature:
|
||||
(value: kotlin.Int): kotlin.Unit
|
||||
KtFunctionLikeSignature:
|
||||
receiverType = null
|
||||
returnType = kotlin.Unit
|
||||
symbol = <setter>(value: kotlin.Int): kotlin.Unit
|
||||
valueParameters = [
|
||||
KtVariableLikeSignature:
|
||||
name = value
|
||||
receiverType = null
|
||||
returnType = kotlin.Int
|
||||
symbol = value: kotlin.Int
|
||||
callableIdIfNonLocal = null
|
||||
]
|
||||
callableIdIfNonLocal = null
|
||||
|
||||
+6
-1
@@ -3,4 +3,9 @@ Symbol:
|
||||
var foo: kotlin.Int
|
||||
|
||||
Signature:
|
||||
foo: kotlin.Int
|
||||
KtVariableLikeSignature:
|
||||
name = foo
|
||||
receiverType = null
|
||||
returnType = kotlin.Int
|
||||
symbol = var foo: kotlin.Int
|
||||
callableIdIfNonLocal = /foo
|
||||
|
||||
Vendored
+25
-1
@@ -3,4 +3,28 @@ Symbol:
|
||||
fun <T, S> foo(x: kotlin.collections.List<T>, y: kotlin.collections.Map<T, kotlin.collections.List<S>>, k: kotlin.String): T
|
||||
|
||||
Signature:
|
||||
foo(x: kotlin.collections.List<kotlin.collections.List<S>>, y: kotlin.collections.Map<kotlin.collections.List<S>, kotlin.collections.List<kotlin.Long>>, k: kotlin.String): kotlin.collections.List<S>
|
||||
KtFunctionLikeSignature:
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.List<S>
|
||||
symbol = /foo(x: kotlin.collections.List<T>, y: kotlin.collections.Map<T, kotlin.collections.List<S>>, k: kotlin.String): T
|
||||
valueParameters = [
|
||||
KtVariableLikeSignature:
|
||||
name = x
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.List<kotlin.collections.List<S>>
|
||||
symbol = x: kotlin.collections.List<T>
|
||||
callableIdIfNonLocal = null,
|
||||
KtVariableLikeSignature:
|
||||
name = y
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.Map<kotlin.collections.List<S>, kotlin.collections.List<kotlin.Long>>
|
||||
symbol = y: kotlin.collections.Map<T, kotlin.collections.List<S>>
|
||||
callableIdIfNonLocal = null,
|
||||
KtVariableLikeSignature:
|
||||
name = k
|
||||
receiverType = null
|
||||
returnType = kotlin.String
|
||||
symbol = k: kotlin.String
|
||||
callableIdIfNonLocal = null
|
||||
]
|
||||
callableIdIfNonLocal = /foo
|
||||
|
||||
Vendored
+6
-1
@@ -3,4 +3,9 @@ Symbol:
|
||||
val <T, S> kotlin.collections.Map<T, S>.value: kotlin.collections.List<S>
|
||||
|
||||
Signature:
|
||||
kotlin.collections.Map<kotlin.collections.List<S>, kotlin.Long>.value: kotlin.collections.List<kotlin.Long>
|
||||
KtVariableLikeSignature:
|
||||
name = value
|
||||
receiverType = kotlin.collections.Map<kotlin.collections.List<S>, kotlin.Long>
|
||||
returnType = kotlin.collections.List<kotlin.Long>
|
||||
symbol = val value: kotlin.collections.List<S>
|
||||
callableIdIfNonLocal = /value
|
||||
|
||||
Vendored
+14
-2
@@ -3,7 +3,19 @@ Symbol:
|
||||
fun <A, B, C> A.fooo(x: kotlin.collections.List<B>): C
|
||||
|
||||
Substitutor:
|
||||
A -> kotlin.Int, B -> kotlin.Long, C -> kotlin.collections.List<kotlin.String>
|
||||
<map substitutor: {A = kotlin/Int, B = kotlin/Long, C = kotlin/collections/List<kotlin/String>}>
|
||||
|
||||
Signature after substitution:
|
||||
kotlin.Int.fooo(x: kotlin.collections.List<kotlin.Long>): kotlin.collections.List<kotlin.String>
|
||||
KtFunctionLikeSignature:
|
||||
receiverType = kotlin.Int
|
||||
returnType = kotlin.collections.List<kotlin.String>
|
||||
symbol = /fooo(<extension receiver>: A, x: kotlin.collections.List<B>): C
|
||||
valueParameters = [
|
||||
KtVariableLikeSignature:
|
||||
name = x
|
||||
receiverType = null
|
||||
returnType = kotlin.collections.List<kotlin.Long>
|
||||
symbol = x: kotlin.collections.List<B>
|
||||
callableIdIfNonLocal = null
|
||||
]
|
||||
callableIdIfNonLocal = /fooo
|
||||
|
||||
Reference in New Issue
Block a user