int arg = 0;
final GoFile currentFile = (GoFile) e.getContainingFile();
if (GoUtil.isFunctionNameIdentifier(e)) {
GoCallOrConvExpression callOrConvExpression = findParentOfType(e, GoCallOrConvExpression.class);
stringBuilder.append("(");
for (GoExpr argument : callOrConvExpression.getArguments()) {
if (arg != 0)
stringBuilder.append(',');
stringBuilder.append(String.format("$v%d$ ", arg));
stringList.add(String.format("arg%d", arg));
PsiElement firstChildExp = argument.getFirstChild();
GoType[] goTypes = argument.getType();
if (goTypes.length > 0 && goTypes[0] != null) {
GoType goType = goTypes[0];
stringBuilder.append(GoTypes.getRepresentation(goType, currentFile));
} else if (firstChildExp instanceof GoLiteral) {
/*
* Resolves the type of a literal
*/
stringBuilder.append(((GoLiteral) firstChildExp).getType().name().toLowerCase());
} else {
/*
* This block try to resolve the return type of a closure being called on the paramenter list
* ex: unresolvedFn(func()int{return 25*4}())
* will generate:
* func unresolvedFn(arg0 int){}
* @note i think any one will do that, but we never know :D
*/
PsiElement firstChild = firstChildExp.getFirstChild();
if (firstChild instanceof GoLiteralFunction) {
GoType[] returnType = ((GoLiteralFunction) firstChild).getReturnTypes();
if (returnType.length > 0) {
stringBuilder.append("<berila>");
} else {
stringBuilder.append("interface{}");
}
} else if (firstChild instanceof GoLiteral) {
GoLiteral.Type type = ((GoLiteral) firstChild).getType();
//Fix TEST PR ##321 this only happens on test. i don't know why
if (type == GoLiteral.Type.Float || type == GoLiteral.Type.ImaginaryFloat) {
stringBuilder.append("float32");
} else {
stringBuilder.append(type.name().toLowerCase());
}
} else {
stringBuilder.append("interface{}");
}
}
arg++;
}
stringBuilder.append(")");
} else {
/*
* Try to resolve the type declaration for the generated function based on called function
* ex: when http.HandleFunc("/",myIndexHandle)
* will generate:
* func myIndexHandle(arg0 http.ResponseWriter, arg1 *http.Request){}
*/
GoCallOrConvExpression callExpression = findParentOfType(e, GoCallOrConvExpression.class);
GoType[] type = callExpression.getBaseExpression().getType();
if ( type.length != 1 || ! (type[0] instanceof GoTypeFunction) )
return "";
GoTypeFunction function = (GoTypeFunction) type[0];
int pos = -1;
for (GoExpr expr : callExpression.getArguments()) {
pos++;
if ( expr.getTextOffset() == e.getTextOffset() && expr.getTextLength() == e.getTextLength() )
break;
}