Populate xpath/ hierarchy
[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 java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.yang.common.YangVersion;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19
20 /**
21  * A {@link CommonStmtCtx} which has additionally been bound to a {@link StatementSupport}. It provides
22  * {@link #argument()} as interpreted by that support.
23  *
24  * @param <A> Argument type
25  */
26 @Beta
27 public interface BoundStmtCtx<A> extends CommonStmtCtx {
28     /**
29      * Return the statement argument.
30      *
31      * @return statement argument, or null if this statement does not have an argument
32      */
33     @Nullable A argument();
34
35     /**
36      * Return the statement argument in literal format.
37      *
38      * @return raw statement argument string
39      * @throws VerifyException if this statement does not have an argument
40      */
41     default @NonNull A getArgument() {
42         return verifyNotNull(argument(), "Attempted to use non-existent argument of %s", this);
43     }
44
45     /**
46      * Return the {@link YangVersion} associated with this statement.
47      *
48      * @return YANG version used to bind this statement
49      */
50     @NonNull YangVersion yangVersion();
51
52     /**
53      * Search of any child statement context of specified type and return its argument. If such a statement exists, it
54      * is assumed to have the right argument. Users should be careful to use this method for statements which have
55      * cardinality {@code 0..1}, otherwise this method can return any one of the statement's argument.
56      *
57      * @param <X> Substatement argument type
58      * @param <Z> Substatement effective statement representation
59      * @param type Effective statement representation being look up
60      * @return {@link Optional#empty()} if no statement exists, otherwise the argument value
61      */
62     <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(@NonNull Class<Z> type);
63
64     /**
65      * Check if there is any child statement context of specified type.
66      *
67      * @param type Effective statement representation being look up
68      * @return True if such a child statement exists, false otherwise
69      */
70     boolean hasSubstatement(@NonNull Class<? extends EffectiveStatement<?, ?>> type);
71 }