YANG: Restriction resolution implementation

Change-Id: I69503e8229def07b289a0c8c762bfe0ae5530232
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/LocationInfo.java b/src/main/java/org/onosproject/yangutils/datamodel/LocationInfo.java
new file mode 100644
index 0000000..edd8849
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/LocationInfo.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-present 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.datamodel;
+
+/**
+ * Abstraction of location information, this is used during resolution is
+ * carried out and line/character position in line is required to point
+ * out the error location in YANG file.
+ */
+public interface LocationInfo {
+
+    /**
+     * Returns the line number YANG construct in file.
+     *
+     * @return the line number YANG construct in file
+     */
+    int getLineNumber();
+
+    /**
+     * Returns the character position in line.
+     *
+     * @return the character position in line
+     */
+    int getCharPosition();
+
+    /**
+     * Sets line number of YANG construct.
+     *
+     * @param lineNumber the line number of YANG construct in file
+     */
+    void setLineNumber(int lineNumber);
+
+    /**
+     * Sets character position of YANG construct.
+     *
+     * @param charPositionInLine character position of YANG construct in file
+     */
+    void setCharPosition(int charPositionInLine);
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangDataTypes.java b/src/main/java/org/onosproject/yangutils/datamodel/YangDataTypes.java
index 601a831..32408d9 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangDataTypes.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangDataTypes.java
@@ -228,7 +228,7 @@
     public static YangDataTypes getType(String name) {
         name = name.replace("\"", "");
         for (YangDataTypes yangDataType : values()) {
-            if (yangDataType.name().equalsIgnoreCase(name)) {
+            if (yangDataType.name().toLowerCase().equals(name)) {
                 return yangDataType;
             }
         }
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java b/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
index a0e83ec..8c94d7d 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
@@ -16,12 +16,30 @@
 
 package org.onosproject.yangutils.datamodel;
 
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import com.google.common.base.Strings;
+
+import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.BITS;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.EMPTY;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.ENUMERATION;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.IDENTITYREF;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION;
+import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
+import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
+import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction;
+
 /**
  * Represents the derived information.
  *
  * @param <T> extended information.
  */
-public class YangDerivedInfo<T> {
+public class YangDerivedInfo<T> implements LocationInfo {
 
     /**
      * YANG typedef reference.
@@ -36,11 +54,38 @@
     private T resolvedExtendedInfo;
 
     /**
-     * Additional information about data type, example restriction info, named
-     * values, etc. The extra information is based on the data type. Based on
-     * the data type, the extended info can vary.
+     * Line number of pattern restriction in YANG file.
      */
-    private T extendedInfo;
+    private int lineNumber;
+
+    /**
+     * Position of pattern restriction in line.
+     */
+    private int charPositionInLine;
+
+    /**
+     * Effective built-in type, requried in case type of typedef is again a
+     * derived type. This information is to be added during linking.
+     */
+    private YangDataTypes effectiveBuiltInType;
+
+    /**
+     * Length restriction string to temporary store the length restriction when the type
+     * is derived.
+     */
+    private String lengthRestrictionString;
+
+    /**
+     * Range restriction string to temporary store the range restriction when the type
+     * is derived.
+     */
+    private String rangeRestrictionString;
+
+    /**
+     * Pattern restriction string to  temporary store the pattern restriction when the type
+     * is derived.
+     */
+    private YangPatternRestriction patternRestriction;
 
     /**
      * Returns the referred typedef reference.
@@ -78,21 +123,503 @@
         this.resolvedExtendedInfo = resolvedExtendedInfo;
     }
 
-    /**
-     * Returns extended information.
-     *
-     * @return extended information
-     */
-    public T getExtendedInfo() {
-        return extendedInfo;
+    @Override
+    public int getLineNumber() {
+        return lineNumber;
+    }
+
+    @Override
+    public int getCharPosition() {
+        return charPositionInLine;
+    }
+
+    @Override
+    public void setLineNumber(int lineNumber) {
+        this.lineNumber = lineNumber;
+    }
+
+    @Override
+    public void setCharPosition(int charPositionInLine) {
+        this.charPositionInLine = charPositionInLine;
     }
 
     /**
-     * Sets extended information.
+     * Returns the length restriction string.
      *
-     * @param extendedInfo extended information
+     * @return the length restriction string
      */
-    public void setExtendedInfo(T extendedInfo) {
-        this.extendedInfo = extendedInfo;
+    public String getLengthRestrictionString() {
+        return lengthRestrictionString;
+    }
+
+    /**
+     * Sets the length restriction string.
+     *
+     * @param lengthRestrictionString the length restriction string
+     */
+    public void setLengthRestrictionString(String lengthRestrictionString) {
+        this.lengthRestrictionString = lengthRestrictionString;
+    }
+
+    /**
+     * Returns the range restriction string.
+     *
+     * @return the range restriction string
+     */
+    public String getRangeRestrictionString() {
+        return rangeRestrictionString;
+    }
+
+    /**
+     * Sets the range restriction string.
+     *
+     * @param rangeRestrictionString the range restriction string
+     */
+    public void setRangeRestrictionString(String rangeRestrictionString) {
+        this.rangeRestrictionString = rangeRestrictionString;
+    }
+
+    /**
+     * Returns the pattern restriction.
+     *
+     * @return the pattern restriction
+     */
+    public YangPatternRestriction getPatternRestriction() {
+        return patternRestriction;
+    }
+
+    /**
+     * Sets the pattern restriction.
+     *
+     * @param patternRestriction the pattern restriction
+     */
+    public void setPatternRestriction(YangPatternRestriction patternRestriction) {
+        this.patternRestriction = patternRestriction;
+    }
+
+    /**
+     * Returns effective built-in type.
+     *
+     * @return effective built-in type
+     */
+    public YangDataTypes getEffectiveBuiltInType() {
+        return effectiveBuiltInType;
+    }
+
+    /**
+     * Sets effective built-in type.
+     *
+     * @param effectiveBuiltInType effective built-in type
+     */
+    public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) {
+        this.effectiveBuiltInType = effectiveBuiltInType;
+    }
+
+    /**
+     * Resolves the type derived info, by obtaining the effective built-in type
+     * and resolving the restrictions.
+     *
+     * @return resolution status
+     * @throws DataModelException a violation in data mode rule
+     */
+    public ResolvableStatus resolve() throws DataModelException {
+
+        YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType();
+
+        /*
+         * Checks the data type of the referred typedef, if it's derived,
+         * obtain effective built-in type and restrictions from it's derived
+         * info, otherwise take from the base type of type itself.
+         */
+        if (baseType.getDataType() == DERIVED) {
+            /*
+             * Check whether the referred typedef is resolved.
+             */
+            if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
+                throw new DataModelException("Linker Error: Referred typedef is not resolved.");
+            }
+
+            /*
+             * Check if the referred typedef is intra file resolved, if yes sets
+             * current status also to intra file resolved .
+             */
+            if (getReferredTypeDef().getTypeDefBaseType().getResolvableStatus() == INTRA_FILE_RESOLVED) {
+                return INTRA_FILE_RESOLVED;
+            }
+            setEffectiveBuiltInType(((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo())
+                    .getEffectiveBuiltInType());
+            YangDerivedInfo refDerivedInfo = ((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo());
+            /*
+             * Check whether the effective built-in type can have range
+             * restrictions, if yes call resolution of range.
+             */
+            if (isOfRangeRestrictedType(getEffectiveBuiltInType())) {
+                if (refDerivedInfo.getResolvedExtendedInfo() == null) {
+                    resolveRangeRestriction(null);
+                    /*
+                     * Return the resolution status as resolved, if it's not
+                     * resolve range/string restriction will throw exception
+                     * in previous function.
+                     */
+                    return RESOLVED;
+                } else {
+                    if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
+                        throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+                                "type.");
+                    }
+                    resolveRangeRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
+                    /*
+                     * Return the resolution status as resolved, if it's not
+                     * resolve range/string restriction will throw exception
+                     * in previous function.
+                     */
+                    return RESOLVED;
+                }
+                /*
+                 * If the effective built-in type is of type string calls
+                 * for string resolution.
+                 */
+            } else if (getEffectiveBuiltInType() == STRING) {
+                if (refDerivedInfo.getResolvedExtendedInfo() == null) {
+                    resolveStringRestriction(null);
+                    /*
+                     * Return the resolution status as resolved, if it's not
+                     * resolve range/string restriction will throw exception
+                     * in previous function.
+                     */
+                    return RESOLVED;
+                } else {
+                    if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangStringRestriction)) {
+                        throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+                                "type.");
+                    }
+                    resolveStringRestriction((YangStringRestriction) refDerivedInfo.getResolvedExtendedInfo());
+                    /*
+                     * Return the resolution status as resolved, if it's not
+                     * resolve range/string restriction will throw exception
+                     * in previous function.
+                     */
+                    return RESOLVED;
+                }
+            }
+        } else {
+            setEffectiveBuiltInType((baseType.getDataType()));
+            /*
+             * Check whether the effective built-in type can have range
+             * restrictions, if yes call resolution of range.
+             */
+            if (isOfRangeRestrictedType(getEffectiveBuiltInType())) {
+                if (baseType.getDataTypeExtendedInfo() == null) {
+                    resolveRangeRestriction(null);
+                    /*
+                     * Return the resolution status as resolved, if it's not
+                     * resolve range/string restriction will throw exception
+                     * in previous function.
+                     */
+                    return RESOLVED;
+                } else {
+                    if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
+                        throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+                                "type.");
+                    }
+                    resolveRangeRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
+                    /*
+                     * Return the resolution status as resolved, if it's not
+                     * resolve range/string restriction will throw exception
+                     * in previous function.
+                     */
+                    return RESOLVED;
+                }
+                /*
+                 * If the effective built-in type is of type string calls
+                 * for string resolution.
+                 */
+            } else if (getEffectiveBuiltInType() == STRING) {
+                if (baseType.getDataTypeExtendedInfo() == null) {
+                    resolveStringRestriction(null);
+                    /*
+                     * Return the resolution status as resolved, if it's not
+                     * resolve range/string restriction will throw exception
+                     * in previous function.
+                     */
+                    return RESOLVED;
+                } else {
+                    if (!(baseType.getDataTypeExtendedInfo() instanceof YangStringRestriction)) {
+                        throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
+                                "type.");
+                    }
+                    resolveStringRestriction((YangStringRestriction) baseType.getDataTypeExtendedInfo());
+                    /*
+                     * Return the resolution status as resolved, if it's not
+                     * resolve range/string restriction will throw exception
+                     * in previous function.
+                     */
+                    return RESOLVED;
+                }
+            }
+        }
+
+        /*
+         * Check if the data type is the one which can't be restricted, in
+         * this case check whether no self restrictions should be present.
+         */
+        if (isOfValidNonRestrictedType(getEffectiveBuiltInType())) {
+            if (Strings.isNullOrEmpty(getLengthRestrictionString())
+                    && Strings.isNullOrEmpty(getRangeRestrictionString())
+                    && getPatternRestriction() == null) {
+                return RESOLVED;
+            } else {
+                throw new DataModelException("YANG file error: Restrictions can't be applied to a given type");
+            }
+        }
+
+        // Throw exception for unsupported types
+        throw new DataModelException("Linker error: Unable to process the derived type.");
+    }
+
+    /**
+     * Resolves the string restrictions.
+     *
+     * @param refStringRestriction referred string restriction of typedef
+     * @throws DataModelException a violation in data model rule
+     */
+    private void resolveStringRestriction(YangStringRestriction refStringRestriction) throws DataModelException {
+        YangStringRestriction curStringRestriction = null;
+        YangRangeRestriction refRangeRestriction = null;
+        YangPatternRestriction refPatternRestriction = null;
+
+        /*
+         * Check that range restriction should be null when built-in type is
+         * string.
+         */
+        if (!(Strings.isNullOrEmpty(getRangeRestrictionString()))) {
+            DataModelException dataModelException = new DataModelException("YANG file error: Range restriction " +
+                    "should't be present for string data type.");
+            dataModelException.setLine(lineNumber);
+            dataModelException.setCharPosition(charPositionInLine);
+            throw dataModelException;
+        }
+
+        /*
+         * If referred restriction and self restriction both are null, no
+         * resolution is required.
+         */
+        if (refStringRestriction == null && Strings.isNullOrEmpty(getLengthRestrictionString())
+                && getPatternRestriction() == null) {
+            return;
+        }
+
+        /*
+         * If referred string restriction is not null, take value of length
+         * and pattern restriction and assign.
+         */
+        if (refStringRestriction != null) {
+            refRangeRestriction = refStringRestriction.getLengthRestriction();
+            refPatternRestriction = refStringRestriction.getPatternRestriction();
+        }
+
+        YangRangeRestriction lengthRestriction = resolveLengthRestriction(refRangeRestriction);
+        YangPatternRestriction patternRestriction = resolvePatternRestriction(refPatternRestriction);
+
+        /*
+         * Check if either of length or pattern restriction is present, if yes
+         * create string restriction and assign value.
+         */
+        if (lengthRestriction != null || patternRestriction != null) {
+            curStringRestriction = new YangStringRestriction();
+            curStringRestriction.setLengthRestriction(lengthRestriction);
+            curStringRestriction.setPatternRestriction(patternRestriction);
+        }
+        setResolvedExtendedInfo((T) curStringRestriction);
+    }
+
+    /**
+     * Resolves pattern restriction.
+     *
+     * @param refPatternRestriction referred pattern restriction of typedef
+     * @return resolved pattern restriction
+     */
+    private YangPatternRestriction resolvePatternRestriction(YangPatternRestriction refPatternRestriction) {
+        /*
+         * If referred restriction and self restriction both are null, no
+         * resolution is required.
+         */
+        if (refPatternRestriction == null && getPatternRestriction() == null) {
+            return null;
+        }
+
+        /*
+         * If self restriction is null, and referred restriction is present
+         * shallow copy the referred to self.
+         */
+        if (getPatternRestriction() == null) {
+            return refPatternRestriction;
+        }
+
+        /*
+         * If referred restriction is null, and self restriction is present
+         * carry out self resolution.
+         */
+        if (refPatternRestriction == null) {
+            return getPatternRestriction();
+        }
+
+        /*
+         * Get patterns of referred type and add it to current pattern
+         * restrictions.
+         */
+        for (String pattern : refPatternRestriction.getPatternList()) {
+            getPatternRestriction().addPattern(pattern);
+        }
+        return getPatternRestriction();
+    }
+
+    /**
+     * Resolves the length restrictions.
+     *
+     * @param refLengthRestriction referred length restriction of typedef
+     * @return resolved length restriction
+     * @throws DataModelException a violation in data model rule
+     */
+    private YangRangeRestriction resolveLengthRestriction(YangRangeRestriction refLengthRestriction) throws
+            DataModelException {
+
+        /*
+         * If referred restriction and self restriction both are null, no
+         * resolution is required.
+         */
+        if (refLengthRestriction == null && Strings.isNullOrEmpty(getLengthRestrictionString())) {
+            return null;
+        }
+
+        /*
+         * If self restriction is null, and referred restriction is present
+         * shallow copy the referred to self.
+         */
+        if (Strings.isNullOrEmpty(getLengthRestrictionString())) {
+            return refLengthRestriction;
+        }
+
+        /*
+         * If referred restriction is null, and self restriction is present
+         * carry out self resolution.
+         */
+        if (refLengthRestriction == null) {
+            YangRangeRestriction curLengthRestriction = processLengthRestriction(null, lineNumber,
+                    charPositionInLine, false, getLengthRestrictionString());
+            return curLengthRestriction;
+        }
+
+        /*
+         * Carry out self resolution based with obtained effective built-in
+         * type and MIN/MAX values as per the referred typedef's values.
+         */
+        YangRangeRestriction curLengthRestriction = processLengthRestriction(refLengthRestriction, lineNumber,
+                charPositionInLine, true, getLengthRestrictionString());
+
+        // Resolve the range with referred typedef's restriction.
+        resolveLengthAndRangeRestriction(refLengthRestriction, curLengthRestriction);
+        return curLengthRestriction;
+    }
+
+    /**
+     * Resolves the length/range self and referred restriction, to check whether
+     * the all the range interval in self restriction is stricter than the
+     * referred typedef's restriction.
+     *
+     * @param refRestriction referred restriction
+     * @param curRestriction self restriction
+     */
+    private void resolveLengthAndRangeRestriction(YangRangeRestriction refRestriction,
+                                                  YangRangeRestriction curRestriction) throws DataModelException {
+        for (Object curInterval : curRestriction.getAscendingRangeIntervals()) {
+            if (!(curInterval instanceof YangRangeInterval)) {
+                throw new DataModelException("Linker error: Current range intervals not processed correctly.");
+            }
+            try {
+                refRestriction.isValidInterval((YangRangeInterval) curInterval);
+            } catch (DataModelException e) {
+                DataModelException dataModelException = new DataModelException(e);
+                dataModelException.setLine(lineNumber);
+                dataModelException.setCharPosition(charPositionInLine);
+                throw dataModelException;
+            }
+        }
+    }
+
+    /**
+     * Resolves the range restrictions.
+     *
+     * @param refRangeRestriction referred range restriction of typedef
+     * @throws DataModelException a violation in data model rule
+     */
+    private void resolveRangeRestriction(YangRangeRestriction refRangeRestriction) throws DataModelException {
+
+        /*
+         * Check that string restriction should be null when built-in type is
+         * of range type.
+         */
+        if (!(Strings.isNullOrEmpty(getLengthRestrictionString())) || getPatternRestriction() != null) {
+            DataModelException dataModelException = new DataModelException("YANG file error: Length/Pattern " +
+                    "restriction should't be present for int/uint/decimal data type.");
+            dataModelException.setLine(lineNumber);
+            dataModelException.setCharPosition(charPositionInLine);
+            throw dataModelException;
+        }
+
+        /*
+         * If referred restriction and self restriction both are null, no
+         * resolution is required.
+         */
+        if (refRangeRestriction == null && Strings.isNullOrEmpty(getRangeRestrictionString())) {
+            return;
+        }
+
+        /*
+         * If self restriction is null, and referred restriction is present
+         * shallow copy the referred to self.
+         */
+        if (Strings.isNullOrEmpty(getRangeRestrictionString())) {
+            setResolvedExtendedInfo((T) refRangeRestriction);
+            return;
+        }
+
+        /*
+         * If referred restriction is null, and self restriction is present
+         * carry out self resolution.
+         */
+        if (refRangeRestriction == null) {
+            YangRangeRestriction curRangeRestriction = processRangeRestriction(null, lineNumber,
+                    charPositionInLine, false, getRangeRestrictionString(), getEffectiveBuiltInType());
+            setResolvedExtendedInfo((T) curRangeRestriction);
+            return;
+        }
+
+        /*
+         * Carry out self resolution based with obtained effective built-in
+         * type and MIN/MAX values as per the referred typedef's values.
+         */
+        YangRangeRestriction curRangeRestriction = processRangeRestriction(refRangeRestriction, lineNumber,
+                charPositionInLine, true, getRangeRestrictionString(), getEffectiveBuiltInType());
+
+        // Resolve the range with referred typedef's restriction.
+        resolveLengthAndRangeRestriction(refRangeRestriction, curRangeRestriction);
+        setResolvedExtendedInfo((T) curRangeRestriction);
+    }
+
+    /**
+     * Returns whether the data type is of non restricted type.
+     *
+     * @param dataType data type to be checked
+     * @return true, if data type can't be restricted, false otherwise
+     */
+    private boolean isOfValidNonRestrictedType(YangDataTypes dataType) {
+        return (dataType == BOOLEAN
+                || dataType == ENUMERATION
+                || dataType == BITS
+                || dataType == EMPTY
+                || dataType == UNION
+                || dataType == IDENTITYREF
+                || dataType == LEAFREF);
     }
 }
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java b/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
index 1233b08..997e4b6 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
@@ -46,6 +46,7 @@
  *   | reference     | 7.19.4  | 0..1        |
  *   +---------------+---------+-------------+
  */
