Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions rewrite-kotlin/src/main/kotlin/org/openrewrite/RecipeDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,56 @@ public open class EditScope internal constructor() : LanguageHost() {
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, R> rewrite(first: (P1, P2) -> R, vararg rest: (P1, P2) -> R): RewriteAdvice2<P1, P2, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, R> rewrite(before: (P1, P2, P3) -> R): RewriteAdvice3<P1, P2, P3, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, R> rewrite(first: (P1, P2, P3) -> R, vararg rest: (P1, P2, P3) -> R): RewriteAdvice3<P1, P2, P3, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, R> rewrite(before: (P1, P2, P3, P4) -> R): RewriteAdvice4<P1, P2, P3, P4, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, R> rewrite(first: (P1, P2, P3, P4) -> R, vararg rest: (P1, P2, P3, P4) -> R): RewriteAdvice4<P1, P2, P3, P4, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, R> rewrite(before: (P1, P2, P3, P4, P5) -> R): RewriteAdvice5<P1, P2, P3, P4, P5, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, R> rewrite(first: (P1, P2, P3, P4, P5) -> R, vararg rest: (P1, P2, P3, P4, P5) -> R): RewriteAdvice5<P1, P2, P3, P4, P5, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, R> rewrite(before: (P1, P2, P3, P4, P5, P6) -> R): RewriteAdvice6<P1, P2, P3, P4, P5, P6, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, R> rewrite(first: (P1, P2, P3, P4, P5, P6) -> R, vararg rest: (P1, P2, P3, P4, P5, P6) -> R): RewriteAdvice6<P1, P2, P3, P4, P5, P6, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, R> rewrite(before: (P1, P2, P3, P4, P5, P6, P7) -> R): RewriteAdvice7<P1, P2, P3, P4, P5, P6, P7, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, R> rewrite(first: (P1, P2, P3, P4, P5, P6, P7) -> R, vararg rest: (P1, P2, P3, P4, P5, P6, P7) -> R): RewriteAdvice7<P1, P2, P3, P4, P5, P6, P7, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, R> rewrite(before: (P1, P2, P3, P4, P5, P6, P7, P8) -> R): RewriteAdvice8<P1, P2, P3, P4, P5, P6, P7, P8, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, R> rewrite(first: (P1, P2, P3, P4, P5, P6, P7, P8) -> R, vararg rest: (P1, P2, P3, P4, P5, P6, P7, P8) -> R): RewriteAdvice8<P1, P2, P3, P4, P5, P6, P7, P8, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, R> rewrite(before: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R): RewriteAdvice9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, R> rewrite(first: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R, vararg rest: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R): RewriteAdvice9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R> rewrite(before: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R): RewriteAdvice10<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R> rewrite(first: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R, vararg rest: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R): RewriteAdvice10<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, R> rewrite(before: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R): RewriteAdvice11<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, R> rewrite(first: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R, vararg rest: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R): RewriteAdvice11<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, R> = pluginRequired()

@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, R> rewrite(before: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R): RewriteAdvice12<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, R> = pluginRequired()
@Suppress("UNUSED_PARAMETER")
public fun <P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, R> rewrite(first: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R, vararg rest: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R): RewriteAdvice12<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, R> = pluginRequired()

private fun <T> pluginRequired(): T = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin. " +
"Add rewrite-kotlin to `kotlinCompilerPluginClasspath` (plugin id `org.openrewrite.kotlin.recipe`)."
Expand Down Expand Up @@ -548,6 +598,76 @@ public open class GenerateScope internal constructor(public val ctx: ExecutionCo
)
}

@RecipeDsl public class RewriteAdvice3<P1, P2, P3, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

@RecipeDsl public class RewriteAdvice4<P1, P2, P3, P4, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3, P4) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

@RecipeDsl public class RewriteAdvice5<P1, P2, P3, P4, P5, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3, P4, P5) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

@RecipeDsl public class RewriteAdvice6<P1, P2, P3, P4, P5, P6, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3, P4, P5, P6) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

@RecipeDsl public class RewriteAdvice7<P1, P2, P3, P4, P5, P6, P7, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3, P4, P5, P6, P7) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

@RecipeDsl public class RewriteAdvice8<P1, P2, P3, P4, P5, P6, P7, P8, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3, P4, P5, P6, P7, P8) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

@RecipeDsl public class RewriteAdvice9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

@RecipeDsl public class RewriteAdvice10<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

@RecipeDsl public class RewriteAdvice11<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

@RecipeDsl public class RewriteAdvice12<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, R> internal constructor() {
@Suppress("UNUSED_PARAMETER")
public infix fun <R2> to(after: (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) -> R2): Unit = error(
"Recipe DSL: `rewrite { } to { }` requires the rewrite-kotlin K2 compiler plugin.",
)
}

// ---------------------------------------------------------------------------
// Runtime support for the K2 plugin's imperative-recipe synthesis.
// ---------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ internal class RecipeIrGenerationExtension : IrGenerationExtension {
val RECIPE_FQN: FqName = FqName("org.openrewrite.recipe")
val RECIPES_FQN: FqName = FqName("org.openrewrite.recipes")

const val REWRITE_ADVICE_0_TO = "org.openrewrite.RewriteAdvice0.to"
const val REWRITE_ADVICE_1_TO = "org.openrewrite.RewriteAdvice1.to"
const val REWRITE_ADVICE_2_TO = "org.openrewrite.RewriteAdvice2.to"

val REWRITE_ADVICE_TO_FQNS = setOf(REWRITE_ADVICE_0_TO, REWRITE_ADVICE_1_TO, REWRITE_ADVICE_2_TO)
val REWRITE_ADVICE_TO_FQNS: Set<String> = (0..12).map { "org.openrewrite.RewriteAdvice$it.to" }.toSet()

const val EDIT_SCOPE_REWRITE_FQN = "org.openrewrite.EditScope.rewrite"
const val RECIPE_BUILDER_EDIT_FQN = "org.openrewrite.RecipeBuilder.edit"
Expand Down