Reformulate StatementContextFactory.createEffective()
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / reference / ReferenceStatementSupport.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.reference;
9
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStringStatementSupport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
20
21 public final class ReferenceStatementSupport
22         extends BaseStringStatementSupport<ReferenceStatement, ReferenceEffectiveStatement> {
23     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
24         YangStmtMapping.REFERENCE)
25         .build();
26     private static final ReferenceStatementSupport INSTANCE = new ReferenceStatementSupport();
27
28     private ReferenceStatementSupport() {
29         super(YangStmtMapping.REFERENCE);
30     }
31
32     public static ReferenceStatementSupport getInstance() {
33         return INSTANCE;
34     }
35
36     @Override
37     protected SubstatementValidator getSubstatementValidator() {
38         return SUBSTATEMENT_VALIDATOR;
39     }
40
41     @Override
42     protected ReferenceStatement createDeclared(final StmtContext<String, ReferenceStatement, ?> ctx,
43             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
44         return new RegularReferenceStatement(ctx.coerceRawStatementArgument(), substatements);
45     }
46
47     @Override
48     protected ReferenceStatement createEmptyDeclared(final StmtContext<String, ReferenceStatement, ?> ctx) {
49         return new EmptyReferenceStatement(ctx.coerceRawStatementArgument());
50     }
51
52     @Override
53     protected ReferenceEffectiveStatement createEffective(final Current<String, ReferenceStatement> stmt,
54             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
55         return substatements.isEmpty() ? new EmptyReferenceEffectiveStatement(stmt.declared())
56             : new RegularReferenceEffectiveStatement(stmt.declared(), substatements);
57     }
58 }