+
 /**
  * Represents pattern restriction information. The regular expression restriction on string
  * data type.
@@ -58,11 +59,6 @@
     private List<String> patternList;
 
     /**
-     * Effective pattern restriction that needs inherited from base type.
-     */
-    private List<String> basePattern;
-
-    /**
      * Creates a YANG pattern restriction object.
      */
     public YangPatternRestriction() {
@@ -95,22 +91,4 @@
     public void addPattern(String newPattern) {
         getPatternList().add(newPattern);
     }
-
-    /**
-     * Returns the pattern restriction defined in base type.
-     *
-     * @return pattern restriction defined in base type.
-     */
-    public List<String> getBasePattern() {
-        return basePattern;
-    }
-
-    /**
-     * Sets the pattern restriction defined in base type.
-     *
-     * @param basePattern pattern restriction defined in base type.
-     */
-    public void setBasePattern(List<String> basePattern) {
-        this.basePattern = basePattern;
-    }
 }
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java b/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
index 39c2cb5..d66f170 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
@@ -18,7 +18,6 @@
 
 import java.util.LinkedList;
 import java.util.List;
-
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
 
@@ -111,8 +110,8 @@
     /**
      * Returns the minimum valid value as per the restriction.
      *
-     * @throws DataModelException data model exception for minimum restriction
      * @return minimum restricted value
+     * @throws DataModelException data model exception for minimum restriction
      */
     public T getMinRestrictedvalue() throws DataModelException {
         if (getAscendingRangeIntervals() == null) {
@@ -127,8 +126,8 @@
     /**
      * Returns the maximum valid value as per the restriction.
      *
-     * @throws DataModelException data model exception for maximum restriction
      * @return minimum maximum value
+     * @throws DataModelException data model exception for maximum restriction
      */
     public T getMaxRestrictedvalue() throws DataModelException {
         if (getAscendingRangeIntervals() == null) {
@@ -175,7 +174,7 @@
     }
 
     /**
-     * Check if the given value is correct as per the restriction.
+     * Validates if the given value is correct as per the restriction.
      *
      * @param valueInString value
      * @return true, if the value is confirming to restriction, false otherwise
@@ -206,6 +205,32 @@
     }
 
     /**
+     * Validates if the given interval is correct as per the restriction.
+     *
+     * @param rangeInterval range interval
+     * @return true, if the interval is confirming to restriction, false otherwise
+     * @throws DataModelException data model error
+     */
+    public boolean isValidInterval(YangRangeInterval rangeInterval) throws DataModelException {
+
+        if (getAscendingRangeIntervals() == null
+                || getAscendingRangeIntervals().isEmpty()) {
+            // Throw exception, At least one default range needs to be set in constructor or in linker.
+            throw new DataModelException("Range interval missing in range restriction.");
+        }
+
+        for (YangRangeInterval<T> interval : getAscendingRangeIntervals()) {
+            int rangeStartCompareRes = interval.getStartValue().compareTo((T) rangeInterval.getStartValue());
+            int rangeEndCompareRes = interval.getEndValue().compareTo((T) rangeInterval.getEndValue());
+
+            if (rangeStartCompareRes <= 0 && rangeEndCompareRes >= 0) {
+                return true;
+            }
+        }
+        throw new DataModelException("Range interval doesn't fall within the referred restriction ranges");
+    }
+
+    /**
      * Returns the textual reference of the length restriction.
      *
      * @return textual reference of the length restriction
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java b/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
index 1d7fb9a..ac2d6b3 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
@@ -17,7 +17,6 @@
 package org.onosproject.yangutils.datamodel;
 
 import java.util.Stack;
-
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
 
 import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
@@ -30,7 +29,7 @@
  *
  * @param <T> type of resolution entity uses / type
  */
-public class YangResolutionInfo<T> {
+public class YangResolutionInfo<T> implements LocationInfo {
 
     /**
      * Information about the entity that needs to be resolved.
@@ -64,9 +63,9 @@
     /**
      * Creates a resolution information object with all the inputs.
      *
-     * @param dataNode current parsable data node
-     * @param holderNode parent YANG node
-     * @param lineNumber error line number
+     * @param dataNode           current parsable data node
+     * @param holderNode         parent YANG node
+     * @param lineNumber         error line number
      * @param charPositionInLine error character position in line
      */
     public YangResolutionInfo(T dataNode, YangNode holderNode, int lineNumber, int charPositionInLine) {
@@ -193,7 +192,6 @@
     private void resolveTopOfStack()
             throws DataModelException {
         ((Resolvable) getCurrentEntityToResolveFromStack()).resolve();
-
         if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus()
                 != INTRA_FILE_RESOLVED) {
             // Sets the resolution status in inside the type/uses.
@@ -453,42 +451,6 @@
     }
 
     /**
-     * Returns error position.
-     *
-     * @return error position
-     */
-    public int getCharPosition() {
-        return charPosition;
-    }
-
-    /**
-     * Sets error position.
-     *
-     * @param charPosition position of error
-     */
-    public void setCharPosition(int charPosition) {
-        this.charPosition = charPosition;
-    }
-
-    /**
-     * Returns error character position in line.
-     *
-     * @return error character position in line
-     */
-    public int getLineNumber() {
-        return lineNumber;
-    }
-
-    /**
-     * Sets error character position in line.
-     *
-     * @param lineNumber error character position in line
-     */
-    public void setLineNumber(int lineNumber) {
-        this.lineNumber = lineNumber;
-    }
-
-    /**
      * Returns stack of YANG type with partially resolved YANG construct
      * hierarchy.
      *
@@ -539,9 +501,29 @@
      * Sets information about the entity that needs to be resolved.
      *
      * @param entityToResolveInfo information about the entity that needs to be
-     * resolved
+     *                            resolved
      */
     public void setEntityToResolveInfo(YangEntityToResolveInfo<T> entityToResolveInfo) {
         this.entityToResolveInfo = entityToResolveInfo;
     }
+
+    @Override
+    public int getLineNumber() {
+        return lineNumber;
+    }
+
+    @Override
+    public int getCharPosition() {
+        return charPosition;
+    }
+
+    @Override
+    public void setLineNumber(int lineNumber) {
+        this.lineNumber = lineNumber;
+    }
+
+    @Override
+    public void setCharPosition(int charPositionInLine) {
+        this.charPosition = charPositionInLine;
+    }
 }
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java b/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
index f2c67c3..715e315 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
@@ -24,6 +24,7 @@
  * A string can be restricted with the "length" and "pattern" statements.
  *
  */
+
 /**
  * Represents the restriction for string data type.
  */
@@ -113,7 +114,7 @@
      *
      * @param patternRestriction pattern restriction for the type
      */
-    private void setPatternRestriction(YangPatternRestriction patternRestriction) {
+    public void setPatternRestriction(YangPatternRestriction patternRestriction) {
         this.patternRestriction = patternRestriction;
     }
 
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangType.java b/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
index 2a0c878..d37a8c7 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
@@ -20,7 +20,6 @@
 import org.onosproject.yangutils.parser.Parsable;
 import org.onosproject.yangutils.utils.YangConstructType;
 
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
 
 /*
@@ -78,18 +77,6 @@
     private T dataTypeExtendedInfo;
 
     /**
-     * Effective built-in type, requried in case type of typedef is again a
-     * derived type. This information is to be added during linking.
-     */
-    private YangDataTypes effectiveBuiltInType;
-
-    /**
-     * Effective pattern restriction, requried in case type of typedef is again
-     * a derived type. This information is to be added during linking.
-     */
-    private YangPatternRestriction effectivePatternRestriction;
-
-    /**
      * Status of resolution. If completely resolved enum value is "RESOLVED",
      * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
      * is added to uses/type but it's not resolved value of enum should be
@@ -215,42 +202,6 @@
     }
 
     /**
-     * Return effective built-in type.
-     *
-     * @return effective built-in type
-     */
-    public YangDataTypes getEffectiveBuiltInType() {
-        return effectiveBuiltInType;
-    }
-
-    /**
-     * Sets effective built-in type.
-     *
-     * @param effectiveBuiltInType effective built-in type
-     */
-    public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) {
-        this.effectiveBuiltInType = effectiveBuiltInType;
-    }
-
-    /**
-     * Returns effective pattern restriction.
-     *
-     * @return effective pattern restriction
-     */
-    public YangPatternRestriction getEffectivePatternRestriction() {
-        return effectivePatternRestriction;
-    }
-
-    /**
-     * Sets effective pattern restriction.
-     *
-     * @param effectivePatternRestriction effective pattern restriction
-     */
-    public void setEffectivePatternRestriction(YangPatternRestriction effectivePatternRestriction) {
-        this.effectivePatternRestriction = effectivePatternRestriction;
-    }
-
-    /**
      * Returns the type of the parsed data.
      *
      * @return returns TYPE_DATA
@@ -269,7 +220,6 @@
     public void validateDataOnEntry()
             throws DataModelException {
         // TODO auto-generated method stub, to be implemented by parser
-
     }
 
     /**
@@ -281,7 +231,6 @@
     public void validateDataOnExit()
             throws DataModelException {
         // TODO auto-generated method stub, to be implemented by parser
-
     }
 
     @Override
@@ -297,17 +246,19 @@
     @Override
     public void resolve() throws DataModelException {
        /*
-       Inherit the Restriction from the referred typedef definition.
+        * Check whether the data type is derived.
         */
         if (getDataType() != DERIVED) {
-            throw new DataModelException("Resolve should only be called for derived data types");
+            throw new DataModelException("Linker Error: Resolve should only be called for derived data types.");
         }
 
-        YangDerivedInfo<?> derrivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
-        YangType<?> baseType = derrivedInfo.getReferredTypeDef().getTypeDefBaseType();
-        if (DERIVED == baseType.getDataType() && baseType.getResolvableStatus() == INTRA_FILE_RESOLVED) {
-                setResolvableStatus(INTRA_FILE_RESOLVED);
+        // Check if the derived info is present.
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
+        if (derivedInfo == null) {
+            throw new DataModelException("Linker Error: Derived information is missing.");
         }
-        //TODO:
+
+        // Initiate the resolution
+        setResolvableStatus(derivedInfo.resolve());
     }
 }
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java b/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
index 2eac613..aa2181c 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
@@ -83,11 +83,6 @@
     private String name;
 
     /**
-     * Maintain the data type information.
-     */
-    private YangType<?> dataType;
-
-    /**
      * Units of the data type.
      */
     private String units;
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
index e3cd47f..03fc737 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -16,34 +16,26 @@
 
 package org.onosproject.yangutils.parser.impl.listeners;
 
-import java.util.regex.Pattern;
-
-import org.onosproject.yangutils.datamodel.YangRangeRestriction;
-import org.onosproject.yangutils.datamodel.YangRangeInterval;
-import org.onosproject.yangutils.datamodel.YangStringRestriction;
-import org.onosproject.yangutils.datamodel.YangType;
 import org.onosproject.yangutils.datamodel.YangDataTypes;
 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.YangStringRestriction;
+import org.onosproject.yangutils.datamodel.YangType;
 import org.onosproject.yangutils.parser.Parsable;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
 import org.onosproject.yangutils.utils.YangConstructType;
-import org.onosproject.yangutils.utils.builtindatatype.DataTypeException;
-import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
 
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.utils.YangConstructType.LENGTH_DATA;
-import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
-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.INVALID_HOLDER;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
+import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
+import static org.onosproject.yangutils.utils.YangConstructType.LENGTH_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
 
 /*
  * Reference: RFC6020 and YANG ANTLR Grammar
@@ -71,11 +63,6 @@
  */
 public final class LengthRestrictionListener {
 
-    private static final String PIPE = "|";
-    private static final String LENGTH_INTERVAL = "..";
-    private static final int MAX_RANGE_BOUNDARY = 2;
-    private static final int MIN_RANGE_BOUNDARY = 1;
-
     /**
      * Creates a new length restriction listener.
      */
@@ -88,10 +75,10 @@
      * tree.
      *
      * @param listener listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processLengthRestrictionEntry(TreeWalkListener listener,
-                                                    GeneratedYangParser.LengthStatementContext ctx) {
+                                                     GeneratedYangParser.LengthStatementContext ctx) {
 
         // Check for stack to be non empty.
         checkStackIsNotEmpty(listener, MISSING_HOLDER, LENGTH_DATA, ctx.length().getText(), ENTRY);
@@ -110,18 +97,22 @@
      * Sets the length restriction to type.
      *
      * @param type Yang type for which length restriction to be set
-     * @param ctx context object of the grammar rule
+     * @param ctx  context object of the grammar rule
      */
     private static void setLengthRestriction(YangType type,
-                                            GeneratedYangParser.LengthStatementContext ctx) {
+                                             GeneratedYangParser.LengthStatementContext ctx) {
 
-        YangStringRestriction stringRestriction;
-        YangBuiltInDataTypeInfo<?> startValue;
-        YangBuiltInDataTypeInfo<?> endValue;
-        YangRangeRestriction lengthRestriction = new YangRangeRestriction<>();
+        if (type.getDataType() == DERIVED) {
+            ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
+                    .setLengthRestrictionString(ctx.length().getText());
+            ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
+                    .setLineNumber(ctx.getStart().getLine());
+            ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
+                    .setCharPosition(ctx.getStart().getCharPositionInLine());
+            return;
+        }
 
-        if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) {
-
+        if (type.getDataType() != YangDataTypes.STRING) {
             ParserException parserException = new ParserException("YANG file error : " +
                     YangConstructType.getYangConstructType(LENGTH_DATA) + " name " + ctx.length().getText() +
                     " can be used to restrict the built-in type string or types derived from string.");
@@ -130,71 +121,14 @@
             throw parserException;
         }
 
-        if (type.getDataType() == YangDataTypes.STRING) {
-            stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
-        } else {
-            stringRestriction = (YangStringRestriction) ((YangDerivedInfo<?>) type
-                    .getDataTypeExtendedInfo()).getExtendedInfo();
-        }
+        YangRangeRestriction lengthRestriction = processLengthRestriction(null, ctx.getStart().getLine(),
+                ctx.getStart().getCharPositionInLine(), false, ctx.length().getText());
+
+        YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
 
         if (stringRestriction == null) {
             stringRestriction = new YangStringRestriction();
-            if (type.getDataType() == YangDataTypes.STRING) {
-                type.setDataTypeExtendedInfo(stringRestriction);
-            } else {
-                ((YangDerivedInfo<YangStringRestriction>) type.getDataTypeExtendedInfo())
-                        .setExtendedInfo(stringRestriction);
-            }
-        }
-
-        String rangeArgument = removeQuotesAndHandleConcat(ctx.length().getText());
-        String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
-
-        for (String rangePart : rangeArguments) {
-            String startInterval;
-            String endInterval;
-            YangRangeInterval rangeInterval = new YangRangeInterval<>();
-            String[] rangeBoundary = rangePart.trim().split(Pattern.quote(LENGTH_INTERVAL));
-
-            if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
-                ParserException parserException = new ParserException("YANG file error : " +
-                        YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument +
-                        " is not valid.");
-                parserException.setLine(ctx.getStart().getLine());
-                parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
-                throw parserException;
-            }
-
-            if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
-                startInterval = rangeBoundary[0];
-                endInterval = rangeBoundary[0];
-            } else {
-                startInterval = rangeBoundary[0];
-                endInterval = rangeBoundary[1];
-            }
-
-            try {
-                startValue = getDataObjectFromString(startInterval, YangDataTypes.UINT64);
-                endValue = getDataObjectFromString(endInterval, YangDataTypes.UINT64);
-            } catch (DataTypeException e) {
-                ParserException parserException = new ParserException(e.getMessage());
-                parserException.setLine(ctx.getStart().getLine());
-                parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
-                throw parserException;
-            }
-
-            rangeInterval.setStartValue(startValue);
-            rangeInterval.setEndValue(endValue);
-
-            try {
-                lengthRestriction.addRangeRestrictionInterval(rangeInterval);
-            } catch (DataModelException e) {
-                ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
-                        UNHANDLED_PARSED_DATA, LENGTH_DATA, rangeArgument, ENTRY, e.getMessage()));
-                parserException.setLine(ctx.getStart().getLine());
-                parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
-                throw parserException;
-            }
+            type.setDataTypeExtendedInfo(stringRestriction);
         }
 
         stringRestriction.setLengthRestriction(lengthRestriction);
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java
index b06ecb5..3c1fd5a 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -16,23 +16,24 @@
 
 package org.onosproject.yangutils.parser.impl.listeners;
 
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangStringRestriction;
 import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangDerivedInfo;
+import org.onosproject.yangutils.datamodel.YangPatternRestriction;
+import org.onosproject.yangutils.datamodel.YangStringRestriction;
+import org.onosproject.yangutils.datamodel.YangType;
 import org.onosproject.yangutils.parser.Parsable;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
 import org.onosproject.yangutils.utils.YangConstructType;
 
-import static org.onosproject.yangutils.utils.YangConstructType.PATTERN_DATA;
-import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
 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;
+import static org.onosproject.yangutils.utils.YangConstructType.PATTERN_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
 
 /*
  * Reference: RFC6020 and YANG ANTLR Grammar
@@ -72,10 +73,10 @@
      * tree.
      *
      * @param listener listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processPatternRestrictionEntry(TreeWalkListener listener,
-                                        GeneratedYangParser.PatternStatementContext ctx) {
+                                                      GeneratedYangParser.PatternStatementContext ctx) {
 
         // Check for stack to be non empty.
         checkStackIsNotEmpty(listener, MISSING_HOLDER, PATTERN_DATA, ctx.string().getText(), ENTRY);
@@ -94,13 +95,11 @@
      * Sets the pattern restriction to type.
      *
      * @param type Yang type for which pattern restriction to be set
-     * @param ctx context object of the grammar rule
+     * @param ctx  context object of the grammar rule
      */
     private static void setPatternRestriction(YangType type,
                                               GeneratedYangParser.PatternStatementContext ctx) {
 
-        YangStringRestriction stringRestriction;
-
         if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) {
 
             ParserException parserException = new ParserException("YANG file error : " +
@@ -111,24 +110,28 @@
             throw parserException;
         }
 
-        if (type.getDataType() == YangDataTypes.STRING) {
-            stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
-        } else {
-            stringRestriction = (YangStringRestriction) ((YangDerivedInfo<?>) type
-                    .getDataTypeExtendedInfo()).getExtendedInfo();
-        }
+        String patternArgument = ctx.string().getText().replace("\"", EMPTY_STRING);
 
-        if (stringRestriction == null) {
-            stringRestriction = new YangStringRestriction();
-            if (type.getDataType() == YangDataTypes.STRING) {
+        if (type.getDataType() == YangDataTypes.STRING) {
+            YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
+            if (stringRestriction == null) {
+                stringRestriction = new YangStringRestriction();
                 type.setDataTypeExtendedInfo(stringRestriction);
+                stringRestriction.addPattern(patternArgument);
             } else {
-                ((YangDerivedInfo<YangStringRestriction>) type.getDataTypeExtendedInfo())
-                        .setExtendedInfo(stringRestriction);
+                stringRestriction.addPattern(patternArgument);
+            }
+        } else {
+            YangPatternRestriction patternRestriction = (YangPatternRestriction) ((YangDerivedInfo<?>) type
+                    .getDataTypeExtendedInfo()).getPatternRestriction();
+            if (patternRestriction == null) {
+                patternRestriction = new YangPatternRestriction();
+                ((YangDerivedInfo<?>) type.getDataTypeExtendedInfo()).setPatternRestriction(patternRestriction);
+                patternRestriction.addPattern(patternArgument);
+            } else {
+                ((YangDerivedInfo<?>) type.getDataTypeExtendedInfo()).setPatternRestriction(patternRestriction);
+                patternRestriction.addPattern(patternArgument);
             }
         }
-
-        String patternArgument = ctx.string().getText().replace("\"", EMPTY_STRING);
-        stringRestriction.addPattern(patternArgument);
     }
 }
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
index e4e5485..b6e0cf6 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
@@ -16,33 +16,24 @@
 
 package org.onosproject.yangutils.parser.impl.listeners;
 
-import java.util.regex.Pattern;
-
-import org.onosproject.yangutils.datamodel.YangRangeInterval;
+import org.onosproject.yangutils.datamodel.YangDerivedInfo;
 import org.onosproject.yangutils.datamodel.YangRangeRestriction;
 import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.YangDataTypes;
 import org.onosproject.yangutils.parser.Parsable;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-import org.onosproject.yangutils.utils.YangConstructType;
-import org.onosproject.yangutils.utils.builtindatatype.DataTypeException;
-import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
 
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
-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.INVALID_HOLDER;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
+import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
+import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction;
 import static org.onosproject.yangutils.utils.YangConstructType.RANGE_DATA;
-import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
+import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
 
 /*
  * Reference: RFC6020 and YANG ANTLR Grammar
@@ -68,11 +59,6 @@
  */
 public final class RangeRestrictionListener {
 
-    private static final String PIPE = "|";
-    private static final String RANGE_INTERVAL = "..";
-    private static final int MAX_RANGE_BOUNDARY = 2;
-    private static final int MIN_RANGE_BOUNDARY = 1;
-
     /**
      * Creates a new range restriction listener.
      */
@@ -85,10 +71,10 @@
      * tree.
      *
      * @param listener listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processRangeRestrictionEntry(TreeWalkListener listener,
-                                                      GeneratedYangParser.RangeStatementContext ctx) {
+                                                    GeneratedYangParser.RangeStatementContext ctx) {
 
         // Check for stack to be non empty.
         checkStackIsNotEmpty(listener, MISSING_HOLDER, RANGE_DATA, ctx.range().getText(), ENTRY);
@@ -107,73 +93,34 @@
      * Sets the range restriction to type.
      *
      * @param type YANG type for which range restriction to be added
-     * @param ctx context object of the grammar rule
+     * @param ctx  context object of the grammar rule
      */
     private static void setRangeRestriction(YangType type,
-            GeneratedYangParser.RangeStatementContext ctx) {
+                                            GeneratedYangParser.RangeStatementContext ctx) {
 
-        YangBuiltInDataTypeInfo<?> startValue;
-        YangBuiltInDataTypeInfo<?> endValue;
-        YangRangeRestriction rangeRestriction = new YangRangeRestriction();
-
-        String rangeArgument = removeQuotesAndHandleConcat(ctx.range().getText());
-        String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
-
-        for (String rangePart : rangeArguments) {
-            String startInterval;
-            String endInterval;
-            YangRangeInterval rangeInterval = new YangRangeInterval();
-            String[] rangeBoundary = rangePart.trim().split(Pattern.quote(RANGE_INTERVAL));
-
-            if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
-                ParserException parserException = new ParserException("YANG file error : " +
-                        YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument +
-                        " is not valid.");
-                parserException.setLine(ctx.getStart().getLine());
-                parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
-                throw parserException;
-            }
-
-            if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
-                startInterval = rangeBoundary[0];
-                endInterval = rangeBoundary[0];
-            } else {
-                startInterval = rangeBoundary[0];
-                endInterval = rangeBoundary[1];
-            }
-
-            try {
-                startValue = getDataObjectFromString(startInterval, type.getDataType());
-                endValue = getDataObjectFromString(endInterval, type.getDataType());
-            } catch (DataTypeException e) {
-                ParserException parserException = new ParserException(e.getMessage());
-                parserException.setLine(ctx.getStart().getLine());
-                parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
-                throw parserException;
-            }
-
-            rangeInterval.setStartValue(startValue);
-            rangeInterval.setEndValue(endValue);
-
-            try {
-                rangeRestriction.addRangeRestrictionInterval(rangeInterval);
-            } catch (DataModelException e) {
-                ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
-                        UNHANDLED_PARSED_DATA, RANGE_DATA, rangeArgument, ENTRY, e.getMessage()));
-                parserException.setLine(ctx.getStart().getLine());
-                parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
-                throw parserException;
-            }
+        if (type.getDataType() == DERIVED) {
+            ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
+                    .setRangeRestrictionString(ctx.range().getText());
+            ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
+                    .setLineNumber(ctx.getStart().getLine());
+            ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
+                    .setCharPosition(ctx.getStart().getCharPositionInLine());
+            return;
         }
 
+        if (!(isOfRangeRestrictedType(type.getDataType()))) {
+            ParserException parserException = new ParserException("YANG file error: Range restriction can't be " +
+                    "applied to a given type");
+            parserException.setLine(ctx.getStart().getLine());
+            parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+            throw parserException;
+        }
+
+        YangRangeRestriction rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(),
+                ctx.getStart().getCharPositionInLine(), false, ctx.range().getText(), type.getDataType());
+
         if (rangeRestriction != null) {
-            if (type.getDataType() == YangDataTypes.DERIVED) {
-                ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
-                        .setExtendedInfo(rangeRestriction);
-            } else {
-                type.setDataTypeExtendedInfo(rangeRestriction);
-            }
+            type.setDataTypeExtendedInfo(rangeRestriction);
         }
-
     }
 }
\ No newline at end of file
diff --git a/src/main/java/org/onosproject/yangutils/utils/RestrictionResolver.java b/src/main/java/org/onosproject/yangutils/utils/RestrictionResolver.java
new file mode 100644
index 0000000..6227126
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/RestrictionResolver.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2016-present 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.utils;
+
+import java.util.regex.Pattern;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangRangeInterval;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.builtindatatype.DataTypeException;
+import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
+
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DECIMAL64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT16;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT8;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT16;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.utils.YangConstructType.LENGTH_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.RANGE_DATA;
+import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
+
+/**
+ * Represents restriction resolver which provide common utility used by parser
+ * and during linking for restriction resolution.
+ */
+public final class RestrictionResolver {
+
+    private static final String PIPE = "|";
+    private static final String INTERVAL = "..";
+    private static final int MAX_RANGE_BOUNDARY = 2;
+    private static final int MIN_RANGE_BOUNDARY = 1;
+    private static final String MIN_KEYWORD = "min";
+    private static final String MAX_KEYWORD = "max";
+
+    /**
+     * Creates a restriction resolver.
+     */
+    private RestrictionResolver() {
+    }
+
+    /**
+     * Processes the range restriction for parser and linker.
+     *
+     * @param refRangeRestriction    range restriction of referred typedef
+     * @param lineNumber             error line number
+     * @param charPositionInLine     error character position in line
+     * @param hasReferredRestriction whether has referred restriction
+     * @param curRangeString         caller type's range string
+     * @param effectiveType          effective type, when called from linker
+     * @return YANG range restriction
+     */
+    public static YangRangeRestriction processRangeRestriction(YangRangeRestriction refRangeRestriction,
+                                                               int lineNumber, int charPositionInLine,
+                                                               boolean hasReferredRestriction,
+                                                               String curRangeString, YangDataTypes effectiveType) {
+        YangBuiltInDataTypeInfo<?> startValue;
+        YangBuiltInDataTypeInfo<?> endValue;
+        YangRangeRestriction rangeRestriction = new YangRangeRestriction();
+
+        String rangeArgument = removeQuotesAndHandleConcat(curRangeString);
+        String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
+
+        for (String rangePart : rangeArguments) {
+            String startInterval;
+            String endInterval;
+            YangRangeInterval rangeInterval = new YangRangeInterval();
+            String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
+
+            if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
+                ParserException parserException = new ParserException("YANG file error : " +
+                        YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument +
+                        " is not valid.");
+                parserException.setLine(lineNumber);
+                parserException.setCharPosition(charPositionInLine);
+                throw parserException;
+            }
+
+            if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
+                startInterval = rangeBoundary[0];
+                endInterval = rangeBoundary[0];
+            } else {
+                startInterval = rangeBoundary[0];
+                endInterval = rangeBoundary[1];
+            }
+
+            try {
+                if (hasReferredRestriction && startInterval.equals(MIN_KEYWORD)
+                        && refRangeRestriction.getMinRestrictedvalue() != null) {
+                    startValue = refRangeRestriction.getMinRestrictedvalue();
+                } else if (hasReferredRestriction && startInterval.equals(MAX_KEYWORD)
+                        && refRangeRestriction.getMaxRestrictedvalue() != null) {
+                    startValue = refRangeRestriction.getMaxRestrictedvalue();
+                } else {
+                    startValue = getDataObjectFromString(startInterval, effectiveType);
+                }
+                if (hasReferredRestriction && endInterval.equals(MIN_KEYWORD)
+                        && refRangeRestriction.getMinRestrictedvalue() != null) {
+                    endValue = refRangeRestriction.getMinRestrictedvalue();
+                } else if (hasReferredRestriction && endInterval.equals(MAX_KEYWORD)
+                        && refRangeRestriction.getMaxRestrictedvalue() != null) {
+                    endValue = refRangeRestriction.getMaxRestrictedvalue();
+                } else {
+                    endValue = getDataObjectFromString(endInterval, effectiveType);
+                }
+            } catch (DataTypeException | DataModelException e) {
+                ParserException parserException = new ParserException(e.getMessage());
+                parserException.setLine(lineNumber);
+                parserException.setCharPosition(charPositionInLine);
+                throw parserException;
+            }
+
+            rangeInterval.setStartValue(startValue);
+            rangeInterval.setEndValue(endValue);
+
+            try {
+                rangeRestriction.addRangeRestrictionInterval(rangeInterval);
+            } catch (DataModelException e) {
+                ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
+                        UNHANDLED_PARSED_DATA, RANGE_DATA, rangeArgument, ENTRY, e.getMessage()));
+                parserException.setLine(lineNumber);
+                parserException.setCharPosition(charPositionInLine);
+                throw parserException;
+            }
+        }
+        return rangeRestriction;
+    }
+
+    /**
+     * Processes the length restriction for parser and linker.
+     *
+     * @param refLengthRestriction   length restriction of referred typedef
+     * @param lineNumber             error line number
+     * @param charPositionInLine     error character position in line
+     * @param hasReferredRestriction whether has referred restriction
+     * @param curLengthString        caller type's length string
+     * @return YANG range restriction
+     */
+    public static YangRangeRestriction processLengthRestriction(YangRangeRestriction refLengthRestriction,
+                                                                int lineNumber, int charPositionInLine,
+                                                                boolean hasReferredRestriction,
+                                                                String curLengthString) {
+
+        YangBuiltInDataTypeInfo<?> startValue;
+        YangBuiltInDataTypeInfo<?> endValue;
+        YangRangeRestriction lengthRestriction = new YangRangeRestriction<>();
+
+        String rangeArgument = removeQuotesAndHandleConcat(curLengthString);
+        String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
+
+        for (String rangePart : rangeArguments) {
+            String startInterval;
+            String endInterval;
+            YangRangeInterval rangeInterval = new YangRangeInterval<>();
+            String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
+
+            if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
+                ParserException parserException = new ParserException("YANG file error : " +
+                        YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument +
+                        " is not valid.");
+                parserException.setLine(lineNumber);
+                parserException.setCharPosition(charPositionInLine);
+                throw parserException;
+            }
+
+            if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
+                startInterval = rangeBoundary[0];
+                endInterval = rangeBoundary[0];
+            } else {
+                startInterval = rangeBoundary[0];
+                endInterval = rangeBoundary[1];
+            }
+
+            try {
+                if (hasReferredRestriction && startInterval.equals(MIN_KEYWORD)
+                        && refLengthRestriction.getMinRestrictedvalue() != null) {
+                    startValue = refLengthRestriction.getMinRestrictedvalue();
+                } else if (hasReferredRestriction && startInterval.equals(MAX_KEYWORD)
+                        && refLengthRestriction.getMaxRestrictedvalue() != null) {
+                    startValue = refLengthRestriction.getMaxRestrictedvalue();
+                } else {
+                    startValue = getDataObjectFromString(startInterval, YangDataTypes.UINT64);
+                }
+                if (hasReferredRestriction && endInterval.equals(MIN_KEYWORD)
+                        && refLengthRestriction.getMinRestrictedvalue() != null) {
+                    endValue = refLengthRestriction.getMinRestrictedvalue();
+                } else if (hasReferredRestriction && endInterval.equals(MAX_KEYWORD)
+                        && refLengthRestriction.getMaxRestrictedvalue() != null) {
+                    endValue = refLengthRestriction.getMaxRestrictedvalue();
+                } else {
+                    endValue = getDataObjectFromString(endInterval, YangDataTypes.UINT64);
+                }
+            } catch (DataTypeException | DataModelException e) {
+                ParserException parserException = new ParserException(e.getMessage());
+                parserException.setLine(lineNumber);
+                parserException.setCharPosition(charPositionInLine);
+                throw parserException;
+            }
+
+            rangeInterval.setStartValue(startValue);
+            rangeInterval.setEndValue(endValue);
+
+            try {
+                lengthRestriction.addRangeRestrictionInterval(rangeInterval);
+            } catch (DataModelException e) {
+                ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
+                        UNHANDLED_PARSED_DATA, LENGTH_DATA, rangeArgument, ENTRY, e.getMessage()));
+                parserException.setLine(lineNumber);
+                parserException.setCharPosition(charPositionInLine);
+                throw parserException;
+            }
+        }
+        return lengthRestriction;
+    }
+
+    /**
+     * Returns whether the data type is of range restricted type.
+     *
+     * @param dataType data type to be checked
+     * @return true, if data type can have range restrictions, false otherwise
+     */
+    public static boolean isOfRangeRestrictedType(YangDataTypes dataType) {
+        return (dataType == INT8
+                || dataType == INT16
+                || dataType == INT32
+                || dataType == INT64
+                || dataType == UINT8
+                || dataType == UINT16
+                || dataType == UINT32
+                || dataType == UINT64
+                || dataType == DECIMAL64);
+    }
+}
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt16.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt16.java
index 1ad76b5..f9055e8 100644
--- a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt16.java
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt16.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onosproject.yangutils.utils.builtindatatype;
 
 import org.onosproject.yangutils.datamodel.YangDataTypes;
