Migrate compiler, idea and others to new case conversion api

This commit is contained in:
Abduqodiri Qurbonzoda
2021-04-08 02:28:57 +03:00
parent aa543c6631
commit 40d1849f33
138 changed files with 239 additions and 224 deletions
@@ -106,7 +106,7 @@ object ConversionsRunner {
private fun Conversion.description(): String {
val conversionName = this::class.simpleName
val words = conversionName?.let { wordRegex.findAll(conversionName).map { it.value.decapitalize(Locale.US) }.toList() }
val words = conversionName?.let { wordRegex.findAll(conversionName).map { it.value.replaceFirstChar(Char::lowercaseChar) }.toList() }
return when {
conversionName == null -> "Converting..."
conversionName.endsWith("Conversion") -> "Converting ${words!!.dropLast(1).joinToString(" ")}"
@@ -43,11 +43,11 @@ class BoxedTypeOperationsConversion(context: NewJ2kConverterContext) : Recursive
val shouldConvertToIntFirst =
primitiveTypeName in floatingPointPrimitiveTypeNames && operationType in typeNameOfIntegersLesserThanInt
val conversionType = if (shouldConvertToIntFirst) "Int" else operationType.capitalize(Locale.US)
val conversionType = if (shouldConvertToIntFirst) "Int" else operationType.replaceFirstChar(Char::uppercaseChar)
return JKCallExpressionImpl(
symbolProvider.provideMethodSymbol(
"kotlin.${primitiveTypeName.capitalize(Locale.US)}.to$conversionType"
"kotlin.${primitiveTypeName.replaceFirstChar(Char::uppercaseChar)}}.to$conversionType"
),
JKArgumentList()
).withFormattingFrom(methodCallExpression)
@@ -32,7 +32,7 @@ class LiteralConversion(context: NewJ2kConverterContext) : RecursiveApplicableCo
}
private fun cannotConvertLiteralMessage(element: JKLiteralExpression): String {
val literalType = element.type.toString().toLowerCase()
val literalType = element.type.toString().lowercase()
val literalValue = element.literal
return "Could not convert $literalType literal '$literalValue' to Kotlin"
}
@@ -116,7 +116,7 @@ class LiteralConversion(context: NewJ2kConverterContext) : RecursiveApplicableCo
}
private fun String.convertOctalLiteral(isLongLiteral: Boolean): String {
if (!startsWith("0") || length == 1 || get(1).toLowerCase() == 'x') return this
if (!startsWith("0") || length == 1 || get(1).lowercaseChar() == 'x') return this
val value = BigInteger(drop(1), 8)
return if (isLongLiteral) value.toLong().toString(10) else value.toInt().toString(10)
}