[4266],[4267],[4268] Defect fix of special characters support for attributes
Change-Id: Ibf79749eb667627a592fcc7325021a32e73e11b4
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index 8895560..b88d5df 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -32,6 +32,8 @@
import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.sonatype.plexus.build.incremental.BuildContext;
@@ -87,6 +89,24 @@
private MavenProject project;
/**
+ * Replacement required for period special character in the identifier.
+ */
+ @Parameter(property = "replacementForPeriod")
+ private String replacementForPeriod;
+
+ /**
+ * Replacement required for underscore special character in the identifier.
+ */
+ @Parameter(property = "replacementForUnderscore")
+ private String replacementForUnderscore;
+
+ /**
+ * Replacement required for hyphen special character in the identifier.
+ */
+ @Parameter(property = "replacementForHyphen")
+ private String replacementForHyphen;
+
+ /**
* Build context.
*/
@Component
@@ -112,15 +132,21 @@
searchDir = getDirectory(baseDir, yangFilesDir);
codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
-
+ YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
+ conflictResolver.setReplacementForPeriod(replacementForPeriod);
+ conflictResolver.setReplacementForHyphen(replacementForHyphen);
+ conflictResolver.setReplacementForUnderscore(replacementForHyphen);
List<String> yangFiles = YangFileScanner.getYangFiles(searchDir);
+ YangPluginConfig yangPlugin = new YangPluginConfig();
+ yangPlugin.setCodeGenDir(codeGenDir);
+ yangPlugin.setConflictResolver(conflictResolver);
Iterator<String> yangFileIterator = yangFiles.iterator();
while (yangFileIterator.hasNext()) {
String yangFile = yangFileIterator.next();
try {
YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
setRootNode(yangNode);
- generateJavaCode(yangNode, codeGenDir);
+ generateJavaCode(yangNode, yangPlugin);
} catch (ParserException e) {
String logInfo = "Error in file: " + e.getFileName();
if (e.getLineNumber() != 0) {
@@ -181,7 +207,6 @@
*
* @param rootNode current root YANG node of data-model tree
*/
-
public void setRootNode(YangNode rootNode) {
this.rootNode = rootNode;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
index 63ebe07..f09b98f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
@@ -276,7 +276,7 @@
JavaAttributeInfo newAttr = new JavaAttributeInfo();
newAttr.setImportInfo(importInfo);
newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(curNode, importInfo));
- newAttr.setAttributeName(getCamelCase(attributeName));
+ newAttr.setAttributeName(getCamelCase(attributeName, null));
newAttr.setListAttr(isListAttribute);
newAttr.setImportInfo(importInfo);
newAttr.setAttributeType(attributeType);
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
index 3f660ca..4fd049d 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
@@ -18,6 +18,8 @@
import java.io.IOException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
+
/**
* Abstraction of an entity which provides Code generator functionalities.
*/
@@ -26,10 +28,10 @@
/**
* Traverse the schema of application and generate corresponding code.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException when fails to translate the data model tree
*/
- void generateCodeEntry(String codeGenDir) throws IOException;
+ void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException;
/**
* Traverse the schema of application and generate corresponding code.
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
index f0e700f..577a3ba 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
@@ -21,6 +21,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT;
@@ -65,11 +66,11 @@
* Generates Java code files corresponding to the YANG schema.
*
* @param rootNode root node of the data model tree
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException when fails to generate java code file the current
* node
*/
- public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException {
+ public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin) throws IOException {
YangNode curNode = rootNode;
TraversalType curTraversal = ROOT;
@@ -77,7 +78,7 @@
while (!(curNode == null)) {
if (curTraversal != PARENT) {
setCurNode(curNode);
- generateCodeEntry(curNode, codeGenDir);
+ generateCodeEntry(curNode, yangPlugin);
}
if (curTraversal != PARENT && curNode.getChild() != null) {
curTraversal = CHILD;
@@ -99,14 +100,13 @@
*
* @param curNode current data model node for which the code needs to be
* generated
- * @param codeGenDir the base directory where the code needs to be generated
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation exception
*/
- private static void generateCodeEntry(YangNode curNode,
- String codeGenDir) throws IOException {
+ private static void generateCodeEntry(YangNode curNode, YangPluginConfig yangPlugin) throws IOException {
if (curNode instanceof JavaCodeGenerator) {
- ((JavaCodeGenerator) curNode).generateCodeEntry(codeGenDir);
+ ((JavaCodeGenerator) curNode).generateCodeEntry(yangPlugin);
} else {
throw new TranslatorException(
"Generated data model node cannot be translated to target language code");
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
index f63a997..c815c95 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -923,7 +923,7 @@
/*
* TODO: check if this utility needs to be called or move to the caller
*/
- String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()));
+ String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()), null);
if (attr.isQualifiedName()) {
return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(),
attributeName, attr.isListAttr());
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
index 7cf50f3..0498cd7 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
@@ -22,6 +22,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
@@ -127,12 +128,12 @@
* Prepare the information for java code generation corresponding to YANG
* augment info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
- generateCodeOfNode(this, codeGenDir, false);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
+ generateCodeOfNode(this, yangPlugin, false);
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
index f9038f5..2bd538e 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
@@ -22,6 +22,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
@@ -126,12 +127,12 @@
* Prepare the information for java code generation corresponding to YANG
* case info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
- generateCodeOfNode(this, codeGenDir, false);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
+ generateCodeOfNode(this, yangPlugin, false);
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
index d550815..4ed9967 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
@@ -22,6 +22,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
@@ -126,12 +127,12 @@
* Prepare the information for java code generation corresponding to YANG
* case info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
- generateCodeOfNode(this, codeGenDir, false);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
+ generateCodeOfNode(this, yangPlugin, false);
// TODO:getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
index dabac6b..5099c85 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
@@ -22,6 +22,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
@@ -126,12 +127,12 @@
* Prepare the information for java code generation corresponding to YANG
* container info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
- generateCodeOfNode(this, codeGenDir, false);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
+ generateCodeOfNode(this, yangPlugin, false);
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
index 05d13be..f0dc4b0 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
@@ -22,6 +22,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
@@ -126,12 +127,12 @@
* Prepare the information for java code generation corresponding to YANG
* container info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
- generateCodeOfNode(this, codeGenDir, false);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
+ generateCodeOfNode(this, yangPlugin, false);
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
index f2f01d7..3fac592 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
@@ -23,6 +23,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
@@ -127,12 +128,12 @@
* Prepare the information for java code generation corresponding to YANG
* container info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
- generateCodeOfNode(this, codeGenDir, false);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
+ generateCodeOfNode(this, yangPlugin, false);
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
index 8e84716..f28cd1f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
@@ -22,6 +22,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
@@ -126,12 +127,12 @@
* Prepare the information for java code generation corresponding to YANG
* container info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
- generateCodeOfNode(this, codeGenDir, true);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
+ generateCodeOfNode(this, yangPlugin, true);
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
index 235ebc5..d6ba066 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
@@ -23,6 +23,7 @@
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
@@ -126,13 +127,13 @@
/**
* Generates java code for module.
*
- * @param baseCodeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException when fails to generate the source files
*/
@Override
- public void generateCodeEntry(String baseCodeGenDir) throws IOException {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate());
- YangJavaModelUtils.generateCodeOfRootNode(this, baseCodeGenDir, modulePkg);
+ YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, modulePkg);
}
@Override
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
index bfa9dc1..83e9f3b 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
@@ -27,6 +27,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
@@ -138,17 +139,17 @@
* Prepare the information for java code generation corresponding to YANG
* notification info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
- getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
+ getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
- getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
+ getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
String absolutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
index 7718f71..c205be3 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
@@ -23,6 +23,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
@@ -127,12 +128,12 @@
* Prepare the information for java code generation corresponding to YANG
* container info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
- generateCodeOfNode(this, codeGenDir, false);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
+ generateCodeOfNode(this, yangPlugin, false);
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
index b109789..5096784 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
/**
* Represents rpc information extended to support java code generation.
@@ -35,11 +36,11 @@
* Prepares the information for java code generation corresponding to YANG
* rpc info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
// TODO
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
index 177fad8..6dee3af 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
@@ -24,6 +24,7 @@
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
@@ -140,14 +141,14 @@
* Prepare the information for java code generation corresponding to YANG
* container info.
*
- * @param baseCodeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
*/
@Override
- public void generateCodeEntry(String baseCodeGenDir) throws IOException {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
getRevision().getRevDate());
- YangJavaModelUtils.generateCodeOfRootNode(this, baseCodeGenDir, subModulePkg);
+ YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, subModulePkg);
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
index 67ee326..8fc3865 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
@@ -26,6 +26,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
@@ -136,18 +137,18 @@
* Prepare the information for java code generation corresponding to YANG
* container info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
*/
@Override
- public void generateCodeEntry(String codeGenDir) throws IOException {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
- getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
+ getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
- getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
+ getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
index 32b96c2..27a97b2 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
@@ -22,6 +22,7 @@
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
+import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
@@ -104,16 +105,16 @@
* Prepare the information for java code generation corresponding to YANG
* container info.
*
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
*/
@Override
- public void generateCodeEntry(String codeGenDir) {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) {
- getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
+ getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
- getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
+ getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
//TODO:addCurNodeLeavesInfoToTempFiles(this);
//TODO:addCurNodeInfoInParentTempFile(this, false);
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
index 5a8594a..3dffc96 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataType.java
@@ -196,7 +196,7 @@
} else if (type.equals(INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(DERIVED)) {
- return getCaptialCase(getCamelCase(yangType.getDataTypeName()));
+ return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
}
} else {
if (type.equals(UINT64)) {
@@ -222,7 +222,7 @@
} else if (type.equals(INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(DERIVED)) {
- return getCaptialCase(getCamelCase(yangType.getDataTypeName()));
+ return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
}
}
return null;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
index cebad58..861ef4d 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -79,7 +79,7 @@
/*
* get the camel case name for java class / interface.
*/
- yangName = getCamelCase(yangName);
+ yangName = getCamelCase(yangName, null);
return generateClassDefinition(genFileTypes, yangName);
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
index c71f2d1..dd0b893 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.util.ArrayList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -30,12 +31,19 @@
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_DIGITS_WITH_SINGLE_LETTER;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SPECIAL_CHAR;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_HYPHEN;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_IDENTIFIER_SPECIAL_CHAR;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_SINGLE_LETTER;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_UNDERSCORE;
+import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_ALL_SPECIAL_CHAR;
import static org.onosproject.yangutils.utils.UtilConstants.REVISION_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
import static org.onosproject.yangutils.utils.UtilConstants.VERSION_PREFIX;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
/**
* Represents an utility Class for translating the name from YANG to java convention.
@@ -137,7 +145,7 @@
ArrayList<String> pkgArr = new ArrayList<String>();
nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING);
- String properNameSpace = nameSpace.replaceAll(REGEX_WITH_SPECIAL_CHAR, COLAN);
+ String properNameSpace = nameSpace.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
String[] nameSpaceArr = properNameSpace.split(COLAN);
for (String nameSpaceString : nameSpaceArr) {
@@ -191,7 +199,7 @@
for (String member : pkgArr) {
boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member);
if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) {
- member = UNDER_SCORE + member;
+ member = YANG_AUTO_PREFIX + member;
}
pkg = pkg + member;
if (i != size - 1) {
@@ -223,16 +231,121 @@
* Returns the YANG identifier name as java identifier.
*
* @param yangIdentifier identifier in YANG file
+ * @param conflictResolver object of YANG to java naming confilct util
* @return corresponding java identifier
*/
- public static String getCamelCase(String yangIdentifier) {
+ public static String getCamelCase(String yangIdentifier, YangToJavaNamingConflictUtil conflictResolver) {
- String[] strArray = yangIdentifier.split(HYPHEN);
- String camelCase = strArray[0];
- for (int i = 1; i < strArray.length; i++) {
- camelCase = camelCase + strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1);
+ if (conflictResolver != null) {
+ String replacementForHyphen = conflictResolver.getReplacementForHyphen();
+ String replacementForPeriod = conflictResolver.getReplacementForPeriod();
+ String replacementForUnderscore = conflictResolver.getReplacementForUnderscore();
+ if (replacementForPeriod != null) {
+ yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_PERIOD,
+ PERIOD + replacementForPeriod.toLowerCase() + PERIOD);
+ }
+ if (replacementForUnderscore != null) {
+ yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_UNDERSCORE,
+ UNDER_SCORE + replacementForUnderscore.toLowerCase() + UNDER_SCORE);
+ }
+ if (replacementForHyphen != null) {
+ yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_HYPHEN,
+ HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
+ }
}
- return camelCase;
+ yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLAN);
+ String[] strArray = yangIdentifier.split(COLAN);
+ if (strArray[0].isEmpty()) {
+ List<String> stringArrangement = new ArrayList<String>();
+ for (int i = 1; i < strArray.length; i++) {
+ stringArrangement.add(strArray[i]);
+ }
+ strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
+ }
+ return applyCamelCaseRule(strArray);
+ }
+
+ /**
+ * Applies the rule that a string does not end with a capitalized letter and capitalizes
+ * the letter next to a number in an array.
+ *
+ * @param stringArray containing strings for camel case separation
+ * @return camel cased string
+ */
+ public static String applyCamelCaseRule(String[] stringArray) {
+
+ String ruleChecker = stringArray[0];
+ int i;
+ if (ruleChecker.matches(REGEX_FOR_FIRST_DIGIT)) {
+ i = 0;
+ ruleChecker = EMPTY_STRING;
+ } else {
+ i = 1;
+ }
+ for (; i < stringArray.length; i++) {
+ if ((i + 1) == stringArray.length) {
+ if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER)
+ || stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) {
+ ruleChecker = ruleChecker + stringArray[i];
+ break;
+ }
+ }
+ if (stringArray[i].matches(REGEX_FOR_FIRST_DIGIT)) {
+ for (int j = 0; j < stringArray[i].length(); j++) {
+ char letterCheck = stringArray[i].charAt(j);
+ if (Character.isLetter(letterCheck)) {
+ stringArray[i] = stringArray[i].substring(0, j)
+ + stringArray[i].substring(j, j + 1).toUpperCase() + stringArray[i].substring(j + 1);
+ break;
+ }
+ }
+ ruleChecker = ruleChecker + stringArray[i];
+ } else {
+ ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1);
+ }
+ }
+ String ruleCheckerWithPrefix = addPrefix(ruleChecker);
+ return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix);
+ }
+
+ /**
+ * Adds prefix YANG auto prefix if the string begins with digit or is a java key word.
+ *
+ * @param camelCasePrefixer string for adding prefix
+ * @return prefixed camel case string
+ */
+ public static String addPrefix(String camelCasePrefixer) {
+
+ if (camelCasePrefixer.matches(REGEX_FOR_FIRST_DIGIT)) {
+ camelCasePrefixer = YANG_AUTO_PREFIX + camelCasePrefixer;
+ }
+ if (JAVA_KEY_WORDS.contains(camelCasePrefixer)) {
+ camelCasePrefixer = YANG_AUTO_PREFIX + camelCasePrefixer.substring(0, 1).toUpperCase()
+ + camelCasePrefixer.substring(1);
+ }
+ return camelCasePrefixer;
+ }
+
+ /**
+ * Restricts consecutive capital cased string as a rule in camel case.
+ *
+ * @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
+ * @return string without consecutive capital case
+ */
+ public static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
+
+ for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
+ if (k + 1 < consecCapitalCaseRemover.length()) {
+ if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k))) {
+ if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k + 1))) {
+ consecCapitalCaseRemover = consecCapitalCaseRemover.substring(0, k + 1)
+ + consecCapitalCaseRemover.substring(k + 1, k + 2).toLowerCase()
+ + consecCapitalCaseRemover.substring(k + 2);
+ }
+ }
+ }
+ }
+ return consecCapitalCaseRemover;
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index 6270cd2..90c122b 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -447,9 +447,9 @@
String attributeName = getSmallCase(attr.getAttributeName());
- String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName) + SPACE + EQUAL
+ String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL
+ SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
- + getCaptialCase(getCamelCase(attributeName)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ + getCaptialCase(getCamelCase(attributeName, null)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ NEW_LINE;
return constructor;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
index 6ba2f7d..f0fb9bc 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
@@ -43,34 +43,37 @@
* Updates YANG java file package information.
*
* @param javaCodeGeneratorInfo YANG java file info node
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
*/
- private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir)
+ private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
- .setJavaName(getCaptialCase(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName())));
+ .setJavaName(getCaptialCase(
+ getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), yangPlugin.getConflictResolver())));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
- javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
+ javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
}
/**
* Updates YANG java file package information for specified package.
*
* @param javaCodeGeneratorInfo YANG java file info node
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
*/
- private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir, String pkg)
+ private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
+ String pkg)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
- .setJavaName(getCaptialCase(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName())));
+ .setJavaName(getCaptialCase(
+ getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), yangPlugin.getConflictResolver())));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
- javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
+ javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
}
/**
@@ -96,7 +99,6 @@
*/
private static void updateLeafInfoInTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo)
throws IOException {
-
if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo);
@@ -127,17 +129,17 @@
* Process generate code entry of YANG node.
*
* @param javaCodeGeneratorInfo YANG java file info node
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @param isMultiInstance flag to indicate whether it's a list
* @throws IOException IO operations fails
*/
- public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir,
+ public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
boolean isMultiInstance) throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
- updatePackageInfo(javaCodeGeneratorInfo, codeGenDir);
- generateTempFiles(javaCodeGeneratorInfo, codeGenDir);
+ updatePackageInfo(javaCodeGeneratorInfo, yangPlugin);
+ generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
@@ -147,16 +149,16 @@
* Process generate code entry of root node.
*
* @param javaCodeGeneratorInfo YANG java file info node
- * @param codeGenDir code generation directory
+ * @param yangPlugin YANG plugin config
* @param rootPkg package of the root node
* @throws IOException IO operations fails
*/
- public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir,
+ public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
String rootPkg) throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
- updatePackageInfo(javaCodeGeneratorInfo, codeGenDir, rootPkg);
- generateTempFiles(javaCodeGeneratorInfo, codeGenDir);
+ updatePackageInfo(javaCodeGeneratorInfo, yangPlugin, rootPkg);
+ generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java
new file mode 100644
index 0000000..49be81c
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java
@@ -0,0 +1,75 @@
+/*
+ * 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.translator.tojava.utils;
+
+/**
+ * Representation of plugin configurations required for YANG utils.
+ */
+public final class YangPluginConfig {
+
+ /**
+ * Creates an object for YANG plugin config.
+ */
+ public YangPluginConfig() {
+ }
+
+ /**
+ * Contains the code generation directory.
+ */
+ private String codeGenDir;
+
+ /**
+ * Contains information of naming conflicts that can be resolved.
+ */
+ private YangToJavaNamingConflictUtil conflictResolver;
+
+ /**
+ * Sets the path of the java code where it has to be generated.
+ *
+ * @param codeGenDir path of the directory
+ */
+ public void setCodeGenDir(String codeGenDir) {
+ this.codeGenDir = codeGenDir;
+ }
+
+ /**
+ * Returns the code generation directory path.
+ *
+ * @return code generation directory
+ */
+ public String getCodeGenDir() {
+ return codeGenDir;
+ }
+
+ /**
+ * Sets the object.
+ *
+ * @param conflictResolver object of the class
+ */
+ public void setConflictResolver(YangToJavaNamingConflictUtil conflictResolver) {
+ this.conflictResolver = conflictResolver;
+ }
+
+ /**
+ * Returns the object.
+ *
+ * @return object of the class
+ */
+ public YangToJavaNamingConflictUtil getConflictResolver() {
+ return conflictResolver;
+ }
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangToJavaNamingConflictUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangToJavaNamingConflictUtil.java
new file mode 100644
index 0000000..bfb0d05
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangToJavaNamingConflictUtil.java
@@ -0,0 +1,98 @@
+/*
+ * 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.translator.tojava.utils;
+
+/**
+ * Representation of YANG to java naming conflict resolver util.
+ */
+public final class YangToJavaNamingConflictUtil {
+
+ /**
+ * Contains the replacement value for a period.
+ */
+ private static String replacementForPeriodInIdentifier;
+
+ /**
+ * Contains the replacement value for an underscore.
+ */
+ private static String replacementForUnderscoreInIdentifier;
+
+ /**
+ * Contains the replacement value for a hyphen.
+ */
+ private static String replacementForHyphenInIdentifier;
+
+ /**
+ * Creates an object for YANG to java naming conflict util.
+ */
+ public YangToJavaNamingConflictUtil() {
+ }
+
+ /**
+ * Sets the replacement value for a period.
+ *
+ * @param periodReplacement replacement value for period
+ */
+ public void setReplacementForPeriod(String periodReplacement) {
+ replacementForPeriodInIdentifier = periodReplacement;
+ }
+
+ /**
+ * Returns the replaced period value.
+ *
+ * @return replaced period
+ */
+ public String getReplacementForPeriod() {
+ return replacementForPeriodInIdentifier;
+ }
+
+ /**
+ * Sets the replacement value for a hyphen.
+ *
+ * @param hyphenReplacement replacement value for hyphen
+ */
+ public void setReplacementForHyphen(String hyphenReplacement) {
+ replacementForHyphenInIdentifier = hyphenReplacement;
+ }
+
+ /**
+ * Returns the replaced hyphen value.
+ *
+ * @return replaced hyphen
+ */
+ public String getReplacementForHyphen() {
+ return replacementForHyphenInIdentifier;
+ }
+
+ /**
+ * Sets the replacement value for an underscore.
+ *
+ * @param underscoreReplacement replacement value for underscore
+ */
+ public void setReplacementForUnderscore(String underscoreReplacement) {
+ replacementForUnderscoreInIdentifier = underscoreReplacement;
+ }
+
+ /**
+ * Returns the replaced underscore value.
+ *
+ * @return replaced underscore
+ */
+ public String getReplacementForUnderscore() {
+ return replacementForUnderscoreInIdentifier;
+ }
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 6a994c9..a0b05aa 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -408,6 +408,11 @@
public static final String REVISION_PREFIX = "rev";
/**
+ * Static attribute for YANG automatic prefix for identifiers with keywords and beginning with digits.
+ */
+ public static final String YANG_AUTO_PREFIX = "yangAutoPrefix";
+
+ /**
* Static attribute for YANG version perifx.
*/
public static final String VERSION_PREFIX = "v";
@@ -522,9 +527,29 @@
"synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while");
/**
- * Static attribute for regex for special char.
+ * Static attribute for regex for all the special characters.
*/
- public static final String REGEX_WITH_SPECIAL_CHAR = "[ : / - @ $ # ' * + , ; = ]+";
+ public static final String REGEX_WITH_ALL_SPECIAL_CHAR = "\\p{Punct}+";
+
+ /**
+ * Static attribute for regex for three special characters used in identifier.
+ */
+ public static final String REGEX_FOR_IDENTIFIER_SPECIAL_CHAR = "[. _ -]+";
+
+ /**
+ * Static attribute for regex for period.
+ */
+ public static final String REGEX_FOR_PERIOD = "[.]";
+
+ /**
+ * Static attribute for regex for underscore.
+ */
+ public static final String REGEX_FOR_UNDERSCORE = "[_]";
+
+ /**
+ * Static attribute for regex for hyphen.
+ */
+ public static final String REGEX_FOR_HYPHEN = "[-]";
/**
* Static attribute for regex for digits.
@@ -532,6 +557,16 @@
public static final String REGEX_FOR_FIRST_DIGIT = "\\d.*";
/**
+ * Static attribute for regex for single letter.
+ */
+ public static final String REGEX_FOR_SINGLE_LETTER = "[a-zA-Z]";
+
+ /**
+ * Static attribute for regex for digits with single letter.
+ */
+ public static final String REGEX_FOR_DIGITS_WITH_SINGLE_LETTER = "[0-9]+[a-zA-Z]";
+
+ /**
* Static attribute for class syntax.
*/
public static final String CLASS = "class";
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index c25c947..982cbc4 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -140,7 +140,7 @@
*/
public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
- name = JavaIdentifierSyntax.getSmallCase(JavaIdentifierSyntax.getCamelCase(name));
+ name = JavaIdentifierSyntax.getSmallCase(JavaIdentifierSyntax.getCamelCase(name, null));
String javaDoc = UtilConstants.EMPTY_STRING;
if (type.equals(JavaDocType.IMPL_CLASS)) {
javaDoc = generateForImplClass(name);
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
index ee42d28..a5eeb04 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
@@ -73,6 +73,6 @@
public void processWithoutRevision() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/RevisionAbsence.yang");
- assertThat(((YangModule) node).getRevision().getRevDate(), notNullValue());
+ assertThat(((YangModule) node).getRevision().getRevDate(), notNullValue());
}
}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java
index 6e87272..6a53cbe 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java
@@ -109,7 +109,7 @@
// Checks for the version value in data model tree.
assertThat(yangNode.getBelongsTo().getPrefix(), is("On1"));
//Checks the revision with current date is created for empty revision statement.
- assertThat(((YangSubModule) node).getRevision().getRevDate(), notNullValue());
+ assertThat(((YangSubModule) node).getRevision().getRevDate(), notNullValue());
}
/**
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
index fdf1f21..cf92284 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
@@ -49,10 +49,18 @@
private static final String VERSION_NUMBER = "v1";
private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
- private static final String VALID_NAME_SPACE1 = "_byte.test2._9test3";
- private static final String VALID_NAME_SPACE2 = "_const.test2._9test3";
+ private static final String VALID_NAME_SPACE1 = "yangautoprefixbyte.test2.yangautoprefix9test3";
+ private static final String VALID_NAME_SPACE2 = "yangautoprefixconst.test2.yangautoprefix9test3";
private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier";
private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier";
+ private static final String WITHOUT_CAMEL_CASE1 = ".-_try-._-.123";
+ private static final String WITH_CAMEL_CASE1 = "try123";
+ private static final String WITHOUT_CAMEL_CASE2 = "_try";
+ private static final String WITH_CAMEL_CASE2 = "yangAutoPrefixTry";
+ private static final String WITHOUT_CAMEL_CASE3 = "-1-123g-123ga-a";
+ private static final String WITH_CAMEL_CASE3 = "yangAutoPrefix1123G123Gaa";
+ private static final String WITHOUT_CAMEL_CASE4 = "a-b-c-d-e-f-g-h";
+ private static final String WITH_CAMEL_CASE4 = "aBcDeFgh";
private static final String WITHOUT_CAPITAL = "test_this";
private static final String WITH_CAPITAL = "Test_this";
private static final String WITH_SMALL = "test_this";
@@ -130,8 +138,16 @@
*/
@Test
public void getCamelCaseTest() {
- String camelCase = getCamelCase(WITHOUT_CAMEL_CASE);
+ String camelCase = getCamelCase(WITHOUT_CAMEL_CASE, null);
assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true));
+ String camelCase1 = getCamelCase(WITHOUT_CAMEL_CASE1, null);
+ assertThat(camelCase1.equals(WITH_CAMEL_CASE1), is(true));
+ String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE2, null);
+ assertThat(camelCase2.equals(WITH_CAMEL_CASE2), is(true));
+ String camelCase3 = getCamelCase(WITHOUT_CAMEL_CASE3, null);
+ assertThat(camelCase3.equals(WITH_CAMEL_CASE3), is(true));
+ String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, null);
+ assertThat(camelCase4.equals(WITH_CAMEL_CASE4), is(true));
}
/**