From ff4d447ed2665eea2740d9bd511cc76780b61eea Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 26 Oct 2016 18:14:44 +0200 Subject: [PATCH] Revert "BUG-6522: create a dedicated extensions map" This reverts commit 7eafc450f8a7c09f9d98c0d4d7608b16588244cb, as it breaks extension resolution in GBP's ned.yang. The problem boils down to an extension declared in a submodule to of tailf-comon to fail to resolve. Change-Id: Idaa4be44dc0ef18b0e5cca5153b37a3ec7042cf2 Signed-off-by: Robert Varga --- .../stmt/reactor/SourceSpecificContext.java | 32 +++++++------------ .../stmt/rfc6020/YangInferencePipeline.java | 2 +- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java index ec0ae03634..1d8c2ac6ed 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java @@ -11,7 +11,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Multimap; import java.net.URI; import java.util.ArrayList; @@ -83,13 +82,12 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh .put(TypeUtils.INSTANCE_IDENTIFIER, new InstanceIdentifierSpecificationImpl.Definition()) .build(); - private final QNameToStatementDefinitionMap qNameToStmtDefMap = new QNameToStatementDefinitionMap(); private final Multimap modifiers = HashMultimap.create(); + private final QNameToStatementDefinitionMap qNameToStmtDefMap = new QNameToStatementDefinitionMap(); private final PrefixToModuleMap prefixToModuleMap = new PrefixToModuleMap(); private final BuildGlobalContext currentContext; private final StatementStreamSource source; - private Map> definedExtensions = ImmutableMap.of(); private Collection importedNamespaces = ImmutableList.of(); private ModelProcessingPhase finishedPhase = ModelProcessingPhase.INIT; private ModelProcessingPhase inProgressPhase; @@ -113,7 +111,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh StatementDefinitionContext def = currentContext.getStatementDefinition(name); if (def == null) { - final StatementSupport extension = definedExtensions.get(name); + final StatementSupport extension = qNameToStmtDefMap.get(name); if (extension != null) { def = new StatementDefinitionContext<>(extension); } else { @@ -364,28 +362,20 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh return prefixToModuleMap; } - private static void addSupports(final Builder builder, @Nullable final Map supports) { - if (supports != null) { - builder.putAll(supports); - } - } - private QNameToStatementDefinition stmtDef() { // regular YANG statements and extension supports added qNameToStmtDefMap.putAll(currentContext.getSupportsForPhase(inProgressPhase).getDefinitions()); - // We need to any and all extension statements which have been declared in the context - if (inProgressPhase == ModelProcessingPhase.FULL_DECLARATION) { - // We maintain this map for createDeclaredChild(), which calls out to global context first, - // hence there is no point in performing double lookups. - final Builder> b = ImmutableMap.builder(); - addSupports(b, getRoot().getAllFromLocalStorage(StatementDefinitionNamespace.class)); - for (NamespaceStorageNode namespace : importedNamespaces) { - addSupports(b, namespace.getAllFromLocalStorage(StatementDefinitionNamespace.class)); - } + // No further actions needed + if (inProgressPhase != ModelProcessingPhase.FULL_DECLARATION) { + return qNameToStmtDefMap; + } - definedExtensions = b.build(); - definedExtensions.forEach((qname, support) -> { + // We need to any and all extension statements which have been declared in the context + final Map> extensions = currentContext.getAllFromNamespace( + StatementDefinitionNamespace.class); + if (extensions != null) { + extensions.forEach((qname, support) -> { final StatementSupport existing = qNameToStmtDefMap.putIfAbsent(qname, support); if (existing != null) { LOG.debug("Source {} already defines statement {} as {}", source, qname, existing); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java index 4bb671e651..d0802782e9 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java @@ -144,7 +144,7 @@ public final class YangInferencePipeline { .addSupport(new FractionDigitsStatementImpl.Definition()) .addSupport(new BaseStatementImpl.Definition()) .addSupport(global(DerivedIdentitiesNamespace.class)) - .addSupport(sourceLocal(StatementDefinitionNamespace.class)) + .addSupport(global(StatementDefinitionNamespace.class)) .build(); public static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle -- 2.36.6