Use kotlin.math instead of java.lang.Math
Recipe ID
org.openrewrite.kotlin.migrate.UseKotlinMath$KtRecipeArtifactio.moderne.recipe:recipes-kotlinReplaces JVM-only java.lang.Math calls with their multiplatform kotlin.math equivalents — top-level functions (abs, sqrt, sin, …), constants (PI, E), and receiver-style extensions on Double/Int/Long (pow, roundToInt, floorDiv, mod, …).
Composite recipeProprietary
Add to your build
Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.kotlin.migrate.UseKotlinMath$KtRecipe")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("io.moderne.recipe:recipes-kotlin:0.5.0")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.kotlin.migrate.UseKotlinMath$KtRecipeIf the recipe isn’t available locally, install it with:
mod config recipes jar install io.moderne.recipe:recipes-kotlin:RELEASEDefinition
This recipe runs the following recipes in order.
- Use
kotlin.math.absinstead ofjava.lang.Math.absorg.openrewrite.kotlin.migrate.UseKotlinMathAbs$KtRecipe - Use
kotlin.math.sqrtinstead ofjava.lang.Math.sqrtorg.openrewrite.kotlin.migrate.UseKotlinMathSqrt$KtRecipe - Use
kotlin.math.floorinstead ofjava.lang.Math.floororg.openrewrite.kotlin.migrate.UseKotlinMathFloor$KtRecipe - Use
kotlin.math.ceilinstead ofjava.lang.Math.ceilorg.openrewrite.kotlin.migrate.UseKotlinMathCeil$KtRecipe - Use
kotlin.math.mininstead ofjava.lang.Math.minorg.openrewrite.kotlin.migrate.UseKotlinMathMin$KtRecipe - Use
kotlin.math.maxinstead ofjava.lang.Math.maxorg.openrewrite.kotlin.migrate.UseKotlinMathMax$KtRecipe - Use
kotlin.math.expinstead ofjava.lang.Math.exporg.openrewrite.kotlin.migrate.UseKotlinMathExp$KtRecipe - Use
kotlin.math.lninstead ofjava.lang.Math.logorg.openrewrite.kotlin.migrate.UseKotlinMathLn$KtRecipe - Use
kotlin.math.log10instead ofjava.lang.Math.log10org.openrewrite.kotlin.migrate.UseKotlinMathLog10$KtRecipe - Use
kotlin.math.sininstead ofjava.lang.Math.sinorg.openrewrite.kotlin.migrate.UseKotlinMathSin$KtRecipe - Use
kotlin.math.cosinstead ofjava.lang.Math.cosorg.openrewrite.kotlin.migrate.UseKotlinMathCos$KtRecipe - Use
kotlin.math.taninstead ofjava.lang.Math.tanorg.openrewrite.kotlin.migrate.UseKotlinMathTan$KtRecipe - Use
kotlin.math.asininstead ofjava.lang.Math.asinorg.openrewrite.kotlin.migrate.UseKotlinMathAsin$KtRecipe - Use
kotlin.math.acosinstead ofjava.lang.Math.acosorg.openrewrite.kotlin.migrate.UseKotlinMathAcos$KtRecipe - Use
kotlin.math.ataninstead ofjava.lang.Math.atanorg.openrewrite.kotlin.migrate.UseKotlinMathAtan$KtRecipe - Use
kotlin.math.atan2instead ofjava.lang.Math.atan2org.openrewrite.kotlin.migrate.UseKotlinMathAtan2$KtRecipe - Use
kotlin.math.sinhinstead ofjava.lang.Math.sinhorg.openrewrite.kotlin.migrate.UseKotlinMathSinh$KtRecipe - Use
kotlin.math.coshinstead ofjava.lang.Math.coshorg.openrewrite.kotlin.migrate.UseKotlinMathCosh$KtRecipe - Use
kotlin.math.tanhinstead ofjava.lang.Math.tanhorg.openrewrite.kotlin.migrate.UseKotlinMathTanh$KtRecipe - Use
kotlin.math.cbrtinstead ofjava.lang.Math.cbrtorg.openrewrite.kotlin.migrate.UseKotlinMathCbrt$KtRecipe - Use
kotlin.math.hypotinstead ofjava.lang.Math.hypotorg.openrewrite.kotlin.migrate.UseKotlinMathHypot$KtRecipe - Use
kotlin.math.expm1instead ofjava.lang.Math.expm1org.openrewrite.kotlin.migrate.UseKotlinMathExpm1$KtRecipe - Use
kotlin.math.ln1pinstead ofjava.lang.Math.log1porg.openrewrite.kotlin.migrate.UseKotlinMathLn1p$KtRecipe - Use
kotlin.math.signinstead ofjava.lang.Math.signumorg.openrewrite.kotlin.migrate.UseKotlinMathSign$KtRecipe - Use
kotlin.math.PIinstead ofjava.lang.Math.PIorg.openrewrite.kotlin.migrate.UseKotlinMathPi$KtRecipe - Use
kotlin.math.Einstead ofjava.lang.Math.Eorg.openrewrite.kotlin.migrate.UseKotlinMathE$KtRecipe - Use
Double.powinstead ofjava.lang.Math.poworg.openrewrite.kotlin.migrate.UseDoublePow$KtRecipe - Use
Double.roundToLong()instead ofjava.lang.Math.roundorg.openrewrite.kotlin.migrate.UseDoubleRoundToLong$KtRecipe - Use
Float.roundToInt()instead ofjava.lang.Math.roundorg.openrewrite.kotlin.migrate.UseFloatRoundToInt$KtRecipe - Use
Double.withSigninstead ofjava.lang.Math.copySignorg.openrewrite.kotlin.migrate.UseDoubleWithSign$KtRecipe - Use
Double.IEEEreminstead ofjava.lang.Math.IEEEremainderorg.openrewrite.kotlin.migrate.UseDoubleIEEErem$KtRecipe - Use
Double.nextUp()instead ofjava.lang.Math.nextUporg.openrewrite.kotlin.migrate.UseDoubleNextUp$KtRecipe - Use
Double.nextDown()instead ofjava.lang.Math.nextDownorg.openrewrite.kotlin.migrate.UseDoubleNextDown$KtRecipe - Use
Double.nextTowards()instead ofjava.lang.Math.nextAfterorg.openrewrite.kotlin.migrate.UseDoubleNextTowards$KtRecipe - Use
Int.floorDivinstead ofjava.lang.Math.floorDivorg.openrewrite.kotlin.migrate.UseIntFloorDiv$KtRecipe - Use
Long.floorDivinstead ofjava.lang.Math.floorDivorg.openrewrite.kotlin.migrate.UseLongFloorDiv$KtRecipe - Use
Int.mod()instead ofjava.lang.Math.floorModorg.openrewrite.kotlin.migrate.UseIntMod$KtRecipe - Use
Long.mod()instead ofjava.lang.Math.floorModorg.openrewrite.kotlin.migrate.UseLongMod$KtRecipe - Use
Long.mod(Int)instead ofjava.lang.Math.floorModorg.openrewrite.kotlin.migrate.UseLongModInt$KtRecipe
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats