[Analysis API] rework renderer
^KTIJ-23268 fixed
This commit is contained in:
+16
-9
@@ -6,15 +6,19 @@
|
||||
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.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.impl.KtDeclarationRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
/**
|
||||
* KtType to string renderer options
|
||||
* @see KtType
|
||||
* @see KtSymbolDeclarationRendererProvider.render
|
||||
* @see KtSymbolDeclarationRendererProvider.renderType
|
||||
*/
|
||||
public data class KtTypeRendererOptions(
|
||||
/**
|
||||
@@ -49,7 +53,7 @@ public data class KtTypeRendererOptions(
|
||||
/**
|
||||
* KtSymbol to string renderer options
|
||||
* @see KtSymbol
|
||||
* @see KtSymbolDeclarationRendererProvider.render
|
||||
* @see KtSymbolDeclarationRendererProvider.renderType
|
||||
*/
|
||||
public data class KtDeclarationRendererOptions(
|
||||
/**
|
||||
@@ -127,9 +131,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 renderDeclaration(symbol: KtDeclarationSymbol, renderer: KtDeclarationRenderer): String
|
||||
|
||||
public abstract fun render(type: KtType, options: KtTypeRendererOptions): String
|
||||
public abstract fun renderType(type: KtType, renderer: KtTypeRenderer, position: Variance): String
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,12 +143,15 @@ public interface KtSymbolDeclarationRendererMixIn : KtAnalysisSessionMixIn {
|
||||
/**
|
||||
* Render symbol into the representable Kotlin string
|
||||
*/
|
||||
public fun KtDeclarationSymbol.render(options: KtDeclarationRendererOptions = KtDeclarationRendererOptions.DEFAULT): String =
|
||||
withValidityAssertion { analysisSession.symbolDeclarationRendererProvider.renderDeclaration(this, options) }
|
||||
public fun KtDeclarationSymbol.render(renderer: KtDeclarationRenderer = KtDeclarationRendererForSource.WITH_QUALIFIED_NAMES): String =
|
||||
withValidityAssertion { analysisSession.symbolDeclarationRendererProvider.renderDeclaration(this, renderer) }
|
||||
|
||||
/**
|
||||
* Render kotlin type into the representable Kotlin type string
|
||||
*/
|
||||
public fun KtType.render(options: KtTypeRendererOptions = KtTypeRendererOptions.DEFAULT): String =
|
||||
withValidityAssertion { analysisSession.symbolDeclarationRendererProvider.render(this, options) }
|
||||
public fun KtType.render(
|
||||
renderer: KtTypeRenderer = KtTypeRendererForSource.WITH_QUALIFIED_NAMES,
|
||||
position: Variance,
|
||||
): String =
|
||||
withValidityAssertion { analysisSession.symbolDeclarationRendererProvider.renderType(this, renderer, position) }
|
||||
}
|
||||
+20
-6
@@ -19,7 +19,9 @@ import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
public abstract class KtTypeProvider : KtAnalysisSessionComponent() {
|
||||
public abstract val builtinTypes: KtBuiltinTypes
|
||||
|
||||
public abstract fun approximateToSuperPublicDenotableType(type: KtType): KtType?
|
||||
public abstract fun approximateToSuperPublicDenotableType(type: KtType, approximateLocalTypes: Boolean): KtType?
|
||||
|
||||
public abstract fun approximateToSubPublicDenotableType(type: KtType, approximateLocalTypes: Boolean): KtType?
|
||||
|
||||
public abstract fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType
|
||||
|
||||
@@ -50,13 +52,25 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* Approximates [KtType] with the a supertype which can be rendered in a source code
|
||||
*
|
||||
* Return `null` if the type do not need approximation and can be rendered as is
|
||||
* Otherwise, for type `T` return type `S` such `T <: S` and `T` and every it type argument is [org.jetbrains.kotlin.analysis.api.types.KtDenotableType]`
|
||||
* Otherwise, for type `T` return type `S` such `T <: S` and `T` and every it type argument is denotable
|
||||
*/
|
||||
public fun KtType.approximateToSuperPublicDenotable(): KtType? =
|
||||
withValidityAssertion { analysisSession.typeProvider.approximateToSuperPublicDenotableType(this) }
|
||||
public fun KtType.approximateToSuperPublicDenotable(approximateLocalTypes: Boolean): KtType? =
|
||||
withValidityAssertion { analysisSession.typeProvider.approximateToSuperPublicDenotableType(this, approximateLocalTypes) }
|
||||
|
||||
public fun KtType.approximateToSuperPublicDenotableOrSelf(): KtType =
|
||||
withValidityAssertion { approximateToSuperPublicDenotable() ?: this }
|
||||
/**
|
||||
* Approximates [KtType] with the a subtype which can be rendered in a source code
|
||||
*
|
||||
* Return `null` if the type do not need approximation and can be rendered as is
|
||||
* Otherwise, for type `T` return type `S` such `S <: T` and `T` and every it type argument is denotable
|
||||
*/
|
||||
public fun KtType.approximateToSubPublicDenotable(approximateLocalTypes: Boolean): KtType? =
|
||||
withValidityAssertion { analysisSession.typeProvider.approximateToSubPublicDenotableType(this, approximateLocalTypes) }
|
||||
|
||||
public fun KtType.approximateToSubPublicDenotableOrSelf(approximateLocalTypes: Boolean): KtType =
|
||||
withValidityAssertion { approximateToSubPublicDenotable(approximateLocalTypes) ?: this }
|
||||
|
||||
public fun KtType.approximateToSuperPublicDenotableOrSelf(approximateLocalTypes: Boolean): KtType =
|
||||
withValidityAssertion { approximateToSuperPublicDenotable(approximateLocalTypes) ?: this }
|
||||
|
||||
public fun KtNamedClassOrObjectSymbol.buildSelfClassType(): KtType =
|
||||
withValidityAssertion { analysisSession.typeProvider.buildSelfClassType(this) }
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
|
||||
public interface KtKeywordRenderer {
|
||||
context(KtAnalysisSession)
|
||||
public fun renderKeyword(keyword: KtKeywordToken, owner: KtAnnotated, printer: PrettyPrinter)
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public fun renderKeywords(keywords: List<KtKeywordToken>, owner: KtAnnotated, printer: PrettyPrinter) {
|
||||
printer.printCollection(keywords, separator = " ") {
|
||||
renderKeyword(it, owner, this)
|
||||
}
|
||||
}
|
||||
|
||||
public object AS_WORD : KtKeywordRenderer {
|
||||
context(KtAnalysisSession)
|
||||
override fun renderKeyword(keyword: KtKeywordToken, owner: KtAnnotated, printer: PrettyPrinter) {
|
||||
printer.append(keyword.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.renderers.KtAnnotationArgumentsRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.renderers.KtAnnotationListRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.renderers.KtAnnotationQualifierRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.renderers.KtAnnotationUseSiteTargetRenderer
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public class KtAnnotationRenderer internal constructor(
|
||||
public val annotationListRenderer: KtAnnotationListRenderer,
|
||||
public val annotationFilter: KtRendererAnnotationsFilter,
|
||||
public val annotationsQualifiedNameRenderer: KtAnnotationQualifierRenderer,
|
||||
public val annotationUseSiteTargetRenderer: KtAnnotationUseSiteTargetRenderer,
|
||||
public val annotationArgumentsRenderer: KtAnnotationArgumentsRenderer,
|
||||
) {
|
||||
context(KtAnalysisSession)
|
||||
public fun renderAnnotations(owner: KtAnnotated, printer: PrettyPrinter) {
|
||||
annotationListRenderer.renderAnnotations(owner, printer)
|
||||
}
|
||||
|
||||
public inline fun with(action: Builder.() -> Unit): KtAnnotationRenderer {
|
||||
val renderer = this
|
||||
return KtAnnotationRenderer {
|
||||
this.annotationListRenderer = renderer.annotationListRenderer
|
||||
this.annotationFilter = renderer.annotationFilter
|
||||
this.annotationsQualifiedNameRenderer = renderer.annotationsQualifiedNameRenderer
|
||||
this.annotationUseSiteTargetRenderer = renderer.annotationUseSiteTargetRenderer
|
||||
this.annotationArgumentsRenderer = renderer.annotationArgumentsRenderer
|
||||
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
public lateinit var annotationListRenderer: KtAnnotationListRenderer
|
||||
public lateinit var annotationFilter: KtRendererAnnotationsFilter
|
||||
public lateinit var annotationsQualifiedNameRenderer: KtAnnotationQualifierRenderer
|
||||
public lateinit var annotationUseSiteTargetRenderer: KtAnnotationUseSiteTargetRenderer
|
||||
public lateinit var annotationArgumentsRenderer: KtAnnotationArgumentsRenderer
|
||||
|
||||
|
||||
public fun build(): KtAnnotationRenderer = KtAnnotationRenderer(
|
||||
annotationListRenderer,
|
||||
annotationFilter,
|
||||
annotationsQualifiedNameRenderer,
|
||||
annotationUseSiteTargetRenderer,
|
||||
annotationArgumentsRenderer
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public inline operator fun invoke(action: Builder.() -> Unit): KtAnnotationRenderer =
|
||||
Builder().apply(action).build()
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.renderers.KtAnnotationArgumentsRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.renderers.KtAnnotationListRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.renderers.KtAnnotationQualifierRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.renderers.KtAnnotationUseSiteTargetRenderer
|
||||
|
||||
public object KtAnnotationRendererForSource {
|
||||
public val WITH_QUALIFIED_NAMES: KtAnnotationRenderer = KtAnnotationRenderer {
|
||||
annotationListRenderer = KtAnnotationListRenderer.FOR_SOURCE
|
||||
annotationFilter = KtRendererAnnotationsFilter.NO_NULLABILITY and KtRendererAnnotationsFilter.NO_PARAMETER_NAME
|
||||
annotationsQualifiedNameRenderer = KtAnnotationQualifierRenderer.WITH_QUALIFIED_NAMES
|
||||
annotationUseSiteTargetRenderer = KtAnnotationUseSiteTargetRenderer.WITH_NON_DEFAULT_USE_SITE
|
||||
annotationArgumentsRenderer = KtAnnotationArgumentsRenderer.IF_ANY
|
||||
}
|
||||
|
||||
public val WITH_SHORT_NAMES: KtAnnotationRenderer = WITH_QUALIFIED_NAMES.with {
|
||||
annotationsQualifiedNameRenderer = KtAnnotationQualifierRenderer.WITH_SHORT_NAMES
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.annotations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.load.java.NULLABILITY_ANNOTATIONS
|
||||
|
||||
public interface KtRendererAnnotationsFilter {
|
||||
context(KtAnalysisSession)
|
||||
public fun filter(annotation: KtAnnotationApplication, owner: KtAnnotated): Boolean
|
||||
|
||||
public infix fun and(other: KtRendererAnnotationsFilter): KtRendererAnnotationsFilter =
|
||||
KtRendererAnnotationsFilter { annotation, owner ->
|
||||
filter(annotation, owner) && other.filter(annotation, owner)
|
||||
}
|
||||
|
||||
public infix fun or(other: KtRendererAnnotationsFilter): KtRendererAnnotationsFilter =
|
||||
KtRendererAnnotationsFilter { annotation, owner ->
|
||||
filter(annotation, owner) || other.filter(annotation, owner)
|
||||
}
|
||||
|
||||
public object ALL : KtRendererAnnotationsFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(annotation: KtAnnotationApplication, owner: KtAnnotated): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public object NO_NULLABILITY : KtRendererAnnotationsFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(annotation: KtAnnotationApplication, owner: KtAnnotated): Boolean {
|
||||
return annotation.classId?.asSingleFqName() !in NULLABILITY_ANNOTATIONS
|
||||
}
|
||||
}
|
||||
|
||||
public object NO_PARAMETER_NAME : KtRendererAnnotationsFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(annotation: KtAnnotationApplication, owner: KtAnnotated): Boolean {
|
||||
return annotation.classId?.asSingleFqName() != StandardNames.FqNames.parameterName
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public object NONE : KtRendererAnnotationsFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(annotation: KtAnnotationApplication, owner: KtAnnotated): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public operator fun invoke(
|
||||
predicate: context(KtAnalysisSession) (annotation: KtAnnotationApplication, owner: KtAnnotated) -> Boolean
|
||||
): KtRendererAnnotationsFilter = object : KtRendererAnnotationsFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(annotation: KtAnnotationApplication, owner: KtAnnotated): Boolean {
|
||||
return predicate(this@KtAnalysisSession, annotation, owner)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.annotations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationValueRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRenderer
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
|
||||
public interface KtAnnotationArgumentsRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
public fun renderAnnotationArguments(annotation: KtAnnotationApplication, owner: KtAnnotated, printer: PrettyPrinter)
|
||||
|
||||
public object NONE : KtAnnotationArgumentsRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
override fun renderAnnotationArguments(annotation: KtAnnotationApplication, owner: KtAnnotated, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
public object IF_ANY : KtAnnotationArgumentsRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
override fun renderAnnotationArguments(
|
||||
annotation: KtAnnotationApplication,
|
||||
owner: KtAnnotated,
|
||||
printer: PrettyPrinter
|
||||
) {
|
||||
if (annotation.arguments.isEmpty()) return
|
||||
printer.printCollection(annotation.arguments, prefix = "(", postfix = ")") { argument ->
|
||||
append(argument.name.render())
|
||||
append(" = ")
|
||||
append(KtAnnotationValueRenderer.render(argument.expression))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.annotations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.annotations
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtAnnotationListRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
public fun renderAnnotations(owner: KtAnnotated, printer: PrettyPrinter)
|
||||
|
||||
public object FOR_SOURCE : KtAnnotationListRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
override fun renderAnnotations(owner: KtAnnotated, printer: PrettyPrinter) {
|
||||
val annotations = owner.annotations.filter { annotationFilter.filter(it, owner) }.ifEmpty { return }
|
||||
printer.printCollection(
|
||||
annotations,
|
||||
separator = when (owner) {
|
||||
is KtValueParameterSymbol -> " "
|
||||
is KtDeclarationSymbol -> "\n"
|
||||
else -> " "
|
||||
}
|
||||
) { annotation ->
|
||||
append('@')
|
||||
annotationUseSiteTargetRenderer.renderUseSiteTarget(annotation, owner, printer)
|
||||
annotationsQualifiedNameRenderer.renderQualifier(annotation, owner, printer)
|
||||
annotationArgumentsRenderer.renderAnnotationArguments(annotation, owner, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.annotations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRenderer
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
|
||||
public interface KtAnnotationQualifierRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
public fun renderQualifier(annotation: KtAnnotationApplication, owner: KtAnnotated, printer: PrettyPrinter)
|
||||
|
||||
public object WITH_QUALIFIED_NAMES : KtAnnotationQualifierRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
override fun renderQualifier(annotation: KtAnnotationApplication, owner: KtAnnotated, printer: PrettyPrinter): Unit = printer {
|
||||
val classId = annotation.classId
|
||||
if (classId != null) {
|
||||
append(classId.asSingleFqName().render())
|
||||
} else {
|
||||
append("ERROR_ANNOTATION")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_SHORT_NAMES : KtAnnotationQualifierRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
override fun renderQualifier(annotation: KtAnnotationApplication, owner: KtAnnotated, printer: PrettyPrinter): Unit = printer {
|
||||
val classId = annotation.classId
|
||||
if (classId != null) {
|
||||
printer.append(classId.shortClassName.render())
|
||||
} else {
|
||||
printer.append("ERROR_ANNOTATION")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.annotations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KtAnnotationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
|
||||
public interface KtAnnotationUseSiteTargetRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
public fun renderUseSiteTarget(annotation: KtAnnotationApplication, owner: KtAnnotated, printer: PrettyPrinter)
|
||||
|
||||
public object WITHOUT_USE_SITE : KtAnnotationUseSiteTargetRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
override fun renderUseSiteTarget(annotation: KtAnnotationApplication, owner: KtAnnotated, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_USES_SITE : KtAnnotationUseSiteTargetRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
override fun renderUseSiteTarget(annotation: KtAnnotationApplication, owner: KtAnnotated, printer: PrettyPrinter) {
|
||||
val useSite = annotation.useSiteTarget ?: return
|
||||
printer.append(useSite.renderName)
|
||||
printer.append(':')
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_NON_DEFAULT_USE_SITE : KtAnnotationUseSiteTargetRenderer {
|
||||
context(KtAnalysisSession, KtAnnotationRenderer)
|
||||
override fun renderUseSiteTarget(annotation: KtAnnotationApplication, owner: KtAnnotated, printer: PrettyPrinter) {
|
||||
if (owner !is KtCallableSymbol) return
|
||||
val print = when (owner) {
|
||||
is KtAnonymousFunctionSymbol -> true
|
||||
is KtConstructorSymbol -> true
|
||||
is KtFunctionSymbol -> true
|
||||
is KtPropertyGetterSymbol -> annotation.useSiteTarget != AnnotationUseSiteTarget.PROPERTY_GETTER
|
||||
is KtPropertySetterSymbol -> annotation.useSiteTarget != AnnotationUseSiteTarget.PROPERTY_SETTER
|
||||
is KtSamConstructorSymbol -> true
|
||||
is KtBackingFieldSymbol -> annotation.useSiteTarget != AnnotationUseSiteTarget.FIELD
|
||||
is KtEnumEntrySymbol -> true
|
||||
is KtValueParameterSymbol ->
|
||||
owner.getContainingSymbol() !is KtPropertySetterSymbol || annotation.useSiteTarget != AnnotationUseSiteTarget.SETTER_PARAMETER
|
||||
|
||||
is KtJavaFieldSymbol -> true
|
||||
is KtLocalVariableSymbol -> true
|
||||
is KtKotlinPropertySymbol -> annotation.useSiteTarget != AnnotationUseSiteTarget.PROPERTY
|
||||
is KtSyntheticJavaPropertySymbol -> annotation.useSiteTarget != AnnotationUseSiteTarget.PROPERTY
|
||||
}
|
||||
if (print) {
|
||||
WITH_USES_SITE.renderUseSiteTarget(annotation, owner, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+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.declarations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
|
||||
public interface KtCallableReturnTypeFilter {
|
||||
context (KtAnalysisSession)
|
||||
public fun shouldRenderReturnType(type: KtType, symbol: KtCallableSymbol): Boolean
|
||||
|
||||
public object ALWAYS : KtCallableReturnTypeFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun shouldRenderReturnType(type: KtType, symbol: KtCallableSymbol): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public object NO_UNIT_FOR_FUNCTIONS : KtCallableReturnTypeFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun shouldRenderReturnType(type: KtType, symbol: KtCallableSymbol): Boolean {
|
||||
return when (symbol) {
|
||||
is KtFunctionSymbol -> !type.isUnit
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* 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.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.declarations.bodies.*
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.KtDeclarationModifiersRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.*
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.callables.*
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classifiers.KtAnonymousObjectSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classifiers.KtNamedClassOrObjectSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classifiers.KtSingleTypeParameterSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classifiers.KtTypeAliasSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.superTypes.KtSuperTypeListRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.superTypes.KtSuperTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.superTypes.KtSuperTypesCallArgumentsRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.superTypes.KtSuperTypesFilter
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public class KtDeclarationRenderer private constructor(
|
||||
public val nameRenderer: KtDeclarationNameRenderer,
|
||||
public val keywordRender: KtKeywordRenderer,
|
||||
public val codeStyle: KtRendererCodeStyle,
|
||||
public val typeRenderer: KtTypeRenderer,
|
||||
public val annotationRenderer: KtAnnotationRenderer,
|
||||
public val modifiersRenderer: KtDeclarationModifiersRenderer,
|
||||
public val declarationTypeApproximator: KtRendererTypeApproximator,
|
||||
public val classifierBodyRenderer: KtClassifierBodyRenderer,
|
||||
|
||||
|
||||
public val superTypeRenderer: KtSuperTypeRenderer,
|
||||
public val superTypeListRenderer: KtSuperTypeListRenderer,
|
||||
public val superTypesFilter: KtSuperTypesFilter,
|
||||
public val superTypesArgumentRenderer: KtSuperTypesCallArgumentsRenderer,
|
||||
|
||||
public val bodyMemberScopeProvider: KtRendererBodyMemberScopeProvider,
|
||||
public val bodyMemberScopeSorter: KtRendererBodyMemberScopeSorter,
|
||||
|
||||
public val functionLikeBodyRenderer: KtFunctionLikeBodyRenderer,
|
||||
public val variableInitializerRenderer: KtVariableInitializerRenderer,
|
||||
public val parameterDefaultValueRenderer: KtParameterDefaultValueRenderer,
|
||||
public val accessorBodyRenderer: KtPropertyAccessorBodyRenderer,
|
||||
|
||||
public val returnTypeRenderer: KtCallableReturnTypeRenderer,
|
||||
public val receiverTyperRenderer: KtCallableReceiverTypeRenderer,
|
||||
|
||||
public val valueParametersRenderer: KtCallableParameterRenderer,
|
||||
public val typeParametersRenderer: KtTypeParametersRenderer,
|
||||
public val typeParametersFilter: KtTypeParameterRendererFilter,
|
||||
|
||||
public val callableSignatureRenderer: KtCallableSignatureRender,
|
||||
|
||||
public val anonymousFunctionRenderer: KtAnonymousFunctionSymbolRenderer,
|
||||
public val backingFieldRenderer: KtBackingFieldSymbolRenderer,
|
||||
public val constructorRenderer: KtConstructorSymbolRenderer,
|
||||
public val enumEntryRenderer: KtEnumEntrySymbolRenderer,
|
||||
public val functionSymbolRenderer: KtFunctionSymbolRenderer,
|
||||
public val javaFieldRenderer: KtJavaFieldSymbolRenderer,
|
||||
public val localVariableRenderer: KtLocalVariableSymbolRenderer,
|
||||
public val getterRenderer: KtPropertyGetterSymbolRenderer,
|
||||
public val setterRenderer: KtPropertySetterSymbolRenderer,
|
||||
public val propertyRenderer: KtKotlinPropertySymbolRenderer,
|
||||
public val kotlinPropertyRenderer: KtKotlinPropertySymbolRenderer,
|
||||
public val syntheticJavaPropertyRenderer: KtSyntheticJavaPropertySymbolRenderer,
|
||||
public val valueParameterRenderer: KtValueParameterSymbolRenderer,
|
||||
public val samConstructorRenderer: KtSamConstructorSymbolRenderer,
|
||||
public val propertyAccessorsRenderer: KtPropertyAccessorsRenderer,
|
||||
|
||||
public val classInitializerRender: KtClassInitializerRenderer,
|
||||
public val classOrObjectRenderer: KtNamedClassOrObjectSymbolRenderer,
|
||||
public val typeAliasRenderer: KtTypeAliasSymbolRenderer,
|
||||
public val anonymousObjectRenderer: KtAnonymousObjectSymbolRenderer,
|
||||
public val singleTypeParameterRenderer: KtSingleTypeParameterSymbolRenderer,
|
||||
public val returnTypeFilter: KtCallableReturnTypeFilter,
|
||||
) {
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public fun renderDeclaration(symbol: KtDeclarationSymbol, printer: PrettyPrinter) {
|
||||
when (symbol) {
|
||||
is KtAnonymousObjectSymbol -> anonymousObjectRenderer.renderSymbol(symbol, printer)
|
||||
is KtNamedClassOrObjectSymbol -> classOrObjectRenderer.renderSymbol(symbol, printer)
|
||||
is KtTypeAliasSymbol -> typeAliasRenderer.renderSymbol(symbol, printer)
|
||||
is KtAnonymousFunctionSymbol -> anonymousFunctionRenderer.renderSymbol(symbol, printer)
|
||||
is KtConstructorSymbol -> constructorRenderer.renderSymbol(symbol, printer)
|
||||
is KtFunctionSymbol -> functionSymbolRenderer.renderSymbol(symbol, printer)
|
||||
is KtPropertyGetterSymbol -> getterRenderer.renderSymbol(symbol, printer)
|
||||
is KtPropertySetterSymbol -> setterRenderer.renderSymbol(symbol, printer)
|
||||
is KtSamConstructorSymbol -> samConstructorRenderer.renderSymbol(symbol, printer)
|
||||
is KtBackingFieldSymbol -> backingFieldRenderer.renderSymbol(symbol, printer)
|
||||
is KtEnumEntrySymbol -> enumEntryRenderer.renderSymbol(symbol, printer)
|
||||
is KtValueParameterSymbol -> valueParameterRenderer.renderSymbol(symbol, printer)
|
||||
is KtJavaFieldSymbol -> javaFieldRenderer.renderSymbol(symbol, printer)
|
||||
is KtLocalVariableSymbol -> localVariableRenderer.renderSymbol(symbol, printer)
|
||||
is KtKotlinPropertySymbol -> kotlinPropertyRenderer.renderSymbol(symbol, printer)
|
||||
is KtSyntheticJavaPropertySymbol -> syntheticJavaPropertyRenderer.renderSymbol(symbol, printer)
|
||||
is KtTypeParameterSymbol -> singleTypeParameterRenderer.renderSymbol(symbol, printer)
|
||||
is KtClassInitializerSymbol -> classInitializerRender.renderClassInitializer(symbol, printer)
|
||||
}
|
||||
}
|
||||
|
||||
public fun with(action: Builder.() -> Unit): KtDeclarationRenderer {
|
||||
val renderer = this
|
||||
return KtDeclarationRenderer {
|
||||
this.nameRenderer = renderer.nameRenderer
|
||||
this.keywordRender = renderer.keywordRender
|
||||
this.codeStyle = renderer.codeStyle
|
||||
this.typeRenderer = renderer.typeRenderer
|
||||
this.annotationRenderer = renderer.annotationRenderer
|
||||
this.modifiersRenderer = renderer.modifiersRenderer
|
||||
this.declarationTypeApproximator = renderer.declarationTypeApproximator
|
||||
this.classifierBodyRenderer = renderer.classifierBodyRenderer
|
||||
|
||||
this.superTypeRenderer = renderer.superTypeRenderer
|
||||
this.superTypeListRenderer = renderer.superTypeListRenderer
|
||||
this.superTypesFilter = renderer.superTypesFilter
|
||||
this.superTypesArgumentRenderer = renderer.superTypesArgumentRenderer
|
||||
|
||||
this.bodyMemberScopeProvider = renderer.bodyMemberScopeProvider
|
||||
this.bodyMemberScopeSorter = renderer.bodyMemberScopeSorter
|
||||
|
||||
this.functionLikeBodyRenderer = renderer.functionLikeBodyRenderer
|
||||
this.variableInitializerRenderer = renderer.variableInitializerRenderer
|
||||
this.parameterDefaultValueRenderer = renderer.parameterDefaultValueRenderer
|
||||
this.accessorBodyRenderer = renderer.accessorBodyRenderer
|
||||
|
||||
this.returnTypeRenderer = renderer.returnTypeRenderer
|
||||
this.receiverTyperRenderer = renderer.receiverTyperRenderer
|
||||
|
||||
this.valueParametersRenderer = renderer.valueParametersRenderer
|
||||
this.typeParametersRenderer = renderer.typeParametersRenderer
|
||||
this.typeParametersFilter = renderer.typeParametersFilter
|
||||
|
||||
this.callableSignatureRenderer = renderer.callableSignatureRenderer
|
||||
|
||||
this.anonymousFunctionRenderer = renderer.anonymousFunctionRenderer
|
||||
this.backingFieldRenderer = renderer.backingFieldRenderer
|
||||
this.constructorRenderer = renderer.constructorRenderer
|
||||
this.enumEntryRenderer = renderer.enumEntryRenderer
|
||||
this.functionSymbolRenderer = renderer.functionSymbolRenderer
|
||||
this.javaFieldRenderer = renderer.javaFieldRenderer
|
||||
this.localVariableRenderer = renderer.localVariableRenderer
|
||||
this.getterRenderer = renderer.getterRenderer
|
||||
this.setterRenderer = renderer.setterRenderer
|
||||
this.propertyRenderer = renderer.propertyRenderer
|
||||
this.kotlinPropertyRenderer = renderer.kotlinPropertyRenderer
|
||||
this.syntheticJavaPropertyRenderer = renderer.syntheticJavaPropertyRenderer
|
||||
this.valueParameterRenderer = renderer.valueParameterRenderer
|
||||
this.samConstructorRenderer = renderer.samConstructorRenderer
|
||||
this.propertyAccessorsRenderer = renderer.propertyAccessorsRenderer
|
||||
|
||||
this.classInitializerRender = renderer.classInitializerRender
|
||||
this.classOrObjectRenderer = renderer.classOrObjectRenderer
|
||||
this.typeAliasRenderer = renderer.typeAliasRenderer
|
||||
this.anonymousObjectRenderer = renderer.anonymousObjectRenderer
|
||||
this.singleTypeParameterRenderer = renderer.singleTypeParameterRenderer
|
||||
this.returnTypeFilter = renderer.returnTypeFilter
|
||||
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public operator fun invoke(action: Builder.() -> Unit): KtDeclarationRenderer =
|
||||
Builder().apply(action).build()
|
||||
}
|
||||
|
||||
public open class Builder {
|
||||
public lateinit var returnTypeFilter: KtCallableReturnTypeFilter
|
||||
public lateinit var nameRenderer: KtDeclarationNameRenderer
|
||||
public lateinit var keywordRender: KtKeywordRenderer
|
||||
public lateinit var codeStyle: KtRendererCodeStyle
|
||||
public lateinit var typeRenderer: KtTypeRenderer
|
||||
public lateinit var annotationRenderer: KtAnnotationRenderer
|
||||
public lateinit var modifiersRenderer: KtDeclarationModifiersRenderer
|
||||
public lateinit var declarationTypeApproximator: KtRendererTypeApproximator
|
||||
public lateinit var classifierBodyRenderer: KtClassifierBodyRenderer
|
||||
|
||||
public lateinit var superTypeRenderer: KtSuperTypeRenderer
|
||||
public lateinit var superTypeListRenderer: KtSuperTypeListRenderer
|
||||
public lateinit var superTypesFilter: KtSuperTypesFilter
|
||||
public lateinit var superTypesArgumentRenderer: KtSuperTypesCallArgumentsRenderer
|
||||
|
||||
public lateinit var bodyMemberScopeProvider: KtRendererBodyMemberScopeProvider
|
||||
public lateinit var bodyMemberScopeSorter: KtRendererBodyMemberScopeSorter
|
||||
|
||||
public lateinit var functionLikeBodyRenderer: KtFunctionLikeBodyRenderer
|
||||
public lateinit var variableInitializerRenderer: KtVariableInitializerRenderer
|
||||
public lateinit var parameterDefaultValueRenderer: KtParameterDefaultValueRenderer
|
||||
public lateinit var accessorBodyRenderer: KtPropertyAccessorBodyRenderer
|
||||
|
||||
public lateinit var returnTypeRenderer: KtCallableReturnTypeRenderer
|
||||
public lateinit var receiverTyperRenderer: KtCallableReceiverTypeRenderer
|
||||
|
||||
public lateinit var valueParametersRenderer: KtCallableParameterRenderer
|
||||
public lateinit var typeParametersRenderer: KtTypeParametersRenderer
|
||||
public lateinit var typeParametersFilter: KtTypeParameterRendererFilter
|
||||
public lateinit var callableSignatureRenderer: KtCallableSignatureRender
|
||||
|
||||
public lateinit var anonymousFunctionRenderer: KtAnonymousFunctionSymbolRenderer
|
||||
public lateinit var backingFieldRenderer: KtBackingFieldSymbolRenderer
|
||||
public lateinit var constructorRenderer: KtConstructorSymbolRenderer
|
||||
public lateinit var enumEntryRenderer: KtEnumEntrySymbolRenderer
|
||||
public lateinit var functionSymbolRenderer: KtFunctionSymbolRenderer
|
||||
public lateinit var javaFieldRenderer: KtJavaFieldSymbolRenderer
|
||||
public lateinit var localVariableRenderer: KtLocalVariableSymbolRenderer
|
||||
public lateinit var getterRenderer: KtPropertyGetterSymbolRenderer
|
||||
public lateinit var setterRenderer: KtPropertySetterSymbolRenderer
|
||||
public lateinit var propertyRenderer: KtKotlinPropertySymbolRenderer
|
||||
public lateinit var kotlinPropertyRenderer: KtKotlinPropertySymbolRenderer
|
||||
public lateinit var syntheticJavaPropertyRenderer: KtSyntheticJavaPropertySymbolRenderer
|
||||
public lateinit var valueParameterRenderer: KtValueParameterSymbolRenderer
|
||||
public lateinit var samConstructorRenderer: KtSamConstructorSymbolRenderer
|
||||
public lateinit var propertyAccessorsRenderer: KtPropertyAccessorsRenderer
|
||||
|
||||
public lateinit var classInitializerRender: KtClassInitializerRenderer
|
||||
public lateinit var classOrObjectRenderer: KtNamedClassOrObjectSymbolRenderer
|
||||
public lateinit var typeAliasRenderer: KtTypeAliasSymbolRenderer
|
||||
public lateinit var anonymousObjectRenderer: KtAnonymousObjectSymbolRenderer
|
||||
public lateinit var singleTypeParameterRenderer: KtSingleTypeParameterSymbolRenderer
|
||||
|
||||
|
||||
public fun build(): KtDeclarationRenderer = KtDeclarationRenderer(
|
||||
nameRenderer,
|
||||
keywordRender,
|
||||
codeStyle,
|
||||
typeRenderer,
|
||||
annotationRenderer,
|
||||
modifiersRenderer,
|
||||
declarationTypeApproximator,
|
||||
classifierBodyRenderer,
|
||||
|
||||
superTypeRenderer,
|
||||
superTypeListRenderer,
|
||||
superTypesFilter,
|
||||
superTypesArgumentRenderer,
|
||||
|
||||
bodyMemberScopeProvider,
|
||||
bodyMemberScopeSorter,
|
||||
|
||||
functionLikeBodyRenderer,
|
||||
variableInitializerRenderer,
|
||||
parameterDefaultValueRenderer,
|
||||
accessorBodyRenderer,
|
||||
|
||||
returnTypeRenderer,
|
||||
receiverTyperRenderer,
|
||||
|
||||
valueParametersRenderer,
|
||||
typeParametersRenderer,
|
||||
typeParametersFilter,
|
||||
callableSignatureRenderer,
|
||||
|
||||
anonymousFunctionRenderer,
|
||||
backingFieldRenderer,
|
||||
constructorRenderer,
|
||||
enumEntryRenderer,
|
||||
functionSymbolRenderer,
|
||||
javaFieldRenderer,
|
||||
localVariableRenderer,
|
||||
getterRenderer,
|
||||
setterRenderer,
|
||||
propertyRenderer,
|
||||
kotlinPropertyRenderer,
|
||||
syntheticJavaPropertyRenderer,
|
||||
valueParameterRenderer,
|
||||
samConstructorRenderer,
|
||||
propertyAccessorsRenderer,
|
||||
|
||||
classInitializerRender,
|
||||
classOrObjectRenderer,
|
||||
typeAliasRenderer,
|
||||
anonymousObjectRenderer,
|
||||
singleTypeParameterRenderer,
|
||||
returnTypeFilter,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.declarations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
|
||||
public interface KtRendererCodeStyle {
|
||||
context(KtAnalysisSession)
|
||||
public fun getIndentSize(): Int
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public fun getSeparatorBetweenAnnotationAndOwner(symbol: KtAnnotated): String
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public fun getSeparatorBetweenAnnotations(symbol: KtAnnotated): String
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public fun getSeparatorBetweenModifiers(): String
|
||||
|
||||
context(KtAnalysisSession)
|
||||
public fun getSeparatorBetweenMembers(first: KtDeclarationSymbol, second: KtDeclarationSymbol): String
|
||||
}
|
||||
|
||||
public object KtRecommendedRendererCodeStyle : KtRendererCodeStyle {
|
||||
context(KtAnalysisSession) override fun getIndentSize(): Int {
|
||||
return 4
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun getSeparatorBetweenAnnotationAndOwner(symbol: KtAnnotated): String {
|
||||
return when (symbol) {
|
||||
is KtType -> " "
|
||||
is KtTypeParameterSymbol -> " "
|
||||
is KtValueParameterSymbol -> " "
|
||||
else -> "\n"
|
||||
}
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun getSeparatorBetweenAnnotations(symbol: KtAnnotated): String {
|
||||
return when (symbol) {
|
||||
is KtType -> " "
|
||||
is KtTypeParameterSymbol -> " "
|
||||
is KtValueParameterSymbol -> " "
|
||||
else -> "\n"
|
||||
}
|
||||
}
|
||||
|
||||
context(KtAnalysisSession) override fun getSeparatorBetweenModifiers(): String {
|
||||
return " "
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun getSeparatorBetweenMembers(first: KtDeclarationSymbol, second: KtDeclarationSymbol): String {
|
||||
return when {
|
||||
first is KtEnumEntrySymbol && second is KtEnumEntrySymbol -> ",\n"
|
||||
first is KtEnumEntrySymbol && second !is KtEnumEntrySymbol -> ";\n\n"
|
||||
else -> "\n\n"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.declarations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public interface KtRendererTypeApproximator {
|
||||
context(KtAnalysisSession)
|
||||
public fun approximateType(type: KtType, position: Variance): KtType
|
||||
|
||||
public object TO_DENNOTABLE : KtRendererTypeApproximator {
|
||||
context(KtAnalysisSession)
|
||||
override fun approximateType(type: KtType, position: Variance): KtType {
|
||||
return when (position) {
|
||||
Variance.INVARIANT -> type
|
||||
Variance.IN_VARIANCE -> type.approximateToSubPublicDenotableOrSelf(approximateLocalTypes = false)
|
||||
Variance.OUT_VARIANCE -> type.approximateToSuperPublicDenotableOrSelf(approximateLocalTypes = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object NO_APPROXIMATION : KtRendererTypeApproximator {
|
||||
context(KtAnalysisSession)
|
||||
override fun approximateType(type: KtType, position: Variance): KtType {
|
||||
return type
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.declarations.bodies
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtFunctionLikeBodyRenderer {
|
||||
context(KtAnalysisSession)
|
||||
public fun renderBody(symbol: KtFunctionLikeSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object NO_BODY : KtFunctionLikeBodyRenderer {
|
||||
context(KtAnalysisSession)
|
||||
override fun renderBody(symbol: KtFunctionLikeSymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.declarations.bodies
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtParameterDefaultValueRenderer {
|
||||
context(KtAnalysisSession)
|
||||
public fun renderDefaultValue(symbol: KtValueParameterSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object NO_DEFAULT_VALUE : KtParameterDefaultValueRenderer {
|
||||
context(KtAnalysisSession)
|
||||
override fun renderDefaultValue(symbol: KtValueParameterSymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
public object THREE_DOTS : KtParameterDefaultValueRenderer {
|
||||
context(KtAnalysisSession)
|
||||
override fun renderDefaultValue(symbol: KtValueParameterSymbol, printer: PrettyPrinter) {
|
||||
if (symbol.hasDefaultValue) {
|
||||
printer.append("...")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.declarations.bodies
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertyAccessorSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtPropertyAccessorBodyRenderer {
|
||||
context(KtAnalysisSession)
|
||||
public fun renderBody(symbol: KtPropertyAccessorSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object NO_BODY : KtPropertyAccessorBodyRenderer {
|
||||
context(KtAnalysisSession)
|
||||
override fun renderBody(symbol: KtPropertyAccessorSymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+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.declarations.bodies
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
|
||||
public interface KtRendererBodyMemberScopeProvider {
|
||||
context(KtAnalysisSession)
|
||||
public fun getMemberScope(symbol: KtSymbolWithMembers): List<KtDeclarationSymbol>
|
||||
|
||||
public object ALL : KtRendererBodyMemberScopeProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getMemberScope(symbol: KtSymbolWithMembers): List<KtDeclarationSymbol> {
|
||||
return symbol.getDeclaredMemberScope().getAllSymbols().toList()
|
||||
}
|
||||
}
|
||||
|
||||
public object ALL_DECLARED : KtRendererBodyMemberScopeProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getMemberScope(symbol: KtSymbolWithMembers): List<KtDeclarationSymbol> {
|
||||
return symbol.getDeclaredMemberScope().getAllSymbols()
|
||||
.filter { member ->
|
||||
val origin = member.origin
|
||||
origin != KtSymbolOrigin.DELEGATED &&
|
||||
origin != KtSymbolOrigin.SOURCE_MEMBER_GENERATED &&
|
||||
origin != KtSymbolOrigin.SUBSTITUTION_OVERRIDE &&
|
||||
origin != KtSymbolOrigin.INTERSECTION_OVERRIDE
|
||||
}.filter { member ->
|
||||
member !is KtConstructorSymbol || symbol !is KtClassOrObjectSymbol || !symbol.classKind.isObject
|
||||
}.filterNot { member ->
|
||||
member is KtConstructorSymbol && symbol is KtEnumEntrySymbol
|
||||
}
|
||||
.toList()
|
||||
}
|
||||
}
|
||||
|
||||
public object NONE : KtRendererBodyMemberScopeProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getMemberScope(symbol: KtSymbolWithMembers): List<KtDeclarationSymbol> {
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.declarations.bodies
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
|
||||
public interface KtRendererBodyMemberScopeSorter {
|
||||
context(KtAnalysisSession)
|
||||
public fun sortMembers(members: List<KtDeclarationSymbol>, owner: KtSymbolWithMembers): List<KtDeclarationSymbol>
|
||||
|
||||
public object ENUM_ENTRIES_AT_BEGINING : KtRendererBodyMemberScopeSorter {
|
||||
context(KtAnalysisSession)
|
||||
override fun sortMembers(members: List<KtDeclarationSymbol>, owner: KtSymbolWithMembers): List<KtDeclarationSymbol> {
|
||||
return members.sortedBy { it !is KtEnumEntrySymbol }
|
||||
}
|
||||
}
|
||||
}
|
||||
+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.declarations.bodies
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.KtConstantInitializerValue
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtVariableSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtVariableInitializerRenderer {
|
||||
context(KtAnalysisSession)
|
||||
public fun renderInitializer(symbol: KtVariableSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object NO_INITIALIZER : KtVariableInitializerRenderer {
|
||||
context(KtAnalysisSession)
|
||||
override fun renderInitializer(symbol: KtVariableSymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
public object ONLY_CONST_VALUE_INITIALIZERS : KtVariableInitializerRenderer {
|
||||
context(KtAnalysisSession)
|
||||
override fun renderInitializer(symbol: KtVariableSymbol, printer: PrettyPrinter) {
|
||||
//todo add initializer to KtVariableSymbol and render for it too KT-54794/
|
||||
val initializer = (symbol as? KtPropertySymbol)?.initializer as? KtConstantInitializerValue ?: return
|
||||
printer.append(" = ")
|
||||
printer.append(initializer.constant.renderAsKotlinConstant())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.declarations.impl
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtRendererTypeApproximator
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.callables.KtSamConstructorSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classifiers.KtSingleTypeParameterSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForDebug
|
||||
|
||||
public object KtDeclarationRendererForDebug {
|
||||
public val WITH_QUALIFIED_NAMES: KtDeclarationRenderer = KtDeclarationRendererForSource.WITH_QUALIFIED_NAMES.with {
|
||||
singleTypeParameterRenderer = KtSingleTypeParameterSymbolRenderer.WITHOUT_BOUNDS
|
||||
samConstructorRenderer = KtSamConstructorSymbolRenderer.AS_FUNCTION
|
||||
typeRenderer = KtTypeRendererForDebug.WITH_QUALIFIED_NAMES
|
||||
declarationTypeApproximator = KtRendererTypeApproximator.NO_APPROXIMATION
|
||||
}
|
||||
}
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.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.declarations.KtCallableReturnTypeFilter
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtRecommendedRendererCodeStyle
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtRendererTypeApproximator
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.bodies.*
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.impl.KtDeclarationModifiersRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.*
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.callables.*
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classifiers.KtAnonymousObjectSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classifiers.KtNamedClassOrObjectSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classifiers.KtSingleTypeParameterSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.classifiers.KtTypeAliasSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.superTypes.KtSuperTypeListRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.superTypes.KtSuperTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.superTypes.KtSuperTypesCallArgumentsRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.superTypes.KtSuperTypesFilter
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
|
||||
|
||||
public object KtDeclarationRendererForSource {
|
||||
public val WITH_QUALIFIED_NAMES: KtDeclarationRenderer = KtDeclarationRenderer {
|
||||
nameRenderer = KtDeclarationNameRenderer.QUOTED
|
||||
keywordRender = KtKeywordRenderer.AS_WORD
|
||||
codeStyle = KtRecommendedRendererCodeStyle
|
||||
modifiersRenderer = KtDeclarationModifiersRendererForSource.NO_IMPLICIT_MODIFIERS
|
||||
classifierBodyRenderer = KtClassifierBodyRenderer.NO_BODY
|
||||
bodyMemberScopeProvider = KtRendererBodyMemberScopeProvider.ALL_DECLARED
|
||||
bodyMemberScopeSorter = KtRendererBodyMemberScopeSorter.ENUM_ENTRIES_AT_BEGINING
|
||||
|
||||
superTypeRenderer = KtSuperTypeRenderer.WITH_OUT_APPROXIMATION
|
||||
superTypeListRenderer = KtSuperTypeListRenderer.AS_LIST
|
||||
superTypesFilter = KtSuperTypesFilter.NO_DEFAULT_TYPES
|
||||
superTypesArgumentRenderer = KtSuperTypesCallArgumentsRenderer.EMPTY_PARENS
|
||||
functionLikeBodyRenderer = KtFunctionLikeBodyRenderer.NO_BODY
|
||||
valueParametersRenderer = KtCallableParameterRenderer.PARAMETERS_IN_PARENS
|
||||
|
||||
typeParametersRenderer = KtTypeParametersRenderer.WITH_BOUNDS_IN_WHERE_CLAUSE
|
||||
typeParametersFilter = KtTypeParameterRendererFilter.NO_FOR_CONSTURCTORS
|
||||
|
||||
classInitializerRender = KtClassInitializerRenderer.INIT_BLOCK_WITH_BRACES
|
||||
|
||||
anonymousFunctionRenderer = KtAnonymousFunctionSymbolRenderer.AS_SOURCE
|
||||
backingFieldRenderer = KtBackingFieldSymbolRenderer.AS_FIELD_KEYWROD
|
||||
constructorRenderer = KtConstructorSymbolRenderer.AS_SOURCE
|
||||
enumEntryRenderer = KtEnumEntrySymbolRenderer.AS_SOURCE
|
||||
functionSymbolRenderer = KtFunctionSymbolRenderer.AS_SOURCE
|
||||
javaFieldRenderer = KtJavaFieldSymbolRenderer.AS_SOURCE
|
||||
localVariableRenderer = KtLocalVariableSymbolRenderer.AS_SOURCE
|
||||
getterRenderer = KtPropertyGetterSymbolRenderer.AS_SOURCE
|
||||
setterRenderer = KtPropertySetterSymbolRenderer.AS_SOURCE
|
||||
propertyRenderer = KtKotlinPropertySymbolRenderer.AS_SOURCE
|
||||
kotlinPropertyRenderer = KtKotlinPropertySymbolRenderer.AS_SOURCE
|
||||
syntheticJavaPropertyRenderer = KtSyntheticJavaPropertySymbolRenderer.AS_SOURCE
|
||||
valueParameterRenderer = KtValueParameterSymbolRenderer.AS_SOURCE
|
||||
samConstructorRenderer = KtSamConstructorSymbolRenderer.NOT_RENDER
|
||||
|
||||
callableSignatureRenderer = KtCallableSignatureRender.FOR_SOURCE
|
||||
accessorBodyRenderer = KtPropertyAccessorBodyRenderer.NO_BODY
|
||||
parameterDefaultValueRenderer = KtParameterDefaultValueRenderer.NO_DEFAULT_VALUE
|
||||
variableInitializerRenderer = KtVariableInitializerRenderer.NO_INITIALIZER
|
||||
|
||||
classOrObjectRenderer = KtNamedClassOrObjectSymbolRenderer.AS_SOURCE
|
||||
typeAliasRenderer = KtTypeAliasSymbolRenderer.AS_SOURCE
|
||||
anonymousObjectRenderer = KtAnonymousObjectSymbolRenderer.AS_SOURCE
|
||||
singleTypeParameterRenderer = KtSingleTypeParameterSymbolRenderer.WITHOUT_BOUNDS
|
||||
propertyAccessorsRenderer = KtPropertyAccessorsRenderer.NO_DEFAULT
|
||||
|
||||
receiverTyperRenderer = KtCallableReceiverTypeRenderer.WITH_IN_APPROXIMATION
|
||||
returnTypeRenderer = KtCallableReturnTypeRenderer.WITH_OUT_APPROXIMATION
|
||||
|
||||
typeRenderer = KtTypeRendererForSource.WITH_QUALIFIED_NAMES
|
||||
annotationRenderer = KtAnnotationRendererForSource.WITH_QUALIFIED_NAMES
|
||||
declarationTypeApproximator = KtRendererTypeApproximator.TO_DENNOTABLE
|
||||
returnTypeFilter = KtCallableReturnTypeFilter.NO_UNIT_FOR_FUNCTIONS
|
||||
}
|
||||
|
||||
public val WITH_SHORT_NAMES: KtDeclarationRenderer = WITH_QUALIFIED_NAMES.with {
|
||||
annotationRenderer = KtAnnotationRendererForSource.WITH_SHORT_NAMES
|
||||
typeRenderer = KtTypeRendererForSource.WITH_SHORT_NAMES
|
||||
}
|
||||
}
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.declarations
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
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(
|
||||
symbol: S,
|
||||
printer: PrettyPrinter,
|
||||
keyword: KtKeywordToken,
|
||||
): Unit where S : KtAnnotated, S : KtDeclarationSymbol = printer {
|
||||
renderAnnotationsAndModifiers(symbol, printer, listOf(keyword))
|
||||
}
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun <S> renderAnnotationsAndModifiers(
|
||||
symbol: S,
|
||||
printer: PrettyPrinter,
|
||||
keywords: List<KtKeywordToken>,
|
||||
): Unit where S : KtAnnotated, S : KtDeclarationSymbol = printer {
|
||||
val annotationsRendered: Boolean
|
||||
val modifiersRendered: Boolean
|
||||
codeStyle.getSeparatorBetweenAnnotationAndOwner(symbol).separated(
|
||||
{ annotationsRendered = checkIfPrinted { annotationRenderer.renderAnnotations(symbol, printer) } },
|
||||
{ modifiersRendered = checkIfPrinted { modifiersRenderer.renderDeclarationModifiers(symbol, printer) } }
|
||||
)
|
||||
val separator = when {
|
||||
annotationsRendered && !modifiersRendered -> codeStyle.getSeparatorBetweenAnnotationAndOwner(symbol)
|
||||
annotationsRendered || modifiersRendered -> codeStyle.getSeparatorBetweenModifiers()
|
||||
else -> ""
|
||||
}
|
||||
|
||||
withPrefix(separator) {
|
||||
keywordRender.renderKeywords(keywords, symbol, printer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun <S> renderAnnotationsAndModifiers(
|
||||
symbol: S,
|
||||
printer: PrettyPrinter,
|
||||
): Unit where S : KtAnnotated, S : KtDeclarationSymbol = printer {
|
||||
codeStyle.getSeparatorBetweenAnnotationAndOwner(symbol).separated(
|
||||
{ annotationRenderer.renderAnnotations(symbol, printer) },
|
||||
{ modifiersRenderer.renderDeclarationModifiers(symbol, printer) }
|
||||
)
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.declarations.modifiers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.KtKeywordRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.renderers.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public class KtDeclarationModifiersRenderer private constructor(
|
||||
public val modifierListRenderer: KtModifierListRenderer,
|
||||
public val modifierFilter: KtRendererModifierFilter,
|
||||
public val modifiersSorter: KtModifiersSorter,
|
||||
public val modalityProvider: KtRendererModalityModifierProvider,
|
||||
public val visibilityProvider: KtRendererVisibilityModifierProvider,
|
||||
public val otherModifiersProvider: KtRendererOtherModifiersProvider,
|
||||
public val keywordRenderer: KtKeywordRenderer,
|
||||
) {
|
||||
context(KtAnalysisSession)
|
||||
public fun renderDeclarationModifiers(symbol: KtDeclarationSymbol, printer: PrettyPrinter) {
|
||||
modifierListRenderer.renderModifiers(symbol, printer)
|
||||
}
|
||||
|
||||
public inline fun with(action: Builder.() -> Unit): KtDeclarationModifiersRenderer {
|
||||
val renderer = this
|
||||
return KtDeclarationModifiersRenderer {
|
||||
this.modifierListRenderer = renderer.modifierListRenderer
|
||||
this.modifierFilter = renderer.modifierFilter
|
||||
this.modifiersSorter = renderer.modifiersSorter
|
||||
this.modalityProvider = renderer.modalityProvider
|
||||
this.visibilityProvider = renderer.visibilityProvider
|
||||
this.otherModifiersProvider = renderer.otherModifiersProvider
|
||||
this.keywordRenderer = renderer.keywordRenderer
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public inline operator fun invoke(action: Builder.() -> Unit): KtDeclarationModifiersRenderer =
|
||||
Builder().apply(action).build()
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
public lateinit var modifierListRenderer: KtModifierListRenderer
|
||||
public lateinit var modifierFilter: KtRendererModifierFilter
|
||||
public lateinit var modifiersSorter: KtModifiersSorter
|
||||
public lateinit var modalityProvider: KtRendererModalityModifierProvider
|
||||
public lateinit var visibilityProvider: KtRendererVisibilityModifierProvider
|
||||
public lateinit var otherModifiersProvider: KtRendererOtherModifiersProvider
|
||||
public lateinit var keywordRenderer: KtKeywordRenderer
|
||||
|
||||
public fun build(): KtDeclarationModifiersRenderer = KtDeclarationModifiersRenderer(
|
||||
modifierListRenderer,
|
||||
modifierFilter,
|
||||
modifiersSorter,
|
||||
modalityProvider,
|
||||
visibilityProvider,
|
||||
otherModifiersProvider,
|
||||
keywordRenderer,
|
||||
)
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.declarations.modifiers.impl
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.base.KtKeywordRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.KtDeclarationModifiersRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.renderers.*
|
||||
|
||||
public object KtDeclarationModifiersRendererForSource {
|
||||
public val NO_IMPLICIT_MODIFIERS: KtDeclarationModifiersRenderer = KtDeclarationModifiersRenderer {
|
||||
modifierListRenderer = KtModifierListRenderer.AS_LIST
|
||||
modifierFilter = KtRendererModifierFilter.ALL
|
||||
modifiersSorter = KtModifiersSorter.CANONICAL
|
||||
modalityProvider = KtRendererModalityModifierProvider.WITHOUT_IMPLICIT_MODALITY
|
||||
visibilityProvider = KtRendererVisibilityModifierProvider.NO_IMPLICIT_VISIBILITY
|
||||
otherModifiersProvider = KtRendererOtherModifiersProvider.ALL
|
||||
keywordRenderer = KtKeywordRenderer.AS_WORD
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.declarations.modifiers.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.KtDeclarationModifiersRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithModality
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithVisibility
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
|
||||
public interface KtModifierListRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationModifiersRenderer)
|
||||
public fun renderModifiers(symbol: KtDeclarationSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_LIST : KtModifierListRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationModifiersRenderer)
|
||||
override fun renderModifiers(symbol: KtDeclarationSymbol, printer: PrettyPrinter) {
|
||||
val modifiers = getModifiers(symbol)
|
||||
.distinct()
|
||||
.filter { modifierFilter.filter(it, symbol) }
|
||||
.let { modifiersSorter.sort(it, symbol) }
|
||||
.ifEmpty { return }
|
||||
keywordRenderer.renderKeywords(modifiers, symbol, printer)
|
||||
}
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationModifiersRenderer)
|
||||
private fun getModifiers(symbol: KtDeclarationSymbol): List<KtModifierKeywordToken> {
|
||||
return buildList {
|
||||
if (symbol is KtSymbolWithVisibility) {
|
||||
visibilityProvider.getVisibilityModifier(symbol)?.let(::add)
|
||||
}
|
||||
if (symbol is KtSymbolWithModality) {
|
||||
modalityProvider.getModalityModifier(symbol)?.let(::add)
|
||||
}
|
||||
addAll(otherModifiersProvider.getOtherModifiers(symbol))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.declarations.modifiers.renderers
|
||||
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
|
||||
public interface KtRendererModifierFilter {
|
||||
context(KtAnalysisSession)
|
||||
public fun filter(modifier: KtModifierKeywordToken, symbol: KtDeclarationSymbol): Boolean
|
||||
|
||||
public infix fun and(other: KtRendererModifierFilter): KtRendererModifierFilter {
|
||||
val self = this
|
||||
return KtRendererModifierFilter { modifier, symbol ->
|
||||
self.filter(modifier, symbol) && other.filter(modifier, symbol)
|
||||
}
|
||||
}
|
||||
|
||||
public infix fun or(other: KtRendererModifierFilter): KtRendererModifierFilter {
|
||||
val self = this
|
||||
return KtRendererModifierFilter { modifier, symbol ->
|
||||
self.filter(modifier, symbol) || other.filter(modifier, symbol)
|
||||
}
|
||||
}
|
||||
|
||||
public object ALL : KtRendererModifierFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(modifier: KtModifierKeywordToken, symbol: KtDeclarationSymbol): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public object NONE : KtRendererModifierFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(modifier: KtModifierKeywordToken, symbol: KtDeclarationSymbol): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public operator fun invoke(
|
||||
predicate: context(KtAnalysisSession)(modifier: KtModifierKeywordToken, symbol: KtDeclarationSymbol) -> Boolean
|
||||
): KtRendererModifierFilter =
|
||||
object : KtRendererModifierFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(modifier: KtModifierKeywordToken, symbol: KtDeclarationSymbol): Boolean {
|
||||
return predicate(this@KtAnalysisSession, modifier, symbol)
|
||||
}
|
||||
}
|
||||
|
||||
public fun onlyWith(vararg modifiers: KtModifierKeywordToken): KtRendererModifierFilter =
|
||||
KtRendererModifierFilter { modifier, _ -> modifier in modifiers }
|
||||
|
||||
public fun onlyWith(modifiers: TokenSet): KtRendererModifierFilter =
|
||||
KtRendererModifierFilter { modifier, _ -> modifier in modifiers }
|
||||
|
||||
public fun without(vararg modifiers: KtModifierKeywordToken): KtRendererModifierFilter =
|
||||
KtRendererModifierFilter { modifier, _ -> modifier !in modifiers }
|
||||
|
||||
public fun without(modifiers: TokenSet): KtRendererModifierFilter =
|
||||
KtRendererModifierFilter { modifier, _ -> modifier !in modifiers }
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.declarations.modifiers.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.psi.addRemoveModifier.sortModifiers
|
||||
|
||||
public interface KtModifiersSorter {
|
||||
context(KtAnalysisSession)
|
||||
public fun sort(modifiers: List<KtModifierKeywordToken>, owner: KtDeclarationSymbol): List<KtModifierKeywordToken>
|
||||
|
||||
public object CANONICAL : KtModifiersSorter {
|
||||
context(KtAnalysisSession)
|
||||
override fun sort(modifiers: List<KtModifierKeywordToken>, owner: KtDeclarationSymbol): List<KtModifierKeywordToken> {
|
||||
return sortModifiers(modifiers)
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.declarations.modifiers.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithModality
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtRendererModalityModifierProvider {
|
||||
context(KtAnalysisSession)
|
||||
public fun getModalityModifier(symbol: KtSymbolWithModality): KtModifierKeywordToken?
|
||||
|
||||
public fun onlyIf(
|
||||
condition: context(KtAnalysisSession) (symbol: KtSymbolWithModality) -> Boolean
|
||||
): KtRendererModalityModifierProvider {
|
||||
val self = this
|
||||
return object : KtRendererModalityModifierProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getModalityModifier(symbol: KtSymbolWithModality): KtModifierKeywordToken? =
|
||||
if (condition(this@KtAnalysisSession, symbol)) self.getModalityModifier(symbol)
|
||||
else null
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_IMPLICIT_MODALITY : KtRendererModalityModifierProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getModalityModifier(symbol: KtSymbolWithModality): KtModifierKeywordToken? {
|
||||
if (symbol is KtPropertyAccessorSymbol) return null
|
||||
return when (symbol.modality) {
|
||||
Modality.SEALED -> KtTokens.SEALED_KEYWORD
|
||||
Modality.OPEN -> KtTokens.OPEN_KEYWORD
|
||||
Modality.ABSTRACT -> KtTokens.ABSTRACT_KEYWORD
|
||||
Modality.FINAL -> KtTokens.FINAL_KEYWORD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object WITHOUT_IMPLICIT_MODALITY : KtRendererModalityModifierProvider {
|
||||
context(KtAnalysisSession) override fun getModalityModifier(symbol: KtSymbolWithModality): KtModifierKeywordToken? {
|
||||
when (symbol) {
|
||||
is KtFunctionSymbol -> if (symbol.isOverride && symbol.modality != Modality.FINAL) return null
|
||||
is KtPropertySymbol -> if (symbol.isOverride && symbol.modality != Modality.FINAL) return null
|
||||
}
|
||||
if ((symbol as? KtClassOrObjectSymbol)?.classKind == KtClassKind.INTERFACE) return null
|
||||
if ((symbol.getContainingSymbol() as? KtClassOrObjectSymbol)?.classKind == KtClassKind.INTERFACE) return null
|
||||
|
||||
return when (symbol.modality) {
|
||||
Modality.FINAL -> null
|
||||
else -> WITH_IMPLICIT_MODALITY.getModalityModifier(symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.declarations.modifiers.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public interface KtRendererOtherModifiersProvider {
|
||||
context(KtAnalysisSession)
|
||||
public fun getOtherModifiers(symbol: KtDeclarationSymbol): List<KtModifierKeywordToken>
|
||||
|
||||
public infix fun and(other: KtRendererOtherModifiersProvider): KtRendererOtherModifiersProvider {
|
||||
val self = this
|
||||
return object : KtRendererOtherModifiersProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getOtherModifiers(symbol: KtDeclarationSymbol): List<KtModifierKeywordToken> {
|
||||
return self.getOtherModifiers(symbol) + other.getOtherModifiers(symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public fun onlyIf(
|
||||
condition: context(KtAnalysisSession) (symbol: KtDeclarationSymbol) -> Boolean
|
||||
): KtRendererOtherModifiersProvider {
|
||||
val self = this
|
||||
return object : KtRendererOtherModifiersProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getOtherModifiers(symbol: KtDeclarationSymbol): List<KtModifierKeywordToken> =
|
||||
if (condition(this@KtAnalysisSession, symbol)) self.getOtherModifiers(symbol)
|
||||
else emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public object ALL : KtRendererOtherModifiersProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getOtherModifiers(symbol: KtDeclarationSymbol): List<KtModifierKeywordToken> = buildList {
|
||||
if (symbol is KtFunctionSymbol) {
|
||||
if (symbol.isExternal) add(KtTokens.EXTERNAL_KEYWORD)
|
||||
if (symbol.isOverride) add(KtTokens.OVERRIDE_KEYWORD)
|
||||
if (symbol.isInline) add(KtTokens.INLINE_KEYWORD)
|
||||
if (symbol.isInfix) add(KtTokens.INFIX_KEYWORD)
|
||||
if (symbol.isOperator) add(KtTokens.OPERATOR_KEYWORD)
|
||||
if (symbol.isSuspend) add(KtTokens.SUSPEND_KEYWORD)
|
||||
}
|
||||
|
||||
if (symbol is KtPropertySymbol) {
|
||||
if (symbol.isOverride) add(KtTokens.OVERRIDE_KEYWORD)
|
||||
}
|
||||
|
||||
if (symbol is KtValueParameterSymbol) {
|
||||
if (symbol.isVararg) add(KtTokens.VARARG_KEYWORD)
|
||||
if (symbol.isCrossinline) add(KtTokens.CROSSINLINE_KEYWORD)
|
||||
if (symbol.isNoinline) add(KtTokens.NOINLINE_KEYWORD)
|
||||
}
|
||||
|
||||
if (symbol is KtKotlinPropertySymbol) {
|
||||
if (symbol.isConst) add(KtTokens.CONST_KEYWORD)
|
||||
if (symbol.isLateInit) add(KtTokens.LATEINIT_KEYWORD)
|
||||
}
|
||||
|
||||
if (symbol is KtNamedClassOrObjectSymbol) {
|
||||
if (symbol.isExternal) add(KtTokens.EXTERNAL_KEYWORD)
|
||||
if (symbol.isInline) add(KtTokens.INLINE_KEYWORD)
|
||||
if (symbol.isData) add(KtTokens.DATA_KEYWORD)
|
||||
if (symbol.isFun) add(KtTokens.FUN_KEYWORD)
|
||||
if (symbol.isInner) add(KtTokens.INNER_KEYWORD)
|
||||
}
|
||||
|
||||
if (symbol is KtTypeParameterSymbol) {
|
||||
if (symbol.isReified) add(KtTokens.REIFIED_KEYWORD)
|
||||
when (symbol.variance) {
|
||||
Variance.INVARIANT -> {}
|
||||
Variance.IN_VARIANCE -> add(KtTokens.IN_KEYWORD)
|
||||
Variance.OUT_VARIANCE -> add(KtTokens.OUT_KEYWORD)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.declarations.modifiers.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.java.JavaVisibilities
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtRendererVisibilityModifierProvider {
|
||||
context(KtAnalysisSession)
|
||||
public fun getVisibilityModifier(symbol: KtSymbolWithVisibility): KtModifierKeywordToken?
|
||||
|
||||
public fun onlyIf(
|
||||
condition: context(KtAnalysisSession) (symbol: KtSymbolWithVisibility) -> Boolean
|
||||
): KtRendererVisibilityModifierProvider {
|
||||
val self = this
|
||||
return object : KtRendererVisibilityModifierProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getVisibilityModifier(symbol: KtSymbolWithVisibility): KtModifierKeywordToken? =
|
||||
if (condition(this@KtAnalysisSession, symbol)) self.getVisibilityModifier(symbol)
|
||||
else null
|
||||
}
|
||||
}
|
||||
|
||||
public object NO_IMPLICIT_VISIBILITY : KtRendererVisibilityModifierProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getVisibilityModifier(symbol: KtSymbolWithVisibility): KtModifierKeywordToken? {
|
||||
when (symbol) {
|
||||
is KtFunctionSymbol -> if (symbol.isOverride) return null
|
||||
is KtPropertySymbol -> if (symbol.isOverride) return null
|
||||
is KtConstructorSymbol -> {
|
||||
if ((symbol.getContainingSymbol() as? KtClassOrObjectSymbol)?.classKind == KtClassKind.ENUM_CLASS) return null
|
||||
}
|
||||
}
|
||||
|
||||
return when (symbol.visibility) {
|
||||
Visibilities.Public -> null
|
||||
JavaVisibilities.PackageVisibility -> null
|
||||
JavaVisibilities.ProtectedStaticVisibility, JavaVisibilities.ProtectedAndPackage -> null
|
||||
else -> WITH_IMPLICIT_VISIBILITY.getVisibilityModifier(symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_IMPLICIT_VISIBILITY : KtRendererVisibilityModifierProvider {
|
||||
context(KtAnalysisSession)
|
||||
override fun getVisibilityModifier(symbol: KtSymbolWithVisibility): KtModifierKeywordToken? {
|
||||
return when (symbol.visibility) {
|
||||
Visibilities.Private, Visibilities.PrivateToThis -> KtTokens.PRIVATE_KEYWORD
|
||||
Visibilities.Protected -> KtTokens.PROTECTED_KEYWORD
|
||||
Visibilities.Internal -> KtTokens.INTERNAL_KEYWORD
|
||||
Visibilities.Public -> KtTokens.PUBLIC_KEYWORD
|
||||
Visibilities.Local -> null
|
||||
JavaVisibilities.PackageVisibility -> KtTokens.PUBLIC_KEYWORD
|
||||
JavaVisibilities.ProtectedStaticVisibility, JavaVisibilities.ProtectedAndPackage -> KtTokens.PROTECTED_KEYWORD
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.declarations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtCallableParameterRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderValueParameters(symbol: KtCallableSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object PARAMETERS_IN_PARENS : KtCallableParameterRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderValueParameters(symbol: KtCallableSymbol, printer: PrettyPrinter) {
|
||||
val valueParameters = when (symbol) {
|
||||
is KtFunctionLikeSymbol -> symbol.valueParameters
|
||||
else -> return
|
||||
}
|
||||
printer.printCollection(valueParameters, prefix = "(", postfix = ")") {
|
||||
renderDeclaration(it, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.declarations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassInitializerSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtClassInitializerRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderClassInitializer(symbol: KtClassInitializerSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object INIT_BLOCK_WITH_BRACES : KtClassInitializerRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderClassInitializer(symbol: KtClassInitializerSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ keywordRender.renderKeyword(KtTokens.INIT_KEYWORD, symbol, this) },
|
||||
{ printer.withIndentInBraces {} },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.declarations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.prettyPrintWithSettingsFrom
|
||||
|
||||
public interface KtClassifierBodyRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderBody(symbol: KtSymbolWithMembers, printer: PrettyPrinter)
|
||||
|
||||
public object NO_BODY : KtClassifierBodyRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderBody(symbol: KtSymbolWithMembers, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
public object EMPTY_BRACES : KtClassifierBodyRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderBody(symbol: KtSymbolWithMembers, printer: PrettyPrinter) {
|
||||
printer.append("{\n}")
|
||||
}
|
||||
}
|
||||
|
||||
public object BODY_WITH_MEMBERS : KtClassifierBodyWithMembersRenderer() {
|
||||
override fun renderEmptyBodyForEmptyMemberScope(symbol: KtSymbolWithMembers): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public object BODY_WITH_MEMBERS_OR_EMPTY_BRACES : KtClassifierBodyWithMembersRenderer() {
|
||||
override fun renderEmptyBodyForEmptyMemberScope(symbol: KtSymbolWithMembers): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class KtClassifierBodyWithMembersRenderer : KtClassifierBodyRenderer {
|
||||
public abstract fun renderEmptyBodyForEmptyMemberScope(symbol: KtSymbolWithMembers): Boolean
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public override fun renderBody(symbol: KtSymbolWithMembers, printer: PrettyPrinter) {
|
||||
val members = bodyMemberScopeProvider.getMemberScope(symbol).filter { it !is KtConstructorSymbol || !it.isPrimary }
|
||||
.let { bodyMemberScopeSorter.sortMembers(it, symbol) }
|
||||
val membersToPrint = members.mapNotNull { member ->
|
||||
val rendered = prettyPrintWithSettingsFrom(printer) {
|
||||
renderDeclaration(member, this)
|
||||
}
|
||||
if (rendered.isNotEmpty()) member to rendered else null
|
||||
}
|
||||
if (membersToPrint.isEmpty() && !renderEmptyBodyForEmptyMemberScope(symbol)) return
|
||||
|
||||
printer.withIndentInBraces {
|
||||
var previous: KtDeclarationSymbol? = null
|
||||
for ((member, rendered) in membersToPrint) {
|
||||
if (previous != null) {
|
||||
printer.append(codeStyle.getSeparatorBetweenMembers(previous, member))
|
||||
}
|
||||
previous = member
|
||||
printer.append(rendered)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.declarations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
|
||||
public interface KtDeclarationNameRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderName(symbol: KtNamedSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object QUOTED : KtDeclarationNameRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderName(symbol: KtNamedSymbol, printer: PrettyPrinter) {
|
||||
if (symbol is KtClassOrObjectSymbol && symbol.classKind == KtClassKind.COMPANION_OBJECT && symbol.name == SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT)
|
||||
return
|
||||
printer.append(symbol.name.render())
|
||||
}
|
||||
}
|
||||
|
||||
public object UNQUOTED : KtDeclarationNameRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderName(symbol: KtNamedSymbol, printer: PrettyPrinter) {
|
||||
if (symbol is KtClassOrObjectSymbol && symbol.classKind == KtClassKind.COMPANION_OBJECT && symbol.name == SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT)
|
||||
return
|
||||
printer.append(symbol.name.asString())
|
||||
}
|
||||
}
|
||||
}
|
||||
+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.declarations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithTypeParameters
|
||||
|
||||
public interface KtTypeParameterRendererFilter {
|
||||
context(KtAnalysisSession)
|
||||
public fun filter(typeParameter: KtTypeParameterSymbol, owner: KtSymbolWithTypeParameters): Boolean
|
||||
|
||||
public object NO_FOR_CONSTURCTORS : KtTypeParameterRendererFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(typeParameter: KtTypeParameterSymbol, owner: KtSymbolWithTypeParameters): Boolean {
|
||||
return owner !is KtConstructorSymbol
|
||||
}
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public operator fun invoke(predicate: context(KtAnalysisSession)(typeParameter: KtTypeParameterSymbol, owner: KtSymbolWithTypeParameters) -> Boolean): KtTypeParameterRendererFilter {
|
||||
return object : KtTypeParameterRendererFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(typeParameter: KtTypeParameterSymbol, owner: KtSymbolWithTypeParameters): Boolean {
|
||||
return predicate(this@KtAnalysisSession, typeParameter, owner)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.declarations.renderers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public interface KtTypeParametersRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderTypeParameters(symbol: KtDeclarationSymbol, printer: PrettyPrinter)
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderWhereClause(symbol: KtDeclarationSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object NO_TYPE_PARAMETERS : KtTypeParametersRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderTypeParameters(symbol: KtDeclarationSymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderWhereClause(symbol: KtDeclarationSymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
public object WIHTOUT_BOUNDS : KtTypeParametersRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderTypeParameters(symbol: KtDeclarationSymbol, printer: PrettyPrinter) {
|
||||
val typeParameters = symbol.typeParameters
|
||||
.filter { typeParametersFilter.filter(it, symbol) }
|
||||
.ifEmpty { return }
|
||||
printer.printCollection(typeParameters, prefix = "<", postfix = ">") { typeParameter ->
|
||||
codeStyle.getSeparatorBetweenAnnotationAndOwner(typeParameter).separated(
|
||||
{ modifiersRenderer.renderDeclarationModifiers(typeParameter, printer) },
|
||||
{ nameRenderer.renderName(typeParameter, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderWhereClause(symbol: KtDeclarationSymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_BOUNDS_IN_WHERE_CLAUSE : KtTypeParametersRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderTypeParameters(symbol: KtDeclarationSymbol, printer: PrettyPrinter) {
|
||||
val typeParameters = symbol.typeParameters
|
||||
.filter { typeParametersFilter.filter(it, symbol) }
|
||||
.ifEmpty { return }
|
||||
printer.printCollection(typeParameters, prefix = "<", postfix = ">") { typeParameter ->
|
||||
codeStyle.getSeparatorBetweenAnnotationAndOwner(typeParameter).separated(
|
||||
{ modifiersRenderer.renderDeclarationModifiers(typeParameter, printer) },
|
||||
{ nameRenderer.renderName(typeParameter, printer) },
|
||||
)
|
||||
if (typeParameter.upperBounds.size == 1) {
|
||||
append(" : ")
|
||||
typeRenderer.renderType(typeParameter.upperBounds.single(), printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderWhereClause(symbol: KtDeclarationSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
val allBounds = symbol.typeParameters
|
||||
.filter { typeParametersFilter.filter(it, symbol) }
|
||||
.flatMap { typeParam ->
|
||||
if (typeParam.upperBounds.size > 1) {
|
||||
typeParam.upperBounds.map { bound -> typeParam to bound }
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}.ifEmpty { return }
|
||||
" ".separated(
|
||||
{ keywordRender.renderKeyword(KtTokens.WHERE_KEYWORD, symbol, printer) },
|
||||
{
|
||||
printer.printCollection(allBounds) { (typeParameter, bound) ->
|
||||
" : ".separated(
|
||||
{ nameRenderer.renderName(typeParameter, printer) },
|
||||
{ typeRenderer.renderType(declarationTypeApproximator.approximateType(bound, Variance.OUT_VARIANCE), printer) },
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtAnonymousFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtAnonymousFunctionSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtAnonymousFunctionSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtAnonymousFunctionSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtAnonymousFunctionSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
callableSignatureRenderer.renderCallableSignature(symbol, KtTokens.FUN_KEYWORD, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtBackingFieldSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtBackingFieldSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtBackingFieldSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_FIELD_KEYWROD : KtBackingFieldSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtBackingFieldSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
keywordRender.renderKeyword(KtTokens.FIELD_KEYWORD, symbol, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public interface KtCallableReceiverTypeRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderReceiverType(symbol: KtCallableSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object WITH_IN_APPROXIMATION : KtCallableReceiverTypeRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderReceiverType(symbol: KtCallableSymbol, printer: PrettyPrinter) {
|
||||
val receiverType = symbol.receiverType?.let { declarationTypeApproximator.approximateType(it, Variance.IN_VARIANCE) } ?: return
|
||||
typeRenderer.renderType(receiverType, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public interface KtCallableReturnTypeRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderReturnType(symbol: KtCallableSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object WITH_OUT_APPROXIMATION : KtCallableReturnTypeRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderReturnType(symbol: KtCallableSymbol, printer: PrettyPrinter) {
|
||||
if (symbol is KtConstructorSymbol) return
|
||||
val type = declarationTypeApproximator.approximateType(symbol.returnType, Variance.OUT_VARIANCE)
|
||||
if (!returnTypeFilter.shouldRenderReturnType(type, symbol)) return
|
||||
typeRenderer.renderType(type, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
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.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
|
||||
public interface KtCallableSignatureRender {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderCallableSignature(symbol: KtCallableSymbol, keyword: KtKeywordToken?, printer: PrettyPrinter)
|
||||
|
||||
public object FOR_SOURCE : KtCallableSignatureRender {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderCallableSignature(symbol: KtCallableSymbol, keyword: KtKeywordToken?, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{
|
||||
if (keyword != null) renderAnnotationsAndModifiers(symbol, printer, keyword)
|
||||
else renderAnnotationsAndModifiers(symbol, printer)
|
||||
},
|
||||
{ typeParametersRenderer.renderTypeParameters(symbol, printer) },
|
||||
{
|
||||
withSuffix(".") { receiverTyperRenderer.renderReceiverType(symbol, printer) }
|
||||
if (symbol is KtNamedSymbol) {
|
||||
nameRenderer.renderName(symbol, printer)
|
||||
}
|
||||
},
|
||||
)
|
||||
" ".separated(
|
||||
{
|
||||
valueParametersRenderer.renderValueParameters(symbol, printer)
|
||||
withPrefix(": ") { returnTypeRenderer.renderReturnType(symbol, printer) }
|
||||
},
|
||||
{ typeParametersRenderer.renderWhereClause(symbol, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtConstructorSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtConstructorSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtConstructorSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtConstructorSymbol, printer: PrettyPrinter) {
|
||||
callableSignatureRenderer.renderCallableSignature(symbol, KtTokens.CONSTRUCTOR_KEYWORD, printer)
|
||||
functionLikeBodyRenderer.renderBody(symbol, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
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.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtEnumEntrySymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtEnumEntrySymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtEnumEntrySymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtEnumEntrySymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ renderAnnotationsAndModifiers(symbol, printer) },
|
||||
{ nameRenderer.renderName(symbol, printer) },
|
||||
{ classifierBodyRenderer.renderBody(symbol, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtFunctionSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtFunctionSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtFunctionSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtFunctionSymbol, printer: PrettyPrinter) {
|
||||
callableSignatureRenderer.renderCallableSignature(symbol, KtTokens.FUN_KEYWORD, printer)
|
||||
functionLikeBodyRenderer.renderBody(symbol, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtJavaFieldSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtJavaFieldSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtJavaFieldSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtJavaFieldSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtJavaFieldSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
val mutabilityKeyword = if (symbol.isVal) KtTokens.VAL_KEYWORD else KtTokens.VAR_KEYWORD
|
||||
callableSignatureRenderer.renderCallableSignature(symbol, mutabilityKeyword, printer)
|
||||
variableInitializerRenderer.renderInitializer(symbol, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtKotlinPropertySymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtKotlinPropertySymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtKotlinPropertySymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtKotlinPropertySymbol, printer: PrettyPrinter): Unit = printer {
|
||||
val mutabilityKeyword = if (symbol.isVal) KtTokens.VAL_KEYWORD else KtTokens.VAR_KEYWORD
|
||||
callableSignatureRenderer.renderCallableSignature(symbol, mutabilityKeyword, printer)
|
||||
variableInitializerRenderer.renderInitializer(symbol, printer)
|
||||
propertyAccessorsRenderer.renderAccessors(symbol, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtLocalVariableSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtLocalVariableSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtLocalVariableSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtLocalVariableSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtLocalVariableSymbol, printer: PrettyPrinter) {
|
||||
val mutabilityKeyword = if (symbol.isVal) KtTokens.VAL_KEYWORD else KtTokens.VAR_KEYWORD
|
||||
callableSignatureRenderer.renderCallableSignature(symbol, mutabilityKeyword, printer)
|
||||
variableInitializerRenderer.renderInitializer(symbol, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.annotations
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertyGetterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySetterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
|
||||
public interface KtPropertyAccessorsRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderAccessors(symbol: KtPropertySymbol, printer: PrettyPrinter)
|
||||
|
||||
public object ALL : KtPropertyAccessorsRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderAccessors(symbol: KtPropertySymbol, printer: PrettyPrinter): Unit = printer {
|
||||
val toRender = listOfNotNull(symbol.getter, symbol.setter).ifEmpty { return }
|
||||
append("\n")
|
||||
withIndent {
|
||||
"\n".separated(
|
||||
{ toRender.firstIsInstanceOrNull<KtPropertyGetterSymbol>()?.let { getterRenderer.renderSymbol(it, printer) } },
|
||||
{ toRender.firstIsInstanceOrNull<KtPropertySetterSymbol>()?.let { setterRenderer.renderSymbol(it, printer) } },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object NO_DEFAULT : KtPropertyAccessorsRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderAccessors(symbol: KtPropertySymbol, printer: PrettyPrinter): Unit = printer {
|
||||
val toRender = listOfNotNull(symbol.getter, symbol.setter)
|
||||
.filter { !it.isDefault || it.annotations.isNotEmpty() }
|
||||
.ifEmpty { return }
|
||||
append("\n")
|
||||
withIndent {
|
||||
"\n".separated(
|
||||
{ toRender.firstIsInstanceOrNull<KtPropertyGetterSymbol>()?.let { getterRenderer.renderSymbol(it, printer) } },
|
||||
{ toRender.firstIsInstanceOrNull<KtPropertySetterSymbol>()?.let { setterRenderer.renderSymbol(it, printer) } },
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public object NONE : KtPropertyAccessorsRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderAccessors(symbol: KtPropertySymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
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.symbols.KtPropertyGetterSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtPropertyGetterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtPropertyGetterSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtPropertyGetterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtPropertyGetterSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{
|
||||
renderAnnotationsAndModifiers(symbol, printer, KtTokens.GET_KEYWORD)
|
||||
valueParametersRenderer.renderValueParameters(symbol, printer)
|
||||
},
|
||||
{ accessorBodyRenderer.renderBody(symbol, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
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.symbols.KtPropertySetterSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtPropertySetterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtPropertySetterSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtPropertySetterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtPropertySetterSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{
|
||||
renderAnnotationsAndModifiers(symbol, printer, KtTokens.SET_KEYWORD)
|
||||
valueParametersRenderer.renderValueParameters(symbol, printer)
|
||||
},
|
||||
{ accessorBodyRenderer.renderBody(symbol, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSamConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtSamConstructorSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtSamConstructorSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object NOT_RENDER : KtSamConstructorSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtSamConstructorSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
}
|
||||
}
|
||||
|
||||
public object AS_FUNCTION : KtSamConstructorSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtSamConstructorSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
callableSignatureRenderer.renderCallableSignature(symbol, keyword = null, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSyntheticJavaPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtSyntheticJavaPropertySymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtSyntheticJavaPropertySymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtSyntheticJavaPropertySymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtSyntheticJavaPropertySymbol, printer: PrettyPrinter): Unit = printer {
|
||||
val mutabilityKeyword = if (symbol.isVal) KtTokens.VAL_KEYWORD else KtTokens.VAR_KEYWORD
|
||||
callableSignatureRenderer.renderCallableSignature(symbol, mutabilityKeyword, printer)
|
||||
variableInitializerRenderer.renderInitializer(symbol, printer)
|
||||
propertyAccessorsRenderer.renderAccessors(symbol, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+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.declarations.renderers.callables
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtValueParameterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtValueParameterSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtValueParameterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtValueParameterSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" = ".separated(
|
||||
{ callableSignatureRenderer.renderCallableSignature(symbol, keyword = null, printer) },
|
||||
{ parameterDefaultValueRenderer.renderDefaultValue(symbol, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.declarations.renderers.classifiers
|
||||
|
||||
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.symbols.KtAnonymousObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtAnonymousObjectSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtAnonymousObjectSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtAnonymousObjectSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtAnonymousObjectSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{
|
||||
" : ".separated(
|
||||
{ renderAnnotationsAndModifiers(symbol, printer, KtTokens.OBJECT_KEYWORD) },
|
||||
{ superTypeListRenderer.renderSuperTypes(symbol, printer) }
|
||||
)
|
||||
},
|
||||
{ classifierBodyRenderer.renderBody(symbol, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.declarations.renderers.classifiers
|
||||
|
||||
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.symbols.KtClassKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtNamedClassOrObjectSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtNamedClassOrObjectSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtNamedClassOrObjectSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtNamedClassOrObjectSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
val keywords = when (symbol.classKind) {
|
||||
KtClassKind.CLASS -> listOf(KtTokens.CLASS_KEYWORD)
|
||||
KtClassKind.ENUM_CLASS -> listOf(KtTokens.ENUM_KEYWORD, KtTokens.CLASS_KEYWORD)
|
||||
KtClassKind.ANNOTATION_CLASS -> listOf(KtTokens.ANNOTATION_KEYWORD, KtTokens.CLASS_KEYWORD)
|
||||
KtClassKind.OBJECT -> listOf(KtTokens.OBJECT_KEYWORD)
|
||||
KtClassKind.COMPANION_OBJECT -> listOf(KtTokens.COMPANION_KEYWORD, KtTokens.OBJECT_KEYWORD)
|
||||
KtClassKind.INTERFACE -> listOf(KtTokens.INTERFACE_KEYWORD)
|
||||
KtClassKind.ANONYMOUS_OBJECT -> error("KtNamedClassOrObjectSymbol cannot be KtAnonymousObjectSymbol")
|
||||
}
|
||||
|
||||
" ".separated(
|
||||
{ renderAnnotationsAndModifiers(symbol, printer, keywords) },
|
||||
{
|
||||
val primaryConstructor =
|
||||
bodyMemberScopeProvider.getMemberScope(symbol).filterIsInstance<KtConstructorSymbol>()
|
||||
.firstOrNull { it.isPrimary }
|
||||
|
||||
nameRenderer.renderName(symbol, printer)
|
||||
typeParametersRenderer.renderTypeParameters(symbol, printer)
|
||||
if (primaryConstructor != null) {
|
||||
val annotationsPrinted = checkIfPrinted { renderAnnotationsAndModifiers(primaryConstructor, printer) }
|
||||
if (annotationsPrinted) {
|
||||
withPrefix(" ") {
|
||||
keywordRender.renderKeyword(KtTokens.CONSTRUCTOR_KEYWORD, primaryConstructor, printer)
|
||||
}
|
||||
}
|
||||
if (primaryConstructor.valueParameters.isNotEmpty()) {
|
||||
valueParametersRenderer.renderValueParameters(primaryConstructor, printer)
|
||||
}
|
||||
}
|
||||
},
|
||||
{ typeParametersRenderer.renderWhereClause(symbol, printer) },
|
||||
{ withPrefix(": ") { superTypeListRenderer.renderSuperTypes(symbol, printer) } },
|
||||
{ classifierBodyRenderer.renderBody(symbol, printer) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.declarations.renderers.classifiers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public interface KtSingleTypeParameterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtTypeParameterSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object NO : KtSingleTypeParameterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtTypeParameterSymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public object WITHOUT_BOUNDS : KtSingleTypeParameterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtTypeParameterSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ modifiersRenderer.renderDeclarationModifiers(symbol, printer) },
|
||||
{ nameRenderer.renderName(symbol, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_COMMA_SEPARATED_BOUNDS : KtSingleTypeParameterSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtTypeParameterSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ modifiersRenderer.renderDeclarationModifiers(symbol, printer) },
|
||||
{ nameRenderer.renderName(symbol, printer) },
|
||||
{
|
||||
if (symbol.upperBounds.isNotEmpty()) {
|
||||
withPrefix(": ") {
|
||||
printCollection(symbol.upperBounds) {
|
||||
typeRenderer.renderType(declarationTypeApproximator.approximateType(it, Variance.OUT_VARIANCE), printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.declarations.renderers.classifiers
|
||||
|
||||
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.symbols.KtTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
public interface KtTypeAliasSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSymbol(symbol: KtTypeAliasSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtTypeAliasSymbolRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSymbol(symbol: KtTypeAliasSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ renderAnnotationsAndModifiers(symbol, printer, KtTokens.TYPE_ALIAS_KEYWORD) },
|
||||
{
|
||||
" = ".separated(
|
||||
{
|
||||
nameRenderer.renderName(symbol, printer)
|
||||
typeParametersRenderer.renderTypeParameters(symbol, printer)
|
||||
},
|
||||
{ typeRenderer.renderType(symbol.expandedType, printer) })
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.declarations.superTypes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtSuperTypeListRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSuperTypes(symbol: KtClassOrObjectSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object AS_LIST : KtSuperTypeListRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSuperTypes(symbol: KtClassOrObjectSymbol, printer: PrettyPrinter): Unit = printer {
|
||||
val superTypesToRender = symbol.superTypes.filter { superTypesFilter.filter(it, symbol) }.ifEmpty { return }
|
||||
printCollection(superTypesToRender) { type ->
|
||||
superTypeRenderer.renderSuperType(type, symbol, printer)
|
||||
superTypesArgumentRenderer.renderSuperTypeArguments(type, symbol, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.declarations.superTypes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public interface KtSuperTypeRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSuperType(type: KtType, symbol: KtClassOrObjectSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object WITH_OUT_APPROXIMATION : KtSuperTypeRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSuperType(type: KtType, symbol: KtClassOrObjectSymbol, printer: PrettyPrinter) {
|
||||
typeRenderer.renderType(declarationTypeApproximator.approximateType(type, Variance.OUT_VARIANCE), printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.declarations.superTypes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtClassType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtSuperTypesCallArgumentsRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
public fun renderSuperTypeArguments(type: KtType, symbol: KtClassOrObjectSymbol, printer: PrettyPrinter)
|
||||
|
||||
public object NO_ARGS : KtSuperTypesCallArgumentsRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSuperTypeArguments(type: KtType, symbol: KtClassOrObjectSymbol, printer: PrettyPrinter) {
|
||||
}
|
||||
}
|
||||
|
||||
public object EMPTY_PARENS : KtSuperTypesCallArgumentsRenderer {
|
||||
context(KtAnalysisSession, KtDeclarationRenderer)
|
||||
override fun renderSuperTypeArguments(type: KtType, symbol: KtClassOrObjectSymbol, printer: PrettyPrinter) {
|
||||
if ((type as? KtClassType)?.expandedClassSymbol?.classKind?.isClass != true) {
|
||||
return
|
||||
}
|
||||
printer.append("()")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.declarations.superTypes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
|
||||
public fun interface KtSuperTypesFilter {
|
||||
context(KtAnalysisSession)
|
||||
public fun filter(superType: KtType, symbol: KtClassOrObjectSymbol): Boolean
|
||||
|
||||
public object NO_DEFAULT_TYPES : KtSuperTypesFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(superType: KtType, symbol: KtClassOrObjectSymbol): Boolean {
|
||||
if (superType.isAny) return false
|
||||
if (symbol.classKind == KtClassKind.ANNOTATION_CLASS && superType.isClassTypeWithClassId(StandardClassIds.Annotation)) return false
|
||||
if (symbol.classKind == KtClassKind.ENUM_CLASS && superType.isClassTypeWithClassId(StandardClassIds.Enum)) return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public object NO_ANY_FOR_INTERFACES : KtSuperTypesFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(superType: KtType, symbol: KtClassOrObjectSymbol): Boolean {
|
||||
return when (symbol.classKind) {
|
||||
KtClassKind.INTERFACE -> !superType.isAny
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object ALL : KtSuperTypesFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(superType: KtType, symbol: KtClassOrObjectSymbol): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public object NONE : KtSuperTypesFilter {
|
||||
context(KtAnalysisSession)
|
||||
override fun filter(superType: KtType, symbol: KtClassOrObjectSymbol): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public companion object {
|
||||
public operator fun invoke(
|
||||
predicate: context(KtAnalysisSession) (type: KtType, symbol: KtClassOrObjectSymbol) -> Boolean
|
||||
): KtSuperTypesFilter = object : KtSuperTypesFilter {
|
||||
context(KtAnalysisSession) override fun filter(superType: KtType, symbol: KtClassOrObjectSymbol): Boolean {
|
||||
return predicate(this@KtAnalysisSession, superType, symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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.types
|
||||
|
||||
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.declarations.KtRendererTypeApproximator
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.renders.*
|
||||
import org.jetbrains.kotlin.analysis.api.types.*
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public class KtTypeRenderer private constructor(
|
||||
public val capturedTypeRenderer: KtCapturedTypeRenderer,
|
||||
public val definitelyNotNullTypeRenderer: KtDefinitelyNotNullTypeRenderer,
|
||||
public val dynamicTypeRenderer: KtDynamicTypeRenderer,
|
||||
public val flexibleTypeRenderer: KtFlexibleTypeRenderer,
|
||||
public val functionalTypeRenderer: KtFunctionalTypeRenderer,
|
||||
public val integerLiteralTypeRenderer: KtIntegerLiteralTypeRenderer,
|
||||
public val intersectionTypeRenderer: KtIntersectionTypeRenderer,
|
||||
public val typeErrorTypeRenderer: KtTypeErrorTypeRenderer,
|
||||
public val typeParameterTypeRenderer: KtTypeParameterTypeRenderer,
|
||||
public val unresolvedClassErrorTypeRenderer: KtUnresolvedClassErrorTypeRenderer,
|
||||
public val usualClassTypeRenderer: KtUsualClassTypeRenderer,
|
||||
|
||||
public val classIdRenderer: KtClassTypeQualifierRenderer,
|
||||
public val typeNameRenderer: KtTypeNameRenderer,
|
||||
public val typeApproximator: KtRendererTypeApproximator,
|
||||
public val typeProjectionRenderer: KtTypeProjectionRenderer,
|
||||
public val annotationsRender: KtAnnotationRenderer,
|
||||
public val keywordRenderer: KtKeywordRenderer,
|
||||
) {
|
||||
context(KtAnalysisSession)
|
||||
public fun renderType(type: KtType, printer: PrettyPrinter) {
|
||||
when (type) {
|
||||
is KtCapturedType -> capturedTypeRenderer.renderType(type, printer)
|
||||
is KtFunctionalType -> functionalTypeRenderer.renderType(type, printer)
|
||||
is KtUsualClassType -> usualClassTypeRenderer.renderType(type, printer)
|
||||
is KtDefinitelyNotNullType -> definitelyNotNullTypeRenderer.renderType(type, printer)
|
||||
is KtDynamicType -> dynamicTypeRenderer.renderType(type, printer)
|
||||
is KtFlexibleType -> flexibleTypeRenderer.renderType(type, printer)
|
||||
is KtIntegerLiteralType -> integerLiteralTypeRenderer.renderType(type, printer)
|
||||
is KtIntersectionType -> intersectionTypeRenderer.renderType(type, printer)
|
||||
is KtTypeParameterType -> typeParameterTypeRenderer.renderType(type, printer)
|
||||
is KtClassErrorType -> unresolvedClassErrorTypeRenderer.renderType(type, printer)
|
||||
is KtTypeErrorType -> typeErrorTypeRenderer.renderType(type, printer)
|
||||
}
|
||||
}
|
||||
|
||||
public fun with(action: Builder.() -> Unit): KtTypeRenderer {
|
||||
val renderer = this
|
||||
return KtTypeRenderer {
|
||||
this.capturedTypeRenderer = renderer.capturedTypeRenderer
|
||||
this.definitelyNotNullTypeRenderer = renderer.definitelyNotNullTypeRenderer
|
||||
this.dynamicTypeRenderer = renderer.dynamicTypeRenderer
|
||||
this.flexibleTypeRenderer = renderer.flexibleTypeRenderer
|
||||
this.functionalTypeRenderer = renderer.functionalTypeRenderer
|
||||
this.integerLiteralTypeRenderer = renderer.integerLiteralTypeRenderer
|
||||
this.intersectionTypeRenderer = renderer.intersectionTypeRenderer
|
||||
this.typeErrorTypeRenderer = renderer.typeErrorTypeRenderer
|
||||
this.typeParameterTypeRenderer = renderer.typeParameterTypeRenderer
|
||||
this.unresolvedClassErrorTypeRenderer = renderer.unresolvedClassErrorTypeRenderer
|
||||
this.usualClassTypeRenderer = renderer.usualClassTypeRenderer
|
||||
this.classIdRenderer = renderer.classIdRenderer
|
||||
this.typeNameRenderer = renderer.typeNameRenderer
|
||||
this.typeApproximator = renderer.typeApproximator
|
||||
this.typeProjectionRenderer = renderer.typeProjectionRenderer
|
||||
this.annotationsRender = renderer.annotationsRender
|
||||
this.keywordRenderer = renderer.keywordRenderer
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
public companion object {
|
||||
public operator fun invoke(action: Builder.() -> Unit): KtTypeRenderer =
|
||||
Builder().apply(action).build()
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
public lateinit var capturedTypeRenderer: KtCapturedTypeRenderer
|
||||
public lateinit var definitelyNotNullTypeRenderer: KtDefinitelyNotNullTypeRenderer
|
||||
public lateinit var dynamicTypeRenderer: KtDynamicTypeRenderer
|
||||
public lateinit var flexibleTypeRenderer: KtFlexibleTypeRenderer
|
||||
public lateinit var functionalTypeRenderer: KtFunctionalTypeRenderer
|
||||
public lateinit var integerLiteralTypeRenderer: KtIntegerLiteralTypeRenderer
|
||||
public lateinit var intersectionTypeRenderer: KtIntersectionTypeRenderer
|
||||
public lateinit var typeErrorTypeRenderer: KtTypeErrorTypeRenderer
|
||||
public lateinit var typeParameterTypeRenderer: KtTypeParameterTypeRenderer
|
||||
public lateinit var unresolvedClassErrorTypeRenderer: KtUnresolvedClassErrorTypeRenderer
|
||||
public lateinit var usualClassTypeRenderer: KtUsualClassTypeRenderer
|
||||
public lateinit var classIdRenderer: KtClassTypeQualifierRenderer
|
||||
public lateinit var typeNameRenderer: KtTypeNameRenderer
|
||||
public lateinit var typeApproximator: KtRendererTypeApproximator
|
||||
public lateinit var typeProjectionRenderer: KtTypeProjectionRenderer
|
||||
public lateinit var annotationsRender: KtAnnotationRenderer
|
||||
public lateinit var keywordRenderer: KtKeywordRenderer
|
||||
|
||||
|
||||
public fun build(): KtTypeRenderer = KtTypeRenderer(
|
||||
capturedTypeRenderer,
|
||||
definitelyNotNullTypeRenderer,
|
||||
dynamicTypeRenderer,
|
||||
flexibleTypeRenderer,
|
||||
functionalTypeRenderer,
|
||||
integerLiteralTypeRenderer,
|
||||
intersectionTypeRenderer,
|
||||
typeErrorTypeRenderer,
|
||||
typeParameterTypeRenderer,
|
||||
unresolvedClassErrorTypeRenderer,
|
||||
usualClassTypeRenderer,
|
||||
classIdRenderer,
|
||||
typeNameRenderer,
|
||||
typeApproximator,
|
||||
typeProjectionRenderer,
|
||||
annotationsRender,
|
||||
keywordRenderer,
|
||||
)
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.types.impl
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.renders.KtCapturedTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.renders.KtFlexibleTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.renders.KtTypeErrorTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.renders.KtUnresolvedClassErrorTypeRenderer
|
||||
|
||||
public object KtTypeRendererForDebug {
|
||||
public val WITH_QUALIFIED_NAMES: KtTypeRenderer = KtTypeRendererForSource.WITH_QUALIFIED_NAMES.with {
|
||||
capturedTypeRenderer = KtCapturedTypeRenderer.AS_CAPUTRED_TYPE_WITH_PROJECTION
|
||||
flexibleTypeRenderer = KtFlexibleTypeRenderer.AS_SHORT
|
||||
typeErrorTypeRenderer = KtTypeErrorTypeRenderer.WITH_ERROR_MESSAGE
|
||||
unresolvedClassErrorTypeRenderer = KtUnresolvedClassErrorTypeRenderer.WITH_ERROR_MESSAGE
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.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.declarations.KtRendererTypeApproximator
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.renders.*
|
||||
|
||||
public object KtTypeRendererForSource {
|
||||
public val WITH_QUALIFIED_NAMES: KtTypeRenderer = KtTypeRenderer {
|
||||
capturedTypeRenderer = KtCapturedTypeRenderer.AS_RPOJECTION
|
||||
definitelyNotNullTypeRenderer = KtDefinitelyNotNullTypeRenderer.AS_TYPE_INTERSECTION
|
||||
dynamicTypeRenderer = KtDynamicTypeRenderer.AS_DYNAMIC_WORD
|
||||
flexibleTypeRenderer = KtFlexibleTypeRenderer.AS_SHORT
|
||||
functionalTypeRenderer = KtFunctionalTypeRenderer.AS_FUNCTIONAL_TYPE
|
||||
integerLiteralTypeRenderer = KtIntegerLiteralTypeRenderer.AS_ILT_WITH_VALUE
|
||||
intersectionTypeRenderer = KtIntersectionTypeRenderer.AS_INTERSECTION
|
||||
typeErrorTypeRenderer = KtTypeErrorTypeRenderer.AS_CODE_IF_POSSIBLE
|
||||
typeParameterTypeRenderer = KtTypeParameterTypeRenderer.AS_SOURCE
|
||||
unresolvedClassErrorTypeRenderer = KtUnresolvedClassErrorTypeRenderer.UNRESOLVED_QUALIFIER
|
||||
usualClassTypeRenderer = KtUsualClassTypeRenderer.AS_CLASS_TYPE_WITH_TYPE_ARGUMENTS
|
||||
classIdRenderer = KtClassTypeQualifierRenderer.WITH_QUALIFIED_NAMES
|
||||
typeNameRenderer = KtTypeNameRenderer.QUOTED
|
||||
typeApproximator = KtRendererTypeApproximator.TO_DENNOTABLE
|
||||
typeProjectionRenderer = KtTypeProjectionRenderer.WITH_VARIANCE
|
||||
annotationsRender = KtAnnotationRendererForSource.WITH_QUALIFIED_NAMES
|
||||
keywordRenderer = KtKeywordRenderer.AS_WORD
|
||||
}
|
||||
|
||||
public val WITH_SHORT_NAMES: KtTypeRenderer = WITH_QUALIFIED_NAMES.with {
|
||||
classIdRenderer = KtClassTypeQualifierRenderer.WITH_SHORT_NAMES_WITH_NESTED_CLASSIFIERS
|
||||
annotationsRender = KtAnnotationRendererForSource.WITH_SHORT_NAMES
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtCapturedType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
|
||||
public interface KtCapturedTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtCapturedType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_RPOJECTION : KtCapturedTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtCapturedType, printer: PrettyPrinter) {
|
||||
typeProjectionRenderer.renderTypeProjection(type.projection, printer)
|
||||
}
|
||||
}
|
||||
|
||||
public object AS_CAPUTRED_TYPE_WITH_PROJECTION : KtCapturedTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtCapturedType, printer: PrettyPrinter) {
|
||||
printer.append("CapturedType(")
|
||||
AS_RPOJECTION.renderType(type, printer)
|
||||
printer.append(")")
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtClassType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtNonErrorClassType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
|
||||
public interface KtClassTypeQualifierRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderClassTypeQualifier(type: KtClassType, printer: PrettyPrinter)
|
||||
|
||||
public object WITH_SHORT_NAMES : KtClassTypeQualifierRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderClassTypeQualifier(type: KtClassType, printer: PrettyPrinter) {
|
||||
typeNameRenderer.renderName(type.qualifiers.last().name, type, printer)
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_SHORT_NAMES_WITH_NESTED_CLASSIFIERS : KtClassTypeQualifierRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderClassTypeQualifier(type: KtClassType, printer: PrettyPrinter): Unit = printer {
|
||||
printCollection(type.qualifiers, separator = ".") { qualifier ->
|
||||
typeNameRenderer.renderName(qualifier.name, type, printer)
|
||||
printCollectionIfNotEmpty(qualifier.typeArguments, prefix = "<", postfix = ">") {
|
||||
typeProjectionRenderer.renderTypeProjection(it, this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_QUALIFIED_NAMES : KtClassTypeQualifierRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderClassTypeQualifier(type: KtClassType, printer: PrettyPrinter): Unit = printer {
|
||||
".".separated(
|
||||
{
|
||||
if (type is KtNonErrorClassType) {
|
||||
append(type.classId.packageFqName.render())
|
||||
}
|
||||
},
|
||||
{ WITH_SHORT_NAMES_WITH_NESTED_CLASSIFIERS.renderClassTypeQualifier(type, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtDefinitelyNotNullType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
|
||||
public interface KtDefinitelyNotNullTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtDefinitelyNotNullType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_TYPE_INTERSECTION : KtDefinitelyNotNullTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtDefinitelyNotNullType, printer: PrettyPrinter): Unit = printer {
|
||||
renderType(type.original, printer)
|
||||
printer.append(" & ")
|
||||
renderType(builtinTypes.ANY, printer)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtDynamicType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
|
||||
public interface KtDynamicTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtDynamicType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_DYNAMIC_WORD : KtDynamicTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtDynamicType, printer: PrettyPrinter) {
|
||||
keywordRenderer.renderKeyword(KtTokens.DYNAMIC_KEYWORD, type, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.*
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
|
||||
public interface KtFlexibleTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtFlexibleType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_RANGE : KtFlexibleTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtFlexibleType, printer: PrettyPrinter): Unit = printer {
|
||||
append('(')
|
||||
renderType(type.lowerBound, printer)
|
||||
append("..")
|
||||
renderType(type.upperBound, printer)
|
||||
append(')')
|
||||
}
|
||||
}
|
||||
|
||||
public object AS_SHORT : KtFlexibleTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtFlexibleType, printer: PrettyPrinter): Unit = printer {
|
||||
val lower = type.lowerBound
|
||||
val upper = type.upperBound
|
||||
|
||||
when {
|
||||
isNullabilityFlexibleType(lower, upper) -> {
|
||||
renderType(lower, printer)
|
||||
append("!")
|
||||
}
|
||||
|
||||
isMutabilityFlexibleType(lower, upper) -> {
|
||||
" ".separated(
|
||||
{ annotationsRender.renderAnnotations(type, printer) },
|
||||
{ append(lower.classId.asFqNameString().replace("Mutable", "(Mutable)")) },
|
||||
)
|
||||
printCollectionIfNotEmpty(lower.ownTypeArguments, prefix = "<", postfix = ">") { typeArgument ->
|
||||
typeProjectionRenderer.renderTypeProjection(typeArgument, this)
|
||||
}
|
||||
if (lower.nullability != type.upperBound.nullability) {
|
||||
append('!')
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
AS_RANGE.renderType(type, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isNullabilityFlexibleType(lower: KtType, upper: KtType): Boolean {
|
||||
val isTheSameType = lower is KtNonErrorClassType && upper is KtNonErrorClassType && lower.classId == upper.classId ||
|
||||
lower is KtTypeParameterType && upper is KtTypeParameterType && lower.symbol == upper.symbol
|
||||
if (isTheSameType &&
|
||||
lower.nullability == KtTypeNullability.NON_NULLABLE
|
||||
&& upper.nullability == KtTypeNullability.NULLABLE
|
||||
) {
|
||||
if ((lower !is KtNonErrorClassType || lower.ownTypeArguments.isEmpty()) &&
|
||||
(upper !is KtNonErrorClassType || upper.ownTypeArguments.isEmpty())
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
private fun isMutabilityFlexibleType(lower: KtType, upper: KtType): Boolean {
|
||||
contract {
|
||||
returns(true) implies (lower is KtNonErrorClassType)
|
||||
returns(true) implies (upper is KtNonErrorClassType)
|
||||
}
|
||||
if (lower !is KtNonErrorClassType || upper !is KtNonErrorClassType) return false
|
||||
|
||||
if (StandardClassIds.Collections.mutableCollectionToBaseCollection[lower.classId] != upper.classId) return false
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtFunctionalType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
|
||||
public interface KtFunctionalTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtFunctionalType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_FUNCTIONAL_TYPE : KtFunctionalTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtFunctionalType, printer: PrettyPrinter): Unit = printer {
|
||||
val annotationsRendererd = checkIfPrinted { annotationsRender.renderAnnotations(type, this) }
|
||||
if (annotationsRendererd) printer.append(" ")
|
||||
if (annotationsRendererd || type.nullability == KtTypeNullability.NULLABLE) append("(")
|
||||
" ".separated(
|
||||
{
|
||||
if (type.isSuspend) {
|
||||
keywordRenderer.renderKeyword(KtTokens.SUSPEND_KEYWORD, type, printer)
|
||||
}
|
||||
},
|
||||
{
|
||||
type.receiverType?.let { renderType(it, printer); printer.append('.') }
|
||||
printCollection(type.parameterTypes, prefix = "(", postfix = ")") {
|
||||
renderType(it, this)
|
||||
}
|
||||
append(" -> ")
|
||||
renderType(type.returnType, printer)
|
||||
},
|
||||
)
|
||||
if (annotationsRendererd || type.nullability == KtTypeNullability.NULLABLE) append(")")
|
||||
if (type.nullability == KtTypeNullability.NULLABLE) append("?")
|
||||
}
|
||||
}
|
||||
|
||||
public object AS_CLASS_TYPE : KtFunctionalTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtFunctionalType, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ annotationsRender.renderAnnotations(type, printer) },
|
||||
{
|
||||
classIdRenderer.renderClassTypeQualifier(type, printer)
|
||||
if (type.nullability == KtTypeNullability.NULLABLE) {
|
||||
append('?')
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtIntegerLiteralType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
|
||||
public interface KtIntegerLiteralTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtIntegerLiteralType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_ILT_WITH_VALUE : KtIntegerLiteralTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtIntegerLiteralType, printer: PrettyPrinter): Unit = printer {
|
||||
append("ILT(")
|
||||
printer.append(type.value.toString())
|
||||
append(')')
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtIntersectionType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
|
||||
public interface KtIntersectionTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtIntersectionType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_INTERSECTION : KtIntersectionTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtIntersectionType, printer: PrettyPrinter): Unit = printer {
|
||||
printCollection(type.conjuncts, separator = " & ") {
|
||||
renderType(it, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeErrorType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtTypeErrorTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtTypeErrorType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_CODE_IF_POSSIBLE : KtTypeErrorTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtTypeErrorType, printer: PrettyPrinter) {
|
||||
type.tryRenderAsNonErrorType()?.let {
|
||||
printer.append(it)
|
||||
return
|
||||
}
|
||||
printer.append("ERROR")
|
||||
}
|
||||
}
|
||||
|
||||
public object AS_ERROR_WORD : KtTypeErrorTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtTypeErrorType, printer: PrettyPrinter) {
|
||||
printer.append("ERROR")
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_ERROR_MESSAGE : KtTypeErrorTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtTypeErrorType, printer: PrettyPrinter) {
|
||||
printer.append("ERROR(${type.errorMessage})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
|
||||
public interface KtTypeNameRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderName(name: Name, owner: KtType, printer: PrettyPrinter)
|
||||
|
||||
public object QUOTED : KtTypeNameRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderName(name: Name, owner: KtType, printer: PrettyPrinter) {
|
||||
printer.append(name.render())
|
||||
}
|
||||
}
|
||||
|
||||
public object UNQUOTED : KtTypeNameRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderName(name: Name, owner: KtType, printer: PrettyPrinter) {
|
||||
printer.append(name.asString())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeParameterType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
|
||||
public interface KtTypeParameterTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtTypeParameterType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_SOURCE : KtTypeParameterTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtTypeParameterType, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ annotationsRender.renderAnnotations(type, printer) },
|
||||
{
|
||||
typeNameRenderer.renderName(type.name, type, printer)
|
||||
if (type.nullability == KtTypeNullability.NULLABLE) {
|
||||
printer.append('?')
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.KtStarTypeProjection
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeArgumentWithVariance
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeProjection
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtTypeProjectionRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderTypeProjection(projection: KtTypeProjection, printer: PrettyPrinter)
|
||||
|
||||
public object WITH_VARIANCE : KtTypeProjectionRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderTypeProjection(projection: KtTypeProjection, printer: PrettyPrinter): Unit = printer {
|
||||
when (projection) {
|
||||
is KtStarTypeProjection -> printer.append('*')
|
||||
is KtTypeArgumentWithVariance -> {
|
||||
" ".separated(
|
||||
{ printer.append(projection.variance.label) },
|
||||
{ renderType(projection.type, printer) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object WITHOUT_VARIANCE : KtTypeProjectionRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderTypeProjection(projection: KtTypeProjection, printer: PrettyPrinter) {
|
||||
when (projection) {
|
||||
is KtStarTypeProjection -> printer.append('*')
|
||||
is KtTypeArgumentWithVariance -> {
|
||||
renderType(projection.type, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtClassErrorType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
public interface KtUnresolvedClassErrorTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtClassErrorType, printer: PrettyPrinter)
|
||||
|
||||
public object UNRESOLVED_QUALIFIER : KtUnresolvedClassErrorTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtClassErrorType, printer: PrettyPrinter): Unit = printer {
|
||||
annotationsRender.renderAnnotations(type, printer)
|
||||
classIdRenderer.renderClassTypeQualifier(type, printer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public object AS_ERROR_WORD : KtUnresolvedClassErrorTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtClassErrorType, printer: PrettyPrinter) {
|
||||
printer.append("ERROR_TYPE")
|
||||
}
|
||||
}
|
||||
|
||||
public object WITH_ERROR_MESSAGE : KtUnresolvedClassErrorTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtClassErrorType, printer: PrettyPrinter) {
|
||||
printer.append("ERROR_TYPE(${type.errorMessage})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+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.types.renders
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtUsualClassType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
|
||||
|
||||
public interface KtUsualClassTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
public fun renderType(type: KtUsualClassType, printer: PrettyPrinter)
|
||||
|
||||
public object AS_CLASS_TYPE_WITH_TYPE_ARGUMENTS : KtUsualClassTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtUsualClassType, printer: PrettyPrinter): Unit = printer {
|
||||
" ".separated(
|
||||
{ annotationsRender.renderAnnotations(type, printer) },
|
||||
{
|
||||
classIdRenderer.renderClassTypeQualifier(type, printer)
|
||||
if (type.nullability == KtTypeNullability.NULLABLE) {
|
||||
append('?')
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
@@ -98,4 +98,5 @@ public enum class KtClassKind {
|
||||
ANONYMOUS_OBJECT;
|
||||
|
||||
public val isObject: Boolean get() = this == OBJECT || this == COMPANION_OBJECT || this == ANONYMOUS_OBJECT
|
||||
public val isClass: Boolean get() = this == CLASS || this == ANNOTATION_CLASS || this == ENUM_CLASS
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user