-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3948905
commit eaa5c29
Showing
11 changed files
with
151 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
plugin/src/main/kotlin/org/jetbrains/hackathon2024/dsl/dslBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.jetbrains.hackathon2024.dsl | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.provider.Property | ||
import org.jetbrains.hackathon2024.ArgumentType | ||
import org.jetbrains.hackathon2024.KapiFenceClassDsl | ||
import org.jetbrains.hackathon2024.KapiFenceRootDsl | ||
|
||
internal class KapiFenceRootBuilder(project: Project) : KapiFenceRootDsl { | ||
internal val records: List<String> | ||
get() = records_ | ||
private val records_: MutableList<String> = mutableListOf() | ||
|
||
override val deprecationMessage: Property<String> = project.objects.property(String::class.java) | ||
|
||
override fun deprecateClass( | ||
name: String, | ||
body: (KapiFenceClassDsl.() -> Unit)?, | ||
) { | ||
records_.add("class $name") | ||
if (body != null) { | ||
deprecateMembers(name, body) | ||
} | ||
} | ||
|
||
override fun deprecateMembers( | ||
name: String, | ||
body: KapiFenceClassDsl.() -> Unit, | ||
) { | ||
val funBuilder = StringBuilder() | ||
funBuilder.appendLine("class $name {") | ||
val propBuilder = StringBuilder() | ||
propBuilder.appendLine("class $name {") | ||
KapiFenceClassBuilder(funBuilder, propBuilder).body() | ||
funBuilder.appendLine("}") | ||
propBuilder.appendLine("}") | ||
records_.add(funBuilder.toString()) | ||
records_.add(propBuilder.toString()) | ||
} | ||
} | ||
|
||
internal class KapiFenceClassBuilder(private val funBuilder: StringBuilder, private val propBuilder: StringBuilder) : KapiFenceClassDsl { | ||
override fun deprecateConstructor(vararg argumentType: ArgumentType) { | ||
deprecateFun("<init>", *argumentType) | ||
} | ||
|
||
override fun deprecateFun( | ||
name: String, | ||
vararg argumentType: ArgumentType, | ||
) { | ||
funBuilder.appendLine("*** $name(${argumentType.joinToString(", ") { it.type }});") | ||
} | ||
|
||
override fun deprecateProperty(name: String) { | ||
propBuilder.appendLine("private *** $name;") | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
plugin/src/main/kotlin/org/jetbrains/hackathon2024/kapiFenceDsl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.jetbrains.hackathon2024 | ||
|
||
import org.gradle.api.provider.Property | ||
|
||
@DslMarker | ||
annotation class KapiFenceDsl | ||
|
||
@KapiFenceDsl | ||
sealed class ArgumentType(val type: kotlin.String) { | ||
|
||
object Byte : ArgumentType("byte") | ||
object NullableByte : ArgumentType("java.lang.Byte") | ||
object Short : ArgumentType("short") | ||
object NullableShort : ArgumentType("java.lang.Short") | ||
object Int : ArgumentType("int") | ||
object NullableInt : ArgumentType("java.lang.Integer") | ||
object Long : ArgumentType("long") | ||
object NullableLong : ArgumentType("java.lang.Long") | ||
object Float : ArgumentType("float") | ||
object NullableFloat : ArgumentType("java.lang.Float") | ||
object Double : ArgumentType("double") | ||
object NullableDouble : ArgumentType("java.lang.Double") | ||
object Char : ArgumentType("char") | ||
object NullableChar : ArgumentType("java.lang.Character") | ||
object Boolean : ArgumentType("boolean") | ||
object NullableBoolean : ArgumentType("java.lang.Boolean") | ||
object String : ArgumentType("java.lang.String") | ||
object Wildcard : ArgumentType("***") | ||
class Class(name: kotlin.String) : ArgumentType(name) | ||
} | ||
|
||
@KapiFenceDsl | ||
interface KapiFenceRootDsl { | ||
val deprecationMessage: Property<String> | ||
fun deprecateClass(name: String, body: (KapiFenceClassDsl.() -> Unit)? = null) | ||
fun deprecateMembers(name: String, body: KapiFenceClassDsl.() -> Unit) | ||
} | ||
|
||
const val KAPI_FENCE_WILDCARD_NAME = "*" | ||
|
||
@KapiFenceDsl | ||
interface KapiFenceClassDsl { | ||
fun deprecateConstructor(vararg argumentType: ArgumentType) | ||
fun deprecateFun(name: String, vararg argumentType: ArgumentType) | ||
fun deprecateProperty(name: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters