Remove AbstractStatementSupport.createEmptyDeclared()
[yangtools.git] / yang / openconfig-parser-support / src / main / java / org / opendaylight / yangtools / openconfig / parser / AbstractHashedValueStatementSupport.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.openconfig.parser;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableList;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.openconfig.model.api.OpenConfigHashedValueEffectiveStatement;
16 import org.opendaylight.yangtools.openconfig.model.api.OpenConfigHashedValueStatement;
17 import org.opendaylight.yangtools.yang.common.Empty;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.SchemaNodeDefaults;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
24 import org.opendaylight.yangtools.yang.model.spi.meta.AbstractDeclaredStatement.WithoutArgument.WithSubstatements;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractEmptyStatementSupport;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.SchemaPathSupport;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
31
32 abstract class AbstractHashedValueStatementSupport
33         extends AbstractEmptyStatementSupport<OpenConfigHashedValueStatement, OpenConfigHashedValueEffectiveStatement> {
34
35     private static final class Declared extends WithSubstatements implements OpenConfigHashedValueStatement {
36         private final @NonNull StatementDefinition definition;
37
38         Declared(final StatementDefinition definition,
39                 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
40             super(substatements);
41             this.definition = requireNonNull(definition);
42         }
43
44         @Override
45         public StatementDefinition statementDefinition() {
46             return definition;
47         }
48     }
49
50     private static final class Effective
51             extends UnknownEffectiveStatementBase<Empty, OpenConfigHashedValueStatement>
52             implements OpenConfigHashedValueEffectiveStatement {
53         private final @NonNull StatementDefinition definition;
54         private final @NonNull Immutable path;
55
56         Effective(final Current<Empty, OpenConfigHashedValueStatement> stmt,
57                 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
58             super(stmt, substatements);
59             definition = stmt.publicDefinition();
60             path = SchemaPathSupport.toEffectivePath(stmt.getEffectiveParent().getSchemaPath()
61                     .createChild(stmt.publicDefinition().getStatementName()));
62         }
63
64         @Override
65         public QName getQName() {
66             return SchemaNodeDefaults.extractQName(path);
67         }
68
69         @Override
70         @Deprecated
71         public SchemaPath getPath() {
72             return SchemaNodeDefaults.extractPath(this, path);
73         }
74
75         @Override
76         public StatementDefinition statementDefinition() {
77             return definition;
78         }
79
80         @Override
81         public OpenConfigHashedValueEffectiveStatement asEffectiveStatement() {
82             return this;
83         }
84     }
85
86     private final SubstatementValidator validator;
87
88     AbstractHashedValueStatementSupport(final StatementDefinition definition) {
89         super(definition, StatementPolicy.contextIndependent());
90         this.validator = SubstatementValidator.builder(definition).build();
91     }
92
93     @Override
94     protected final SubstatementValidator getSubstatementValidator() {
95         return validator;
96     }
97
98     @Override
99     protected final OpenConfigHashedValueStatement createDeclared(
100             final StmtContext<Empty, OpenConfigHashedValueStatement, ?> ctx,
101             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
102         return new Declared(getPublicView(), substatements);
103     }
104
105     @Override
106     protected OpenConfigHashedValueEffectiveStatement createEffective(
107             final Current<Empty, OpenConfigHashedValueStatement> stmt,
108             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
109         return new Effective(stmt, substatements);
110     }
111 }