Prepare for other years
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
@file:JvmName("Days")
|
||||
|
||||
package be.vandewalleh.aoc.utils.factory
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.TempFileResourceLoader
|
||||
import io.micronaut.context.BeanContext
|
||||
import java.io.File
|
||||
|
||||
fun <T> createDay(beanType: Class<T>): T = BeanContext.run().getBean(beanType)
|
||||
|
||||
inline fun <reified T> createDay() = createDay(T::class.java)
|
||||
|
||||
// A custom resourceLoader that returns a string should be more appropriate but ¯\_(ツ)_/¯
|
||||
private fun BeanContext.registerExampleLoader(example: String) {
|
||||
registerSingleton(TempFileResourceLoader(File.createTempFile("aoc-example", ".txt").apply {
|
||||
writeText(example)
|
||||
}))
|
||||
}
|
||||
|
||||
fun <T> createDay(beanType: Class<T>, example: String): T {
|
||||
return BeanContext.build()
|
||||
.apply { registerExampleLoader(example) }
|
||||
.start()
|
||||
.getBean(beanType)
|
||||
}
|
||||
|
||||
inline fun <reified T> createDay(example: String): T = createDay(T::class.java, example)
|
||||
@@ -10,7 +10,7 @@ import javax.inject.Qualifier
|
||||
@Qualifier
|
||||
@Introspected
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
annotation class Day(val day: Int)
|
||||
annotation class Day(val value: Int)
|
||||
|
||||
@Qualifier
|
||||
@Prototype
|
||||
|
||||
@@ -90,7 +90,7 @@ class InputFactory(private val resourceLoader: ResourceLoader) {
|
||||
if (dayAnnotation.isEmpty)
|
||||
error("@DayInput cannot only be used on classes annotated with ${Day::class.qualifiedName}")
|
||||
|
||||
return dayAnnotation.get().intValue("day").asInt
|
||||
return dayAnnotation.get().intValue("value").asInt
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -1,36 +1,11 @@
|
||||
package be.vandewalleh.aoc.utils.input
|
||||
|
||||
import io.micronaut.context.BeanContext
|
||||
import io.micronaut.context.getBean
|
||||
import io.micronaut.core.annotation.AnnotationMetadataDelegate
|
||||
import io.micronaut.core.annotation.AnnotationMetadataProvider
|
||||
import io.micronaut.core.annotation.AnnotationValue
|
||||
import io.micronaut.core.beans.BeanIntrospection
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
internal inline fun <reified T> getIntrospection(): BeanIntrospection<T> =
|
||||
BeanIntrospection.getIntrospection(T::class.java)
|
||||
|
||||
internal inline fun <reified T : Annotation> AnnotationMetadataDelegate.getAnnotation(): AnnotationValue<T>? =
|
||||
getAnnotation(T::class.java)
|
||||
|
||||
internal inline fun <reified T : Annotation> AnnotationMetadataProvider.findAnnotation(): Optional<AnnotationValue<T>> =
|
||||
findAnnotation(T::class.java)
|
||||
|
||||
internal inline fun <reified T : Annotation> AnnotationMetadataProvider.hasAnnotation(): Boolean =
|
||||
findAnnotation(T::class.java).isPresent
|
||||
|
||||
inline fun <reified T> createDay() = BeanContext.run().getBean<T>()
|
||||
|
||||
// A custom resourceLoader that returns a string should be more appropriate but ¯\_(ツ)_/¯
|
||||
fun BeanContext.registerExampleLoader(example: String) {
|
||||
registerSingleton(TempFileResourceLoader(File.createTempFile("aoc-example", ".txt").apply {
|
||||
writeText(example)
|
||||
}))
|
||||
}
|
||||
|
||||
inline fun <reified T> createDay(example: String): T = BeanContext.build()
|
||||
.apply { registerExampleLoader(example) }
|
||||
.start()
|
||||
.getBean()
|
||||
|
||||
Reference in New Issue
Block a user