Fixed allModuleIdentifiers 96/27796/3
authorTony Tkacik <ttkacik@cisco.com>
Fri, 2 Oct 2015 09:28:57 +0000 (11:28 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 2 Oct 2015 09:58:38 +0000 (09:58 +0000)
allModuleIdentifiers was incorrectly populated from optional
part of API instead of required part of API,
which leaded to misrepporting identifiers to users.

Change-Id: I6e2d4b84137211fef1446b047cb6e5d3cea3101f
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSchemaContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveSchemaContext.java

index a4a94111a430e92c5985a70f9e54a325e432a0ec..3f280f2b86b5292aae549e57f9bcc303f15d71dc 100644 (file)
@@ -259,12 +259,6 @@ public abstract class AbstractEffectiveSchemaContext implements SchemaContext {
         return Collections.emptySet();
     }
 
-    // FIXME: should work for submodules too
-    @Override
-    public Set<ModuleIdentifier> getAllModuleIdentifiers() {
-        return getIdentifiersToSources().keySet();
-    }
-
     @Override
     public Optional<String> getModuleSource(
             final ModuleIdentifier moduleIdentifier) {
index 0e3940e021a6e8fc51027826140190d679fe3ec4..d9acb0103cb9cd246ab2b1844efed3831fb0e874 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
@@ -25,6 +26,7 @@ import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
 
 public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
@@ -35,6 +37,7 @@ public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
 
     private final ImmutableList<DeclaredStatement<?>> rootDeclaredStatements;
     private final ImmutableList<EffectiveStatement<?, ?>> rootEffectiveStatements;
+    private final Set<ModuleIdentifier> moduleIdentifiers;
 
     public EffectiveSchemaContext(final List<DeclaredStatement<?>> rootDeclaredStatements,
             final List<EffectiveStatement<?, ?>> rootEffectiveStatements) {
@@ -57,14 +60,16 @@ public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
                 new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER);
         final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(
                 new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER);
-
+        Set<ModuleIdentifier> modIdBuilder = new HashSet<>();
         for (Module m : modulesInit) {
             nameMap.put(m.getName(), m);
             nsMap.put(m.getNamespace(), m);
+            modIdBuilder.add(new ModuleIdentifierImpl(m.getName(), Optional.of(m.getNamespace()), Optional.of(m.getRevision())));
         }
 
         namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
         nameToModules = ImmutableSetMultimap.copyOf(nameMap);
+        moduleIdentifiers = ImmutableSet.copyOf(modIdBuilder);
     }
 
     public EffectiveSchemaContext(final Set<Module> modules) {
@@ -88,16 +93,19 @@ public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
         final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(
                 new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER);
 
+        Set<ModuleIdentifier> modIdBuilder = new HashSet<>();
         for (Module m : modules) {
             nameMap.put(m.getName(), m);
             nsMap.put(m.getNamespace(), m);
+            modIdBuilder.add(new ModuleIdentifierImpl(m.getName(), Optional.of(m.getNamespace()), Optional.of(m.getRevision())));
         }
 
         namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
         nameToModules = ImmutableSetMultimap.copyOf(nameMap);
+        moduleIdentifiers = ImmutableSet.copyOf(modIdBuilder);
 
-        rootDeclaredStatements = null;
-        rootEffectiveStatements = null;
+        rootDeclaredStatements = ImmutableList.of();
+        rootEffectiveStatements = ImmutableList.of();
     }
 
     public static SchemaContext resolveSchemaContext(final Set<Module> modules) {
@@ -132,6 +140,11 @@ public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
         return nameToModules;
     }
 
+    @Override
+    public Set<ModuleIdentifier> getAllModuleIdentifiers() {
+        return moduleIdentifiers;
+    }
+
     @Override
     public String toString() {
         return String.format("SchemaContextImpl{modules=%s}", modules);