PHondogo
04/25/2024, 1:48 PM// interfaces declaration
@NotReferencable
interface SomeBuilder {
@AtLeastOnce
fun author(name: String)
fun comment(text: String)
@ExactlyOnce
fun body(lambda: SomeScope.()->Unit)
}
fun build(lambda: SomeBuilder.()->Unit)
// usage
var builder: SomeBuilder? = null
build {
builder = this // ERROR cause SomeBuilder is constrained with @NotReferencable
author(name = "Test name 1") // OK (if comment this line and line after than it is error at compile time, cause fun author must be called at least once)
author(name = "Test name 2") // OK
comment(text = "Comment 1") // OK (if comment this line and line after it still will be OK, cause there are no constraints for this function)
comment(text = "Comment 2") // OK
body {} // OK
body {} // ERROR cause exactly once constraint specified, if comment both lines that it will be an error cause of the same reason
}
Youssef Shoaib [MOD]
04/25/2024, 1:57 PMmikhail.zarechenskiy
04/25/2024, 2:14 PMPHondogo
04/25/2024, 3:56 PMPHondogo
04/25/2024, 4:03 PM// interfaces declaration
interface SomeBuilder {
@ExactlyOnce(group="bodyGroup")
fun body(lambda: SomeScope.()->Unit)
@ExactlyOnce(group="bodyGroup")
fun body(script: String)
}
fun build(lambda: SomeBuilder.()->Unit)
// usage
build {
body {} // OK
body("some script") // ERROR cause function with constraint @ExactlyOnce and same group=bodyGroup was already invoked
}
hfhbd
04/25/2024, 4:23 PMPHondogo
04/25/2024, 4:34 PM