Brandon Ward
07/24/2019, 8:41 PM@DslMarker
scope verification?
See attached example.
In case you need a use case to justify my question, my global helper is just something that can supply resources as strings, and it makes sense to be able to do that at various layers of the DSL without needing to repeat the globalHelper
declaration, but at the same time, other functions not marked as global should have their scope enforced by the compiler so that it helps people use the DSL.karelpeeters
07/24/2019, 8:51 PMCasey Brooks
07/24/2019, 9:06 PMthis
to a variable in the initial customDsl
scope, and then refer to that object from child scopes. The DslMarkers
should only limit the implicit scope, but explicit scope (like variabled declared in that scope) should still be accessible
customDsl {
val globalScope = this
scopedEntry { /*work*/ }
nestedObject {
// this should be allowed because I want it global
globalScope.globalHelper { /*work*/ }
}
globalHelper { /*work*/ }
}
Brandon Ward
07/24/2019, 9:09 PMthis@customDsl.globalHelper { /* work */ }
wherever the helper is needed outside the original scopeDominaezzz
07/24/2019, 9:56 PM@CustomDslMarker
.fun scopedEntry(@CustomDslMarker init: Any.() -> Unit)
Brandon Ward
07/24/2019, 9:57 PM