Optimize isConfiguration()/isIgnoringConfig() interplay
[yangtools.git] / yang / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / BuildGlobalContext.java
index 980a17ead348ebc0f2a4950a8ca77b06ffd63d01..2d4dcf926a562714e059ee73000aae61300c57fa 100644 (file)
@@ -15,6 +15,8 @@ import com.google.common.collect.HashBasedTable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.SetMultimap;
 import com.google.common.collect.Table;
 import com.google.common.collect.TreeBasedTable;
 import java.util.ArrayList;
@@ -29,7 +31,7 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
 import java.util.SortedMap;
-import javax.annotation.Nonnull;
+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;
@@ -77,17 +79,17 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     private final Map<QName, StatementDefinitionContext<?, ?, ?>> modelDefinedStmtDefs = new HashMap<>();
     private final Map<Class<?>, NamespaceBehaviourWithListeners<?, ?, ?>> supportedNamespaces = new HashMap<>();
     private final List<MutableStatement> mutableStatementsToSeal = new ArrayList<>();
-    private final Map<ModelProcessingPhase, StatementSupportBundle> supports;
+    private final ImmutableMap<ModelProcessingPhase, StatementSupportBundle> supports;
     private final Set<SourceSpecificContext> sources = new HashSet<>();
-    private final Set<YangVersion> supportedVersions;
+    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 Map<ModelProcessingPhase, StatementSupportBundle> supports,
-            final Map<ValidationBundleType, Collection<?>> supportedValidation,
+    BuildGlobalContext(final ImmutableMap<ModelProcessingPhase, StatementSupportBundle> supports,
+            final ImmutableMap<ValidationBundleType, Collection<?>> supportedValidation,
             final StatementParserMode statementParserMode) {
         this.supports = requireNonNull(supports, "BuildGlobalContext#supports cannot be null");
 
@@ -113,15 +115,15 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
         return enabledSemanticVersions;
     }
 
-    StatementSupportBundle getSupportsForPhase(final ModelProcessingPhase currentPhase) {
-        return supports.get(currentPhase);
+    StatementSupportBundle getSupportsForPhase(final ModelProcessingPhase phase) {
+        return supports.get(phase);
     }
 
-    void addSource(@Nonnull final StatementStreamSource source) {
+    void addSource(final @NonNull StatementStreamSource source) {
         sources.add(new SourceSpecificContext(this, source));
     }
 
-    void addLibSource(@Nonnull final StatementStreamSource libSource) {
+    void addLibSource(final @NonNull StatementStreamSource libSource) {
         checkState(!isEnabledSemanticVersioning(),
             "Library sources are not supported in semantic version mode currently.");
         checkState(currentPhase == ModelProcessingPhase.INIT,
@@ -134,9 +136,9 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
                     ImmutableSet.copyOf(supportedFeatures));
     }
 
-    void setModulesDeviatedByModules(final Map<QNameModule, Set<QNameModule>> modulesDeviatedByModules) {
+    void setModulesDeviatedByModules(final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) {
         addToNs(ModulesDeviatedByModules.class, SupportedModules.SUPPORTED_MODULES,
-                    ImmutableMap.copyOf(modulesDeviatedByModules));
+                    ImmutableSetMultimap.copyOf(modulesDeviatedByModules));
     }
 
     @Override
@@ -220,7 +222,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
         }
     }
 
-    EffectiveModelContext build() throws ReactorException {
+    ReactorDeclaredModel build() throws ReactorException {
         executePhases();
         return transform();
     }
@@ -230,13 +232,13 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
         return transformEffective();
     }
 
-    private EffectiveModelContext transform() {
+    private ReactorDeclaredModel transform() {
         checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
         final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
         for (final SourceSpecificContext source : sources) {
             rootStatements.add(source.getRoot().buildDeclared());
         }
-        return new EffectiveModelContext(rootStatements);
+        return new ReactorDeclaredModel(rootStatements);
     }
 
     private SomeModifiersUnresolvedException propagateException(final SourceSpecificContext source,
@@ -301,8 +303,8 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
     }
 
     @SuppressWarnings("checkstyle:illegalCatch")
-    private void loadPhaseStatementsFor(final Set<SourceSpecificContext> sources) throws ReactorException {
-        for (final SourceSpecificContext source : sources) {
+    private void loadPhaseStatementsFor(final Set<SourceSpecificContext> srcs) throws ReactorException {
+        for (final SourceSpecificContext source : srcs) {
             try {
                 source.loadStatements();
             } catch (final RuntimeException ex) {
@@ -316,7 +318,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
         SomeModifiersUnresolvedException buildFailure = null;
         for (final SourceSpecificContext failedSource : sourcesToProgress) {
             final Optional<SourceException> optSourceEx = failedSource.failModifiers(currentPhase);
-            if (!optSourceEx.isPresent()) {
+            if (optSourceEx.isEmpty()) {
                 continue;
             }
 
@@ -336,13 +338,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
 
                 int count = 1;
                 for (final Throwable t : suppressed) {
-                    // FIXME: this should be configured in the appender, really
-                    if (LOG.isDebugEnabled()) {
-                        LOG.error("Error {}: {}", count, t.getMessage(), t);
-                    } else {
-                        LOG.error("Error {}: {}", count, t.getMessage());
-                    }
-
+                    LOG.error("Error {}: {}", count, t.getMessage());
                     count++;
                 }
             }