2 * Copyright (c) 2015 Cisco Systems, Inc. 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.stmt.rfc6020.effective;
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableMap;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.Collection;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.LinkedList;
17 import java.util.List;
19 import java.util.Objects;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
23 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
25 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.UsesNode;
27 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
28 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
29 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
30 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
31 import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
33 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
35 public final class UsesEffectiveStatementImpl extends DeclaredEffectiveStatementBase<QName, UsesStatement> implements UsesNode {
36 private final SchemaPath groupingPath;
37 private final boolean addedByUses;
38 private final Map<SchemaPath, SchemaNode> refines;
39 private final Set<AugmentationSchema> augmentations;
40 private final List<UnknownSchemaNode> unknownNodes;
42 public UsesEffectiveStatementImpl(
43 final StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
47 StmtContext<?, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> grpCtx = ctx.getFromNamespace(
48 GroupingNamespace.class, ctx.getStatementArgument());
49 this.groupingPath = grpCtx.getSchemaPath().get();
52 List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
53 if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
59 // initSubstatementCollections
60 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
61 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
62 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
63 Map<SchemaPath, SchemaNode> refinesInit = new HashMap<>();
64 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
65 if (effectiveStatement instanceof UnknownSchemaNode) {
66 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
67 unknownNodesInit.add(unknownNode);
69 if (effectiveStatement instanceof AugmentationSchema) {
70 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
71 augmentationsInit.add(augmentationSchema);
73 if (effectiveStatement instanceof RefineEffectiveStatementImpl) {
74 RefineEffectiveStatementImpl refineStmt = (RefineEffectiveStatementImpl) effectiveStatement;
75 SchemaNodeIdentifier identifier = refineStmt.argument();
76 refinesInit.put(identifier.asSchemaPath(), refineStmt.getRefineTargetNode());
79 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
80 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
81 this.refines = ImmutableMap.copyOf(refinesInit);
85 public SchemaPath getGroupingPath() {
90 public Set<AugmentationSchema> getAugmentations() {
95 public boolean isAugmenting() {
100 public boolean isAddedByUses() {
105 public Map<SchemaPath, SchemaNode> getRefines() {
109 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
114 public int hashCode() {
115 final int prime = 31;
117 result = prime * result + Objects.hashCode(groupingPath);
118 result = prime * result + Objects.hashCode(augmentations);
123 public boolean equals(final Object obj) {
130 if (getClass() != obj.getClass()) {
133 final UsesEffectiveStatementImpl other = (UsesEffectiveStatementImpl) obj;
134 return Objects.equals(groupingPath, other.groupingPath) && Objects.equals(augmentations, other.augmentations);
138 public String toString() {
139 return UsesEffectiveStatementImpl.class.getSimpleName() + "[groupingPath=" +