identityref tostring generation
Change-Id: I06b7b62c923f4ae73f64cc38efa8e3b93656a372
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
index 231675e..60f5208 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
@@ -79,7 +79,7 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getAddToListMethodInterface;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
@@ -89,7 +89,7 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getToStringMethod;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getYangDataStructure;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOverRideString;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorErrorType.INVALID_LEAF_HOLDER;
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaTypeFragmentFiles.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaTypeFragmentFiles.java
index 81a7718..76930f8 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaTypeFragmentFiles.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaTypeFragmentFiles.java
@@ -16,6 +16,7 @@
package org.onosproject.yang.compiler.translator.tojava;
+import org.onosproject.yang.compiler.datamodel.YangIdentity;
import org.onosproject.yang.compiler.datamodel.YangIdentityRef;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangType;
@@ -50,6 +51,7 @@
import static org.onosproject.yang.compiler.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getDerivedPkfInfo;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
@@ -331,10 +333,17 @@
//TODO: Union with two identities code generation has to be changed.
private void addIdentityToImport(List<YangType<?>> types,
YangPluginConfig config) {
- for (YangType<?> type :types) {
+ for (YangType<?> type : types) {
Object ex = type.getDataTypeExtendedInfo();
if (ex != null && ex instanceof YangIdentityRef) {
+ YangIdentity base = ((YangIdentityRef) ex).getReferredIdentity();
getAttributeForType(type, config);
+ List<YangIdentity> idList = base.getExtendList();
+ for (YangIdentity id : idList) {
+ JavaQualifiedTypeInfoTranslator derPkgInfo =
+ getDerivedPkfInfo(id);
+ getIsQualifiedAccessOrAddToImportList(derPkgInfo);
+ }
}
}
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaIdentityTranslator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaIdentityTranslator.java
index 3b7fa5e..9c2dc06 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaIdentityTranslator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/YangJavaIdentityTranslator.java
@@ -37,6 +37,7 @@
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils.updatePackageInfo;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getDerivedPkfInfo;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
@@ -48,7 +49,6 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.getErrorMsg;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yang.compiler.utils.UtilConstants.IDENTITY;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_FILE_EXTENSION;
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
import static org.onosproject.yang.compiler.utils.io.impl.FileSystemUtil.closeFile;
@@ -191,26 +191,10 @@
*/
private List<String> getImportOfDerId(List<YangIdentity> idList,
List<String> imports, String className) {
- String derClassName;
if (idList != null) {
for (YangIdentity id : idList) {
- if (id.isNameConflict()) {
- derClassName = getCapitalCase(
- getCamelCase(id.getName() + IDENTITY, null));
- } else {
- derClassName = getCapitalCase(
- getCamelCase(id.getName(), null));
- }
- JavaFileInfoTranslator info = ((
- YangJavaIdentityTranslator) id).getJavaFileInfo();
- String derPkg = info.getPackage();
- if (derPkg == null) {
- derPkg = getDerivedPackage(id);
- }
JavaQualifiedTypeInfoTranslator derPkgInfo =
- new JavaQualifiedTypeInfoTranslator();
- derPkgInfo.setClassInfo(derClassName);
- derPkgInfo.setPkgInfo(derPkg);
+ getDerivedPkfInfo(id);
importData.addImportInfo(derPkgInfo, className,
javaFileInfo.getPackage());
}
@@ -225,8 +209,8 @@
* @param id YANG Identity.
* @return package of identity.
*/
- private String getDerivedPackage(YangIdentity id) {
- String derPkg = null;
+ public static String getDerivedPackage(YangIdentity id) {
+ String derPkg;
byte version;
String moduleName;
YangRevision revision;
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaCodeSnippetGen.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaCodeSnippetGen.java
index 8a9d90b..396b522 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -29,7 +29,7 @@
import static java.util.Collections.sort;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getYangDataStructure;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getDefaultDefinition;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOpenCloseParaWithValue;
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java
index 624cf7e..bc6e5e3 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGenerator.java
@@ -123,7 +123,7 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getUnionToStringMethod;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getYangDataStructure;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.isLeafValueSetInterface;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getInterfaceLeafIdEnumMethods;
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java
index f38c90b..42f946e 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -17,14 +17,19 @@
package org.onosproject.yang.compiler.translator.tojava.utils;
import org.onosproject.yang.compiler.datamodel.InvalidOpTypeHolder;
+import org.onosproject.yang.compiler.datamodel.YangAppDataStructure;
import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
import org.onosproject.yang.compiler.datamodel.YangAugment;
+import org.onosproject.yang.compiler.datamodel.YangCompilerAnnotation;
+import org.onosproject.yang.compiler.datamodel.YangDataStructure;
+import org.onosproject.yang.compiler.datamodel.YangIdentity;
import org.onosproject.yang.compiler.datamodel.YangLeafRef;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangNodeIdentifier;
import org.onosproject.yang.compiler.datamodel.YangType;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.compiler.translator.exception.TranslatorException;
+import org.onosproject.yang.compiler.translator.tojava.JavaAttributeInfo;
import org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoTranslator;
@@ -37,14 +42,18 @@
import org.onosproject.yang.compiler.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yang.compiler.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yang.compiler.translator.tojava.TempJavaTypeFragmentFiles;
+import org.onosproject.yang.compiler.translator.tojava.javamodel.YangJavaIdentityTranslator;
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
@@ -86,17 +95,48 @@
import static org.onosproject.yang.compiler.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils.getNodesPackage;
import static org.onosproject.yang.compiler.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
+import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.FOUR_SPACE;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodClassTypes.INTERFACE_TYPE;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getIfConditionBegin;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOverRideString;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getReturnString;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getTwoParaEqualsString;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.methodClose;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.methodSignature;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.multiAttrMethodSignature;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.signatureClose;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.AUGMENTED;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CLASS_STRING;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_CURLY_BRACKET;
+import static org.onosproject.yang.compiler.utils.UtilConstants.COMPARE_TO;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.ERROR_MSG_FOR_GEN_CODE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EXTEND;
+import static org.onosproject.yang.compiler.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.IDENTITY;
+import static org.onosproject.yang.compiler.utils.UtilConstants.INT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.KEYS;
import static org.onosproject.yang.compiler.utils.UtilConstants.LEAFREF;
+import static org.onosproject.yang.compiler.utils.UtilConstants.NEG_ONE;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yang.compiler.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yang.compiler.utils.UtilConstants.PACKAGE;
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
+import static org.onosproject.yang.compiler.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yang.compiler.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yang.compiler.utils.UtilConstants.SET_METHOD_PREFIX;
import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.TO_CAPS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_CAPS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.VOID;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ZERO;
import static org.onosproject.yang.compiler.utils.io.impl.CopyrightHeader.parseCopyrightHeader;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CLASS;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
@@ -846,4 +886,165 @@
}
return attributeType;
}
+
+ /**
+ * Returns package info of derived identity.
+ *
+ * @param id YANG identity.
+ * @return derived package info.
+ */
+ public static JavaQualifiedTypeInfoTranslator getDerivedPkfInfo(YangIdentity id) {
+ String pkg = YangJavaIdentityTranslator.getDerivedPackage(id);
+ String name;
+ if (id.isNameConflict()) {
+ name = getCapitalCase(
+ getCamelCase(id.getName() + IDENTITY, null));
+ } else {
+ name = getCapitalCase(
+ getCamelCase(id.getName(), null));
+ }
+ JavaQualifiedTypeInfoTranslator derPkgInfo =
+ new JavaQualifiedTypeInfoTranslator();
+ derPkgInfo.setClassInfo(name);
+ derPkgInfo.setPkgInfo(pkg);
+ return derPkgInfo;
+ }
+
+ /**
+ * Returns Identity name of the Identity.
+ *
+ * @param id YANG identity.
+ * @return YANG identity name.
+ */
+ public static String getIdName(YangIdentity id) {
+ String idName;
+ if (id.isNameConflict()) {
+ idName = getCapitalCase(
+ getCamelCase(id.getName() + IDENTITY, null));
+ } else {
+ idName = getCapitalCase(
+ getCamelCase(id.getName(), null));
+ }
+ return idName;
+ }
+
+ /**
+ * Returns add to list method interface.
+ *
+ * @param attr java attribute
+ * @param className name of the class
+ * @return add to list method interface
+ */
+ public static String getAddToListMethodInterface(JavaAttributeInfo attr,
+ String className) {
+
+ String methodName = ADD_STRING + TO_CAPS + getCapitalCase(
+ attr.getAttributeName());
+ String retType = getReturnType(attr);
+ YangDataStructure struct = getYangDataStructure(attr.getCompilerAnnotation());
+ if (struct != null) {
+ switch (struct) {
+ case MAP:
+ Map<String, String> param = new LinkedHashMap<>();
+ param.put(attr.getAttributeName() + KEYS, retType + KEYS);
+ param.put(attr.getAttributeName() + VALUE_CAPS, retType);
+ return multiAttrMethodSignature(methodName, null, null,
+ VOID, param,
+ INTERFACE_TYPE,
+ FOUR_SPACE_INDENTATION);
+ default:
+ return methodSignature(methodName, null, null, ADD_STRING + TO_CAPS,
+ VOID, retType,
+ INTERFACE_TYPE);
+ }
+ }
+ return methodSignature(methodName, null, null, ADD_STRING + TO_CAPS,
+ VOID, getReturnType(attr),
+ INTERFACE_TYPE);
+ }
+
+ /**
+ * Returns YANG data structure from java attribute.
+ *
+ * @param annotation compiler annotation
+ * @return YANG data structure from java attribute
+ */
+ public static YangDataStructure getYangDataStructure(
+ YangCompilerAnnotation annotation) {
+ if (annotation != null) {
+ YangAppDataStructure data = annotation.getYangAppDataStructure();
+ if (data != null) {
+ return data.getDataStructure();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns return type for attribute.
+ *
+ * @param attr attribute info
+ * @return return type
+ */
+ static String getReturnType(JavaAttributeInfo attr) {
+ StringBuilder builder = new StringBuilder();
+
+ if (attr.isQualifiedName() &&
+ attr.getImportInfo().getPkgInfo() != null) {
+ builder.append(attr.getImportInfo().getPkgInfo()).append(PERIOD);
+ }
+ builder.append(attr.getImportInfo().getClassInfo());
+
+ if (attr.getAttributeType() != null &&
+ attr.getAttributeType().getDataType() == IDENTITYREF) {
+ return CLASS_STRING + DIAMOND_OPEN_BRACKET +
+ QUESTION_MARK + SPACE + EXTEND + SPACE +
+ builder.toString() + DIAMOND_CLOSE_BRACKET;
+ }
+ return builder.toString();
+ }
+
+ /**
+ * Returns compare to method for key class.
+ *
+ * @param attrs attribute list
+ * @param className class name
+ * @return compare to method
+ */
+ public static String getCompareToForKeyClass(
+ List<JavaAttributeInfo> attrs, String className) {
+
+ StringBuilder builder = new StringBuilder(getOverRideString());
+ builder.append(methodSignature(COMPARE_TO, null, PUBLIC, VALUE, INT,
+ className, CLASS_TYPE));
+ String cond;
+ String attrName;
+ String para;
+ StringBuilder space = new StringBuilder();
+ List<String> spaces = new ArrayList<>();
+ int count = 1;
+ for (JavaAttributeInfo attr : attrs) {
+ attrName = attr.getAttributeName();
+ para = VALUE + PERIOD + attrName;
+ cond = getTwoParaEqualsString(attrName, para);
+ if (count == 1) {
+ space.append(EIGHT_SPACE_INDENTATION);
+ } else {
+ space.append(FOUR_SPACE_INDENTATION);
+ }
+ spaces.add(space.toString());
+ count++;
+ builder.append(getIfConditionBegin(space.toString(), cond));
+ }
+ space.append(FOUR_SPACE_INDENTATION);
+ builder.append(getReturnString(ZERO, space.toString()))
+ .append(signatureClose());
+ for (int i = spaces.size() - 1; i >= 0; i--) {
+ builder.append(spaces.get(i)).append(CLOSE_CURLY_BRACKET)
+ .append(NEW_LINE);
+ }
+ builder.append(getReturnString(NEG_ONE, EIGHT_SPACE_INDENTATION))
+ .append(signatureClose()).append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
}
\ No newline at end of file
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
index ed46a96..fbefdd7 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
@@ -17,7 +17,6 @@
package org.onosproject.yang.compiler.translator.tojava.utils;
import org.onosproject.yang.compiler.datamodel.InvalidOpTypeHolder;
-import org.onosproject.yang.compiler.datamodel.YangAppDataStructure;
import org.onosproject.yang.compiler.datamodel.YangAtomicPath;
import org.onosproject.yang.compiler.datamodel.YangCompilerAnnotation;
import org.onosproject.yang.compiler.datamodel.YangDataStructure;
@@ -34,7 +33,6 @@
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType;
-import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -50,7 +48,10 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.IndentationType.TWELVE_SPACE;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getCurNodeName;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getIdName;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getReturnType;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getYangDataStructure;
import static org.onosproject.yang.compiler.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodBodyTypes.GETTER;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodBodyTypes.MANAGER_METHODS;
@@ -80,6 +81,7 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getReturnOfSubString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getReturnString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getSetValueParaCondition;
+import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getSetterInterfaceString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getStringBuilderAttr;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getToStringCall;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getTrySubString;
@@ -117,10 +119,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yang.compiler.utils.UtilConstants.COLON;
import static org.onosproject.yang.compiler.utils.UtilConstants.COMMA;
-import static org.onosproject.yang.compiler.utils.UtilConstants.COMPARE_TO;
import static org.onosproject.yang.compiler.utils.UtilConstants.DECODE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
import static org.onosproject.yang.compiler.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.ELSE;
import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
@@ -159,7 +158,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_LEAF_IDENTIFIER;
import static org.onosproject.yang.compiler.utils.UtilConstants.MODEL_OBJECT;
-import static org.onosproject.yang.compiler.utils.UtilConstants.NEG_ONE;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_STRING_JOINER_OBJECT;
@@ -215,7 +213,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_LEAF_SET;
import static org.onosproject.yang.compiler.utils.UtilConstants.VARIABLE_C;
import static org.onosproject.yang.compiler.utils.UtilConstants.VOID;
-import static org.onosproject.yang.compiler.utils.UtilConstants.ZERO;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
import static org.onosproject.yang.compiler.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD;
@@ -253,7 +250,6 @@
* @return getter string
*/
public static String getGetterString(JavaAttributeInfo attr, int genType) {
-
String returnType = getReturnType(attr);
String attributeName = attr.getAttributeName();
String appDataStructure = null;
@@ -614,51 +610,6 @@
}
/**
- * Returns setter string for interface.
- *
- * @param name class name
- * @param attrName attribute name
- * @param attrType attribute type
- * @return setter string
- */
- private static String getSetterInterfaceString(String name,
- String attrName,
- String attrType,
- int genType) {
- if (genType == GENERATE_SERVICE_AND_MANAGER) {
- return methodSignature(getCapitalCase(attrName), SET_METHOD_PREFIX,
- null, attrName, VOID, attrType + OP_PARAM,
- INTERFACE_TYPE);
- }
- return methodSignature(attrName, EMPTY_STRING, null,
- attrName, VOID, attrType, INTERFACE_TYPE);
- }
-
- /**
- * Returns return type for attribute.
- *
- * @param attr attribute info
- * @return return type
- */
- private static String getReturnType(JavaAttributeInfo attr) {
- StringBuilder builder = new StringBuilder();
-
- if (attr.isQualifiedName() &&
- attr.getImportInfo().getPkgInfo() != null) {
- builder.append(attr.getImportInfo().getPkgInfo()).append(PERIOD);
- }
- builder.append(attr.getImportInfo().getClassInfo());
-
- if (attr.getAttributeType() != null &&
- attr.getAttributeType().getDataType() == IDENTITYREF) {
- return CLASS_STRING + DIAMOND_OPEN_BRACKET +
- QUESTION_MARK + SPACE + EXTEND + SPACE +
- builder.toString() + DIAMOND_CLOSE_BRACKET;
- }
- return builder.toString();
- }
-
- /**
* Returns the constructor strings for class file.
*
* @param attr attribute info
@@ -1431,58 +1382,6 @@
}
/**
- * Returns add to list method interface.
- *
- * @param attr java attribute
- * @param className name of the class
- * @return add to list method interface
- */
- public static String getAddToListMethodInterface(JavaAttributeInfo attr,
- String className) {
-
- String methodName = ADD_STRING + TO_CAPS + getCapitalCase(
- attr.getAttributeName());
- String retType = getReturnType(attr);
- YangDataStructure struct = getYangDataStructure(attr.getCompilerAnnotation());
- if (struct != null) {
- switch (struct) {
- case MAP:
- Map<String, String> param = new LinkedHashMap<>();
- param.put(attr.getAttributeName() + KEYS, retType + KEYS);
- param.put(attr.getAttributeName() + VALUE_CAPS, retType);
- return multiAttrMethodSignature(methodName, null, null,
- VOID, param,
- INTERFACE_TYPE,
- FOUR_SPACE_INDENTATION);
- default:
- return methodSignature(methodName, null, null, ADD_STRING + TO_CAPS,
- VOID, retType,
- INTERFACE_TYPE);
- }
- }
- return methodSignature(methodName, null, null, ADD_STRING + TO_CAPS,
- VOID, getReturnType(attr),
- INTERFACE_TYPE);
- }
-
- /**
- * Returns YANG data structure from java attribute.
- *
- * @param annotation compiler annotation
- * @return YANG data structure from java attribute
- */
- public static YangDataStructure getYangDataStructure(
- YangCompilerAnnotation annotation) {
- if (annotation != null) {
- YangAppDataStructure data = annotation.getYangAppDataStructure();
- if (data != null) {
- return data.getDataStructure();
- }
- }
- return null;
- }
-
- /**
* Returns add to list method impl.
*
* @param attr java attribute
@@ -1683,9 +1582,16 @@
StringBuilder builder = new StringBuilder(getOverRideString())
.append(methodSignature(TO_STRING_METHOD, null, PUBLIC, null,
STRING_DATA_TYPE, null, CLASS_TYPE));
- builder.append(getReturnString(
- getToStringForSpecialType(type, attr), EIGHT_SPACE_INDENTATION))
- .append(signatureClose()).append(methodClose(FOUR_SPACE));
+ if (type.getDataType() == IDENTITYREF) {
+ builder.append(getToStringForSpecialType(type, attr))
+ .append(getReturnString(null, EIGHT_SPACE_INDENTATION))
+ .append(signatureClose())
+ .append(methodClose(FOUR_SPACE));
+ } else {
+ builder.append(getReturnString(
+ getToStringForSpecialType(type, attr), EIGHT_SPACE_INDENTATION))
+ .append(signatureClose()).append(methodClose(FOUR_SPACE));
+ }
return builder.toString();
}
@@ -1727,13 +1633,7 @@
getToStringForSpecialType(rt, name);
case IDENTITYREF:
- YangIdentityRef ir = (YangIdentityRef) type
- .getDataTypeExtendedInfo();
- YangIdentity identity = ir.getReferredIdentity();
- String idName = getCamelCase(getIdentityRefName(type), null);
- return getCapitalCase(idName) + PERIOD +
- getCamelCase(identity.getName(), null) + TO_CAPS +
- STRING_DATA_TYPE + OPEN_CLOSE_BRACKET_STRING;
+ return getIdRefToString(type, name, "");
case ENUMERATION:
case INSTANCE_IDENTIFIER:
case UINT64:
@@ -1748,24 +1648,83 @@
}
/**
+ * Returns indented toString method of identiref.
+ *
+ * @param type type of attribute.
+ * @param name @return to string method body for typedef class
+ * @param indent number of indent spaces.
+ * @return returns tostring method.
+ */
+ private static String getIdRefToString(YangType type, String name, String
+ indent) {
+ YangIdentityRef ir = (YangIdentityRef) type
+ .getDataTypeExtendedInfo();
+ StringBuilder builder = new StringBuilder();
+ String idName = getCamelCase(getIdentityRefName(type), null);
+ YangIdentity identity = ir.getReferredIdentity();
+ //condition for comparision
+ String cond = getTwoParaEqualsString(name, getCapitalCase(idName) + PERIOD + CLASS);
+ //return value in toString method
+ String returnVal = getCapitalCase(idName) + PERIOD + getCamelCase(
+ identity.getName(), null) + TO_CAPS +
+ STRING_DATA_TYPE + OPEN_CLOSE_BRACKET_STRING;
+ List<YangIdentity> idList = identity.getExtendList();
+ //adding present identity's tostring method
+ builder.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION + indent,
+ cond))
+ .append(getReturnString(returnVal, TWELVE_SPACE_INDENTATION +
+ indent))
+ .append(signatureClose());
+ //adding derived identities tostring method
+ for (YangIdentity id : idList) {
+ idName = getIdName(id);
+ cond = getTwoParaEqualsString(name, getCapitalCase(idName) +
+ PERIOD + CLASS);
+
+ returnVal = getCapitalCase(idName) + PERIOD + getCamelCase(id.getName(), null) + TO_CAPS +
+ STRING_DATA_TYPE + OPEN_CLOSE_BRACKET_STRING;
+
+ builder.append(getElseIfConditionBegin(
+ EIGHT_SPACE_INDENTATION + indent, cond))
+ .append(getReturnString(returnVal,
+ TWELVE_SPACE_INDENTATION + indent))
+ .append(signatureClose());
+ }
+ //passing indents for if-else statements in toString methods
+ if (indent.equals(FOUR_SPACE_INDENTATION)) {
+ builder.append(methodClose(TWELVE_SPACE));
+ } else {
+ builder.append(methodClose(EIGHT_SPACE));
+ }
+ return builder.toString();
+ }
+
+ /**
* Returns union class's to string method.
*
* @param types list of types
* @return union class's to string method
*/
static String getUnionToStringMethod(List<YangType<?>> types) {
-
StringBuilder builder = new StringBuilder(getOverRideString());
builder.append(methodSignature(TO_STRING_METHOD, null, PUBLIC, null,
STRING_DATA_TYPE, null, CLASS_TYPE));
for (YangType type : types) {
builder.append(getIfConditionBegin(
EIGHT_SPACE_INDENTATION, getSetValueParaCondition(
- types.indexOf(type)))).append(getReturnString(
- getToStringForSpecialType(type,
- getCamelCase(type.getDataTypeName(), null)),
- TWELVE_SPACE_INDENTATION))
- .append(signatureClose()).append(methodClose(EIGHT_SPACE));
+ types.indexOf(type))));
+ String retVal = getToStringForSpecialType(
+ type, getCamelCase(type.getDataTypeName(), null));
+ if (type.getDataType() != IDENTITYREF) {
+ builder.append(getReturnString(retVal, TWELVE_SPACE_INDENTATION))
+ .append(signatureClose());
+ } else {
+ retVal = getIdRefToString(type,
+ getCamelCase(type.getDataTypeName(), null),
+ FOUR_SPACE_INDENTATION);
+ builder.append(retVal);
+ }
+ builder.append(methodClose(EIGHT_SPACE));
}
builder.append(getReturnString(NULL, EIGHT_SPACE_INDENTATION)).append(signatureClose())
.append(methodClose(FOUR_SPACE));
@@ -1906,50 +1865,6 @@
}
/**
- * Returns compare to method for key class.
- *
- * @param attrs attribute list
- * @param className class name
- * @return compare to method
- */
- public static String getCompareToForKeyClass(
- List<JavaAttributeInfo> attrs, String className) {
-
- StringBuilder builder = new StringBuilder(getOverRideString());
- builder.append(methodSignature(COMPARE_TO, null, PUBLIC, VALUE, INT,
- className, CLASS_TYPE));
- String cond;
- String attrName;
- String para;
- StringBuilder space = new StringBuilder();
- List<String> spaces = new ArrayList<>();
- int count = 1;
- for (JavaAttributeInfo attr : attrs) {
- attrName = attr.getAttributeName();
- para = VALUE + PERIOD + attrName;
- cond = getTwoParaEqualsString(attrName, para);
- if (count == 1) {
- space.append(EIGHT_SPACE_INDENTATION);
- } else {
- space.append(FOUR_SPACE_INDENTATION);
- }
- spaces.add(space.toString());
- count++;
- builder.append(getIfConditionBegin(space.toString(), cond));
- }
- space.append(FOUR_SPACE_INDENTATION);
- builder.append(getReturnString(ZERO, space.toString()))
- .append(signatureClose());
- for (int i = spaces.size() - 1; i >= 0; i--) {
- builder.append(spaces.get(i)).append(CLOSE_CURLY_BRACKET)
- .append(NEW_LINE);
- }
- builder.append(getReturnString(NEG_ONE, EIGHT_SPACE_INDENTATION))
- .append(signatureClose()).append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- /**
* Returns parameterisied constructor string.
*
* @param name class name
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
index ff8c231..7f0a2f3 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
@@ -40,11 +40,13 @@
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yang.compiler.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET;
import static org.onosproject.yang.compiler.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
import static org.onosproject.yang.compiler.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
-import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
+import static org.onosproject.yang.compiler.translator.tojava.utils.JavaFileGeneratorUtils.getYangDataStructure;
+import static org.onosproject.yang.compiler.translator.tojava.utils.MethodClassTypes.INTERFACE_TYPE;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.getIdentityRefName;
import static org.onosproject.yang.compiler.utils.UtilConstants.ABSTRACT;
import static org.onosproject.yang.compiler.utils.UtilConstants.ADD;
@@ -108,6 +110,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_PARENTHESIS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yang.compiler.utils.UtilConstants.OVERRIDE;
import static org.onosproject.yang.compiler.utils.UtilConstants.PARSE_BOOLEAN;
import static org.onosproject.yang.compiler.utils.UtilConstants.PARSE_BYTE;
@@ -122,6 +125,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.RETURN;
import static org.onosproject.yang.compiler.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yang.compiler.utils.UtilConstants.SET;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SET_METHOD_PREFIX;
import static org.onosproject.yang.compiler.utils.UtilConstants.SET_VALUE_PARA;
import static org.onosproject.yang.compiler.utils.UtilConstants.SHORT;
import static org.onosproject.yang.compiler.utils.UtilConstants.SHORT_MAX_RANGE;
@@ -147,6 +151,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.ULONG_MIN_RANGE;
import static org.onosproject.yang.compiler.utils.UtilConstants.VALIDATE_RANGE;
import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.VOID;
import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_UTILS_TODO;
import static org.onosproject.yang.compiler.utils.UtilConstants.ZERO;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
@@ -1365,4 +1370,25 @@
.append(pkg).append(PERIOD).append(cls).append(signatureClose());
return builder.toString();
}
+
+ /**
+ * Returns setter string for interface.
+ *
+ * @param name class name
+ * @param attrName attribute name
+ * @param attrType attribute type
+ * @return setter string
+ */
+ static String getSetterInterfaceString(String name,
+ String attrName,
+ String attrType,
+ int genType) {
+ if (genType == GENERATE_SERVICE_AND_MANAGER) {
+ return methodSignature(getCapitalCase(attrName), SET_METHOD_PREFIX,
+ null, attrName, VOID, attrType + OP_PARAM,
+ INTERFACE_TYPE);
+ }
+ return methodSignature(attrName, EMPTY_STRING, null,
+ attrName, VOID, attrType, INTERFACE_TYPE);
+ }
}
diff --git a/compiler/plugin/maven/src/test/resources/DerivedIdentity/DerivedIdentities.yang b/compiler/plugin/maven/src/test/resources/DerivedIdentity/DerivedIdentities.yang
index 379f832..70fcc5a 100644
--- a/compiler/plugin/maven/src/test/resources/DerivedIdentity/DerivedIdentities.yang
+++ b/compiler/plugin/maven/src/test/resources/DerivedIdentity/DerivedIdentities.yang
@@ -15,6 +15,32 @@
base ref-address-family;
}
+ typedef type2 {
+ type identityref {
+ base ipv4-address-family;
+ }
+ }
+
+ typedef type3 {
+ type union {
+ type type2;
+ type identityref {
+ base ipv4-address-family;
+ }
+ }
+ }
+
+ typedef type4 {
+ type union {
+ type identityref {
+ base ipv4-address-family;
+ }
+ type identityref {
+ base ipv6-address-family;
+ }
+ }
+ }
+
leaf tunnel {
type type15;
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
index 480b753..519bf81 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
@@ -33,6 +33,8 @@
import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def1;
import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def2;
import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def3;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def6;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def7;
import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.DefaultCont1;
import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Physical;
import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Virtual;
@@ -41,6 +43,7 @@
import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.cont2.AugmentedCont2;
import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.cont2.DefaultAugmentedCont2;
import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.def1.Def1Union;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.def7.Def7Union;
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.YtbIetfSchedule;
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.ytbietfschedule.Enum1Enum;
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.ytbietfschedule.Enum2Enum;
@@ -95,6 +98,7 @@
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF11;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF12;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF13;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF14;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF2;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF3;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF4;
@@ -108,6 +112,8 @@
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL11;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL12;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL13;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL14;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL15;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL2;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL3;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL4;
@@ -116,6 +122,7 @@
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL7;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL8;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL9;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Cont1.LeafIdentifier.LEAF15;
import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.def1.def1union.Def1UnionEnum1.of;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
@@ -1369,6 +1376,10 @@
SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "11011");
validateDataNode(it.next(), "leaf13", ns,
SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "*");
+ validateDataNode(it.next(), "leaf14", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "physical");
+ validateDataNode(it.next(), "leaf15", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "physical");
validateDataNode(it.next(), "ll1", ns,
MULTI_INSTANCE_LEAF_VALUE_NODE, true, "leaf-list1");
validateDataNode(it.next(), "ll1", ns,
@@ -1411,6 +1422,13 @@
MULTI_INSTANCE_LEAF_VALUE_NODE, true, "110111");
validateDataNode(it.next(), "ll13", ns,
MULTI_INSTANCE_LEAF_VALUE_NODE, true, "*");
+ validateDataNode(it.next(), "ll14", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "physical");
+ validateDataNode(it.next(), "ll14", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "virtual");
+ validateDataNode(it.next(), "ll15", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "physical");
+
return it;
}
@@ -1439,6 +1457,10 @@
Def2 def21 = new Def2(bits1);
Def3 def3 = new Def3(false);
Def3 def31 = new Def3(true);
+ Def6 def6 = new Def6(Physical.class);
+ Def6 def61 = new Def6(Virtual.class);
+ Def7Union def7 = new Def7Union(Physical.class);
+ Def7 def71 = new Def7(def7);
Cont1 cont1 = new DefaultCont1();
cont1.leaf1("leaf1");
cont1.leaf2(def1);
@@ -1453,6 +1475,8 @@
cont1.leaf11(true);
cont1.leaf12(arr);
cont1.leaf13(def11);
+ cont1.leaf14(def6);
+ cont1.leaf15(def71);
cont1.addToLl1("leaf-list1");
cont1.addToLl1("leaf-list1-2");
cont1.addToLl2(def1);
@@ -1478,6 +1502,10 @@
cont1.addToLl12(arr);
cont1.addToLl12(arr1);
cont1.addToLl13(def11);
+ cont1.addToLl14(def6);
+ cont1.addToLl14(def61);
+ cont1.addToLl15(def71);
+
cont1.cont2(cont2);
data.addModelObject((ModelObject) cont1);
return data;
@@ -1508,6 +1536,10 @@
Def2 def21 = new Def2(bits1);
Def3 def3 = new Def3(false);
Def3 def31 = new Def3(true);
+ Def6 def6 = new Def6(Physical.class);
+ Def6 def61 = new Def6(Virtual.class);
+ Def7Union def7 = new Def7Union(Physical.class);
+ Def7 def71 = new Def7(def7);
augC.leaf1("leaf1");
augC.leaf2(def1);
augC.leaf3(arr);
@@ -1521,6 +1553,8 @@
augC.leaf11(true);
augC.leaf12(arr);
augC.leaf13(def11);
+ augC.leaf14(def6);
+ augC.leaf15(def71);
augC.addToLl1("leaf-list1");
augC.addToLl1("leaf-list1-2");
augC.addToLl2(def1);
@@ -1546,6 +1580,9 @@
augC.addToLl12(arr);
augC.addToLl12(arr1);
augC.addToLl13(def11);
+ augC.addToLl14(def6);
+ augC.addToLl14(def61);
+ augC.addToLl15(def71);
cont2.addAugmentation((InnerModelObject) augC);
return cont2;
}
@@ -1594,6 +1631,14 @@
data = addLeafModelObject(LEAF13, def11, data);
+ Def6 def6 = new Def6(Physical.class);
+ Def6 def61 = new Def6(Virtual.class);
+ data = addLeafModelObject(LEAF14, def6, data);
+
+ Def7Union def7 = new Def7Union(Physical.class);
+ Def7 def71 = new Def7(def7);
+ data = addLeafModelObject(LEAF15, def71, data);
+
List<Object> objs = new LinkedList<>();
objs.add("leaf-list1");
objs.add("leaf-list1-2");
@@ -1664,6 +1709,15 @@
objs = new LinkedList<>();
objs.add(def11);
data = addLeafListModelObject(LL13, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(def6);
+ objs.add(def61);
+ data = addLeafListModelObject(LL14, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(def71);
+ data = addLeafListModelObject(LL15, objs, data);
return data;
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YtbResourceIdTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YtbResourceIdTest.java
index c2ca334..302f5d4 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YtbResourceIdTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YtbResourceIdTest.java
@@ -359,7 +359,7 @@
Iterator<DataNode> it1 = inputDN.iterator();
validateDataNode(it1.next(), "stream", ns,
- SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "stream");
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "NETCONF");
validateDataNode(it1.next(), "replay-start-time", ns,
SINGLE_INSTANCE_LEAF_VALUE_NODE, true,
"2000-06-12T06:23:21");
@@ -481,6 +481,6 @@
SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "456");
validateDataNode(it.next(), "status", ns,
SINGLE_INSTANCE_LEAF_VALUE_NODE, true,
- "subscription-status");
+ "active");
}
}
diff --git a/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang b/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang
index 92818c1..4e06efa 100644
--- a/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang
+++ b/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang
@@ -47,6 +47,23 @@
}
}
+ typedef def6 {
+ type identityref {
+ base type;
+ }
+ }
+
+ typedef def7 {
+ type union {
+ type identityref {
+ base physical ;
+ }
+ type identityref {
+ base virtual;
+ }
+ }
+ }
+
identity type {
description "type value";
}
@@ -121,6 +138,14 @@
type def1;
}
+ leaf leaf14 {
+ type def6;
+ }
+
+ leaf leaf15 {
+ type def7;
+ }
+
container cont1 {
leaf leaf1 {
type string;
@@ -184,6 +209,14 @@
type def1;
}
+ leaf leaf14 {
+ type def6;
+ }
+
+ leaf leaf15 {
+ type def7;
+ }
+
leaf-list ll1 {
type string;
}
@@ -246,6 +279,13 @@
type def1;
}
+ leaf-list ll14 {
+ type def6;
+ }
+
+ leaf-list ll15 {
+ type def7;
+ }
container cont2 {
}
}
@@ -312,6 +352,13 @@
type def1;
}
+ leaf-list ll14 {
+ type def6;
+ }
+
+ leaf-list ll15 {
+ type def7;
+ }
augment "/cont1/cont2" {
leaf leaf1 {
type string;
@@ -375,6 +422,14 @@
type def1;
}
+ leaf leaf14 {
+ type def6;
+ }
+
+ leaf leaf15 {
+ type def7;
+ }
+
leaf-list ll1 {
type string;
}
@@ -436,5 +491,13 @@
leaf-list ll13 {
type def1;
}
+
+ leaf-list ll14 {
+ type def6;
+ }
+
+ leaf-list ll15 {
+ type def7;
+ }
}
}