[ONOS-4753] Identity/identityref implementation and UT
Change-Id: I40148fa228465555be3bdf410cc294ffc0f34c18
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index 443c071..a1daf0f 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -28,6 +28,7 @@
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.impl.listeners.AugmentListener;
import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener;
+import org.onosproject.yangutils.parser.impl.listeners.BaseListener;
import org.onosproject.yangutils.parser.impl.listeners.BelongsToListener;
import org.onosproject.yangutils.parser.impl.listeners.BitListener;
import org.onosproject.yangutils.parser.impl.listeners.BitsListener;
@@ -42,7 +43,9 @@
import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
+import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener;
import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
+import org.onosproject.yangutils.parser.impl.listeners.IdentityListener;
import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
import org.onosproject.yangutils.parser.impl.listeners.InputListener;
@@ -450,12 +453,12 @@
@Override
public void enterIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
- handleUnsupportedYangConstruct(YangConstructType.IDENTITY_DATA, ctx, CURRENTLY_UNSUPPORTED);
+ IdentityListener.processIdentityEntry(this, ctx);
}
@Override
public void exitIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
- // do nothing.
+ IdentityListener.processIdentityExit(this, ctx);
}
@Override
@@ -470,7 +473,7 @@
@Override
public void enterBaseStatement(GeneratedYangParser.BaseStatementContext ctx) {
- handleUnsupportedYangConstruct(YangConstructType.BASE_DATA, ctx, CURRENTLY_UNSUPPORTED);
+ BaseListener.processBaseEntry(this, ctx);
}
@Override
@@ -710,12 +713,12 @@
@Override
public void enterIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
- // do nothing.
+ IdentityrefListener.processIdentityrefEntry(this, ctx);
}
@Override
public void exitIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
- // do nothing.
+ IdentityrefListener.processIdentityrefExit(this, ctx);
}
@Override
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;
}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index 2aaa563..48ac0de 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -48,10 +48,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENT;
-import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
-import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_SQUARE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
@@ -341,7 +339,6 @@
String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx));
return nodeIdentifier;
} else if (tmpData.length == 2) {
@@ -375,7 +372,6 @@
String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
nodeIdentifier.setName(getValidIdentifierForLeafref(tmpData[0], yangConstruct, ctx, yangLeafRef));
return nodeIdentifier;
} else if (tmpData.length == 2) {
@@ -706,24 +702,6 @@
}
/**
- * Checks whether the type is an unsupported type.
- *
- * @param typeName name of the type
- * @param yangConstruct yang construct to check if it is type
- * @param ctx yang construct's context to get the line number and character position
- */
- private static void checkForUnsupportedTypes(String typeName,
- YangConstructType yangConstruct, ParserRuleContext ctx) {
-
- if (yangConstruct == YangConstructType.TYPE_DATA) {
- if (typeName.equalsIgnoreCase(IDENTITYREF)) {
- handleUnsupportedYangConstruct(YangConstructType.IDENTITYREF_DATA,
- ctx, CURRENTLY_UNSUPPORTED);
- }
- }
- }
-
- /**
* Checks and return valid absolute schema node id.
*
* @param argumentString string from yang file