2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
12 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
15 * Thrown when there is an inference error.
17 public class InferenceException extends SourceException {
18 private static final long serialVersionUID = 1L;
20 public InferenceException(final @NonNull String message, final @NonNull StatementSourceReference source) {
21 super(message, source);
24 public InferenceException(final @NonNull String message, final @NonNull StatementSourceReference source,
25 final Throwable cause) {
26 super(message, source, cause);
29 public InferenceException(final @NonNull StatementSourceReference source, final @NonNull String format,
30 final Object... args) {
31 this(String.format(format, args), source);
34 public InferenceException(final @NonNull String message, final @NonNull CommonStmtCtx stmt) {
38 public InferenceException(final @NonNull String message, final @NonNull CommonStmtCtx stmt, final Throwable cause) {
39 super(message, stmt, cause);
42 public InferenceException(final @NonNull CommonStmtCtx stmt, final @NonNull String format,
43 final Object... args) {
44 this(stmt.sourceReference(), format, args);
48 * Throw an instance of this exception if an expression evaluates to true. If the expression evaluates to false,
49 * this method does nothing.
51 * @param expression Expression to be evaluated
52 * @param source Statement source reference
53 * @param format Format string, according to {@link String#format(String, Object...)}.
54 * @param args Format string arguments, according to {@link String#format(String, Object...)}
55 * @throws InferenceException if the expression evaluates to true.
57 public static void throwIf(final boolean expression, final @NonNull StatementSourceReference source,
58 final @NonNull String format, final Object... args) {
60 throw new InferenceException(source, format, args);
65 * Throw an instance of this exception if an expression evaluates to true. If the expression evaluates to false,
66 * this method does nothing.
68 * @param expression Expression to be evaluated
69 * @param stmt Statement context
70 * @param format Format string, according to {@link String#format(String, Object...)}.
71 * @param args Format string arguments, according to {@link String#format(String, Object...)}
72 * @throws InferenceException if the expression evaluates to true.
74 public static void throwIf(final boolean expression, final @NonNull CommonStmtCtx stmt,
75 final @NonNull String format, final Object... args) {
77 throw new InferenceException(stmt.sourceReference(), format, args);