Skip to content

Commit

Permalink
Overall Codebase Enhancement (#74)
Browse files Browse the repository at this point in the history
Resolves #63.
  • Loading branch information
jisungbin authored Jan 14, 2024
1 parent aac4bd5 commit 65021f4
Show file tree
Hide file tree
Showing 68 changed files with 2,532 additions and 1,831 deletions.
7 changes: 3 additions & 4 deletions compiler-integration-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ kotlin {
compilerOptions {
optIn.add("org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
optIn.add("org.jetbrains.kotlin.utils.addToStdlib.UnsafeCastFunction")
freeCompilerArgs.addAll(
"-P",
"plugin:land.sungbin.composeinvestigator.compiler:verbose=true",
)
optIn.add("land.sungbin.composeinvestigator.runtime.ComposeInvestigatorCompilerApi")
optIn.add("land.sungbin.composeinvestigator.runtime.ExperimentalComposeInvestigatorApi")
freeCompilerArgs.addAll("-P", "plugin:land.sungbin.composeinvestigator.compiler:verbose=true")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import land.sungbin.composeinvestigator.runtime.currentComposableInvalidationTracker

val invalidationProcessedFileTable = currentComposableInvalidationTracker

@Composable
fun InvalidationProcessedRoot_StateDelegateReference() {
var count by remember { mutableIntStateOf(0) }
Button(onClick = { count = 1 }) {}
InvalidationProcessedChild_StateDelegateReference(count)
var delegateState by remember { mutableIntStateOf(0) }
Button(onClick = { delegateState++ }) {}
InvalidationProcessedChild_StateDelegateReference(delegateState)
}

@Composable
private fun InvalidationProcessedChild_StateDelegateReference(count: Int) {
Text(text = "$count")
private fun InvalidationProcessedChild_StateDelegateReference(delegateCount: Int) {
Text(text = "$delegateCount")
}

@Composable
fun InvalidationProcessedRoot_StateDirectReference() {
val count = remember { mutableIntStateOf(0) }
Button(onClick = { count.intValue = 1 }) {}
InvalidationProcessedChild_StateDirectReference(count.intValue)
val directState = remember { mutableIntStateOf(0) }
Button(onClick = { directState.intValue++ }) {}
InvalidationProcessedChild_StateDirectReference(directState.intValue)
}

@Composable
private fun InvalidationProcessedChild_StateDirectReference(count: Int) {
Text(text = "$count")
private fun InvalidationProcessedChild_StateDirectReference(directCount: Int) {
Text(text = "$directCount")
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import androidx.compose.runtime.currentRecomposeScope
import land.sungbin.composeinvestigator.runtime.ComposableName
import land.sungbin.composeinvestigator.runtime.currentComposableInvalidationTracker

val invalidationSkippedFileTable = currentComposableInvalidationTracker

@Composable
fun InvalidationSkippedRoot() {
val recomposeScope = currentRecomposeScope

Button(onClick = { recomposeScope.invalidate() }) {}
Button(onClick = recomposeScope::invalidate) {}
InvalidationSkippedChild()
}

Expand All @@ -32,7 +34,7 @@ fun InvalidationSkippedRoot_CustomName() {
currentComposableInvalidationTracker.currentComposableName = ComposableName("InvalidationSkippedRoot_custom_name")
val recomposeScope = currentRecomposeScope

Button(onClick = { recomposeScope.invalidate() }) {}
Button(onClick = recomposeScope::invalidate) {}
InvalidationSkippedChild_CustomName()
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@ package land.sungbin.composeinvestigator.compiler.test.source.logger

import land.sungbin.composeinvestigator.runtime.ComposableInvalidationLogger
import land.sungbin.composeinvestigator.runtime.ComposableInvalidationType
import land.sungbin.composeinvestigator.runtime.StateChangedListener
import land.sungbin.composeinvestigator.runtime.affect.AffectedComposable

data class StateNameValue(val name: String, val previousValue: Any?, val newValue: Any?)

val invalidationLog = mutableMapOf<AffectedComposable, MutableList<ComposableInvalidationType>>()
val stateChangeLog = mutableMapOf<AffectedComposable, MutableList<StateNameValue>>()

fun clearInvalidationLog() {
invalidationLog.clear()
val invalidationLogger = ComposableInvalidationLogger { composable, type ->
invalidationLog.getOrPut(composable, ::mutableListOf).add(type)
}

val stateChangeLogger = StateChangedListener { composable, name, previousValue, newValue ->
val stateLog = StateNameValue(name = name, previousValue = previousValue, newValue = newValue)
stateChangeLog.getOrPut(composable, ::mutableListOf).add(stateLog)
}

fun findInvalidationLog(composableName: String): List<ComposableInvalidationType> =
invalidationLog.filterKeys { composable -> composable.name == composableName }.values.flatten()

val invalidationLogger = ComposableInvalidationLogger { composable, type ->
invalidationLog.getOrPut(composable, ::mutableListOf).add(type)
fun findStateChangeLog(composableName: String): List<StateNameValue> =
stateChangeLog.filterKeys { composable -> composable.name == composableName }.values.flatten()

fun clearInvalidationLog() {
invalidationLog.clear()
}

fun clearStateChangeLog() {
stateChangeLog.clear()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.currentRecomposeScope
import land.sungbin.composeinvestigator.runtime.ComposableInvalidationEffect
import land.sungbin.composeinvestigator.runtime.ComposableInvalidationListener
import land.sungbin.composeinvestigator.runtime.ComposableInvalidationType
import land.sungbin.composeinvestigator.runtime.affect.AffectedComposable
import land.sungbin.composeinvestigator.runtime.currentComposableInvalidationTracker

val invalidationListensViaEffects = mutableMapOf<AffectedComposable, MutableList<ComposableInvalidationType>>()

fun findInvalidationListensViaEffects(composableName: String): List<ComposableInvalidationType> =
invalidationListensViaEffects.filterKeys { composable -> composable.name == composableName }.values.flatten()

@Composable
fun Effects_InvalidationSkippedRoot() {
val recomposeScope = currentRecomposeScope
Expand All @@ -34,7 +27,7 @@ fun Effects_InvalidationSkippedRoot() {
}
}

Button(onClick = { recomposeScope.invalidate() }) {}
Button(onClick = recomposeScope::invalidate) {}
Effects_InvalidationSkippedChild()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@ import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.currentRecomposeScope
import land.sungbin.composeinvestigator.runtime.ComposableInvalidationType
import land.sungbin.composeinvestigator.runtime.affect.AffectedComposable
import land.sungbin.composeinvestigator.runtime.currentComposableInvalidationTracker

val invalidationListensViaManualRegister = mutableMapOf<AffectedComposable, MutableList<ComposableInvalidationType>>()

fun findInvalidationListensViaManualRegister(composableName: String): List<ComposableInvalidationType> =
invalidationListensViaManualRegister.filterKeys { composable -> composable.name == composableName }.values.flatten()

@Composable
fun RegisterListener_InvalidationSkippedRoot() {
val recomposeScope = currentRecomposeScope
Expand All @@ -29,7 +22,7 @@ fun RegisterListener_InvalidationSkippedRoot() {
invalidationListensViaManualRegister.getOrPut(composable, ::mutableListOf).add(type)
}

Button(onClick = { recomposeScope.invalidate() }) {}
Button(onClick = recomposeScope::invalidate) {}
RegisterListener_InvalidationSkippedChild()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Designed and developed by Ji Sungbin 2023.
*
* Licensed under the MIT.
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE
*/

package land.sungbin.composeinvestigator.compiler.test.source.table.callback

import land.sungbin.composeinvestigator.runtime.ComposableInvalidationType
import land.sungbin.composeinvestigator.runtime.affect.AffectedComposable

val invalidationListensViaEffects = mutableMapOf<AffectedComposable, MutableList<ComposableInvalidationType>>()
val invalidationListensViaManualRegister = mutableMapOf<AffectedComposable, MutableList<ComposableInvalidationType>>()

fun findInvalidationListensViaEffects(composableName: String): List<ComposableInvalidationType> =
invalidationListensViaEffects.filterKeys { composable -> composable.name == composableName }.values.flatten()

fun findInvalidationListensViaManualRegister(composableName: String): List<ComposableInvalidationType> =
invalidationListensViaManualRegister.filterKeys { composable -> composable.name == composableName }.values.flatten()

fun clearInvalidationListensViaEffectsLog() {
invalidationListensViaEffects.clear()
}

fun clearInvalidationListensViaManualRegisterLog() {
invalidationListensViaManualRegister.clear()
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ fun IrBaseTest.buildIrVisiterRegistrar(builder: (context: IrPluginContext) -> Ir

fun IrBaseTest.kotlinCompilation(
workingDir: File,
enableComposeCompiler: Boolean = true,
enableVerboseLogging: Boolean = true,
composeCompiling: Boolean = true,
verboseLogging: Boolean = true,
@Suppress("DEPRECATION") additionalVisitor: ComponentRegistrar? = null,
vararg sourceFiles: SourceFile,
): JvmCompilationResult = KotlinCompilation().apply {
Expand All @@ -72,15 +72,15 @@ fun IrBaseTest.kotlinCompilation(
PluginOption(
pluginId = ComposeInvestigatorCommandLineProcessor.PLUGIN_ID,
optionName = ComposeInvestigatorCommandLineProcessor.OPTION_VERBOSE.optionName,
optionValue = if (System.getenv("CI") == "true") "false" else enableVerboseLogging.toString(),
optionValue = if (System.getenv("CI") == "true") "false" else verboseLogging.toString(),
),
)
@Suppress("DEPRECATION")
componentRegistrars = mutableListOf<ComponentRegistrar>(ComposeInvestigatorPluginRegistrar()).also { registrars ->
if (enableComposeCompiler) registrars.add(0, ComposePluginRegistrar())
if (composeCompiling) registrars.add(0, ComposePluginRegistrar())
if (additionalVisitor != null) registrars.add(additionalVisitor)
}
commandLineProcessors = mutableListOf<CommandLineProcessor>(ComposeInvestigatorCommandLineProcessor()).also { processors ->
if (enableComposeCompiler) processors.add(0, ComposeCommandLineProcessor())
if (composeCompiling) processors.add(0, ComposeCommandLineProcessor())
}
}.compile()
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ package land.sungbin.composeinvestigator.compiler.test

import androidx.compose.compiler.plugins.kotlin.ComposeCommandLineProcessor
import androidx.compose.compiler.plugins.kotlin.ComposePluginRegistrar
import com.tschuchort.compiletesting.JvmCompilationResult
import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.PluginOption
import com.tschuchort.compiletesting.SourceFile
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorCommandLineProcessor
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorPluginRegistrar
import land.sungbin.composeinvestigator.compiler.test.utils.source
import org.jetbrains.kotlin.cli.common.toBooleanLenient
import org.jetbrains.kotlin.config.JvmTarget
import org.junit.Rule
import org.junit.Test
Expand All @@ -30,10 +30,9 @@ class IrDumpingTest {
compile(source("SourceForIrDump.kt"))
}

private fun compile(vararg sourceFiles: SourceFile): JvmCompilationResult =
prepareCompilation(*sourceFiles).compile()
private fun compile(vararg sourceFiles: SourceFile) = prepareCompilation(*sourceFiles).compile()

private fun prepareCompilation(vararg sourceFiles: SourceFile): KotlinCompilation =
private fun prepareCompilation(vararg sourceFiles: SourceFile) =
KotlinCompilation().apply {
workingDir = tempDir.root
sources = sourceFiles.asList()
Expand All @@ -44,13 +43,13 @@ class IrDumpingTest {
PluginOption(
pluginId = ComposeInvestigatorCommandLineProcessor.PLUGIN_ID,
optionName = ComposeInvestigatorCommandLineProcessor.OPTION_VERBOSE.optionName,
optionValue = if (System.getenv("CI") == "true") "false" else "true",
optionValue = if (System.getenv("CI").toBooleanLenient() == true) "false" else "true",
),
PluginOption(
pluginId = ComposeCommandLineProcessor.PLUGIN_ID,
optionName = ComposeCommandLineProcessor.LIVE_LITERALS_V2_ENABLED_OPTION.optionName,
optionValue = "false",
),
// PluginOption(
// pluginId = ComposeCommandLineProcessor.PLUGIN_ID,
// optionName = ComposeCommandLineProcessor.LIVE_LITERALS_V2_ENABLED_OPTION.optionName,
// optionValue = "true",
// ),
)
@Suppress("DEPRECATION")
componentRegistrars = listOf(ComposePluginRegistrar(), ComposeInvestigatorPluginRegistrar())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,53 @@

package land.sungbin.composeinvestigator.compiler.test.source

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag

@Composable
fun InvalidationProcessedRoot_StateDelegateReference() {
val countDirect = remember { mutableIntStateOf(0) }
var countDelegation by remember { mutableIntStateOf(0) }
Column {
var delegateState by remember { mutableIntStateOf(0) }
Button(
modifier = Modifier.testTag("InvalidationProcessedRoot_StateDelegateReference"),
onClick = { delegateState++ },
content = {},
)
InvalidationProcessedChild_StateDelegateReference(delegateState)
}
}

@Composable
private fun InvalidationProcessedChild_StateDelegateReference(delegateCount: Int) {
Column {
Text(text = "$delegateCount")
InvalidationProcessedChild_NestedStateDelegateReferenceProvider()
}
}

@Composable
private fun InvalidationProcessedChild_NestedStateDelegateReferenceProvider() {
Column {
var nestedDelegateState by remember { mutableStateOf("state") }
Button(
modifier = Modifier.testTag("InvalidationProcessedChild_NestedStateDelegateReferenceProvider"),
onClick = { nestedDelegateState += " state" },
content = {},
)
InvalidationProcessedChild_NestedStateDelegateReferenceConsumer(nestedDelegateState)
}
}

@Composable
private fun InvalidationProcessedChild_NestedStateDelegateReferenceConsumer(nestedDelegateString: String) {
Text(text = nestedDelegateString)
}
Loading

0 comments on commit 65021f4

Please sign in to comment.