[Analysis API] add some basic tests for symbol substitution
This commit is contained in:
@@ -33,6 +33,10 @@ sourceSets {
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
|
||||
}
|
||||
|
||||
testsJar()
|
||||
|
||||
projectTest {
|
||||
|
||||
+7
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.signatures.KtCallableSignature
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
@@ -127,6 +128,9 @@ 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
|
||||
}
|
||||
|
||||
@@ -140,6 +144,9 @@ 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
|
||||
*/
|
||||
|
||||
+12
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtAnalysisSessionComponent
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtAnalysisSessionMixIn
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
@@ -136,3 +137,14 @@ public interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public val ROOT_PACKAGE_SYMBOL: KtPackageSymbol
|
||||
get() = withValidityAssertion { analysisSession.symbolProvider.ROOT_PACKAGE_SYMBOL }
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public inline fun <reified S : KtSymbol> KtDeclaration.getSymbolOfType(): S =
|
||||
withValidityAssertion { getSymbol() } as S
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public inline fun <reified S : KtSymbol> KtDeclaration.getSymbolOfTypeSafe(): S? =
|
||||
withValidityAssertion { getSymbol() } as? S
|
||||
|
||||
|
||||
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// SUBSTITUTOR: T->kotlin.collections.List<S>;S->kotlin.Long
|
||||
|
||||
fun <T, S> f<caret>oo(x: List<T>, y: Map<T, List<S>>, k: String): T
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
KtDeclaration: KtNamedFunction
|
||||
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
|
||||
|
||||
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>
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// SUBSTITUTOR: T->kotlin.collections.List<S>;S->kotlin.Long
|
||||
|
||||
val <T, S> Map<T, S>.val<caret>ue: List<S>
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
KtDeclaration: KtProperty
|
||||
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>
|
||||
|
||||
Signature after substitution:
|
||||
kotlin.collections.Map<kotlin.collections.List<S>, kotlin.Long>.value: kotlin.collections.List<kotlin.Long>
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
fun <T> f<caret>oo(x: List<T>, y: Map<T, String>, k: String): Int
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
KtDeclaration: KtNamedFunction
|
||||
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
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
var foo: Int
|
||||
g<caret>et() = 10
|
||||
set(value){}
|
||||
analysis/analysis-api/testData/components/signatureSubstitution/symbolAsSignature/propertyGetter.txt
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
KtDeclaration: KtPropertyAccessor
|
||||
Symbol:
|
||||
get()
|
||||
|
||||
Signature:
|
||||
(): kotlin.Int
|
||||
+1
@@ -0,0 +1 @@
|
||||
val f<caret>oo: Int = 10
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
KtDeclaration: KtProperty
|
||||
Symbol:
|
||||
val foo: kotlin.Int
|
||||
|
||||
Signature:
|
||||
foo: kotlin.Int
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
var foo: Int
|
||||
get() = 10
|
||||
se<caret>t(value){}
|
||||
analysis/analysis-api/testData/components/signatureSubstitution/symbolAsSignature/propertySetter.txt
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
KtDeclaration: KtPropertyAccessor
|
||||
Symbol:
|
||||
set(value: kotlin.Int)
|
||||
|
||||
Signature:
|
||||
(value: kotlin.Int): kotlin.Unit
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
var f<caret>oo: Int
|
||||
get() = 10
|
||||
set(value){}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
KtDeclaration: KtProperty
|
||||
Symbol:
|
||||
var foo: kotlin.Int
|
||||
|
||||
Signature:
|
||||
foo: kotlin.Int
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// SUBSTITUTOR: T->kotlin.collections.List<S>;S->kotlin.Long
|
||||
|
||||
fun <T, S> f<caret>oo(x: List<T>, y: Map<T, List<S>>, k: String): T
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
KtDeclaration: KtNamedFunction
|
||||
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>
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
// SUBSTITUTOR: T->kotlin.collections.List<S>;S->kotlin.Long
|
||||
|
||||
val <T, S> Map<T, S>.val<caret>ue: List<S>
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
KtDeclaration: KtProperty
|
||||
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>
|
||||
Reference in New Issue
Block a user