Problem with nested class
Closed this issue · 1 comments
CTKnight commented
autodsl can't generate code properly when it marks a nested class.
A minimal example is
package me.ctknight.uploadmanager
import com.autodsl.annotation.AutoDsl
class Test {
@AutoDsl
class NestClass(val whatever: String)
}
it generates
// Code generated by AutoDsl. Do not edit.
package me.ctknight.uploadmanager
import com.autodsl.annotation.AutoDslMarker
import kotlin.String
import kotlin.Unit
import kotlin.properties.Delegates
fun nestClass(block: NestClassAutoDslBuilder.() -> Unit): Test.NestClass = NestClassAutoDslBuilder().apply(block).build()
@AutoDslMarker
class NestClassAutoDslBuilder() {
var whatever: String by Delegates.notNull()
fun withWhatever(whatever: String): NestClassAutoDslBuilder = this.apply { this.whatever = whatever}
fun build(): Test.NestClass = NestClass(whatever)
}
and compiler complaints about NestClass not found.
e: NestClassAutoDslBuilder.kt: (17, 35): Unresolved reference: NestClass
I think solutions can be
- import the nested class
or
- call the constructor with fully qualified name just like return type.
I personally prefer the second one.