Populate parser/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / uses / SimpleCopiedUsesEffectiveStatement.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, 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.uses;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.ImmutableMap;
14 import java.util.Collection;
15 import java.util.Map;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
20 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.UsesNode;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant;
24 import org.opendaylight.yangtools.yang.model.api.stmt.UsesEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
26 import org.opendaylight.yangtools.yang.model.spi.meta.AbstractDeclaredEffectiveStatement.DefaultWithArgument;
27 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.CopyableMixin;
28 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.DocumentedNodeMixin.WithStatus;
29 import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.WhenConditionMixin;
30
31 /**
32  * A simple case of a copied statement. The key difference here is that the argument does not match the declared
33  * argument -- i.e. the effective instance is in a different module. This also means that there is some history
34  * copy history attached.
35  *
36  * <p>
37  * Since we have to keep the argument already, we perform a different field cut than in the local case and handle
38  * also substatements here. We do not handle further refines, though, as that requires yet another field, further
39  * growing instance size. That case is handled by {@link FullCopiedUsesEffectiveStatement}.
40  */
41 class SimpleCopiedUsesEffectiveStatement extends DefaultWithArgument.WithSubstatements<QName, UsesStatement>
42         implements UsesEffectiveStatement, UsesNode, CopyableMixin<QName, UsesStatement>,
43             WhenConditionMixin<QName, UsesStatement>, WithStatus<QName, UsesStatement> {
44     private final @NonNull GroupingDefinition sourceGrouping;
45     private final int flags;
46
47     SimpleCopiedUsesEffectiveStatement(final UsesStatement declared, final QName argument,
48             final GroupingDefinition sourceGrouping, final int flags,
49             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
50         super(declared, argument, substatements);
51         this.sourceGrouping = requireNonNull(sourceGrouping);
52         this.flags = flags;
53     }
54
55     SimpleCopiedUsesEffectiveStatement(final UsesStatement declared, final QName argument,
56             final GroupingDefinition sourceGrouping, final int flags) {
57         this(declared, argument, sourceGrouping, flags, ImmutableList.of());
58     }
59
60     @Override
61     public final GroupingDefinition getSourceGrouping() {
62         return sourceGrouping;
63     }
64
65     @Override
66     public final int flags() {
67         return flags;
68     }
69
70     @Override
71     public final Collection<? extends AugmentationSchemaNode> getAugmentations() {
72         return filterEffectiveStatements(AugmentationSchemaNode.class);
73     }
74
75     @Override
76     public final UsesEffectiveStatement asEffectiveStatement() {
77         return this;
78     }
79
80     @Override
81     public Map<Descendant, SchemaNode> getRefines() {
82         return ImmutableMap.of();
83     }
84 }