001/*
002 * Copyright (c) 2012-2021 Institut National des Sciences Appliquées de Lyon (INSA Lyon) and others
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License 2.0 which is available at
006 * http://www.eclipse.org/legal/epl-2.0.
007 *
008 * SPDX-License-Identifier: EPL-2.0
009 */
010
011package org.eclipse.golo.runtime;
012
013public class InvalidDestructuringException extends IllegalArgumentException {
014  // TODO: localize the error message?
015
016  public InvalidDestructuringException(String message) {
017    super(message);
018  }
019
020  public InvalidDestructuringException(String message, Throwable cause) {
021    super(message, cause);
022  }
023
024  public InvalidDestructuringException(Throwable cause) {
025    super(cause);
026  }
027
028  public static InvalidDestructuringException tooManyValues(int expected) {
029    return new InvalidDestructuringException(String.format(
030          "too many values (expecting %d).",
031            expected));
032  }
033
034  public static InvalidDestructuringException notEnoughValues(int expected, boolean sub) {
035    return new InvalidDestructuringException(String.format(
036          "not enough values (expecting%s %d).",
037            sub ? " at least" : "",
038            sub ? expected - 1 : expected));
039  }
040
041  public static InvalidDestructuringException notEnoughValues(int expected, int available, boolean sub) {
042    return new InvalidDestructuringException(String.format(
043          "not enough values (expecting%s %d and got %d).",
044            sub ? " at least" : "",
045            sub ? expected - 1 : expected,
046            available));
047  }
048
049}