YANG Translator optimization
Change-Id: Ie6a6b9d371a4fc5fd973cf56d6f3c7b44a3146ba
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
index 138b7d4..97b4758 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
@@ -16,8 +16,12 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import java.util.Set;
+import java.util.TreeSet;
+
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.utils.UtilConstants;
/**
@@ -25,6 +29,8 @@
*/
public final class AttributesJavaDataType {
+ private static Set<JavaQualifiedTypeInfo> importInfo = new TreeSet<>();
+
/**
* Default constructor.
*/
@@ -32,6 +38,24 @@
}
/**
+ * Returns import info.
+ *
+ * @return import info
+ */
+ public static Set<JavaQualifiedTypeInfo> getImportInfo() {
+ return importInfo;
+ }
+
+ /**
+ * Adds import info to the import info set.
+ *
+ * @param importData import info
+ */
+ public static void addImportInfo(JavaQualifiedTypeInfo importData) {
+ getImportInfo().add(importData);
+ }
+
+ /**
* Returns java type.
*
* @param yangType YANG type
@@ -134,7 +158,8 @@
} else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(YangDataTypes.DERIVED)) {
- //TODO:DERIVED
+ return JavaIdentifierSyntax
+ .getCaptialCase(JavaIdentifierSyntax.getCamelCase(yangType.getDataTypeName()));
}
} else {
if (type.equals(YangDataTypes.UINT64)) {
@@ -160,7 +185,8 @@
} else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(YangDataTypes.DERIVED)) {
- //TODO:DERIVED
+ return JavaIdentifierSyntax
+ .getCaptialCase(JavaIdentifierSyntax.getCamelCase(yangType.getDataTypeName()));
}
}
return null;
@@ -171,9 +197,10 @@
*
* @param yangType YANG type
* @param isListAttr if the attribute is of list type
+ * @param classInfo java import class info
* @return java import package
*/
- public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr) {
+ public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) {
YangDataTypes type = yangType.getDataType();
if (isListAttr) {
@@ -208,7 +235,11 @@
} else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(YangDataTypes.DERIVED)) {
- //TODO:DERIVED
+ for (JavaQualifiedTypeInfo imports : getImportInfo()) {
+ if (imports.getClassInfo().equals(classInfo)) {
+ return imports.getPkgInfo();
+ }
+ }
}
} else {
@@ -235,7 +266,11 @@
} else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(YangDataTypes.DERIVED)) {
- //TODO:DERIVED
+ for (JavaQualifiedTypeInfo imports : getImportInfo()) {
+ if (imports.getClassInfo().equals(classInfo)) {
+ return imports.getPkgInfo();
+ }
+ }
}
}
return null;