2 * Copyright (c) 2016 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950.effective;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.HashSet;
14 import java.util.LinkedHashSet;
15 import java.util.Objects;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.ActionStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
26 import org.opendaylight.yangtools.yang.parser.rfc6020.util.AbstractEffectiveSchemaNode;
27 import org.opendaylight.yangtools.yang.parser.rfc6020.util.EffectiveStmtUtils;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
31 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.InputEffectiveStatementImpl;
32 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.OutputEffectiveStatementImpl;
34 public class ActionEffectiveStatementImpl extends AbstractEffectiveSchemaNode<ActionStatement>
35 implements ActionDefinition, ActionEffectiveStatement {
36 private final ContainerSchemaNode input;
37 private final ContainerSchemaNode output;
38 private final Set<TypeDefinition<?>> typeDefinitions;
39 private final Set<GroupingDefinition> groupings;
40 private final boolean augmenting;
41 private final boolean addedByUses;
43 public ActionEffectiveStatementImpl(
44 final StmtContext<QName, ActionStatement, EffectiveStatement<QName, ActionStatement>> ctx) {
46 this.input = firstEffective(InputEffectiveStatementImpl.class);
47 this.output = firstEffective(OutputEffectiveStatementImpl.class);
50 final Set<GroupingDefinition> groupingsInit = new HashSet<>();
51 final Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
52 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
53 if (effectiveStatement instanceof GroupingDefinition) {
54 final GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
55 groupingsInit.add(groupingDefinition);
57 if (effectiveStatement instanceof TypedefEffectiveStatement) {
58 final TypedefEffectiveStatement typeDef = (TypedefEffectiveStatement) effectiveStatement;
59 final TypeDefinition<?> type = typeDef.getTypeDefinition();
60 if (!mutableTypeDefinitions.contains(type)) {
61 mutableTypeDefinitions.add(type);
63 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
67 this.groupings = ImmutableSet.copyOf(groupingsInit);
68 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
71 final CopyHistory copyTypesFromOriginal = ctx.getCopyHistory();
72 if (copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES_AUGMENTATION)) {
73 this.addedByUses = this.augmenting = true;
75 this.augmenting = copyTypesFromOriginal.contains(CopyType.ADDED_BY_AUGMENTATION);
76 this.addedByUses = copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES);
81 public ContainerSchemaNode getInput() {
86 public ContainerSchemaNode getOutput() {
91 public Set<TypeDefinition<?>> getTypeDefinitions() {
92 return typeDefinitions;
96 public Set<GroupingDefinition> getGroupings() {
101 public boolean isAugmenting() {
106 public boolean isAddedByUses() {
111 public int hashCode() {
112 return Objects.hash(getQName(), getPath());
116 public boolean equals(final Object obj) {
125 if (getClass() != obj.getClass()) {
129 final ActionEffectiveStatementImpl other = (ActionEffectiveStatementImpl) obj;
130 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
134 public String toString() {
135 return MoreObjects.toStringHelper(this).add("qname", getQName()).add("path", getPath()).add("input", input)
136 .add("output", output).toString();