CodeGenerator refactor/rewrite
Closed this issue · 0 comments
JonathanxD commented
The intention is to make CodeGenerator
more flexible, currently we have 2 types of CodeGenerator
s, VisitGenerator
and ValueGenerator
, the second type is useless and only exists because SourceGenerator uses it. I'd like to see an implementation that works like modify.visit
, a system like that will be enough to supply all needs.
Note: CodeGenerator
should receive the CodePart
to process and a Data
instance (or a Data
instance provided by CodeGenerator.createData()
(old makeData
)),
CodeGenerator.kt
:
interface CodeGenerator<out R> {
fun process(part: CodePart) = this.process(part, createData())
fun process(part: CodePart, data: Data): R
fun createData(): Data
}
VisitorLikeGenerator.kt
:
interface VisitorLikeGenerator<out R> : CodeGenerator<R> {
private val visitors_ = mutableMapOf<Class<*>, Visitor<*>>()
fun visit(part: CodePart, data: Data) = this.visit(part: CodePart, type: Class<*>, data: Data)
fun visit(part: CodePart, type: Class<*> data: Data) {
//...
visitors.get(type::class.java)!!.visit(part, data, this) //...
// ...
}
}
interface Visitor<in P: CodePart> {
fun visit(codePart: P, data: Data, visitor: VisitorLikeGenerator<*>)
}