Minor code refactoring. 80/1880/1
authorMartin Vitez <mvitez@cisco.com>
Mon, 14 Oct 2013 16:03:00 +0000 (18:03 +0200)
committerMartin Vitez <mvitez@cisco.com>
Mon, 14 Oct 2013 16:08:58 +0000 (18:08 +0200)
 - fixed code formatting
 - removed redundant code
 - replaced explicitly defined generic type parameters with Java 7 diamond type '<>'
 - replaced too complex if/else statements with switch where possible
 - updated javadocs

Signed-off-by: Martin Vitez <mvitez@cisco.com>
13 files changed:
code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/RefineTest.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/CopyUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/GroupingUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/MustDefinitionImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ParserListenerUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/RefineUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TypeConstraints.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TypeUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/YangParseException.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java
yang/yang-parser-impl/src/test/resources/augment-test/rpc/bar.yang
yang/yang-parser-impl/src/test/resources/augment-test/rpc/foo.yang

index 92185784c9bdd2ccdff2cbe68c966f78b9268215..ecf545eae6e156c40a6dac9f6d93e297510f2127 100644 (file)
@@ -148,7 +148,7 @@ public class RefineTest {
         DataSchemaNodeBuilder builderData = new AnyXmlBuilder("module", 4, qname, createSchemaPath(qname));
 
         assertNotNull("Refine holder data wasn't initialized.", refHolderData);
-        RefineUtils.refineAnyxml((AnyXmlBuilder) builderData, refHolderData, 3);
+        RefineUtils.refineAnyxml((AnyXmlBuilder) builderData, refHolderData);
 
         // data node
         ConstraintsBuilder conDefData = builderData.getConstraints();
@@ -169,7 +169,7 @@ public class RefineTest {
         DataSchemaNodeBuilder builderChc2 = new ChoiceBuilder("module", 4, qname);
         assertNotNull("Refine holder chc2 wasn't initialized.", refHolderChc2);
 
-        RefineUtils.refineChoice((ChoiceBuilder) builderChc2, refHolderChc2, 3);
+        RefineUtils.refineChoice((ChoiceBuilder) builderChc2, refHolderChc2);
 
         // chc2 node
         ConstraintsBuilder conDefChc2 = builderChc2.getConstraints();
@@ -185,7 +185,7 @@ public class RefineTest {
 
         assertNotNull("Refine holder chc wasn't initialized.", refHolderChc);
         assertNotNull("Data schema node builder chc wasn't initialized.", builderChc);
-        RefineUtils.refineChoice((ChoiceBuilder) builderChc, refHolderChc, 2);
+        RefineUtils.refineChoice((ChoiceBuilder) builderChc, refHolderChc);
 
         ChoiceBuilder choiceBuilder = null;
         if (builderChc instanceof ChoiceBuilder) {
@@ -207,7 +207,7 @@ public class RefineTest {
 
         assertNotNull("Refine holder " + nodeName + " wasn't initialized.", refHolderLflst);
         assertNotNull("Data schema node builder " + nodeName + " wasn't initialized.", builderLflst);
-        RefineUtils.refineLeafList((LeafListSchemaNodeBuilder) builderLflst, refHolderLflst, 1);
+        RefineUtils.refineLeafList((LeafListSchemaNodeBuilder) builderLflst, refHolderLflst);
         // lflst node
 
         ConstraintsBuilder conDefLflst = builderLflst.getConstraints();
index 89b757561644065e18ad1ec56a785bbcefacc4cc..38b282de69c362bc8511c2bd002e718ad0dcad23 100644 (file)
@@ -47,7 +47,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
-import org.opendaylight.yangtools.yang.model.util.IdentityrefType;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
 import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
@@ -162,7 +161,7 @@ public final class YangParserImpl implements YangModelParser {
                 }
             }
 
-            return new LinkedHashSet<Module>(buildWithContext(modules, context).values());
+            return new LinkedHashSet<>(buildWithContext(modules, context).values());
         }
         return Collections.emptySet();
     }
@@ -178,7 +177,7 @@ public final class YangParserImpl implements YangModelParser {
             Map<ModuleBuilder, InputStream> builderToStreamMap = Maps.newHashMap();
             final Map<String, TreeMap<Date, ModuleBuilder>> modules = resolveModuleBuildersWithContext(
                     yangModelStreams, builderToStreamMap, context);
-            return new LinkedHashSet<Module>(buildWithContext(modules, context).values());
+            return new LinkedHashSet<>(buildWithContext(modules, context).values());
         }
         return Collections.emptySet();
     }
@@ -249,7 +248,7 @@ public final class YangParserImpl implements YangModelParser {
         final Map<InputStream, ModuleBuilder> builders = new LinkedHashMap<>();
 
         // validate yang
-        new YangModelBasicValidator(walker).validate(new ArrayList<ParseTree>(trees.values()));
+        new YangModelBasicValidator(walker).validate(new ArrayList<>(trees.values()));
 
         YangParserListenerImpl yangModelParser;
         for(Map.Entry<InputStream, ParseTree> entry : trees.entrySet()) {
@@ -275,7 +274,7 @@ public final class YangParserImpl implements YangModelParser {
             final SchemaContext context) {
         Map<InputStream, ModuleBuilder> parsedBuilders = parseModuleBuilders(yangFileStreams, streamToBuilderMap);
         ModuleBuilder[] builders = new ModuleBuilder[parsedBuilders.size()];
-        final ModuleBuilder[] moduleBuilders = new ArrayList<>(parsedBuilders.values()).toArray(builders);
+        parsedBuilders.values().toArray(builders);
 
         // module dependency graph sorted
         List<ModuleBuilder> sorted;
@@ -309,7 +308,7 @@ public final class YangParserImpl implements YangModelParser {
             }
             TreeMap<Date, ModuleBuilder> builderByRevision = result.get(builderName);
             if (builderByRevision == null) {
-                builderByRevision = new TreeMap<Date, ModuleBuilder>();
+                builderByRevision = new TreeMap<>();
             }
             builderByRevision.put(builderRevision, builder);
             result.put(builderName, builderByRevision);
@@ -375,7 +374,7 @@ public final class YangParserImpl implements YangModelParser {
         resolveDeviations(modules);
 
         // build
-        final Map<ModuleBuilder, Module> result = new LinkedHashMap<ModuleBuilder, Module>();
+        final Map<ModuleBuilder, Module> result = new LinkedHashMap<>();
         for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
                 final ModuleBuilder moduleBuilder = childEntry.getValue();
@@ -398,7 +397,7 @@ public final class YangParserImpl implements YangModelParser {
         resolveDeviationsWithContext(modules, context);
 
         // build
-        final Map<ModuleBuilder, Module> result = new LinkedHashMap<ModuleBuilder, Module>();
+        final Map<ModuleBuilder, Module> result = new LinkedHashMap<>();
         for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
                 final ModuleBuilder moduleBuilder = childEntry.getValue();
@@ -1040,18 +1039,16 @@ public final class YangParserImpl implements YangModelParser {
             if (prefix == null) {
                 prefix = module.getPrefix();
             }
-            String name = null;
 
             ModuleBuilder dependentModuleBuilder = findModuleFromBuilders(modules, module, prefix, line);
             if (dependentModuleBuilder == null) {
-                Module dependentModule = findModuleFromContext(context, module, prefix, line);
-                Object currentParent = dependentModule;
+                Object currentParent = findModuleFromContext(context, module, prefix, line);
 
                 for (QName q : path) {
                     if (currentParent == null) {
                         throw new YangParseException(module.getName(), line, FAIL_DEVIATION_TARGET);
                     }
-                    name = q.getLocalName();
+                    String name = q.getLocalName();
                     if (currentParent instanceof DataNodeContainer) {
                         currentParent = ((DataNodeContainer) currentParent).getDataChildByName(name);
                     }
index f56e7623df743482fcebdb6088e66aefb9b01747..d9858bc3cc6e56d10d1f9a60e9ec9682247538b0 100644 (file)
@@ -63,9 +63,13 @@ public final class CopyUtils {
      * true, qname of node will be corrected based on new parent.
      * 
      * @param old
+     *            builder to copy
      * @param newParent
+     *            new parent
      * @param updateQName
-     * @return copy
+     *            flag to indicate if qname should be updated based on new
+     *            parent location
+     * @return copy of given builder
      */
     public static DataSchemaNodeBuilder copy(DataSchemaNodeBuilder old, Builder newParent, boolean updateQName) {
         if (old instanceof AnyXmlBuilder) {
@@ -357,7 +361,7 @@ public final class CopyUtils {
         DataBean data = getdata(old, newParent, updateQName);
         QName newQName = data.qname;
         SchemaPath newSchemaPath = data.schemaPath;
-        TypeDefinitionBuilder type = null;
+        TypeDefinitionBuilder type;
 
         if (old instanceof UnionTypeBuilder) {
             UnionTypeBuilder oldUnion = (UnionTypeBuilder) old;
@@ -568,7 +572,9 @@ public final class CopyUtils {
      * Create AnyXmlBuilder from given AnyXmlSchemaNode.
      * 
      * @param anyxml
+     *            base anyxml
      * @param qname
+     *            new qname
      * @param moduleName
      *            current module name
      * @param line
@@ -587,7 +593,9 @@ public final class CopyUtils {
      * Create GroupingBuilder from given GroupingDefinition.
      * 
      * @param grouping
+     *            base grouping
      * @param qname
+     *            new qname
      * @param moduleName
      *            current module name
      * @param line
@@ -612,7 +620,9 @@ public final class CopyUtils {
      * Create TypeDefinitionBuilder from given ExtendedType.
      * 
      * @param typedef
+     *            base typedef
      * @param qname
+     *            new qname
      * @param moduleName
      *            current module name
      * @param line
@@ -642,7 +652,9 @@ public final class CopyUtils {
      * Create UnknownSchemaNodeBuilder from given UnknownSchemaNode.
      * 
      * @param unknownNode
+     *            base unknown node
      * @param qname
+     *            new qname
      * @param moduleName
      *            current module name
      * @param line
@@ -669,6 +681,7 @@ public final class CopyUtils {
      * @param leaf
      *            leaf from which to create builder
      * @param qname
+     *            new qname
      * @param moduleName
      *            current module name
      * @param line
@@ -692,7 +705,9 @@ public final class CopyUtils {
      * Create ContainerSchemaNodeBuilder from given ContainerSchemaNode.
      * 
      * @param container
+     *            base container
      * @param qname
+     *            new qname
      * @param moduleName
      *            current module name
      * @param line
@@ -719,7 +734,9 @@ public final class CopyUtils {
      * Create ListSchemaNodeBuilder from given ListSchemaNode.
      * 
      * @param list
+     *            base list
      * @param qname
+     *            new qname
      * @param moduleName
      *            current module name
      * @param line
@@ -744,7 +761,9 @@ public final class CopyUtils {
      * Create LeafListSchemaNodeBuilder from given LeafListSchemaNode.
      * 
      * @param leafList
+     *            base leaf-list
      * @param qname
+     *            new qname
      * @param moduleName
      *            current module name
      * @param line
@@ -767,7 +786,9 @@ public final class CopyUtils {
      * Create ChoiceBuilder from given ChoiceNode.
      * 
      * @param choice
+     *            base choice
      * @param qname
+     *            new qname
      * @param moduleName
      *            current module name
      * @param line
index 6f3bb1757ab261fcf59ecb1cb1e267a45433088c..14718e6a4bcf132cf4abe378ed06a44a52c22094 100644 (file)
@@ -81,7 +81,7 @@ public final class GroupingUtils {
             groupingName = groupingString;
         }
 
-        ModuleBuilder dependentModule = null;
+        ModuleBuilder dependentModule;
         if (groupingPrefix.equals(module.getPrefix())) {
             dependentModule = module;
         } else {
@@ -92,7 +92,7 @@ public final class GroupingUtils {
             return null;
         }
 
-        GroupingBuilder result = null;
+        GroupingBuilder result;
         Set<GroupingBuilder> groupings = dependentModule.getGroupingBuilders();
         result = findGroupingBuilder(groupings, groupingName);
         if (result != null) {
@@ -196,6 +196,7 @@ public final class GroupingUtils {
      * Add nodes defined in uses target grouping to uses parent.
      *
      * @param usesNode
+     *            yang uses node which will be instantiated in current location
      */
     public static void updateUsesParent(UsesNodeBuilder usesNode) {
         DataNodeContainerBuilder parent = usesNode.getParent();
@@ -205,10 +206,8 @@ public final class GroupingUtils {
         String prefix = module.getPrefix();
 
         SchemaPath parentPath = parent.getPath();
-
-
-        if(parent instanceof AugmentationSchemaBuilder) {
-            parentPath = ((AugmentationSchemaBuilder)parent).getTargetNodeSchemaPath();
+        if (parent instanceof AugmentationSchemaBuilder) {
+            parentPath = ((AugmentationSchemaBuilder) parent).getTargetNodeSchemaPath();
         }
 
         // child nodes
@@ -217,19 +216,25 @@ public final class GroupingUtils {
                 ((GroupingMember) child).setAddedByUses(true);
             }
 
-            GroupingMember gm = (GroupingMember) child;
-            if (gm.isAddedByUses()) {
-                if(usesNode.isAugmenting()) {
-                    child.setAugmenting(true);
-                }
-                if(usesNode.isAugmenting() && !(usesNode.getParentAugment().getParent() instanceof UsesNodeBuilder)) {
-                    AugmentationSchemaBuilder parentAugment = usesNode.getParentAugment();
-                    ModuleBuilder m = ParserUtils.getParentModule(parentAugment);
-                    correctNodePathForUsesNodes(child, parentPath, m);
-                } else {
-                    child.setQName(new QName(ns, rev, prefix, child.getQName().getLocalName()));
-                    correctNodePathForUsesNodes(child, parentPath, module);
+            if (child instanceof GroupingMember) {
+                GroupingMember gm = (GroupingMember) child;
+                if (gm.isAddedByUses()) {
+                    if (usesNode.isAugmenting()) {
+                        child.setAugmenting(true);
+                    }
+                    if (usesNode.isAugmenting()
+                            && !(usesNode.getParentAugment().getParent() instanceof UsesNodeBuilder)) {
+                        AugmentationSchemaBuilder parentAugment = usesNode.getParentAugment();
+                        ModuleBuilder m = ParserUtils.getParentModule(parentAugment);
+                        correctNodePathForUsesNodes(child, parentPath, m);
+                    } else {
+                        child.setQName(new QName(ns, rev, prefix, child.getQName().getLocalName()));
+                        correctNodePathForUsesNodes(child, parentPath, module);
+                    }
                 }
+            } else {
+                throw new YangParseException(module.getName(), usesNode.getLine(),
+                        "Failed to process uses node: unresolved child node");
             }
 
             parent.addChildNode(child);
@@ -279,17 +284,17 @@ public final class GroupingUtils {
      * Read child nodes defined in target grouping and make a copy of them.
      *
      * @param usesNode
-     * @return copy of child nodes defined in uses target grouping
+     *            uses node for which data will be collected
      */
     private static void collectTargetChildNodes(UsesNodeBuilder usesNode) {
         final GroupingBuilder target = usesNode.getGroupingBuilder();
         final Set<DataSchemaNodeBuilder> collection = new HashSet<>();
-        addChildNodeToCollection(usesNode, collection, target.getChildNodeBuilders());
+        addChildNodeToCollection(usesNode, collection, target.getChildNodeBuilders(), usesNode.getParent());
 
         for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
             Set<DataSchemaNodeBuilder> targetUsesChildNodes = collectTargetUsesChildNodes(targetUses,
                     usesNode.getParent());
-            addChildNodeToCollection(usesNode, collection, targetUsesChildNodes);
+            addChildNodeToCollection(usesNode, collection, targetUsesChildNodes, usesNode.getParent());
         }
         usesNode.getTargetChildren().addAll(collection);
     }
@@ -298,17 +303,17 @@ public final class GroupingUtils {
             DataNodeContainerBuilder parent) {
         final GroupingBuilder target = usesNode.getGroupingBuilder();
         final Set<DataSchemaNodeBuilder> collection = new HashSet<>(usesNode.getTargetChildren());
-        addChildNodeToCollection(usesNode, collection, target.getChildNodeBuilders());
+        addChildNodeToCollection(usesNode, collection, target.getChildNodeBuilders(), parent);
 
         for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
             Set<DataSchemaNodeBuilder> targetUsesChildNodes = collectTargetUsesChildNodes(targetUses, parent);
-            addChildNodeToCollection(usesNode, collection, targetUsesChildNodes);
+            addChildNodeToCollection(usesNode, collection, targetUsesChildNodes, parent);
         }
         return collection;
     }
 
     private static void addChildNodeToCollection(UsesNodeBuilder usesNode, Set<DataSchemaNodeBuilder> collection,
-            Set<DataSchemaNodeBuilder> allNodes) {
+            Set<DataSchemaNodeBuilder> allNodes, Builder parent) {
         for (DataSchemaNodeBuilder childNode : allNodes) {
             boolean exists = false;
             for (DataSchemaNodeBuilder usesChildNode : usesNode.getTargetChildren()) {
@@ -318,7 +323,7 @@ public final class GroupingUtils {
                 }
             }
             if (!exists) {
-                DataSchemaNodeBuilder copy = CopyUtils.copy(childNode, usesNode.getParent(), true);
+                DataSchemaNodeBuilder copy = CopyUtils.copy(childNode, parent, true);
                 collection.add(copy);
             }
         }
@@ -328,16 +333,16 @@ public final class GroupingUtils {
      * Read typedefs defined in target grouping and make a copy of them.
      *
      * @param usesNode
-     * @return copy of typedefs defined in uses target grouping
+     *            uses node for which data will be collected
      */
     private static void collectTargetTypedefs(UsesNodeBuilder usesNode) {
         final GroupingBuilder target = usesNode.getGroupingBuilder();
         Set<TypeDefinitionBuilder> collection = new HashSet<>();
-        addTypedefToCollection(usesNode, collection, target.getTypeDefinitionBuilders());
+        addTypedefToCollection(usesNode, collection, target.getTypeDefinitionBuilders(), usesNode.getParent());
 
         for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
             Set<TypeDefinitionBuilder> targetUsesTypedefs = collectTargetUsesTypedefs(targetUses, usesNode.getParent());
-            addTypedefToCollection(usesNode, collection, targetUsesTypedefs);
+            addTypedefToCollection(usesNode, collection, targetUsesTypedefs, usesNode.getParent());
         }
         usesNode.getTargetTypedefs().addAll(collection);
     }
@@ -346,17 +351,17 @@ public final class GroupingUtils {
             DataNodeContainerBuilder parent) {
         final GroupingBuilder target = usesNode.getGroupingBuilder();
         Set<TypeDefinitionBuilder> collection = new HashSet<>(usesNode.getTargetTypedefs());
-        addTypedefToCollection(usesNode, collection, target.getTypeDefinitionBuilders());
+        addTypedefToCollection(usesNode, collection, target.getTypeDefinitionBuilders(), parent);
 
         for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
             Set<TypeDefinitionBuilder> targetUsesTypedefs = collectTargetUsesTypedefs(targetUses, parent);
-            addTypedefToCollection(usesNode, collection, targetUsesTypedefs);
+            addTypedefToCollection(usesNode, collection, targetUsesTypedefs, parent);
         }
         return collection;
     }
 
     private static void addTypedefToCollection(UsesNodeBuilder usesNode, Set<TypeDefinitionBuilder> collection,
-            Set<TypeDefinitionBuilder> allTypedefs) {
+            Set<TypeDefinitionBuilder> allTypedefs, Builder parent) {
         for (TypeDefinitionBuilder childNode : allTypedefs) {
             boolean exists = false;
             for (TypeDefinitionBuilder usesTypedef : usesNode.getTargetTypedefs()) {
@@ -366,7 +371,7 @@ public final class GroupingUtils {
                 }
             }
             if (!exists) {
-                TypeDefinitionBuilder copy = CopyUtils.copy(childNode, usesNode.getParent(), true);
+                TypeDefinitionBuilder copy = CopyUtils.copy(childNode, parent, true);
                 collection.add(copy);
             }
         }
@@ -376,16 +381,16 @@ public final class GroupingUtils {
      * Read groupings defined in target grouping and make a copy of them.
      *
      * @param usesNode
-     * @return copy of groupings defined in uses target grouping
+     *            uses node for which data will be collected
      */
     private static void collectTargetGroupings(UsesNodeBuilder usesNode) {
         final GroupingBuilder target = usesNode.getGroupingBuilder();
         Set<GroupingBuilder> collection = new HashSet<>();
-        addGroupingToCollection(usesNode, collection, target.getGroupingBuilders());
+        addGroupingToCollection(usesNode, collection, target.getGroupingBuilders(), usesNode.getParent());
 
         for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
             Set<GroupingBuilder> targetUsesGrouping = collectTargetGroupings(targetUses, usesNode.getParent());
-            addGroupingToCollection(usesNode, collection, targetUsesGrouping);
+            addGroupingToCollection(usesNode, collection, targetUsesGrouping, usesNode.getParent());
         }
         usesNode.getTargetGroupings().addAll(collection);
     }
@@ -393,17 +398,17 @@ public final class GroupingUtils {
     private static Set<GroupingBuilder> collectTargetGroupings(UsesNodeBuilder usesNode, DataNodeContainerBuilder parent) {
         final GroupingBuilder target = usesNode.getGroupingBuilder();
         Set<GroupingBuilder> collection = new HashSet<>(usesNode.getTargetGroupings());
-        addGroupingToCollection(usesNode, collection, target.getGroupingBuilders());
+        addGroupingToCollection(usesNode, collection, target.getGroupingBuilders(), parent);
 
         for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
             Set<GroupingBuilder> targetUsesGroupings = collectTargetGroupings(targetUses, parent);
-            addGroupingToCollection(usesNode, collection, targetUsesGroupings);
+            addGroupingToCollection(usesNode, collection, targetUsesGroupings, parent);
         }
         return collection;
     }
 
     private static void addGroupingToCollection(UsesNodeBuilder usesNode, Set<GroupingBuilder> collection,
-            Set<GroupingBuilder> allGroupings) {
+            Set<GroupingBuilder> allGroupings, Builder parent) {
         for (GroupingBuilder childNode : allGroupings) {
             boolean exists = false;
             for (GroupingBuilder usesGrouping : usesNode.getTargetGroupings()) {
@@ -413,7 +418,7 @@ public final class GroupingUtils {
                 }
             }
             if (!exists) {
-                GroupingBuilder copy = CopyUtils.copy(childNode, usesNode.getParent(), true);
+                GroupingBuilder copy = CopyUtils.copy(childNode, parent, true);
                 collection.add(copy);
             }
         }
@@ -423,17 +428,17 @@ public final class GroupingUtils {
      * Read unknown nodes defined in target grouping and make a copy of them.
      *
      * @param usesNode
-     * @return copy of unknown nodes defined in uses target grouping
+     *            uses node for which data will be collected
      */
     private static void collectTargetUnknownNodes(UsesNodeBuilder usesNode) {
         final GroupingBuilder target = usesNode.getGroupingBuilder();
         final List<UnknownSchemaNodeBuilder> collection = new ArrayList<>();
-        addUnknownNodeToCollection(usesNode, collection, target.getUnknownNodeBuilders());
+        addUnknownNodeToCollection(usesNode, collection, target.getUnknownNodeBuilders(), usesNode.getParent());
 
         for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
             List<UnknownSchemaNodeBuilder> targetUsesUnknownNodes = collectTargetUnknownNodes(targetUses,
                     usesNode.getParent());
-            addUnknownNodeToCollection(usesNode, collection, targetUsesUnknownNodes);
+            addUnknownNodeToCollection(usesNode, collection, targetUsesUnknownNodes, usesNode.getParent());
         }
         usesNode.getTargetUnknownNodes().addAll(collection);
     }
@@ -442,17 +447,17 @@ public final class GroupingUtils {
             DataNodeContainerBuilder parent) {
         final GroupingBuilder target = usesNode.getGroupingBuilder();
         List<UnknownSchemaNodeBuilder> collection = new ArrayList<>(usesNode.getTargetUnknownNodes());
-        addUnknownNodeToCollection(usesNode, collection, target.getUnknownNodeBuilders());
+        addUnknownNodeToCollection(usesNode, collection, target.getUnknownNodeBuilders(), parent);
 
         for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
             List<UnknownSchemaNodeBuilder> targetUsesUnknownNodes = collectTargetUnknownNodes(targetUses, parent);
-            addUnknownNodeToCollection(usesNode, collection, targetUsesUnknownNodes);
+            addUnknownNodeToCollection(usesNode, collection, targetUsesUnknownNodes, parent);
         }
         return collection;
     }
 
     private static void addUnknownNodeToCollection(UsesNodeBuilder usesNode, List<UnknownSchemaNodeBuilder> collection,
-            List<UnknownSchemaNodeBuilder> allUnknownNodes) {
+            List<UnknownSchemaNodeBuilder> allUnknownNodes, Builder parent) {
         for (UnknownSchemaNodeBuilder childNode : allUnknownNodes) {
             boolean exists = false;
             for (UnknownSchemaNodeBuilder usesUnknownNode : usesNode.getTargetUnknownNodes()) {
@@ -462,7 +467,7 @@ public final class GroupingUtils {
                 }
             }
             if (!exists) {
-                UnknownSchemaNodeBuilder copy = CopyUtils.copy(childNode, usesNode.getParent(), true);
+                UnknownSchemaNodeBuilder copy = CopyUtils.copy(childNode, parent, true);
                 collection.add(copy);
             }
         }
@@ -562,10 +567,8 @@ public final class GroupingUtils {
                     throw new YangParseException(moduleName, lineNumber,
                             "Unknown member of target grouping while resolving uses node.");
                 }
-                if (newChild instanceof GroupingMember) {
-                    ((GroupingMember) newChild).setAddedByUses(true);
-                }
 
+                ((GroupingMember) newChild).setAddedByUses(true);
                 newChildren.add(newChild);
             }
         }
@@ -586,7 +589,7 @@ public final class GroupingUtils {
     private static void correctNodePathForUsesNodes(final SchemaNodeBuilder node, final SchemaPath parentSchemaPath,
             final ModuleBuilder parentModule) {
         // set correct path
-        List<QName> targetNodePath = new ArrayList<QName>(parentSchemaPath.getPath());
+        List<QName> targetNodePath = new ArrayList<>(parentSchemaPath.getPath());
         targetNodePath.add(new QName(parentModule.getNamespace(), parentModule.getRevision(), parentModule.getPrefix(),
                 node.getQName().getLocalName()));
         node.setPath(new SchemaPath(targetNodePath, true));
@@ -613,6 +616,7 @@ public final class GroupingUtils {
      * already performed.
      *
      * @param usesNode
+     *            uses node containing refine statements
      */
     public static void performRefine(UsesNodeBuilder usesNode) {
         for (RefineHolder refine : usesNode.getRefines()) {
index c1cb4a51d7d5337884524a0bde3a5a3e247e9847..d0b232c550c133f2aae369180ace3835292e5a99 100644 (file)
@@ -17,8 +17,7 @@ final class MustDefinitionImpl implements MustDefinition {
     private final String errorAppTag;
     private final String errorMessage;
 
-    MustDefinitionImpl(String mustStr, String description, String reference,
-            String errorAppTag, String errorMessage) {
+    MustDefinitionImpl(String mustStr, String description, String reference, String errorAppTag, String errorMessage) {
         this.mustStr = mustStr;
         this.description = description;
         this.reference = reference;
@@ -56,10 +55,8 @@ final class MustDefinitionImpl implements MustDefinition {
         final int prime = 31;
         int result = 1;
         result = prime * result + ((mustStr == null) ? 0 : mustStr.hashCode());
-        result = prime * result
-                + ((description == null) ? 0 : description.hashCode());
-        result = prime * result
-                + ((reference == null) ? 0 : reference.hashCode());
+        result = prime * result + ((description == null) ? 0 : description.hashCode());
+        result = prime * result + ((reference == null) ? 0 : reference.hashCode());
         return result;
     }
 
index 505fa97dee12ef3c4e633b3f388d542220de1e00..917a001c6b449385a27d342e2735a5416bea41a5 100644 (file)
@@ -112,7 +112,6 @@ import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceCaseBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ConstraintsBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder;
@@ -183,13 +182,17 @@ public final class ParserListenerUtils {
             ParseTree statusArg = ctx.getChild(i);
             if (statusArg instanceof Status_argContext) {
                 String statusArgStr = stringFromNode(statusArg);
-                if ("current".equals(statusArgStr)) {
+                switch (statusArgStr) {
+                case "current":
                     result = Status.CURRENT;
-                } else if ("deprecated".equals(statusArgStr)) {
+                    break;
+                case "deprecated":
                     result = Status.DEPRECATED;
-                } else if ("obsolete".equals(statusArgStr)) {
+                    break;
+                case "obsolete":
                     result = Status.OBSOLETE;
-                } else {
+                    break;
+                default:
                     LOG.warn("Invalid 'status' statement: " + statusArgStr);
                 }
             }
@@ -245,7 +248,7 @@ public final class ParserListenerUtils {
      * @return SchemaPath object
      */
     public static SchemaPath createActualSchemaPath(final Stack<QName> actualPath) {
-        final List<QName> path = new ArrayList<QName>(actualPath);
+        final List<QName> path = new ArrayList<>(actualPath);
         return new SchemaPath(path, true);
     }
 
@@ -265,10 +268,10 @@ public final class ParserListenerUtils {
      */
     public static List<QName> createListKey(final String keyDefinition, final URI namespace, final Date revision,
             final String prefix) {
-        List<QName> key = new ArrayList<QName>();
+        List<QName> key = new ArrayList<>();
         String[] splittedKey = keyDefinition.split(" ");
 
-        QName qname = null;
+        QName qname;
         for (String keyElement : splittedKey) {
             if (keyElement.length() != 0) {
                 qname = new QName(namespace, revision, prefix, keyElement);
@@ -291,7 +294,7 @@ public final class ParserListenerUtils {
      */
     private static List<EnumTypeDefinition.EnumPair> getEnumConstants(final Type_body_stmtsContext ctx,
             final Stack<QName> path, final String moduleName) {
-        List<EnumTypeDefinition.EnumPair> enumConstants = new ArrayList<EnumTypeDefinition.EnumPair>();
+        List<EnumTypeDefinition.EnumPair> enumConstants = new ArrayList<>();
 
         for (int i = 0; i < ctx.getChildCount(); i++) {
             ParseTree enumSpecChild = ctx.getChild(i);
@@ -319,7 +322,7 @@ public final class ParserListenerUtils {
      *            enum statement context
      * @param highestValue
      *            current highest value in enumeration
-     * @param path
+     * @param actualPath
      *            actual position in YANG model
      * @param moduleName
      *            current module name
@@ -495,6 +498,7 @@ public final class ParserListenerUtils {
      * @param ctx
      *            type body context to parse
      * @param moduleName
+     *            name of current module
      * @return List of RangeConstraint created from this context
      */
     private static List<RangeConstraint> getRangeConstraints(final Type_body_stmtsContext ctx, final String moduleName) {
@@ -520,11 +524,12 @@ public final class ParserListenerUtils {
      * @param ctx
      *            range context to parse
      * @param moduleName
+     *            name of current module
      * @return List of RangeConstraints parsed from this context
      */
     private static List<RangeConstraint> parseRangeConstraints(final Range_stmtContext ctx, final String moduleName) {
         final int line = ctx.getStart().getLine();
-        List<RangeConstraint> rangeConstraints = new ArrayList<RangeConstraint>();
+        List<RangeConstraint> rangeConstraints = new ArrayList<>();
         String description = null;
         String reference = null;
 
@@ -563,6 +568,7 @@ public final class ParserListenerUtils {
      * @param ctx
      *            type body context to parse
      * @param moduleName
+     *            name of current module
      * @return List of LengthConstraint created from this context
      */
     private static List<LengthConstraint> getLengthConstraints(final Type_body_stmtsContext ctx, final String moduleName) {
@@ -588,11 +594,12 @@ public final class ParserListenerUtils {
      * @param ctx
      *            length context to parse
      * @param moduleName
+     *            name of current module
      * @return List of LengthConstraints parsed from this context
      */
     private static List<LengthConstraint> parseLengthConstraints(final Length_stmtContext ctx, final String moduleName) {
         final int line = ctx.getStart().getLine();
-        List<LengthConstraint> lengthConstraints = new ArrayList<LengthConstraint>();
+        List<LengthConstraint> lengthConstraints = new ArrayList<>();
         String description = null;
         String reference = null;
 
@@ -636,7 +643,7 @@ public final class ParserListenerUtils {
      *         type is one of special YANG values 'min' or 'max'
      */
     private static Number parseNumberConstraintValue(final String value, final String moduleName, final int line) {
-        Number result = null;
+        Number result;
         if ("min".equals(value) || "max".equals(value)) {
             result = new UnknownBoundaryNumber(value);
         } else {
@@ -657,7 +664,7 @@ public final class ParserListenerUtils {
      * @return list of pattern constraints
      */
     private static List<PatternConstraint> getPatternConstraint(final Type_body_stmtsContext ctx) {
-        List<PatternConstraint> patterns = new ArrayList<PatternConstraint>();
+        List<PatternConstraint> patterns = new ArrayList<>();
 
         for (int i = 0; i < ctx.getChildCount(); i++) {
             ParseTree stringRestrChild = ctx.getChild(i);
@@ -779,7 +786,7 @@ public final class ParserListenerUtils {
      */
     private static List<BitsTypeDefinition.Bit> getBits(Type_body_stmtsContext ctx, Stack<QName> actualPath,
             String moduleName) {
-        final List<BitsTypeDefinition.Bit> bits = new ArrayList<BitsTypeDefinition.Bit>();
+        final List<BitsTypeDefinition.Bit> bits = new ArrayList<>();
         for (int j = 0; j < ctx.getChildCount(); j++) {
             ParseTree bitsSpecChild = ctx.getChild(j);
             if (bitsSpecChild instanceof Bits_specificationContext) {
@@ -867,11 +874,14 @@ public final class ParserListenerUtils {
             ParseTree orderArg = ctx.getChild(j);
             if (orderArg instanceof Ordered_by_argContext) {
                 String orderStr = stringFromNode(orderArg);
-                if ("system".equals(orderStr)) {
+                switch (orderStr) {
+                case "system":
                     result = false;
-                } else if ("user".equals(orderStr)) {
+                    break;
+                case "user":
                     result = true;
-                } else {
+                    break;
+                default:
                     LOG.warn("Invalid 'ordered-by' statement.");
                 }
             }
@@ -894,7 +904,7 @@ public final class ParserListenerUtils {
      * @return config statement parsed from given context
      */
     public static Boolean getConfig(final ParseTree ctx, final Builder parent, final String moduleName, final int line) {
-        Boolean result = null;
+        Boolean result;
         // parse configuration statement
         Boolean config = null;
         for (int i = 0; i < ctx.getChildCount(); i++) {
@@ -913,18 +923,6 @@ public final class ParserListenerUtils {
                 // If the parent node is a rpc input or output, it can has
                 // config set to null
                 result = parentConfig == null ? true : parentConfig;
-            } else if (parent instanceof ChoiceCaseBuilder) {
-                // If the parent node is a 'case' node, the value is the same as
-                // the 'case' node's parent 'choice' node
-                ChoiceCaseBuilder choiceCase = (ChoiceCaseBuilder) parent;
-                Builder choice = choiceCase.getParent();
-                Boolean parentConfig = null;
-                if (choice instanceof ChoiceBuilder) {
-                    parentConfig = ((ChoiceBuilder) choice).isConfiguration();
-                } else {
-                    parentConfig = true;
-                }
-                result = parentConfig;
             } else {
                 result = true;
             }
@@ -960,13 +958,14 @@ public final class ParserListenerUtils {
                 final ParseTree configContext = ctx.getChild(i);
                 if (configContext instanceof Config_argContext) {
                     final String value = stringFromNode(configContext);
-                    if ("true".equals(value)) {
+                    switch (value) {
+                    case "true":
                         result = true;
                         break;
-                    } else if ("false".equals(value)) {
+                    case "false":
                         result = false;
                         break;
-                    } else {
+                    default:
                         throw new YangParseException(moduleName, ctx.getStart().getLine(),
                                 "Failed to parse 'config' statement value: '" + value + "'.");
                     }
@@ -984,10 +983,15 @@ public final class ParserListenerUtils {
      * @param ctx
      *            type body
      * @param actualPath
+     *            actual path in model
      * @param namespace
+     *            module namespace
      * @param revision
+     *            module revision
      * @param prefix
+     *            module prefix
      * @param parent
+     *            current node parent
      * @return UnknownType object with constraints from parsed type body
      */
     public static TypeDefinition<?> parseUnknownTypeWithBody(final QName typedefQName,
@@ -1013,7 +1017,6 @@ public final class ParserListenerUtils {
                 return unknownType.build();
             } else {
                 TypeDefinition<?> baseType = unknownType.build();
-                TypeDefinition<?> result = null;
                 QName qname = new QName(namespace, revision, prefix, typeName);
                 SchemaPath schemaPath = createTypePath(actualPath, typeName);
 
@@ -1022,9 +1025,8 @@ public final class ParserListenerUtils {
                 typeBuilder.lengths(lengthStatements);
                 typeBuilder.patterns(patternStatements);
                 typeBuilder.fractionDigits(fractionDigits);
-                result = typeBuilder.build();
 
-                return result;
+                return typeBuilder.build();
             }
         }
 
@@ -1089,14 +1091,19 @@ public final class ParserListenerUtils {
             baseType = decimalType;
         } else if (typeName.startsWith("int")) {
             IntegerTypeDefinition intType = null;
-            if ("int8".equals(typeName)) {
+            switch (typeName) {
+            case "int8":
                 intType = Int8.getInstance();
-            } else if ("int16".equals(typeName)) {
+                break;
+            case "int16":
                 intType = Int16.getInstance();
-            } else if ("int32".equals(typeName)) {
+                break;
+            case "int32":
                 intType = Int32.getInstance();
-            } else if ("int64".equals(typeName)) {
+                break;
+            case "int64":
                 intType = Int64.getInstance();
+                break;
             }
             if (intType == null) {
                 throw new YangParseException(moduleName, line, "Unknown yang type " + typeName);
@@ -1105,14 +1112,19 @@ public final class ParserListenerUtils {
             baseType = intType;
         } else if (typeName.startsWith("uint")) {
             UnsignedIntegerTypeDefinition uintType = null;
-            if ("uint8".equals(typeName)) {
+            switch (typeName) {
+            case "uint8":
                 uintType = Uint8.getInstance();
-            } else if ("uint16".equals(typeName)) {
+                break;
+            case "uint16":
                 uintType = Uint16.getInstance();
-            } else if ("uint32".equals(typeName)) {
+                break;
+            case "uint32":
                 uintType = Uint32.getInstance();
-            } else if ("uint64".equals(typeName)) {
+                break;
+            case "uint64":
                 uintType = Uint64.getInstance();
+                break;
             }
             if (uintType == null) {
                 throw new YangParseException(moduleName, line, "Unknown yang type " + typeName);
@@ -1151,35 +1163,31 @@ public final class ParserListenerUtils {
             return baseType;
         }
 
-        TypeDefinition<?> result = null;
-        ExtendedType.Builder typeBuilder = null;
-
-        List<QName> path = new ArrayList<QName>(actualPath);
+        List<QName> path = new ArrayList<>(actualPath);
         path.add(new QName(namespace, revision, prefix, typeName));
         SchemaPath schemaPath = new SchemaPath(path, true);
 
         QName qname = schemaPath.getPath().get(schemaPath.getPath().size() - 1);
-        typeBuilder = new ExtendedType.Builder(qname, baseType, "", "", schemaPath);
+        ExtendedType.Builder typeBuilder = new ExtendedType.Builder(qname, baseType, "", "", schemaPath);
 
         typeBuilder.ranges(constraints.getRange());
         typeBuilder.lengths(constraints.getLength());
         typeBuilder.patterns(constraints.getPatterns());
         typeBuilder.fractionDigits(constraints.getFractionDigits());
 
-        result = typeBuilder.build();
-        return result;
+        return typeBuilder.build();
     }
 
     private static SchemaPath createTypePath(Stack<QName> actual, String typeName) {
         QName last = actual.peek();
         QName typeQName = new QName(last.getNamespace(), last.getRevision(), last.getPrefix(), typeName);
-        List<QName> path = new ArrayList<QName>(actual);
+        List<QName> path = new ArrayList<>(actual);
         path.add(typeQName);
         return new SchemaPath(path, true);
     }
 
     private static SchemaPath createBaseTypePath(Stack<QName> actual, String typeName) {
-        List<QName> path = new ArrayList<QName>(actual);
+        List<QName> path = new ArrayList<>(actual);
         path.add(BaseTypes.constructQName(typeName));
         return new SchemaPath(path, true);
     }
@@ -1188,7 +1196,7 @@ public final class ParserListenerUtils {
             String prefix, String typeName) {
         QName extTypeName = new QName(namespace, revision, prefix, typeName);
         QName baseTypeName = BaseTypes.constructQName(typeName);
-        List<QName> path = new ArrayList<QName>(actual);
+        List<QName> path = new ArrayList<>(actual);
         path.add(extTypeName);
         path.add(baseTypeName);
         return new SchemaPath(path, true);
@@ -1311,9 +1319,7 @@ public final class ParserListenerUtils {
             }
         }
 
-        MustDefinition must = new MustDefinitionImpl(mustText.toString(), description, reference, errorAppTag,
-                errorMessage);
-        return must;
+        return new MustDefinitionImpl(mustText.toString(), description, reference, errorAppTag, errorMessage);
     }
 
     /**
@@ -1427,18 +1433,19 @@ public final class ParserListenerUtils {
      *             informations in its body
      */
     public static void checkMissingBody(final String typeName, final String moduleName, final int line) {
-        if ("decimal64".equals(typeName)) {
+        switch (typeName) {
+        case "decimal64":
             throw new YangParseException(moduleName, line,
                     "The 'fraction-digits' statement MUST be present if the type is 'decimal64'.");
-        } else if ("identityref".equals(typeName)) {
+        case "identityref":
             throw new YangParseException(moduleName, line,
                     "The 'base' statement MUST be present if the type is 'identityref'.");
-        } else if ("leafref".equals(typeName)) {
+        case "leafref":
             throw new YangParseException(moduleName, line,
                     "The 'path' statement MUST be present if the type is 'leafref'.");
-        } else if ("bits".equals(typeName)) {
+        case "bits":
             throw new YangParseException(moduleName, line, "The 'bit' statement MUST be present if the type is 'bits'.");
-        } else if ("enumeration".equals(typeName)) {
+        case "enumeration":
             throw new YangParseException(moduleName, line,
                     "The 'enum' statement MUST be present if the type is 'enumeration'.");
         }
index 53e5205d9efbc1ea79e306487a54a65b1dead6a7..b499fdbce43a2ab32198693def65ae295f12ea13 100644 (file)
@@ -55,7 +55,7 @@ public final class RefineUtils {
         }
     }
 
-    public static void refineContainer(ContainerSchemaNodeBuilder container, RefineHolder refine, int line) {
+    public static void refineContainer(ContainerSchemaNodeBuilder container, RefineHolder refine) {
         Boolean presence = refine.isPresence();
         MustDefinition must = refine.getMust();
         List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodeBuilders();
@@ -73,7 +73,7 @@ public final class RefineUtils {
         }
     }
 
-    public static void refineList(ListSchemaNodeBuilder list, RefineHolder refine, int line) {
+    public static void refineList(ListSchemaNodeBuilder list, RefineHolder refine) {
         MustDefinition must = refine.getMust();
         Integer min = refine.getMinElements();
         Integer max = refine.getMaxElements();
@@ -95,7 +95,7 @@ public final class RefineUtils {
         }
     }
 
-    public static void refineLeafList(LeafListSchemaNodeBuilder leafList, RefineHolder refine, int line) {
+    public static void refineLeafList(LeafListSchemaNodeBuilder leafList, RefineHolder refine) {
         MustDefinition must = refine.getMust();
         Integer min = refine.getMinElements();
         Integer max = refine.getMaxElements();
@@ -117,7 +117,7 @@ public final class RefineUtils {
         }
     }
 
-    public static void refineChoice(ChoiceBuilder choice, RefineHolder refine, int line) {
+    public static void refineChoice(ChoiceBuilder choice, RefineHolder refine) {
         String defaultStr = refine.getDefaultStr();
         Boolean mandatory = refine.isMandatory();
         List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodeBuilders();
@@ -135,7 +135,7 @@ public final class RefineUtils {
         }
     }
 
-    public static void refineAnyxml(AnyXmlBuilder anyXml, RefineHolder refine, int line) {
+    public static void refineAnyxml(AnyXmlBuilder anyXml, RefineHolder refine) {
         Boolean mandatory = refine.isMandatory();
         MustDefinition must = refine.getMust();
         List<UnknownSchemaNodeBuilder> unknownNodes = refine.getUnknownNodeBuilders();
@@ -298,21 +298,20 @@ public final class RefineUtils {
      *            refine object containing information about refine process
      */
     public static void performRefine(SchemaNodeBuilder nodeToRefine, RefineHolder refine) {
-        final int line = refine.getLine();
         checkRefine(nodeToRefine, refine);
         refineDefault(nodeToRefine, refine);
         if (nodeToRefine instanceof LeafSchemaNodeBuilder) {
             refineLeaf((LeafSchemaNodeBuilder) nodeToRefine, refine);
         } else if (nodeToRefine instanceof ContainerSchemaNodeBuilder) {
-            refineContainer((ContainerSchemaNodeBuilder) nodeToRefine, refine, line);
+            refineContainer((ContainerSchemaNodeBuilder) nodeToRefine, refine);
         } else if (nodeToRefine instanceof ListSchemaNodeBuilder) {
-            refineList((ListSchemaNodeBuilder) nodeToRefine, refine, line);
+            refineList((ListSchemaNodeBuilder) nodeToRefine, refine);
         } else if (nodeToRefine instanceof LeafListSchemaNodeBuilder) {
-            refineLeafList((LeafListSchemaNodeBuilder) nodeToRefine, refine, line);
+            refineLeafList((LeafListSchemaNodeBuilder) nodeToRefine, refine);
         } else if (nodeToRefine instanceof ChoiceBuilder) {
-            refineChoice((ChoiceBuilder) nodeToRefine, refine, line);
+            refineChoice((ChoiceBuilder) nodeToRefine, refine);
         } else if (nodeToRefine instanceof AnyXmlBuilder) {
-            refineAnyxml((AnyXmlBuilder) nodeToRefine, refine, line);
+            refineAnyxml((AnyXmlBuilder) nodeToRefine, refine);
         }
     }
 
index e3c31966a31b9ee0a6ec32c1145c96f15e2d112e..8391759ec35fb5d38a8708c6df514479426d9013 100644 (file)
@@ -23,20 +23,16 @@ import org.opendaylight.yangtools.yang.model.util.BaseConstraints;
 public final class TypeConstraints {
     private final String moduleName;
     private final int line;
-    private final List<List<RangeConstraint>> ranges = new ArrayList<List<RangeConstraint>>();
-    private final List<List<LengthConstraint>> lengths = new ArrayList<List<LengthConstraint>>();
-    private final List<List<PatternConstraint>> patterns = new ArrayList<List<PatternConstraint>>();
-    private final List<Integer> fractionDigits = new ArrayList<Integer>();
+    private final List<List<RangeConstraint>> ranges = new ArrayList<>();
+    private final List<List<LengthConstraint>> lengths = new ArrayList<>();
+    private final List<List<PatternConstraint>> patterns = new ArrayList<>();
+    private final List<Integer> fractionDigits = new ArrayList<>();
 
     public TypeConstraints(final String moduleName, final int line) {
         this.moduleName = moduleName;
         this.line = line;
     }
 
-    List<List<RangeConstraint>> getAllRanges() {
-        return ranges;
-    }
-
     public List<RangeConstraint> getRange() {
         if (ranges.size() < 2) {
             return Collections.emptyList();
index 2839779a451fc125044430719dc3de025f60260b..d73807c9d577f513737150ce3573cf2b8a87ca44 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.parser.util;
 
-import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.*;
+import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findModuleFromBuilders;
+import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findModuleFromContext;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -20,7 +21,12 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.*;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.UnknownType;
 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
@@ -121,7 +127,7 @@ public final class TypeUtils {
     public static void resolveTypeUnion(final UnionTypeBuilder union,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder builder) {
         final List<TypeDefinition<?>> unionTypes = union.getTypes();
-        final List<TypeDefinition<?>> toRemove = new ArrayList<TypeDefinition<?>>();
+        final List<TypeDefinition<?>> toRemove = new ArrayList<>();
         for (TypeDefinition<?> unionType : unionTypes) {
             if (unionType instanceof UnknownType) {
                 final ModuleBuilder dependentModule = findModuleFromBuilders(modules, builder, unionType.getQName()
@@ -147,7 +153,7 @@ public final class TypeUtils {
 
     /**
      * Resolve union type which contains one or more unresolved types.
-     *
+     * 
      * @param union
      *            union type builder to resolve
      * @param modules
@@ -161,7 +167,7 @@ public final class TypeUtils {
             final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module,
             final SchemaContext context) {
         final List<TypeDefinition<?>> unionTypes = union.getTypes();
-        final List<TypeDefinition<?>> toRemove = new ArrayList<TypeDefinition<?>>();
+        final List<TypeDefinition<?>> toRemove = new ArrayList<>();
         for (TypeDefinition<?> unionType : unionTypes) {
             if (unionType instanceof UnknownType) {
                 resolveUnionUnknownType(union, (UnknownType) unionType, modules, module, context);
index 0ec354b017650275db212612b987150d408d31e2..056215fa52880f6b6377eee3d5b430f4bb015b60 100644 (file)
@@ -18,16 +18,12 @@ public class YangParseException extends RuntimeException {
         super(errorMsg, exception);
     }
 
-    public YangParseException(final String moduleName, final int line,
-            final String errorMsg) {
-        super("Error in module '" + moduleName + "' at line " + line + ": "
-                + errorMsg);
+    public YangParseException(final String moduleName, final int line, final String errorMsg) {
+        super("Error in module '" + moduleName + "' at line " + line + ": " + errorMsg);
     }
 
-    public YangParseException(final String moduleName, final int line,
-            final String errorMsg, final Exception exception) {
-        super("Error in module '" + moduleName + "' at line " + line + ": "
-                + errorMsg, exception);
+    public YangParseException(final String moduleName, final int line, final String errorMsg, final Exception exception) {
+        super("Error in module '" + moduleName + "' at line " + line + ": " + errorMsg, exception);
     }
 
 }
index 97454af9d20e4b46a21dc52c841c0d7b4d8e7f23..6ee61357e55563b6d68812802f4c94e14b7db453 100644 (file)
@@ -14,6 +14,7 @@ import java.net.URI;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -34,8 +35,6 @@ import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.util.BaseTypes;
 
-import com.google.common.collect.Lists;
-
 public class AugmentTest {
 
     private final URI types1NS = URI.create("urn:simple.nodes.test");
@@ -70,14 +69,21 @@ public class AugmentTest {
 
     @Test
     public void testAugmentParsing() {
-        SchemaPath expectedPath = null;
-        QName[] qnames = null;
+        SchemaPath expectedSchemaPath;
+        QName[] qnames = new QName[3];
+        qnames[0] = q0;
+        qnames[1] = q1;
+        qnames[2] = q2;
 
         // testfile1
         Module module1 = TestUtils.findModule(modules, "nodes");
         Set<AugmentationSchema> augmentations = module1.getAugmentations();
         assertEquals(1, augmentations.size());
         AugmentationSchema augment = augmentations.iterator().next();
+        assertNotNull(augment);
+
+        expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true);
+        assertEquals(expectedSchemaPath, augment.getTargetPath());
 
         Set<DataSchemaNode> augmentChildren = augment.getChildNodes();
         assertEquals(5, augmentChildren.size());
@@ -104,33 +110,38 @@ public class AugmentTest {
 
         // leaf ds0ChannelNumber
         qnames[3] = new QName(types1NS, types1Rev, t1, "ds0ChannelNumber");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
-        assertEquals(expectedPath, ds0ChannelNumber.getPath());
+        expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true);
+        assertEquals(expectedSchemaPath, ds0ChannelNumber.getPath());
+        assertFalse(ds0ChannelNumber.isAugmenting());
         // type of leaf ds0ChannelNumber
         QName typeQName = BaseTypes.constructQName("string");
         List<QName> typePath = Collections.singletonList(typeQName);
-        expectedPath = new SchemaPath(typePath, true);
-        assertEquals(expectedPath, ds0ChannelNumber.getType().getPath());
+        expectedSchemaPath = new SchemaPath(typePath, true);
+        assertEquals(expectedSchemaPath, ds0ChannelNumber.getType().getPath());
 
         // leaf interface-id
         qnames[3] = new QName(types1NS, types1Rev, t1, "interface-id");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
-        assertEquals(expectedPath, interfaceId.getPath());
+        expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true);
+        assertEquals(expectedSchemaPath, interfaceId.getPath());
+        assertFalse(interfaceId.isAugmenting());
 
         // leaf my-type
         qnames[3] = new QName(types1NS, types1Rev, t1, "my-type");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
-        assertEquals(expectedPath, myType.getPath());
+        expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true);
+        assertEquals(expectedSchemaPath, myType.getPath());
+        assertFalse(myType.isAugmenting());
 
         // container schemas
         qnames[3] = new QName(types1NS, types1Rev, t1, "schemas");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
-        assertEquals(expectedPath, schemas.getPath());
+        expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true);
+        assertEquals(expectedSchemaPath, schemas.getPath());
+        assertFalse(schemas.isAugmenting());
 
         // choice odl
         qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
-        assertEquals(expectedPath, odl.getPath());
+        expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true);
+        assertEquals(expectedSchemaPath, odl.getPath());
+        assertFalse(odl.isAugmenting());
 
         // testfile3
         Module module3 = TestUtils.findModule(modules, "custom");
@@ -159,9 +170,6 @@ public class AugmentTest {
 
     @Test
     public void testAugmentResolving() throws ParseException {
-        SchemaPath expectedPath = null;
-        QName[] qnames = null;
-
         Module module2 = TestUtils.findModule(modules, "types");
         ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces");
         ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
@@ -182,42 +190,40 @@ public class AugmentTest {
         assertNotNull(schemas);
         assertNotNull(odl);
 
-        qnames = new QName[4];
+        SchemaPath expectedPath;
+        QName[] qnames = new QName[4];
         qnames[0] = q0;
         qnames[1] = q1;
         qnames[2] = q2;
 
         // leaf ds0ChannelNumber
         qnames[3] = new QName(types1NS, types1Rev, t1, "ds0ChannelNumber");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, ds0ChannelNumber.getPath());
 
         // leaf interface-id
         qnames[3] = new QName(types1NS, types1Rev, t1, "interface-id");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, interfaceId.getPath());
 
         // leaf my-type
         qnames[3] = new QName(types1NS, types1Rev, t1, "my-type");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, myType.getPath());
 
         // container schemas
         qnames[3] = new QName(types1NS, types1Rev, t1, "schemas");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, schemas.getPath());
 
         // choice odl
         qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, odl.getPath());
     }
 
     @Test
     public void testAugmentChoice() throws ParseException {
-        SchemaPath expectedPath = null;
-        QName[] qnames = null;
-
         Module module2 = TestUtils.findModule(modules, "types");
         ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces");
         ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
@@ -253,7 +259,8 @@ public class AugmentTest {
         assertNotNull(node2);
         assertNotNull(node3);
 
-        qnames = new QName[5];
+        SchemaPath expectedPath;
+        QName[] qnames = new QName[5];
         qnames[0] = q0;
         qnames[1] = q1;
         qnames[2] = q2;
@@ -261,28 +268,28 @@ public class AugmentTest {
 
         // case id
         qnames[4] = new QName(types1NS, types1Rev, t1, "id");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, id.getPath());
         Set<DataSchemaNode> idChildren = id.getChildNodes();
         assertEquals(1, idChildren.size());
 
         // case node1
         qnames[4] = new QName(types1NS, types1Rev, t1, "node1");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, node1.getPath());
         Set<DataSchemaNode> node1Children = node1.getChildNodes();
         assertTrue(node1Children.isEmpty());
 
         // case node2
         qnames[4] = new QName(types1NS, types1Rev, t1, "node2");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, node2.getPath());
         Set<DataSchemaNode> node2Children = node2.getChildNodes();
         assertTrue(node2Children.isEmpty());
 
         // case node3
         qnames[4] = new QName(types1NS, types1Rev, t1, "node3");
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, node3.getPath());
         Set<DataSchemaNode> node3Children = node3.getChildNodes();
         assertEquals(1, node3Children.size());
@@ -299,7 +306,7 @@ public class AugmentTest {
         qnames[5] = new QName(types1NS, types1Rev, t1, "id");
         LeafSchemaNode caseIdChild = (LeafSchemaNode) idChildren.iterator().next();
         assertNotNull(caseIdChild);
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, caseIdChild.getPath());
 
         // case node3 child
@@ -307,7 +314,7 @@ public class AugmentTest {
         qnames[5] = new QName(types1NS, types1Rev, t1, "node3");
         ContainerSchemaNode caseNode3Child = (ContainerSchemaNode) node3Children.iterator().next();
         assertNotNull(caseNode3Child);
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, caseNode3Child.getPath());
     }
 
@@ -363,7 +370,7 @@ public class AugmentTest {
         assertTrue(create.isAugmenting());
         assertTrue(destroy.isAugmenting());
 
-        SchemaPath expectedPath = null;
+        SchemaPath expectedPath;
         QName[] qnames = new QName[4];
         qnames[0] = submitQName;
         qnames[1] = inputQName;
@@ -372,7 +379,7 @@ public class AugmentTest {
         // case attach
         qnames[3] = new QName(NS_FOO, revision, "f", "attach");
         assertEquals(qnames[3], attach.getQName());
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, attach.getPath());
         Set<DataSchemaNode> attachChildren = attach.getChildNodes();
         assertEquals(1, attachChildren.size());
@@ -380,7 +387,7 @@ public class AugmentTest {
         // case create
         qnames[3] = new QName(NS_FOO, revision, "f", "create");
         assertEquals(qnames[3], create.getQName());
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, create.getPath());
         Set<DataSchemaNode> createChildren = create.getChildNodes();
         assertEquals(1, createChildren.size());
@@ -388,7 +395,7 @@ public class AugmentTest {
         // case attach
         qnames[3] = new QName(NS_FOO, revision, "f", "destroy");
         assertEquals(qnames[3], destroy.getQName());
-        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
         assertEquals(expectedPath, destroy.getPath());
         Set<DataSchemaNode> destroyChildren = destroy.getChildNodes();
         assertEquals(1, destroyChildren.size());
index 99357bbfe9378db5692aaa659c4635b1cd7d1faf..0d1ffb9ea812fe5660156cf66dfb8f974963f446 100644 (file)
@@ -1,7 +1,7 @@
 module bar {
     yang-version 1;
     namespace "urn:opendaylight:bar";
-    prefix "b";
+    prefix "bar";
 
     revision "2013-10-11" {
     }
index cecce24cede9cdfad14015af6a1a1c537add5089..7ee2c1b40aeebd39f734cadb1e7aacb1e5dd9150 100644 (file)
@@ -1,14 +1,14 @@
 module foo {
     yang-version 1;
     namespace "urn:opendaylight:foo";
-    prefix "f";
+    prefix "foo";
 
     import bar { prefix b; revision-date 2013-10-11; }
 
     revision "2013-10-11" {
     }
 
-       augment "/b:submit/b:input/b:arguments" {
+    augment "/b:submit/b:input/b:arguments" {
         when "../type = attach-path-instruction";
 
         case attach {