IntelliJ IDEA Live Template Groovy 脚本错误

问题描述

我为 Datagrip 创建了一个基于 Groovy 脚本的实时模板,但它总是引发启动错误,但它适用于在线凹槽执行器:

def result = '';
def i=1;
_1.split().eachWithIndex { item,index ->
    def ans = '';
    if (_2=='id' && index==0) {
        return;
    } else if (_2=='uuid' && index==0) {
        ans = 'gen_random_uuid()';
    } else {
        ans = '$'+i;
        i++;
    }
    if (index.next() != _1.split().size()) {
       ans= ans + ','
    }
    result = result + ans
};
return result;

这里是错误

startup Failed:
Script1.groovy: 1: expecting '}',found 'if' @ line 1,column 267.
        '$' + i;
i++;
}     if (index.
                                 ^

1 error

解决方法

解决方案是在每个 if 关闭后加一个分号。