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.EnumEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
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.SubstatementValidator;
28 public final class EnumStatementSupport
29 extends AbstractStatementSupport<String, EnumStatement, EnumEffectiveStatement> {
30 private static final @NonNull EnumStatementSupport RFC6020_INSTANCE = new EnumStatementSupport(
31 SubstatementValidator.builder(YangStmtMapping.ENUM)
32 .addOptional(YangStmtMapping.DESCRIPTION)
33 .addOptional(YangStmtMapping.REFERENCE)
34 .addOptional(YangStmtMapping.STATUS)
35 .addOptional(YangStmtMapping.VALUE)
37 private static final @NonNull EnumStatementSupport RFC7950_INSTANCE = new EnumStatementSupport(
38 SubstatementValidator.builder(YangStmtMapping.ENUM)
39 .addOptional(YangStmtMapping.DESCRIPTION)
40 .addAny(YangStmtMapping.IF_FEATURE)
41 .addOptional(YangStmtMapping.REFERENCE)
42 .addOptional(YangStmtMapping.STATUS)
43 .addOptional(YangStmtMapping.VALUE)
46 private final SubstatementValidator validator;
48 private EnumStatementSupport(final SubstatementValidator validator) {
49 super(YangStmtMapping.ENUM, StatementPolicy.contextIndependent());
50 this.validator = requireNonNull(validator);
53 public static @NonNull EnumStatementSupport rfc6020Instance() {
54 return RFC6020_INSTANCE;
57 public static @NonNull EnumStatementSupport rfc7950Instance() {
58 return RFC7950_INSTANCE;
62 public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
63 // FIXME: Checks for real value
68 protected SubstatementValidator getSubstatementValidator() {
73 protected EnumStatement createDeclared(final StmtContext<String, EnumStatement, ?> ctx,
74 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
75 return DeclaredStatements.createEnum(ctx.getRawArgument(), ctx.getArgument(), substatements);
79 protected EnumEffectiveStatement createEffective(final Current<String, EnumStatement> stmt,
80 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
81 return EffectiveStatements.createEnum(stmt.declared(), substatements);