io.github.darvld.wireframe.ProcessingEnvironment.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compiler-core Show documentation
Show all versions of compiler-core Show documentation
A GraphQL server library for Kotlin.
package io.github.darvld.wireframe
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.TypeSpec
import graphql.schema.GraphQLNamedType
import io.github.darvld.wireframe.WireframeCompiler.Output
import io.github.darvld.wireframe.extensions.generateNameFor
/**Provides information about the environment in which the code will be generated.*/
public class ProcessingEnvironment internal constructor(
public val projectName: String,
public val basePackage: String,
) {
@JvmInline
private value class OutputKey(@Suppress("unused") val qualifiedName: String) {
constructor(packageName: String, fileName: String) : this("$packageName.${fileName}")
}
private val packageNameCache: MutableMap = mutableMapOf()
private val nameResolutionCache: MutableMap = mutableMapOf()
private val outputs: MutableMap = mutableMapOf()
public fun registerPackageFor(typeName: String, packageName: String) {
packageNameCache.put(typeName, packageName)
}
public fun resolve(type: GraphQLNamedType): ClassName = nameResolutionCache.getOrPut(type) {
ClassName(packageNameCache.getOrDefault(type.name, basePackage), generateNameFor(type))
}
public fun output(packageName: String, fileName: String, block: FileSpec.Builder.() -> Unit) {
outputs.getOrPut(OutputKey(packageName, fileName)) { FileSpec.builder(packageName, fileName) }.apply(block)
}
public fun getOutputs(): Sequence
© 2015 - 2024 Weber Informatics LLC | Privacy Policy