[ONOS-3897] Yang Listener for Enumeration Data Type
Change-Id: If257c73da8fe2dcc2f4111f103967cfcdd7fa273
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java b/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
index 59da354..76ab0f3 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
@@ -20,6 +20,8 @@
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
+import java.util.Objects;
+
/*-
* The "ENUM" statement, which is a sub-statement to the "type"
* statement, MUST be present if the type is "enumeration". It is
@@ -188,6 +190,23 @@
return ParsableDataType.ENUM_DATA;
}
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangEnum) {
+ final YangEnum other = (YangEnum) obj;
+ return Objects.equals(this.namedValue, other.namedValue);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(this.namedValue);
+ }
+
/**
* Validate the data on entering the corresponding parse tree node.
*
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java b/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
index 7aae900..ec5374e 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
@@ -16,13 +16,12 @@
package org.onosproject.yangutils.datamodel;
-import java.util.HashSet;
-import java.util.Set;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
-import org.onosproject.yangutils.translator.CachedFileHandle;
+
+import java.util.HashSet;
+import java.util.Set;
/*
* The enumeration built-in type represents values from a set of
@@ -32,20 +31,19 @@
/**
* Maintains the enumeration data type information.
*/
-public class YangEnumeration extends YangNode implements Parsable {
+public class YangEnumeration implements Parsable {
- /**
- * Enumeration info set.
- */
+ // Enumeration info set.
private Set<YangEnum> enumSet;
+ // Enumeration name.
+ private String enumerationName;
+
/**
- * Create an enumeration object.
+ * Creates an enumeration object.
*/
public YangEnumeration() {
- super(YangNodeType.ENUMERATION_NODE);
setEnumSet(new HashSet<YangEnum>());
-
}
/**
@@ -67,12 +65,33 @@
}
/**
- * Add ENUM value.
+ * Add ENUM information.
*
- * @param enumInfo the ENUM value of string
+ * @param enumInfo the ENUM information to be added.
+ * @throws DataModelException due to violation in data model rules.
*/
- public void addEnumInfo(YangEnum enumInfo) {
+ public void addEnumInfo(YangEnum enumInfo) throws DataModelException {
+ if (!getEnumSet().add(enumInfo)) {
+ throw new DataModelException("YANG ENUM already exists");
+ }
+ }
+ /**
+ * Return enumeration name.
+ *
+ * @return the enumeration name
+ */
+ public String getEnumerationName() {
+ return enumerationName;
+ }
+
+ /**
+ * Set the enumeration name.
+ *
+ * @param enumerationName enumeration name
+ */
+ public void setEnumerationName(String enumerationName) {
+ this.enumerationName = enumerationName;
}
/**
@@ -104,70 +123,4 @@
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.datamodel.YangNode#getName()
- */
- @Override
- public String getName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
- */
- @Override
- public void setName(String name) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
- */
- @Override
- public String getPackage() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
- */
- @Override
- public void setPackage(String pkg) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
- */
- @Override
- public void generateJavaCodeEntry() {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
- */
- @Override
- public void generateJavaCodeExit() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public CachedFileHandle getFileHandle() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void setFileHandle(CachedFileHandle fileHandle) {
- // TODO Auto-generated method stub
-
- }
}
diff --git a/src/main/java/org/onosproject/yangutils/parser/ParsableDataType.java b/src/main/java/org/onosproject/yangutils/parser/ParsableDataType.java
index 41d790d..0e2366b 100644
--- a/src/main/java/org/onosproject/yangutils/parser/ParsableDataType.java
+++ b/src/main/java/org/onosproject/yangutils/parser/ParsableDataType.java
@@ -215,6 +215,11 @@
DEFAULT_DATA,
/**
+ * Identifies the YANG value element parsed data.
+ */
+ VALUE_DATA,
+
+ /**
* Identifies the YANG organization parsed data.
*/
ORGANIZATION_DATA;
@@ -228,88 +233,90 @@
public static String getParsableDataType(ParsableDataType parsableDataType) {
switch (parsableDataType) {
- case MODULE_DATA:
- return "module";
- case SUB_MODULE_DATA:
- return "submodule";
- case TYPEDEF_DATA:
- return "typedef";
- case TYPE_DATA:
- return "type";
- case CHOICE_DATA:
- return "choice";
- case CASE_DATA:
- return "case";
- case ENUMERATION_DATA:
- return "enumeration";
- case GROUPING_DATA:
- return "grouping";
- case USES_DATA:
- return "uses";
- case AUGMENT_DATA:
- return "augment";
- case CONTAINER_DATA:
- return "container";
- case LIST_DATA:
- return "list";
- case BELONGS_TO_DATA:
- return "belongs-to";
- case BIT_DATA:
- return "bit";
- case BITS_DATA:
- return "bits";
- case ENUM_DATA:
- return "enum";
- case IMPORT_DATA:
- return "import";
- case INCLUDE_DATA:
- return "include";
- case LEAF_DATA:
- return "leaf";
- case LEAF_LIST_DATA:
- return "leaf-list";
- case MUST_DATA:
- return "must";
- case REVISION_DATA:
- return "revision";
- case REVISION_DATE_DATA:
- return "revision-date";
- case NAMESPACE_DATA:
- return "namespace";
- case CONTACT_DATA:
- return "contact";
- case CONFIG_DATA:
- return "config";
- case DESCRIPTION_DATA:
- return "description";
- case KEY_DATA:
- return "key";
- case MANDATORY_DATA:
- return "mandatory";
- case MAX_ELEMENT_DATA:
- return "max-elements";
- case MIN_ELEMENT_DATA:
- return "min-elements";
- case PRESENCE_DATA:
- return "presence";
- case REFERENCE_DATA:
- return "reference";
- case STATUS_DATA:
- return "status";
- case UNITS_DATA:
- return "units";
- case VERSION_DATA:
- return "version";
- case YANGBASE_DATA:
- return "yangbase";
- case PREFIX_DATA:
- return "prefix";
- case ORGANIZATION_DATA:
- return "organization";
- case DEFAULT_DATA:
- return "default";
- default:
- return "yang";
+ case MODULE_DATA:
+ return "module";
+ case SUB_MODULE_DATA:
+ return "submodule";
+ case TYPEDEF_DATA:
+ return "typedef";
+ case TYPE_DATA:
+ return "type";
+ case CHOICE_DATA:
+ return "choice";
+ case CASE_DATA:
+ return "case";
+ case ENUMERATION_DATA:
+ return "enumeration";
+ case GROUPING_DATA:
+ return "grouping";
+ case USES_DATA:
+ return "uses";
+ case AUGMENT_DATA:
+ return "augment";
+ case CONTAINER_DATA:
+ return "container";
+ case LIST_DATA:
+ return "list";
+ case BELONGS_TO_DATA:
+ return "belongs-to";
+ case BIT_DATA:
+ return "bit";
+ case BITS_DATA:
+ return "bits";
+ case ENUM_DATA:
+ return "enum";
+ case IMPORT_DATA:
+ return "import";
+ case INCLUDE_DATA:
+ return "include";
+ case LEAF_DATA:
+ return "leaf";
+ case LEAF_LIST_DATA:
+ return "leaf-list";
+ case MUST_DATA:
+ return "must";
+ case REVISION_DATA:
+ return "revision";
+ case REVISION_DATE_DATA:
+ return "revision-date";
+ case NAMESPACE_DATA:
+ return "namespace";
+ case CONTACT_DATA:
+ return "contact";
+ case CONFIG_DATA:
+ return "config";
+ case DESCRIPTION_DATA:
+ return "description";
+ case KEY_DATA:
+ return "key";
+ case MANDATORY_DATA:
+ return "mandatory";
+ case MAX_ELEMENT_DATA:
+ return "max-elements";
+ case MIN_ELEMENT_DATA:
+ return "min-elements";
+ case PRESENCE_DATA:
+ return "presence";
+ case REFERENCE_DATA:
+ return "reference";
+ case STATUS_DATA:
+ return "status";
+ case UNITS_DATA:
+ return "units";
+ case VERSION_DATA:
+ return "version";
+ case YANGBASE_DATA:
+ return "yangbase";
+ case PREFIX_DATA:
+ return "prefix";
+ case ORGANIZATION_DATA:
+ return "organization";
+ case VALUE_DATA:
+ return "value";
+ case DEFAULT_DATA:
+ return "default";
+ default:
+ return "yang";
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index c0c128b..08b1da7 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -16,8 +16,6 @@
package org.onosproject.yangutils.parser.impl;
-import java.util.Stack;
-
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
@@ -32,6 +30,8 @@
import org.onosproject.yangutils.parser.impl.listeners.ContainerListener;
import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
+import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
+import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
import org.onosproject.yangutils.parser.impl.listeners.KeyListener;
@@ -54,8 +54,11 @@
import org.onosproject.yangutils.parser.impl.listeners.TypeDefListener;
import org.onosproject.yangutils.parser.impl.listeners.TypeListener;
import org.onosproject.yangutils.parser.impl.listeners.UnitsListener;
+import org.onosproject.yangutils.parser.impl.listeners.ValueListener;
import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
+import java.util.Stack;
+
/**
* ANTLR generates a parse-tree listener interface that responds to events
* triggered by the built-in tree walker. The methods in listener are just
@@ -128,62 +131,62 @@
@Override
public void enterModuleBody(GeneratedYangParser.ModuleBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitModuleBody(GeneratedYangParser.ModuleBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterModuleHeaderStatement(GeneratedYangParser.ModuleHeaderStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitModuleHeaderStatement(GeneratedYangParser.ModuleHeaderStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterLinkageStatements(GeneratedYangParser.LinkageStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitLinkageStatements(GeneratedYangParser.LinkageStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterMetaStatements(GeneratedYangParser.MetaStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitMetaStatements(GeneratedYangParser.MetaStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRevisionStatements(GeneratedYangParser.RevisionStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRevisionStatements(GeneratedYangParser.RevisionStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterBodyStatements(GeneratedYangParser.BodyStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitBodyStatements(GeneratedYangParser.BodyStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -193,7 +196,7 @@
@Override
public void exitYangVersionStatement(GeneratedYangParser.YangVersionStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -203,7 +206,7 @@
@Override
public void exitNamespaceStatement(GeneratedYangParser.NamespaceStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -213,7 +216,7 @@
@Override
public void exitPrefixStatement(GeneratedYangParser.PrefixStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -228,12 +231,12 @@
@Override
public void enterImportStatementBody(GeneratedYangParser.ImportStatementBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitImportStatementBody(GeneratedYangParser.ImportStatementBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -243,7 +246,7 @@
@Override
public void exitRevisionDateStatement(GeneratedYangParser.RevisionDateStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -263,7 +266,7 @@
@Override
public void exitOrganizationStatement(GeneratedYangParser.OrganizationStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -273,7 +276,7 @@
@Override
public void exitContactStatement(GeneratedYangParser.ContactStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -283,7 +286,7 @@
@Override
public void exitDescriptionStatement(GeneratedYangParser.DescriptionStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -293,7 +296,7 @@
@Override
public void exitReferenceStatement(GeneratedYangParser.ReferenceStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -308,12 +311,12 @@
@Override
public void enterRevisionStatementBody(GeneratedYangParser.RevisionStatementBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRevisionStatementBody(GeneratedYangParser.RevisionStatementBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -328,22 +331,22 @@
@Override
public void enterSubmoduleBody(GeneratedYangParser.SubmoduleBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitSubmoduleBody(GeneratedYangParser.SubmoduleBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterSubmoduleHeaderStatement(GeneratedYangParser.SubmoduleHeaderStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitSubmoduleHeaderStatement(GeneratedYangParser.SubmoduleHeaderStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -358,132 +361,132 @@
@Override
public void enterBelongstoStatementBody(GeneratedYangParser.BelongstoStatementBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitBelongstoStatementBody(GeneratedYangParser.BelongstoStatementBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterExtensionBody(GeneratedYangParser.ExtensionBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitExtensionBody(GeneratedYangParser.ExtensionBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterArgumentStatement(GeneratedYangParser.ArgumentStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitArgumentStatement(GeneratedYangParser.ArgumentStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterArgumentBody(GeneratedYangParser.ArgumentBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitArgumentBody(GeneratedYangParser.ArgumentBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterYinElementStatement(GeneratedYangParser.YinElementStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitYinElementStatement(GeneratedYangParser.YinElementStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterIdentityBody(GeneratedYangParser.IdentityBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitIdentityBody(GeneratedYangParser.IdentityBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterBaseStatement(GeneratedYangParser.BaseStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitBaseStatement(GeneratedYangParser.BaseStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterDataDefStatement(GeneratedYangParser.DataDefStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitDataDefStatement(GeneratedYangParser.DataDefStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -493,7 +496,7 @@
@Override
public void exitUnitsStatement(GeneratedYangParser.UnitsStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -513,77 +516,77 @@
@Override
public void exitTypeStatement(GeneratedYangParser.TypeStatementContext ctx) {
- //TODO: implement the method.
+ TypeListener.processTypeExit(this, ctx);
}
@Override
public void enterTypeBodyStatements(GeneratedYangParser.TypeBodyStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitTypeBodyStatements(GeneratedYangParser.TypeBodyStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRangeStatement(GeneratedYangParser.RangeStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRangeStatement(GeneratedYangParser.RangeStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterCommonStatements(GeneratedYangParser.CommonStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitCommonStatements(GeneratedYangParser.CommonStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterStringRestrictions(GeneratedYangParser.StringRestrictionsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitStringRestrictions(GeneratedYangParser.StringRestrictionsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterLengthStatement(GeneratedYangParser.LengthStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitLengthStatement(GeneratedYangParser.LengthStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterPatternStatement(GeneratedYangParser.PatternStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitPatternStatement(GeneratedYangParser.PatternStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -593,137 +596,137 @@
@Override
public void exitDefaultStatement(GeneratedYangParser.DefaultStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterEnumSpecification(GeneratedYangParser.EnumSpecificationContext ctx) {
- //TODO: implement the method.
+ EnumerationListener.processEnumerationEntry(this, ctx);
}
@Override
public void exitEnumSpecification(GeneratedYangParser.EnumSpecificationContext ctx) {
- //TODO: implement the method.
+ EnumerationListener.processEnumerationExit(this, ctx);
}
@Override
public void enterEnumStatement(GeneratedYangParser.EnumStatementContext ctx) {
- //TODO: implement the method.
+ EnumListener.processEnumEntry(this, ctx);
}
@Override
public void exitEnumStatement(GeneratedYangParser.EnumStatementContext ctx) {
- //TODO: implement the method.
+ EnumListener.processEnumExit(this, ctx);
}
@Override
public void enterEnumStatementBody(GeneratedYangParser.EnumStatementBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitEnumStatementBody(GeneratedYangParser.EnumStatementBodyContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterPathStatement(GeneratedYangParser.PathStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitPathStatement(GeneratedYangParser.PathStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRequireInstanceStatement(GeneratedYangParser.RequireInstanceStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRequireInstanceStatement(GeneratedYangParser.RequireInstanceStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterInstanceIdentifierSpecification(GeneratedYangParser.InstanceIdentifierSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitInstanceIdentifierSpecification(GeneratedYangParser.InstanceIdentifierSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterUnionSpecification(GeneratedYangParser.UnionSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitUnionSpecification(GeneratedYangParser.UnionSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterBitsSpecification(GeneratedYangParser.BitsSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitBitsSpecification(GeneratedYangParser.BitsSpecificationContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterBitStatement(GeneratedYangParser.BitStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitBitStatement(GeneratedYangParser.BitStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterBitBodyStatement(GeneratedYangParser.BitBodyStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitBitBodyStatement(GeneratedYangParser.BitBodyStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterPositionStatement(GeneratedYangParser.PositionStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitPositionStatement(GeneratedYangParser.PositionStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -733,7 +736,7 @@
@Override
public void exitStatusStatement(GeneratedYangParser.StatusStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -743,7 +746,7 @@
@Override
public void exitConfigStatement(GeneratedYangParser.ConfigStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -753,7 +756,7 @@
@Override
public void exitMandatoryStatement(GeneratedYangParser.MandatoryStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -763,47 +766,47 @@
@Override
public void exitPresenceStatement(GeneratedYangParser.PresenceStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterOrderedByStatement(GeneratedYangParser.OrderedByStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitOrderedByStatement(GeneratedYangParser.OrderedByStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterMustStatement(GeneratedYangParser.MustStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitMustStatement(GeneratedYangParser.MustStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -813,7 +816,7 @@
@Override
public void exitMinElementsStatement(GeneratedYangParser.MinElementsStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -823,37 +826,37 @@
@Override
public void exitMaxElementsStatement(GeneratedYangParser.MaxElementsStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterMaxValueArgument(GeneratedYangParser.MaxValueArgumentContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitMaxValueArgument(GeneratedYangParser.MaxValueArgumentContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterValueStatement(GeneratedYangParser.ValueStatementContext ctx) {
- //TODO: implement the method.
+ ValueListener.processValueEntry(this, ctx);
}
@Override
public void exitValueStatement(GeneratedYangParser.ValueStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterGroupingStatement(GeneratedYangParser.GroupingStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitGroupingStatement(GeneratedYangParser.GroupingStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
@@ -903,276 +906,276 @@
@Override
public void exitKeyStatement(GeneratedYangParser.KeyStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterUniqueStatement(GeneratedYangParser.UniqueStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitUniqueStatement(GeneratedYangParser.UniqueStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterChoiceStatement(GeneratedYangParser.ChoiceStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitChoiceStatement(GeneratedYangParser.ChoiceStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterCaseStatement(GeneratedYangParser.CaseStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitCaseStatement(GeneratedYangParser.CaseStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterUsesStatement(GeneratedYangParser.UsesStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitUsesStatement(GeneratedYangParser.UsesStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRefineStatement(GeneratedYangParser.RefineStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRefineStatement(GeneratedYangParser.RefineStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRefineContainerStatements(GeneratedYangParser.RefineContainerStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRefineContainerStatements(GeneratedYangParser.RefineContainerStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRefineLeafStatements(GeneratedYangParser.RefineLeafStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRefineLeafStatements(GeneratedYangParser.RefineLeafStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRefineLeafListStatements(GeneratedYangParser.RefineLeafListStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRefineLeafListStatements(GeneratedYangParser.RefineLeafListStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRefineListStatements(GeneratedYangParser.RefineListStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRefineListStatements(GeneratedYangParser.RefineListStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRefineChoiceStatements(GeneratedYangParser.RefineChoiceStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRefineChoiceStatements(GeneratedYangParser.RefineChoiceStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRefineCaseStatements(GeneratedYangParser.RefineCaseStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRefineCaseStatements(GeneratedYangParser.RefineCaseStatementsContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterUsesAugmentStatement(GeneratedYangParser.UsesAugmentStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitUsesAugmentStatement(GeneratedYangParser.UsesAugmentStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterAugmentStatement(GeneratedYangParser.AugmentStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitAugmentStatement(GeneratedYangParser.AugmentStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterWhenStatement(GeneratedYangParser.WhenStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitWhenStatement(GeneratedYangParser.WhenStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterRpcStatement(GeneratedYangParser.RpcStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitRpcStatement(GeneratedYangParser.RpcStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterInputStatement(GeneratedYangParser.InputStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitInputStatement(GeneratedYangParser.InputStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitOutputStatement(GeneratedYangParser.OutputStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterDeviationStatement(GeneratedYangParser.DeviationStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitDeviationStatement(GeneratedYangParser.DeviationStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterDeviateNotSupportedStatement(GeneratedYangParser.DeviateNotSupportedStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitDeviateNotSupportedStatement(GeneratedYangParser.DeviateNotSupportedStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterString(GeneratedYangParser.StringContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitString(GeneratedYangParser.StringContext ctx) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void visitTerminal(TerminalNode terminalNode) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void visitErrorNode(ErrorNode errorNode) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void enterEveryRule(ParserRuleContext parserRuleContext) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
@Override
public void exitEveryRule(ParserRuleContext parserRuleContext) {
- //TODO: implement the method.
+ // TODO: implement the method.
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
new file mode 100644
index 0000000..e255441
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2014-2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * enum-stmt = enum-keyword sep string optsep
+ * (";" /
+ * "{" stmtsep
+ * ;; these stmts can appear in any order
+ * [value-stmt stmtsep]
+ * [status-stmt stmtsep]
+ * [description-stmt stmtsep]
+ * [reference-stmt stmtsep]
+ * "}")
+ *
+ * ANTLR grammar rule
+ * enumStatement : ENUM_KEYWORD string (STMTEND | LEFT_CURLY_BRACE enumStatementBody RIGHT_CURLY_BRACE);
+ *
+ * enumStatementBody : valueStatement? statusStatement? descriptionStatement? referenceStatement?
+ * | valueStatement? statusStatement? referenceStatement? descriptionStatement?
+ * | valueStatement? descriptionStatement? statusStatement? referenceStatement?
+ * | valueStatement? descriptionStatement? referenceStatement? statusStatement?
+ * | valueStatement? referenceStatement? statusStatement? descriptionStatement?
+ * | valueStatement? referenceStatement? descriptionStatement? statusStatement?
+ * | statusStatement? valueStatement? descriptionStatement? referenceStatement?
+ * | statusStatement? valueStatement? referenceStatement? descriptionStatement?
+ * | statusStatement? descriptionStatement? descriptionStatement? valueStatement?
+ * | statusStatement? descriptionStatement? valueStatement? descriptionStatement?
+ * | statusStatement? referenceStatement? valueStatement? descriptionStatement?
+ * | statusStatement? referenceStatement? descriptionStatement? valueStatement?
+ * | descriptionStatement? valueStatement? statusStatement? referenceStatement?
+ * | descriptionStatement? valueStatement? referenceStatement? statusStatement?
+ * | descriptionStatement? statusStatement? valueStatement? referenceStatement?
+ * | descriptionStatement? statusStatement? referenceStatement? valueStatement?
+ * | descriptionStatement? referenceStatement? valueStatement? statusStatement?
+ * | descriptionStatement? referenceStatement? statusStatement? valueStatement?
+ * | referenceStatement? valueStatement? descriptionStatement? statusStatement?
+ * | referenceStatement? valueStatement? statusStatement? descriptionStatement?
+ * | referenceStatement? statusStatement? descriptionStatement? valueStatement?
+ * | referenceStatement? statusStatement? valueStatement? descriptionStatement?
+ * | referenceStatement? descriptionStatement? valueStatement? statusStatement?
+ * | referenceStatement? descriptionStatement? statusStatement? valueStatement?
+ * ;
+ */
+
+import org.onosproject.yangutils.datamodel.YangEnum;
+import org.onosproject.yangutils.datamodel.YangEnumeration;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.Parsable;
+import static org.onosproject.yangutils.parser.ParsableDataType.ENUM_DATA;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.DUPLICATE_ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Implements listener based call back function corresponding to the "enum" rule
+ * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class EnumListener {
+
+ /**
+ * Creates a new enum listener.
+ */
+ private EnumListener() {
+ }
+
+ /**
+ * It is called when parser enters grammar rule (enum), it perform
+ * validations and updates the data model tree.
+ *
+ * @param listener listener's object.
+ * @param ctx context object of the grammar rule.
+ */
+ public static void processEnumEntry(TreeWalkListener listener, GeneratedYangParser.EnumStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), ENTRY);
+
+ YangEnum enumNode = new YangEnum();
+ enumNode.setNamedValue(ctx.string().getText());
+ listener.getParsedDataStack().push(enumNode);
+ }
+
+ /**
+ * It is called when parser exits from grammar rule (enum), it perform
+ * validations and update the data model tree.
+ *
+ * @param listener Listener's object.
+ * @param ctx context object of the grammar rule.
+ */
+ public static void processEnumExit(TreeWalkListener listener, GeneratedYangParser.EnumStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT);
+
+ Parsable tmpEnumNode = listener.getParsedDataStack().peek();
+ if (tmpEnumNode instanceof YangEnum) {
+ listener.getParsedDataStack().pop();
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case ENUMERATION_DATA: {
+ YangEnumeration yangEnumeration = (YangEnumeration) tmpNode;
+ if ((ctx.enumStatementBody() == null) || (ctx.enumStatementBody().valueStatement() == null)) {
+ int maxValue = 0;
+ boolean isValuePresent = false;
+
+ for (YangEnum curEnum : yangEnumeration.getEnumSet()) {
+ if (maxValue <= curEnum.getValue()) {
+ maxValue = curEnum.getValue();
+ isValuePresent = true;
+ }
+ }
+ if (isValuePresent) {
+ maxValue++;
+ }
+ ((YangEnum) tmpEnumNode).setValue(maxValue);
+ }
+ try {
+ yangEnumeration.addEnumInfo((YangEnum) tmpEnumNode);
+ } catch (DataModelException e) {
+ ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
+ DUPLICATE_ENTRY, ENUM_DATA, ctx.string().getText(), EXIT, e.getMessage()));
+ parserException.setLine(ctx.string().STRING(0).getSymbol().getLine());
+ parserException.setCharPosition(ctx.string().STRING(0).getSymbol().getCharPositionInLine());
+ throw parserException;
+ }
+ break;
+ }
+ default:
+ throw new ParserException(
+ constructListenerErrorMessage(INVALID_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT));
+ }
+ } else {
+ throw new ParserException(
+ constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT));
+ }
+ }
+}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java
new file mode 100644
index 0000000..f83c49c
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2014-2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * type-body-stmts = numerical-restrictions /
+ * decimal64-specification /
+ * string-restrictions /
+ * enum-specification /
+ * leafref-specification /
+ * identityref-specification /
+ * instance-identifier-specification /
+ * bits-specification /
+ * union-specification
+ *
+ * enum-specification = 1*(enum-stmt stmtsep)
+ *
+ * ANTLR grammar rule
+ *
+ * typeBodyStatements : numericalRestrictions | stringRestrictions | enumSpecification
+ * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
+ * | bitsSpecification | unionSpecification;
+ *
+ * enumSpecification : enumStatement+;
+ */
+
+import org.onosproject.yangutils.datamodel.YangEnumeration;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.parser.Parsable;
+import static org.onosproject.yangutils.parser.ParsableDataType.ENUMERATION_DATA;
+import static org.onosproject.yangutils.parser.ParsableDataType.TYPE_DATA;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Implements listener based call back function corresponding to the
+ * "enumeration" rule defined in ANTLR grammar file for corresponding ABNF rule
+ * in RFC 6020.
+ */
+public final class EnumerationListener {
+
+ /**
+ * Creates a new enumeration listener.
+ */
+ private EnumerationListener() {
+ }
+
+ /**
+ * It is called when parser enters grammar rule (enumeration), it perform
+ * validations and updates the data model tree.
+ *
+ * @param listener listener's object.
+ * @param ctx context object of the grammar rule.
+ */
+ public static void processEnumerationEntry(TreeWalkListener listener,
+ GeneratedYangParser.EnumSpecificationContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", ENTRY);
+
+ if (listener.getParsedDataStack().peek() instanceof YangType) {
+ YangEnumeration enumerationNode = new YangEnumeration();
+ Parsable typeData = listener.getParsedDataStack().pop();
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", ENTRY);
+
+ Parsable tmpData = listener.getParsedDataStack().peek();
+
+ switch (tmpData.getParsableDataType()) {
+ case LEAF_DATA:
+ enumerationNode.setEnumerationName(((YangLeaf) tmpData).getLeafName());
+ break;
+ case LEAF_LIST_DATA:
+ enumerationNode.setEnumerationName(((YangLeafList) tmpData).getLeafName());
+ break;
+ // TODO typedef, union, deviate.
+ default:
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
+ ((YangType) typeData).getDataTypeName(), ENTRY));
+ }
+ listener.getParsedDataStack().push(typeData);
+ listener.getParsedDataStack().push(enumerationNode);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ENUMERATION_DATA, "", ENTRY));
+ }
+ }
+
+ /**
+ * It is called when parser exits from grammar rule (enumeration), it
+ * perform validations and update the data model tree.
+ *
+ * @param listener Listener's object.
+ * @param ctx context object of the grammar rule.
+ */
+ public static void processEnumerationExit(TreeWalkListener listener,
+ GeneratedYangParser.EnumSpecificationContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", EXIT);
+
+ Parsable tmpEnumerationNode = listener.getParsedDataStack().peek();
+ if (tmpEnumerationNode instanceof YangEnumeration) {
+ listener.getParsedDataStack().pop();
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", EXIT);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case TYPE_DATA: {
+ YangType typeNode = (YangType) tmpNode;
+ typeNode.setDataTypeExtendedInfo((YangEnumeration) tmpEnumerationNode);
+ break;
+ }
+ default:
+ throw new ParserException(
+ constructListenerErrorMessage(INVALID_HOLDER, ENUMERATION_DATA, "", EXIT));
+ }
+ } else {
+ throw new ParserException(
+ constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUMERATION_DATA, "", EXIT));
+ }
+ }
+}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
index e5ebf36..de595f5 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
@@ -21,18 +21,18 @@
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.parser.Parsable;
+import static org.onosproject.yangutils.parser.ParsableDataType.TYPE_DATA;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.parser.ParsableDataType.TYPE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
@@ -48,8 +48,8 @@
*/
/**
- * Implements listener based call back function corresponding to the "type"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ * Implements listener based call back function corresponding to the "type" rule
+ * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class TypeListener {
@@ -60,15 +60,14 @@
}
/**
- * It is called when parser receives an input matching the grammar
- * rule (type), performs validation and updates the data model
- * tree.
+ * It is called when parser receives an input matching the grammar rule
+ * (type), performs validation and updates the data model tree.
*
* @param listener listener's object.
* @param ctx context object of the grammar rule.
*/
public static void processTypeEntry(TreeWalkListener listener,
- GeneratedYangParser.TypeStatementContext ctx) {
+ GeneratedYangParser.TypeStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY);
@@ -78,21 +77,46 @@
type.setDataTypeName(ctx.string().getText());
type.setDataType(yangDataTypes);
+ listener.getParsedDataStack().push(type);
+ }
+
+ /**
+ * It is called when parser exits from grammar rule (type), it perform
+ * validations and update the data model tree.
+ *
+ * @param listener Listener's object.
+ * @param ctx context object of the grammar rule.
+ */
+ public static void processTypeExit(TreeWalkListener listener,
+ GeneratedYangParser.TypeStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT);
+
+ Parsable type = listener.getParsedDataStack().pop();
+ if (!(type instanceof YangType)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
+ ctx.string().getText(), EXIT));
+ }
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT);
+
Parsable tmpData = listener.getParsedDataStack().peek();
switch (tmpData.getParsableDataType()) {
case LEAF_DATA:
YangLeaf leaf = (YangLeaf) tmpData;
- leaf.setDataType(type);
+ leaf.setDataType((YangType) type);
break;
case LEAF_LIST_DATA:
YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setDataType(type);
+ leafList.setDataType((YangType) type);
break;
case TYPEDEF_DATA: //TODO
break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
- ctx.string().getText(), ENTRY));
+ ctx.string().getText(), EXIT));
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ValueListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ValueListener.java
new file mode 100644
index 0000000..07ada45
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ValueListener.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2014-2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * value-stmt = value-keyword sep integer-value stmtend
+ *
+ * ANTLR grammar rule
+ * valueStatement : VALUE_KEYWORD ((MINUS INTEGER) | INTEGER) STMTEND;
+ */
+
+import org.onosproject.yangutils.datamodel.YangEnum;
+import org.onosproject.yangutils.datamodel.YangEnumeration;
+import org.onosproject.yangutils.parser.Parsable;
+import static org.onosproject.yangutils.parser.ParsableDataType.VALUE_DATA;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Implements listener based call back function corresponding to the "value"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class ValueListener {
+
+ /**
+ * Creates a new value listener.
+ */
+ private ValueListener() {
+ }
+
+ /**
+ * It is called when parser receives an input matching the grammar rule
+ * (value), perform validations and update the data model tree.
+ *
+ * @param listener Listener's object.
+ * @param ctx context object of the grammar rule.
+ */
+ public static void processValueEntry(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, VALUE_DATA, ctx.INTEGER().getText(), ENTRY);
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case ENUM_DATA: {
+ YangEnum enumNode = (YangEnum) tmpNode;
+ if (!isEnumValueValid(listener, ctx)) {
+ ParserException parserException = new ParserException("Input version not supported");
+ parserException.setLine(ctx.INTEGER().getSymbol().getLine());
+ parserException.setCharPosition(ctx.INTEGER().getSymbol().getCharPositionInLine());
+ throw parserException;
+ }
+ enumNode.setValue(Integer.valueOf(ctx.INTEGER().getText()));
+ break;
+ }
+ default:
+ throw new ParserException(
+ constructListenerErrorMessage(INVALID_HOLDER, VALUE_DATA, ctx.INTEGER().getText(), ENTRY));
+ }
+ }
+
+ /**
+ * Validates ENUM value uniqueness.
+ *
+ * @param listener Listener's object.
+ * @param ctx context object of the grammar rule.
+ * @return validation result
+ */
+ private static boolean isEnumValueValid(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx) {
+ Parsable enumNode = listener.getParsedDataStack().pop();
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case ENUMERATION_DATA: {
+ YangEnumeration yangEnumeration = (YangEnumeration) tmpNode;
+ for (YangEnum curEnum : yangEnumeration.getEnumSet()) {
+ if (Integer.valueOf(ctx.INTEGER().getText()) == curEnum.getValue()) {
+ listener.getParsedDataStack().push(enumNode);
+ return false;
+ }
+ }
+ listener.getParsedDataStack().push(enumNode);
+ return true;
+ }
+ default:
+ listener.getParsedDataStack().push(enumNode);
+ throw new ParserException(
+ constructListenerErrorMessage(INVALID_HOLDER, VALUE_DATA, ctx.INTEGER().getText(), EXIT));
+ }
+ }
+}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java b/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java
index 13925bc..e28d186 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java
@@ -21,22 +21,26 @@
*/
public enum ListenerErrorType {
/**
- * Represents the parent holder in parsable stack for given YANG construct is invalid.
+ * Represents the parent holder in parsable stack for given YANG construct
+ * is invalid.
*/
INVALID_HOLDER(),
/**
- * Represents the parent holder in parsable stack for given YANG construct is missing.
+ * Represents the parent holder in parsable stack for given YANG construct
+ * is missing.
*/
MISSING_HOLDER(),
/**
- * Represents the current holder in parsable stack for given YANG construct is missing.
+ * Represents the current holder in parsable stack for given YANG construct
+ * is missing.
*/
MISSING_CURRENT_HOLDER(),
/**
- * Represents that the child in parsable stack for given YANG construct is invalid.
+ * Represents that the child in parsable stack for given YANG construct is
+ * invalid.
*/
INVALID_CHILD(),
@@ -46,6 +50,11 @@
INVALID_CARDINALITY(),
/**
+ * Represents that the entry is duplicate.
+ */
+ DUPLICATE_ENTRY(),
+
+ /**
* Represents that some of earlier parsed data is not handled correctly.
*/
UNHANDLED_PARSED_DATA();
@@ -59,20 +68,22 @@
public static String getErrorType(ListenerErrorType errorType) {
switch (errorType) {
- case INVALID_HOLDER:
- return "Invalid holder for";
- case MISSING_HOLDER:
- return "Missing holder at";
- case MISSING_CURRENT_HOLDER:
- return "Missing";
- case INVALID_CHILD:
- return "Invalid child in";
- case INVALID_CARDINALITY:
- return "Invalid cardinality in";
- case UNHANDLED_PARSED_DATA:
- return "Unhandled parsed data at";
- default:
- return "Problem in";
+ case INVALID_HOLDER:
+ return "Invalid holder for";
+ case MISSING_HOLDER:
+ return "Missing holder at";
+ case MISSING_CURRENT_HOLDER:
+ return "Missing";
+ case INVALID_CHILD:
+ return "Invalid child in";
+ case INVALID_CARDINALITY:
+ return "Invalid cardinality in";
+ case DUPLICATE_ENTRY:
+ return "Duplicate";
+ case UNHANDLED_PARSED_DATA:
+ return "Unhandled parsed data at";
+ default:
+ return "Problem in";
}
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java
new file mode 100644
index 0000000..60de57f
--- /dev/null
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/EnumListenerTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2014-2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangEnum;
+import org.onosproject.yangutils.datamodel.YangEnumeration;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+ * Test cases for enum listener.
+ */
+public class EnumListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks enum statement without value.
+ */
+ @Test
+ public void processEnumTypeStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/EnumTypeStatement.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getLeafName(), is("speed"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
+ assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumerationName(),
+ is("speed"));
+
+ Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
+ for (YangEnum tmp : enumSet) {
+ if (tmp.getNamedValue().equals("10m")) {
+ assertThat(tmp.getValue(), is(0));
+ } else if (tmp.getNamedValue().equals("100m")) {
+ assertThat(tmp.getValue(), is(1));
+ } else if (tmp.getNamedValue().equals("auto")) {
+ assertThat(tmp.getValue(), is(2));
+ }
+ }
+ }
+}
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ValueListenerTest.java b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ValueListenerTest.java
new file mode 100644
index 0000000..2339363
--- /dev/null
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ValueListenerTest.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2014-2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangEnum;
+import org.onosproject.yangutils.datamodel.YangEnumeration;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+ * Test cases for value listener.
+ */
+public class ValueListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks explicitly configured value.
+ */
+ @Test
+ public void processValueStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ValueStatement.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getLeafName(), is("speed"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
+ assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumerationName(),
+ is("speed"));
+
+ Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
+ for (YangEnum tmp : enumSet) {
+ if (tmp.getNamedValue().equals("10m")) {
+ assertThat(tmp.getValue(), is(10));
+ } else if (tmp.getNamedValue().equals("100m")) {
+ assertThat(tmp.getValue(), is(100));
+ } else if (tmp.getNamedValue().equals("auto")) {
+ assertThat(tmp.getValue(), is(1000));
+ }
+ }
+ }
+
+ /**
+ * Checks explicit value and auto generated value.
+ */
+ @Test
+ public void processValueAndAutoStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ValueAndAutoStatement.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getLeafName(), is("speed"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
+ assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumerationName(),
+ is("speed"));
+
+ Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
+ for (YangEnum tmp : enumSet) {
+ if (tmp.getNamedValue().equals("10m")) {
+ assertThat(tmp.getValue(), is(10));
+ } else if (tmp.getNamedValue().equals("100m")) {
+ assertThat(tmp.getValue(), is(11));
+ } else if (tmp.getNamedValue().equals("auto")) {
+ assertThat(tmp.getValue(), is(1000));
+ }
+ }
+ }
+
+ /**
+ * Checks explicit value should not be repeated.
+ */
+ @Test(expected = ParserException.class)
+ public void processValueDuplication() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ValueDuplication.yang");
+ }
+
+ /**
+ * Checks explicit or auto generated value should not be repeated.
+ */
+ @Test(expected = ParserException.class)
+ public void processValueExplicitAndAutoDuplication() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ValueExplicitAndAutoDuplication.yang");
+ }
+}
diff --git a/src/test/resources/EnumTypeStatement.yang b/src/test/resources/EnumTypeStatement.yang
new file mode 100644
index 0000000..1d64805
--- /dev/null
+++ b/src/test/resources/EnumTypeStatement.yang
@@ -0,0 +1,12 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf speed {
+ type enumeration {
+ enum 10m;
+ enum 100m;
+ enum auto;
+ }
+ }
+}
diff --git a/src/test/resources/ValueAndAutoStatement.yang b/src/test/resources/ValueAndAutoStatement.yang
new file mode 100644
index 0000000..31f098e
--- /dev/null
+++ b/src/test/resources/ValueAndAutoStatement.yang
@@ -0,0 +1,16 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf speed {
+ type enumeration {
+ enum 10m {
+ value 10;
+ }
+ enum 100m;
+ enum auto {
+ value 1000;
+ }
+ }
+ }
+}
diff --git a/src/test/resources/ValueDuplication.yang b/src/test/resources/ValueDuplication.yang
new file mode 100644
index 0000000..339a737
--- /dev/null
+++ b/src/test/resources/ValueDuplication.yang
@@ -0,0 +1,18 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf speed {
+ type enumeration {
+ enum 10m {
+ value 10;
+ }
+ enum 100m {
+ value 100;
+ }
+ enum auto {
+ value 10;
+ }
+ }
+ }
+}
diff --git a/src/test/resources/ValueExplicitAndAutoDuplication.yang b/src/test/resources/ValueExplicitAndAutoDuplication.yang
new file mode 100644
index 0000000..3e58155
--- /dev/null
+++ b/src/test/resources/ValueExplicitAndAutoDuplication.yang
@@ -0,0 +1,16 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf speed {
+ type enumeration {
+ enum 10m {
+ value 10;
+ }
+ enum 100m;
+ enum auto {
+ value 11;
+ }
+ }
+ }
+}
diff --git a/src/test/resources/ValueStatement.yang b/src/test/resources/ValueStatement.yang
new file mode 100644
index 0000000..f461359
--- /dev/null
+++ b/src/test/resources/ValueStatement.yang
@@ -0,0 +1,18 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf speed {
+ type enumeration {
+ enum 10m {
+ value 10;
+ }
+ enum 100m {
+ value 100;
+ }
+ enum auto {
+ value 1000;
+ }
+ }
+ }
+}