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
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.action;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.Verify;
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.InputEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
27 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
28 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveSchemaNode;
29 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
34 final 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 ActionEffectiveStatementImpl(
44 final StmtContext<QName, ActionStatement, EffectiveStatement<QName, ActionStatement>> ctx) {
47 input = findAsContainer(this, InputEffectiveStatement.class);
48 output = findAsContainer(this, OutputEffectiveStatement.class);
51 final Set<GroupingDefinition> groupingsInit = new HashSet<>();
52 final Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
53 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
54 if (effectiveStatement instanceof GroupingDefinition) {
55 final GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
56 groupingsInit.add(groupingDefinition);
58 if (effectiveStatement instanceof TypedefEffectiveStatement) {
59 final TypedefEffectiveStatement typeDef = (TypedefEffectiveStatement) effectiveStatement;
60 final TypeDefinition<?> type = typeDef.getTypeDefinition();
61 if (!mutableTypeDefinitions.contains(type)) {
62 mutableTypeDefinitions.add(type);
64 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
68 this.groupings = ImmutableSet.copyOf(groupingsInit);
69 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
72 final CopyHistory copyTypesFromOriginal = ctx.getCopyHistory();
73 if (copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES_AUGMENTATION)) {
74 this.augmenting = true;
75 this.addedByUses = true;
77 this.augmenting = copyTypesFromOriginal.contains(CopyType.ADDED_BY_AUGMENTATION);
78 this.addedByUses = copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES);
82 private static ContainerSchemaNode findAsContainer(final EffectiveStatement<?, ?> parent,
83 final Class<? extends EffectiveStatement<QName, ?>> statementType) {
84 final EffectiveStatement<?, ?> statement = parent.findFirstEffectiveSubstatement(statementType).get();
85 Verify.verify(statement instanceof ContainerSchemaNode, "Child statement %s is not a ContainerSchemaNode");
86 return (ContainerSchemaNode) statement;
90 public ContainerSchemaNode getInput() {
95 public ContainerSchemaNode getOutput() {
100 public Set<TypeDefinition<?>> getTypeDefinitions() {
101 return typeDefinitions;
105 public Set<GroupingDefinition> getGroupings() {
110 public boolean isAugmenting() {
115 public boolean isAddedByUses() {
120 public int hashCode() {
121 return Objects.hash(getQName(), getPath());
125 public boolean equals(final Object obj) {
134 if (getClass() != obj.getClass()) {
138 final ActionEffectiveStatementImpl other = (ActionEffectiveStatementImpl) obj;
139 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
143 public String toString() {
144 return MoreObjects.toStringHelper(this).add("qname", getQName()).add("path", getPath()).add("input", input)
145 .add("output", output).toString();