Reputation: 1
i am new to groovy,i want to generate parameters comments like "@param [paramemter name] [parameter type] " for a method by live template.The predefined function "methodParameters()" can not do this,so i want run the custom grooy script by predefined function "groovyScript".
The custom script named "test.groovy" as follow:
def methodParameters=_1
def methodParameterTypes=_2
def result='';
def params=methodParameters.replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();
def type=methodParameterTypes.replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();
for(i = 0; i < params.size(); i++) {
result+='* @param '+ params[i] + ' ' + type[i] + ((i < params.size() - 1) ? '\\n ' : '')
};
return result
and I call this this script by inline function "groovyScript" like this:
groovyScript("D:\project\groovyDemo\src\test.groovy",methodParameters(),methodParameterTypes())
but I got the error message as follow:
No signature of method: java.util.ArrayList.replaceAll() is applicable for argument types: (java.lang.String, java.lang.String) values: [[\\[|\\]|\\s], ]Possible solutions: replaceAll(java.util.function.UnaryOperator)
i can not find any ideas to debug this groovy script using in live template of Idea.Can anyone give me some advice?
update:
Question definition:
For the second question,I asked the IntelliJ IDEA support for help.He said that I can fix errors by simulating scripts instead of debugging directly,but I do not know how to simulate it.
Upvotes: 0
Views: 437
Reputation: 749
because "methodParameters(),methodParameterTypes()" return a arrayList, it's not a String, so you can't call replaceAll method of String, you can try this: methodParameters.toString().replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();
Upvotes: 0