You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Acceleo生成Java主方法时,String[]方括号引发未终止调用错误

Acceleo生成Java主方法时"The invocation isn't terminated"错误解决

问题复现

在.mtl文件中编写的Acceleo模板代码:

[template public generateElement(aMiniFamily : MiniFamily)]
[comment @main/]
[file ('CreateMiniFamily.java', false, 'UTF-8')]
public static void main(String[] args) {
    }
[/file]
[/template]

运行时触发错误:The invocation isn't terminated,错误定位在String[]的]位置。尝试\[]和/[]转义无效。

原因分析

Acceleo语法中,[和]是指令(如模板、文件块)的起止标记。String[]里的]会被Acceleo误判为某个未完成指令的结束符,导致解析失败。

解决方案

提供两种可行的修复方式:

方式1:单个方括号转义

对String[]中的]单独添加反斜杠转义,明确告知Acceleo这是普通文本:

[template public generateElement(aMiniFamily : MiniFamily)]
[comment @main/]
[file ('CreateMiniFamily.java', false, 'UTF-8')]
public static void main(String\[] args) {
    }
[/file]
[/template]

方式2:使用文本块包裹代码段

用[text]和[/text]标记包裹包含方括号的Java代码,块内内容会被当作纯文本直接输出,不会被解析为Acceleo指令:

[template public generateElement(aMiniFamily : MiniFamily)]
[comment @main/]
[file ('CreateMiniFamily.java', false, 'UTF-8')]
[text]
public static void main(String[] args) {
    }
[/text]
[/file]
[/template]

内容的提问来源于stack exchange,提问作者xy3333

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 21:05:20