All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.squareup.anvil.compiler.CommandLineOptions.kt Maven / Gradle / Ivy

Go to download

The core implementation module for Anvil, responsible for hooking into the Kotlin compiler and orchestrating code generation

There is a newer version: 0.4.0
Show newest version
package com.squareup.anvil.compiler

import com.squareup.anvil.compiler.api.AnalysisBackend
import com.squareup.anvil.compiler.api.ComponentMergingBackend
import org.jetbrains.kotlin.config.CompilerConfiguration
import java.util.Locale

public class CommandLineOptions private constructor(
  public val generateFactories: Boolean,
  public val generateFactoriesOnly: Boolean,
  public val disableComponentMerging: Boolean,
  public val trackSourceFiles: Boolean,
  public val willHaveDaggerFactories: Boolean,
  public val backend: AnalysisBackend,
  public val componentMergingBackend: ComponentMergingBackend,
) {
  public companion object {
    public val CompilerConfiguration.commandLineOptions: CommandLineOptions
      get() = CommandLineOptions(
        generateFactories = get(generateDaggerFactoriesKey, false),
        generateFactoriesOnly = get(generateDaggerFactoriesOnlyKey, false),
        disableComponentMerging = get(disableComponentMergingKey, false),
        trackSourceFiles = get(trackSourceFilesKey, false),
        willHaveDaggerFactories = get(willHaveDaggerFactoriesKey, false),
        backend = parseBackend(),
        componentMergingBackend = parseComponentMergingBackend(),
      )

    private fun CompilerConfiguration.parseBackend(): AnalysisBackend {
      val config = get(analysisBackendKey, AnalysisBackend.EMBEDDED.name)
      return config
        .uppercase(Locale.US)
        .let { value -> AnalysisBackend.entries.find { it.name == value } }
        ?: error("Unknown backend option: '$config'")
    }

    private fun CompilerConfiguration.parseComponentMergingBackend(): ComponentMergingBackend {
      val config = get(mergingBackendKey, ComponentMergingBackend.IR.name)
      return ComponentMergingBackend.fromString(config) ?: error("Unknown backend option: '$config'")
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy