Vidyashree Rama
Committed by Gerrit Code Review

[ONOS-4941][ONOS-4883][ONOS-4979]Grouping and uses interfile linking issue + defect fix

Change-Id: I5e8145f05d3ef570d4ecbbe885c93de172de0ea3
Showing 37 changed files with 1472 additions and 169 deletions
/*
* 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;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG app-data-structure.
*/
public class YangAppDataStructure implements Parsable {
/**
* Data structure information.
*/
private YangDataStructure dataStructure;
/**
* List of key names.
*/
private List<String> keyList;
/**
* Prefix of app-data-structure.
*/
private String prefix;
/**
* Returns the YANG data structure information.
*
* @return the YANG data structure information
*/
public YangDataStructure getDataStructure() {
return dataStructure;
}
/**
* Sets the YANG data structure information.
*
* @param dataStructure the YANG data structure to set
*/
public void setDataStructure(YangDataStructure dataStructure) {
this.dataStructure = dataStructure;
}
/**
* Returns the list of key field names.
*
* @return the list of key field names
*/
public List<String> getKeyList() {
return keyList;
}
/**
* Sets the list of key field names.
*
* @param keyList the list of key field names
*/
public void setKeyList(List<String> keyList) {
this.keyList = keyList;
}
/**
* Adds a key field name.
*
* @param key key field name
*/
public void addKey(String key) {
if (getKeyList() == null) {
setKeyList(new LinkedList<>());
}
getKeyList().add(key);
}
/**
* Returns the prefix.
*
* @return the prefix
*/
public String getPrefix() {
return prefix;
}
/**
* Sets the prefix information.
*
* @param prefix the prefix to set
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.APP_DATA_STRUCTURE;
}
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO : to be implemented
}
@Override
public void validateDataOnExit() throws DataModelException {
// TODO : to be implemented
}
}
/*
* 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;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG extended name.
*/
public class YangAppExtendedName implements Parsable {
/**
* App extended name information.
*/
private String yangAppExtendedName;
/**
* Prefix of extended name.
*/
private String prefix;
/**
* Returns the YANG app extended name information.
*
* @return the YANG app extended name information
*/
public String getYangAppExtendedName() {
return yangAppExtendedName;
}
/**
* Sets the YANG app extended name information.
*
* @param yangAppExtendedName the YANG app extended name to set
*/
public void setYangAppExtendedName(String yangAppExtendedName) {
this.yangAppExtendedName = yangAppExtendedName;
}
/**
* Returns the prefix.
*
* @return the prefix
*/
public String getPrefix() {
return prefix;
}
/**
* Sets the prefix information.
*
* @param prefix the prefix to set
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.APP_EXTENDED_NAME_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO : to be implemented
}
@Override
public void validateDataOnExit() throws DataModelException {
// TODO : to be implemented
}
}
/*
* 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;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG compiler-annotation.
*/
public class YangCompilerAnnotation implements Parsable {
/**
* App data structure information.
*/
private YangAppDataStructure yangAppDataStructure;
/**
* App extended name information.
*/
private YangAppExtendedName yangAppExtendedName;
/**
* Prefix of compiler-annotation.
*/
private String prefix;
/**
* Path of compiler-annotation.
*/
private String path;
/**
* Returns the YANG app data structure information.
*
* @return the YANG app data structure information
*/
public YangAppDataStructure getYangAppDataStructure() {
return yangAppDataStructure;
}
/**
* Sets the YANG app data structure information.
*
* @param yangAppDataStructure the YANG app data structure to set
*/
public void setYangAppDataStructure(YangAppDataStructure yangAppDataStructure) {
this.yangAppDataStructure = yangAppDataStructure;
}
/**
* Returns the prefix.
*
* @return the prefix
*/
public String getPrefix() {
return prefix;
}
/**
* Sets the prefix information.
*
* @param prefix the prefix to set
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
/**
* Returns the path.
*
* @return the path
*/
public String getPath() {
return path;
}
/**
* Sets the path.
*
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* Returns the YANG app extended name information.
*
* @return the YANG app extended name information
*/
public YangAppExtendedName getYangAppExtendedName() {
return yangAppExtendedName;
}
/**
* Sets the YANG app extended name information.
*
* @param yangAppExtendedName the YANG app extended name to set
*/
public void setYangAppExtendedName(YangAppExtendedName yangAppExtendedName) {
this.yangAppExtendedName = yangAppExtendedName;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.COMPILER_ANNOTATION_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO : to be implemented
}
@Override
public void validateDataOnExit() throws DataModelException {
// TODO : to be implemented
}
}
/*
* 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;
/**
* Represents ENUM to identify the YANG data type.
*/
public enum YangDataStructure {
MAP,
LIST,
SET;
/**
* Returns YANG data structure type for corresponding data structure name.
*
* @param name data structure name from YANG file.
* @return YANG data structure for corresponding data structure name.
*/
public static YangDataStructure getType(String name) {
name = name.replace("\"", "");
for (YangDataStructure dataStructure : values()) {
if (dataStructure.name().toLowerCase().equals(name)) {
return dataStructure;
}
}
return null;
}
}
......@@ -16,15 +16,14 @@
package org.onosproject.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
/*
......@@ -72,7 +71,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
public class YangList
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangMustHolder, YangIfFeatureHolder, YangDataNode {
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangDataNode {
private static final long serialVersionUID = 806201609L;
......@@ -219,6 +218,7 @@ public class YangList
*
* @return the when
*/
@Override
public YangWhen getWhen() {
return when;
}
......@@ -228,6 +228,7 @@ public class YangList
*
* @param when the when to set
*/
@Override
public void setWhen(YangWhen when) {
this.when = when;
}
......@@ -624,7 +625,6 @@ public class YangList
* Validates key statement of list.
*
* @param leaves list of leaf attributes of list
* @param leafLists list of leaf-list attributes of list
* @param keys list of key attributes of list
* @throws DataModelException a violation of data model rules
*/
......
......@@ -231,7 +231,12 @@ public class YangModule
private List<YangResolutionInfo> augmentResolutionList;
/**
* extension list.
* Compiler annotation list.
*/
private List<YangCompilerAnnotation> compilerAnnotationList;
/**
* Extension list.
*/
private List<YangExtension> extensionList;
......@@ -248,6 +253,7 @@ public class YangModule
leafrefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
compilerAnnotationList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -563,6 +569,33 @@ public class YangModule
}
/**
* Adds compiler annotation in compiler-annotation list.
*
* @param compilerAnnotation the compiler-annotation to be added
*/
public void addCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
getCompilerAnnotationList().add(compilerAnnotation);
}
/**
* Returns the compiler annotation list.
*
* @return the compiler annotation list
*/
public List<YangCompilerAnnotation> getCompilerAnnotationList() {
return compilerAnnotationList;
}
/**
* Sets the compiler-annotation list.
*
* @param compilerAnnotationList the list of compiler-annotation
*/
public void setCompilerAnnotationList(List<YangCompilerAnnotation> compilerAnnotationList) {
this.compilerAnnotationList = compilerAnnotationList;
}
/**
* Adds extension in extension list.
*
* @param extension the extension to be added
......
......@@ -224,6 +224,11 @@ public class YangSubModule
private List<YangResolutionInfo> identityrefResolutionList;
/**
* Compiler annotation list.
*/
private List<YangCompilerAnnotation> compilerAnnotationList;
/**
* extension list.
*/
private List<YangExtension> extensionList;
......@@ -245,6 +250,7 @@ public class YangSubModule
leafrefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
compilerAnnotationList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
......@@ -692,6 +698,34 @@ public class YangSubModule
}
/**
* Adds compiler annotation in compiler annotation list.
*
* @param compilerAnnotation the compiler annotation to be added
*/
public void addCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
getCompilerAnnotationList().add(compilerAnnotation);
}
/**
* Returns the compiler annotation list.
*
* @return the compiler annotation list
*/
public List<YangCompilerAnnotation> getCompilerAnnotationList() {
return compilerAnnotationList;
}
/**
* Sets the compiler annotation list.
*
* @param compilerAnnotationList the list of compiler annotation
*/
public void setCompilerAnnotationList(List<YangCompilerAnnotation> compilerAnnotationList) {
this.compilerAnnotationList = compilerAnnotationList;
}
/**
* Adds extension in extension list.
*
* @param extension the extension to be added
......
......@@ -17,17 +17,20 @@ package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeaf;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeafList;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
/*-
* Reference RFC 6020.
......@@ -365,6 +368,14 @@ public class YangUses
if (referredGrouping == null) {
throw new DataModelException("YANG uses linker error, cannot resolve uses");
} else {
/*
* if referredGrouping has uses which is not resolved then set the status
* as Intra file resolved and return
*/
if (checkIsUnresolvedRecursiveUsesInGrouping(referredGrouping)) {
return null;
}
}
YangNode usesParentNode = getParentNodeInGenCode(this);
......@@ -405,7 +416,7 @@ public class YangUses
clonedLeafList = leafList.clone();
if (getCurrentGroupingDepth() == 0) {
YangEntityToResolveInfoImpl resolveInfo =
resolveLeafrefUnderGroupingForLeafList(clonedLeafList, usesParentLeavesHolder);
resolveLeafrefUnderGroupingForLeafList(clonedLeafList, usesParentLeavesHolder);
if (resolveInfo != null) {
addEntityToResolve(resolveInfo);
}
......@@ -429,6 +440,49 @@ public class YangUses
}
/**
* Checks if referred grouping has uses which is not resolved then it set the
* status of current uses as intra file resolved and returns true.
*
* @param referredGrouping referred grouping node of uses
* @return true if referred grouping has unresolved uses
*/
private boolean checkIsUnresolvedRecursiveUsesInGrouping(YangGrouping referredGrouping) {
/**
* Search the grouping node's children for presence of uses node.
*/
TraversalType curTraversal = ROOT;
YangNode curNode = referredGrouping.getChild();
while (curNode != null) {
if (curNode.getName().equals(referredGrouping.getName())) {
// if we have traversed all the child nodes, then exit from loop
return false;
}
// if child nodes has uses, then add it to resolution stack
if (curNode instanceof YangUses) {
if (((YangUses) curNode).getResolvableStatus() != ResolvableStatus.RESOLVED) {
setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
return true;
}
}
// Traversing all the child nodes of grouping
if (curTraversal != PARENT && curNode.getChild() != null) {
curTraversal = CHILD;
curNode = curNode.getChild();
} else if (curNode.getNextSibling() != null) {
curTraversal = SIBILING;
curNode = curNode.getNextSibling();
} else {
curTraversal = PARENT;
curNode = curNode.getParent();
}
}
return false;
}
/**
* Clone the resolved uses contained in grouping to the uses of grouping.
*
* @param usesInGrouping resolved uses in grouping
......
......@@ -385,6 +385,21 @@ public enum YangConstructType {
ANYXML_DATA,
/**
* Identifies the YANG compiler annotation element parsed data.
*/
COMPILER_ANNOTATION_DATA,
/**
* Identifies the YANG app data structure element parsed data.
*/
APP_DATA_STRUCTURE,
/**
* Identifies the YANG app extended element parsed data.
*/
APP_EXTENDED_NAME_DATA,
/**
* Identifies the YANG argument element parsed data.
*/
ARGUMENT_DATA;
......@@ -544,6 +559,12 @@ public enum YangConstructType {
return "deviation";
case ANYXML_DATA:
return "anyxml";
case COMPILER_ANNOTATION_DATA:
return "compiler-annotation";
case APP_DATA_STRUCTURE:
return "app-data-structure";
case APP_EXTENDED_NAME_DATA:
return "app-extended-name";
case ARGUMENT_DATA:
return "argument";
default:
......
......@@ -172,7 +172,7 @@ public class YangLinkerManager
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_AUGMENT);
.resolveInterFileLinking(ResolvableType.YANG_AUGMENT);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) yangNode)
......
......@@ -1594,11 +1594,7 @@ public class YangResolutionInfoImpl<T>
if (linkedNode != null) {
// Add the link to external entity.
addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
/*
* Update the current reference resolver to external
* module/sub-module containing the referred typedef/grouping.
*/
setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode());
// Add the type/uses of referred typedef/grouping to the stack.
addUnresolvedRecursiveReferenceToStack(linkedNode);
return true;
......@@ -1641,12 +1637,7 @@ public class YangResolutionInfoImpl<T>
if (linkedNode != null) {
// Add the link to external entity.
addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
/*
* Update the current reference resolver to external
* module/sub-module containing the referred
* typedef/grouping.
*/
setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode());
// Add the type/uses of referred typedef/grouping to the
// stack.
addUnresolvedRecursiveReferenceToStack(linkedNode);
......
......@@ -1835,136 +1835,94 @@ public interface GeneratedYangListener extends ParseTreeListener {
void exitCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule annotation statement.
* Enters a parse tree produced by GeneratedYangParser for grammar rule compiler annotation body statement.
*
* @param currentContext current context in the parsed tree
*/
void enterAnnotationStatement(GeneratedYangParser.AnnotationStatementContext currentContext);
void enterCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext
currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar rule annotation statement.
* Exits a parse tree produced by GeneratedYangParser for grammar rule compiler annotation body statement.
*
* @param currentContext current context in the parsed tree
*/
void exitAnnotationStatement(GeneratedYangParser.AnnotationStatementContext currentContext);
void exitCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext
currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule annotation type.
* Enters a parse tree produced by GeneratedYangParser for grammar rule app data structure statement.
*
* @param currentContext current context in the parsed tree
*/
void enterAnnotationType(GeneratedYangParser.AnnotationTypeContext currentContext);
void enterAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext
currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar rule annotation type.
* Exits a parse tree produced by GeneratedYangParser for grammar rule app data structure statement.
*
* @param currentContext current context in the parsed tree
*/
void exitAnnotationType(GeneratedYangParser.AnnotationTypeContext currentContext);
void exitAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule
* annotation parameter specification.
* Enters a parse tree produced by GeneratedYangParser for grammar rule app data structure.
*
* @param currentContext current context in the parsed tree
*/
void enterAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext
currentContext);
void enterAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar rule
* annotation parameter specification.
* Exits a parse tree produced by GeneratedYangParser for grammar rule app data strcuture.
*
* @param currentContext current context in the parsed tree
*/
void exitAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext
currentContext);
void exitAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule
* annotation parameter specification argument.
* Enters a parse tree produced by GeneratedYangParser for grammar rule app extended statement.
*
* @param currentContext current context in the parsed tree
*/
void enterAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
currentContext);
void enterAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar rule
* annotation parameter specification argument.
* Exits a parse tree produced by GeneratedYangParser for grammar rule app extended statement.
*
* @param currentContext current context in the parsed tree
*/
void exitAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
currentContext);
void exitAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule annotation parameter instance.
* Enters a parse tree produced by GeneratedYangParser for grammar rule extended name.
*
* @param currentContext current context in the parsed tree
*/
void enterAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext
currentContext);
void enterExtendedName(GeneratedYangParser.ExtendedNameContext currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar rule annotation parameter instance.
* Exits a parse tree produced by GeneratedYangParser for grammar rule extended name.
*
* @param currentContext current context in the parsed tree
*/
void exitAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext
currentContext);
void exitExtendedName(GeneratedYangParser.ExtendedNameContext currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule
* annotation parameter type identifier.
*
* @param currentContext current context in the parsed tree
*/
void enterAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext
currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar rule
* annotation parameter type identifier.
*
* @param currentContext current context in the parsed tree
*/
void exitAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext
currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule
* annotation parameter type value.
* data structure key statement.
*
* @param currentContext current context in the parsed tree
*/
void enterAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext
currentContext);
void enterDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar rule
* annotation parameter type value.
*
* @param currentContext current context in the parsed tree
*/
void exitAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext
currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule annotation identifier.
*
* @param currentContext current context in the parsed tree
*/
void enterAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext
currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar rule annotation identifier.
* data structure key statement.
*
* @param currentContext current context in the parsed tree
*/
void exitAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext
currentContext);
void exitDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule require instance.
......
......@@ -24,6 +24,8 @@ import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.impl.listeners.AppDataStructureListener;
import org.onosproject.yangutils.parser.impl.listeners.AppExtendedNameListener;
import org.onosproject.yangutils.parser.impl.listeners.ArgumentListener;
import org.onosproject.yangutils.parser.impl.listeners.AugmentListener;
import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener;
......@@ -33,9 +35,11 @@ import org.onosproject.yangutils.parser.impl.listeners.BitListener;
import org.onosproject.yangutils.parser.impl.listeners.BitsListener;
import org.onosproject.yangutils.parser.impl.listeners.CaseListener;
import org.onosproject.yangutils.parser.impl.listeners.ChoiceListener;
import org.onosproject.yangutils.parser.impl.listeners.CompilerAnnotationListener;
import org.onosproject.yangutils.parser.impl.listeners.ConfigListener;
import org.onosproject.yangutils.parser.impl.listeners.ContactListener;
import org.onosproject.yangutils.parser.impl.listeners.ContainerListener;
import org.onosproject.yangutils.parser.impl.listeners.DataStructureKeyListener;
import org.onosproject.yangutils.parser.impl.listeners.Decimal64Listener;
import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
......@@ -1428,95 +1432,72 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
// TODO: implement the method.
CompilerAnnotationListener.processCompilerAnnotationEntry(this, ctx);
}
@Override
public void exitCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
// TODO: implement the method.
}
@Override
public void enterAnnotationStatement(GeneratedYangParser.AnnotationStatementContext ctx) {
// TODO: implement the method.
}
@Override
public void exitAnnotationStatement(GeneratedYangParser.AnnotationStatementContext ctx) {
// TODO: implement the method.
CompilerAnnotationListener.processCompilerAnnotationExit(this, ctx);
}
@Override
public void enterAnnotationType(GeneratedYangParser.AnnotationTypeContext ctx) {
// TODO: implement the method.
}
@Override
public void exitAnnotationType(GeneratedYangParser.AnnotationTypeContext ctx) {
// TODO: implement the method.
}
@Override
public void enterAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext
ctx) {
// TODO: implement the method.
public void enterCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext ctx) {
// do nothing
}
@Override
public void exitAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext ctx) {
// TODO: implement the method.
public void exitCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext ctx) {
// do nothing
}
@Override
public void enterAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
ctx) {
// TODO: implement the method.
public void enterAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext ctx) {
AppDataStructureListener.processAppDataStructureEntry(this, ctx);
}
@Override
public void exitAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
ctx) {
// TODO: implement the method.
public void exitAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext ctx) {
AppDataStructureListener.processAppDataStructureExit(this, ctx);
}
@Override
public void enterAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext ctx) {
// TODO: implement the method.
public void enterAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext) {
// do nothing
}
@Override
public void exitAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext ctx) {
// TODO: implement the method.
public void exitAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext) {
// do nothing
}
@Override
public void enterAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext ctx) {
// TODO: implement the method.
public void enterAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext) {
AppExtendedNameListener.processAppExtendedNameEntry(this, currentContext);
}
@Override
public void exitAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext ctx) {
// TODO: implement the method.
public void exitAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext) {
// TODO : to be implemented
}
@Override
public void enterAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext ctx) {
// TODO: implement the method.
public void enterExtendedName(GeneratedYangParser.ExtendedNameContext currentContext) {
// do nothing
}
@Override
public void exitAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext ctx) {
// TODO: implement the method.
public void exitExtendedName(GeneratedYangParser.ExtendedNameContext currentContext) {
// do nothing
}
@Override
public void enterAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext ctx) {
// TODO: implement the method.
public void enterDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext ctx) {
DataStructureKeyListener.processDataStructureKeyEntry(this, ctx);
}
@Override
public void exitAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext ctx) {
// TODO: implement the method.
public void exitDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext ctx) {
// do nothing
}
@Override
......
/*
* 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.YangAppDataStructure;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangDataStructure;
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.YangDataStructure.getType;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.APP_DATA_STRUCTURE;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidPrefix;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* app-data-structure-stmt = prefix:app-data-structure-keyword string
* (";" /
* "{"
* [data-structure-key-stmt stmtsep]
* "}")
*
* ANTLR grammar rule
* appDataStructureStatement : APP_DATA_STRUCTURE appDataStructure (STMTEND | (LEFT_CURLY_BRACE
* dataStructureKeyStatement? RIGHT_CURLY_BRACE));
*/
/**
* Represents listener based call back function corresponding to the "app-data-structure"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class AppDataStructureListener {
/**
* Creates a new app-data-structure listener.
*/
private AppDataStructureListener() {
}
/**
* Performs validation and updates the data model tree. It is called when parser receives an
* input matching the grammar rule(app-data-structure).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processAppDataStructureEntry(TreeWalkListener listener,
GeneratedYangParser.AppDataStructureStatementContext ctx) {
checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_DATA_STRUCTURE, "", ENTRY);
String prefix = getValidPrefix(ctx.APP_DATA_STRUCTURE().getText(), APP_DATA_STRUCTURE, ctx);
YangDataStructure dataStructure = getType(ctx.appDataStructure().getText());
YangAppDataStructure appDataStructure = new YangAppDataStructure();
appDataStructure.setPrefix(prefix);
appDataStructure.setDataStructure(dataStructure);
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangCompilerAnnotation) {
YangCompilerAnnotation compilerAnnotation = ((YangCompilerAnnotation) curData);
compilerAnnotation.setYangAppDataStructure(appDataStructure);
listener.getParsedDataStack().push(appDataStructure);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, APP_DATA_STRUCTURE,
"", ENTRY));
}
}
/**
* Performs validation and updates the data model tree. It is called when parser
* exits from grammar rule (app-data-structure).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processAppDataStructureExit(TreeWalkListener listener,
GeneratedYangParser.AppDataStructureStatementContext ctx) {
checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_DATA_STRUCTURE, "", EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangAppDataStructure)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, APP_DATA_STRUCTURE,
"", EXIT));
}
listener.getParsedDataStack().pop();
}
}
/*
* 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.YangAppExtendedName;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
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.YangConstructType.APP_EXTENDED_NAME_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.ListenerUtil.getValidPrefix;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* app-extended-stmt = prefix:app-extended-name-keyword string ";"
*
* ANTLR grammar rule
* appExtendedStatement : APP_EXTENDED extendedName STMTEND;
*/
/**
* Represents listener based call back function corresponding to the "app-extended-name"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class AppExtendedNameListener {
/**
* Creates a new app-extended-name listener.
*/
private AppExtendedNameListener() {
}
/**
* Performs validation and updates the data model tree. It is called when parser receives an
* input matching the grammar rule(app-extended-name).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processAppExtendedNameEntry(TreeWalkListener listener,
GeneratedYangParser.AppExtendedStatementContext ctx) {
checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_EXTENDED_NAME_DATA, ctx.extendedName().getText(), ENTRY);
String prefix = getValidPrefix(ctx.APP_EXTENDED().getText(), APP_EXTENDED_NAME_DATA, ctx);
YangAppExtendedName extendedName = new YangAppExtendedName();
extendedName.setPrefix(prefix);
extendedName.setYangAppExtendedName(removeQuotesAndHandleConcat(ctx.extendedName().getText()));
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangCompilerAnnotation) {
YangCompilerAnnotation compilerAnnotation = ((YangCompilerAnnotation) curData);
compilerAnnotation.setYangAppExtendedName(extendedName);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, APP_EXTENDED_NAME_DATA,
ctx.extendedName().getText(), ENTRY));
}
}
}
/*
* 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.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
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.YangConstructType.COMPILER_ANNOTATION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidPrefix;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* compiler-annotation-stmt = prefix:compiler-annotation-keyword string
* "{"
* [app-data-structure-stmt stmtsep]
* [app-extended-stmt stmtsep]
* "}"
*
* ANTLR grammar rule
* compilerAnnotationStatement : COMPILER_ANNOTATION string LEFT_CURLY_BRACE
* compilerAnnotationBodyStatement RIGHT_CURLY_BRACE;
*
* compilerAnnotationBodyStatement : appDataStructureStatement? appExtendedStatement? ;
*/
/**
* Represents listener based call back function corresponding to the "compiler-annotation"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class CompilerAnnotationListener {
/**
* Creates a new compiler-annotation listener.
*/
private CompilerAnnotationListener() {
}
/**
* Performs validation and updates the data model tree. It is called when parser receives an
* input matching the grammar rule(compiler-annotation).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processCompilerAnnotationEntry(TreeWalkListener listener,
GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, COMPILER_ANNOTATION_DATA, ctx.string().getText(), ENTRY);
String prefix = getValidPrefix(ctx.COMPILER_ANNOTATION().getText(), COMPILER_ANNOTATION_DATA, ctx);
YangCompilerAnnotation compilerAnnotation = new YangCompilerAnnotation();
compilerAnnotation.setPrefix(prefix);
compilerAnnotation.setPath(removeQuotesAndHandleConcat(ctx.string().getText()));
Parsable curData = listener.getParsedDataStack().peek();
switch (curData.getYangConstructType()) {
case MODULE_DATA:
YangModule module = ((YangModule) curData);
module.addCompilerAnnotation(compilerAnnotation);
break;
case SUB_MODULE_DATA:
YangSubModule subModule = ((YangSubModule) curData);
subModule.addCompilerAnnotation(compilerAnnotation);
break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, COMPILER_ANNOTATION_DATA,
ctx.string().getText(), ENTRY));
}
listener.getParsedDataStack().push(compilerAnnotation);
}
/**
* Performs validation and updates the data model tree. It is called when parser
* exits from grammar rule (compiler-annotation).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processCompilerAnnotationExit(TreeWalkListener listener,
GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
checkStackIsNotEmpty(listener, MISSING_HOLDER, COMPILER_ANNOTATION_DATA, ctx.string().getText(), EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangCompilerAnnotation)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, COMPILER_ANNOTATION_DATA,
ctx.string().getText(), EXIT));
}
listener.getParsedDataStack().pop();
}
}
/*
* 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.YangAppDataStructure;
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.YangConstructType.KEY_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.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
* data-structure-key-stmt = prefix:key-keyword string ";"
*
* ANTLR grammar rule
* dataStructureKeyStatement : DATA_STRUCTURE_KEY string STMTEND;
*/
/**
* Represents listener based call back function corresponding to the "key"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
*/
public final class DataStructureKeyListener {
/**
* Creates a new data-structure-key listener.
*/
private DataStructureKeyListener() {
}
/**
* Performs validation and updates the data model tree. It is called when parser receives an
* input matching the grammar rule(key).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processDataStructureKeyEntry(TreeWalkListener listener,
GeneratedYangParser.DataStructureKeyStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, KEY_DATA, ctx.string().getText(), ENTRY);
Parsable tmpData = listener.getParsedDataStack().peek();
if (listener.getParsedDataStack().peek() instanceof YangAppDataStructure) {
YangAppDataStructure dataStructure = (YangAppDataStructure) tmpData;
String tmpKeyValue = removeQuotesAndHandleConcat(ctx.string().getText());
if (tmpKeyValue.contains(SPACE)) {
String[] keyValues = tmpKeyValue.split(SPACE);
for (String keyValue : keyValues) {
dataStructure.addKey(keyValue);
}
} else {
dataStructure.addKey(tmpKeyValue);
}
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, KEY_DATA, ctx.string().getText(),
ENTRY));
}
}
}
......@@ -1026,4 +1026,28 @@ public final class ListenerUtil {
throw parserException;
}
}
/**
* Checks and return valid prefix.
*
* @param inputString string from yang file
* @param yangConstruct yang construct for creating error message
* @param ctx yang construct's context to get the line number and character position
* @return valid prefix
*/
public static String getValidPrefix(String inputString,
YangConstructType yangConstruct, ParserRuleContext ctx) {
String tmpPrefixString = removeQuotesAndHandleConcat(inputString);
String[] tmpData = tmpPrefixString.split(Pattern.quote(COLON));
if (tmpData.length == 2) {
return tmpData[0];
} else {
ParserException parserException = new ParserException("YANG file error : " +
YangConstructType.getYangConstructType(yangConstruct) + " name " + inputString +
" is not valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
}
}
......
......@@ -101,6 +101,14 @@ lexer grammar YangLexer;
UNBOUNDED_KEYWORD : 'unbounded';
USER_KEYWORD : 'user';
COMPILER_ANNOTATION_KEYWORD : 'compiler-annotation';
COMPILER_ANNOTATION : IDENTIFIER COLON COMPILER_ANNOTATION_KEYWORD;
APP_DATA_STRUCTURE_KEYWORD : 'app-data-structure';
APP_DATA_STRUCTURE : IDENTIFIER COLON APP_DATA_STRUCTURE_KEYWORD;
DATA_STRUCTURE_KEYWORD : 'data-structure';
DATA_STRUCTURE : IDENTIFIER COLON DATA_STRUCTURE_KEYWORD;
DATA_STRUCTURE_KEY : IDENTIFIER COLON KEY_KEYWORD;
APP_EXTENDED_KEYWORD : 'app-extended-name';
APP_EXTENDED : IDENTIFIER COLON APP_EXTENDED_KEYWORD;
// Lexer tokens to be skipped
COMMENT
......@@ -117,18 +125,11 @@ lexer grammar YangLexer;
DATE_ARG : DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT;
LEFT_CURLY_BRACE : '{';
RIGHT_CURLY_BRACE : '}';
LEFT_ROUND_BRACE : '(';
RIGHT_ROUND_BRACE : ')';
ANNOTATION_START : '@';
ANNOTATION_IDENTIFIER : ('@')(ALPHA | '_')
(ALPHA | DIGIT | '_' | '-' | '.')*;
IDENTIFIER : (ALPHA | '_')
(ALPHA | DIGIT | '_' | '-' | '.')*;
STMTEND : ';';
DQUOTE : '"';
COLON : ':';
COMMA : ',';
EQUAL : '=';
PLUS : '+';
MINUS: '-';
......
/*
* 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 java.io.IOException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangAppDataStructure;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangDataStructure;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
/**
* Test cases for compiler annotation listener.
*/
public class CompilerAnnotationListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks valid compiler annotation statements.
*/
@Test
public void processValidCompilerAnnotation() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ValidCompilerAnnotation.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("event"));
YangCompilerAnnotation compilerAnnotation = yangNode.getCompilerAnnotationList()
.iterator().next();
assertThat(compilerAnnotation.getPrefix(), is("ca"));
assertThat(compilerAnnotation.getPath(), is("/candidate-servers/server"));
YangAppDataStructure appDataStructure = compilerAnnotation.getYangAppDataStructure();
assertThat(appDataStructure.getPrefix(), is("abc"));
assertThat(appDataStructure.getDataStructure(), is(YangDataStructure.MAP));
assertThat(appDataStructure.getKeyList().iterator().next(), is("name"));
}
}
......@@ -23,13 +23,13 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
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.YangStatusType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
......@@ -208,4 +208,30 @@ public class ListListenerTest {
thrown.expectMessage("YANG file error : list name 1valid is not valid.");
YangNode node = manager.getDataModel("src/test/resources/ListInvalidIdentifier.yang");
}
/**
* Checks list with identifier name as enum.
*/
@Test
public void processListWithIdentifierNameEnum() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ListWithIdentifierNameEnum.yang");
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
// Check whether the list is child of module
YangList yangList = (YangList) yangNode.getChild();
assertThat(yangList.getName(), is("enumList"));
assertThat(yangList.getKeyList().contains("enum"), is(true));
YangLeaf leaf = yangList.getListOfLeaf().iterator().next();
assertThat(leaf.getName(), is("enum"));
assertThat(leaf.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
}
}
......
......@@ -16,6 +16,8 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import java.util.ListIterator;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangLeaf;
......@@ -25,9 +27,6 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import java.util.ListIterator;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
......@@ -49,12 +48,12 @@ public class WhenListenerTest {
assertThat(yangNode.getName(), is("Test"));
YangList yangList = (YangList) yangNode.getChild();
String expectedConstraint = "../switching-capability = 'TDM'";
assertThat(yangList.getName(), is("interface-switching-capability"));
assertThat(yangList.getWhen().getCondition(), is(expectedConstraint));
YangContainer container = (YangContainer) yangList.getNextSibling();
assertThat(container.getName(), is("time-division-multiplex-capable"));
String expectedConstraint = "../switching-capability = 'TDM'";
assertThat(container.getWhen().getCondition(), is(expectedConstraint));
}
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.ListIterator;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Rule;
import org.junit.Test;
......@@ -34,12 +36,10 @@ import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import java.io.IOException;
import java.util.ListIterator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
/**
* Test cases for testing inter file linking for identity.
......@@ -73,6 +73,8 @@ public class InterFileIdentityLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -162,6 +164,8 @@ public class InterFileIdentityLinkingTest {
// Add references to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -244,6 +248,8 @@ public class InterFileIdentityLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -302,7 +308,7 @@ public class InterFileIdentityLinkingTest {
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
}
}
/**
* Checks inter file feature linking with included file with dependency.
......@@ -332,6 +338,8 @@ public class InterFileIdentityLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -417,6 +425,8 @@ public class InterFileIdentityLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
}
......@@ -436,10 +446,6 @@ public class InterFileIdentityLinkingTest {
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
YangNode refNode1 = null;
YangNode refNode2 = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
......@@ -452,6 +458,9 @@ public class InterFileIdentityLinkingTest {
// Add references to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
// Update the priority for all the files.
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
}
......@@ -478,6 +487,8 @@ public class InterFileIdentityLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -570,6 +581,8 @@ public class InterFileIdentityLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......
......@@ -36,6 +36,7 @@ import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
/**
* Test cases for testing inter file linking.
......@@ -67,6 +68,8 @@ public class InterFileIfFeatureLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -137,6 +140,8 @@ public class InterFileIfFeatureLinkingTest {
// Add references to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -201,6 +206,9 @@ public class InterFileIfFeatureLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Update the priority for all the files.
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -272,6 +280,8 @@ public class InterFileIfFeatureLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -337,6 +347,8 @@ public class InterFileIfFeatureLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -409,6 +421,8 @@ public class InterFileIfFeatureLinkingTest {
// Add references to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......
......@@ -16,6 +16,9 @@
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.Iterator;
import java.util.ListIterator;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Rule;
import org.junit.Test;
......@@ -32,15 +35,12 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import java.io.IOException;
import java.util.Iterator;
import java.util.ListIterator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
/**
* Test cases for testing leafref inter file linking.
......@@ -74,6 +74,8 @@ public class InterFileLeafrefLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -146,6 +148,8 @@ public class InterFileLeafrefLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -209,6 +213,8 @@ public class InterFileLeafrefLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -278,6 +284,8 @@ public class InterFileLeafrefLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......
......@@ -24,6 +24,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangGrouping;
......@@ -49,6 +50,7 @@ import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
......@@ -84,6 +86,8 @@ public class InterFileLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -154,6 +158,8 @@ public class InterFileLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -227,6 +233,8 @@ public class InterFileLinkingTest {
// Add reference to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -300,6 +308,8 @@ public class InterFileLinkingTest {
// Add reference to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -370,6 +380,8 @@ public class InterFileLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -440,6 +452,8 @@ public class InterFileLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -511,6 +525,8 @@ public class InterFileLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -579,6 +595,8 @@ public class InterFileLinkingTest {
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -837,4 +855,80 @@ public class InterFileLinkingTest {
YangList list = ((YangList) uses.getNextSibling());
assertThat(list.getName(), is("connectivity-matrix"));
}
/**
* Checks contents of uses are copied as child of grouping.
*/
@Test
public void interFileUsesInsideChildOfGrouping()
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interFileUsesInsideChildOfGrouping";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
YangNode selfNode = null;
YangNode refNode1 = null;
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("ietf-network")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("ietf-te-topology")) {
refNode1 = rootNode;
}
}
// Check whether the data model tree returned is of type module.
assertThat(selfNode instanceof YangModule, is(true));
assertThat(selfNode.getNodeType(), is(MODULE_NODE));
YangModule yangNode = (YangModule) selfNode;
assertThat(yangNode.getName(), is("ietf-network"));
YangModule refNode = (YangModule) refNode1;
assertThat(refNode.getName(), is("ietf-te-topology"));
YangAugment augment = ((YangAugment) refNode.getChild().getNextSibling().
getNextSibling().getNextSibling().getNextSibling().getNextSibling());
assertThat(augment.getName(), is("/nw:networks/nw:network/nt:link"));
YangUses uses = ((YangUses) augment.getChild());
assertThat(uses.getResolvableStatus(), is(RESOLVED));
YangContainer container = ((YangContainer) uses.getNextSibling());
assertThat(container.getName(), is("te"));
container = ((YangContainer) container.getChild());
assertThat(container.getName(), is("config"));
uses = ((YangUses) container.getChild().getNextSibling());
assertThat(uses.getName(), is("te-link-config-attributes"));
assertThat(uses.getResolvableStatus(), is(RESOLVED));
YangContainer container1 = ((YangContainer) uses.getNextSibling());
assertThat(container1.getName(), is("te-link-attributes"));
container = ((YangContainer) container1.getChild());
assertThat(container.getName(), is("underlay"));
uses = ((YangUses) container.getChild());
assertThat(uses.getName(), is("te-link-underlay-attributes"));
assertThat(uses.getResolvableStatus(), is(RESOLVED));
container = ((YangContainer) uses.getNextSibling());
assertThat(container.getName(), is("underlay-primary-path"));
YangList yangList = ((YangList) container.getChild());
assertThat(yangList.getName(), is("path-element"));
uses = ((YangUses) yangList.getChild());
assertThat(uses.getName(), is("te-path-element"));
assertThat(uses.getResolvableStatus(), is(RESOLVED));
uses = ((YangUses) uses.getNextSibling());
assertThat(uses.getName(), is("explicit-route-subobject"));
assertThat(uses.getResolvableStatus(), is(RESOLVED));
YangChoice choice = ((YangChoice) uses.getNextSibling());
assertThat(choice.getName(), is("type"));
}
}
......
......@@ -486,7 +486,7 @@ public class IntraFileUsesLinkingTest {
// Check whether uses is getting resolved.
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
is(ResolvableStatus.INTRA_FILE_RESOLVED));
// Check whether grouping is the child of module.
assertThat((yangNode.getChild() instanceof YangGrouping), is(true));
......@@ -610,7 +610,7 @@ public class IntraFileUsesLinkingTest {
// Check whether uses is getting resolved.
assertThat(yangUses1.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
is(ResolvableStatus.INTRA_FILE_RESOLVED));
// Check whether grouping is the sibling of uses.
YangGrouping yangGrouping1 = (YangGrouping) yangUses1.getNextSibling();
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.ResolvableType;
......@@ -32,6 +31,7 @@ import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
/**
* Unit test cases for x-path linker.
......@@ -237,6 +237,7 @@ public class YangXpathLinkerTest {
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......@@ -267,6 +268,7 @@ public class YangXpathLinkerTest {
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......@@ -451,6 +453,7 @@ public class YangXpathLinkerTest {
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......@@ -484,6 +487,7 @@ public class YangXpathLinkerTest {
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
String targetNodeName = null;
......@@ -516,6 +520,7 @@ public class YangXpathLinkerTest {
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
String targetNodeName = null;
......@@ -548,6 +553,7 @@ public class YangXpathLinkerTest {
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......@@ -581,6 +587,7 @@ public class YangXpathLinkerTest {
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......@@ -614,6 +621,7 @@ public class YangXpathLinkerTest {
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......
module Test {
yang-version 1;
namespace http://huawei.com;
namespace "http://huawei.com";
prefix Ant;
list interface-switching-capability {
when "../switching-capability = 'TDM'" {
description "Valid only for TDM";
}
key "switching-capability";
description
"List of Interface Switching Capabilities Descriptors (ISCD)
......
module Test {
yang-version 1;
namespace "ydt.enum";
prefix "t";
list enumList {
key enum;
leaf enum {
type enumeration {
enum ten { value "10";}
enum hundred { value "100";}
enum thousand { value "1000"; }
}
}
}
}
module event {
namespace "http://example.com/event";
prefix "ev";
ca:compiler-annotation "/candidate-servers/server" {
abc:app-data-structure "map" {
ca:key "name";
}
xyz:app-extended-name "special-server";
}
}
module ietf-network-topology {
yang-version 1;
namespace "ietf-vidya-topology";
prefix lnk;
import ietf-network {
prefix nd;
}
revision 2015-12-08 {
description
"Initial revision.
NOTE TO RFC EDITOR: Please replace the following reference
to draft-ietf-i2rs-yang-network-topo-02 with
RFC number when published (i.e. RFC xxxx).";
reference
"draft-ietf-i2rs-yang-network-topo-02.";
}
augment "/nd:networks/nd:network" {
list link {
key "link-id";
container source {
leaf source-node {
type string;
mandatory true;
}
leaf source-tp {
type string;
}
}
leaf link-id {
type string;
}
}
}
}
module ietf-network {
yang-version 1;
namespace "ietf-network";
prefix nd;
revision 2015-12-08 {
description
"Initial revision.
NOTE TO RFC EDITOR: Please replace the following reference
to draft-ietf-i2rs-yang-network-topo-02 with
RFC number when published (i.e. RFC xxxx).";
reference
"draft-ietf-i2rs-yang-network-topo-02";
}
container networks {
list network {
key "network-id";
leaf network-id {
type string;
}
list node {
key "node-id";
leaf node-id {
type string;
}
}
}
}
}
module ietf-te-topology {
yang-version 1;
namespace "ietf-te-topology";
prefix "tet";
import ietf-te-types {
prefix "te-types";
}
import ietf-network {
prefix "nw";
}
import ietf-network-topology {
prefix "nt";
}
revision "2016-03-17" {
description "Initial revision";
reference "TBD";
}
grouping te-link-augment {
container te {
container config {
uses te-link-config;
} // config
} // te
} // te-link-augment
grouping te-link-config {
uses te-link-config-attributes;
} // te-link-config
grouping te-link-config-attributes {
container te-link-attributes {
container underlay {
uses te-link-underlay-attributes;
} // underlay
} // te-link-attributes
} // te-link-config-attributes
grouping te-link-underlay-attributes {
container underlay-primary-path {
list path-element {
key "path-element-id";
description
"A list of path elements describing the service path.";
leaf path-element-id {
type uint32;
description "To identify the element in a path.";
}
uses te-path-element;
}
} // underlay-primary-path
} // te-link-underlay-attributes
grouping te-path-element {
uses te-types:explicit-route-subobject;
} // te-path-element
augment "/nw:networks/nw:network/nt:link" {
uses te-link-augment;
}
}
module ietf-te-types {
namespace "ietf-te-types";
prefix "te-types";
revision 2016-03-20 {
description "Latest revision of TE generic types";
reference "RFC3209";
}
grouping explicit-route-subobject {
choice type {
case ipv4-address {
leaf v4-address {
type string;
}
}
}
}
}