Hide SourceSpecificContext and make it final 71/87671/9
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 13 Feb 2020 12:27:40 +0000 (13:27 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 13 Feb 2020 12:53:53 +0000 (13:53 +0100)
This class is used only by the reactor, hide it from outside view
and make it explicitly final. Also remove methods forwarding to
BuildGlobalContext, as they have a single caller which can perform
the dispatch itself.

JIRA: YANGTOOLS-652
Change-Id: I9c6ef4eb599a9d703ec599fb1b76f175c5e8066c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java

index f10533b5cfb2c3ecf646608a7ea198ba386fcf83..dfc0f044723654b59d0403fca1953ece3f8258bf 100644 (file)
@@ -223,7 +223,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     boolean isEnabledSemanticVersioningImpl() {
-        return sourceContext.isEnabledSemanticVersioning();
+        return sourceContext.globalContext().isEnabledSemanticVersioning();
     }
 
     @NonNull YangVersion getRootVersionImpl() {
@@ -231,7 +231,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     void setRootVersionImpl(final YangVersion version) {
-        checkArgument(sourceContext.getSupportedVersions().contains(version),
+        checkArgument(sourceContext.globalContext().getSupportedVersions().contains(version),
                 "Unsupported yang version %s in %s", version, getStatementSourceReference());
         checkState(this.rootVersion == null, "Version of root %s has been already set to %s", argument,
                 this.rootVersion);
@@ -239,7 +239,7 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     }
 
     void addMutableStmtToSealImpl(final MutableStatement mutableStatement) {
-        sourceContext.addMutableStmtToSeal(mutableStatement);
+        sourceContext.globalContext().addMutableStmtToSeal(mutableStatement);
     }
 
     void addRequiredSourceImpl(final SourceIdentifier dependency) {
index 324e4a83f6d9f083c6d8c4e05703d3ba743641ca..f278afcd5673f24f528ae8f910d04b943c9c9567 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
-import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Mutable;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -36,7 +35,6 @@ import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
@@ -61,9 +59,8 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBehaviour.Registry, Mutable {
-
-    public enum PhaseCompletionProgress {
+final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBehaviour.Registry, Mutable {
+    enum PhaseCompletionProgress {
         NO_PROGRESS,
         PROGRESS,
         FINISHED
@@ -74,7 +71,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
     private final Multimap<ModelProcessingPhase, ModifierImpl> modifiers = HashMultimap.create();
     private final QNameToStatementDefinitionMap qnameToStmtDefMap = new QNameToStatementDefinitionMap();
     private final PrefixToModuleMap prefixToModuleMap = new PrefixToModuleMap();
-    private final BuildGlobalContext currentContext;
+    private final @NonNull BuildGlobalContext globalContext;
 
     // Freed as soon as we complete ModelProcessingPhase.EFFECTIVE_MODEL
     private StatementStreamSource source;
@@ -89,13 +86,13 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
     private ModelProcessingPhase inProgressPhase;
     private RootStatementContext<?, ?, ?> root;
 
-    SourceSpecificContext(final BuildGlobalContext currentContext, final StatementStreamSource source) {
-        this.currentContext = requireNonNull(currentContext);
+    SourceSpecificContext(final BuildGlobalContext globalContext, final StatementStreamSource source) {
+        this.globalContext = requireNonNull(globalContext);
         this.source = requireNonNull(source);
     }
 
-    boolean isEnabledSemanticVersioning() {
-        return currentContext.isEnabledSemanticVersioning();
+    @NonNull BuildGlobalContext globalContext() {
+        return globalContext;
     }
 
     ModelProcessingPhase getInProgressPhase() {
@@ -104,14 +101,14 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
 
     AbstractResumedStatement<?, ?, ?> createDeclaredChild(final AbstractResumedStatement<?, ?, ?> current,
             final int childId, final QName name, final String argument, final StatementSourceReference ref) {
-        StatementDefinitionContext<?, ?, ?> def = currentContext.getStatementDefinition(getRootVersion(), name);
+        StatementDefinitionContext<?, ?, ?> def = globalContext.getStatementDefinition(getRootVersion(), name);
         if (def == null) {
-            def = currentContext.getModelDefinedStatementDefinition(name);
+            def = globalContext.getModelDefinedStatementDefinition(name);
             if (def == null) {
                 final StatementSupport<?, ?, ?> extension = qnameToStmtDefMap.get(name);
                 if (extension != null) {
                     def = new StatementDefinitionContext<>(extension);
-                    currentContext.putModelDefinedStatementDefinition(name, def);
+                    globalContext.putModelDefinedStatementDefinition(name, def);
                 }
             }
         } else if (current != null && StmtContextUtils.isUnrecognizedStatement(current)) {
@@ -273,12 +270,12 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
     @Override
     public <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(
             final Class<N> type) {
-        return currentContext.getNamespaceBehaviour(type);
+        return globalContext.getNamespaceBehaviour(type);
     }
 
     @Override
     public NamespaceStorageNode getParentNamespaceStorage() {
-        return currentContext;
+        return globalContext;
     }
 
     PhaseCompletionProgress tryToCompletePhase(final ModelProcessingPhase phase) {
@@ -409,7 +406,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
 
     private QNameToStatementDefinition stmtDef() {
         // regular YANG statements and extension supports added
-        final StatementSupportBundle supportsForPhase = currentContext.getSupportsForPhase(inProgressPhase);
+        final StatementSupportBundle supportsForPhase = globalContext.getSupportsForPhase(inProgressPhase);
         qnameToStmtDefMap.putAll(supportsForPhase.getCommonDefinitions());
         qnameToStmtDefMap.putAll(supportsForPhase.getDefinitionsSpecificForVersion(getRootVersion()));
 
@@ -419,7 +416,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
         }
 
         // We need to any and all extension statements which have been declared in the context
-        final Map<QName, StatementSupport<?, ?, ?>> extensions = currentContext.getNamespace(
+        final Map<QName, StatementSupport<?, ?, ?>> extensions = globalContext.getNamespace(
                 StatementDefinitionNamespace.class);
         if (extensions != null) {
             extensions.forEach((qname, support) -> {
@@ -435,14 +432,6 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
         return qnameToStmtDefMap;
     }
 
-    public Set<YangVersion> getSupportedVersions() {
-        return currentContext.getSupportedVersions();
-    }
-
-    void addMutableStmtToSeal(final MutableStatement mutableStatement) {
-        currentContext.addMutableStmtToSeal(mutableStatement);
-    }
-
     Collection<SourceIdentifier> getRequiredSources() {
         return root.getRequiredSources();
     }