001/*
002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon)
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009
010package org.eclipse.golo.runtime;
011
012import java.lang.reflect.Method;
013import java.lang.reflect.Parameter;
014import java.util.Arrays;
015import java.util.List;
016
017import static java.util.stream.Collectors.toList;
018import static gololang.Messages.message;
019
020public final class NamedArgumentsHelper {
021
022  private NamedArgumentsHelper() {
023    // utility class
024  }
025
026  public static Boolean hasNamedParameters(Method method) {
027    return Arrays.stream(method.getParameters()).allMatch(Parameter::isNamePresent);
028  }
029
030  public static List<String> getParameterNames(Method method) {
031    return Arrays.stream(method.getParameters())
032        .map(Parameter::getName)
033        .collect(toList());
034  }
035
036  public static void checkArgumentPosition(int position, String argument, String declaration) {
037    if (position == -1) {
038      throw new IllegalArgumentException(message("invalid_argument_name", argument, declaration));
039    }
040  }
041}