@@ -66,7 +67,8 @@
             try {
                 value = Short.parseShort(valueInString);
             } catch (Exception e) {
-                throw new DataTypeException("YANG file error : " + valueInString + " is not valid.");
+                throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+                        "int16.");
             }
         }
     }
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt32.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt32.java
index 93dcec6..2f48f33 100644
--- a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt32.java
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt32.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onosproject.yangutils.utils.builtindatatype;
 
 import org.onosproject.yangutils.datamodel.YangDataTypes;
@@ -65,7 +66,8 @@
             try {
                 value = Integer.parseInt(valueInString);
             } catch (Exception e) {
-                throw new DataTypeException("YANG file error : " + valueInString + " is not valid.");
+                throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+                        "int32.");
             }
         }
     }
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt64.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt64.java
index a046ee8..6b0b685 100644
--- a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt64.java
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt64.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onosproject.yangutils.utils.builtindatatype;
 
 import org.onosproject.yangutils.datamodel.YangDataTypes;
@@ -65,7 +66,8 @@
             try {
                 value = Long.parseLong(valueInString);
             } catch (Exception e) {
-                throw new DataTypeException("YANG file error : " + valueInString + " is not valid.");
+                throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+                        "int64.");
             }
         }
     }
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt8.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt8.java
index c902410..b2823e5 100644
--- a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt8.java
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt8.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onosproject.yangutils.utils.builtindatatype;
 
 import org.onosproject.yangutils.datamodel.YangDataTypes;
