[ONOS-4753] Identity/identityref implementation and UT

Change-Id: I40148fa228465555be3bdf410cc294ffc0f34c18
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseListener.java
new file mode 100644
index 0000000..1925375
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseListener.java
@@ -0,0 +1,116 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangBase;
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BASE_DATA;
+
+/**
+ * base-stmt           = base-keyword sep identifier-ref-arg-str
+ *                          optsep stmtend*
+ * identifier-ref-arg  = [prefix ":"] identifier
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "base"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class BaseListener {
+
+    //Creates a new base listener.
+    private BaseListener() {
+    }
+
+    /**
+     * Performs validation and updates the data model tree when parser receives an
+     * input matching the grammar rule (base).
+     *
+     * @param listener listener's object
+     * @param ctx context object of the grammar rule
+     */
+    public static void processBaseEntry(TreeWalkListener listener,
+                                          GeneratedYangParser.BaseStatementContext ctx) {
+
+        // Check for stack to be non empty.
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, BASE_DATA, ctx.string().getText(), ENTRY);
+
+        YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), BASE_DATA, ctx);
+
+        Parsable tmpData = listener.getParsedDataStack().peek();
+
+        /**
+         * For identityref base node identifier is copied in identity listener itself, so no need to process
+         * base statement for indentityref
+         */
+        if (tmpData instanceof YangIdentityRef) {
+            return;
+        }
+
+        if (!(tmpData instanceof YangIdentity)) {
+             throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BASE_DATA,
+                                                                     ctx.string().getText(), ENTRY));
+        }
+
+        YangBase yangBase = new YangBase();
+        yangBase.setBaseIdentifier(nodeIdentifier);
+        ((YangIdentity) tmpData).setBaseNode(yangBase);
+
+        int errorLine = ctx.getStart().getLine();
+        int errorPosition = ctx.getStart().getCharPositionInLine();
+
+        // Add resolution information to the list
+        YangResolutionInfoImpl resolutionInfo =
+                new YangResolutionInfoImpl<YangBase>(yangBase, (YangNode) tmpData, errorLine, errorPosition);
+        addToResolutionList(resolutionInfo, ctx);
+    }
+
+    /**
+     * Add to resolution list.
+     *
+     * @param resolutionInfo resolution information
+     * @param ctx context object of the grammar rule
+     */
+    private static void addToResolutionList(YangResolutionInfoImpl<YangBase> resolutionInfo,
+                                            GeneratedYangParser.BaseStatementContext ctx) {
+
+        try {
+            addResolutionInfo(resolutionInfo);
+        } catch (DataModelException e) {
+            throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+                    BASE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
+        }
+    }
+
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListener.java
new file mode 100644
index 0000000..d8dec2c
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListener.java
@@ -0,0 +1,123 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
+import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangIdentityNode;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITY_DATA;
+
+/**
+ * Reference: RFC6020 and YANG ANTLR Grammar.
+ *
+ * ABNF grammar as per RFC6020
+ * identity-stmt       = identity-keyword sep identifier-arg-str optsep
+ *                       (";" /
+ *                        "{" stmtsep
+ *                            ;; these stmts can appear in any order
+ *                            [base-stmt stmtsep]
+ *                            [status-stmt stmtsep]
+ *                            [description-stmt stmtsep]
+ *                            [reference-stmt stmtsep]
+ *                        "}")
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "identity"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class IdentityListener {
+
+    //Creates a identity listener.
+    private IdentityListener() {
+    }
+
+    /**
+     * Performs validations and update the data model tree when parser receives an input
+     * matching the grammar rule (identity).
+     *
+     * @param listener Listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processIdentityEntry(TreeWalkListener listener,
+                                            GeneratedYangParser.IdentityStatementContext ctx) {
+
+        // Check for stack to be non empty.
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), ENTRY);
+
+        String identifier = getValidIdentifier(ctx.identifier().getText(), IDENTITY_DATA, ctx);
+
+        YangIdentity identity = getYangIdentityNode(JAVA_GENERATION);
+        identity.setName(identifier);
+
+        Parsable curData = listener.getParsedDataStack().peek();
+        if (curData instanceof YangModule || curData instanceof YangSubModule) {
+            YangNode curNode = (YangNode) curData;
+            try {
+                curNode.addChild(identity);
+            } catch (DataModelException e) {
+                throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+                        IDENTITY_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
+            }
+            // Push identity node to the stack.
+            listener.getParsedDataStack().push(identity);
+        } else {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
+                    ctx.identifier().getText(), ENTRY));
+        }
+
+    }
+
+    /**
+     * Performs validations and update the data model tree when parser exits from grammar
+     * rule (identity).
+     *
+     * @param listener Listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processIdentityExit(TreeWalkListener listener,
+                                       GeneratedYangParser.IdentityStatementContext ctx) {
+
+        // Check for stack to be non empty.
+        checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), EXIT);
+
+        Parsable parsableType = listener.getParsedDataStack().pop();
+        if (!(parsableType instanceof YangIdentity)) {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
+                    ctx.identifier().getText(), EXIT));
+        }
+    }
+
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java
new file mode 100644
index 0000000..49037e2
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java
@@ -0,0 +1,214 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
+import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BASE_DATA;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITYREF_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/**
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * identityref-specification =
+ *                        base-stmt stmtsep
+ * base-stmt           = base-keyword sep identifier-ref-arg-str
+ *                          optsep stmtend*
+ * identifier-ref-arg  = [prefix ":"] identifier
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "identityref"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class IdentityrefListener {
+
+    //Creates a new type listener.
+    private IdentityrefListener() {
+    }
+
+    /**
+     * Performs validation and updates the data model tree when parser receives an input
+     * matching the grammar rule (identityref).
+     *
+     * @param listener listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processIdentityrefEntry(TreeWalkListener listener,
+                                        GeneratedYangParser.IdentityrefSpecificationContext ctx) {
+
+        // Check for stack to be non empty.
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITYREF_DATA, "", ENTRY);
+
+        if (listener.getParsedDataStack().peek() instanceof YangType) {
+
+            YangIdentityRef identityRef = new YangIdentityRef();
+            Parsable typeData = listener.getParsedDataStack().pop();
+            YangDataTypes yangDataTypes = ((YangType) typeData).getDataType();
+            YangResolutionInfoImpl resolutionInfo;
+
+            // Validate node identifier.
+            YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.baseStatement().string().getText(),
+                                                                       BASE_DATA, ctx);
+            identityRef.setBaseIdentity(nodeIdentifier);
+            ((YangType) typeData).setDataTypeExtendedInfo(identityRef);
+
+            int errorLine = ctx.getStart().getLine();
+            int errorPosition = ctx.getStart().getCharPositionInLine();
+
+            Parsable tmpData = listener.getParsedDataStack().peek();
+            switch (tmpData.getYangConstructType()) {
+                case LEAF_DATA:
+
+                    // Pop the stack entry to obtain the parent YANG node.
+                    Parsable leaf = listener.getParsedDataStack().pop();
+                    Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
+
+                    // Push the popped entry back to the stack.
+                    listener.getParsedDataStack().push(leaf);
+
+                    // Verify parent node of leaf
+                    if (!(parentNodeOfLeaf instanceof YangNode)) {
+                        throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+                                                                                IDENTITYREF_DATA, ctx.getText(), EXIT));
+                    }
+
+                    identityRef.setResolvableStatus(UNRESOLVED);
+
+                    // Add resolution information to the list
+                    resolutionInfo =  new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
+                                                  (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
+                    addToResolutionList(resolutionInfo, ctx);
+
+                    break;
+                case LEAF_LIST_DATA:
+
+                    // Pop the stack entry to obtain the parent YANG node.
+                    Parsable leafList = listener.getParsedDataStack().pop();
+                    Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
+
+                    // Push the popped entry back to the stack.
+                    listener.getParsedDataStack().push(leafList);
+
+                    // Verify parent node of leaf
+                    if (!(parentNodeOfLeafList instanceof YangNode)) {
+                        throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+                                                                                IDENTITYREF_DATA, ctx.getText(), EXIT));
+                    }
+
+                    identityRef.setResolvableStatus(UNRESOLVED);
+
+                    // Add resolution information to the list
+                    resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
+                                               (YangNode) parentNodeOfLeafList, errorLine, errorPosition);
+                    addToResolutionList(resolutionInfo, ctx);
+                    break;
+                case UNION_DATA:
+
+                    Parsable parentNodeOfUnionNode = listener.getParsedDataStack().peek();
+
+                    // Verify parent node of leaf
+                    if (!(parentNodeOfUnionNode instanceof YangNode)) {
+                        throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
+                                                                                IDENTITYREF_DATA, ctx.getText(), EXIT));
+                    }
+
+                    identityRef.setResolvableStatus(UNRESOLVED);
+
+                    // Add resolution information to the list
+                    resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
+                                              (YangNode) parentNodeOfUnionNode, errorLine, errorPosition);
+                    addToResolutionList(resolutionInfo, ctx);
+
+                    break;
+                case TYPEDEF_DATA:
+                    /**
+                     * Do not add the identity ref to resolution list. It needs to be
+                     * added to resolution list, when leaf/leaf list references to
+                     * this typedef. At this time that leaf/leaf-list becomes the
+                     * parent for the identityref.
+                     */
+                    break;
+                default:
+                    throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
+                                                                            ctx.getText(), EXIT));
+            }
+            listener.getParsedDataStack().push(typeData);
+            listener.getParsedDataStack().push(identityRef);
+         } else {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA, "", ENTRY));
+        }
+    }
+
+    /**
+     * Performs validations and update the data model tree when parser exits from grammar
+     * rule (identityref).
+     *
+     * @param listener Listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processIdentityrefExit(TreeWalkListener listener,
+                                       GeneratedYangParser.IdentityrefSpecificationContext ctx) {
+
+        // Check for stack to be non empty.
+        checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITYREF_DATA, ctx.getText(), EXIT);
+
+        Parsable parsableType = listener.getParsedDataStack().pop();
+        if (!(parsableType instanceof YangIdentityRef)) {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
+                                                                    ctx.getText(), EXIT));
+        }
+    }
+
+    /**
+     * Adds to resolution list.
+     *
+     * @param resolutionInfo resolution information
+     * @param ctx            context object of the grammar rule
+     */
+    private static void addToResolutionList(YangResolutionInfoImpl<YangIdentityRef> resolutionInfo,
+                                            GeneratedYangParser.IdentityrefSpecificationContext ctx) {
+        try {
+            addResolutionInfo(resolutionInfo);
+        } catch (DataModelException e) {
+            throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+                                               IDENTITYREF_DATA, ctx.getText(), ENTRY, e.getMessage()));
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index ebf9d97..5b50ff9 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -130,6 +130,10 @@
                     .peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
             ((YangReferenceResolver) listener.getParsedDataStack()
                     .peek()).resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
