Skip to content

Commit

Permalink
Cleaning codebase (#37)
Browse files Browse the repository at this point in the history
* Cleanup

* Remove duplicate copyright header
  • Loading branch information
jisungbin committed Nov 20, 2023
1 parent 68b6152 commit 337689a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import androidx.compose.compiler.plugins.kotlin.ComposePluginRegistrar
import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.PluginOption
import com.tschuchort.compiletesting.SourceFile
import land.sungbin.composeinvestigator.compiler.COMPOSE_INVESTIGATOR_PLUGIN_ID
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorCommandLineProcessor
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorPluginRegistrar
import land.sungbin.composeinvestigator.compiler.OPTION_VERBOSE
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.com.intellij.mock.MockProject
Expand Down Expand Up @@ -71,8 +69,8 @@ fun IrBaseTest.kotlinCompilation(
supportsK2 = false
pluginOptions = listOf(
PluginOption(
pluginId = COMPOSE_INVESTIGATOR_PLUGIN_ID,
optionName = OPTION_VERBOSE.optionName,
pluginId = ComposeInvestigatorCommandLineProcessor.PLUGIN_ID,
optionName = ComposeInvestigatorCommandLineProcessor.OPTION_VERBOSE.optionName,
optionValue = enableVerboseLogging.toString(),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import androidx.compose.compiler.plugins.kotlin.ComposePluginRegistrar
import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.PluginOption
import com.tschuchort.compiletesting.SourceFile
import land.sungbin.composeinvestigator.compiler.COMPOSE_INVESTIGATOR_PLUGIN_ID
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorCommandLineProcessor
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorPluginRegistrar
import land.sungbin.composeinvestigator.compiler.OPTION_VERBOSE
import land.sungbin.composeinvestigator.compiler.test.utils.source
import org.jetbrains.kotlin.config.JvmTarget
import org.junit.Rule
Expand Down Expand Up @@ -43,8 +41,8 @@ class IrDumpingTest {
supportsK2 = false
pluginOptions = listOf(
PluginOption(
pluginId = COMPOSE_INVESTIGATOR_PLUGIN_ID,
optionName = OPTION_VERBOSE.optionName,
pluginId = ComposeInvestigatorCommandLineProcessor.PLUGIN_ID,
optionName = ComposeInvestigatorCommandLineProcessor.OPTION_VERBOSE.optionName,
optionValue = "true",
),
PluginOption(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,20 @@
package land.sungbin.composeinvestigator.compiler

import com.google.auto.service.AutoService
import org.jetbrains.annotations.VisibleForTesting
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorConfiguration.KEY_VERBOSE
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.CompilerConfigurationKey

@VisibleForTesting
public const val COMPOSE_INVESTIGATOR_PLUGIN_ID: String = "land.sungbin.composeinvestigator.compiler"

internal val KEY_VERBOSE = CompilerConfigurationKey<String>("Whether to enable verbose log")

@VisibleForTesting
public val OPTION_VERBOSE: CliOption =
CliOption(
optionName = "verbose",
valueDescription = "<true | false>",
description = KEY_VERBOSE.toString(),
required = false,
)
public object ComposeInvestigatorConfiguration {
public val KEY_VERBOSE: CompilerConfigurationKey<String> = CompilerConfigurationKey<String>("Whether to enable verbose log")
}

@VisibleForTesting
@AutoService(CommandLineProcessor::class)
public class ComposeInvestigatorCommandLineProcessor : CommandLineProcessor {
override val pluginId: String = COMPOSE_INVESTIGATOR_PLUGIN_ID

override val pluginId: String = PLUGIN_ID
override val pluginOptions: List<CliOption> = listOf(OPTION_VERBOSE)

override fun processOption(
Expand All @@ -48,4 +36,15 @@ public class ComposeInvestigatorCommandLineProcessor : CommandLineProcessor {
else -> error("Unknown plugin option: $optionName")
}
}

public companion object {
public const val PLUGIN_ID: String = "land.sungbin.composeinvestigator.compiler"

public val OPTION_VERBOSE: CliOption = CliOption(
optionName = "verbose",
valueDescription = "<true | false>",
description = KEY_VERBOSE.toString(),
required = false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
package land.sungbin.composeinvestigator.compiler

import com.google.auto.service.AutoService
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorConfiguration.KEY_VERBOSE
import land.sungbin.composeinvestigator.compiler.util.VerboseLogger
import org.jetbrains.annotations.VisibleForTesting
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.com.intellij.mock.MockProject
import org.jetbrains.kotlin.com.intellij.openapi.extensions.LoadingOrder
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
import org.jetbrains.kotlin.config.CompilerConfiguration

@VisibleForTesting
@AutoService(ComponentRegistrar::class)
public class ComposeInvestigatorPluginRegistrar : ComponentRegistrar {
override fun registerProjectComponents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE
*/

package land.sungbin.composeinvestigator.compiler.internal
package land.sungbin.composeinvestigator.compiler.internal.tracker

import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
Expand All @@ -30,18 +30,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.cast

internal abstract class AbstractInvalidationTrackingLower(context: IrPluginContext) :
IrElementTransformerVoidWithContext() {
private val printlnSymbol: IrSimpleFunctionSymbol =
context
.referenceFunctions(
CallableId(
packageName = FqName("kotlin.io"),
callableName = Name.identifier("println"),
),
)
.single { symbol ->
symbol.owner.valueParameters.size == 1 &&
symbol.owner.valueParameters.single().type.isNullableAny()
}
private val hashCodeSymbol: IrSimpleFunctionSymbol =
context
.referenceFunctions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package land.sungbin.composeinvestigator.compiler.internal.tracker

import androidx.compose.compiler.plugins.kotlin.analysis.StabilityInferencer
import androidx.compose.compiler.plugins.kotlin.analysis.normalize
import land.sungbin.composeinvestigator.compiler.internal.AbstractInvalidationTrackingLower
import land.sungbin.composeinvestigator.compiler.internal.COMPOSABLE_FQN
import land.sungbin.composeinvestigator.compiler.internal.COMPOSER_FQN
import land.sungbin.composeinvestigator.compiler.internal.COMPOSER_KT_FQN
Expand Down

0 comments on commit 337689a

Please sign in to comment.