Documentation Language: Swift

Method

executeTemplate(_:arguments:)

Executes a template with the specified arguments.

@MainActor func executeTemplate(_ template: MTLTemplate, arguments: [(any EcoreValue)?]) async throws

Parameters

template

The template to execute

arguments

The arguments matching the template parameters

Discussion

This method handles:

  1. Parameter binding

  2. Guard condition evaluation

  3. Template body execution

  4. Post-condition evaluation

  5. Statistics updates

Guard Conditions

If the template has a guard condition and it evaluates to false, the template body is not executed:

let template = MTLTemplate(
    name: "generatePublicClass",
    parameters: [MTLVariable(name: "class", type: "Class")],
    guard: MTLExpression(/* class.isPublic */),
    body: ...
)

// If guard fails, body is skipped
try await generator.executeTemplate(template, arguments: [privateClass])

Post-conditions

If the template has a post-condition and it evaluates to false after execution, an error is thrown:

let template = MTLTemplate(
    name: "generateFile",
    parameters: [MTLVariable(name: "path", type: "String")],
    post: MTLExpression(/* fileExists(path) */),
    body: ...
)

// If post fails, throws error
try await generator.executeTemplate(template, arguments: ["/output/file.txt"])