Generated interface extends augmentable interface
Change-Id: Ie145b658f3ebaa10586a574afe213b89afcef8e9
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/JavaImportData.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/JavaImportData.java
index 0eaf757..1dcc1cc 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/JavaImportData.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/JavaImportData.java
@@ -16,6 +16,7 @@
package org.onosproject.yang.compiler.translator.tojava;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -204,6 +205,25 @@
}
/**
+ * Removes the import info from importSet.
+ *
+ * @param importInfo import info to be removed
+ */
+ public void removeFromImportData(JavaQualifiedTypeInfoTranslator
+ importInfo) {
+ Iterator<JavaQualifiedTypeInfoTranslator> it = getImportSet().iterator();
+ while (it.hasNext()) {
+ JavaQualifiedTypeInfoTranslator info = it.next();
+ if (info.getClassInfo().contentEquals(importInfo.getClassInfo())
+ && info.getPkgInfo()
+ .contentEquals(importInfo.getPkgInfo())) {
+ importSet.remove(importInfo);
+ return;
+ }
+ }
+ }
+
+ /**
* Returns import for class.
*
* @param isForInterface if needs to check for interface
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 4fbb5bc..cf17ccc 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
@@ -17,6 +17,7 @@
import org.onosproject.yang.compiler.datamodel.RpcNotificationContainer;
import org.onosproject.yang.compiler.datamodel.YangAugment;
+import org.onosproject.yang.compiler.datamodel.YangAugmentableNode;
import org.onosproject.yang.compiler.datamodel.YangCase;
import org.onosproject.yang.compiler.datamodel.YangDataStructure;
import org.onosproject.yang.compiler.datamodel.YangLeaf;
@@ -96,6 +97,7 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorErrorType.MISSING_PARENT_NODE;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.getBeanFiles;
import static org.onosproject.yang.compiler.translator.tojava.utils.TranslatorUtils.getErrorMsg;
+import static org.onosproject.yang.compiler.utils.UtilConstants.AUGMENTABLE;
import static org.onosproject.yang.compiler.utils.UtilConstants.BIT_SET;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_CURLY_BRACKET;
@@ -1566,6 +1568,13 @@
addImportInfoOfNode(MODEL_OBJECT, MODEL_OBJECT_PKG, getGeneratedJavaClassName(),
getJavaFileInfo().getPackage(), false);
+ JavaQualifiedTypeInfoTranslator info = null;
+ if (curNode instanceof YangAugmentableNode) {
+ info = addImportInfoOfNode(AUGMENTABLE, MODEL_OBJECT_PKG,
+ getGeneratedJavaClassName(),
+ getJavaFileInfo().getPackage(), true);
+ }
+
if (curNode instanceof RpcNotificationContainer) {
addImportInfoOfNode(MAP, JAVA_UTIL_PKG,
getGeneratedJavaClassName(),
@@ -1593,12 +1602,28 @@
//Create interface file.
interfaceJavaFileHandle =
getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX));
+
+ // extend Augmentable interface
+ if (curNode instanceof YangAugmentableNode) {
+ getBeanFiles(curNode).getJavaExtendsListHolder()
+ .addToExtendsList(info, curNode, getBeanFiles(curNode));
+ }
+
interfaceJavaFileHandle =
generateInterfaceFile(interfaceJavaFileHandle, imports,
curNode, isAttributePresent);
insertDataIntoJavaFile(interfaceJavaFileHandle, CLOSE_CURLY_BRACKET);
formatFile(interfaceJavaFileHandle);
+
+ /*
+ * remove augmentable from extend list as it is not required for
+ * default class.
+ */
+ if (curNode instanceof YangAugmentableNode) {
+ getBeanFiles(curNode).getJavaExtendsListHolder()
+ .removeFromExtendsList(info, getBeanFiles(curNode));
+ }
}
//add imports for default class.
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaExtendsListHolder.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaExtendsListHolder.java
index ce22cda..f5841df 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaExtendsListHolder.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/JavaExtendsListHolder.java
@@ -114,4 +114,18 @@
private void addToExtendsList(JavaQualifiedTypeInfoTranslator classInfo) {
getExtendsList().add(classInfo);
}
+
+ /**
+ * Removes from extends list.
+ *
+ * @param info java file info
+ * @param javaFragmentFiles temp java fragment files
+ */
+ public void removeFromExtendsList(JavaQualifiedTypeInfoTranslator info,
+ TempJavaFragmentFiles javaFragmentFiles) {
+ JavaImportData importData = javaFragmentFiles.getJavaImportData();
+ importData.removeFromImportData(info);
+ getExtendedClassStore().remove(info, false);
+ getExtendsList().remove(info);
+ }
}
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
index 29ab285..c7ac66b 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
@@ -1936,6 +1936,7 @@
public static final String DEFAULT_MODEL_OBJECT_DATA =
"DefaultModelObjectData";
public static final String STRING_JOINER_CLASS = "StringJoiner";
+ public static final String AUGMENTABLE = "Augmentable";
// No instantiation.
private UtilConstants() {