@@ -65,7 +66,8 @@
             try {
                 value = Byte.parseByte(valueInString);
             } catch (Exception e) {
-                throw new DataTypeException("YANG file error : " + valueInString + " is not valid.");
+                throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+                        "int8.");
             }
         }
     }
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint16.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint16.java
index b109103..53c3a50 100644
--- a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint16.java
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint16.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onosproject.yangutils.utils.builtindatatype;
 
 import org.onosproject.yangutils.datamodel.YangDataTypes;
@@ -65,7 +66,8 @@
             try {
                 value = Integer.parseInt(valueInString);
             } catch (Exception e) {
-                throw new DataTypeException("YANG file error : " + valueInString + " is not valid.");
+                throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+                        "uint16.");
             }
         }
 
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint32.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint32.java
index e356055..79d1c6d 100644
--- a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint32.java
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint32.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onosproject.yangutils.utils.builtindatatype;
 
 import org.onosproject.yangutils.datamodel.YangDataTypes;
@@ -58,7 +59,8 @@
             try {
                 value = Long.parseLong(valueInString);
             } catch (Exception e) {
-                throw new DataTypeException("YANG file error : " + valueInString + " is not valid.");
+                throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+                        "uint32.");
             }
         }
 
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint64.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint64.java
index 70001ae..cc16a7a 100644
--- a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint64.java
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint64.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onosproject.yangutils.utils.builtindatatype;
 
 import java.math.BigInteger;
