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.collect.ImmutableSet;
12 import java.util.HashSet;
13 import java.util.LinkedHashSet;
14 import java.util.Objects;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
20 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.ActionStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveSchemaNode;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
30 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.InputEffectiveStatementImpl;
31 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.OutputEffectiveStatementImpl;
33 final class ActionEffectiveStatementImpl extends AbstractEffectiveSchemaNode<ActionStatement>
34 implements ActionDefinition, ActionEffectiveStatement {
35 private final ContainerSchemaNode input;
36 private final ContainerSchemaNode output;
37 private final Set<TypeDefinition<?>> typeDefinitions;
38 private final Set<GroupingDefinition> groupings;
39 private final boolean augmenting;
40 private final boolean addedByUses;
42 ActionEffectiveStatementImpl(
43 final StmtContext<QName, ActionStatement, EffectiveStatement<QName, ActionStatement>> ctx) {
45 this.input = firstEffective(InputEffectiveStatementImpl.class);
46 this.output = firstEffective(OutputEffectiveStatementImpl.class);
49 final Set<GroupingDefinition> groupingsInit = new HashSet<>();
50 final Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
51 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
52 if (effectiveStatement instanceof GroupingDefinition) {
53 final GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
54 groupingsInit.add(groupingDefinition);
56 if (effectiveStatement instanceof TypedefEffectiveStatement) {
57 final TypedefEffectiveStatement typeDef = (TypedefEffectiveStatement) effectiveStatement;
58 final TypeDefinition<?> type = typeDef.getTypeDefinition();
59 if (!mutableTypeDefinitions.contains(type)) {
60 mutableTypeDefinitions.add(type);
62 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
66 this.groupings = ImmutableSet.copyOf(groupingsInit);
67 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
70 final CopyHistory copyTypesFromOriginal = ctx.getCopyHistory();
71 if (copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES_AUGMENTATION)) {
72 this.addedByUses = this.augmenting = true;
74 this.augmenting = copyTypesFromOriginal.contains(CopyType.ADDED_BY_AUGMENTATION);
75 this.addedByUses = copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES);
80 public ContainerSchemaNode getInput() {
85 public ContainerSchemaNode getOutput() {
90 public Set<TypeDefinition<?>> getTypeDefinitions() {
91 return typeDefinitions;
95 public Set<GroupingDefinition> getGroupings() {
100 public boolean isAugmenting() {
105 public boolean isAddedByUses() {
110 public int hashCode() {
111 return Objects.hash(getQName(), getPath());
115 public boolean equals(final Object obj) {
124 if (getClass() != obj.getClass()) {
128 final ActionEffectiveStatementImpl other = (ActionEffectiveStatementImpl) obj;
129 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
133 public String toString() {
134 return MoreObjects.toStringHelper(this).add("qname", getQName()).add("path", getPath()).add("input", input)
135 .add("output", output).toString();