Remove AugmentationSchemaNode.getOriginalDefinition()
[yangtools.git] / parser / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / CommonStmtCtx.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 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
20
21 /**
22  * Common interface for all statement contexts, exposing information which is always available. Note this includes only
23  * stateless information -- hence we have {@link #rawArgument()} but do not have an equivalent {@code argument()}.
24  */
25 @Beta
26 public interface CommonStmtCtx {
27     /**
28      * See {@link StatementSupport#getPublicView()}.
29      */
30     @NonNull StatementDefinition publicDefinition();
31
32     /**
33      * Return true if this context produces specified {@link DeclaredStatement} representation.
34      *
35      * @param <D> Declared Statement representation
36      * @param type DeclaredStatement representation
37      * @return True if this context results in specified {@link DeclaredStatement} representation
38      */
39     default <D extends DeclaredStatement<?>> boolean producesDeclared(final Class<? super D> type) {
40         return type.isAssignableFrom(publicDefinition().getDeclaredRepresentationClass());
41     }
42
43     /**
44      * Return true if this context produces specified {@link EffectiveStatement} representation.
45      *
46      * @param <E> Effective Statement representation
47      * @param type EffectiveStatement representation
48      * @return True if this context results in specified {@link EffectiveStatement} representation
49      */
50     default <E extends EffectiveStatement<?, ?>> boolean producesEffective(final Class<? super E> type) {
51         return type.isAssignableFrom(publicDefinition().getEffectiveRepresentationClass());
52     }
53
54     /**
55      * Returns a reference to statement source.
56      *
57      * @return reference of statement source
58      */
59     @NonNull StatementSourceReference sourceReference();
60
61     /**
62      * Return the statement argument in literal format.
63      *
64      * @return raw statement argument string, or null if this statement does not have an argument.
65      */
66     @Nullable String rawArgument();
67
68     /**
69      * Return the statement argument in literal format.
70      *
71      * @return raw statement argument string
72      * @throws VerifyException if this statement does not have an argument
73      */
74     default @NonNull String getRawArgument() {
75         return verifyNotNull(rawArgument(), "Statement context %s does not have an argument", this);
76     }
77 }