Optimize simple declared statements
[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.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
19
20 public final class ReferenceStatementSupport
21         extends BaseStringStatementSupport<ReferenceStatement, ReferenceEffectiveStatement> {
22     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
23         YangStmtMapping.REFERENCE)
24         .build();
25     private static final ReferenceStatementSupport INSTANCE = new ReferenceStatementSupport();
26
27     private ReferenceStatementSupport() {
28         super(YangStmtMapping.REFERENCE);
29     }
30
31     public static ReferenceStatementSupport getInstance() {
32         return INSTANCE;
33     }
34
35     @Override
36     public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
37         return value;
38     }
39
40     @Override
41     protected SubstatementValidator getSubstatementValidator() {
42         return SUBSTATEMENT_VALIDATOR;
43     }
44
45     @Override
46     protected ReferenceStatement createDeclared(final StmtContext<String, ReferenceStatement, ?> ctx,
47             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
48         return new RegularReferenceStatement(ctx, substatements);
49     }
50
51     @Override
52     protected ReferenceStatement createEmptyDeclared(final StmtContext<String, ReferenceStatement, ?> ctx) {
53         return new EmptyReferenceStatement(ctx);
54     }
55
56     @Override
57     protected ReferenceEffectiveStatement createEffective(
58             final StmtContext<String, ReferenceStatement, ReferenceEffectiveStatement> ctx,
59             final ReferenceStatement declared,
60             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
61         return new RegularReferenceEffectiveStatement(declared, substatements);
62     }
63
64     @Override
65     protected ReferenceEffectiveStatement createEmptyEffective(
66             final StmtContext<String, ReferenceStatement, ReferenceEffectiveStatement> ctx,
67             final ReferenceStatement declared) {
68         return new EmptyReferenceEffectiveStatement(declared);
69     }
70 }