New J2K: Split conversions to Java --> Kotlin conversions and Kotlin --> Kotlin conversions

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