code: private static String getReplacement(Matcher matcher, Closure closure) {
          if (!hasGroup(matcher)) {
              return InvokerHelper.toString(closure.call(matcher.group()));
          }
  
          int count = matcher.groupCount();
          List<String> groups = new ArrayList<String>();
          for (int i = 0; i <= count; i++) {
              groups.add(matcher.group(i));
          }
  
          if (closure.getParameterTypes().length == 1
              && closure.getParameterTypes()[0] == Object[].class) {
              return InvokerHelper.toString(closure.call(groups.toArray()));
          }
          return InvokerHelper.toString(closure.call(groups));
      }
docs: Get a replacement corresponding to the matched pattern for {@link org.codehaus.groovy.runtime.StringGroovyMethods#replaceAll(String, java.util.regex.Pattern, groovy.lang.Closure)}.
  The closure take parameter:
  <ul>
  <li>Whole of match if the pattern include no capturing group</li>
  <li>Object[] of capturing groups if the closure takes Object[] as parameter</li>
  <li>List of capturing groups</li>
  </ul>
  
  @param    matcher the matcher object used for matching
  @param    closure specified with replaceAll() to get replacement
  @return   replacement correspond replacement for a match