2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.leaf_list;
10 import static java.util.Objects.requireNonNull;
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.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.UnitsEffectiveStatement;
27 import org.opendaylight.yangtools.yang.model.spi.meta.AbstractDeclaredEffectiveStatement;
28 import org.opendaylight.yangtools.yang.model.spi.type.ConcreteTypeBuilder;
29 import org.opendaylight.yangtools.yang.model.spi.type.ConcreteTypes;
30 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.DataSchemaNodeMixin;
31 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.MustConstraintMixin;
32 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.UserOrderedMixin;
33 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveSchemaTreeStatementState;
34 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStatementState;
35 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStatementStateAware;
37 abstract class AbstractLeafListEffectiveStatement
38 extends AbstractDeclaredEffectiveStatement.Default<QName, LeafListStatement>
39 implements LeafListEffectiveStatement, LeafListSchemaNode, DerivableSchemaNode,
40 UserOrderedMixin<QName, LeafListStatement>, DataSchemaNodeMixin<QName, LeafListStatement>,
41 MustConstraintMixin<QName, LeafListStatement>, EffectiveStatementStateAware {
42 private final @NonNull Object substatements;
43 private final @NonNull Immutable path;
44 private final @NonNull TypeDefinition<?> type;
45 private final int flags;
47 AbstractLeafListEffectiveStatement(final LeafListStatement declared, final Immutable path, final int flags,
48 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
50 this.path = requireNonNull(path);
51 this.substatements = maskList(substatements);
53 // TODO: lazy instantiation?
54 this.type = buildType();
57 AbstractLeafListEffectiveStatement(final AbstractLeafListEffectiveStatement original, final Immutable path,
60 this.path = requireNonNull(path);
61 this.substatements = original.substatements;
63 // FIXME: share with original?
64 this.type = buildType();
68 public final ImmutableList<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
69 return unmaskList(substatements);
73 public final int flags() {
78 public final QName argument() {
83 public final Immutable pathObject() {
88 public final TypeDefinition<?> getType() {
93 public final boolean isUserOrdered() {
98 public final LeafListEffectiveStatement asEffectiveStatement() {
103 public final EffectiveStatementState toEffectiveStatementState() {
104 return new EffectiveSchemaTreeStatementState(path, flags);
108 public final String toString() {
109 return getClass().getSimpleName() + "[" + getQName() + "]";
112 private TypeDefinition<?> buildType() {
113 final TypeEffectiveStatement<?> typeStmt = findFirstEffectiveSubstatement(TypeEffectiveStatement.class).get();
114 final ConcreteTypeBuilder<?> builder = ConcreteTypes.concreteTypeBuilder(typeStmt.getTypeDefinition(),
116 for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
117 // NOTE: 'default' is omitted here on purpose
118 if (stmt instanceof DescriptionEffectiveStatement) {
119 builder.setDescription(((DescriptionEffectiveStatement)stmt).argument());
120 } else if (stmt instanceof ReferenceEffectiveStatement) {
121 builder.setReference(((ReferenceEffectiveStatement)stmt).argument());
122 } else if (stmt instanceof StatusEffectiveStatement) {
123 builder.setStatus(((StatusEffectiveStatement)stmt).argument());
124 } else if (stmt instanceof UnitsEffectiveStatement) {
125 builder.setUnits(((UnitsEffectiveStatement)stmt).argument());
128 return builder.build();