New J2K: Split conversions to Java --> Kotlin conversions and Kotlin --> Kotlin conversions
This commit is contained in:
committed by
Ilya Kirillov
parent
67c6192425
commit
28aeaa040e
@@ -23,6 +23,7 @@ object ConversionsRunner {
|
|||||||
|
|
||||||
private fun createRootConversion(context: ConversionContext) =
|
private fun createRootConversion(context: ConversionContext) =
|
||||||
batchPipe {
|
batchPipe {
|
||||||
|
//Java --> Kotlin conversions
|
||||||
+JavaModifiersConversion()
|
+JavaModifiersConversion()
|
||||||
+InternalClassConversion(context)
|
+InternalClassConversion(context)
|
||||||
+ModalityConversion(context)
|
+ModalityConversion(context)
|
||||||
@@ -49,14 +50,16 @@ object ConversionsRunner {
|
|||||||
+MainFunctionConversion(context)
|
+MainFunctionConversion(context)
|
||||||
+LiteralConversion()
|
+LiteralConversion()
|
||||||
+AssertStatementConversion(context)
|
+AssertStatementConversion(context)
|
||||||
+InnerClassConversion()
|
|
||||||
+StaticsToCompanionExtractConversion()
|
|
||||||
+ClassToObjectPromotionConversion(context)
|
|
||||||
+PolyadicExpressionConversion()
|
+PolyadicExpressionConversion()
|
||||||
+SwitchStatementConversion(context)
|
+SwitchStatementConversion(context)
|
||||||
+InstanceOfConversion()
|
+InstanceOfConversion()
|
||||||
+ForConversion(context)
|
+ForConversion(context)
|
||||||
+ForInConversion()
|
+ForInConversion()
|
||||||
|
|
||||||
|
//Kotlin --> Kotlin conversions
|
||||||
|
+InnerClassConversion()
|
||||||
|
+StaticsToCompanionExtractConversion()
|
||||||
|
+ClassToObjectPromotionConversion(context)
|
||||||
+LabeledStatementConversion()
|
+LabeledStatementConversion()
|
||||||
+SortClassMembersConversion()
|
+SortClassMembersConversion()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,15 +15,14 @@ import org.jetbrains.kotlin.util.collectionUtils.concatInOrder
|
|||||||
//TODO temporary
|
//TODO temporary
|
||||||
class MainFunctionConversion(private val context: ConversionContext) : RecursiveApplicableConversionBase() {
|
class MainFunctionConversion(private val context: ConversionContext) : RecursiveApplicableConversionBase() {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKKtFunction) return recurse(element)
|
if (element !is JKMethod) return recurse(element)
|
||||||
if (element.isMainFunctionDeclaration()) {
|
if (element.isMainFunctionDeclaration()) {
|
||||||
element.parameters.single().apply {
|
element.parameters.single().apply {
|
||||||
val oldType = type.type as JKClassType
|
val oldType = type.type as JKJavaArrayType
|
||||||
val oldTypeParameter = oldType.parameters.single() as JKClassType
|
val oldTypeParameter = oldType.type as JKClassType
|
||||||
val newType =
|
val newType =
|
||||||
JKClassTypeImpl(
|
JKJavaArrayTypeImpl(
|
||||||
oldType.classReference,
|
oldTypeParameter.updateNullability(Nullability.NotNull),
|
||||||
listOf(oldTypeParameter.updateNullability(Nullability.NotNull)),
|
|
||||||
Nullability.NotNull
|
Nullability.NotNull
|
||||||
)
|
)
|
||||||
type = JKTypeElementImpl(newType)
|
type = JKTypeElementImpl(newType)
|
||||||
@@ -37,11 +36,9 @@ class MainFunctionConversion(private val context: ConversionContext) : Recursive
|
|||||||
return recurse(element)
|
return recurse(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun JKKtFunction.isMainFunctionDeclaration(): Boolean {
|
private fun JKMethod.isMainFunctionDeclaration(): Boolean {
|
||||||
val type = parameters.singleOrNull()?.type?.type as? JKClassType ?: return false
|
val type = parameters.singleOrNull()?.type?.type as? JKJavaArrayType ?: return false
|
||||||
val typeArgument = type.parameters.singleOrNull() as? JKClassType ?: return false
|
val typeArgument = type.type as? JKClassType ?: return false
|
||||||
return name.value == "main" &&
|
return name.value == "main" && typeArgument.classReference.name == "String"
|
||||||
type.classReference.name == "Array" &&
|
|
||||||
typeArgument.classReference.name == "String"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user