2 * Copyright (c) 2017 Pantheon Technologies, 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.rfc7950.stmt.meta;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableList;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
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.stmt.BitEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.BitStatement;
20 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
21 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
29 public final class BitStatementSupport extends AbstractStatementSupport<String, BitStatement, BitEffectiveStatement> {
30 private static final @NonNull BitStatementSupport RFC6020_INSTANCE = new BitStatementSupport(
31 SubstatementValidator.builder(YangStmtMapping.BIT)
32 .addOptional(YangStmtMapping.DESCRIPTION)
33 .addOptional(YangStmtMapping.REFERENCE)
34 .addOptional(YangStmtMapping.STATUS)
35 .addOptional(YangStmtMapping.POSITION)
37 private static final @NonNull BitStatementSupport RFC7950_INSTANCE = new BitStatementSupport(
38 SubstatementValidator.builder(YangStmtMapping.BIT)
39 .addOptional(YangStmtMapping.DESCRIPTION)
40 .addAny(YangStmtMapping.IF_FEATURE)
41 .addOptional(YangStmtMapping.REFERENCE)
42 .addOptional(YangStmtMapping.STATUS)
43 .addOptional(YangStmtMapping.POSITION)
46 private final SubstatementValidator validator;
48 private BitStatementSupport(final SubstatementValidator validator) {
49 super(YangStmtMapping.BIT, StatementPolicy.contextIndependent());
50 this.validator = requireNonNull(validator);
53 public static @NonNull BitStatementSupport rfc6020Instance() {
54 return RFC6020_INSTANCE;
57 public static @NonNull BitStatementSupport rfc7950Instance() {
58 return RFC7950_INSTANCE;
62 public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
63 // Performs de-duplication and interning in one go
64 return StmtContextUtils.parseIdentifier(ctx, value).getLocalName();
68 protected SubstatementValidator getSubstatementValidator() {
73 protected BitStatement createDeclared(final StmtContext<String, BitStatement, ?> ctx,
74 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
75 return DeclaredStatements.createBit(ctx.getArgument(), substatements);
79 protected BitEffectiveStatement createEffective(final Current<String, BitStatement> stmt,
80 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
81 return EffectiveStatements.createBit(stmt.declared(), substatements);