Skip to content

Support generating multiple nodes from once in registerNodeFactory #407

@ftomassetti

Description

@ftomassetti

This is a continuation of #211

Currently we need to use work-arounds such:

 registerNodeFactory(TryStatement::class) {
        if (it.onExceptions.isEmpty()) {
            // Dummy try-catch, we will just take the body
            JBlockStmt(translateList(it.statements)).dummyBlock()
        } else {
            TODO()
        }
    }

Where:

/**
 * We cannot directly translate a statement into a sequence of statements, so we use these dummy blocks, which we
 * should later remove
 */
fun JBlockStmt.dummyBlock(): JBlockStmt {
    val annotationInstance = DynamicAnnotationInstance(UUID.randomUUID().toString(), JavaGenerationLanguage.dummyBlock)
    annotations.add(annotationInstance)
    return this
}

Some preparatory work has been done in #211 but it must be completed so that we can write something like:

 registerNodeFactory(TryStatement::class) {
        if (it.onExceptions.isEmpty()) {
           translateList(it.statements)
        } else {
            TODO()
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions