StmtContext should not care about semantic versions
[yangtools.git] / yang / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / BuildGlobalContext.java
index 5f0d52ac72100e37de93a2cb8edea07fb2423759..cd8604df4061d0530c6a55d7ad1d994d524f4fa2 100644 (file)
@@ -30,17 +30,14 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.SortedMap;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.util.RecursiveObjectLeaker;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
@@ -49,6 +46,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Namesp
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceNotAvailableException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
@@ -86,37 +84,20 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
     private final ImmutableMap<ModelProcessingPhase, StatementSupportBundle> supports;
     private final Set<SourceSpecificContext> sources = new HashSet<>();
     private final ImmutableSet<YangVersion> supportedVersions;
-    private final boolean enabledSemanticVersions;
 
     private Set<SourceSpecificContext> libSources = new HashSet<>();
     private ModelProcessingPhase currentPhase = ModelProcessingPhase.INIT;
     private ModelProcessingPhase finishedPhase = ModelProcessingPhase.INIT;
 
     BuildGlobalContext(final ImmutableMap<ModelProcessingPhase, StatementSupportBundle> supports,
-            final ImmutableMap<ValidationBundleType, Collection<?>> supportedValidation,
-            final StatementParserMode statementParserMode) {
+            final ImmutableMap<ValidationBundleType, Collection<?>> supportedValidation) {
         this.supports = requireNonNull(supports, "BuildGlobalContext#supports cannot be null");
 
-        switch (statementParserMode) {
-            case DEFAULT_MODE:
-                enabledSemanticVersions = false;
-                break;
-            case SEMVER_MODE:
-                enabledSemanticVersions = true;
-                break;
-            default:
-                throw new IllegalArgumentException("Unhandled parser mode " + statementParserMode);
-        }
-
         addToNamespace(ValidationBundlesNamespace.class, supportedValidation);
 
         this.supportedVersions = ImmutableSet.copyOf(supports.get(ModelProcessingPhase.INIT).getSupportedVersions());
     }
 
-    boolean isEnabledSemanticVersioning() {
-        return enabledSemanticVersions;
-    }
-
     StatementSupportBundle getSupportsForPhase(final ModelProcessingPhase phase) {
         return supports.get(phase);
     }
@@ -126,8 +107,6 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
     }
 
     void addLibSource(final @NonNull StatementStreamSource libSource) {
-        checkState(!isEnabledSemanticVersioning(),
-            "Library sources are not supported in semantic version mode currently.");
         checkState(currentPhase == ModelProcessingPhase.INIT,
                 "Add library source is allowed in ModelProcessingPhase.INIT only");
         libSources.add(new SourceSpecificContext(this, libSource));
@@ -159,7 +138,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
     }
 
     @Override
-    public <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> getNamespaceBehaviour(
+    public <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> getNamespaceBehaviour(
             final Class<N> type) {
         NamespaceBehaviourWithListeners<?, ?, ?> potential = supportedNamespaces.get(type);
         if (potential == null) {
@@ -182,7 +161,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
-    private <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> createNamespaceContext(
+    private <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> createNamespaceContext(
             final NamespaceBehaviour<K, V, N> potentialRaw) {
         if (potentialRaw instanceof DerivedNamespaceBehaviour) {
             final VirtualNamespaceContext derivedContext = new VirtualNamespaceContext(
@@ -238,7 +217,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
         checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
         final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
         for (final SourceSpecificContext source : sources) {
-            rootStatements.add(source.getRoot().buildDeclared());
+            rootStatements.add(source.getRoot().declared());
         }
         return new ReactorDeclaredModel(rootStatements);
     }
@@ -277,18 +256,14 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
         final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
         final List<EffectiveStatement<?, ?>> rootEffectiveStatements = new ArrayList<>(sources.size());
 
-        try {
-            for (final SourceSpecificContext source : sources) {
-                final RootStatementContext<?, ?, ?> root = source.getRoot();
-                try {
-                    rootStatements.add(root.buildDeclared());
-                    rootEffectiveStatements.add(root.buildEffective());
-                } catch (final RuntimeException ex) {
-                    throw propagateException(source, ex);
-                }
+        for (final SourceSpecificContext source : sources) {
+            final RootStatementContext<?, ?, ?> root = source.getRoot();
+            try {
+                rootStatements.add(root.declared());
+                rootEffectiveStatements.add(root.buildEffective());
+            } catch (final RuntimeException ex) {
+                throw propagateException(source, ex);
             }
-        } finally {
-            RecursiveObjectLeaker.cleanup();
         }
 
         sealMutableStatements();
@@ -387,7 +362,8 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
             while (currentSource.hasNext()) {
                 final SourceSpecificContext nextSourceCtx = currentSource.next();
                 try {
-                    final PhaseCompletionProgress sourceProgress = nextSourceCtx.tryToCompletePhase(currentPhase);
+                    final PhaseCompletionProgress sourceProgress =
+                        nextSourceCtx.tryToCompletePhase(currentPhase.executionOrder());
                     switch (sourceProgress) {
                         case FINISHED:
                             currentSource.remove();