Made some code refactoring to make it more readable
This commit is contained in:
committed by
Mikhail Glukhikh
parent
f07d85eb83
commit
311964acea
@@ -25,19 +25,25 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||||
import org.jetbrains.kotlin.KtNodeTypes.*
|
import org.jetbrains.kotlin.KtNodeTypes.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.*
|
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.*
|
||||||
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.nameAsSafeName
|
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.nameAsSafeName
|
||||||
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.toDelegatedSelfType
|
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.toDelegatedSelfType
|
||||||
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.hasSecondaryConstructor
|
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.hasSecondaryConstructor
|
||||||
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.toFirProperty
|
|
||||||
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.toReturn
|
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.toReturn
|
||||||
|
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.joinTypeParameters
|
||||||
|
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.extractArgumentsFrom
|
||||||
|
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.fillEnumEntryConstructor
|
||||||
|
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.fillConstructors
|
||||||
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.toFirExpression
|
import org.jetbrains.kotlin.fir.lightTree.ConverterUtil.toFirExpression
|
||||||
import org.jetbrains.kotlin.fir.lightTree.FunctionUtil.removeLast
|
import org.jetbrains.kotlin.fir.lightTree.FunctionUtil.removeLast
|
||||||
|
import org.jetbrains.kotlin.fir.lightTree.fir.TypeConstraint
|
||||||
import org.jetbrains.kotlin.fir.lightTree.fir.ValueParameter
|
import org.jetbrains.kotlin.fir.lightTree.fir.ValueParameter
|
||||||
import org.jetbrains.kotlin.name.SpecialNames
|
import org.jetbrains.kotlin.name.SpecialNames
|
||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
|
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
|
||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtDotQualifiedExpressionElementType
|
import org.jetbrains.kotlin.psi.stubs.elements.KtDotQualifiedExpressionElementType
|
||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStringTemplateExpressionElementType
|
import org.jetbrains.kotlin.psi.stubs.elements.KtStringTemplateExpressionElementType
|
||||||
|
import java.util.stream.Collectors
|
||||||
|
|
||||||
class Converter(
|
class Converter(
|
||||||
val session: FirSession,
|
val session: FirSession,
|
||||||
@@ -62,10 +68,16 @@ class Converter(
|
|||||||
private val implicitEnumType = FirImplicitEnumTypeRef(session, null)
|
private val implicitEnumType = FirImplicitEnumTypeRef(session, null)
|
||||||
private val implicitType = FirImplicitTypeRefImpl(session, null)
|
private val implicitType = FirImplicitTypeRefImpl(session, null)
|
||||||
|
|
||||||
private inline fun LighterASTNode.forEachChildren(f: (LighterASTNode) -> Unit) {
|
private fun LighterASTNode?.getChildrenAsArray(): Array<LighterASTNode?> {
|
||||||
|
if (this == null) return arrayOf()
|
||||||
|
|
||||||
val kidsRef = Ref<Array<LighterASTNode?>>()
|
val kidsRef = Ref<Array<LighterASTNode?>>()
|
||||||
tree.getChildren(this, kidsRef)
|
tree.getChildren(this, kidsRef)
|
||||||
val kidsArray = kidsRef.get()
|
return kidsRef.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun LighterASTNode.forEachChildren(f: (LighterASTNode) -> Unit) {
|
||||||
|
val kidsArray = this.getChildrenAsArray()
|
||||||
for (kid in kidsArray) {
|
for (kid in kidsArray) {
|
||||||
if (kid == null) continue
|
if (kid == null) continue
|
||||||
val tokenType = kid.tokenType
|
val tokenType = kid.tokenType
|
||||||
@@ -74,6 +86,20 @@ class Converter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inline fun <T> LighterASTNode.forEachChildrenReturnList(f: (LighterASTNode, MutableList<T>) -> Unit): List<T> {
|
||||||
|
val kidsArray = this.getChildrenAsArray()
|
||||||
|
|
||||||
|
val container = mutableListOf<T>()
|
||||||
|
for (kid in kidsArray) {
|
||||||
|
if (kid == null) continue
|
||||||
|
val tokenType = kid.tokenType
|
||||||
|
if (COMMENTS.contains(tokenType) || tokenType == WHITE_SPACE || tokenType == SEMICOLON) continue
|
||||||
|
f(kid, container)
|
||||||
|
}
|
||||||
|
|
||||||
|
return container
|
||||||
|
}
|
||||||
|
|
||||||
fun convertFile(file: LighterASTNode, fileName: String = ""): FirFile {
|
fun convertFile(file: LighterASTNode, fileName: String = ""): FirFile {
|
||||||
val tokenType = file.tokenType
|
val tokenType = file.tokenType
|
||||||
if (tokenType !is IFileElementType) {
|
if (tokenType !is IFileElementType) {
|
||||||
@@ -87,9 +113,9 @@ class Converter(
|
|||||||
ClassNameUtil.packageFqName = FqName.ROOT
|
ClassNameUtil.packageFqName = FqName.ROOT
|
||||||
file.forEachChildren {
|
file.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
FILE_ANNOTATION_LIST -> fileAnnotationList += convertFileAnnotation(it)
|
FILE_ANNOTATION_LIST -> fileAnnotationList += convertFileAnnotationList(it)
|
||||||
PACKAGE_DIRECTIVE -> ClassNameUtil.packageFqName = convertPackageHeader(it)
|
PACKAGE_DIRECTIVE -> ClassNameUtil.packageFqName = convertPackageName(it)
|
||||||
IMPORT_LIST -> importList += convertImportList(it)
|
IMPORT_LIST -> importList += convertImportDirectives(it)
|
||||||
CLASS -> firDeclarationList += convertClass(it)
|
CLASS -> firDeclarationList += convertClass(it)
|
||||||
FUN -> firDeclarationList += convertFunctionDeclaration(it)
|
FUN -> firDeclarationList += convertFunctionDeclaration(it)
|
||||||
PROPERTY -> firDeclarationList += convertPropertyDeclaration(it)
|
PROPERTY -> firDeclarationList += convertPropertyDeclaration(it)
|
||||||
@@ -111,18 +137,21 @@ class Converter(
|
|||||||
return firFile
|
return firFile
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertFileAnnotation(fileAnnotationList: LighterASTNode): List<FirAnnotationCall> {
|
/**
|
||||||
val annotationList = mutableListOf<FirAnnotationCall>()
|
* [org.jetbrains.kotlin.parsing.KotlinParsing.parseFileAnnotationList]
|
||||||
fileAnnotationList.forEachChildren {
|
*/
|
||||||
when (it.tokenType) {
|
private fun convertFileAnnotationList(fileAnnotationList: LighterASTNode): List<FirAnnotationCall> {
|
||||||
ANNOTATION -> annotationList += convertAnnotation(it)
|
return fileAnnotationList.forEachChildrenReturnList { node, container ->
|
||||||
|
when (node.tokenType) {
|
||||||
|
ANNOTATION -> container += convertAnnotation(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return annotationList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertPackageHeader(packageNode: LighterASTNode): FqName {
|
/**
|
||||||
|
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePackageName
|
||||||
|
*/
|
||||||
|
private fun convertPackageName(packageNode: LighterASTNode): FqName {
|
||||||
var packageName: FqName = FqName.ROOT
|
var packageName: FqName = FqName.ROOT
|
||||||
packageNode.forEachChildren {
|
packageNode.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
@@ -132,17 +161,20 @@ class Converter(
|
|||||||
return packageName
|
return packageName
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertImportList(importList: LighterASTNode): List<FirImport> {
|
/**
|
||||||
val imports = mutableListOf<FirImport>()
|
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseImportDirectives
|
||||||
importList.forEachChildren {
|
*/
|
||||||
when (it.tokenType) {
|
private fun convertImportDirectives(importList: LighterASTNode): List<FirImport> {
|
||||||
IMPORT_DIRECTIVE -> imports += convertImportDirective(it)
|
return importList.forEachChildrenReturnList { node, container ->
|
||||||
|
when (node.tokenType) {
|
||||||
|
IMPORT_DIRECTIVE -> container += convertImportDirective(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return imports
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseImportDirective
|
||||||
|
*/
|
||||||
private fun convertImportDirective(importDirective: LighterASTNode): FirImport {
|
private fun convertImportDirective(importDirective: LighterASTNode): FirImport {
|
||||||
var importedFqName: FqName? = null
|
var importedFqName: FqName? = null
|
||||||
var isAllUnder: Boolean = false
|
var isAllUnder: Boolean = false
|
||||||
@@ -166,32 +198,31 @@ class Converter(
|
|||||||
null,
|
null,
|
||||||
importedFqName,
|
importedFqName,
|
||||||
isAllUnder,
|
isAllUnder,
|
||||||
aliasName?.let { Name.identifier(it) }
|
aliasName.nameAsSafeName()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertImportAlias(importAlias: LighterASTNode): String {
|
private fun convertImportAlias(importAlias: LighterASTNode): String {
|
||||||
var alias: String? = null
|
|
||||||
importAlias.forEachChildren {
|
importAlias.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
IDENTIFIER -> alias = it.toString()
|
IDENTIFIER -> return it.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO specify error
|
//TODO specify error
|
||||||
return alias ?: throw Exception()
|
throw Exception()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertClass(classNode: LighterASTNode): FirDeclaration {
|
private fun convertClass(classNode: LighterASTNode): FirDeclaration {
|
||||||
var modifiers = Modifier(session)
|
var modifiers = Modifier(session)
|
||||||
var classKind: ClassKind? = null
|
lateinit var classKind: ClassKind
|
||||||
var identifier: String? = null
|
var identifier: String? = null
|
||||||
val typeParameters = mutableListOf<FirTypeParameter>()
|
val typeParameters = mutableListOf<FirTypeParameter>()
|
||||||
var primaryConstructor: LighterASTNode? = null
|
var primaryConstructor: LighterASTNode? = null
|
||||||
val superTypeRefs = mutableListOf<FirTypeRef>()
|
val superTypeRefs = mutableListOf<FirTypeRef>()
|
||||||
val superTypeCallEntry = mutableListOf<FirExpression>()
|
val superTypeCallEntry = mutableListOf<FirExpression>()
|
||||||
var delegatedSuperTypeRef: FirTypeRef? = null
|
var delegatedSuperTypeRef: FirTypeRef? = null
|
||||||
val typeConstraints = mutableListOf<Pair<String, FirTypeRef>>()
|
val typeConstraints = mutableListOf<TypeConstraint>()
|
||||||
var classBody: LighterASTNode? = null
|
var classBody: LighterASTNode? = null
|
||||||
classNode.forEachChildren {
|
classNode.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
@@ -215,9 +246,12 @@ class Converter(
|
|||||||
classKind = when {
|
classKind = when {
|
||||||
modifiers.classModifier == ClassModifier.ENUM -> ClassKind.ENUM_CLASS
|
modifiers.classModifier == ClassModifier.ENUM -> ClassKind.ENUM_CLASS
|
||||||
modifiers.classModifier == ClassModifier.ANNOTATION -> ClassKind.ANNOTATION_CLASS
|
modifiers.classModifier == ClassModifier.ANNOTATION -> ClassKind.ANNOTATION_CLASS
|
||||||
else -> classKind!!
|
else -> classKind
|
||||||
}
|
}
|
||||||
|
val hasSecondaryConstructor = classBody.hasSecondaryConstructor(classBody.getChildrenAsArray())
|
||||||
val className = identifier.nameAsSafeName(if (modifiers.classModifier == ClassModifier.COMPANION) "Companion" else "")
|
val className = identifier.nameAsSafeName(if (modifiers.classModifier == ClassModifier.COMPANION) "Companion" else "")
|
||||||
|
val delegatedSelfTypeRef = className.toDelegatedSelfType(session)
|
||||||
|
delegatedSuperTypeRef = delegatedSuperTypeRef ?: if (classKind == ClassKind.ENUM_CLASS) implicitEnumType else implicitAnyType
|
||||||
|
|
||||||
return ClassNameUtil.withChildClassName(className) {
|
return ClassNameUtil.withChildClassName(className) {
|
||||||
val firClass = FirClassImpl(
|
val firClass = FirClassImpl(
|
||||||
@@ -229,7 +263,7 @@ class Converter(
|
|||||||
modifiers.inheritanceModifier?.toModality(),
|
modifiers.inheritanceModifier?.toModality(),
|
||||||
modifiers.platformModifier == PlatformModifier.EXPECT,
|
modifiers.platformModifier == PlatformModifier.EXPECT,
|
||||||
modifiers.platformModifier == PlatformModifier.ACTUAL,
|
modifiers.platformModifier == PlatformModifier.ACTUAL,
|
||||||
classKind!!,
|
classKind,
|
||||||
isInner = modifiers.classModifier == ClassModifier.INNER,
|
isInner = modifiers.classModifier == ClassModifier.INNER,
|
||||||
isCompanion = modifiers.classModifier == ClassModifier.COMPANION,
|
isCompanion = modifiers.classModifier == ClassModifier.COMPANION,
|
||||||
isData = modifiers.classModifier == ClassModifier.DATA,
|
isData = modifiers.classModifier == ClassModifier.DATA,
|
||||||
@@ -237,86 +271,40 @@ class Converter(
|
|||||||
)
|
)
|
||||||
firClass.annotations += modifiers.annotations
|
firClass.annotations += modifiers.annotations
|
||||||
firClass.typeParameters += typeParameters
|
firClass.typeParameters += typeParameters
|
||||||
typeConstraints.forEach { (identifier, type) ->
|
firClass.joinTypeParameters(typeConstraints)
|
||||||
firClass.typeParameters.forEach { typeParameter ->
|
|
||||||
if (identifier == typeParameter.name.identifier) {
|
|
||||||
(typeParameter as FirTypeParameterImpl).bounds += type
|
|
||||||
typeParameter.annotations += type.annotations
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
firClass.superTypeRefs += superTypeRefs
|
firClass.superTypeRefs += superTypeRefs
|
||||||
|
|
||||||
var firPrimaryConstructor: FirConstructor? = null
|
var firPrimaryConstructor: FirConstructor? = null
|
||||||
val hasSecondaryConstructor = classBody.hasSecondaryConstructor(tree)
|
if (classKind != ClassKind.INTERFACE && !(primaryConstructor == null && hasSecondaryConstructor)) {
|
||||||
val delegatedSelfType = identifier.nameAsSafeName().toDelegatedSelfType(session)
|
val firDelegatedConstructorCall = convertConstructorDelegationCall(null)
|
||||||
if (classKind != ClassKind.INTERFACE) {
|
.extractArgumentsFrom(superTypeCallEntry, stubMode)
|
||||||
delegatedSuperTypeRef =
|
firPrimaryConstructor = convertPrimaryConstructor(primaryConstructor)
|
||||||
delegatedSuperTypeRef ?: if (classKind == ClassKind.ENUM_CLASS) implicitEnumType else implicitAnyType
|
.apply {
|
||||||
firPrimaryConstructor = convertPrimaryConstructor(
|
this.returnTypeRef = delegatedSelfTypeRef
|
||||||
primaryConstructor,
|
this.delegatedConstructor = firDelegatedConstructorCall
|
||||||
hasSecondaryConstructor,
|
firClass.declarations += this
|
||||||
superTypeCallEntry,
|
}
|
||||||
delegatedSelfType,
|
|
||||||
delegatedSuperTypeRef!!
|
|
||||||
)?.apply {
|
|
||||||
firClass.declarations += this
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
getValueParameters(primaryConstructor).forEach {
|
getValueParameters(primaryConstructor).forEach {
|
||||||
if (it.isVal || it.isVar) {
|
if (it.isValOrVar()) {
|
||||||
firClass.declarations += it.toFirProperty()
|
firClass.declarations += it.toFirProperty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classKind == ClassKind.ENUM_CLASS) {
|
classBody?.let {
|
||||||
// separate converter only for enum entries
|
if (classKind == ClassKind.ENUM_CLASS) {
|
||||||
classBody?.let {
|
// separate converter only for enum entries
|
||||||
val firEnumEntries = convertEnumClassBody(it)
|
val firEnumEntries = convertEnumClassBody(it) //return enum entries list
|
||||||
firEnumEntries.forEach { firEnumEntry ->
|
firEnumEntries.fillEnumEntryConstructor(firPrimaryConstructor!!, stubMode)
|
||||||
val enumDelegatedSelfTypeRef = className.toDelegatedSelfType(session)
|
|
||||||
val enumDelegatedSuperTypeRef: FirTypeRef?
|
|
||||||
val enumSuperTypeCallEntry = mutableListOf<FirValueParameter>()
|
|
||||||
|
|
||||||
if (firPrimaryConstructor != null && firPrimaryConstructor.valueParameters.isNotEmpty()) {
|
|
||||||
enumDelegatedSuperTypeRef = enumDelegatedSelfTypeRef
|
|
||||||
firEnumEntry.superTypeRefs += enumDelegatedSuperTypeRef
|
|
||||||
enumSuperTypeCallEntry += firPrimaryConstructor.valueParameters
|
|
||||||
} else {
|
|
||||||
enumDelegatedSuperTypeRef = implicitAnyType
|
|
||||||
}
|
|
||||||
|
|
||||||
val firEnumPrimaryConstructor = convertPrimaryConstructor(
|
|
||||||
null, //null means that enum entry has no primary consctuctor
|
|
||||||
false,
|
|
||||||
firPrimaryConstructor?.valueParameters?.map { valueParameter ->
|
|
||||||
valueParameter.toFirExpression(
|
|
||||||
session,
|
|
||||||
stubMode
|
|
||||||
)
|
|
||||||
} ?: listOf(),
|
|
||||||
enumDelegatedSelfTypeRef,
|
|
||||||
enumDelegatedSuperTypeRef
|
|
||||||
)
|
|
||||||
firEnumEntry.declarations.add(0, firEnumPrimaryConstructor!!)
|
|
||||||
}
|
|
||||||
firClass.declarations += firEnumEntries
|
firClass.declarations += firEnumEntries
|
||||||
}
|
}
|
||||||
|
firClass.declarations += convertClassBody(it)
|
||||||
}
|
}
|
||||||
classBody?.let { firClass.declarations += convertClassBody(it) }
|
|
||||||
if (hasSecondaryConstructor) {
|
firClass.declarations.stream()
|
||||||
firClass.declarations.stream().filter { it is FirConstructor }.forEach { secondaryConstructor ->
|
.filter { it is FirConstructor }
|
||||||
(secondaryConstructor as FirConstructorImpl).returnTypeRef = delegatedSelfType
|
.collect(Collectors.toList())
|
||||||
val constructorDelegationCall = secondaryConstructor.delegatedConstructor as? FirDelegatedConstructorCallImpl
|
.fillConstructors(primaryConstructor != null, delegatedSelfTypeRef, delegatedSuperTypeRef!!)
|
||||||
val isThis =
|
|
||||||
(constructorDelegationCall == null && primaryConstructor != null) || constructorDelegationCall?.isThis == true
|
|
||||||
val delegatedType = when {
|
|
||||||
isThis -> delegatedSelfType
|
|
||||||
else -> delegatedSuperTypeRef ?: FirErrorTypeRefImpl(session, null, "No super type")
|
|
||||||
}
|
|
||||||
constructorDelegationCall?.constructedTypeRef = delegatedType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return@withChildClassName firClass
|
return@withChildClassName firClass
|
||||||
}
|
}
|
||||||
@@ -325,24 +313,15 @@ class Converter(
|
|||||||
private fun getValueParameters(primaryConstructor: LighterASTNode?): List<ValueParameter> {
|
private fun getValueParameters(primaryConstructor: LighterASTNode?): List<ValueParameter> {
|
||||||
if (primaryConstructor == null) return listOf()
|
if (primaryConstructor == null) return listOf()
|
||||||
|
|
||||||
val valueParameters = mutableListOf<ValueParameter>()
|
return primaryConstructor.forEachChildrenReturnList { node, container ->
|
||||||
primaryConstructor.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
VALUE_PARAMETER_LIST -> container += convertClassParameters(node)
|
||||||
VALUE_PARAMETER_LIST -> valueParameters += convertClassParameters(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valueParameters
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertPrimaryConstructor(
|
private fun convertPrimaryConstructor(primaryConstructor: LighterASTNode?): FirConstructorImpl {
|
||||||
primaryConstructor: LighterASTNode?,
|
//if (primaryConstructor == null && hasSecondaryConstructor) return null
|
||||||
hasSecondaryConstructor: Boolean,
|
|
||||||
superTypeCallEntry: List<FirExpression>,
|
|
||||||
delegatedSelfType: FirTypeRef,
|
|
||||||
delegatedSuperTypeRef: FirTypeRef
|
|
||||||
): FirConstructor? {
|
|
||||||
if (primaryConstructor == null && hasSecondaryConstructor) return null
|
|
||||||
|
|
||||||
var modifiers = Modifier(session)
|
var modifiers = Modifier(session)
|
||||||
val valueParameters = mutableListOf<ValueParameter>()
|
val valueParameters = mutableListOf<ValueParameter>()
|
||||||
@@ -353,12 +332,6 @@ class Converter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val firDelegatedCall = FirDelegatedConstructorCallImpl(
|
|
||||||
session,
|
|
||||||
null,
|
|
||||||
delegatedSuperTypeRef,
|
|
||||||
isThis = false
|
|
||||||
)
|
|
||||||
return FirPrimaryConstructorImpl(
|
return FirPrimaryConstructorImpl(
|
||||||
session,
|
session,
|
||||||
null,
|
null,
|
||||||
@@ -366,37 +339,28 @@ class Converter(
|
|||||||
modifiers.visibilityModifier.toVisibility(),
|
modifiers.visibilityModifier.toVisibility(),
|
||||||
modifiers.platformModifier == PlatformModifier.EXPECT,
|
modifiers.platformModifier == PlatformModifier.EXPECT,
|
||||||
modifiers.platformModifier == PlatformModifier.ACTUAL,
|
modifiers.platformModifier == PlatformModifier.ACTUAL,
|
||||||
delegatedSelfType,
|
implicitType, //must be initialized with "delegatedSelfTypeRef" outside of this method
|
||||||
firDelegatedCall
|
null //must be initialized outside of this method
|
||||||
).apply {
|
).apply {
|
||||||
annotations += modifiers.annotations
|
annotations += modifiers.annotations
|
||||||
this.valueParameters += valueParameters.map { it.firValueParameter }
|
this.valueParameters += valueParameters.map { it.firValueParameter }
|
||||||
delegatedConstructor?.apply {
|
|
||||||
if (!stubMode) {
|
|
||||||
TODO("not implemented")
|
|
||||||
//superTypeCallEntry?.extractArgumentsTo(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertClassParameters(classParameters: LighterASTNode): List<ValueParameter> {
|
private fun convertClassParameters(classParameters: LighterASTNode): List<ValueParameter> {
|
||||||
val valueParameters = mutableListOf<ValueParameter>()
|
return classParameters.forEachChildrenReturnList { node, container ->
|
||||||
classParameters.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
VALUE_PARAMETER -> container += convertClassParameter(node)
|
||||||
VALUE_PARAMETER -> valueParameters += convertClassParameter(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valueParameters
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertClassParameter(classParameter: LighterASTNode): ValueParameter {
|
private fun convertClassParameter(classParameter: LighterASTNode): ValueParameter {
|
||||||
var modifiers = Modifier(session)
|
var modifiers = Modifier(session)
|
||||||
var isVal = false
|
var isVal = false
|
||||||
var isVar = false
|
var isVar = false
|
||||||
var identifier: String? = null
|
lateinit var identifier: String
|
||||||
var firType: FirTypeRef? = null
|
lateinit var firType: FirTypeRef
|
||||||
var firExpression: FirExpression? = null
|
var firExpression: FirExpression? = null
|
||||||
classParameter.forEachChildren {
|
classParameter.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
@@ -415,8 +379,8 @@ class Converter(
|
|||||||
val firValueParameter = FirValueParameterImpl(
|
val firValueParameter = FirValueParameterImpl(
|
||||||
session,
|
session,
|
||||||
null,
|
null,
|
||||||
Name.identifier(identifier!!),
|
Name.identifier(identifier),
|
||||||
firType!!,
|
firType,
|
||||||
firExpression,
|
firExpression,
|
||||||
isCrossinline = modifiers.parameterModifier == ParameterModifier.CROSSINLINE,
|
isCrossinline = modifiers.parameterModifier == ParameterModifier.CROSSINLINE,
|
||||||
isNoinline = modifiers.parameterModifier == ParameterModifier.NOINLINE,
|
isNoinline = modifiers.parameterModifier == ParameterModifier.NOINLINE,
|
||||||
@@ -447,20 +411,24 @@ class Converter(
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* constructorInvocation
|
||||||
|
* : userType valueArguments
|
||||||
|
*/
|
||||||
private fun convertConstructorInvocation(constructorInvocation: LighterASTNode): Pair<FirTypeRef, List<FirExpression>> {
|
private fun convertConstructorInvocation(constructorInvocation: LighterASTNode): Pair<FirTypeRef, List<FirExpression>> {
|
||||||
var firTypeRef: FirTypeRef? = null
|
lateinit var firTypeRef: FirTypeRef
|
||||||
val firValueArguments = mutableListOf<FirExpression>()
|
val firValueArguments = mutableListOf<FirExpression>()
|
||||||
constructorInvocation.forEachChildren {
|
constructorInvocation.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
CONSTRUCTOR_CALLEE -> firTypeRef = convertType(it)
|
CONSTRUCTOR_CALLEE -> firTypeRef = convertType(it)
|
||||||
VALUE_ARGUMENT_LIST -> if (!stubMode) firValueArguments += convertValueArguments(it)
|
VALUE_ARGUMENT_LIST -> firValueArguments += convertValueArguments(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Pair(firTypeRef!!, firValueArguments)
|
return Pair(firTypeRef, firValueArguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertExplicitDelegation(explicitDelegation: LighterASTNode): FirDelegatedTypeRef {
|
private fun convertExplicitDelegation(explicitDelegation: LighterASTNode): FirDelegatedTypeRef {
|
||||||
var firTypeRef: FirTypeRef? = null
|
lateinit var firTypeRef: FirTypeRef
|
||||||
var expression: FirExpression? = null
|
var expression: FirExpression? = null
|
||||||
explicitDelegation.forEachChildren {
|
explicitDelegation.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
@@ -473,32 +441,32 @@ class Converter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return FirDelegatedTypeRefImpl(
|
return FirDelegatedTypeRefImpl(
|
||||||
firTypeRef!!,
|
firTypeRef,
|
||||||
expression
|
expression
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertClassBody(classBody: LighterASTNode): List<FirDeclaration> {
|
private fun convertClassBody(classBody: LighterASTNode): List<FirDeclaration> {
|
||||||
val firDeclarationList = mutableListOf<FirDeclaration>()
|
return classBody.forEachChildrenReturnList { node, container ->
|
||||||
classBody.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
CLASS -> container += convertClass(node)
|
||||||
CLASS -> firDeclarationList += convertClass(it)
|
FUN -> container += convertFunctionDeclaration(node)
|
||||||
FUN -> firDeclarationList += convertFunctionDeclaration(it)
|
PROPERTY -> container += convertPropertyDeclaration(node)
|
||||||
PROPERTY -> firDeclarationList += convertPropertyDeclaration(it)
|
TYPEALIAS -> container += convertTypeAlias(node)
|
||||||
TYPEALIAS -> firDeclarationList += convertTypeAlias(it)
|
OBJECT_DECLARATION -> container += convertClass(node)
|
||||||
OBJECT_DECLARATION -> firDeclarationList += convertClass(it)
|
CLASS_INITIALIZER -> container += convertAnonymousInitializer(node) //anonymousInitializer
|
||||||
CLASS_INITIALIZER -> firDeclarationList += convertAnonymousInitializer(it) //anonymousInitializer
|
SECONDARY_CONSTRUCTOR -> container += convertSecondaryConstructor(node)
|
||||||
SECONDARY_CONSTRUCTOR -> firDeclarationList += convertSecondaryConstructor(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return firDeclarationList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertConstructorDelegationCall(constructorDelegationCall: LighterASTNode): FirDelegatedConstructorCall {
|
/**
|
||||||
|
* see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor#convert(KtConstructorDelegationCall, FirTypeRef, Boolean)
|
||||||
|
*/
|
||||||
|
private fun convertConstructorDelegationCall(constructorDelegationCall: LighterASTNode?): FirDelegatedConstructorCallImpl {
|
||||||
var isThis: Boolean = false
|
var isThis: Boolean = false
|
||||||
var isSuper: Boolean = false
|
var isSuper: Boolean = false
|
||||||
constructorDelegationCall.forEachChildren {
|
constructorDelegationCall?.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
CONSTRUCTOR_DELEGATION_REFERENCE -> {
|
CONSTRUCTOR_DELEGATION_REFERENCE -> {
|
||||||
if (it.toString() == "this") isThis = true
|
if (it.toString() == "this") isThis = true
|
||||||
@@ -508,33 +476,20 @@ class Converter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*val isThis = this?.THIS() != null || (this == null && hasPrimaryConstructor)
|
|
||||||
val delegatedType = when {
|
|
||||||
isThis -> delegatedSelfTypeRef
|
|
||||||
else -> delegatedSuperTypeRef ?: FirErrorTypeRefImpl(session, null, "No super type")
|
|
||||||
}*/
|
|
||||||
return FirDelegatedConstructorCallImpl(
|
return FirDelegatedConstructorCallImpl(
|
||||||
session,
|
session,
|
||||||
null,
|
null,
|
||||||
implicitType,
|
implicitType,
|
||||||
isThis
|
isThis
|
||||||
).apply {
|
).extractArgumentsFrom(listOf(), stubMode) //TODO implement
|
||||||
if (!stubMode) {
|
|
||||||
TODO("not implemented")
|
|
||||||
//extractArgumentsTo(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertEnumClassBody(classBody: LighterASTNode): List<FirEnumEntryImpl> {
|
private fun convertEnumClassBody(classBody: LighterASTNode): List<FirEnumEntryImpl> {
|
||||||
val firDeclarationList = mutableListOf<FirEnumEntryImpl>()
|
return classBody.forEachChildrenReturnList { node, container ->
|
||||||
classBody.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
ENUM_ENTRY -> container += convertEnumEntry(node)
|
||||||
ENUM_ENTRY -> firDeclarationList += convertEnumEntry(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return firDeclarationList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private fun convertClassMemberDeclarations(classMemberDeclarations: LighterASTNode): FirElement {
|
/*private fun convertClassMemberDeclarations(classMemberDeclarations: LighterASTNode): FirElement {
|
||||||
@@ -578,8 +533,8 @@ class Converter(
|
|||||||
modifiers.visibilityModifier.toVisibility(),
|
modifiers.visibilityModifier.toVisibility(),
|
||||||
modifiers.platformModifier == PlatformModifier.EXPECT,
|
modifiers.platformModifier == PlatformModifier.EXPECT,
|
||||||
modifiers.platformModifier == PlatformModifier.ACTUAL,
|
modifiers.platformModifier == PlatformModifier.ACTUAL,
|
||||||
implicitType,//delegatedSelfTypeRef,
|
implicitType, //must be initialized with "delegatedSelfTypeRef" outside of this method
|
||||||
constructorDelegationCall//this?.constructorDelegationCall().convert(delegatedSuperTypeRef, delegatedSelfTypeRef, hasPrimaryConstructor)
|
constructorDelegationCall
|
||||||
)
|
)
|
||||||
FunctionUtil.firFunctions += firConstructor
|
FunctionUtil.firFunctions += firConstructor
|
||||||
firConstructor.annotations += modifiers.annotations
|
firConstructor.annotations += modifiers.annotations
|
||||||
@@ -591,7 +546,7 @@ class Converter(
|
|||||||
|
|
||||||
private fun convertEnumEntry(enumEntry: LighterASTNode): FirEnumEntryImpl {
|
private fun convertEnumEntry(enumEntry: LighterASTNode): FirEnumEntryImpl {
|
||||||
var modifiers = Modifier(session)
|
var modifiers = Modifier(session)
|
||||||
var identifier: String? = null
|
lateinit var identifier: String
|
||||||
var initializerList = null
|
var initializerList = null
|
||||||
val firDeclarations = mutableListOf<FirDeclaration>()
|
val firDeclarations = mutableListOf<FirDeclaration>()
|
||||||
enumEntry.forEachChildren {
|
enumEntry.forEachChildren {
|
||||||
@@ -603,7 +558,7 @@ class Converter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val enumEntryName = Name.identifier(identifier!!)
|
val enumEntryName = Name.identifier(identifier)
|
||||||
return ClassNameUtil.withChildClassName(enumEntryName) {
|
return ClassNameUtil.withChildClassName(enumEntryName) {
|
||||||
return@withChildClassName FirEnumEntryImpl(
|
return@withChildClassName FirEnumEntryImpl(
|
||||||
session,
|
session,
|
||||||
@@ -619,13 +574,13 @@ class Converter(
|
|||||||
|
|
||||||
private fun convertFunctionDeclaration(functionDeclaration: LighterASTNode): FirDeclaration {
|
private fun convertFunctionDeclaration(functionDeclaration: LighterASTNode): FirDeclaration {
|
||||||
var modifiers = Modifier(session)
|
var modifiers = Modifier(session)
|
||||||
var identifier: String? = null
|
lateinit var identifier: String
|
||||||
val typeParameters = mutableListOf<FirTypeParameter>()
|
val typeParameters = mutableListOf<FirTypeParameter>()
|
||||||
val valueParametersList = mutableListOf<FirValueParameter>()
|
val valueParametersList = mutableListOf<FirValueParameter>()
|
||||||
var isReturnType = false
|
var isReturnType = false
|
||||||
var receiverType: FirTypeRef? = null
|
var receiverType: FirTypeRef? = null
|
||||||
var returnType: FirTypeRef? = null
|
var returnType: FirTypeRef? = null
|
||||||
val typeConstraints = mutableListOf<Pair<String, FirTypeRef>>()
|
val typeConstraints = mutableListOf<TypeConstraint>()
|
||||||
var firBlock: FirBlock? = null
|
var firBlock: FirBlock? = null
|
||||||
var firExpression: FirExpression? = null
|
var firExpression: FirExpression? = null
|
||||||
functionDeclaration.forEachChildren {
|
functionDeclaration.forEachChildren {
|
||||||
@@ -651,7 +606,7 @@ class Converter(
|
|||||||
} else {
|
} else {
|
||||||
returnType ?: implicitType
|
returnType ?: implicitType
|
||||||
}
|
}
|
||||||
val functionName = Name.identifier(identifier!!)
|
val functionName = Name.identifier(identifier)
|
||||||
val firFunction = FirMemberFunctionImpl(
|
val firFunction = FirMemberFunctionImpl(
|
||||||
session,
|
session,
|
||||||
null,
|
null,
|
||||||
@@ -676,14 +631,7 @@ class Converter(
|
|||||||
firFunction.annotations += modifiers.annotations
|
firFunction.annotations += modifiers.annotations
|
||||||
|
|
||||||
firFunction.typeParameters += typeParameters
|
firFunction.typeParameters += typeParameters
|
||||||
typeConstraints.forEach { (identifier, type) ->
|
firFunction.joinTypeParameters(typeConstraints)
|
||||||
firFunction.typeParameters.forEach { typeParameter ->
|
|
||||||
if (identifier == typeParameter.name.identifier) {
|
|
||||||
(typeParameter as FirTypeParameterImpl).bounds += type
|
|
||||||
typeParameter.annotations += type.annotations
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
firFunction.valueParameters += valueParametersList
|
firFunction.valueParameters += valueParametersList
|
||||||
firFunction.body = visitFunctionBody(firBlock, firExpression)
|
firFunction.body = visitFunctionBody(firBlock, firExpression)
|
||||||
@@ -692,20 +640,17 @@ class Converter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun convertFunctionValueParameters(functionValueParameters: LighterASTNode): List<FirValueParameter> {
|
private fun convertFunctionValueParameters(functionValueParameters: LighterASTNode): List<FirValueParameter> {
|
||||||
val firValueParameters = mutableListOf<FirValueParameter>()
|
return functionValueParameters.forEachChildrenReturnList { node, container ->
|
||||||
functionValueParameters.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
VALUE_PARAMETER -> container += convertFunctionValueParameter(node)
|
||||||
VALUE_PARAMETER -> firValueParameters += convertFunctionValueParameter(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return firValueParameters
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertFunctionValueParameter(functionValueParameter: LighterASTNode): FirValueParameter {
|
private fun convertFunctionValueParameter(functionValueParameter: LighterASTNode): FirValueParameter {
|
||||||
var modifiers = Modifier(session)
|
var modifiers = Modifier(session)
|
||||||
var identifier: String? = null
|
lateinit var identifier: String
|
||||||
var firType: FirTypeRef? = null
|
lateinit var firType: FirTypeRef
|
||||||
var firExpression: FirExpression? = null
|
var firExpression: FirExpression? = null
|
||||||
functionValueParameter.forEachChildren {
|
functionValueParameter.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
@@ -723,8 +668,8 @@ class Converter(
|
|||||||
return FirValueParameterImpl(
|
return FirValueParameterImpl(
|
||||||
session,
|
session,
|
||||||
null,
|
null,
|
||||||
Name.identifier(identifier!!),
|
Name.identifier(identifier),
|
||||||
firType!!,
|
firType,
|
||||||
firExpression,
|
firExpression,
|
||||||
isCrossinline = modifiers.parameterModifier == ParameterModifier.CROSSINLINE,
|
isCrossinline = modifiers.parameterModifier == ParameterModifier.CROSSINLINE,
|
||||||
isNoinline = modifiers.parameterModifier == ParameterModifier.NOINLINE,
|
isNoinline = modifiers.parameterModifier == ParameterModifier.NOINLINE,
|
||||||
@@ -756,7 +701,7 @@ class Converter(
|
|||||||
|
|
||||||
private fun convertSetterParameter(setterParameter: LighterASTNode, propertyTypeRef: FirTypeRef): FirValueParameter {
|
private fun convertSetterParameter(setterParameter: LighterASTNode, propertyTypeRef: FirTypeRef): FirValueParameter {
|
||||||
var modifiers = Modifier(session)
|
var modifiers = Modifier(session)
|
||||||
var firValueParameter: FirValueParameter? = null
|
lateinit var firValueParameter: FirValueParameter
|
||||||
setterParameter.forEachChildren {
|
setterParameter.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
MODIFIER_LIST -> modifiers = convertModifiers(it)
|
MODIFIER_LIST -> modifiers = convertModifiers(it)
|
||||||
@@ -767,8 +712,8 @@ class Converter(
|
|||||||
return FirValueParameterImpl(
|
return FirValueParameterImpl(
|
||||||
session,
|
session,
|
||||||
null,
|
null,
|
||||||
firValueParameter!!.name,
|
firValueParameter.name,
|
||||||
if (firValueParameter!!.returnTypeRef == implicitType) propertyTypeRef else firValueParameter!!.returnTypeRef,
|
if (firValueParameter.returnTypeRef == implicitType) propertyTypeRef else firValueParameter.returnTypeRef,
|
||||||
null,
|
null,
|
||||||
isCrossinline = modifiers.parameterModifier == ParameterModifier.CROSSINLINE,
|
isCrossinline = modifiers.parameterModifier == ParameterModifier.CROSSINLINE,
|
||||||
isNoinline = modifiers.parameterModifier == ParameterModifier.NOINLINE,
|
isNoinline = modifiers.parameterModifier == ParameterModifier.NOINLINE,
|
||||||
@@ -801,14 +746,14 @@ class Converter(
|
|||||||
private fun convertPropertyDeclaration(property: LighterASTNode): FirDeclaration {
|
private fun convertPropertyDeclaration(property: LighterASTNode): FirDeclaration {
|
||||||
//TODO DESTRUCTURING_DECLARATION
|
//TODO DESTRUCTURING_DECLARATION
|
||||||
var modifiers = Modifier(session)
|
var modifiers = Modifier(session)
|
||||||
var identifier: String? = null
|
lateinit var identifier: String
|
||||||
val typeParameters = mutableListOf<FirTypeParameter>()
|
val typeParameters = mutableListOf<FirTypeParameter>()
|
||||||
var isReturnType = false
|
var isReturnType = false
|
||||||
var isDelegate = false
|
var isDelegate = false
|
||||||
var isVar = false
|
var isVar = false
|
||||||
var receiverType: FirTypeRef? = null
|
var receiverType: FirTypeRef? = null
|
||||||
var returnType: FirTypeRef = implicitType
|
var returnType: FirTypeRef = implicitType
|
||||||
val typeConstraints = mutableListOf<Pair<String, FirTypeRef>>()
|
val typeConstraints = mutableListOf<TypeConstraint>()
|
||||||
var getter: FirPropertyAccessor? = null
|
var getter: FirPropertyAccessor? = null
|
||||||
var setter: FirPropertyAccessor? = null
|
var setter: FirPropertyAccessor? = null
|
||||||
var firExpression: FirExpression? = null
|
var firExpression: FirExpression? = null
|
||||||
@@ -835,7 +780,7 @@ class Converter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val propertyName = Name.identifier(identifier!!)
|
val propertyName = Name.identifier(identifier)
|
||||||
|
|
||||||
return if (FunctionUtil.firFunctions.isNotEmpty()) {
|
return if (FunctionUtil.firFunctions.isNotEmpty()) {
|
||||||
FirVariableImpl(
|
FirVariableImpl(
|
||||||
@@ -877,14 +822,7 @@ class Converter(
|
|||||||
} else null
|
} else null
|
||||||
).apply {
|
).apply {
|
||||||
this.typeParameters += typeParameters
|
this.typeParameters += typeParameters
|
||||||
typeConstraints.forEach { (identifier, type) ->
|
this.joinTypeParameters(typeConstraints)
|
||||||
this.typeParameters.forEach { typeParameter ->
|
|
||||||
if (identifier == typeParameter.name.identifier) {
|
|
||||||
(typeParameter as FirTypeParameterImpl).bounds += type
|
|
||||||
typeParameter.annotations += type.annotations
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
annotations += modifiers.annotations
|
annotations += modifiers.annotations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -970,8 +908,8 @@ class Converter(
|
|||||||
|
|
||||||
private fun convertTypeAlias(typeAlias: LighterASTNode): FirDeclaration {
|
private fun convertTypeAlias(typeAlias: LighterASTNode): FirDeclaration {
|
||||||
var modifiers = Modifier(session)
|
var modifiers = Modifier(session)
|
||||||
var identifier: String? = null
|
lateinit var identifier: String
|
||||||
var firType: FirTypeRef? = null
|
lateinit var firType: FirTypeRef
|
||||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
||||||
typeAlias.forEachChildren {
|
typeAlias.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
@@ -982,7 +920,7 @@ class Converter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val typeAliasName = Name.identifier(identifier!!)
|
val typeAliasName = Name.identifier(identifier)
|
||||||
return ClassNameUtil.withChildClassName(typeAliasName) {
|
return ClassNameUtil.withChildClassName(typeAliasName) {
|
||||||
return@withChildClassName FirTypeAliasImpl(
|
return@withChildClassName FirTypeAliasImpl(
|
||||||
session,
|
session,
|
||||||
@@ -992,7 +930,7 @@ class Converter(
|
|||||||
modifiers.visibilityModifier.toVisibility(),
|
modifiers.visibilityModifier.toVisibility(),
|
||||||
modifiers.platformModifier == PlatformModifier.EXPECT,
|
modifiers.platformModifier == PlatformModifier.EXPECT,
|
||||||
modifiers.platformModifier == PlatformModifier.ACTUAL,
|
modifiers.platformModifier == PlatformModifier.ACTUAL,
|
||||||
firType!!
|
firType
|
||||||
).apply {
|
).apply {
|
||||||
annotations += modifiers.annotations
|
annotations += modifiers.annotations
|
||||||
typeParameters += firTypeParameters
|
typeParameters += firTypeParameters
|
||||||
@@ -1001,24 +939,21 @@ class Converter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun convertTypeParameters(typeParameterList: LighterASTNode): List<FirTypeParameter> {
|
private fun convertTypeParameters(typeParameterList: LighterASTNode): List<FirTypeParameter> {
|
||||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
return typeParameterList.forEachChildrenReturnList { node, container ->
|
||||||
typeParameterList.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
TYPE_PARAMETER -> container += convertTypeParameter(node)
|
||||||
TYPE_PARAMETER -> firTypeParameters += convertTypeParameter(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return firTypeParameters
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertTypeParameter(typeParameter: LighterASTNode): FirTypeParameter {
|
private fun convertTypeParameter(typeParameter: LighterASTNode): FirTypeParameter {
|
||||||
var typeParameterModifiers = TypeParameterModifier(session)
|
var typeParameterModifiers = TypeParameterModifier(session)
|
||||||
var parameterName: String? = null
|
lateinit var identifier: String
|
||||||
var type: FirTypeRef? = null
|
var type: FirTypeRef? = null
|
||||||
typeParameter.forEachChildren {
|
typeParameter.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
MODIFIER_LIST -> typeParameterModifiers = convertTypeParameterModifiers(it)
|
MODIFIER_LIST -> typeParameterModifiers = convertTypeParameterModifiers(it)
|
||||||
IDENTIFIER -> parameterName = it.toString()
|
IDENTIFIER -> identifier = it.toString()
|
||||||
TYPE_REFERENCE -> type = convertType(it)
|
TYPE_REFERENCE -> type = convertType(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1027,7 +962,7 @@ class Converter(
|
|||||||
session,
|
session,
|
||||||
null,
|
null,
|
||||||
FirTypeParameterSymbol(),
|
FirTypeParameterSymbol(),
|
||||||
Name.identifier(parameterName!!),
|
identifier.nameAsSafeName(),
|
||||||
typeParameterModifiers.varianceModifier.toVariance(),
|
typeParameterModifiers.varianceModifier.toVariance(),
|
||||||
typeParameterModifiers.reificationModifier != null
|
typeParameterModifiers.reificationModifier != null
|
||||||
)
|
)
|
||||||
@@ -1106,7 +1041,7 @@ class Converter(
|
|||||||
|
|
||||||
private fun convertFunctionType(functionType: LighterASTNode, isNullable: Boolean = false): FirTypeRef {
|
private fun convertFunctionType(functionType: LighterASTNode, isNullable: Boolean = false): FirTypeRef {
|
||||||
var receiverTypeReference: FirTypeRef? = null
|
var receiverTypeReference: FirTypeRef? = null
|
||||||
var returnTypeReference: FirTypeRef? = null
|
lateinit var returnTypeReference: FirTypeRef
|
||||||
val valueParametersList = mutableListOf<FirValueParameter>()
|
val valueParametersList = mutableListOf<FirValueParameter>()
|
||||||
functionType.forEachChildren {
|
functionType.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
@@ -1121,25 +1056,24 @@ class Converter(
|
|||||||
null,
|
null,
|
||||||
isNullable,
|
isNullable,
|
||||||
receiverTypeReference,
|
receiverTypeReference,
|
||||||
returnTypeReference!!
|
returnTypeReference
|
||||||
).apply { valueParameters += valueParametersList }
|
).apply { valueParameters += valueParametersList }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertReceiverType(receiverType: LighterASTNode): FirTypeRef? {
|
private fun convertReceiverType(receiverType: LighterASTNode): FirTypeRef? {
|
||||||
var firTypeRef: FirTypeRef? = null
|
|
||||||
receiverType.forEachChildren {
|
receiverType.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
TYPE_REFERENCE -> firTypeRef = convertType(it)
|
TYPE_REFERENCE -> return convertType(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO specify error
|
//TODO specify error
|
||||||
return firTypeRef ?: throw Exception()
|
throw Exception()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertUserType(userType: LighterASTNode, isNullable: Boolean = false): FirUserTypeRef {
|
private fun convertUserType(userType: LighterASTNode, isNullable: Boolean = false): FirUserTypeRef {
|
||||||
var simpleFirUserType: FirUserTypeRef? = null
|
var simpleFirUserType: FirUserTypeRef? = null
|
||||||
var identifier: String? = null
|
lateinit var identifier: String
|
||||||
val firTypeArguments = mutableListOf<FirTypeProjection>()
|
val firTypeArguments = mutableListOf<FirTypeProjection>()
|
||||||
userType.forEachChildren {
|
userType.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
@@ -1150,7 +1084,7 @@ class Converter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val qualifier = FirQualifierPartImpl(
|
val qualifier = FirQualifierPartImpl(
|
||||||
Name.identifier(identifier!!)
|
Name.identifier(identifier)
|
||||||
).apply { typeArguments += firTypeArguments }
|
).apply { typeArguments += firTypeArguments }
|
||||||
|
|
||||||
return FirUserTypeRefImpl(
|
return FirUserTypeRefImpl(
|
||||||
@@ -1164,64 +1098,56 @@ class Converter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun convertFunctionTypeParameters(functionTypeParameters: LighterASTNode): List<FirValueParameter> {
|
private fun convertFunctionTypeParameters(functionTypeParameters: LighterASTNode): List<FirValueParameter> {
|
||||||
val valueParametersList = mutableListOf<FirValueParameter>()
|
return functionTypeParameters.forEachChildrenReturnList { node, container ->
|
||||||
functionTypeParameters.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
VALUE_PARAMETER -> container += convertParameter(node)
|
||||||
VALUE_PARAMETER -> valueParametersList += convertParameter(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valueParametersList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertTypeConstraints(typeConstraints: LighterASTNode): List<Pair<String, FirTypeRef>> {
|
private fun convertTypeConstraints(typeConstraints: LighterASTNode): List<TypeConstraint> {
|
||||||
val typeConstraintsList = mutableListOf<Pair<String, FirTypeRef>>()
|
return typeConstraints.forEachChildrenReturnList { node, container ->
|
||||||
typeConstraints.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
TYPE_CONSTRAINT -> container += convertTypeConstraint(node)
|
||||||
TYPE_CONSTRAINT -> typeConstraintsList += convertTypeConstraint(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeConstraintsList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertTypeConstraint(typeConstraint: LighterASTNode): Pair<String, FirTypeRef> {
|
private fun convertTypeConstraint(typeConstraint: LighterASTNode): TypeConstraint {
|
||||||
var identifier: String? = null
|
lateinit var identifier: String
|
||||||
var firType: FirTypeRef? = null
|
lateinit var firType: FirTypeRef
|
||||||
|
val annotaions = mutableListOf<FirAnnotationCall>()
|
||||||
typeConstraint.forEachChildren {
|
typeConstraint.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
|
//TODO check annotations
|
||||||
|
ANNOTATION, ANNOTATION_ENTRY -> annotaions += convertAnnotation(it)
|
||||||
REFERENCE_EXPRESSION -> identifier = it.toString()
|
REFERENCE_EXPRESSION -> identifier = it.toString()
|
||||||
TYPE_REFERENCE -> firType = convertType(it)
|
TYPE_REFERENCE -> firType = convertType(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pair(identifier!!, firType!!)
|
return TypeConstraint(annotaions, identifier, firType)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertValueArguments(valueArguments: LighterASTNode): List<FirExpression> {
|
private fun convertValueArguments(valueArguments: LighterASTNode): List<FirExpression> {
|
||||||
val firValueArguments = mutableListOf<FirExpression>()
|
return valueArguments.forEachChildrenReturnList { node, container ->
|
||||||
valueArguments.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
VALUE_ARGUMENT -> container += convertValueArgument(node)
|
||||||
VALUE_ARGUMENT -> firValueArguments += convertValueArgument(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return firValueArguments
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertTypeArguments(typeArguments: LighterASTNode): List<FirTypeProjection> {
|
private fun convertTypeArguments(typeArguments: LighterASTNode): List<FirTypeProjection> {
|
||||||
val firTypeArguments = mutableListOf<FirTypeProjection>()
|
return typeArguments.forEachChildrenReturnList { node, container ->
|
||||||
typeArguments.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
TYPE_PROJECTION -> container += convertTypeProjection(node)
|
||||||
TYPE_PROJECTION -> firTypeArguments += convertTypeProjection(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return firTypeArguments
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertTypeProjection(typeProjection: LighterASTNode): FirTypeProjection {
|
private fun convertTypeProjection(typeProjection: LighterASTNode): FirTypeProjection {
|
||||||
var modifiers = TypeProjectionModifier(session)
|
var modifiers = TypeProjectionModifier(session)
|
||||||
var type: FirTypeRef? = null
|
lateinit var type: FirTypeRef
|
||||||
var isStarProjection = false
|
var isStarProjection = false
|
||||||
typeProjection.forEachChildren {
|
typeProjection.forEachChildren {
|
||||||
when (it.tokenType) {
|
when (it.tokenType) {
|
||||||
@@ -1237,7 +1163,7 @@ class Converter(
|
|||||||
session,
|
session,
|
||||||
null,
|
null,
|
||||||
modifiers.varianceModifier.toVariance(),
|
modifiers.varianceModifier.toVariance(),
|
||||||
type!!
|
type
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1261,6 +1187,20 @@ class Converter(
|
|||||||
private fun convertValueArgument(valueArgument: LighterASTNode): FirExpression {
|
private fun convertValueArgument(valueArgument: LighterASTNode): FirExpression {
|
||||||
return FirErrorExpressionImpl(session, null, "Not implemented")
|
return FirErrorExpressionImpl(session, null, "Not implemented")
|
||||||
//TODO implement
|
//TODO implement
|
||||||
|
|
||||||
|
/*
|
||||||
|
this ?: return FirErrorExpressionImpl(session, this as? KtElement, "No argument given")
|
||||||
|
val expression = this.getArgumentExpression()
|
||||||
|
return when (expression) {
|
||||||
|
is KtConstantExpression, is KtStringTemplateExpression -> {
|
||||||
|
expression.accept(this@Visitor, Unit) as FirExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
{ expression }.toFirExpression("Argument is absent")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertModifiers(modifiers: LighterASTNode): Modifier {
|
private fun convertModifiers(modifiers: LighterASTNode): Modifier {
|
||||||
@@ -1329,15 +1269,12 @@ class Converter(
|
|||||||
|
|
||||||
private fun convertAnnotation(annotationNode: LighterASTNode): List<FirAnnotationCall> {
|
private fun convertAnnotation(annotationNode: LighterASTNode): List<FirAnnotationCall> {
|
||||||
var annotationTarget: AnnotationUseSiteTarget? = null
|
var annotationTarget: AnnotationUseSiteTarget? = null
|
||||||
val annotationList = mutableListOf<FirAnnotationCall>()
|
return annotationNode.forEachChildrenReturnList { node, container ->
|
||||||
annotationNode.forEachChildren {
|
when (node.tokenType) {
|
||||||
when (it.tokenType) {
|
ANNOTATION_TARGET -> annotationTarget = convertAnnotationTarget(node)
|
||||||
ANNOTATION_TARGET -> annotationTarget = convertAnnotationTarget(it)
|
ANNOTATION_ENTRY -> container += convertUnescapedAnnotation(node, annotationTarget)
|
||||||
ANNOTATION_ENTRY -> annotationList += convertUnescapedAnnotation(it, annotationTarget)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return annotationList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertAnnotationTarget(annotationUseSiteTarget: LighterASTNode): AnnotationUseSiteTarget {
|
private fun convertAnnotationTarget(annotationUseSiteTarget: LighterASTNode): AnnotationUseSiteTarget {
|
||||||
|
|||||||
@@ -6,25 +6,23 @@
|
|||||||
package org.jetbrains.kotlin.fir.lightTree
|
package org.jetbrains.kotlin.fir.lightTree
|
||||||
|
|
||||||
import com.intellij.lang.LighterASTNode
|
import com.intellij.lang.LighterASTNode
|
||||||
import com.intellij.openapi.util.Ref
|
|
||||||
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
|
||||||
import org.jetbrains.kotlin.KtNodeTypes
|
import org.jetbrains.kotlin.KtNodeTypes
|
||||||
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.fir.FirFunctionTarget
|
import org.jetbrains.kotlin.fir.FirFunctionTarget
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.*
|
import org.jetbrains.kotlin.fir.declarations.impl.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirReturnExpression
|
import org.jetbrains.kotlin.fir.expressions.FirReturnExpression
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractCall
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirDelegatedConstructorCallImpl
|
import org.jetbrains.kotlin.fir.expressions.impl.FirDelegatedConstructorCallImpl
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub
|
import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirReturnExpressionImpl
|
import org.jetbrains.kotlin.fir.expressions.impl.FirReturnExpressionImpl
|
||||||
import org.jetbrains.kotlin.fir.lightTree.fir.ValueParameter
|
import org.jetbrains.kotlin.fir.lightTree.fir.TypeConstraint
|
||||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.MemberModifier
|
|
||||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier
|
|
||||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.PlatformModifier
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
|
import org.jetbrains.kotlin.fir.types.impl.FirImplicitAnyTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl
|
import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirUserTypeRefImpl
|
import org.jetbrains.kotlin.fir.types.impl.FirUserTypeRefImpl
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
@@ -50,12 +48,9 @@ object ConverterUtil {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun LighterASTNode?.hasSecondaryConstructor(tree: FlyweightCapableTreeStructure<LighterASTNode>): Boolean {
|
fun LighterASTNode?.hasSecondaryConstructor(kidsArray: Array<LighterASTNode?>): Boolean {
|
||||||
if (this == null) return false
|
if (this == null) return false
|
||||||
//TODO check if node isn't CLASS_BODY
|
//TODO check if node isn't CLASS_BODY
|
||||||
val kidsRef = Ref<Array<LighterASTNode?>>()
|
|
||||||
tree.getChildren(this, kidsRef)
|
|
||||||
val kidsArray = kidsRef.get()
|
|
||||||
|
|
||||||
for (kid in kidsArray) {
|
for (kid in kidsArray) {
|
||||||
if (kid == null) continue
|
if (kid == null) continue
|
||||||
@@ -66,33 +61,6 @@ object ConverterUtil {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ValueParameter.toFirProperty(): FirProperty {
|
|
||||||
val modifier = this.modifier
|
|
||||||
val name = this.firValueParameter.name
|
|
||||||
val type = this.firValueParameter.returnTypeRef
|
|
||||||
|
|
||||||
return FirMemberPropertyImpl(
|
|
||||||
this.firValueParameter.session,
|
|
||||||
null,
|
|
||||||
FirPropertySymbol(ClassNameUtil.callableIdForName(name)),
|
|
||||||
name,
|
|
||||||
modifier.visibilityModifier.toVisibility(),
|
|
||||||
modifier.inheritanceModifier?.toModality(),
|
|
||||||
modifier.platformModifier == PlatformModifier.EXPECT,
|
|
||||||
modifier.platformModifier == PlatformModifier.ACTUAL,
|
|
||||||
isOverride = modifier.memberModifier == MemberModifier.OVERRIDE,
|
|
||||||
isConst = false,
|
|
||||||
isLateInit = false,
|
|
||||||
receiverTypeRef = null,
|
|
||||||
returnTypeRef = type,
|
|
||||||
isVar = this.isVar,
|
|
||||||
initializer = null,
|
|
||||||
getter = FirDefaultPropertyGetter(this.firValueParameter.session, null, type, modifier.visibilityModifier.toVisibility()),
|
|
||||||
setter = FirDefaultPropertySetter(this.firValueParameter.session, null, type, modifier.visibilityModifier.toVisibility()),
|
|
||||||
delegate = null
|
|
||||||
).apply { annotations += this@toFirProperty.firValueParameter.annotations }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FirExpression.toReturn(labelName: String? = null): FirReturnExpression {
|
fun FirExpression.toReturn(labelName: String? = null): FirReturnExpression {
|
||||||
return FirReturnExpressionImpl(
|
return FirReturnExpressionImpl(
|
||||||
session,
|
session,
|
||||||
@@ -129,8 +97,83 @@ object ConverterUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirValueParameter.toFirExpression(session: FirSession, stubMode: Boolean): FirExpression {
|
fun FirTypeParameterContainer.joinTypeParameters(typeConstraints: List<TypeConstraint>) {
|
||||||
return if (stubMode) FirExpressionStub(session, null)
|
typeConstraints.forEach { (identifier, type) ->
|
||||||
|
this.typeParameters.forEach { typeParameter ->
|
||||||
|
if (identifier == typeParameter.name.identifier) {
|
||||||
|
(typeParameter as FirTypeParameterImpl).bounds += type
|
||||||
|
typeParameter.annotations += type.annotations
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : FirAbstractCall> T.extractArgumentsFrom(container: List<FirExpression>, stubMode: Boolean): T {
|
||||||
|
if (!stubMode) {
|
||||||
|
//TODO("not implemented")
|
||||||
|
this.arguments += container
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun List<FirEnumEntryImpl>.fillEnumEntryConstructor(
|
||||||
|
firPrimaryConstructor: FirConstructor,
|
||||||
|
stubMode: Boolean
|
||||||
|
) {
|
||||||
|
this.forEach { firEnumEntry ->
|
||||||
|
val enumDelegatedSelfTypeRef = firPrimaryConstructor.returnTypeRef
|
||||||
|
var enumDelegatedSuperTypeRef: FirTypeRef = FirImplicitAnyTypeRef(firEnumEntry.session, null)
|
||||||
|
val enumSuperTypeCallEntry = mutableListOf<FirExpression>()
|
||||||
|
|
||||||
|
if (firPrimaryConstructor.valueParameters.isNotEmpty()) {
|
||||||
|
enumDelegatedSuperTypeRef = enumDelegatedSelfTypeRef
|
||||||
|
firEnumEntry.superTypeRefs += enumDelegatedSuperTypeRef
|
||||||
|
enumSuperTypeCallEntry += firPrimaryConstructor.valueParameters.map { firValueParameter ->
|
||||||
|
firValueParameter.toFirExpression(stubMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val firDelegatedConstructorCall = FirDelegatedConstructorCallImpl(
|
||||||
|
firEnumEntry.session,
|
||||||
|
null,
|
||||||
|
enumDelegatedSuperTypeRef,
|
||||||
|
false
|
||||||
|
).extractArgumentsFrom(enumSuperTypeCallEntry, stubMode)
|
||||||
|
|
||||||
|
val firEnumPrimaryConstructor = FirPrimaryConstructorImpl(
|
||||||
|
firEnumEntry.session,
|
||||||
|
null,
|
||||||
|
FirFunctionSymbol(ClassNameUtil.callableIdForClassConstructor()),
|
||||||
|
Visibilities.UNKNOWN,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
enumDelegatedSelfTypeRef,
|
||||||
|
firDelegatedConstructorCall
|
||||||
|
)
|
||||||
|
firEnumEntry.declarations.add(0, firEnumPrimaryConstructor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun List<FirDeclaration>.fillConstructors(
|
||||||
|
hasPrimaryConstructor: Boolean,
|
||||||
|
delegatedSelfTypeRef: FirTypeRef,
|
||||||
|
delegatedSuperTypeRef: FirTypeRef
|
||||||
|
) {
|
||||||
|
this.forEach { constructor ->
|
||||||
|
(constructor as FirConstructorImpl).returnTypeRef = delegatedSelfTypeRef
|
||||||
|
val constructorDelegationCall = constructor.delegatedConstructor as? FirDelegatedConstructorCallImpl
|
||||||
|
val isThis =
|
||||||
|
(constructorDelegationCall == null && hasPrimaryConstructor) || constructorDelegationCall?.isThis == true
|
||||||
|
val delegatedType = when {
|
||||||
|
isThis -> delegatedSelfTypeRef
|
||||||
|
else -> delegatedSuperTypeRef
|
||||||
|
}
|
||||||
|
constructorDelegationCall?.constructedTypeRef = delegatedType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun FirValueParameter.toFirExpression(stubMode: Boolean): FirExpression {
|
||||||
|
return if (stubMode) FirExpressionStub(this.session, null)
|
||||||
else TODO("not implemeted")
|
else TODO("not implemeted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. 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.lightTree.fir
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
|
|
||||||
|
class TypeConstraint(val annotations: List<FirAnnotationCall>, val identifier: String, val firTypeRef: FirTypeRef) {
|
||||||
|
operator fun component1(): String {
|
||||||
|
return identifier
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun component2(): FirTypeRef {
|
||||||
|
return firTypeRef
|
||||||
|
}
|
||||||
|
}
|
||||||
+44
-1
@@ -5,7 +5,50 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.lightTree.fir
|
package org.jetbrains.kotlin.fir.lightTree.fir
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.impl.FirMemberPropertyImpl
|
||||||
|
import org.jetbrains.kotlin.fir.lightTree.ClassNameUtil
|
||||||
|
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.MemberModifier
|
||||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier
|
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier
|
||||||
|
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.PlatformModifier
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
|
|
||||||
class ValueParameter(val isVal: Boolean, val isVar: Boolean, val modifier: Modifier, val firValueParameter: FirValueParameter)
|
class ValueParameter(
|
||||||
|
val isVal: Boolean,
|
||||||
|
val isVar: Boolean,
|
||||||
|
val modifier: Modifier,
|
||||||
|
val firValueParameter: FirValueParameter
|
||||||
|
) {
|
||||||
|
fun isValOrVar(): Boolean {
|
||||||
|
return isVal || isVar
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toFirProperty(): FirProperty {
|
||||||
|
val name = this.firValueParameter.name
|
||||||
|
val type = this.firValueParameter.returnTypeRef
|
||||||
|
|
||||||
|
return FirMemberPropertyImpl(
|
||||||
|
this.firValueParameter.session,
|
||||||
|
null,
|
||||||
|
FirPropertySymbol(ClassNameUtil.callableIdForName(name)),
|
||||||
|
name,
|
||||||
|
modifier.visibilityModifier.toVisibility(),
|
||||||
|
modifier.inheritanceModifier?.toModality(),
|
||||||
|
modifier.platformModifier == PlatformModifier.EXPECT,
|
||||||
|
modifier.platformModifier == PlatformModifier.ACTUAL,
|
||||||
|
isOverride = modifier.memberModifier == MemberModifier.OVERRIDE,
|
||||||
|
isConst = false,
|
||||||
|
isLateInit = false,
|
||||||
|
receiverTypeRef = null,
|
||||||
|
returnTypeRef = type,
|
||||||
|
isVar = this.isVar,
|
||||||
|
initializer = null,
|
||||||
|
getter = FirDefaultPropertyGetter(this.firValueParameter.session, null, type, modifier.visibilityModifier.toVisibility()),
|
||||||
|
setter = FirDefaultPropertySetter(this.firValueParameter.session, null, type, modifier.visibilityModifier.toVisibility()),
|
||||||
|
delegate = null
|
||||||
|
).apply { annotations += this@ValueParameter.firValueParameter.annotations }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user