Clean up yang parser. 51/3651/3
authorMartin Vitez <mvitez@cisco.com>
Wed, 11 Dec 2013 17:18:12 +0000 (18:18 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 13 Dec 2013 12:05:56 +0000 (12:05 +0000)
Removed redundant code, refactored some methods.

Signed-off-by: Martin Vitez <mvitez@cisco.com>
15 files changed:
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BaseTemplate.xtend
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/UsesNodeBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/UsesNodeBuilderImpl.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/ParserListenerUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ParserUtils.xtend
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/RefineUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java

index b9118ac0f513d7cc6e5dfc4f42481e4a1ee0d1b8..99a19687142de6054cd602c2c9f7994657801541 100644 (file)
@@ -279,15 +279,6 @@ abstract class BaseTemplate {
         return null;
     }
 
-    def GeneratedProperty getPropByName(Collection<GeneratedProperty> props, String name) {
-        for (GeneratedProperty prop : props) {
-            if (prop.name.equals(name)) {
-                return prop;
-            }
-        }
-        return null;
-    }
-
     def getRestrictions(Type type) {
         var Restrictions restrictions = null
         if (type instanceof ConcreteType) {
index 6b827841af9a8459707f1e632e3cc57005006537..a3c786d5de82016bd81e2e0b6c13f4f56b4c14e9 100644 (file)
@@ -14,7 +14,6 @@ import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.model.api.YangNode;
-import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.util.RefineHolder;
 
 /**
@@ -88,25 +87,6 @@ public interface UsesNodeBuilder extends GroupingMember, Builder {
      */
     void setAugmenting(boolean augmenting);
 
-    /**
-     * Get augment under which was this uses node was defined.
-     * <p>
-     * Note: This method may return different object than {@link #getParent()}
-     * if this node is a copy of other uses node. If the uses node is copied,
-     * its parent has changed, but parent augment is always same.
-     * </p>
-     *
-     * @return AugmentationSchemaBuilder under which was this node defined
-     */
-    AugmentationSchemaBuilder getParentAugment();
-
-    /**
-     * Set augment under which was this uses node was defined.
-     *
-     * @param augment
-     */
-    void setParentAugment(AugmentationSchemaBuilder augment);
-
     /**
      * Get augmentations defined in this uses node.
      *
@@ -157,55 +137,6 @@ public interface UsesNodeBuilder extends GroupingMember, Builder {
      */
     UsesNode build(YangNode parent);
 
-    /**
-     * Get child nodes defined in target grouping.
-     *
-     * @return set of DataSchemaNodeBuilder objects
-     */
-    Set<DataSchemaNodeBuilder> getTargetChildren();
-
-    /**
-     * Get groupings defined in target grouping.
-     *
-     * @return set of GroupingBuilder objects
-     */
-    Set<GroupingBuilder> getTargetGroupings();
-
-    /**
-     * Get type definitions defined in target grouping.
-     *
-     * @return set of typedefs defined in target grouping
-     */
-    Set<TypeDefinitionBuilder> getTargetTypedefs();
-
-    /**
-     * Get unknown nodes defined in target grouping.
-     *
-     * @return list of unknown nodes defined in target grouping
-     */
-    List<UnknownSchemaNodeBuilder> getTargetUnknownNodes();
-
-    /**
-     *
-     * @return true, if this object was built based on another UsesNodeBuilder,
-     *         false otherwise
-     */
-    boolean isCopy();
-
-    /**
-     *
-     * @return true, if target grouping objects was loaded already, false
-     *         otherwise
-     */
-    boolean isDataCollected();
-
-    /**
-     * Set if target grouping objects was loaded already.
-     *
-     * @param dataCollected
-     */
-    void setDataCollected(boolean dataCollected);
-
     boolean isResolved();
 
     void setResolved(boolean resolved);
index d14fed577971e503574a483e383e781fafad334e..c248f84bed89e2976b37f322f8d48127370f46b3 100644 (file)
@@ -199,15 +199,6 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         return instance;
     }
 
-    public boolean isAllUsesDataCollected() {
-        for (UsesNodeBuilder usesNode : allUsesNodes) {
-            if (!usesNode.isDataCollected()) {
-                return false;
-            }
-        }
-        return true;
-    }
-
     @Override
     public void setParent(Builder parent) {
         throw new YangParseException(name, 0, "Can not set parent to module");
@@ -491,7 +482,6 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         }
         if(parent instanceof AugmentationSchemaBuilder) {
             usesBuilder.setAugmenting(true);
-            usesBuilder.setParentAugment((AugmentationSchemaBuilder)parent);
         }
 
         allUsesNodes.add(usesBuilder);
index 8d6190678fe33acd5d60539e1f2c6a348e040b56..7ab57c644fb1e57e5b3b31cac3c7cf9f7bda71a6 100644 (file)
@@ -29,7 +29,6 @@ import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuild
 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
 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.api.UsesNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.util.RefineHolder;
 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
@@ -38,67 +37,22 @@ public final class UsesNodeBuilderImpl extends AbstractBuilder implements UsesNo
     private boolean isBuilt;
     private UsesNodeImpl instance;
     private DataNodeContainerBuilder parentBuilder;
-    private final String groupingName;
+    private final String groupingPathString;
     private SchemaPath groupingPath;
     private GroupingDefinition groupingDefinition;
     private GroupingBuilder groupingBuilder;
     private boolean addedByUses;
     private boolean augmenting;
     private boolean resolved;
-    private AugmentationSchemaBuilder parentAugment;
     private final Set<AugmentationSchema> augments = new HashSet<>();
     private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<>();
     private final List<SchemaNodeBuilder> refineBuilders = new ArrayList<>();
     private final List<RefineHolder> refines = new ArrayList<>();
 
-    /**
-     * Copies of target grouping child nodes.
-     */
-    private final Set<DataSchemaNodeBuilder> targetChildren = new HashSet<>();
-
-    /**
-     * Copies of target grouping groupings.
-     */
-    private final Set<GroupingBuilder> targetGroupings = new HashSet<>();
-
-    /**
-     * Copies of target grouping typedefs.
-     */
-    private final Set<TypeDefinitionBuilder> targetTypedefs = new HashSet<>();
-
-    /**
-     * Copies of target grouping unknown nodes.
-     */
-    private final List<UnknownSchemaNodeBuilder> targetUnknownNodes = new ArrayList<>();
-
-    private final boolean isCopy;
-    private boolean dataCollected;
-
-    @Override
-    public boolean isCopy() {
-        return isCopy;
-    }
-
-    @Override
-    public boolean isDataCollected() {
-        return dataCollected;
-    }
-
-    @Override
-    public void setDataCollected(boolean dataCollected) {
-        this.dataCollected = dataCollected;
-    }
 
     public UsesNodeBuilderImpl(final String moduleName, final int line, final String groupingName) {
         super(moduleName, line);
-        this.groupingName = groupingName;
-        isCopy = false;
-    }
-
-    public UsesNodeBuilderImpl(final String moduleName, final int line, final String groupingName, final boolean isCopy) {
-        super(moduleName, line);
-        this.groupingName = groupingName;
-        this.isCopy = isCopy;
+        this.groupingPathString = groupingName;
     }
 
     @Override
@@ -181,7 +135,7 @@ public final class UsesNodeBuilderImpl extends AbstractBuilder implements UsesNo
 
     @Override
     public String getGroupingPathAsString() {
-        return groupingName;
+        return groupingPathString;
     }
 
     @Override
@@ -223,16 +177,6 @@ public final class UsesNodeBuilderImpl extends AbstractBuilder implements UsesNo
         this.resolved = resolved;
     }
 
-    @Override
-    public AugmentationSchemaBuilder getParentAugment() {
-        return parentAugment;
-    }
-
-    @Override
-    public void setParentAugment(AugmentationSchemaBuilder augment) {
-        this.parentAugment = augment;
-    }
-
     @Override
     public List<SchemaNodeBuilder> getRefineNodes() {
         return refineBuilders;
@@ -253,31 +197,11 @@ public final class UsesNodeBuilderImpl extends AbstractBuilder implements UsesNo
         refines.add(refine);
     }
 
-    @Override
-    public Set<DataSchemaNodeBuilder> getTargetChildren() {
-        return targetChildren;
-    }
-
-    @Override
-    public Set<GroupingBuilder> getTargetGroupings() {
-        return targetGroupings;
-    }
-
-    @Override
-    public Set<TypeDefinitionBuilder> getTargetTypedefs() {
-        return targetTypedefs;
-    }
-
-    @Override
-    public List<UnknownSchemaNodeBuilder> getTargetUnknownNodes() {
-        return targetUnknownNodes;
-    }
-
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((groupingName == null) ? 0 : groupingName.hashCode());
+        result = prime * result + ((groupingPathString == null) ? 0 : groupingPathString.hashCode());
         result = prime * result + ((parentBuilder == null) ? 0 : parentBuilder.hashCode());
         return result;
     }
