X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fstmt%2Frfc6020%2Feffective%2FAbstractEffectiveDocumentedDataNodeContainer.java;h=9cbb9c5766a24476882f25f8bc41a72e969a2c65;hb=fcfb9bd360a007d6f68a63394681fa0c440896d9;hp=8d3e6735ab17bb7d10f1dd25b9b22af514a5fdc2;hpb=6a812b89197f7c15df59a00133377db769570445;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDocumentedDataNodeContainer.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDocumentedDataNodeContainer.java index 8d3e6735ab..9cbb9c5766 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDocumentedDataNodeContainer.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveDocumentedDataNodeContainer.java @@ -7,17 +7,18 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; +import static java.util.Objects.requireNonNull; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; -import java.util.Objects; +import java.util.Optional; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; +import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; @@ -45,25 +46,23 @@ abstract class AbstractEffectiveDocumentedDataNodeContainer ctx) { super(ctx); - Collection> effectiveSubstatements = effectiveSubstatements(); - Map mutableChildNodes = new LinkedHashMap<>(); Set mutableGroupings = new HashSet<>(); Set mutableUses = new HashSet<>(); Set> mutableTypeDefinitions = new LinkedHashSet<>(); Set mutablePublicChildNodes = new LinkedHashSet<>(); - for (EffectiveStatement effectiveStatement : effectiveSubstatements) { - if (effectiveStatement instanceof DataSchemaNode) { - final DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement; + for (EffectiveStatement stmt : effectiveSubstatements()) { + if (stmt instanceof DataSchemaNode) { + final DataSchemaNode dataSchemaNode = (DataSchemaNode) stmt; if (!mutableChildNodes.containsKey(dataSchemaNode.getQName())) { /** * Add case short hand when augmenting choice with short hand **/ - if (this instanceof AugmentationSchema && !(effectiveStatement instanceof ChoiceCaseNode || - effectiveStatement instanceof ChoiceSchemaNode) && - (YangValidationBundles.SUPPORTED_CASE_SHORTHANDS.contains(effectiveStatement.statementDefinition())) && - Objects.equals(true, ctx.getFromNamespace(AugmentToChoiceNamespace.class, ctx))) { + if (this instanceof AugmentationSchemaNode + && !(stmt instanceof ChoiceCaseNode || stmt instanceof ChoiceSchemaNode) + && YangValidationBundles.SUPPORTED_CASE_SHORTHANDS.contains(stmt.statementDefinition()) + && Boolean.TRUE.equals(ctx.getFromNamespace(AugmentToChoiceNamespace.class, ctx))) { final CaseShorthandImpl caseShorthand = new CaseShorthandImpl(dataSchemaNode); mutableChildNodes.put(caseShorthand.getQName(), caseShorthand); mutablePublicChildNodes.add(caseShorthand); @@ -72,32 +71,32 @@ abstract class AbstractEffectiveDocumentedDataNodeContainer type = typeDef.getTypeDefinition(); if (!mutableTypeDefinitions.contains(type)) { mutableTypeDefinitions.add(type); } else { - throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement); + throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt); } } - if (effectiveStatement instanceof GroupingDefinition) { - GroupingDefinition grp = (GroupingDefinition) effectiveStatement; + if (stmt instanceof GroupingDefinition) { + GroupingDefinition grp = (GroupingDefinition) stmt; if (!mutableGroupings.contains(grp)) { mutableGroupings.add(grp); } else { - throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement); + throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt); } } } @@ -125,10 +124,9 @@ abstract class AbstractEffectiveDocumentedDataNodeContainer findDataChildByName(final QName name) { + // Child nodes are keyed by their container name, so we can do a direct lookup + return Optional.ofNullable(childNodes.get(requireNonNull(name))); } @Override