StringBuilder (GrReflectedMethod method) { final GrParameter[] actualParams = method.getParameterList().getParameters(); final GrParameter[] parameters = method.getBaseMethod().getParameters(); Set<String> actual = new HashSet<>(actualParams.length); for (GrParameter param : actualParams) { actual.add(param.getName()); } StringBuilder builder = new StringBuilder(); if (method.isConstructor()) { builder.append("this"); } else { if (!PsiTypes.voidType().equals(context.typeProvider.getReturnType(method))) { builder.append("return "); } builder.append(method.getName()); } builder.append('('); for (GrParameter parameter : parameters) { if (actual.contains(parameter.getName())) { builder.append(parameter.getName()); } else { LOG.assertTrue(parameter.isOptional()); final GrExpression initializer = parameter.getInitializerGroovy(); LOG.assertTrue(initializer != null); builder.append(initializer.getText()); } builder.append(", "); } builder.delete(builder.length()-2, builder.length()); //builder.removeFromTheEnd(2); builder.append(')'); final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(context.project); final GrStatement delegateCall; if (method.isConstructor()) { delegateCall = factory.createConstructorInvocation(builder.toString(), method); } else { delegateCall = factory.createStatementFromText(builder.toString(), method); } final StringBuilder result = new StringBuilder(); delegateCall.accept(new CodeBlockGenerator(result, this.context.extend())); return result; }