DSL markers

Overall I like the new DslMarker annotation. It makes some things a lot less error prone.

The problem I’m seeing is that using dsl marker there is a lot of added verbosity around method calls that I didn’t feel were ambiguous by scope.

I don’t know exactly what I’d like to see, but here’s an example:

@DslMarker
annotation class ComponentDslMarker

@ComponentDslMarker
interface UiComponent { ... }

class MyComponent : ContainerImpl() {
  init {
    +hGroup {
        +button() {
            click().add { this@MyComponent.safeFun() }
        }
    }
  }
   
  private fun safeFun() {
  }
}

Forgive that I didn’t describe all the components in the example, I’m hoping it makes sense by name.

So the DslMarker interface is awesome for preventing things like accidentally invoking something on hGroup that the user thought was in button. However, for the root class, private members aren’t likely to have scope confusion.

Maybe that would be enough-- if private and protected members are excluded from Dsl receiver checking. Thoughts?

I found exactly what I needed at this post: Scope control for builder-like DSLs