2 * Copyright (c) 2015 Cisco Systems, Inc. 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.model.api.stmt;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import java.util.Collection;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
20 @Rfc6020AbnfRule("type-stmt")
21 public interface TypeStatement extends DeclaredStatement<String> {
23 default StatementDefinition statementDefinition() {
24 return YangStmtMapping.TYPE;
27 default @NonNull String getName() {
28 // FIXME: YANGTOOLS-908: verifyNotNull() should not be needed here
29 return verifyNotNull(argument());
32 @Rfc6020AbnfRule("numerical-restrictions")
33 interface NumericalRestrictions extends TypeStatement {
35 default @NonNull RangeStatement getRange() {
36 return findFirstDeclaredSubstatement(RangeStatement.class).get();
40 @Rfc6020AbnfRule("decimal64-specification")
41 interface Decimal64Specification extends TypeStatement {
42 default @NonNull FractionDigitsStatement getFractionDigits() {
43 return findFirstDeclaredSubstatement(FractionDigitsStatement.class).get();
46 default @Nullable RangeStatement getRange() {
47 final Optional<RangeStatement> opt = findFirstDeclaredSubstatement(RangeStatement.class);
48 return opt.isPresent() ? opt.get() : null;
52 @Rfc6020AbnfRule("string-restrictions")
53 interface StringRestrictions extends TypeStatement {
54 default @Nullable LengthStatement getLength() {
55 final Optional<LengthStatement> opt = findFirstDeclaredSubstatement(LengthStatement.class);
56 return opt.isPresent() ? opt.get() : null;
59 default @NonNull Collection<? extends PatternStatement> getPatterns() {
60 return declaredSubstatements(PatternStatement.class);
64 @Rfc6020AbnfRule("enum-specification")
65 interface EnumSpecification extends TypeStatement {
67 default @NonNull Collection<? extends EnumStatement> getEnums() {
68 return declaredSubstatements(EnumStatement.class);
72 @Rfc6020AbnfRule("leafref-specification")
73 interface LeafrefSpecification extends TypeStatement {
74 default @NonNull PathStatement getPath() {
75 return findFirstDeclaredSubstatement(PathStatement.class).get();
79 * Return require-instance statement child, if present. For RFC6020 semantics, this method always returns
82 * @return require-instance statement, if present.
84 default @Nullable RequireInstanceStatement getRequireInstance() {
85 final Optional<RequireInstanceStatement> opt =
86 findFirstDeclaredSubstatement(RequireInstanceStatement.class);
87 return opt.isPresent() ? opt.get() : null;
91 @Rfc6020AbnfRule("instanceidentifier-specification")
92 interface InstanceIdentifierSpecification extends TypeStatement {
94 * Return require-instance statement child, if present. For RFC6020 semantics, this method always returns
97 * @return require-instance statement, if present.
99 default @Nullable RequireInstanceStatement getRequireInstance() {
100 final Optional<RequireInstanceStatement> opt =
101 findFirstDeclaredSubstatement(RequireInstanceStatement.class);
102 return opt.isPresent() ? opt.get() : null;
106 @Rfc6020AbnfRule("identityref-specification")
107 interface IdentityRefSpecification extends TypeStatement {
109 * Returns the base statements.
111 * @return collection of base statements (in YANG 1.1 models) or a collection containing just one base
112 * statement (in YANG 1.0 models)
114 default @NonNull Collection<? extends BaseStatement> getBases() {
115 return declaredSubstatements(BaseStatement.class);
119 @Rfc6020AbnfRule("bits-specification")
120 interface BitsSpecification extends TypeStatement {
121 default @NonNull Collection<? extends BitStatement> getBits() {
122 return declaredSubstatements(BitStatement.class);
126 @Rfc6020AbnfRule("union-specification")
127 interface UnionSpecification extends TypeStatement {
128 default @NonNull Collection<? extends TypeStatement> getTypes() {
129 return declaredSubstatements(TypeStatement.class);
133 @Rfc6020AbnfRule("binary-specification")
134 interface BinarySpecification extends TypeStatement {
135 default @NonNull Collection<? extends LengthStatement> getLength() {
136 return declaredSubstatements(LengthStatement.class);