Automatic description generation for spec properties (JVM only)
This commit is contained in:
parent
0c647cff30
commit
07cc41c645
@ -5,6 +5,7 @@
|
|||||||
### Added
|
### Added
|
||||||
- Device lifecycle message
|
- Device lifecycle message
|
||||||
- Low-code constructor
|
- Low-code constructor
|
||||||
|
- Automatic description generation for spec properties (JVM only)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Property caching moved from core `Device` to the `CachingDevice`
|
- Property caching moved from core `Device` to the `CachingDevice`
|
||||||
|
@ -51,7 +51,12 @@ public abstract class DeviceSpec<D : Device> {
|
|||||||
PropertyDelegateProvider { _: DeviceSpec<D>, property ->
|
PropertyDelegateProvider { _: DeviceSpec<D>, property ->
|
||||||
val propertyName = name ?: property.name
|
val propertyName = name ?: property.name
|
||||||
val deviceProperty = object : DevicePropertySpec<D, T> {
|
val deviceProperty = object : DevicePropertySpec<D, T> {
|
||||||
override val descriptor: PropertyDescriptor = PropertyDescriptor(propertyName).apply(descriptorBuilder)
|
|
||||||
|
override val descriptor: PropertyDescriptor = PropertyDescriptor(propertyName).apply {
|
||||||
|
fromSpec(property)
|
||||||
|
descriptorBuilder()
|
||||||
|
}
|
||||||
|
|
||||||
override val converter: MetaConverter<T> = converter
|
override val converter: MetaConverter<T> = converter
|
||||||
|
|
||||||
override suspend fun read(device: D): T? =
|
override suspend fun read(device: D): T? =
|
||||||
@ -76,7 +81,10 @@ public abstract class DeviceSpec<D : Device> {
|
|||||||
override val descriptor: PropertyDescriptor = PropertyDescriptor(
|
override val descriptor: PropertyDescriptor = PropertyDescriptor(
|
||||||
propertyName,
|
propertyName,
|
||||||
mutable = true
|
mutable = true
|
||||||
).apply(descriptorBuilder)
|
).apply {
|
||||||
|
fromSpec(property)
|
||||||
|
descriptorBuilder()
|
||||||
|
}
|
||||||
override val converter: MetaConverter<T> = converter
|
override val converter: MetaConverter<T> = converter
|
||||||
|
|
||||||
override suspend fun read(device: D): T? =
|
override suspend fun read(device: D): T? =
|
||||||
@ -108,7 +116,10 @@ public abstract class DeviceSpec<D : Device> {
|
|||||||
PropertyDelegateProvider { _: DeviceSpec<D>, property: KProperty<*> ->
|
PropertyDelegateProvider { _: DeviceSpec<D>, property: KProperty<*> ->
|
||||||
val actionName = name ?: property.name
|
val actionName = name ?: property.name
|
||||||
val deviceAction = object : DeviceActionSpec<D, I, O> {
|
val deviceAction = object : DeviceActionSpec<D, I, O> {
|
||||||
override val descriptor: ActionDescriptor = ActionDescriptor(actionName).apply(descriptorBuilder)
|
override val descriptor: ActionDescriptor = ActionDescriptor(actionName).apply {
|
||||||
|
fromSpec(property)
|
||||||
|
descriptorBuilder()
|
||||||
|
}
|
||||||
|
|
||||||
override val inputConverter: MetaConverter<I> = inputConverter
|
override val inputConverter: MetaConverter<I> = inputConverter
|
||||||
override val outputConverter: MetaConverter<O> = outputConverter
|
override val outputConverter: MetaConverter<O> = outputConverter
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package space.kscience.controls.spec
|
||||||
|
|
||||||
|
import space.kscience.controls.api.ActionDescriptor
|
||||||
|
import space.kscience.controls.api.PropertyDescriptor
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
|
||||||
|
public annotation class Description(val content: String)
|
||||||
|
|
||||||
|
internal expect fun PropertyDescriptor.fromSpec(property: KProperty<*>)
|
||||||
|
|
||||||
|
internal expect fun ActionDescriptor.fromSpec(property: KProperty<*>)
|
@ -0,0 +1,9 @@
|
|||||||
|
package space.kscience.controls.spec
|
||||||
|
|
||||||
|
import space.kscience.controls.api.ActionDescriptor
|
||||||
|
import space.kscience.controls.api.PropertyDescriptor
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
internal actual fun PropertyDescriptor.fromSpec(property: KProperty<*>){}
|
||||||
|
|
||||||
|
internal actual fun ActionDescriptor.fromSpec(property: KProperty<*>){}
|
@ -0,0 +1,18 @@
|
|||||||
|
package space.kscience.controls.spec
|
||||||
|
|
||||||
|
import space.kscience.controls.api.ActionDescriptor
|
||||||
|
import space.kscience.controls.api.PropertyDescriptor
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
import kotlin.reflect.full.findAnnotation
|
||||||
|
|
||||||
|
internal actual fun PropertyDescriptor.fromSpec(property: KProperty<*>) {
|
||||||
|
property.findAnnotation<Description>()?.let {
|
||||||
|
description = it.content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal actual fun ActionDescriptor.fromSpec(property: KProperty<*>){
|
||||||
|
property.findAnnotation<Description>()?.let {
|
||||||
|
description = it.content
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +0,0 @@
|
|||||||
package space.kscience.controls.spec
|
|
||||||
|
|
||||||
import space.kscience.controls.api.PropertyDescriptor
|
|
||||||
import kotlin.reflect.KProperty
|
|
||||||
|
|
||||||
internal fun PropertyDescriptor.fromSpec(property: KProperty<*>){
|
|
||||||
property.annotations
|
|
||||||
}
|
|
@ -0,0 +1,9 @@
|
|||||||
|
package space.kscience.controls.spec
|
||||||
|
|
||||||
|
import space.kscience.controls.api.ActionDescriptor
|
||||||
|
import space.kscience.controls.api.PropertyDescriptor
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
internal actual fun PropertyDescriptor.fromSpec(property: KProperty<*>) {}
|
||||||
|
|
||||||
|
internal actual fun ActionDescriptor.fromSpec(property: KProperty<*>){}
|
Loading…
Reference in New Issue
Block a user