[ONOS-7342] Fix for Inter Jar java file info access for augment and identity.
Change-Id: I4a6cb525ad2008053955c6a835aece499ea13f4c
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaServiceFragmentFiles.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaServiceFragmentFiles.java
index 49d812d..7705449 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaServiceFragmentFiles.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaServiceFragmentFiles.java
@@ -112,9 +112,6 @@
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
- // Commenting out call to add resolved augmented info as its not
- // required for service interface creation.
- //addResolvedAugmentedDataNodeImports(curNode);
JavaQualifiedTypeInfoTranslator typeInfo =
new JavaQualifiedTypeInfoTranslator();
typeInfo.setClassInfo(RPC_SERVICE);
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/AttributesJavaDataType.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/AttributesJavaDataType.java
index 3d1004c..3c5d8ab 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/AttributesJavaDataType.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/javamodel/AttributesJavaDataType.java
@@ -16,6 +16,7 @@
package org.onosproject.yang.compiler.translator.tojava.javamodel;
+import org.onosproject.yang.compiler.datamodel.ConflictResolveNode;
import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
import org.onosproject.yang.compiler.datamodel.YangEnumeration;
import org.onosproject.yang.compiler.datamodel.YangIdentity;
@@ -25,13 +26,11 @@
import org.onosproject.yang.compiler.datamodel.YangType;
import org.onosproject.yang.compiler.datamodel.YangTypeDef;
import org.onosproject.yang.compiler.datamodel.YangUnion;
-import org.onosproject.yang.compiler.datamodel.ConflictResolveNode;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.compiler.translator.exception.TranslatorException;
import org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yang.compiler.utils.UtilConstants;
import org.onosproject.yang.compiler.utils.io.YangToJavaNamingConflictUtil;
import java.util.Stack;
@@ -46,6 +45,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.BYTE;
import static org.onosproject.yang.compiler.utils.UtilConstants.BYTE_WRAPPER;
import static org.onosproject.yang.compiler.utils.UtilConstants.COLLECTION_IMPORTS;
+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.INTEGER_WRAPPER;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_LANG;
@@ -58,6 +58,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.SHORT_WRAPPER;
import static org.onosproject.yang.compiler.utils.UtilConstants.SQUARE_BRACKETS;
import static org.onosproject.yang.compiler.utils.UtilConstants.STRING_DATA_TYPE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.TYPEDEF;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
@@ -239,7 +240,7 @@
.getDataTypeExtendedInfo();
YangTypeDef typeDef = derivedInfo.getReferredTypeDef();
if (typeDef.isNameConflict()) {
- name = name + UtilConstants.TYPEDEF;
+ name = name + TYPEDEF;
}
return getCapitalCase(getCamelCase(name, pluginConfig));
}
@@ -426,12 +427,12 @@
/**
* Returns type package.
*
- * @param info YANG code generator info
- * @param conflictResolver object of YANG to java naming conflict util
+ * @param info YANG code generator info
+ * @param conf object of YANG to java naming conflict util
* @return type java package
*/
- private static String getTypePackage(JavaCodeGeneratorInfo info,
- YangToJavaNamingConflictUtil conflictResolver) {
+ public static String getTypePackage(JavaCodeGeneratorInfo info,
+ YangToJavaNamingConflictUtil conf) {
YangNode node = (YangNode) info;
// Check for referred schema type node for grouping scenario.
while (node.getReferredSchema() != null) {
@@ -439,7 +440,7 @@
}
info = (JavaCodeGeneratorInfo) node;
if (info.getJavaFileInfo().getPackage() == null) {
- return getPackageFromParent(node.getParent(), conflictResolver);
+ return getPackageFromParent(node.getParent(), conf);
}
return info.getJavaFileInfo().getPackage();
}
@@ -572,7 +573,7 @@
}
/**
- * Returns identity ref import class.
+ * Returns identity-ref import class name.
*
* @param type YANG type
* @param cnfg YANG to java naming conflict util
@@ -585,11 +586,23 @@
return OBJECT_STRING;
}
YangIdentity identity = ir.getReferredIdentity();
- String name = identity.getName();
- if (identity.isNameConflict()) {
- name = name + UtilConstants.IDENTITY;
+ return getCapitalCase(getIdJavaName(identity, cnfg));
+ }
+
+ /**
+ * Returns java name of the YANG identity.
+ *
+ * @param id YANG identity
+ * @param cnfg YANG to java naming conflict util
+ * @return identity java name
+ */
+ public static String getIdJavaName(YangIdentity id,
+ YangToJavaNamingConflictUtil cnfg) {
+ String name = id.getName();
+ if (id.isNameConflict()) {
+ name = name + IDENTITY;
}
- return getCapitalCase(getCamelCase(name, cnfg));
+ return getCamelCase(name, cnfg);
}
/**
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 b96a239..f2088aa 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
@@ -25,6 +25,7 @@
import org.onosproject.yang.compiler.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yang.compiler.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.YangToJavaNamingConflictUtil;
import java.io.File;
import java.io.IOException;
@@ -33,6 +34,8 @@
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.javamodel.AttributesJavaDataType.getIdJavaName;
+import static org.onosproject.yang.compiler.translator.tojava.javamodel.AttributesJavaDataType.getTypePackage;
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;
@@ -122,14 +125,14 @@
* Prepare the information for java code generation corresponding to YANG
* container info.
*
- * @param yangPlugin YANG plugin config
+ * @param plg YANG plugin config
* @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ public void generateCodeEntry(YangPluginConfig plg) throws TranslatorException {
try {
- updatePackageInfo(this, yangPlugin);
+ updatePackageInfo(this, plg);
JavaQualifiedTypeInfoTranslator basePkgInfo =
new JavaQualifiedTypeInfoTranslator();
JavaFileInfoTranslator itsInfo = getJavaFileInfo();
@@ -137,32 +140,44 @@
String className = getCapitalCase(name);
String path = itsInfo.getPackageFilePath();
createPackage(this);
+
List<String> imports = null;
boolean isQualified;
List<YangIdentity> idList = getExtendList();
- if (getBaseNode() != null && getBaseNode().getReferredIdentity() != null) {
- if (!(getBaseNode().getReferredIdentity() instanceof YangJavaIdentityTranslator)) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
- EMPTY_STRING));
+
+ if (getBaseNode() != null &&
+ getBaseNode().getReferredIdentity() != null) {
+ if (!(getBaseNode().getReferredIdentity()
+ instanceof YangJavaIdentityTranslator)) {
+ throw new TranslatorException(
+ getErrorMsg(FAIL_AT_ENTRY, this, EMPTY_STRING));
}
YangJavaIdentityTranslator base =
- (YangJavaIdentityTranslator) getBaseNode().getReferredIdentity();
+ (YangJavaIdentityTranslator) getBaseNode()
+ .getReferredIdentity();
JavaFileInfoTranslator info = base.getJavaFileInfo();
- String baseClassName = getCapitalCase(info.getJavaName());
- String basePkg = info.getPackage();
- basePkgInfo.setClassInfo(baseClassName);
- basePkgInfo.setPkgInfo(basePkg);
- isQualified = importData.addImportInfo(basePkgInfo, className,
- javaFileInfo.getPackage());
+ YangToJavaNamingConflictUtil conf = plg.getConflictResolver();
+
+ if (info.getPackage() == null || info.getJavaName() == null) {
+ info.setJavaName(getIdJavaName(base, conf));
+ info.setPackage(getTypePackage(base, conf));
+ }
+
+ basePkgInfo.setClassInfo(getCapitalCase(info.getJavaName()));
+ basePkgInfo.setPkgInfo(info.getPackage());
+ isQualified = importData.addImportInfo(
+ basePkgInfo, className, javaFileInfo.getPackage());
if (!isQualified) {
imports = importData.getImports(true);
}
}
+
imports = getImportOfDerId(idList, imports, className);
+ File file = getFileObject(path, className,
+ JAVA_FILE_EXTENSION, itsInfo);
+ initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS,
+ imports, this, className);
- File file = getFileObject(path, className, JAVA_FILE_EXTENSION, itsInfo);
-
- initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
//Add to string and from string method to class
addStringMethodsToClass(file, name, idList);
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
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 37a2eee..fbbfa34 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
@@ -16,7 +16,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.YangAugment;
@@ -39,7 +38,6 @@
import org.onosproject.yang.compiler.translator.tojava.JavaImportData;
import org.onosproject.yang.compiler.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yang.compiler.translator.tojava.TempJavaBeanFragmentFiles;
-import org.onosproject.yang.compiler.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yang.compiler.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yang.compiler.translator.tojava.TempJavaEventFragmentFiles;
import org.onosproject.yang.compiler.translator.tojava.TempJavaFragmentFiles;
@@ -126,7 +124,6 @@
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;
@@ -719,56 +716,6 @@
}
/**
- * Adds resolved augmented node imports to manager class.
- *
- * @param parent parent node
- */
- public static void addResolvedAugmentedDataNodeImports(YangNode parent) {
- List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
- if (targets.isEmpty()) {
- return;
- }
-
- YangNode node = targets.get(0).getResolvedNode();
- if (node instanceof InvalidOpTypeHolder) {
- return;
- }
-
- TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = (
- (JavaCodeGeneratorInfo) parent)
- .getTempJavaCodeFragmentFiles();
- YangNode augmentedNode;
- JavaQualifiedTypeInfoTranslator typeInfo;
- String curNodeName;
- JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent)
- .getJavaFileInfo();
- for (YangAtomicPath nodeId : targets) {
- augmentedNode = nodeId.getResolvedNode().getParent();
- curNodeName = getCurNodeName(augmentedNode, parentInfo
- .getPluginConfig());
-
- typeInfo =
- getQTypeInfoOfNode(
- augmentedNode, curNodeName + OP_PARAM,
- parentInfo.getPluginConfig());
-
- tempJavaCodeFragmentFiles.getServiceTempFiles()
- .getJavaImportData().addImportInfo(
- typeInfo, parentInfo.getJavaName(),
- parentInfo.getPackage());
- typeInfo =
- getQTypeInfoOfNode(
- augmentedNode, curNodeName, parentInfo
- .getPluginConfig());
-
- tempJavaCodeFragmentFiles.getServiceTempFiles()
- .getJavaImportData().addImportInfo(
- typeInfo, parentInfo.getJavaName(),
- parentInfo.getPackage());
- }
- }
-
- /**
* Returns qualified type info of augmented node.
*
* @param augmentedNode augmented node