[AA] KT-55098 Render context receivers in declarations & function types
- `context(...)` is a modifier that must precede annotations and other modifiers, so for declarations it is rendered in `renderAnnotationsAndModifiers`. - Ignore `@ContextFunctionTypeParams` in the annotation list of FE10 types, as the annotation is an implementation detail of context receivers in K1 and shouldn't be rendered. ^KT-55098 fixed
This commit is contained in:
committed by
Space Team
parent
e2804693bf
commit
2cd16f055a
+4
-1
@@ -28,7 +28,10 @@ interface KtFe10Type : KtLifetimeOwner, KtAnnotated {
|
||||
KtFe10AnnotationsList.create(
|
||||
type.annotations,
|
||||
token,
|
||||
ignoreAnnotations = setOf(StandardClassIds.Annotations.ExtensionFunctionType)
|
||||
ignoreAnnotations = setOf(
|
||||
StandardClassIds.Annotations.ExtensionFunctionType,
|
||||
StandardClassIds.Annotations.ContextFunctionTypeParams,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -70,6 +70,12 @@ public class Fe10IdeNormalAnalysisSourceModuleRendererTestGenerated extends Abst
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/constructorOfAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextReceiver.kt")
|
||||
public void testContextReceiver() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/contextReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegates.kt")
|
||||
public void testDelegates() throws Exception {
|
||||
@@ -228,5 +234,11 @@ public class Fe10IdeNormalAnalysisSourceModuleRendererTestGenerated extends Abst
|
||||
public void testAnnotationOnTypesWithComplexExpression() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/types/annotationOnTypesWithComplexExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextFunctionTypes.kt")
|
||||
public void testContextFunctionTypes() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/types/contextFunctionTypes.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -70,6 +70,12 @@ public class FirIdeDependentAnalysisSourceModuleRendererTestGenerated extends Ab
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/constructorOfAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextReceiver.kt")
|
||||
public void testContextReceiver() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/contextReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegates.kt")
|
||||
public void testDelegates() throws Exception {
|
||||
@@ -228,5 +234,11 @@ public class FirIdeDependentAnalysisSourceModuleRendererTestGenerated extends Ab
|
||||
public void testAnnotationOnTypesWithComplexExpression() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/types/annotationOnTypesWithComplexExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextFunctionTypes.kt")
|
||||
public void testContextFunctionTypes() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/types/contextFunctionTypes.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -70,6 +70,12 @@ public class FirIdeNormalAnalysisSourceModuleRendererTestGenerated extends Abstr
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/constructorOfAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextReceiver.kt")
|
||||
public void testContextReceiver() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/contextReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegates.kt")
|
||||
public void testDelegates() throws Exception {
|
||||
@@ -228,5 +234,11 @@ public class FirIdeNormalAnalysisSourceModuleRendererTestGenerated extends Abstr
|
||||
public void testAnnotationOnTypesWithComplexExpression() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/types/annotationOnTypesWithComplexExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextFunctionTypes.kt")
|
||||
public void testContextFunctionTypes() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/types/contextFunctionTypes.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -70,6 +70,12 @@ public class FirStandaloneNormalAnalysisSourceModuleRendererTestGenerated extend
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/constructorOfAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextReceiver.kt")
|
||||
public void testContextReceiver() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/contextReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegates.kt")
|
||||
public void testDelegates() throws Exception {
|
||||
@@ -228,5 +234,11 @@ public class FirStandaloneNormalAnalysisSourceModuleRendererTestGenerated extend
|
||||
public void testAnnotationOnTypesWithComplexExpression() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/types/annotationOnTypesWithComplexExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextFunctionTypes.kt")
|
||||
public void testContextFunctionTypes() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/symbolDeclarationRenderer/renderDeclaration/types/contextFunctionTypes.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.renderer.base.contextReceivers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiversOwner
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.renderers.KtContextReceiverLabelRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.renderers.KtContextReceiverListRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public class KtContextReceiversRenderer(
|
||||
public val contextReceiverListRenderer: KtContextReceiverListRenderer,
|
||||
public val contextReceiverLabelRenderer: KtContextReceiverLabelRenderer,
|
||||
) {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderContextReceivers(owner: KtContextReceiversOwner, printer: PrettyPrinter) {
|
||||
contextReceiverListRenderer.renderContextReceivers(owner, printer)
|
||||
}
|
||||
|
||||
public inline fun with(action: Builder.() -> Unit): KtContextReceiversRenderer {
|
||||
val renderer = this
|
||||
return KtContextReceiversRenderer {
|
||||
this.contextReceiverListRenderer = renderer.contextReceiverListRenderer
|
||||
this.contextReceiverLabelRenderer = renderer.contextReceiverLabelRenderer
|
||||
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
public lateinit var contextReceiverListRenderer: KtContextReceiverListRenderer
|
||||
public lateinit var contextReceiverLabelRenderer: KtContextReceiverLabelRenderer
|
||||
|
||||
public fun build(): KtContextReceiversRenderer = KtContextReceiversRenderer(
|
||||
contextReceiverListRenderer,
|
||||
contextReceiverLabelRenderer,
|
||||
)
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public inline operator fun invoke(action: Builder.() -> Unit): KtContextReceiversRenderer =
|
||||
Builder().apply(action).build()
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.renderer.base.contextReceivers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.renderers.KtContextReceiverLabelRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.renderers.KtContextReceiverListRenderer
|
||||
|
||||
public object KtContextReceiversRendererForSource {
|
||||
public val WITH_LABELS: KtContextReceiversRenderer = KtContextReceiversRenderer {
|
||||
contextReceiverListRenderer = KtContextReceiverListRenderer.AS_SOURCE
|
||||
contextReceiverLabelRenderer = KtContextReceiverLabelRenderer.WITH_LABEL
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.renderer.base.contextReceivers.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiver
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.KtContextReceiversRenderer
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
|
||||
public interface KtContextReceiverLabelRenderer {
|
||||
context(KtAnalysisSession, KtContextReceiversRenderer)
|
||||
public fun renderLabel(contextReceiver: KtContextReceiver, printer: PrettyPrinter)
|
||||
|
||||
public object WITH_LABEL : KtContextReceiverLabelRenderer {
|
||||
context(KtAnalysisSession, KtContextReceiversRenderer)
|
||||
override fun renderLabel(contextReceiver: KtContextReceiver, printer: PrettyPrinter): Unit = printer {
|
||||
val label = contextReceiver.label ?: return@printer
|
||||
append(label.render())
|
||||
append('@')
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.renderer.base.contextReceivers.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiversOwner
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.KtContextReceiversRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtContextReceiverListRenderer {
|
||||
context(KtAnalysisSession, KtContextReceiversRenderer, KtTypeRenderer)
|
||||
public fun renderContextReceivers(owner: KtContextReceiversOwner, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtContextReceiverListRenderer {
|
||||
context(KtAnalysisSession, KtContextReceiversRenderer, KtTypeRenderer)
|
||||
override fun renderContextReceivers(owner: KtContextReceiversOwner, printer: PrettyPrinter) {
|
||||
val contextReceivers = owner.contextReceivers
|
||||
if (contextReceivers.isEmpty()) return
|
||||
|
||||
printer {
|
||||
append("context(")
|
||||
printCollection(contextReceivers) { contextReceiver ->
|
||||
contextReceiverLabelRenderer.renderLabel(contextReceiver, printer)
|
||||
renderType(contextReceiver.type, printer)
|
||||
}
|
||||
append(")")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.KtKeywordRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.KtContextReceiversRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.bodies.*
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.KtDeclarationModifiersRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.*
|
||||
@@ -27,6 +28,7 @@ import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
public class KtDeclarationRenderer private constructor(
|
||||
public val nameRenderer: KtDeclarationNameRenderer,
|
||||
public val keywordRenderer: KtKeywordRenderer,
|
||||
public val contextReceiversRenderer: KtContextReceiversRenderer,
|
||||
public val codeStyle: KtRendererCodeStyle,
|
||||
public val typeRenderer: KtTypeRenderer,
|
||||
public val annotationRenderer: KtAnnotationRenderer,
|
||||
@@ -110,6 +112,7 @@ public class KtDeclarationRenderer private constructor(
|
||||
return KtDeclarationRenderer {
|
||||
this.nameRenderer = renderer.nameRenderer
|
||||
this.keywordRender = renderer.keywordRenderer
|
||||
this.contextReceiversRenderer = renderer.contextReceiversRenderer
|
||||
this.codeStyle = renderer.codeStyle
|
||||
this.typeRenderer = renderer.typeRenderer
|
||||
this.annotationRenderer = renderer.annotationRenderer
|
||||
@@ -174,6 +177,7 @@ public class KtDeclarationRenderer private constructor(
|
||||
public open class Builder {
|
||||
public lateinit var returnTypeFilter: KtCallableReturnTypeFilter
|
||||
public lateinit var nameRenderer: KtDeclarationNameRenderer
|
||||
public lateinit var contextReceiversRenderer: KtContextReceiversRenderer
|
||||
public lateinit var keywordRender: KtKeywordRenderer
|
||||
public lateinit var codeStyle: KtRendererCodeStyle
|
||||
public lateinit var typeRenderer: KtTypeRenderer
|
||||
@@ -229,6 +233,7 @@ public class KtDeclarationRenderer private constructor(
|
||||
public fun build(): KtDeclarationRenderer = KtDeclarationRenderer(
|
||||
nameRenderer,
|
||||
keywordRender,
|
||||
contextReceiversRenderer,
|
||||
codeStyle,
|
||||
typeRenderer,
|
||||
annotationRenderer,
|
||||
|
||||
+10
-6
@@ -17,6 +17,9 @@ public interface KtRendererCodeStyle {
|
||||
context(KtAnalysisSession)
|
||||
public fun getIndentSize(): Int
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public fun getSeparatorAfterContextReceivers(): String
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public fun getSeparatorBetweenAnnotationAndOwner(symbol: KtAnnotated): String
|
||||
|
||||
@@ -31,9 +34,11 @@ public interface KtRendererCodeStyle {
|
||||
}
|
||||
|
||||
public object KtRecommendedRendererCodeStyle : KtRendererCodeStyle {
|
||||
context(KtAnalysisSession) override fun getIndentSize(): Int {
|
||||
return 4
|
||||
}
|
||||
context(KtAnalysisSession)
|
||||
override fun getIndentSize(): Int = 4
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun getSeparatorAfterContextReceivers(): String = "\n"
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun getSeparatorBetweenAnnotationAndOwner(symbol: KtAnnotated): String {
|
||||
@@ -55,9 +60,8 @@ public object KtRecommendedRendererCodeStyle : KtRendererCodeStyle {
|
||||
}
|
||||
}
|
||||
|
||||
context(KtAnalysisSession) override fun getSeparatorBetweenModifiers(): String {
|
||||
return " "
|
||||
}
|
||||
context(KtAnalysisSession)
|
||||
override fun getSeparatorBetweenModifiers(): String = " "
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun getSeparatorBetweenMembers(first: KtDeclarationSymbol, second: KtDeclarationSymbol): String {
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations.impl
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.KtKeywordRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.KtContextReceiversRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtCallableReturnTypeFilter
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtRecommendedRendererCodeStyle
|
||||
@@ -29,6 +30,7 @@ public object KtDeclarationRendererForSource {
|
||||
public val WITH_QUALIFIED_NAMES: KtDeclarationRenderer = KtDeclarationRenderer {
|
||||
nameRenderer = KtDeclarationNameRenderer.QUOTED
|
||||
keywordRender = KtKeywordRenderer.AS_WORD
|
||||
contextReceiversRenderer = KtContextReceiversRendererForSource.WITH_LABELS
|
||||
codeStyle = KtRecommendedRendererCodeStyle
|
||||
modifiersRenderer = KtDeclarationModifiersRendererForSource.NO_IMPLICIT_MODIFIERS
|
||||
classifierBodyRenderer = KtClassifierBodyRenderer.NO_BODY
|
||||
@@ -87,4 +89,3 @@ public object KtDeclarationRendererForSource {
|
||||
typeRenderer = KtTypeRendererForSource.WITH_SHORT_NAMES
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-6
@@ -7,25 +7,28 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiversOwner
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun <S> renderAnnotationsAndModifiers(
|
||||
public fun <S> renderAnnotationsModifiersAndContextReceivers(
|
||||
symbol: S,
|
||||
printer: PrettyPrinter,
|
||||
keyword: KtKeywordToken,
|
||||
): Unit where S : KtAnnotated, S : KtDeclarationSymbol = printer {
|
||||
renderAnnotationsAndModifiers(symbol, printer, listOf(keyword))
|
||||
renderAnnotationsModifiersAndContextReceivers(symbol, printer, listOf(keyword))
|
||||
}
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun <S> renderAnnotationsAndModifiers(
|
||||
public fun <S> renderAnnotationsModifiersAndContextReceivers(
|
||||
symbol: S,
|
||||
printer: PrettyPrinter,
|
||||
keywords: List<KtKeywordToken>,
|
||||
): Unit where S : KtAnnotated, S : KtDeclarationSymbol = printer {
|
||||
renderContextReceivers(symbol, printer)
|
||||
|
||||
val annotationsRendered: Boolean
|
||||
val modifiersRendered: Boolean
|
||||
codeStyle.getSeparatorBetweenAnnotationAndOwner(symbol).separated(
|
||||
@@ -43,14 +46,25 @@ public fun <S> renderAnnotationsAndModifiers(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun <S> renderAnnotationsAndModifiers(
|
||||
public fun <S> renderAnnotationsModifiersAndContextReceivers(
|
||||
symbol: S,
|
||||
printer: PrettyPrinter,
|
||||
): Unit where S : KtAnnotated, S : KtDeclarationSymbol = printer {
|
||||
renderContextReceivers(symbol, printer)
|
||||
codeStyle.getSeparatorBetweenAnnotationAndOwner(symbol).separated(
|
||||
{ annotationRenderer.renderAnnotations(symbol, printer) },
|
||||
{ modifiersRenderer.renderDeclarationModifiers(symbol, printer) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
private fun renderContextReceivers(symbol: KtDeclarationSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
if (symbol !is KtContextReceiversOwner) return
|
||||
|
||||
with(typeRenderer) {
|
||||
withSuffix(codeStyle.getSeparatorAfterContextReceivers()) {
|
||||
contextReceiversRenderer.renderContextReceivers(symbol, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.callab
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsAndModifiers
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsModifiersAndContextReceivers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
@@ -22,8 +22,8 @@ public interface KtCallableSignatureRenderer {
|
||||
override fun renderCallableSignature(symbol: KtCallableSymbol, keyword: KtKeywordToken?, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{
|
||||
if (keyword != null) renderAnnotationsAndModifiers(symbol, printer, keyword)
|
||||
else renderAnnotationsAndModifiers(symbol, printer)
|
||||
if (keyword != null) renderAnnotationsModifiersAndContextReceivers(symbol, printer, keyword)
|
||||
else renderAnnotationsModifiersAndContextReceivers(symbol, printer)
|
||||
},
|
||||
{ typeParametersRenderer.renderTypeParameters(symbol, printer) },
|
||||
{
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.callab
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsAndModifiers
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsModifiersAndContextReceivers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
@@ -19,7 +19,7 @@ public interface KtEnumEntrySymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtEnumEntrySymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ renderAnnotationsAndModifiers(symbol, printer) },
|
||||
{ renderAnnotationsModifiersAndContextReceivers(symbol, printer) },
|
||||
{ nameRenderer.renderName(symbol, printer) },
|
||||
{ classifierBodyRenderer.renderBody(symbol, printer) },
|
||||
)
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.callab
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsAndModifiers
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsModifiersAndContextReceivers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertyGetterSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -21,7 +21,7 @@ public interface KtPropertyGetterSymbolRenderer {
|
||||
override fun renderSymbol(symbol: KtPropertyGetterSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{
|
||||
renderAnnotationsAndModifiers(symbol, printer, KtTokens.GET_KEYWORD)
|
||||
renderAnnotationsModifiersAndContextReceivers(symbol, printer, KtTokens.GET_KEYWORD)
|
||||
valueParametersRenderer.renderValueParameters(symbol, printer)
|
||||
},
|
||||
{ accessorBodyRenderer.renderBody(symbol, printer) },
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.callab
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsAndModifiers
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsModifiersAndContextReceivers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySetterSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -21,7 +21,7 @@ public interface KtPropertySetterSymbolRenderer {
|
||||
override fun renderSymbol(symbol: KtPropertySetterSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{
|
||||
renderAnnotationsAndModifiers(symbol, printer, KtTokens.SET_KEYWORD)
|
||||
renderAnnotationsModifiersAndContextReceivers(symbol, printer, KtTokens.SET_KEYWORD)
|
||||
valueParametersRenderer.renderValueParameters(symbol, printer)
|
||||
},
|
||||
{ accessorBodyRenderer.renderBody(symbol, printer) },
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classi
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsAndModifiers
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsModifiersAndContextReceivers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtAnonymousObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -22,7 +22,7 @@ public interface KtAnonymousObjectSymbolRenderer {
|
||||
" ".separated(
|
||||
{
|
||||
" : ".separated(
|
||||
{ renderAnnotationsAndModifiers(symbol, printer, KtTokens.OBJECT_KEYWORD) },
|
||||
{ renderAnnotationsModifiersAndContextReceivers(symbol, printer, KtTokens.OBJECT_KEYWORD) },
|
||||
{ superTypeListRenderer.renderSuperTypes(symbol, printer) }
|
||||
)
|
||||
},
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classi
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsAndModifiers
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsModifiersAndContextReceivers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
||||
@@ -32,7 +32,7 @@ public interface KtNamedClassOrObjectSymbolRenderer {
|
||||
}
|
||||
|
||||
" ".separated(
|
||||
{ renderAnnotationsAndModifiers(symbol, printer, keywords) },
|
||||
{ renderAnnotationsModifiersAndContextReceivers(symbol, printer, keywords) },
|
||||
{
|
||||
val primaryConstructor =
|
||||
bodyMemberScopeProvider.getMemberScope(symbol).filterIsInstance<KtConstructorSymbol>()
|
||||
@@ -41,7 +41,7 @@ public interface KtNamedClassOrObjectSymbolRenderer {
|
||||
nameRenderer.renderName(symbol, printer)
|
||||
typeParametersRenderer.renderTypeParameters(symbol, printer)
|
||||
if (primaryConstructor != null) {
|
||||
val annotationsPrinted = checkIfPrinted { renderAnnotationsAndModifiers(primaryConstructor, printer) }
|
||||
val annotationsPrinted = checkIfPrinted { renderAnnotationsModifiersAndContextReceivers(primaryConstructor, printer) }
|
||||
if (annotationsPrinted) {
|
||||
withPrefix(" ") {
|
||||
keywordRenderer.renderKeyword(KtTokens.CONSTRUCTOR_KEYWORD, primaryConstructor, printer)
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classi
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsAndModifiers
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderAnnotationsModifiersAndContextReceivers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -20,7 +20,7 @@ public interface KtTypeAliasSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtTypeAliasSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ renderAnnotationsAndModifiers(symbol, printer, KtTokens.TYPE_ALIAS_KEYWORD) },
|
||||
{ renderAnnotationsModifiersAndContextReceivers(symbol, printer, KtTokens.TYPE_ALIAS_KEYWORD) },
|
||||
{
|
||||
" = ".separated(
|
||||
{
|
||||
|
||||
+5
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.renderer.types
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.KtContextReceiversRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.KtKeywordRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtRendererTypeApproximator
|
||||
@@ -31,6 +32,7 @@ public class KtTypeRenderer private constructor(
|
||||
public val typeApproximator: KtRendererTypeApproximator,
|
||||
public val typeProjectionRenderer: KtTypeProjectionRenderer,
|
||||
public val annotationsRenderer: KtAnnotationRenderer,
|
||||
public val contextReceiversRenderer: KtContextReceiversRenderer,
|
||||
public val keywordRenderer: KtKeywordRenderer,
|
||||
) {
|
||||
context(KtAnalysisSession)
|
||||
@@ -69,6 +71,7 @@ public class KtTypeRenderer private constructor(
|
||||
this.typeApproximator = renderer.typeApproximator
|
||||
this.typeProjectionRenderer = renderer.typeProjectionRenderer
|
||||
this.annotationsRenderer = renderer.annotationsRenderer
|
||||
this.contextReceiversRenderer = renderer.contextReceiversRenderer
|
||||
this.keywordRenderer = renderer.keywordRenderer
|
||||
action()
|
||||
}
|
||||
@@ -96,6 +99,7 @@ public class KtTypeRenderer private constructor(
|
||||
public lateinit var typeApproximator: KtRendererTypeApproximator
|
||||
public lateinit var typeProjectionRenderer: KtTypeProjectionRenderer
|
||||
public lateinit var annotationsRenderer: KtAnnotationRenderer
|
||||
public lateinit var contextReceiversRenderer: KtContextReceiversRenderer
|
||||
public lateinit var keywordRenderer: KtKeywordRenderer
|
||||
|
||||
public fun build(): KtTypeRenderer = KtTypeRenderer(
|
||||
@@ -115,6 +119,7 @@ public class KtTypeRenderer private constructor(
|
||||
typeApproximator,
|
||||
typeProjectionRenderer,
|
||||
annotationsRenderer,
|
||||
contextReceiversRenderer,
|
||||
keywordRenderer,
|
||||
)
|
||||
}
|
||||
|
||||
+2
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.renderer.types.impl
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.KtKeywordRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.contextReceivers.KtContextReceiversRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtRendererTypeApproximator
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.renderers.*
|
||||
@@ -29,6 +30,7 @@ public object KtTypeRendererForSource {
|
||||
typeApproximator = KtRendererTypeApproximator.TO_DENNOTABLE
|
||||
typeProjectionRenderer = KtTypeProjectionRenderer.WITH_VARIANCE
|
||||
annotationsRenderer = KtAnnotationRendererForSource.WITH_QUALIFIED_NAMES
|
||||
contextReceiversRenderer = KtContextReceiversRendererForSource.WITH_LABELS
|
||||
keywordRenderer = KtKeywordRenderer.AS_WORD
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -24,6 +24,11 @@ public interface KtFunctionalTypeRenderer {
|
||||
if (annotationsRendered) printer.append(" ")
|
||||
if (annotationsRendered || type.nullability == KtTypeNullability.NULLABLE) append("(")
|
||||
" ".separated(
|
||||
{
|
||||
if (type.hasContextReceivers) {
|
||||
contextReceiversRenderer.renderContextReceivers(type, printer)
|
||||
}
|
||||
},
|
||||
{
|
||||
if (type.isSuspend) {
|
||||
keywordRenderer.renderKeyword(KtTokens.SUSPEND_KEYWORD, type, printer)
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
interface Context1
|
||||
|
||||
interface Context2<A> {
|
||||
fun getContextElement(): A
|
||||
}
|
||||
|
||||
class Context2Impl<A>(value: A) : Context2<A> {
|
||||
override fun getContextElement(): A
|
||||
|
||||
val value: A
|
||||
}
|
||||
|
||||
context(Int, String)
|
||||
class A {
|
||||
constructor(int: Int)
|
||||
}
|
||||
|
||||
context(Context1, c2@Context2<String>)
|
||||
class B {
|
||||
override fun toString(): String
|
||||
}
|
||||
|
||||
context(Context2<A>)
|
||||
class C<A> {
|
||||
val a: A
|
||||
get()
|
||||
}
|
||||
|
||||
context(Context1)
|
||||
@Deprecated(message = "Use `B` instead.")
|
||||
class D
|
||||
|
||||
context(b@B, `fun`@A)
|
||||
fun foo()
|
||||
|
||||
context(Context2<C<String>>)
|
||||
fun bar(): ERROR
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
interface Context1
|
||||
|
||||
interface Context2<A> {
|
||||
fun getContextElement(): A
|
||||
}
|
||||
|
||||
class Context2Impl<A>(val value: A) : Context2<A> {
|
||||
override fun getContextElement(): A = value
|
||||
}
|
||||
|
||||
context(Int, String)
|
||||
class A {
|
||||
context(Double)
|
||||
constructor(int: Int) {}
|
||||
}
|
||||
|
||||
context(Context1, c2@Context2<String>)
|
||||
class B {
|
||||
override fun toString(): String = getContextElement()
|
||||
}
|
||||
|
||||
context(Context2<A>)
|
||||
class C<A> {
|
||||
val a: A
|
||||
get() = getContextElement()
|
||||
}
|
||||
|
||||
context(Context1)
|
||||
@Deprecated("Use `B` instead.")
|
||||
class D
|
||||
|
||||
context(b@B, `fun`@A)
|
||||
fun foo() = Unit
|
||||
|
||||
context(Context2<C<String>>)
|
||||
fun bar() = with (Context2Impl(getContextElement().a)) { C() }
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
interface Context1
|
||||
|
||||
interface Context2<A> {
|
||||
fun getContextElement(): A
|
||||
}
|
||||
|
||||
class Context2Impl<A>(value: A) : Context2<A> {
|
||||
override fun getContextElement(): A
|
||||
|
||||
val value: A
|
||||
}
|
||||
|
||||
context(Int, String)
|
||||
class A {
|
||||
constructor(int: Int)
|
||||
}
|
||||
|
||||
context(Context1, c2@Context2<String>)
|
||||
class B {
|
||||
override fun toString(): String
|
||||
}
|
||||
|
||||
context(Context2<A>)
|
||||
class C<A> {
|
||||
val a: A
|
||||
get()
|
||||
}
|
||||
|
||||
context(Context1)
|
||||
@Deprecated(message = "Use `B` instead.")
|
||||
class D
|
||||
|
||||
context(b@B, `fun`@A)
|
||||
fun foo()
|
||||
|
||||
context(Context2<C<String>>)
|
||||
fun bar(): C<String>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
interface A
|
||||
interface B
|
||||
|
||||
val f1: context(A) () -> Unit = { }
|
||||
|
||||
val f2: context(B, A) Int.() -> Unit = { }
|
||||
|
||||
val f3: (Int) -> (context(A) (String) -> String) = { { "" } }
|
||||
|
||||
val f4: (context(A) B.(Int) -> Unit) -> (context(B) (Int) -> Unit) = { { } }
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface A
|
||||
|
||||
interface B
|
||||
|
||||
val f1: context(A) () -> Unit
|
||||
|
||||
val f2: context(B, A) Int.() -> Unit
|
||||
|
||||
val f3: (Int) -> context(A) (String) -> String
|
||||
|
||||
val f4: (context(A) B.(Int) -> Unit) -> context(B) (Int) -> Unit
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
context(kotlin.Int, s@kotlin.String)
|
||||
class A {
|
||||
constructor(int: kotlin.Int)
|
||||
}
|
||||
|
||||
+1
@@ -1 +1,2 @@
|
||||
context(kotlin.Int, s@kotlin.String)
|
||||
fun y()
|
||||
|
||||
+1
@@ -1,2 +1,3 @@
|
||||
context(kotlin.Int, s@kotlin.String)
|
||||
val y: kotlin.Int
|
||||
get()
|
||||
Vendored
+4
@@ -1,9 +1,13 @@
|
||||
context(A)
|
||||
fun tooo()
|
||||
|
||||
context(B)
|
||||
fun tooo()
|
||||
|
||||
context(A, B)
|
||||
fun tooo()
|
||||
|
||||
context(B, A)
|
||||
fun tooo()
|
||||
|
||||
class A
|
||||
|
||||
@@ -142,6 +142,7 @@ object StandardClassIds {
|
||||
val PublishedApi = "PublishedApi".baseId()
|
||||
val SinceKotlin = "SinceKotlin".baseId()
|
||||
val ExtensionFunctionType = "ExtensionFunctionType".baseId()
|
||||
val ContextFunctionTypeParams = "ContextFunctionTypeParams".baseId()
|
||||
val Deprecated = "Deprecated".baseId()
|
||||
val DeprecatedSinceKotlin = "DeprecatedSinceKotlin".baseId()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user