Defer copy decisions to StatementSupport
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / description / DescriptionStatementSupport.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.description;
9
10 import com.google.common.collect.ImmutableList;
11 import java.util.Optional;
12 import org.opendaylight.yangtools.yang.common.QNameModule;
13 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
18 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStringStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
24
25 public final class DescriptionStatementSupport
26         extends BaseStringStatementSupport<DescriptionStatement, DescriptionEffectiveStatement> {
27     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
28         YangStmtMapping.DESCRIPTION).build();
29     private static final DescriptionStatementSupport INSTANCE = new DescriptionStatementSupport();
30
31     private DescriptionStatementSupport() {
32         super(YangStmtMapping.DESCRIPTION);
33     }
34
35     public static DescriptionStatementSupport getInstance() {
36         return INSTANCE;
37     }
38
39     @Override
40     public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
41         return value;
42     }
43
44     @Override
45     public Optional<? extends Mutable<?, ?, ?>> copyAsChildOf(final Mutable<?, ?, ?> stmt,
46             final Mutable<?, ?, ?> parent, final CopyType type, final QNameModule targetModule) {
47         return StmtContextUtils.isChildOfGrouping(stmt) ? Optional.empty()
48                 : super.copyAsChildOf(stmt, parent, type, targetModule);
49     }
50
51     @Override
52     protected SubstatementValidator getSubstatementValidator() {
53         return SUBSTATEMENT_VALIDATOR;
54     }
55
56     @Override
57     protected DescriptionStatement createDeclared(final StmtContext<String, DescriptionStatement, ?> ctx,
58             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
59         return new RegularDescriptionStatement(ctx, substatements);
60     }
61
62     @Override
63     protected DescriptionStatement createEmptyDeclared(final StmtContext<String, DescriptionStatement, ?> ctx) {
64         return new EmptyDescriptionStatement(ctx);
65     }
66
67     @Override
68     protected DescriptionEffectiveStatement createEffective(
69             final StmtContext<String, DescriptionStatement, DescriptionEffectiveStatement> ctx,
70             final DescriptionStatement declared,
71             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
72         return new RegularDescriptionEffectiveStatement(declared, substatements);
73     }
74
75     @Override
76     protected DescriptionEffectiveStatement createEmptyEffective(
77             final StmtContext<String, DescriptionStatement, DescriptionEffectiveStatement> ctx,
78             final DescriptionStatement declared) {
79         return new EmptyDescriptionEffectiveStatement(declared);
80     }
81 }