mirror of
https://github.com/corda/corda.git
synced 2024-12-20 05:28:21 +00:00
EG-3714 reverted previous change as unnecessarily (#6773)
This commit is contained in:
parent
8ef739b555
commit
d0cfeb1fbe
@ -1,16 +0,0 @@
|
|||||||
package net.corda.nodeapi.internal.config;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This annotation can be used to provide ConfigParser for the class,
|
|
||||||
* the [parseAs] method will use the provided parser instead of data class constructs to parse the object.
|
|
||||||
*/
|
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface CustomConfigParser {
|
|
||||||
Class parser();
|
|
||||||
}
|
|
@ -28,6 +28,7 @@ import kotlin.reflect.KClass
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
import kotlin.reflect.KType
|
import kotlin.reflect.KType
|
||||||
import kotlin.reflect.full.createInstance
|
import kotlin.reflect.full.createInstance
|
||||||
|
import kotlin.reflect.full.findAnnotation
|
||||||
import kotlin.reflect.full.memberProperties
|
import kotlin.reflect.full.memberProperties
|
||||||
import kotlin.reflect.full.primaryConstructor
|
import kotlin.reflect.full.primaryConstructor
|
||||||
import kotlin.reflect.jvm.jvmErasure
|
import kotlin.reflect.jvm.jvmErasure
|
||||||
@ -35,6 +36,13 @@ import kotlin.reflect.jvm.jvmErasure
|
|||||||
@Target(AnnotationTarget.PROPERTY)
|
@Target(AnnotationTarget.PROPERTY)
|
||||||
annotation class OldConfig(val value: String)
|
annotation class OldConfig(val value: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This annotation can be used to provide ConfigParser for the class,
|
||||||
|
* the [parseAs] method will use the provided parser instead of data class constructs to parse the object.
|
||||||
|
*/
|
||||||
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
annotation class CustomConfigParser(val parser: KClass<out ConfigParser<*>>)
|
||||||
|
|
||||||
interface ConfigParser<T> {
|
interface ConfigParser<T> {
|
||||||
fun parse(config: Config): T
|
fun parse(config: Config): T
|
||||||
}
|
}
|
||||||
@ -69,9 +77,7 @@ fun <T : Any> Config.parseAs(
|
|||||||
baseDirectory: Path? = null
|
baseDirectory: Path? = null
|
||||||
): T {
|
): T {
|
||||||
// Use custom parser if provided, instead of treating the object as data class.
|
// Use custom parser if provided, instead of treating the object as data class.
|
||||||
@Suppress("UNCHECKED_CAST")
|
clazz.findAnnotation<CustomConfigParser>()?.let { return uncheckedCast(it.parser.createInstance().parse(this)) }
|
||||||
clazz.java.getAnnotation(CustomConfigParser::class.java)?.let {
|
|
||||||
return ((it.parser.createInstance() as ConfigParser<T>).parse(this)) }
|
|
||||||
|
|
||||||
require(clazz.isData) {
|
require(clazz.isData) {
|
||||||
"Only Kotlin data classes or class annotated with CustomConfigParser can be parsed. Offending: ${clazz.qualifiedName}"
|
"Only Kotlin data classes or class annotated with CustomConfigParser can be parsed. Offending: ${clazz.qualifiedName}"
|
||||||
|
Loading…
Reference in New Issue
Block a user