-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from kitakkun/feature/move_value_containers_i…
…nside_compiler Remove Gradle DSL for ValueContainer and embed it directly into the compiler
- Loading branch information
Showing
14 changed files
with
184 additions
and
328 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
14 changes: 0 additions & 14 deletions
14
...on/src/main/kotlin/io/github/kitakkun/backintime/plugin/extension/ValueContainerConfig.kt
This file was deleted.
Oops, something went wrong.
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
2 changes: 0 additions & 2 deletions
2
...o/github/kitakkun/backintime/compiler/configuration/BackInTimeCompilerConfigurationKey.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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
package io.github.kitakkun.backintime.compiler.configuration | ||
|
||
import io.github.kitakkun.backintime.plugin.BackInTimeCompilerOptionKey | ||
import io.github.kitakkun.backintime.plugin.extension.ValueContainerConfig | ||
import org.jetbrains.kotlin.config.CompilerConfigurationKey | ||
|
||
object BackInTimeCompilerConfigurationKey { | ||
val ENABLED = CompilerConfigurationKey.create<Boolean>(BackInTimeCompilerOptionKey.ENABLED) | ||
val VALUE_CONTAINER = CompilerConfigurationKey.create<List<ValueContainerConfig>>(BackInTimeCompilerOptionKey.VALUE_CONTAINER) | ||
} |
19 changes: 2 additions & 17 deletions
19
...ub/kitakkun/backintime/compiler/configuration/BackInTimeCompilerConfigurationProcessor.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 |
---|---|---|
@@ -1,26 +1,11 @@ | ||
package io.github.kitakkun.backintime.compiler.configuration | ||
|
||
import io.github.kitakkun.backintime.compiler.backend.ValueContainerClassInfo | ||
import io.github.kitakkun.backintime.compiler.valuecontainer.ValueContainerBuiltIns | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
import org.jetbrains.kotlin.name.ClassId | ||
import org.jetbrains.kotlin.name.Name | ||
|
||
class BackInTimeCompilerConfigurationProcessor { | ||
fun process(configuration: CompilerConfiguration) = BackInTimeCompilerConfiguration( | ||
enabled = configuration[BackInTimeCompilerConfigurationKey.ENABLED] ?: false, | ||
valueContainers = configuration[BackInTimeCompilerConfigurationKey.VALUE_CONTAINER].orEmpty() | ||
.map { config -> | ||
val classId = ClassId.fromString(config.className) | ||
|
||
ValueContainerClassInfo( | ||
classId = classId, | ||
capturedFunctionNames = config.captures.map { Name.guessByFirstCharacter(it) }, | ||
getterFunctionName = Name.guessByFirstCharacter(config.getter), | ||
preSetterFunctionNames = config.preSetters.map { Name.guessByFirstCharacter(it) }, | ||
setterFunctionName = Name.guessByFirstCharacter(config.setter), | ||
serializeItSelf = config.serializeItself, | ||
serializeAs = config.serializeAs?.let { ClassId.fromString(it) }, | ||
) | ||
}, | ||
valueContainers = ValueContainerBuiltIns, | ||
) | ||
} |
179 changes: 179 additions & 0 deletions
179
...in/kotlin/io/github/kitakkun/backintime/compiler/valuecontainer/ValueContainerBuiltIns.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,179 @@ | ||
package io.github.kitakkun.backintime.compiler.valuecontainer | ||
|
||
import io.github.kitakkun.backintime.compiler.backend.ValueContainerClassInfo | ||
import org.jetbrains.kotlin.javac.resolve.classId | ||
import org.jetbrains.kotlin.name.Name | ||
import org.jetbrains.kotlin.name.SpecialNames | ||
|
||
val ValueContainerBuiltIns = listOf( | ||
ValueContainerClassInfo( | ||
classId = classId("androidx.lifecycle", "MutableLiveData"), | ||
capturedFunctionNames = listOf( | ||
Name.identifier("postValue"), | ||
Name.identifier("setValue"), | ||
), | ||
getterFunctionName = Name.identifier("getValue"), | ||
setterFunctionName = Name.identifier("postValue"), | ||
preSetterFunctionNames = emptyList(), | ||
serializeItSelf = false, | ||
serializeAs = null, | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("androidx.compose.runtime", "MutableState"), | ||
capturedFunctionNames = listOf( | ||
Name.guessByFirstCharacter("<set-value>"), | ||
), | ||
getterFunctionName = Name.guessByFirstCharacter("<get-value>"), | ||
setterFunctionName = Name.guessByFirstCharacter("<set-value>"), | ||
preSetterFunctionNames = emptyList(), | ||
serializeItSelf = false, | ||
serializeAs = null, | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("kotlinx.coroutines.flow", "MutableStateFlow"), | ||
capturedFunctionNames = listOf( | ||
Name.guessByFirstCharacter("<set-value>"), | ||
Name.identifier("update"), | ||
Name.identifier("updateAndGet"), | ||
Name.identifier("getAndUpdate"), | ||
Name.identifier("emit"), | ||
Name.identifier("tryEmit"), | ||
), | ||
getterFunctionName = Name.guessByFirstCharacter("<get-value>"), | ||
setterFunctionName = Name.guessByFirstCharacter("<set-value>"), | ||
preSetterFunctionNames = emptyList(), | ||
serializeItSelf = false, | ||
serializeAs = null, | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("kotlin.collections", "MutableList"), | ||
capturedFunctionNames = listOf( | ||
Name.identifier("add"), | ||
Name.identifier("addAll"), | ||
Name.identifier("clear"), | ||
Name.identifier("remove"), | ||
Name.identifier("removeAll"), | ||
Name.identifier("removeAt"), | ||
Name.identifier("set"), | ||
Name.identifier("replaceAll"), | ||
), | ||
getterFunctionName = SpecialNames.THIS, | ||
setterFunctionName = Name.identifier("addAll"), | ||
preSetterFunctionNames = listOf(Name.identifier("clear")), | ||
serializeItSelf = true, | ||
serializeAs = null, | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("kotlin.collections", "MutableSet"), | ||
capturedFunctionNames = listOf( | ||
Name.identifier("add"), | ||
Name.identifier("addAll"), | ||
Name.identifier("clear"), | ||
Name.identifier("remove"), | ||
Name.identifier("removeAll"), | ||
), | ||
getterFunctionName = SpecialNames.THIS, | ||
setterFunctionName = Name.identifier("addAll"), | ||
preSetterFunctionNames = listOf(Name.identifier("clear")), | ||
serializeItSelf = true, | ||
serializeAs = null, | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("kotlin.collections", "MutableMap"), | ||
capturedFunctionNames = listOf( | ||
Name.identifier("clear"), | ||
Name.identifier("put"), | ||
Name.identifier("putAll"), | ||
Name.identifier("remove"), | ||
Name.identifier("set"), | ||
Name.identifier("replace"), | ||
Name.identifier("replaceAll"), | ||
), | ||
getterFunctionName = SpecialNames.THIS, | ||
setterFunctionName = Name.identifier("putAll"), | ||
preSetterFunctionNames = listOf(Name.identifier("clear")), | ||
serializeItSelf = true, | ||
serializeAs = null, | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("androidx.compose.runtime", "MutableIntState"), | ||
capturedFunctionNames = listOf( | ||
Name.guessByFirstCharacter("<set-value>"), | ||
Name.guessByFirstCharacter("<set-intValue>"), | ||
), | ||
getterFunctionName = Name.guessByFirstCharacter("<get-value>"), | ||
setterFunctionName = Name.guessByFirstCharacter("<set-value>"), | ||
preSetterFunctionNames = emptyList(), | ||
serializeItSelf = false, | ||
serializeAs = classId("kotlin", "Int"), | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("androidx.compose.runtime", "MutableLongState"), | ||
capturedFunctionNames = listOf( | ||
Name.guessByFirstCharacter("<set-value>"), | ||
Name.guessByFirstCharacter("<set-longValue>"), | ||
), | ||
getterFunctionName = Name.guessByFirstCharacter("<get-value>"), | ||
setterFunctionName = Name.guessByFirstCharacter("<set-value>"), | ||
preSetterFunctionNames = emptyList(), | ||
serializeItSelf = false, | ||
serializeAs = classId("kotlin", "Long"), | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("androidx.compose.runtime", "MutableFloatState"), | ||
capturedFunctionNames = listOf( | ||
Name.guessByFirstCharacter("<set-value>"), | ||
Name.guessByFirstCharacter("<set-floatValue>"), | ||
), | ||
getterFunctionName = Name.guessByFirstCharacter("<get-value>"), | ||
setterFunctionName = Name.guessByFirstCharacter("<set-value>"), | ||
preSetterFunctionNames = emptyList(), | ||
serializeItSelf = false, | ||
serializeAs = classId("kotlin", "Float"), | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("androidx.compose.runtime", "MutableDoubleState"), | ||
capturedFunctionNames = listOf( | ||
Name.guessByFirstCharacter("<set-value>"), | ||
Name.guessByFirstCharacter("<set-doubleValue>"), | ||
), | ||
getterFunctionName = Name.guessByFirstCharacter("<get-value>"), | ||
setterFunctionName = Name.guessByFirstCharacter("<set-value>"), | ||
preSetterFunctionNames = emptyList(), | ||
serializeItSelf = false, | ||
serializeAs = classId("kotlin", "Double"), | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("androidx.compose.runtime.snapshots", "SnapshotStateList"), | ||
capturedFunctionNames = listOf( | ||
Name.identifier("add"), | ||
Name.identifier("addAll"), | ||
Name.identifier("clear"), | ||
Name.identifier("remove"), | ||
Name.identifier("removeAll"), | ||
Name.identifier("removeAt"), | ||
Name.identifier("set"), | ||
Name.identifier("replaceAll"), | ||
), | ||
getterFunctionName = SpecialNames.THIS, | ||
setterFunctionName = Name.identifier("addAll"), | ||
preSetterFunctionNames = listOf(Name.identifier("clear")), | ||
serializeItSelf = true, | ||
serializeAs = classId("kotlin.collections", "List"), | ||
), | ||
ValueContainerClassInfo( | ||
classId = classId("androidx.compose.runtime.snapshots", "SnapshotStateMap"), | ||
capturedFunctionNames = listOf( | ||
Name.identifier("clear"), | ||
Name.identifier("put"), | ||
Name.identifier("putAll"), | ||
Name.identifier("remove"), | ||
Name.identifier("set"), | ||
), | ||
getterFunctionName = SpecialNames.THIS, | ||
setterFunctionName = Name.identifier("putAll"), | ||
preSetterFunctionNames = listOf(Name.identifier("clear")), | ||
serializeItSelf = true, | ||
serializeAs = classId("kotlin.collections", "Map"), | ||
), | ||
) |
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
22 changes: 1 addition & 21 deletions
22
...gin/gradle/src/main/kotlin/io/github/kitakkun/backintime/extension/BackInTimeExtension.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 |
---|---|---|
@@ -1,25 +1,5 @@ | ||
package io.github.kitakkun.backintime.extension | ||
|
||
import groovy.lang.Closure | ||
import io.github.kitakkun.backintime.plugin.extension.ValueContainerConfig | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
open class BackInTimeExtension( | ||
var enabled: Boolean = true, | ||
val valueContainers: MutableList<ValueContainerConfig> = mutableListOf(), | ||
) { | ||
// KTS用 | ||
fun valueContainers(configuration: ValueContainersScope.() -> Unit) { | ||
val scope = ValueContainersScope().apply(configuration) | ||
valueContainers.addAll(scope.containers) | ||
} | ||
|
||
// Groovy用 | ||
fun valueContainers(closure: Closure<ValueContainersScope>) { | ||
val scope = ValueContainersScope() | ||
closure.delegate = scope | ||
closure.call() | ||
valueContainers.addAll(scope.containers) | ||
} | ||
} | ||
) |
Oops, something went wrong.