Remove AbstractStatementSupport.createEmptyDeclared()
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / meta / EnumStatementSupport.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, 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.rfc7950.stmt.meta;
9
10 import static java.util.Objects.requireNonNull;
11
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;
26
27 @Beta
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)
36             .build());
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)
44             .build());
45
46     private final SubstatementValidator validator;
47
48     private EnumStatementSupport(final SubstatementValidator validator) {
49         super(YangStmtMapping.ENUM, StatementPolicy.contextIndependent());
50         this.validator = requireNonNull(validator);
51     }
52
53     public static @NonNull EnumStatementSupport rfc6020Instance() {
54         return RFC6020_INSTANCE;
55     }
56
57     public static @NonNull EnumStatementSupport rfc7950Instance() {
58         return RFC7950_INSTANCE;
59     }
60
61     @Override
62     public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
63         // FIXME: Checks for real value
64         return value;
65     }
66
67     @Override
68     protected SubstatementValidator getSubstatementValidator() {
69         return validator;
70     }
71
72     @Override
73     protected EnumStatement createDeclared(final StmtContext<String, EnumStatement, ?> ctx,
74             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
75         return DeclaredStatements.createEnum(ctx.getRawArgument(), ctx.getArgument(), substatements);
76     }
77
78     @Override
79     protected EnumEffectiveStatement createEffective(final Current<String, EnumStatement> stmt,
80             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
81         return EffectiveStatements.createEnum(stmt.declared(), substatements);
82     }
83 }