@@ -71,7 +72,8 @@
         } else if (NON_NEGATIVE_INTEGER_PATTERN.matcher(valueInString).matches()) {
             value = new BigInteger(valueInString);
         } else {
-            throw new DataTypeException("YANG file error : " + valueInString + " is not valid.");
+            throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+                    "uint64.");
         }
 
         if (value.compareTo(MIN_VALUE) < 0) {
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint8.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint8.java
index caf0628..b9abf4c 100644
--- a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint8.java
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint8.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present 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.
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onosproject.yangutils.utils.builtindatatype;
 
 import org.onosproject.yangutils.datamodel.YangDataTypes;
@@ -65,7 +66,8 @@
             try {
                 value = Short.parseShort(valueInString);
             } catch (Exception e) {
-                throw new DataTypeException("YANG file error : " + valueInString + " is not valid.");
+                throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+                        "uint8.");
             }
         }
 
diff --git a/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java b/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
index 82e9c3a..a4cb0a5 100644
--- a/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
+++ b/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
@@ -18,23 +18,26 @@
 
 import java.io.IOException;
 import java.util.ListIterator;
-
 import org.junit.Test;
-import org.onosproject.yangutils.datamodel.ResolvableStatus;
 import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangDataTypes;
 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
 import org.onosproject.yangutils.datamodel.YangLeaf;
 import org.onosproject.yangutils.datamodel.YangList;
 import org.onosproject.yangutils.datamodel.YangModule;
 import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeType;
 import org.onosproject.yangutils.datamodel.YangTypeDef;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
 
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
+import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
+import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
 
 /**
  * Test cases for testing "type" intra file linking.
@@ -56,7 +59,7 @@
         assertThat(node instanceof YangModule, is(true));
 
         // Check whether the node type is set properly to module.
-        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+        assertThat(node.getNodeType(), is(MODULE_NODE));
 
         // Check whether the module name is set correctly.
         YangModule yangNode = (YangModule) node;
@@ -67,13 +70,23 @@
 
         assertThat(leafInfo.getName(), is("invalid-interval"));
         assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
-        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
 
         assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) node.getChild()));
 
-        assertThat(leafInfo.getDataType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
     }
 
     /**
@@ -91,7 +104,7 @@
         assertThat((node instanceof YangModule), is(true));
 
         // Check whether the node type is set properly to module.
-        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+        assertThat(node.getNodeType(), is(MODULE_NODE));
 
         // Check whether the module name is set correctly.
         YangModule yangNode = (YangModule) node;
@@ -106,13 +119,23 @@
 
         assertThat(leafInfo.getName(), is("invalid-interval"));
         assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
-        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
 
         assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) node.getChild()));
 
-        assertThat(leafInfo.getDataType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
     }
 
     /**
@@ -131,7 +154,7 @@
         assertThat((node instanceof YangModule), is(true));
 
         // Check whether the node type is set properly to module.
-        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+        assertThat(node.getNodeType(), is(MODULE_NODE));
 
         // Check whether the module name is set correctly.
         YangModule yangNode = (YangModule) node;
@@ -146,13 +169,23 @@
 
         assertThat(leafInfo.getName(), is("invalid-interval"));
         assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
-        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
 
         assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) node.getChild().getNextSibling()));
 
-        assertThat(leafInfo.getDataType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
     }
 
     /**
@@ -171,7 +204,7 @@
         assertThat((node instanceof YangModule), is(true));
 
         // Check whether the node type is set properly to module.
-        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+        assertThat(node.getNodeType(), is(MODULE_NODE));
 
         // Check whether the module name is set correctly.
         YangModule yangNode = (YangModule) node;
@@ -186,13 +219,23 @@
 
         assertThat(leafInfo.getName(), is("invalid-interval"));
         assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
-        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
 
         assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
 
-        assertThat(leafInfo.getDataType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
     }
 
     /**
@@ -209,7 +252,7 @@
         assertThat((node instanceof YangModule), is(true));
 
         // Check whether the node type is set properly to module.
-        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+        assertThat(node.getNodeType(), is(MODULE_NODE));
 
         // Check whether the module name is set correctly.
         YangModule yangNode = (YangModule) node;
@@ -224,26 +267,37 @@
 
         assertThat(leafInfo.getName(), is("invalid-interval"));
         assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
-        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
 
         assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) yangList.getChild()));
         assertThat(leafInfo.getDataType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+                is(RESOLVED));
 
         YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
 
         assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
         assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+                is(RESOLVED));
 
         YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
 
         assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) node.getChild()));
         assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+                is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
     }
 
     /**
@@ -261,7 +315,7 @@
         assertThat((node instanceof YangModule), is(true));
 
         // Check whether the node type is set properly to module.
-        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+        assertThat(node.getNodeType(), is(MODULE_NODE));
 
         // Check whether the module name is set correctly.
         YangModule yangNode = (YangModule) node;
@@ -276,26 +330,37 @@
 
         assertThat(leafInfo.getName(), is("invalid-interval"));
         assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
-        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
 
         assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) yangList.getChild()));
         assertThat(leafInfo.getDataType().getResolvableStatus(),
-                is(ResolvableStatus.INTRA_FILE_RESOLVED));
+                is(INTRA_FILE_RESOLVED));
 
         YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
 
         assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
         assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
-                is(ResolvableStatus.INTRA_FILE_RESOLVED));
+                is(INTRA_FILE_RESOLVED));
 
         YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
 
         assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) node.getChild()));
         assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
-                is(ResolvableStatus.INTRA_FILE_RESOLVED));
+                is(INTRA_FILE_RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(nullValue()));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
     }
 
     /**
@@ -312,7 +377,7 @@
         assertThat((node instanceof YangModule), is(true));
 
         // Check whether the node type is set properly to module.
-        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+        assertThat(node.getNodeType(), is(MODULE_NODE));
 
         // Check whether the module name is set correctly.
         YangModule yangNode = (YangModule) node;
@@ -327,26 +392,37 @@
 
         assertThat(leafInfo.getName(), is("invalid-interval"));
         assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
-        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
 
         assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) yangList.getChild()));
         assertThat(leafInfo.getDataType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+                is(RESOLVED));
 
         YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
 
         assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
         assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+                is(RESOLVED));
 
         YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
 
         assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) node.getChild()));
         assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+                is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
     }
 
     /**
@@ -364,7 +440,7 @@
         assertThat((node instanceof YangModule), is(true));
 
         // Check whether the node type is set properly to module.
-        assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+        assertThat(node.getNodeType(), is(MODULE_NODE));
 
         // Check whether the module name is set correctly.
         YangModule yangNode = (YangModule) node;
@@ -379,12 +455,12 @@
 
         assertThat(leafInfo.getName(), is("invalid-interval"));
         assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
-        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
 
         assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) yangList.getChild()));
         assertThat(leafInfo.getDataType().getResolvableStatus(),
-                is(ResolvableStatus.INTRA_FILE_RESOLVED));
+                is(INTRA_FILE_RESOLVED));
 
         YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
 
@@ -393,7 +469,18 @@
         assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
                 is((YangTypeDef) node.getChild()));
         assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
-                is(ResolvableStatus.RESOLVED));
+                is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(nullValue()));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
     }
 
     /**
diff --git a/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java b/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
index 352b3d0..85c3840 100644
--- a/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
+++ b/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 import java.util.ListIterator;
-
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -81,7 +80,7 @@
 
         // Check whether the information in the leaf is correct under grouping.
         assertThat(leafInfo.getName(), is("hello"));
-        assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
         assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
 
         // Check whether uses is module's child.
@@ -97,7 +96,7 @@
 
         // Check whether the information in the leaf is correct under module.
         assertThat(leafInfo.getName(), is("hello"));
-        assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
         assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
 
     }
@@ -135,7 +134,7 @@
 
         // Check whether the information in the leaf is correct under grouping.
         assertThat(leafInfo.getName(), is("treat"));
-        assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
         assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
 
         // Check whether container is the child of grouping.
@@ -150,7 +149,7 @@
 
         // Check whether the information in the leaf is correct under container which is under grouping.
         assertThat(leafInfo.getName(), is("leaf2"));
-        assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
         assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
 
         // Check whether uses is module's child.
@@ -166,7 +165,7 @@
 
         // Check whether the information in the leaf is correct under module.
         assertThat(leafInfo.getName(), is("treat"));
-        assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
         assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
 
         // Check whether container is the child of module.
@@ -181,7 +180,7 @@
 
         // Check whether the information in the leaf is correct under container which is under module.
         assertThat(leafInfo.getName(), is("leaf2"));
-        assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
         assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
     }
 
@@ -688,7 +687,7 @@
 
         // Check whether the information in the leaf is correct under grouping.
         assertThat(leafInfo.getName(), is("hello"));
-        assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
         assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
 
     }
@@ -762,7 +761,7 @@
 
         // Check whether the information in the leaf is correct under grouping.
         assertThat(leafInfo.getName(), is("hello"));
-        assertThat(leafInfo.getDataType().getDataTypeName(), is("String"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
         assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
     }
 
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
index 513c7ed..3c01335 100644
--- a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
@@ -19,20 +19,18 @@
 import java.io.IOException;
 import java.math.BigInteger;
 import java.util.ListIterator;
-
 import org.junit.Rule;
 import org.junit.Test;
-
 import org.junit.rules.ExpectedException;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
 import org.onosproject.yangutils.datamodel.YangLeaf;
 import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangDataTypes;
-import org.onosproject.yangutils.datamodel.YangStringRestriction;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
 import org.onosproject.yangutils.datamodel.YangRangeInterval;
 import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.YangStringRestriction;
 import org.onosproject.yangutils.datamodel.YangTypeDef;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
@@ -71,11 +69,11 @@
         assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
         assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
         YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo
-                                                    .getDataType().getDataTypeExtendedInfo();
+                .getDataType().getDataTypeExtendedInfo();
         YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
 
         ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
-                                                    .listIterator();
+                .listIterator();
 
         YangRangeInterval rangeInterval = lengthListIterator.next();
 
@@ -220,7 +218,7 @@
     @Test
     public void processLengthWithInvalidIntegerPattern() throws IOException, ParserException {
         thrown.expect(ParserException.class);
-        thrown.expectMessage("YANG file error : a is not valid.");
+        thrown.expectMessage("YANG file error : Input value \"a\" is not a valid uint64.");
         YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidIntegerPattern.yang");
     }
 
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListenerTest.java b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListenerTest.java
index 7935abc..76da997 100644
--- a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListenerTest.java
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListenerTest.java
@@ -18,18 +18,17 @@
 
 import java.io.IOException;
 import java.util.ListIterator;
-
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
 import org.onosproject.yangutils.datamodel.YangLeaf;
 import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangRangeRestriction;
-import org.onosproject.yangutils.datamodel.YangRangeInterval;
 import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.datamodel.YangNodeType;
-import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangRangeInterval;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
 import org.onosproject.yangutils.utils.builtindatatype.YangInt32;
@@ -70,7 +69,7 @@
                 .getDataType().getDataTypeExtendedInfo();
 
         ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
-                                                    .listIterator();
+                .listIterator();
         YangRangeInterval rangeInterval = rangeListIterator.next();
         assertThat(((YangInt32) rangeInterval.getStartValue()).getValue(), is(1));
         assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
@@ -172,7 +171,7 @@
     @Test
     public void processRangeWithInvalidIntegerPattern() throws IOException, ParserException {
         thrown.expect(ParserException.class);
-        thrown.expectMessage("YANG file error : a is not valid.");
+        thrown.expectMessage("YANG file error : Input value \"a\" is not a valid int32.");
         YangNode node = manager.getDataModel("src/test/resources/RangeWithInvalidIntegerPattern.yang");
     }
 }
diff --git a/src/test/resources/SelfFileLinkingTypedefAtMiddleLevelAfterParentHolder.yang b/src/test/resources/SelfFileLinkingTypedefAtMiddleLevelAfterParentHolder.yang
index c372bfa..812a528 100644
--- a/src/test/resources/SelfFileLinkingTypedefAtMiddleLevelAfterParentHolder.yang
+++ b/src/test/resources/SelfFileLinkingTypedefAtMiddleLevelAfterParentHolder.yang
@@ -10,7 +10,7 @@
             }
         }
         typedef hello {
-            type String;
+            type string;
         }
     }
 }
diff --git a/src/test/resources/SelfFileLinkingTypedefAtRootIsAfterContainerHavingType.yang b/src/test/resources/SelfFileLinkingTypedefAtRootIsAfterContainerHavingType.yang
index 052cb7e..10ccab6 100644
--- a/src/test/resources/SelfFileLinkingTypedefAtRootIsAfterContainerHavingType.yang
+++ b/src/test/resources/SelfFileLinkingTypedefAtRootIsAfterContainerHavingType.yang
@@ -11,6 +11,6 @@
         }
     }
     typedef hello {
-        type String;
+        type string;
     }
 }
diff --git a/src/test/resources/SelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy.yang b/src/test/resources/SelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy.yang
index 2b4a1e8..eddb649 100644
--- a/src/test/resources/SelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy.yang
+++ b/src/test/resources/SelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy.yang
@@ -3,7 +3,7 @@
     namespace http://huawei.com;
     prefix Ant;
     typedef hello {
-        type String;
+        type string;
     }
     container ospf {
         list valid {
diff --git a/src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang b/src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang
index 84236a2..b6e3b45 100644
--- a/src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang
+++ b/src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang
@@ -7,14 +7,14 @@
     }
     grouping Percentage {
         leaf hello{
-            type String;
+            type string;
         }
     }
     container ospf {
         list valid {
             key "invalid";
-	    leaf invalid{
-                type String;
+            leaf invalid{
+                type string;
             }
             uses Ant:FirstClass;
             grouping FirstClass {
diff --git a/src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang b/src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang
index 23f197b..956ba50 100644
--- a/src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang
+++ b/src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang
@@ -3,15 +3,15 @@
     namespace http://huawei.com;
     prefix Ant;
     grouping Percentage {
-	leaf hello{
-            type String;
+        leaf hello{
+            type string;
         }
     }
     container ospf {
         list valid {
             key "invalid";
-	    leaf invalid{
-                type String;
+            leaf invalid{
+                type string;
             }
             uses Ant:FirstClass;
             grouping FirstClass {
diff --git a/src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang b/src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang
index b6b08a7..da6795b 100644
--- a/src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang
+++ b/src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang
@@ -6,6 +6,6 @@
         type hello;
     }
     typedef hello {
-        type String;
+        type string;
     }
 }
diff --git a/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang b/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang
index 52641d8..f6e9197 100644
--- a/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang
+++ b/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang
@@ -4,8 +4,8 @@
     prefix Ant;
     uses hello;
     grouping hello {
-	leaf hello{
-            type String;
+        leaf hello{
+            type string;
         }
     }
 }
diff --git a/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang b/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang
index f4f12b0..13cc4a5 100644
--- a/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang
+++ b/src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang
@@ -4,12 +4,12 @@
     prefix Ant;
     uses treat;
     grouping treat {
-	leaf treat{
-            type String;
+        leaf treat{
+            type string;
         }
         container test{
             leaf leaf2{
-                type String;
+                type string;
             }
         }
     }