+            ((YangReferenceResolver) listener.getParsedDataStack()
+                    .peek()).resolveSelfFileLinking(ResolvableType.YANG_BASE);
+            ((YangReferenceResolver) listener.getParsedDataStack()
+                    .peek()).resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
         } catch (DataModelException e) {
             LinkerException linkerException = new LinkerException(e.getMessage());
             linkerException.setLine(e.getLineNumber());
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
index 2132324..d2c4f48 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
@@ -135,6 +135,10 @@
                     .resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
             ((YangReferenceResolver) listener.getParsedDataStack().peek())
                     .resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
+            ((YangReferenceResolver) listener.getParsedDataStack().peek())
+                    .resolveSelfFileLinking(ResolvableType.YANG_BASE);
+            ((YangReferenceResolver) listener.getParsedDataStack().peek())
+                    .resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
         } catch (DataModelException e) {
             LinkerException linkerException = new LinkerException(e.getMessage());
             linkerException.setLine(e.getLineNumber());
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
index 32955d5..e108d14 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
@@ -310,7 +310,11 @@
                     parserException = new ParserException("YANG file error : a type leafref" +
                             " must have one path statement.");
                     break;
-                // TODO : decimal64, identity ref
+                case IDENTITYREF:
+                    parserException = new ParserException("YANG file error : a type identityref" +
+                                                                  " must have base statement.");
+                    break;
+                // TODO : decimal64,
                 default:
                     return;
             }