Merge "Bug 2997: Fixed instanceof checks to use interfaces"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / impl / YangParserImpl.java
index c50aa3344f2cb877493c826bdc68904209ffc5ea..5684c045d5a08d1412b48bfdf3db5a28f2b7e21d 100644 (file)
@@ -15,7 +15,6 @@ import static org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils.f
 import static org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils.processAugmentation;
 import static org.opendaylight.yangtools.yang.parser.builder.impl.TypeUtils.resolveType;
 import static org.opendaylight.yangtools.yang.parser.builder.impl.TypeUtils.resolveTypeUnion;
-
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.HashBiMap;
@@ -34,6 +33,7 @@ import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.NavigableMap;
 import java.util.Set;
 import java.util.TreeMap;
 import javax.annotation.concurrent.Immutable;
@@ -47,7 +47,7 @@ import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.YangContext;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
@@ -141,7 +141,7 @@ public final class YangParserImpl implements YangContextParser {
 
         // module builders sorted by dependencies
         List<ModuleBuilder> sortedBuilders = ModuleDependencySort.sort(resolved);
-        LinkedHashMap<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sortedBuilders, null);
+        Map<URI, TreeMap<Date, ModuleBuilder>> modules = resolveModulesWithImports(sortedBuilders, null);
         Collection<Module> unsorted = build(modules).values();
         Set<Module> result = new LinkedHashSet<>(
                 ModuleDependencySort.sort(unsorted.toArray(new Module[unsorted.size()])));
@@ -233,9 +233,9 @@ public final class YangParserImpl implements YangContextParser {
         return resolveSchemaContext(result);
     }
 
-    private static LinkedHashMap<URI, TreeMap<Date, ModuleBuilder>> resolveModulesWithImports(final List<ModuleBuilder> sorted,
+    private static Map<URI, TreeMap<Date, ModuleBuilder>> resolveModulesWithImports(final List<ModuleBuilder> sorted,
             final SchemaContext context) {
-        final LinkedHashMap<URI, TreeMap<Date, ModuleBuilder>> modules = orderModules(sorted);
+        final Map<URI, TreeMap<Date, ModuleBuilder>> modules = orderModules(sorted);
         for (ModuleBuilder module : sorted) {
             if (module != null) {
                 for (ModuleImport imp : module.getImports().values()) {
@@ -481,7 +481,7 @@ public final class YangParserImpl implements YangContextParser {
             final Map<String, TreeMap<Date, ModuleBuilder>> submodules) {
         Map<String, Date> includes = module.getIncludedModules();
         for (Map.Entry<String, Date> entry : includes.entrySet()) {
-            TreeMap<Date, ModuleBuilder> subs = submodules.get(entry.getKey());
+            NavigableMap<Date, ModuleBuilder> subs = submodules.get(entry.getKey());
             if (subs == null) {
                 throw new YangParseException("Failed to find references submodule " + entry.getKey() + " in module "
                         + module.getName());
@@ -563,8 +563,8 @@ public final class YangParserImpl implements YangContextParser {
      *            topologically sorted modules
      * @return modules ordered by namespace and revision
      */
-    private static LinkedHashMap<URI, TreeMap<Date, ModuleBuilder>> orderModules(final List<ModuleBuilder> modules) {
-        final LinkedHashMap<URI, TreeMap<Date, ModuleBuilder>> result = new LinkedHashMap<>();
+    private static Map<URI, TreeMap<Date, ModuleBuilder>> orderModules(final List<ModuleBuilder> modules) {
+        final Map<URI, TreeMap<Date, ModuleBuilder>> result = new LinkedHashMap<>();
         for (final ModuleBuilder builder : modules) {
             if (builder == null) {
                 continue;
@@ -1262,16 +1262,16 @@ public final class YangParserImpl implements YangContextParser {
             for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
                 final ModuleBuilder moduleBuilder = childEntry.getValue();
                 final Module module = moduleBuilder.build();
-                final List<ChoiceNode> allChoicesFromModule = getChoicesFrom(module);
+                final List<ChoiceSchemaNode> allChoicesFromModule = getChoicesFrom(module);
 
-                for (ChoiceNode choiceNode : allChoicesFromModule) {
+                for (ChoiceSchemaNode choiceNode : allChoicesFromModule) {
                     findDuplicityNodesIn(choiceNode, module, moduleBuilder, modules);
                 }
             }
         }
     }
 
-    private void findDuplicityNodesIn(final ChoiceNode choiceNode, final Module module, final ModuleBuilder moduleBuilder,
+    private void findDuplicityNodesIn(final ChoiceSchemaNode choiceNode, final Module module, final ModuleBuilder moduleBuilder,
             final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
         final Set<QName> duplicityTestSet = new HashSet<QName>();
 
@@ -1293,8 +1293,8 @@ public final class YangParserImpl implements YangContextParser {
         }
     }
 
-    private List<ChoiceNode> getChoicesFrom(final Module module) {
-        final List<ChoiceNode> allChoices = new ArrayList<ChoiceNode>();
+    private List<ChoiceSchemaNode> getChoicesFrom(final Module module) {
+        final List<ChoiceSchemaNode> allChoices = new ArrayList<ChoiceSchemaNode>();
 
         for (DataSchemaNode dataSchemaNode : module.getChildNodes()) {
             findChoicesIn(dataSchemaNode, allChoices);
@@ -1302,7 +1302,7 @@ public final class YangParserImpl implements YangContextParser {
         return allChoices;
     }
 
-    private void findChoicesIn(final SchemaNode schemaNode, final Collection<ChoiceNode> choiceNodes) {
+    private void findChoicesIn(final SchemaNode schemaNode, final Collection<ChoiceSchemaNode> choiceNodes) {
         if (schemaNode instanceof ContainerSchemaNode) {
             final ContainerSchemaNode contSchemaNode = (ContainerSchemaNode) schemaNode;
             for (DataSchemaNode dataSchemaNode : contSchemaNode.getChildNodes()) {
@@ -1313,8 +1313,8 @@ public final class YangParserImpl implements YangContextParser {
             for (DataSchemaNode dataSchemaNode : listSchemaNode.getChildNodes()) {
                 findChoicesIn(dataSchemaNode, choiceNodes);
             }
-        } else if (schemaNode instanceof ChoiceNode) {
-            choiceNodes.add((ChoiceNode) schemaNode);
+        } else if (schemaNode instanceof ChoiceSchemaNode) {
+            choiceNodes.add((ChoiceSchemaNode) schemaNode);
         }
     }