@@ -294,11 +218,11 @@ public final class UsesNodeBuilderImpl extends AbstractBuilder implements UsesNo
             return false;
         }
         UsesNodeBuilderImpl other = (UsesNodeBuilderImpl) obj;
-        if (groupingName == null) {
-            if (other.groupingName != null) {
+        if (groupingPathString == null) {
+            if (other.groupingPathString != null) {
                 return false;
             }
-        } else if (!groupingName.equals(other.groupingName)) {
+        } else if (!groupingPathString.equals(other.groupingPathString)) {
             return false;
         }
         if (parentBuilder == null) {
@@ -313,7 +237,7 @@ public final class UsesNodeBuilderImpl extends AbstractBuilder implements UsesNo
 
     @Override
     public String toString() {
-        return "uses '" + groupingName + "'";
+        return "uses '" + groupingPathString + "'";
     }
 
     public final class UsesNodeImpl implements UsesNode {
index f6d4d67cbbe1c3f2b2a53062546106aa6204f8c4..6c22971d7ea3a82073ee325c5d9fba48060cc4ff 100644 (file)
@@ -696,7 +696,7 @@ public final class YangParserImpl implements YangModelParser {
                     "Failed to parse augment: Unresolved parent of augment: " + augmentParent);
         }
 
-        return processAugmentation(augment, firstNodeParent, path);
+        return processAugmentation(augment, firstNodeParent);
     }
 
     /**
@@ -781,7 +781,7 @@ public final class YangParserImpl implements YangModelParser {
         if (currentParent == null) {
             return processAugmentationOnContext(augment, path, module, prefix, context);
         } else {
-            return processAugmentation(augment, currentParent, path);
+            return processAugmentation(augment, currentParent);
         }
     }
 
@@ -948,7 +948,6 @@ public final class YangParserImpl implements YangModelParser {
                 for (AugmentationSchemaBuilder augment : usesNode.getAugmentations()) {
                     processAugmentationOnContext(augment, augment.getTargetPath().getPath(), module, prefix, context);
                 }
-                GroupingUtils.performRefine(usesNode);
             } else {
                 parent.getChildNodeBuilders().addAll(target.instantiateChildNodes(parent));
                 parent.getTypeDefinitionBuilders().addAll(target.instantiateTypedefs(parent));
@@ -957,10 +956,10 @@ public final class YangParserImpl implements YangModelParser {
                 usesNode.setResolved(true);
 
                 for (AugmentationSchemaBuilder augment : usesNode.getAugmentations()) {
-                    processAugmentation(augment, parent, augment.getTargetPath().getPath());
+                    processAugmentation(augment, parent);
                 }
-                GroupingUtils.performRefine(usesNode);
             }
+            GroupingUtils.performRefine(usesNode);
         }
     }
 
index a0101a556df24452ec632e5d1347c6e9a8652b24..9e97fa39f3cf77bfda20e28fe5a63b8901e0c96d 100644 (file)
@@ -415,9 +415,9 @@ public final class CopyUtils {
         return newConstraints;
     }
 
-    static UsesNodeBuilder copyUses(UsesNodeBuilder old, Builder newParent) {
+    private static UsesNodeBuilder copyUses(UsesNodeBuilder old, Builder newParent) {
         UsesNodeBuilder copy = new UsesNodeBuilderImpl(newParent.getModuleName(), newParent.getLine(),
-                old.getGroupingPathAsString(), true);
+                old.getGroupingPathAsString());
         copy.setParent(newParent);
         copy.setGroupingDefinition(old.getGroupingDefinition());
         copy.setGrouping(old.getGroupingBuilder());
@@ -426,7 +426,6 @@ public final class CopyUtils {
         copy.getRefineNodes().addAll(old.getRefineNodes());
         copy.getRefines().addAll(old.getRefines());
         copy.setAugmenting(old.isAugmenting());
-        copy.setParentAugment(old.getParentAugment());
         return copy;
     }
 
index b2e9381b1f779cd228af549f8578ce7b15bed1dc..a25b6279519b2c4227994b3e23b7f5288247b42e 100644 (file)
@@ -743,7 +743,7 @@ public final class ParserListenerUtils {
                 reference = stringFromNode(child);
             }
         }
-        String pattern = patternStringFromNode(ctx);
+        String pattern = parsePatternString(ctx);
         return BaseConstraints.patternConstraint(pattern, description, reference);
     }
 
@@ -754,7 +754,7 @@ public final class ParserListenerUtils {
      *            context to parse
      * @return pattern value as String
      */
-    public static String patternStringFromNode(final Pattern_stmtContext ctx) {
+    private static String parsePatternString(final Pattern_stmtContext ctx) {
         StringBuilder result = new StringBuilder();
         for (int i = 0; i < ctx.getChildCount(); ++i) {
             ParseTree child = ctx.getChild(i);
index e3d3a4898ae78dde32e621a091e1253763a38cf4..9f03e79850f8c14c7ae5e482497eebc0e709ec2e 100644 (file)
@@ -43,7 +43,6 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.NotificationBuilder.NotificationDefinitionImpl;
 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget
 import org.opendaylight.yangtools.yang.parser.builder.impl.RpcDefinitionBuilder
-import java.net.URI
 import org.opendaylight.yangtools.yang.parser.builder.api.GroupingMember
 
 public final class ParserUtils {
@@ -64,14 +63,6 @@ public final class ParserUtils {
         return new SchemaPath(path, schemaPath.isAbsolute());
     }
 
-    public static def SchemaPath correctSchemaPath(SchemaPath old, URI ns, Date revision, String prefix) {
-        val List<QName> newPath = new ArrayList();
-        for (name : old.path) {
-            newPath.add(new QName(ns, revision, prefix, name.localName))
-        }
-        return new SchemaPath(newPath, old.absolute) 
-    }
-
     /**
      * Get module import referenced by given prefix.
      *
@@ -297,7 +288,6 @@ public final class ParserUtils {
      *            schema path of node parent
      */
     static def void correctNodePath(SchemaNodeBuilder node, SchemaPath parentSchemaPath) {
-
         // set correct path
         val targetNodePath = new ArrayList<QName>(parentSchemaPath.getPath());
         targetNodePath.add(node.getQName());
@@ -321,7 +311,6 @@ public final class ParserUtils {
     }
 
 
-
     private static def Builder findNode(Builder firstNodeParent, List<QName> path, String moduleName, int line) {
         var currentName = "";
         var currentParent = firstNodeParent;
@@ -343,16 +332,10 @@ public final class ParserUtils {
                 if (nodeFound == null && currentParent instanceof ModuleBuilder) {
                     nodeFound = searchRpcs(currentParent as ModuleBuilder, currentName);
                 }
-                // if not found, search in uses
                 if (nodeFound == null) {
-                    var found = searchUses(dataNodeContainerParent, currentName);
-                    if(found == null) {
-                        return null;
-                    } else {
-                        currentParent = found;
-                    }
+                    return null
                 } else {
-                    currentParent = nodeFound;
+                    currentParent = nodeFound
                 }
             } else if (currentParent instanceof ChoiceBuilder) {
                 val choiceParent = currentParent as ChoiceBuilder;
@@ -396,41 +379,6 @@ public final class ParserUtils {
         return null;
     }
 
-    private static def searchUses(DataNodeContainerBuilder dataNodeContainerParent, String name) {
-        var currentName = name;
-        for (unb : dataNodeContainerParent.usesNodes) {
-            var result = searchInUsesTarget(currentName, unb);
-            if (result != null) {
-                return result;
-            }
-
-            result = findNodeInUses(currentName, unb);
-            if (result != null) {
-                var copy = CopyUtils.copy(result, unb.getParent(), true);
-                unb.getTargetChildren().add(copy);
-                return copy;
-            }
-        }
-        return null;
-    }
-    
-    public static def getRpc(ModuleBuilder module,String name) {
-        for(rpc : module.getRpcs()) {
-            if(name == rpc.QName.localName) {
-                return rpc;
-            }
-        }
-        return null;
-    }
-    
-    public static def getNotification(ModuleBuilder module,String name) {
-        for(notification : module.getNotifications()) {
-            if(name == notification.QName.localName) {
-                return notification;
-            }
-        }
-    }
-    
     private static def nextLevel(List<QName> path){
         return path.subList(1,path.size)
     }
@@ -445,64 +393,30 @@ public final class ParserUtils {
      *            path to augment target
      * @return true if augmentation process succeed, false otherwise
      */
-    public static def boolean processAugmentation(AugmentationSchemaBuilder augment, Builder firstNodeParent,
-        List<QName> path) {
-
-            // traverse augment target path and try to reach target node
-            val targetNode = findNode(firstNodeParent,path,augment.moduleName,augment.line);
-            if (targetNode === null) return false;
-            
-            if ((targetNode instanceof DataNodeContainerBuilder)) {
-               val targetDataNodeContainer = targetNode as DataNodeContainerBuilder;
-               augment.setTargetNodeSchemaPath(targetDataNodeContainer.getPath());
-                fillAugmentTarget(augment, targetDataNodeContainer);
-            } else if (targetNode instanceof ChoiceBuilder) {
-               val targetChoiceBuilder = targetNode as ChoiceBuilder;
-               augment.setTargetNodeSchemaPath(targetChoiceBuilder.getPath());
-                fillAugmentTarget(augment, targetChoiceBuilder);
-            } else {
-                throw new YangParseException(augment.getModuleName(), augment.getLine(),
-                    "Error in augment parsing: The target node MUST be either a container, list, choice, case, input, output, or notification node.");
-            }
-            (targetNode as AugmentationTargetBuilder).addAugmentation(augment);
-            augment.setResolved(true);
-            return true;
-        }
-
-    private static def DataSchemaNodeBuilder searchInUsesTarget(String localName, UsesNodeBuilder uses) {
-        for(child : uses.targetChildren) {
-            if (child.getQName().getLocalName().equals(localName)) {
-                return child;
-            }
-        }
-    } 
-
-        /**
-     * Find node with given name in uses target.
-     *
-     * @param localName
-     *            name of node to find
-     * @param uses
-     *            uses node which target grouping should be searched
-     * @return node with given name if found, null otherwise
-     */
-    private static def DataSchemaNodeBuilder findNodeInUses(String localName, UsesNodeBuilder uses) {
-        val target = uses.groupingBuilder;
-        for (child : target.childNodeBuilders) {
-            if (child.getQName().getLocalName().equals(localName)) {
-                return child;
-            }
-        }
-        for (usesNode : target.usesNodes) {
-            val result = findNodeInUses(localName, usesNode);
-            if (result != null) {
-                return result;
-            }
+    public static def boolean processAugmentation(AugmentationSchemaBuilder augment, Builder firstNodeParent) {
+        val path = augment.targetPath.path
+        // traverse augment target path and try to reach target node
+        val targetNode = findNode(firstNodeParent, path, augment.moduleName, augment.line);
+        if(targetNode === null) return false;
+
+        if ((targetNode instanceof DataNodeContainerBuilder)) {
+            val targetDataNodeContainer = targetNode as DataNodeContainerBuilder;
+            augment.setTargetNodeSchemaPath(targetDataNodeContainer.getPath());
+            fillAugmentTarget(augment, targetDataNodeContainer);
+        } else if (targetNode instanceof ChoiceBuilder) {
+            val targetChoiceBuilder = targetNode as ChoiceBuilder;
+            augment.setTargetNodeSchemaPath(targetChoiceBuilder.getPath());
+            fillAugmentTarget(augment, targetChoiceBuilder);
+        } else {
+            throw new YangParseException(augment.getModuleName(), augment.getLine(),
+                "Error in augment parsing: The target node MUST be either a container, list, choice, case, input, output, or notification node.");
         }
-        return null;
+        (targetNode as AugmentationTargetBuilder).addAugmentation(augment);
+        augment.setResolved(true);
+        return true;
     }
 
-        /**
+    /**
      * Find augment target node in given context and perform augmentation.
      *
      * @param augment
@@ -516,107 +430,107 @@ public final class ParserUtils {
      *            SchemaContext containing already resolved modules
      * @return true if augment process succeed, false otherwise
      */
-        public static def boolean processAugmentationOnContext(AugmentationSchemaBuilder augment, List<QName> path,
-            ModuleBuilder module, String prefix, SchemaContext context) {
-            val int line = augment.getLine();
-            val Module dependentModule = findModuleFromContext(context, module, prefix, line);
-            if (dependentModule === null) {
-                throw new YangParseException(module.getName(), line,
-                    "Error in augment parsing: failed to find module with prefix " + prefix + ".");
-            }
-
-            var currentName = path.get(0).getLocalName();
-            var SchemaNode currentParent = dependentModule.getDataChildByName(currentName);
-            if (currentParent === null) {
-                val notifications = dependentModule.getNotifications();
-                for (NotificationDefinition ntf : notifications) {
-                    if (ntf.getQName().getLocalName().equals(currentName)) {
-                        currentParent = ntf;
-                    }
+    public static def boolean processAugmentationOnContext(AugmentationSchemaBuilder augment, List<QName> path,
+        ModuleBuilder module, String prefix, SchemaContext context) {
+        val int line = augment.getLine();
+        val Module dependentModule = findModuleFromContext(context, module, prefix, line);
+        if (dependentModule === null) {
+            throw new YangParseException(module.getName(), line,
+                "Error in augment parsing: failed to find module with prefix " + prefix + ".");
+        }
+
+        var currentName = path.get(0).getLocalName();
+        var SchemaNode currentParent = dependentModule.getDataChildByName(currentName);
+        if (currentParent === null) {
+            val notifications = dependentModule.getNotifications();
+            for (NotificationDefinition ntf : notifications) {
+                if (ntf.getQName().getLocalName().equals(currentName)) {
+                    currentParent = ntf;
                 }
             }
-            if (currentParent === null) {
-                throw new YangParseException(module.getName(), line,
-                    "Error in augment parsing: failed to find node " + currentName + ".");
-            }
-
-            for (qname : path.nextLevel) {
-                currentName = qname.getLocalName();
-                if (currentParent instanceof DataNodeContainer) {
-                    currentParent = (currentParent as DataNodeContainer).getDataChildByName(currentName);
-                } else if (currentParent instanceof ChoiceNode) {
-                    currentParent = (currentParent as ChoiceNode).getCaseNodeByName(currentName);
-                } else {
-                    throw new YangParseException(augment.getModuleName(), line,
-                        "Error in augment parsing: failed to find node " + currentName);
-                }
+        }
+        if (currentParent === null) {
+            throw new YangParseException(module.getName(), line,
+                "Error in augment parsing: failed to find node " + currentName + ".");
+        }
 
-                // if node in path not found, return false
-                if (currentParent === null) {
-                    throw new YangParseException(module.getName(), line,
-                        "Error in augment parsing: failed to find node " + currentName + ".");
-                }
+        for (qname : path.nextLevel) {
+            currentName = qname.getLocalName();
+            if (currentParent instanceof DataNodeContainer) {
+                currentParent = (currentParent as DataNodeContainer).getDataChildByName(currentName);
+            } else if (currentParent instanceof ChoiceNode) {
+                currentParent = (currentParent as ChoiceNode).getCaseNodeByName(currentName);
+            } else {
+                throw new YangParseException(augment.getModuleName(), line,
+                    "Error in augment parsing: failed to find node " + currentName);
             }
 
-            val oldPath = currentParent.path;
-
-            if (!(currentParent instanceof AugmentationTarget)) {
+            // if node in path not found, return false
+            if (currentParent === null) {
                 throw new YangParseException(module.getName(), line,
-                    "Target of type " + currentParent.class + " cannot be augmented.");
-            }
-
-            switch (currentParent) {
-                case (currentParent instanceof ContainerSchemaNodeImpl): {
-
-                    // includes container, input and output statement
-                    val c = currentParent as ContainerSchemaNodeImpl;
-                    val cb = c.toBuilder();
-                    fillAugmentTarget(augment, cb);
-                    (cb as AugmentationTargetBuilder ).addAugmentation(augment);
-                    cb.rebuild();
-                }
-                case (currentParent instanceof ListSchemaNodeImpl): {
-                    val l = currentParent as ListSchemaNodeImpl;
-                    val lb = l.toBuilder();
-                    fillAugmentTarget(augment, lb);
-                    (lb as AugmentationTargetBuilder ).addAugmentation(augment);
-                    lb.rebuild();
-                    augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
-                    augment.setResolved(true);
-                }
-                case (currentParent instanceof ChoiceNodeImpl): {
-                    val ch = currentParent as ChoiceNodeImpl;
-                    val chb = ch.toBuilder();
-                    fillAugmentTarget(augment, chb);
-                    (chb as AugmentationTargetBuilder ).addAugmentation(augment);
-                    chb.rebuild();
-                    augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
-                    augment.setResolved(true);
-                }
-                case (currentParent instanceof ChoiceCaseNodeImpl): {
-                    val chc = currentParent as ChoiceCaseNodeImpl;
-                    val chcb = chc.toBuilder();
-                    fillAugmentTarget(augment, chcb);
-                    (chcb as AugmentationTargetBuilder ).addAugmentation(augment);
-                    chcb.rebuild();
-                    augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
-                    augment.setResolved(true);
-                }
-                case (currentParent instanceof NotificationDefinitionImpl): {
-                    val nd = currentParent as NotificationDefinitionImpl;
-                    val nb = nd.toBuilder();
-                    fillAugmentTarget(augment, nb);
-                    (nb as AugmentationTargetBuilder ).addAugmentation(augment);
-                    nb.rebuild();
-                    augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
-                    augment.setResolved(true);
-                }
+                    "Error in augment parsing: failed to find node " + currentName + ".");
             }
-            augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
-            augment.setResolved(true);
-            return true;
         }
 
+        val oldPath = currentParent.path;
+
+        if (!(currentParent instanceof AugmentationTarget)) {
+            throw new YangParseException(module.getName(), line,
+                "Target of type " + currentParent.class + " cannot be augmented.");
+        }
+
+        switch (currentParent) {
+            case (currentParent instanceof ContainerSchemaNodeImpl): {
+
+                // includes container, input and output statement
+                val c = currentParent as ContainerSchemaNodeImpl;
+                val cb = c.toBuilder();
+                fillAugmentTarget(augment, cb);
+                (cb as AugmentationTargetBuilder ).addAugmentation(augment);
+                cb.rebuild();
+            }
+            case (currentParent instanceof ListSchemaNodeImpl): {
+                val l = currentParent as ListSchemaNodeImpl;
+                val lb = l.toBuilder();
+                fillAugmentTarget(augment, lb);
+                (lb as AugmentationTargetBuilder ).addAugmentation(augment);
+                lb.rebuild();
+                augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+                augment.setResolved(true);
+            }
+            case (currentParent instanceof ChoiceNodeImpl): {
+                val ch = currentParent as ChoiceNodeImpl;
+                val chb = ch.toBuilder();
+                fillAugmentTarget(augment, chb);
+                (chb as AugmentationTargetBuilder ).addAugmentation(augment);
+                chb.rebuild();
+                augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+                augment.setResolved(true);
+            }
+            case (currentParent instanceof ChoiceCaseNodeImpl): {
+                val chc = currentParent as ChoiceCaseNodeImpl;
+                val chcb = chc.toBuilder();
+                fillAugmentTarget(augment, chcb);
+                (chcb as AugmentationTargetBuilder ).addAugmentation(augment);
+                chcb.rebuild();
+                augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+                augment.setResolved(true);
+            }
+            case (currentParent instanceof NotificationDefinitionImpl): {
+                val nd = currentParent as NotificationDefinitionImpl;
+                val nb = nd.toBuilder();
+                fillAugmentTarget(augment, nb);
+                (nb as AugmentationTargetBuilder ).addAugmentation(augment);
+                nb.rebuild();
+                augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+                augment.setResolved(true);
+            }
+        }
+        augment.setTargetNodeSchemaPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+        augment.setResolved(true);
+        return true;
+    }
+
     public static def IdentitySchemaNodeBuilder findBaseIdentity(Map<String, TreeMap<Date, ModuleBuilder>> modules,
         ModuleBuilder module, String baseString, int line) {
         var IdentitySchemaNodeBuilder result = null;
@@ -675,22 +589,22 @@ public final class ParserUtils {
         return null;
     }
 
-        /**
+    /**
      * Get module in which this node is defined.
      *
      * @param node
      * @return builder of module where this node is defined
      */
-        public static def ModuleBuilder getParentModule(Builder node) {
-            if (node instanceof ModuleBuilder) {
-                return node as ModuleBuilder;
-            }
-            var parent = node.getParent();
-            while (!(parent instanceof ModuleBuilder)) {
-                parent = parent.getParent();
-            }
-            return parent as ModuleBuilder;
+    public static def ModuleBuilder getParentModule(Builder node) {
+        if (node instanceof ModuleBuilder) {
+            return node as ModuleBuilder;
         }
+        var parent = node.getParent();
+        while (!(parent instanceof ModuleBuilder)) {
+            parent = parent.getParent();
+        }
+        return parent as ModuleBuilder;
+    }
 
 }
 
index f3f2def8fe01437925638503e1e2de349134ee98..f5f5b46478c89c7adbab5345b5a51b0871186370 100644 (file)
@@ -167,7 +167,7 @@ public final class RefineUtils {
      * @param refine
      *            refine object containing information about refine process
      */
-    public static void checkRefine(SchemaNodeBuilder node, RefineHolder refine) {
+    private static void checkRefine(SchemaNodeBuilder node, RefineHolder refine) {
         String moduleName = refine.getModuleName();
         int line = refine.getLine();
         String name = node.getQName().getLocalName();
@@ -259,7 +259,7 @@ public final class RefineUtils {
      * @param refine
      *            refine object containing information about refine process
      */
-    public static void refineDefault(final Builder node, final RefineHolder refine) {
+    private static void refineDefault(final Builder node, final RefineHolder refine) {
         final String moduleName = refine.getModuleName();
         final int line = refine.getLine();
         Class<? extends Builder> cls = node.getClass();
@@ -303,7 +303,7 @@ public final class RefineUtils {
      * @param refine
      *            refine object containing information about refine process
      */
-    public static void performRefine(SchemaNodeBuilder nodeToRefine, RefineHolder refine) {
+    static void performRefine(SchemaNodeBuilder nodeToRefine, RefineHolder refine) {
         checkRefine(nodeToRefine, refine);
         refineDefault(nodeToRefine, refine);
         if (nodeToRefine instanceof LeafSchemaNodeBuilder) {
index dfa7bc4830b850f3d93d8742f54b2c7d0060e5e8..c362a2179c4f7045ff813bea058a74643e90e0ee 100644 (file)
@@ -37,8 +37,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.util.BaseTypes;
 
 public class AugmentTest {
-    private static final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-
     private static final URI fooNS = URI.create("urn:opendaylight.foo");
     private static final URI barNS = URI.create("urn:opendaylight.bar");
     private static final URI bazNS = URI.create("urn:opendaylight.baz");
@@ -56,6 +54,7 @@ public class AugmentTest {
 
     @BeforeClass
     public static void init() throws FileNotFoundException, ParseException {
+        DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
         fooRev = simpleDateFormat.parse("2013-10-13");
         barRev = simpleDateFormat.parse("2013-10-14");
         bazRev = simpleDateFormat.parse("2013-10-15");
@@ -342,7 +341,7 @@ public class AugmentTest {
         modules = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").getPath());
         final URI NS_BAR = URI.create("urn:opendaylight:bar");
         final URI NS_FOO = URI.create("urn:opendaylight:foo");
-        final Date revision = simpleDateFormat.parse("2013-10-11");
+        final Date revision = new SimpleDateFormat("yyyy-MM-dd").parse("2013-10-11");
 
         Module bar = TestUtils.findModule(modules, "bar");
         Set<RpcDefinition> rpcs = bar.getRpcs();
index 44cb0d635d976cbff7f9c96a258ad036b1502b77..2adb544f5a49884b9b2b1b31ad409396ebf7cf7c 100644 (file)
@@ -13,6 +13,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.net.URI;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -390,7 +391,7 @@ public class GroupingTest {
         assertNotNull(gzz);
 
         URI expectedNS = URI.create("urn:grouping:cascade-uses");
-        Date expectedRev = TestUtils.simpleDateFormat.parse("2013-07-18");
+        Date expectedRev = new SimpleDateFormat("yyyy-MM-dd").parse("2013-07-18");
         String expectedPref = "cu";
         SchemaPath expectedPath;
 
index fe438c928d53dcaa5756ca515e394ac72c4b6384..4d77c2506c4e4e1d848092be863f5707270fe4d5 100644 (file)
@@ -39,8 +39,6 @@ import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
 
 final class TestUtils {
 
-    static final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-
     private TestUtils() {
     }
 
@@ -151,7 +149,7 @@ final class TestUtils {
     /**
      * Test if node has augmenting flag set to expected value. In case this is
      * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too.
-     * 
+     *
      * @param node
      *            node to check
      * @param expected
@@ -173,7 +171,7 @@ final class TestUtils {
     /**
      * Check if node has addedByUses flag set to expected value. In case this is
      * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too.
-     * 
+     *
      * @param node
      *            node to check
      * @param expected
index 9b69af60e69e9bdf6c01182dcd46457cbb6c5f38..1d760b870cce686cb0f87e272a796cd74ff10834 100644 (file)
@@ -11,7 +11,9 @@ import static org.junit.Assert.*;
 
 import java.io.FileNotFoundException;
 import java.net.URI;
+import java.text.DateFormat;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
@@ -50,8 +52,9 @@ public class UsesAugmentTest {
 
     @Before
     public void init() throws FileNotFoundException, ParseException {
-        UG_REV = TestUtils.simpleDateFormat.parse("2013-07-30");
-        GD_REV = TestUtils.simpleDateFormat.parse("2013-09-04");
+        DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        UG_REV = simpleDateFormat.parse("2013-07-30");
+        GD_REV = simpleDateFormat.parse("2013-09-04");
     }
 
     /**
index c3cdc27fb8b77be0176e85fc1220bcdf21f4be05..7eced3191ba1f877b67e5c2fa5cb952328cc3bd0 100644 (file)
@@ -214,7 +214,7 @@ public class YangParserSimpleTest {
 
     private SchemaPath createPath(String... names) {
         try {
-            rev = TestUtils.simpleDateFormat.parse("2013-07-30");
+            rev = new SimpleDateFormat("yyyy-MM-dd").parse("2013-07-30");
         } catch (ParseException e) {
             e.printStackTrace();
         }
index ad720994abf65c659b7927a4ce51b239ad54bd04..3c55d4d9d6cf0cca5b377bf521349810fb09543f 100644 (file)
@@ -12,7 +12,9 @@ import static org.junit.Assert.*;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.net.URI;
+import java.text.DateFormat;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -67,9 +69,10 @@ public class YangParserTest {
 
     @Before
     public void init() throws FileNotFoundException, ParseException {
-        fooRev = TestUtils.simpleDateFormat.parse("2013-02-27");
-        barRev = TestUtils.simpleDateFormat.parse("2013-07-03");
-        bazRev = TestUtils.simpleDateFormat.parse("2013-02-27");
+        DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        fooRev = simpleDateFormat.parse("2013-02-27");
+        barRev = simpleDateFormat.parse("2013-07-03");
+        bazRev = simpleDateFormat.parse("2013-02-27");
 
         modules = TestUtils.loadModules(getClass().getResource("/model").getPath());
         assertEquals(3, modules.size());