intellij-ideagroovydatagriplive-templates

IntelliJ IDEA Live Template Groovy script error


I've created a Groovy script based Live Template for DataGrip, but it always throws a startup error but it works on online groove executor:

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;

Here is the error:

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

1 error

Solution

  • Solution is to put a semicolon after each if closes.