739ca30b3b6f69ad5a971822fd7ea74bf43476d4
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / BoundStmtCtx.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.VerifyException;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16
17 /**
18  * A {@link CommonStmtCtx} which has additionally been bound to a {@link StatementSupport}. It provides
19  * {@link #argument()} as interpreted by that support.
20  *
21  * @param <A> Argument type
22  */
23 @Beta
24 public interface BoundStmtCtx<A> extends CommonStmtCtx {
25     /**
26      * Return the statement argument.
27      *
28      * @return statement argument, or null if this statement does not have an argument
29      */
30     @Nullable A argument();
31
32     /**
33      * Return the statement argument in literal format.
34      *
35      * @return raw statement argument string
36      * @throws VerifyException if this statement does not have an argument
37      */
38     default @NonNull A getArgument() {
39         return verifyNotNull(argument(), "Attempted to use non-existent argument of %s", this);
40     }
41 }