2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 static com.google.common.base.Verify.verifyNotNull;
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.model.api.meta.StatementOrigin;
20 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
23 * Common interface for all statement contexts, exposing information which is always available. Note this includes only
24 * stateless information -- hence we have {@link #rawArgument()} but do not have an equivalent {@code argument()}.
27 public interface CommonStmtCtx {
29 * See {@link StatementSupport#getPublicView()}.
31 @NonNull StatementDefinition publicDefinition();
34 * Return true if this context produces specified {@link DeclaredStatement} representation.
36 * @param <D> Declared Statement representation
37 * @param type DeclaredStatement representation
38 * @return True if this context results in specified {@link DeclaredStatement} representation
40 default <D extends DeclaredStatement<?>> boolean producesDeclared(final Class<? super D> type) {
41 return type.isAssignableFrom(publicDefinition().getDeclaredRepresentationClass());
45 * Return true if this context produces specified {@link EffectiveStatement} representation.
47 * @param <E> Effective Statement representation
48 * @param type EffectiveStatement representation
49 * @return True if this context results in specified {@link EffectiveStatement} representation
51 default <E extends EffectiveStatement<?, ?>> boolean producesEffective(final Class<? super E> type) {
52 return type.isAssignableFrom(publicDefinition().getEffectiveRepresentationClass());
56 * Returns a reference to statement source.
58 * @return reference of statement source
60 @NonNull StatementSourceReference sourceReference();
63 * Returns the origin of the statement.
65 * @return origin of statement
67 default @NonNull StatementOrigin origin() {
68 return sourceReference().statementOrigin();
72 * Return the statement argument in literal format.
74 * @return raw statement argument string, or null if this statement does not have an argument.
76 @Nullable String rawArgument();
79 * Return the statement argument in literal format.
81 * @return raw statement argument string
82 * @throws VerifyException if this statement does not have an argument
84 default @NonNull String getRawArgument() {
85 return verifyNotNull(rawArgument(), "Statement context %s does not have an argument", this);