package no.ssb.vtl.script.error;

/*
 * ========================LICENSE_START=================================
 * Java VTL
 * %%
 * Copyright (C) 2016 - 2017 Hadrien Kohl
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =========================LICENSE_END==================================
 */

import org.antlr.v4.runtime.ParserRuleContext;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * A {@link RuntimeException} that contains the context in which it happened.
 */
public class ContextualRuntimeException extends RuntimeException {

    private final ParserRuleContext context;

    public ContextualRuntimeException(ParserRuleContext context) {
        this.context = checkNotNull(context);
    }

    public ContextualRuntimeException(String message, ParserRuleContext context) {
        super(message);
        this.context = checkNotNull(context);
    }

    public ContextualRuntimeException(String message, Throwable cause, ParserRuleContext context) {
        super(message, cause);
        this.context = checkNotNull(context);
    }

    public ContextualRuntimeException(Throwable cause, ParserRuleContext context) {
        super(cause.getMessage(), cause);
        this.context = checkNotNull(context);
    }

    public ContextualRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, ParserRuleContext context) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.context = checkNotNull(context);
    }

    public ParserRuleContext getContext() {
        return context;
    }
}

@@ -911,16 +911,55 @@
 NotNull;
+%0Aimport static java.lang.String.format;
 %0A%0A/**%0A *
@@ -2065,32 +2065,545 @@
 ontext);%0A    %7D%0A%0A
+    public static void checkArgument(ParserRuleContext context, boolean expression) throws ContextualRuntimeException %7B%0A        if (!expression) %7B%0A            throw new ContextualRuntimeException(context);%0A        %7D%0A    %7D%0A%0A    public static void checkArgument(ParserRuleContext context, boolean expression, String template, Object... arguments) throws ContextualRuntimeException %7B%0A        if (!expression) %7B%0A            throw new ContextualRuntimeException(format(template, arguments), context);%0A        %7D%0A    %7D%0A%0A
     public Parse

Add guava like static checkArgument methods