[FIR] Extract FirDeclarationPresenter to the separated class
This commit is contained in:
committed by
Space Team
parent
b490130e8e
commit
5a6e896b45
-210
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirNameConflictsTr
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirOuterClassTypeParameterRef
|
import org.jetbrains.kotlin.fir.declarations.impl.FirOuterClassTypeParameterRef
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isOperator
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirPackageMemberScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirPackageMemberScope
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
@@ -26,218 +25,9 @@ import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
|||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.util.ListMultimap
|
import org.jetbrains.kotlin.fir.util.ListMultimap
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||||
import org.jetbrains.kotlin.name.CallableId
|
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.utils.SmartSet
|
import org.jetbrains.kotlin.utils.SmartSet
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides representations for FirElement's.
|
|
||||||
*/
|
|
||||||
interface FirDeclarationPresenter {
|
|
||||||
fun StringBuilder.appendRepresentation(it: FirElement) {
|
|
||||||
append("NO_REPRESENTATION")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun StringBuilder.appendRepresentation(it: ClassId) {
|
|
||||||
append(it.packageFqName.asString())
|
|
||||||
append('/')
|
|
||||||
append(it.relativeClassName.asString())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun StringBuilder.appendRepresentation(it: CallableId) {
|
|
||||||
if (it.className != null) {
|
|
||||||
append(it.packageName.asString())
|
|
||||||
append('/')
|
|
||||||
append(it.className)
|
|
||||||
append('.')
|
|
||||||
append(it.callableName)
|
|
||||||
} else {
|
|
||||||
append(it.packageName.asString())
|
|
||||||
append('/')
|
|
||||||
append(it.callableName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun StringBuilder.appendRepresentation(it: ConeTypeProjection) {
|
|
||||||
when (it) {
|
|
||||||
ConeStarProjection -> {
|
|
||||||
append('*')
|
|
||||||
}
|
|
||||||
is ConeKotlinTypeProjectionIn -> {
|
|
||||||
append("in ")
|
|
||||||
appendRepresentation(it.type)
|
|
||||||
}
|
|
||||||
is ConeKotlinTypeProjectionOut -> {
|
|
||||||
append("out ")
|
|
||||||
appendRepresentation(it.type)
|
|
||||||
}
|
|
||||||
is ConeKotlinType -> {
|
|
||||||
appendRepresentation(it)
|
|
||||||
}
|
|
||||||
is ConeKotlinTypeConflictingProjection -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun StringBuilder.appendRepresentation(it: ConeKotlinType) {
|
|
||||||
when (it) {
|
|
||||||
is ConeDefinitelyNotNullType -> {
|
|
||||||
appendRepresentation(it.original)
|
|
||||||
append(it.nullability.suffix)
|
|
||||||
}
|
|
||||||
is ConeErrorType -> {
|
|
||||||
append("ERROR(")
|
|
||||||
append(it.diagnostic.reason)
|
|
||||||
append(')')
|
|
||||||
}
|
|
||||||
is ConeCapturedType -> {
|
|
||||||
append(it.constructor.projection)
|
|
||||||
append(it.nullability.suffix)
|
|
||||||
}
|
|
||||||
is ConeClassLikeType -> {
|
|
||||||
appendRepresentation(it.lookupTag.classId)
|
|
||||||
if (it.typeArguments.isNotEmpty()) {
|
|
||||||
append('<')
|
|
||||||
it.typeArguments.forEach { that ->
|
|
||||||
appendRepresentation(that)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
append('>')
|
|
||||||
}
|
|
||||||
append(it.nullability.suffix)
|
|
||||||
}
|
|
||||||
is ConeLookupTagBasedType -> {
|
|
||||||
append(it.lookupTag.name)
|
|
||||||
append(it.nullability.suffix)
|
|
||||||
}
|
|
||||||
is ConeIntegerLiteralConstantType -> {
|
|
||||||
append(it.value)
|
|
||||||
append(it.nullability.suffix)
|
|
||||||
}
|
|
||||||
is ConeIntegerConstantOperatorType -> {
|
|
||||||
append("IOT")
|
|
||||||
append(it.nullability.suffix)
|
|
||||||
}
|
|
||||||
is ConeFlexibleType,
|
|
||||||
is ConeIntersectionType,
|
|
||||||
is ConeStubType -> {
|
|
||||||
append("ERROR")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun StringBuilder.appendRepresentation(it: FirTypeRef) {
|
|
||||||
when (it) {
|
|
||||||
is FirResolvedTypeRef -> appendRepresentation(it.type)
|
|
||||||
else -> append("?")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun StringBuilder.appendRepresentation(it: FirTypeParameter) {
|
|
||||||
append(it.name.asString())
|
|
||||||
append(':')
|
|
||||||
when (it.bounds.size) {
|
|
||||||
0 -> {
|
|
||||||
}
|
|
||||||
1 -> {
|
|
||||||
appendRepresentation(it.bounds[0])
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
val set = sortedSetOf<String>()
|
|
||||||
it.bounds.forEach { that ->
|
|
||||||
set.add(buildString { appendRepresentation(that) })
|
|
||||||
}
|
|
||||||
set.forEach { that ->
|
|
||||||
append(that)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun StringBuilder.appendRepresentation(it: FirValueParameter) {
|
|
||||||
if (it.isVararg) {
|
|
||||||
append("vararg ")
|
|
||||||
}
|
|
||||||
appendRepresentation(it.returnTypeRef)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun represent(it: FirVariable) = buildString {
|
|
||||||
append('[')
|
|
||||||
it.receiverParameter?.typeRef?.let {
|
|
||||||
appendRepresentation(it)
|
|
||||||
}
|
|
||||||
append(']')
|
|
||||||
appendRepresentation(it.symbol.callableId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun StringBuilder.appendOperatorTag(it: FirSimpleFunction) {
|
|
||||||
if (it.isOperator) {
|
|
||||||
append("operator ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun represent(it: FirSimpleFunction) = buildString {
|
|
||||||
it.contextReceivers.forEach {
|
|
||||||
appendRepresentation(it)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
append('<')
|
|
||||||
it.typeParameters.forEach {
|
|
||||||
appendRepresentation(it)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
append('>')
|
|
||||||
append('[')
|
|
||||||
it.receiverParameter?.typeRef?.let {
|
|
||||||
appendRepresentation(it)
|
|
||||||
}
|
|
||||||
append(']')
|
|
||||||
appendOperatorTag(it)
|
|
||||||
appendRepresentation(it.symbol.callableId)
|
|
||||||
append('(')
|
|
||||||
it.valueParameters.forEach {
|
|
||||||
appendRepresentation(it)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
append(')')
|
|
||||||
}
|
|
||||||
|
|
||||||
fun represent(it: FirTypeAlias) = buildString {
|
|
||||||
append('[')
|
|
||||||
append(']')
|
|
||||||
appendRepresentation(it.symbol.classId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun represent(it: FirRegularClass) = buildString {
|
|
||||||
append('[')
|
|
||||||
append(']')
|
|
||||||
appendRepresentation(it.symbol.classId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun represent(it: FirConstructor, owner: FirRegularClass) = buildString {
|
|
||||||
it.contextReceivers.forEach {
|
|
||||||
appendRepresentation(it)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
append('<')
|
|
||||||
it.typeParameters.forEach {
|
|
||||||
appendRepresentation(it)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
append('>')
|
|
||||||
append('[')
|
|
||||||
append(']')
|
|
||||||
appendRepresentation(owner.symbol.classId)
|
|
||||||
append('(')
|
|
||||||
it.valueParameters.forEach {
|
|
||||||
appendRepresentation(it)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
append(')')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class FirDefaultDeclarationPresenter : FirDeclarationPresenter
|
internal class FirDefaultDeclarationPresenter : FirDeclarationPresenter
|
||||||
|
|
||||||
private val NO_NAME_PROVIDED = Name.special("<no name provided>")
|
private val NO_NAME_PROVIDED = Name.special("<no name provided>")
|
||||||
|
|||||||
+220
@@ -0,0 +1,220 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.fir.analysis.checkers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.isOperator
|
||||||
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
|
import org.jetbrains.kotlin.name.CallableId
|
||||||
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides representations for FirElement's.
|
||||||
|
*/
|
||||||
|
interface FirDeclarationPresenter {
|
||||||
|
fun StringBuilder.appendRepresentation(it: FirElement) {
|
||||||
|
append("NO_REPRESENTATION")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendRepresentation(it: ClassId) {
|
||||||
|
append(it.packageFqName.asString())
|
||||||
|
append('/')
|
||||||
|
append(it.relativeClassName.asString())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendRepresentation(it: CallableId) {
|
||||||
|
if (it.className != null) {
|
||||||
|
append(it.packageName.asString())
|
||||||
|
append('/')
|
||||||
|
append(it.className)
|
||||||
|
append('.')
|
||||||
|
append(it.callableName)
|
||||||
|
} else {
|
||||||
|
append(it.packageName.asString())
|
||||||
|
append('/')
|
||||||
|
append(it.callableName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendRepresentation(it: ConeTypeProjection) {
|
||||||
|
when (it) {
|
||||||
|
ConeStarProjection -> {
|
||||||
|
append('*')
|
||||||
|
}
|
||||||
|
is ConeKotlinTypeProjectionIn -> {
|
||||||
|
append("in ")
|
||||||
|
appendRepresentation(it.type)
|
||||||
|
}
|
||||||
|
is ConeKotlinTypeProjectionOut -> {
|
||||||
|
append("out ")
|
||||||
|
appendRepresentation(it.type)
|
||||||
|
}
|
||||||
|
is ConeKotlinType -> {
|
||||||
|
appendRepresentation(it)
|
||||||
|
}
|
||||||
|
is ConeKotlinTypeConflictingProjection -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendRepresentation(it: ConeKotlinType) {
|
||||||
|
when (it) {
|
||||||
|
is ConeDefinitelyNotNullType -> {
|
||||||
|
appendRepresentation(it.original)
|
||||||
|
append(it.nullability.suffix)
|
||||||
|
}
|
||||||
|
is ConeErrorType -> {
|
||||||
|
append("ERROR(")
|
||||||
|
append(it.diagnostic.reason)
|
||||||
|
append(')')
|
||||||
|
}
|
||||||
|
is ConeCapturedType -> {
|
||||||
|
append(it.constructor.projection)
|
||||||
|
append(it.nullability.suffix)
|
||||||
|
}
|
||||||
|
is ConeClassLikeType -> {
|
||||||
|
appendRepresentation(it.lookupTag.classId)
|
||||||
|
if (it.typeArguments.isNotEmpty()) {
|
||||||
|
append('<')
|
||||||
|
it.typeArguments.forEach { that ->
|
||||||
|
appendRepresentation(that)
|
||||||
|
append(',')
|
||||||
|
}
|
||||||
|
append('>')
|
||||||
|
}
|
||||||
|
append(it.nullability.suffix)
|
||||||
|
}
|
||||||
|
is ConeLookupTagBasedType -> {
|
||||||
|
append(it.lookupTag.name)
|
||||||
|
append(it.nullability.suffix)
|
||||||
|
}
|
||||||
|
is ConeIntegerLiteralConstantType -> {
|
||||||
|
append(it.value)
|
||||||
|
append(it.nullability.suffix)
|
||||||
|
}
|
||||||
|
is ConeIntegerConstantOperatorType -> {
|
||||||
|
append("IOT")
|
||||||
|
append(it.nullability.suffix)
|
||||||
|
}
|
||||||
|
is ConeFlexibleType,
|
||||||
|
is ConeIntersectionType,
|
||||||
|
is ConeStubType -> {
|
||||||
|
append("ERROR")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendRepresentation(it: FirTypeRef) {
|
||||||
|
when (it) {
|
||||||
|
is FirResolvedTypeRef -> appendRepresentation(it.type)
|
||||||
|
else -> append("?")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendRepresentation(it: FirTypeParameter) {
|
||||||
|
append(it.name.asString())
|
||||||
|
append(':')
|
||||||
|
when (it.bounds.size) {
|
||||||
|
0 -> {
|
||||||
|
}
|
||||||
|
1 -> {
|
||||||
|
appendRepresentation(it.bounds[0])
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val set = sortedSetOf<String>()
|
||||||
|
it.bounds.forEach { that ->
|
||||||
|
set.add(buildString { appendRepresentation(that) })
|
||||||
|
}
|
||||||
|
set.forEach { that ->
|
||||||
|
append(that)
|
||||||
|
append(',')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendRepresentation(it: FirValueParameter) {
|
||||||
|
if (it.isVararg) {
|
||||||
|
append("vararg ")
|
||||||
|
}
|
||||||
|
appendRepresentation(it.returnTypeRef)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun represent(it: FirVariable) = buildString {
|
||||||
|
append('[')
|
||||||
|
it.receiverParameter?.typeRef?.let {
|
||||||
|
appendRepresentation(it)
|
||||||
|
}
|
||||||
|
append(']')
|
||||||
|
appendRepresentation(it.symbol.callableId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendOperatorTag(it: FirSimpleFunction) {
|
||||||
|
if (it.isOperator) {
|
||||||
|
append("operator ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun represent(it: FirSimpleFunction) = buildString {
|
||||||
|
it.contextReceivers.forEach {
|
||||||
|
appendRepresentation(it)
|
||||||
|
append(',')
|
||||||
|
}
|
||||||
|
append('<')
|
||||||
|
it.typeParameters.forEach {
|
||||||
|
appendRepresentation(it)
|
||||||
|
append(',')
|
||||||
|
}
|
||||||
|
append('>')
|
||||||
|
append('[')
|
||||||
|
it.receiverParameter?.typeRef?.let {
|
||||||
|
appendRepresentation(it)
|
||||||
|
}
|
||||||
|
append(']')
|
||||||
|
appendOperatorTag(it)
|
||||||
|
appendRepresentation(it.symbol.callableId)
|
||||||
|
append('(')
|
||||||
|
it.valueParameters.forEach {
|
||||||
|
appendRepresentation(it)
|
||||||
|
append(',')
|
||||||
|
}
|
||||||
|
append(')')
|
||||||
|
}
|
||||||
|
|
||||||
|
fun represent(it: FirTypeAlias) = buildString {
|
||||||
|
append('[')
|
||||||
|
append(']')
|
||||||
|
appendRepresentation(it.symbol.classId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun represent(it: FirRegularClass) = buildString {
|
||||||
|
append('[')
|
||||||
|
append(']')
|
||||||
|
appendRepresentation(it.symbol.classId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun represent(it: FirConstructor, owner: FirRegularClass) = buildString {
|
||||||
|
it.contextReceivers.forEach {
|
||||||
|
appendRepresentation(it)
|
||||||
|
append(',')
|
||||||
|
}
|
||||||
|
append('<')
|
||||||
|
it.typeParameters.forEach {
|
||||||
|
appendRepresentation(it)
|
||||||
|
append(',')
|
||||||
|
}
|
||||||
|
append('>')
|
||||||
|
append('[')
|
||||||
|
append(']')
|
||||||
|
appendRepresentation(owner.symbol.classId)
|
||||||
|
append('(')
|
||||||
|
it.valueParameters.forEach {
|
||||||
|
appendRepresentation(it)
|
||||||
|
append(',')
|
||||||
|
}
|
||||||
|
append(')')
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user