janani b
Committed by Gerrit Code Review

[4266],[4267],[4268] Defect fix of special characters support for attributes

Change-Id: Ibf79749eb667627a592fcc7325021a32e73e11b4
Showing 31 changed files with 475 additions and 95 deletions
...@@ -32,6 +32,8 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException; ...@@ -32,6 +32,8 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
32 import org.onosproject.yangutils.parser.YangUtilsParser; 32 import org.onosproject.yangutils.parser.YangUtilsParser;
33 import org.onosproject.yangutils.parser.exceptions.ParserException; 33 import org.onosproject.yangutils.parser.exceptions.ParserException;
34 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 34 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
35 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
36 +import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
35 import org.onosproject.yangutils.utils.io.impl.YangFileScanner; 37 import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
36 import org.sonatype.plexus.build.incremental.BuildContext; 38 import org.sonatype.plexus.build.incremental.BuildContext;
37 39
...@@ -87,6 +89,24 @@ public class YangUtilManager extends AbstractMojo { ...@@ -87,6 +89,24 @@ public class YangUtilManager extends AbstractMojo {
87 private MavenProject project; 89 private MavenProject project;
88 90
89 /** 91 /**
92 + * Replacement required for period special character in the identifier.
93 + */
94 + @Parameter(property = "replacementForPeriod")
95 + private String replacementForPeriod;
96 +
97 + /**
98 + * Replacement required for underscore special character in the identifier.
99 + */
100 + @Parameter(property = "replacementForUnderscore")
101 + private String replacementForUnderscore;
102 +
103 + /**
104 + * Replacement required for hyphen special character in the identifier.
105 + */
106 + @Parameter(property = "replacementForHyphen")
107 + private String replacementForHyphen;
108 +
109 + /**
90 * Build context. 110 * Build context.
91 */ 111 */
92 @Component 112 @Component
...@@ -112,15 +132,21 @@ public class YangUtilManager extends AbstractMojo { ...@@ -112,15 +132,21 @@ public class YangUtilManager extends AbstractMojo {
112 132
113 searchDir = getDirectory(baseDir, yangFilesDir); 133 searchDir = getDirectory(baseDir, yangFilesDir);
114 codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH; 134 codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
115 - 135 + YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
136 + conflictResolver.setReplacementForPeriod(replacementForPeriod);
137 + conflictResolver.setReplacementForHyphen(replacementForHyphen);
138 + conflictResolver.setReplacementForUnderscore(replacementForHyphen);
116 List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); 139 List<String> yangFiles = YangFileScanner.getYangFiles(searchDir);
140 + YangPluginConfig yangPlugin = new YangPluginConfig();
141 + yangPlugin.setCodeGenDir(codeGenDir);
142 + yangPlugin.setConflictResolver(conflictResolver);
117 Iterator<String> yangFileIterator = yangFiles.iterator(); 143 Iterator<String> yangFileIterator = yangFiles.iterator();
118 while (yangFileIterator.hasNext()) { 144 while (yangFileIterator.hasNext()) {
119 String yangFile = yangFileIterator.next(); 145 String yangFile = yangFileIterator.next();
120 try { 146 try {
121 YangNode yangNode = yangUtilsParser.getDataModel(yangFile); 147 YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
122 setRootNode(yangNode); 148 setRootNode(yangNode);
123 - generateJavaCode(yangNode, codeGenDir); 149 + generateJavaCode(yangNode, yangPlugin);
124 } catch (ParserException e) { 150 } catch (ParserException e) {
125 String logInfo = "Error in file: " + e.getFileName(); 151 String logInfo = "Error in file: " + e.getFileName();
126 if (e.getLineNumber() != 0) { 152 if (e.getLineNumber() != 0) {
...@@ -181,7 +207,6 @@ public class YangUtilManager extends AbstractMojo { ...@@ -181,7 +207,6 @@ public class YangUtilManager extends AbstractMojo {
181 * 207 *
182 * @param rootNode current root YANG node of data-model tree 208 * @param rootNode current root YANG node of data-model tree
183 */ 209 */
184 -
185 public void setRootNode(YangNode rootNode) { 210 public void setRootNode(YangNode rootNode) {
186 this.rootNode = rootNode; 211 this.rootNode = rootNode;
187 } 212 }
......
...@@ -276,7 +276,7 @@ public final class JavaAttributeInfo { ...@@ -276,7 +276,7 @@ public final class JavaAttributeInfo {
276 JavaAttributeInfo newAttr = new JavaAttributeInfo(); 276 JavaAttributeInfo newAttr = new JavaAttributeInfo();
277 newAttr.setImportInfo(importInfo); 277 newAttr.setImportInfo(importInfo);
278 newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(curNode, importInfo)); 278 newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(curNode, importInfo));
279 - newAttr.setAttributeName(getCamelCase(attributeName)); 279 + newAttr.setAttributeName(getCamelCase(attributeName, null));
280 newAttr.setListAttr(isListAttribute); 280 newAttr.setListAttr(isListAttribute);
281 newAttr.setImportInfo(importInfo); 281 newAttr.setImportInfo(importInfo);
282 newAttr.setAttributeType(attributeType); 282 newAttr.setAttributeType(attributeType);
......
...@@ -18,6 +18,8 @@ package org.onosproject.yangutils.translator.tojava; ...@@ -18,6 +18,8 @@ package org.onosproject.yangutils.translator.tojava;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 20
21 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
22 +
21 /** 23 /**
22 * Abstraction of an entity which provides Code generator functionalities. 24 * Abstraction of an entity which provides Code generator functionalities.
23 */ 25 */
...@@ -26,10 +28,10 @@ public interface JavaCodeGenerator { ...@@ -26,10 +28,10 @@ public interface JavaCodeGenerator {
26 /** 28 /**
27 * Traverse the schema of application and generate corresponding code. 29 * Traverse the schema of application and generate corresponding code.
28 * 30 *
29 - * @param codeGenDir code generation directory 31 + * @param yangPlugin YANG plugin config
30 * @throws IOException when fails to translate the data model tree 32 * @throws IOException when fails to translate the data model tree
31 */ 33 */
32 - void generateCodeEntry(String codeGenDir) throws IOException; 34 + void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException;
33 35
34 /** 36 /**
35 * Traverse the schema of application and generate corresponding code. 37 * Traverse the schema of application and generate corresponding code.
......
...@@ -21,6 +21,7 @@ import java.io.IOException; ...@@ -21,6 +21,7 @@ import java.io.IOException;
21 import org.onosproject.yangutils.datamodel.YangNode; 21 import org.onosproject.yangutils.datamodel.YangNode;
22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 import org.onosproject.yangutils.translator.exception.TranslatorException; 23 import org.onosproject.yangutils.translator.exception.TranslatorException;
24 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
24 25
25 import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD; 26 import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
26 import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT; 27 import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT;
...@@ -65,11 +66,11 @@ public final class JavaCodeGeneratorUtil { ...@@ -65,11 +66,11 @@ public final class JavaCodeGeneratorUtil {
65 * Generates Java code files corresponding to the YANG schema. 66 * Generates Java code files corresponding to the YANG schema.
66 * 67 *
67 * @param rootNode root node of the data model tree 68 * @param rootNode root node of the data model tree
68 - * @param codeGenDir code generation directory 69 + * @param yangPlugin YANG plugin config
69 * @throws IOException when fails to generate java code file the current 70 * @throws IOException when fails to generate java code file the current
70 * node 71 * node
71 */ 72 */
72 - public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException { 73 + public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin) throws IOException {
73 74
74 YangNode curNode = rootNode; 75 YangNode curNode = rootNode;
75 TraversalType curTraversal = ROOT; 76 TraversalType curTraversal = ROOT;
...@@ -77,7 +78,7 @@ public final class JavaCodeGeneratorUtil { ...@@ -77,7 +78,7 @@ public final class JavaCodeGeneratorUtil {
77 while (!(curNode == null)) { 78 while (!(curNode == null)) {
78 if (curTraversal != PARENT) { 79 if (curTraversal != PARENT) {
79 setCurNode(curNode); 80 setCurNode(curNode);
80 - generateCodeEntry(curNode, codeGenDir); 81 + generateCodeEntry(curNode, yangPlugin);
81 } 82 }
82 if (curTraversal != PARENT && curNode.getChild() != null) { 83 if (curTraversal != PARENT && curNode.getChild() != null) {
83 curTraversal = CHILD; 84 curTraversal = CHILD;
...@@ -99,14 +100,13 @@ public final class JavaCodeGeneratorUtil { ...@@ -99,14 +100,13 @@ public final class JavaCodeGeneratorUtil {
99 * 100 *
100 * @param curNode current data model node for which the code needs to be 101 * @param curNode current data model node for which the code needs to be
101 * generated 102 * generated
102 - * @param codeGenDir the base directory where the code needs to be generated 103 + * @param yangPlugin YANG plugin config
103 * @throws IOException IO operation exception 104 * @throws IOException IO operation exception
104 */ 105 */
105 - private static void generateCodeEntry(YangNode curNode, 106 + private static void generateCodeEntry(YangNode curNode, YangPluginConfig yangPlugin) throws IOException {
106 - String codeGenDir) throws IOException {
107 107
108 if (curNode instanceof JavaCodeGenerator) { 108 if (curNode instanceof JavaCodeGenerator) {
109 - ((JavaCodeGenerator) curNode).generateCodeEntry(codeGenDir); 109 + ((JavaCodeGenerator) curNode).generateCodeEntry(yangPlugin);
110 } else { 110 } else {
111 throw new TranslatorException( 111 throw new TranslatorException(
112 "Generated data model node cannot be translated to target language code"); 112 "Generated data model node cannot be translated to target language code");
......
...@@ -923,7 +923,7 @@ public class TempJavaCodeFragmentFiles { ...@@ -923,7 +923,7 @@ public class TempJavaCodeFragmentFiles {
923 /* 923 /*
924 * TODO: check if this utility needs to be called or move to the caller 924 * TODO: check if this utility needs to be called or move to the caller
925 */ 925 */
926 - String attributeName = getCamelCase(getSmallCase(attr.getAttributeName())); 926 + String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()), null);
927 if (attr.isQualifiedName()) { 927 if (attr.isQualifiedName()) {
928 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(), 928 return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(),
929 attributeName, attr.isListAttr()); 929 attributeName, attr.isListAttr());
......
...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 import org.onosproject.yangutils.translator.tojava.JavaImportData; 23 import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 26
26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
27 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 28 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
...@@ -127,12 +128,12 @@ public class YangJavaAugment extends YangAugment implements JavaCodeGeneratorInf ...@@ -127,12 +128,12 @@ public class YangJavaAugment extends YangAugment implements JavaCodeGeneratorInf
127 * Prepare the information for java code generation corresponding to YANG 128 * Prepare the information for java code generation corresponding to YANG
128 * augment info. 129 * augment info.
129 * 130 *
130 - * @param codeGenDir code generation directory 131 + * @param yangPlugin YANG plugin config
131 * @throws IOException IO operation fail 132 * @throws IOException IO operation fail
132 */ 133 */
133 @Override 134 @Override
134 - public void generateCodeEntry(String codeGenDir) throws IOException { 135 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
135 - generateCodeOfNode(this, codeGenDir, false); 136 + generateCodeOfNode(this, yangPlugin, false);
136 } 137 }
137 138
138 /** 139 /**
......
...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 import org.onosproject.yangutils.translator.tojava.JavaImportData; 23 import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 26
26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
27 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 28 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
...@@ -126,12 +127,12 @@ public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, Jav ...@@ -126,12 +127,12 @@ public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, Jav
126 * Prepare the information for java code generation corresponding to YANG 127 * Prepare the information for java code generation corresponding to YANG
127 * case info. 128 * case info.
128 * 129 *
129 - * @param codeGenDir code generation directory 130 + * @param yangPlugin YANG plugin config
130 * @throws IOException IO operation fail 131 * @throws IOException IO operation fail
131 */ 132 */
132 @Override 133 @Override
133 - public void generateCodeEntry(String codeGenDir) throws IOException { 134 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
134 - generateCodeOfNode(this, codeGenDir, false); 135 + generateCodeOfNode(this, yangPlugin, false);
135 } 136 }
136 137
137 /** 138 /**
......
...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 import org.onosproject.yangutils.translator.tojava.JavaImportData; 23 import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 26
26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
27 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 28 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
...@@ -126,12 +127,12 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, ...@@ -126,12 +127,12 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo,
126 * Prepare the information for java code generation corresponding to YANG 127 * Prepare the information for java code generation corresponding to YANG
127 * case info. 128 * case info.
128 * 129 *
129 - * @param codeGenDir code generation directory 130 + * @param yangPlugin YANG plugin config
130 * @throws IOException IO operation fail 131 * @throws IOException IO operation fail
131 */ 132 */
132 @Override 133 @Override
133 - public void generateCodeEntry(String codeGenDir) throws IOException { 134 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
134 - generateCodeOfNode(this, codeGenDir, false); 135 + generateCodeOfNode(this, yangPlugin, false);
135 // TODO:getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); 136 // TODO:getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
136 } 137 }
137 138
......
...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 import org.onosproject.yangutils.translator.tojava.JavaImportData; 23 import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 26
26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
27 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 28 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
...@@ -126,12 +127,12 @@ public class YangJavaContainer extends YangContainer implements JavaCodeGenerato ...@@ -126,12 +127,12 @@ public class YangJavaContainer extends YangContainer implements JavaCodeGenerato
126 * Prepare the information for java code generation corresponding to YANG 127 * Prepare the information for java code generation corresponding to YANG
127 * container info. 128 * container info.
128 * 129 *
129 - * @param codeGenDir code generation directory 130 + * @param yangPlugin YANG plugin config
130 * @throws IOException IO operation fail 131 * @throws IOException IO operation fail
131 */ 132 */
132 @Override 133 @Override
133 - public void generateCodeEntry(String codeGenDir) throws IOException { 134 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
134 - generateCodeOfNode(this, codeGenDir, false); 135 + generateCodeOfNode(this, yangPlugin, false);
135 } 136 }
136 137
137 /** 138 /**
......
...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 import org.onosproject.yangutils.translator.tojava.JavaImportData; 23 import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 26
26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
27 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 28 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
...@@ -126,12 +127,12 @@ public class YangJavaGrouping extends YangGrouping implements JavaCodeGeneratorI ...@@ -126,12 +127,12 @@ public class YangJavaGrouping extends YangGrouping implements JavaCodeGeneratorI
126 * Prepare the information for java code generation corresponding to YANG 127 * Prepare the information for java code generation corresponding to YANG
127 * container info. 128 * container info.
128 * 129 *
129 - * @param codeGenDir code generation directory 130 + * @param yangPlugin YANG plugin config
130 * @throws IOException IO operation fail 131 * @throws IOException IO operation fail
131 */ 132 */
132 @Override 133 @Override
133 - public void generateCodeEntry(String codeGenDir) throws IOException { 134 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
134 - generateCodeOfNode(this, codeGenDir, false); 135 + generateCodeOfNode(this, yangPlugin, false);
135 } 136 }
136 137
137 /** 138 /**
......
...@@ -23,6 +23,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -23,6 +23,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
23 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 23 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
24 import org.onosproject.yangutils.translator.tojava.JavaImportData; 24 import org.onosproject.yangutils.translator.tojava.JavaImportData;
25 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 25 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
26 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
26 27
27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
28 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 29 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
...@@ -127,12 +128,12 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J ...@@ -127,12 +128,12 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J
127 * Prepare the information for java code generation corresponding to YANG 128 * Prepare the information for java code generation corresponding to YANG
128 * container info. 129 * container info.
129 * 130 *
130 - * @param codeGenDir code generation directory 131 + * @param yangPlugin YANG plugin config
131 * @throws IOException IO operation fail 132 * @throws IOException IO operation fail
132 */ 133 */
133 @Override 134 @Override
134 - public void generateCodeEntry(String codeGenDir) throws IOException { 135 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
135 - generateCodeOfNode(this, codeGenDir, false); 136 + generateCodeOfNode(this, yangPlugin, false);
136 } 137 }
137 138
138 /** 139 /**
......
...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 import org.onosproject.yangutils.translator.tojava.JavaImportData; 23 import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 26
26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
27 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 28 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
...@@ -126,12 +127,12 @@ public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, Jav ...@@ -126,12 +127,12 @@ public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, Jav
126 * Prepare the information for java code generation corresponding to YANG 127 * Prepare the information for java code generation corresponding to YANG
127 * container info. 128 * container info.
128 * 129 *
129 - * @param codeGenDir code generation directory 130 + * @param yangPlugin YANG plugin config
130 * @throws IOException IO operation fail 131 * @throws IOException IO operation fail
131 */ 132 */
132 @Override 133 @Override
133 - public void generateCodeEntry(String codeGenDir) throws IOException { 134 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
134 - generateCodeOfNode(this, codeGenDir, true); 135 + generateCodeOfNode(this, yangPlugin, true);
135 } 136 }
136 137
137 /** 138 /**
......
...@@ -23,6 +23,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo; ...@@ -23,6 +23,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
23 import org.onosproject.yangutils.translator.tojava.JavaImportData; 23 import org.onosproject.yangutils.translator.tojava.JavaImportData;
24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 24 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
25 import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils; 25 import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
26 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
26 27
27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
28 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 29 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
...@@ -126,13 +127,13 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo, ...@@ -126,13 +127,13 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo,
126 /** 127 /**
127 * Generates java code for module. 128 * Generates java code for module.
128 * 129 *
129 - * @param baseCodeGenDir code generation directory 130 + * @param yangPlugin YANG plugin config
130 * @throws IOException when fails to generate the source files 131 * @throws IOException when fails to generate the source files
131 */ 132 */
132 @Override 133 @Override
133 - public void generateCodeEntry(String baseCodeGenDir) throws IOException { 134 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
134 String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate()); 135 String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate());
135 - YangJavaModelUtils.generateCodeOfRootNode(this, baseCodeGenDir, modulePkg); 136 + YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, modulePkg);
136 } 137 }
137 138
138 @Override 139 @Override
......
...@@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
27 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 27 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
28 import org.onosproject.yangutils.translator.tojava.JavaImportData; 28 import org.onosproject.yangutils.translator.tojava.JavaImportData;
29 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 29 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
30 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
30 31
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
32 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 33 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
...@@ -138,17 +139,17 @@ public class YangJavaNotification extends YangNotification ...@@ -138,17 +139,17 @@ public class YangJavaNotification extends YangNotification
138 * Prepare the information for java code generation corresponding to YANG 139 * Prepare the information for java code generation corresponding to YANG
139 * notification info. 140 * notification info.
140 * 141 *
141 - * @param codeGenDir code generation directory 142 + * @param yangPlugin YANG plugin config
142 * @throws IOException IO operation fail 143 * @throws IOException IO operation fail
143 */ 144 */
144 @Override 145 @Override
145 - public void generateCodeEntry(String codeGenDir) throws IOException { 146 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
146 147
147 - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); 148 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver())));
148 getJavaFileInfo().setPackage(getCurNodePackage(this)); 149 getJavaFileInfo().setPackage(getCurNodePackage(this));
149 getJavaFileInfo().setPackageFilePath( 150 getJavaFileInfo().setPackageFilePath(
150 getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); 151 getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
151 - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); 152 + getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
152 153
153 String absolutePath = getAbsolutePackagePath( 154 String absolutePath = getAbsolutePackagePath(
154 getJavaFileInfo().getBaseCodeGenPath(), 155 getJavaFileInfo().getBaseCodeGenPath(),
......
...@@ -23,6 +23,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -23,6 +23,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
23 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 23 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
24 import org.onosproject.yangutils.translator.tojava.JavaImportData; 24 import org.onosproject.yangutils.translator.tojava.JavaImportData;
25 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 25 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
26 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
26 27
27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
28 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; 29 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
...@@ -127,12 +128,12 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, ...@@ -127,12 +128,12 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo,
127 * Prepare the information for java code generation corresponding to YANG 128 * Prepare the information for java code generation corresponding to YANG
128 * container info. 129 * container info.
129 * 130 *
130 - * @param codeGenDir code generation directory 131 + * @param yangPlugin YANG plugin config
131 * @throws IOException IO operation fail 132 * @throws IOException IO operation fail
132 */ 133 */
133 @Override 134 @Override
134 - public void generateCodeEntry(String codeGenDir) throws IOException { 135 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
135 - generateCodeOfNode(this, codeGenDir, false); 136 + generateCodeOfNode(this, yangPlugin, false);
136 } 137 }
137 138
138 /** 139 /**
......
...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel; ...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
19 import java.io.IOException; 19 import java.io.IOException;
20 import org.onosproject.yangutils.datamodel.YangRpc; 20 import org.onosproject.yangutils.datamodel.YangRpc;
21 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; 21 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
22 23
23 /** 24 /**
24 * Represents rpc information extended to support java code generation. 25 * Represents rpc information extended to support java code generation.
...@@ -35,11 +36,11 @@ public class YangJavaRpc extends YangRpc implements JavaCodeGenerator { ...@@ -35,11 +36,11 @@ public class YangJavaRpc extends YangRpc implements JavaCodeGenerator {
35 * Prepares the information for java code generation corresponding to YANG 36 * Prepares the information for java code generation corresponding to YANG
36 * rpc info. 37 * rpc info.
37 * 38 *
38 - * @param codeGenDir code generation directory 39 + * @param yangPlugin YANG plugin config
39 * @throws IOException IO operation fail 40 * @throws IOException IO operation fail
40 */ 41 */
41 @Override 42 @Override
42 - public void generateCodeEntry(String codeGenDir) throws IOException { 43 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
43 // TODO 44 // TODO
44 } 45 }
45 46
......
...@@ -24,6 +24,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo; ...@@ -24,6 +24,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
24 import org.onosproject.yangutils.translator.tojava.JavaImportData; 24 import org.onosproject.yangutils.translator.tojava.JavaImportData;
25 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 25 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
26 import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils; 26 import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
27 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
27 28
28 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
29 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; 30 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
...@@ -140,14 +141,14 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato ...@@ -140,14 +141,14 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato
140 * Prepare the information for java code generation corresponding to YANG 141 * Prepare the information for java code generation corresponding to YANG
141 * container info. 142 * container info.
142 * 143 *
143 - * @param baseCodeGenDir code generation directory 144 + * @param yangPlugin YANG plugin config
144 * @throws IOException IO operation fail 145 * @throws IOException IO operation fail
145 */ 146 */
146 @Override 147 @Override
147 - public void generateCodeEntry(String baseCodeGenDir) throws IOException { 148 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
148 String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()), 149 String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
149 getRevision().getRevDate()); 150 getRevision().getRevDate());
150 - YangJavaModelUtils.generateCodeOfRootNode(this, baseCodeGenDir, subModulePkg); 151 + YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, subModulePkg);
151 } 152 }
152 153
153 /** 154 /**
......
...@@ -26,6 +26,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; ...@@ -26,6 +26,7 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
26 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 26 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
27 import org.onosproject.yangutils.translator.tojava.JavaImportData; 27 import org.onosproject.yangutils.translator.tojava.JavaImportData;
28 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; 28 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
29 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
29 30
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
31 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 32 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
...@@ -136,18 +137,18 @@ public class YangJavaTypeDef extends YangTypeDef ...@@ -136,18 +137,18 @@ public class YangJavaTypeDef extends YangTypeDef
136 * Prepare the information for java code generation corresponding to YANG 137 * Prepare the information for java code generation corresponding to YANG
137 * container info. 138 * container info.
138 * 139 *
139 - * @param codeGenDir code generation directory 140 + * @param yangPlugin YANG plugin config
140 * @throws IOException IO operations fails 141 * @throws IOException IO operations fails
141 */ 142 */
142 @Override 143 @Override
143 - public void generateCodeEntry(String codeGenDir) throws IOException { 144 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
144 145
145 - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); 146 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver())));
146 getJavaFileInfo().setPackage(getCurNodePackage(this)); 147 getJavaFileInfo().setPackage(getCurNodePackage(this));
147 148
148 getJavaFileInfo().setPackageFilePath( 149 getJavaFileInfo().setPackageFilePath(
149 getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); 150 getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
150 - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); 151 + getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
151 String absloutePath = getAbsolutePackagePath( 152 String absloutePath = getAbsolutePackagePath(
152 getJavaFileInfo().getBaseCodeGenPath(), 153 getJavaFileInfo().getBaseCodeGenPath(),
153 getJavaFileInfo().getPackageFilePath()); 154 getJavaFileInfo().getPackageFilePath());
......
...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.HasJavaImportData; ...@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
22 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; 22 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
23 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 23 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
24 import org.onosproject.yangutils.translator.tojava.JavaImportData; 24 import org.onosproject.yangutils.translator.tojava.JavaImportData;
25 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 26
26 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
27 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 28 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
...@@ -104,16 +105,16 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava ...@@ -104,16 +105,16 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava
104 * Prepare the information for java code generation corresponding to YANG 105 * Prepare the information for java code generation corresponding to YANG
105 * container info. 106 * container info.
106 * 107 *
107 - * @param codeGenDir code generation directory 108 + * @param yangPlugin YANG plugin config
108 */ 109 */
109 @Override 110 @Override
110 - public void generateCodeEntry(String codeGenDir) { 111 + public void generateCodeEntry(YangPluginConfig yangPlugin) {
111 112
112 - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName()))); 113 + getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver())));
113 getJavaFileInfo().setPackage(getCurNodePackage(this)); 114 getJavaFileInfo().setPackage(getCurNodePackage(this));
114 getJavaFileInfo().setPackageFilePath( 115 getJavaFileInfo().setPackageFilePath(
115 getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage())); 116 getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
116 - getJavaFileInfo().setBaseCodeGenPath(codeGenDir); 117 + getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
117 //TODO:addCurNodeLeavesInfoToTempFiles(this); 118 //TODO:addCurNodeLeavesInfoToTempFiles(this);
118 //TODO:addCurNodeInfoInParentTempFile(this, false); 119 //TODO:addCurNodeInfoInParentTempFile(this, false);
119 } 120 }
......
...@@ -196,7 +196,7 @@ public final class AttributesJavaDataType { ...@@ -196,7 +196,7 @@ public final class AttributesJavaDataType {
196 } else if (type.equals(INSTANCE_IDENTIFIER)) { 196 } else if (type.equals(INSTANCE_IDENTIFIER)) {
197 //TODO:INSTANCE_IDENTIFIER 197 //TODO:INSTANCE_IDENTIFIER
198 } else if (type.equals(DERIVED)) { 198 } else if (type.equals(DERIVED)) {
199 - return getCaptialCase(getCamelCase(yangType.getDataTypeName())); 199 + return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
200 } 200 }
201 } else { 201 } else {
202 if (type.equals(UINT64)) { 202 if (type.equals(UINT64)) {
...@@ -222,7 +222,7 @@ public final class AttributesJavaDataType { ...@@ -222,7 +222,7 @@ public final class AttributesJavaDataType {
222 } else if (type.equals(INSTANCE_IDENTIFIER)) { 222 } else if (type.equals(INSTANCE_IDENTIFIER)) {
223 //TODO:INSTANCE_IDENTIFIER 223 //TODO:INSTANCE_IDENTIFIER
224 } else if (type.equals(DERIVED)) { 224 } else if (type.equals(DERIVED)) {
225 - return getCaptialCase(getCamelCase(yangType.getDataTypeName())); 225 + return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
226 } 226 }
227 } 227 }
228 return null; 228 return null;
......
...@@ -79,7 +79,7 @@ public final class JavaCodeSnippetGen { ...@@ -79,7 +79,7 @@ public final class JavaCodeSnippetGen {
79 /* 79 /*
80 * get the camel case name for java class / interface. 80 * get the camel case name for java class / interface.
81 */ 81 */
82 - yangName = getCamelCase(yangName); 82 + yangName = getCamelCase(yangName, null);
83 return generateClassDefinition(genFileTypes, yangName); 83 return generateClassDefinition(genFileTypes, yangName);
84 } 84 }
85 85
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 import java.util.ArrayList; 19 import java.util.ArrayList;
20 +import java.util.List;
20 21
21 import org.onosproject.yangutils.datamodel.YangNode; 22 import org.onosproject.yangutils.datamodel.YangNode;
22 import org.onosproject.yangutils.translator.exception.TranslatorException; 23 import org.onosproject.yangutils.translator.exception.TranslatorException;
...@@ -30,12 +31,19 @@ import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN; ...@@ -30,12 +31,19 @@ import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
30 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS; 31 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
31 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 32 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
32 import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; 33 import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
34 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_DIGITS_WITH_SINGLE_LETTER;
33 import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT; 35 import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
34 -import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SPECIAL_CHAR; 36 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_HYPHEN;
37 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_IDENTIFIER_SPECIAL_CHAR;
38 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_PERIOD;
39 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_SINGLE_LETTER;
40 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_UNDERSCORE;
41 +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_ALL_SPECIAL_CHAR;
35 import static org.onosproject.yangutils.utils.UtilConstants.REVISION_PREFIX; 42 import static org.onosproject.yangutils.utils.UtilConstants.REVISION_PREFIX;
36 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 43 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
37 import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE; 44 import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
38 import static org.onosproject.yangutils.utils.UtilConstants.VERSION_PREFIX; 45 import static org.onosproject.yangutils.utils.UtilConstants.VERSION_PREFIX;
46 +import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
39 47
40 /** 48 /**
41 * Represents an utility Class for translating the name from YANG to java convention. 49 * Represents an utility Class for translating the name from YANG to java convention.
...@@ -137,7 +145,7 @@ public final class JavaIdentifierSyntax { ...@@ -137,7 +145,7 @@ public final class JavaIdentifierSyntax {
137 145
138 ArrayList<String> pkgArr = new ArrayList<String>(); 146 ArrayList<String> pkgArr = new ArrayList<String>();
139 nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING); 147 nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING);
140 - String properNameSpace = nameSpace.replaceAll(REGEX_WITH_SPECIAL_CHAR, COLAN); 148 + String properNameSpace = nameSpace.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
141 String[] nameSpaceArr = properNameSpace.split(COLAN); 149 String[] nameSpaceArr = properNameSpace.split(COLAN);
142 150
143 for (String nameSpaceString : nameSpaceArr) { 151 for (String nameSpaceString : nameSpaceArr) {
...@@ -191,7 +199,7 @@ public final class JavaIdentifierSyntax { ...@@ -191,7 +199,7 @@ public final class JavaIdentifierSyntax {
191 for (String member : pkgArr) { 199 for (String member : pkgArr) {
192 boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member); 200 boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member);
193 if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) { 201 if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) {
194 - member = UNDER_SCORE + member; 202 + member = YANG_AUTO_PREFIX + member;
195 } 203 }
196 pkg = pkg + member; 204 pkg = pkg + member;
197 if (i != size - 1) { 205 if (i != size - 1) {
...@@ -223,16 +231,121 @@ public final class JavaIdentifierSyntax { ...@@ -223,16 +231,121 @@ public final class JavaIdentifierSyntax {
223 * Returns the YANG identifier name as java identifier. 231 * Returns the YANG identifier name as java identifier.
224 * 232 *
225 * @param yangIdentifier identifier in YANG file 233 * @param yangIdentifier identifier in YANG file
234 + * @param conflictResolver object of YANG to java naming confilct util
226 * @return corresponding java identifier 235 * @return corresponding java identifier
227 */ 236 */
228 - public static String getCamelCase(String yangIdentifier) { 237 + public static String getCamelCase(String yangIdentifier, YangToJavaNamingConflictUtil conflictResolver) {
229 - 238 +
230 - String[] strArray = yangIdentifier.split(HYPHEN); 239 + if (conflictResolver != null) {
231 - String camelCase = strArray[0]; 240 + String replacementForHyphen = conflictResolver.getReplacementForHyphen();
241 + String replacementForPeriod = conflictResolver.getReplacementForPeriod();
242 + String replacementForUnderscore = conflictResolver.getReplacementForUnderscore();
243 + if (replacementForPeriod != null) {
244 + yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_PERIOD,
245 + PERIOD + replacementForPeriod.toLowerCase() + PERIOD);
246 + }
247 + if (replacementForUnderscore != null) {
248 + yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_UNDERSCORE,
249 + UNDER_SCORE + replacementForUnderscore.toLowerCase() + UNDER_SCORE);
250 + }
251 + if (replacementForHyphen != null) {
252 + yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_HYPHEN,
253 + HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
254 + }
255 + }
256 + yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLAN);
257 + String[] strArray = yangIdentifier.split(COLAN);
258 + if (strArray[0].isEmpty()) {
259 + List<String> stringArrangement = new ArrayList<String>();
232 for (int i = 1; i < strArray.length; i++) { 260 for (int i = 1; i < strArray.length; i++) {
233 - camelCase = camelCase + strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1); 261 + stringArrangement.add(strArray[i]);
262 + }
263 + strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
264 + }
265 + return applyCamelCaseRule(strArray);
266 + }
267 +
268 + /**
269 + * Applies the rule that a string does not end with a capitalized letter and capitalizes
270 + * the letter next to a number in an array.
271 + *
272 + * @param stringArray containing strings for camel case separation
273 + * @return camel cased string
274 + */
275 + public static String applyCamelCaseRule(String[] stringArray) {
276 +
277 + String ruleChecker = stringArray[0];
278 + int i;
279 + if (ruleChecker.matches(REGEX_FOR_FIRST_DIGIT)) {
280 + i = 0;
281 + ruleChecker = EMPTY_STRING;
282 + } else {
283 + i = 1;
284 + }
285 + for (; i < stringArray.length; i++) {
286 + if ((i + 1) == stringArray.length) {
287 + if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER)
288 + || stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) {
289 + ruleChecker = ruleChecker + stringArray[i];
290 + break;
291 + }
292 + }
293 + if (stringArray[i].matches(REGEX_FOR_FIRST_DIGIT)) {
294 + for (int j = 0; j < stringArray[i].length(); j++) {
295 + char letterCheck = stringArray[i].charAt(j);
296 + if (Character.isLetter(letterCheck)) {
297 + stringArray[i] = stringArray[i].substring(0, j)
298 + + stringArray[i].substring(j, j + 1).toUpperCase() + stringArray[i].substring(j + 1);
299 + break;
300 + }
301 + }
302 + ruleChecker = ruleChecker + stringArray[i];
303 + } else {
304 + ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1);
305 + }
306 + }
307 + String ruleCheckerWithPrefix = addPrefix(ruleChecker);
308 + return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix);
309 + }
310 +
311 + /**
312 + * Adds prefix YANG auto prefix if the string begins with digit or is a java key word.
313 + *
314 + * @param camelCasePrefixer string for adding prefix
315 + * @return prefixed camel case string
316 + */
317 + public static String addPrefix(String camelCasePrefixer) {
318 +
319 + if (camelCasePrefixer.matches(REGEX_FOR_FIRST_DIGIT)) {
320 + camelCasePrefixer = YANG_AUTO_PREFIX + camelCasePrefixer;
321 + }
322 + if (JAVA_KEY_WORDS.contains(camelCasePrefixer)) {
323 + camelCasePrefixer = YANG_AUTO_PREFIX + camelCasePrefixer.substring(0, 1).toUpperCase()
324 + + camelCasePrefixer.substring(1);
325 + }
326 + return camelCasePrefixer;
327 + }
328 +
329 + /**
330 + * Restricts consecutive capital cased string as a rule in camel case.
331 + *
332 + * @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
333 + * @return string without consecutive capital case
334 + */
335 + public static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
336 +
337 + for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
338 + if (k + 1 < consecCapitalCaseRemover.length()) {
339 + if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k))) {
340 + if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k + 1))) {
341 + consecCapitalCaseRemover = consecCapitalCaseRemover.substring(0, k + 1)
342 + + consecCapitalCaseRemover.substring(k + 1, k + 2).toLowerCase()
343 + + consecCapitalCaseRemover.substring(k + 2);
344 + }
345 + }
346 + }
234 } 347 }
235 - return camelCase; 348 + return consecCapitalCaseRemover;
236 } 349 }
237 350
238 /** 351 /**
......
...@@ -447,9 +447,9 @@ public final class MethodsGenerator { ...@@ -447,9 +447,9 @@ public final class MethodsGenerator {
447 447
448 String attributeName = getSmallCase(attr.getAttributeName()); 448 String attributeName = getSmallCase(attr.getAttributeName());
449 449
450 - String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName) + SPACE + EQUAL 450 + String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL
451 + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX 451 + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
452 - + getCaptialCase(getCamelCase(attributeName)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN 452 + + getCaptialCase(getCamelCase(attributeName, null)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
453 + NEW_LINE; 453 + NEW_LINE;
454 454
455 return constructor; 455 return constructor;
......
...@@ -43,34 +43,37 @@ public final class YangJavaModelUtils { ...@@ -43,34 +43,37 @@ public final class YangJavaModelUtils {
43 * Updates YANG java file package information. 43 * Updates YANG java file package information.
44 * 44 *
45 * @param javaCodeGeneratorInfo YANG java file info node 45 * @param javaCodeGeneratorInfo YANG java file info node
46 - * @param codeGenDir code generation directory 46 + * @param yangPlugin YANG plugin config
47 * @throws IOException IO operations fails 47 * @throws IOException IO operations fails
48 */ 48 */
49 - private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir) 49 + private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin)
50 throws IOException { 50 throws IOException {
51 javaCodeGeneratorInfo.getJavaFileInfo() 51 javaCodeGeneratorInfo.getJavaFileInfo()
52 - .setJavaName(getCaptialCase(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName()))); 52 + .setJavaName(getCaptialCase(
53 + getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), yangPlugin.getConflictResolver())));
53 javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo)); 54 javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
54 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( 55 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
55 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); 56 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
56 - javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(codeGenDir); 57 + javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
57 } 58 }
58 59
59 /** 60 /**
60 * Updates YANG java file package information for specified package. 61 * Updates YANG java file package information for specified package.
61 * 62 *
62 * @param javaCodeGeneratorInfo YANG java file info node 63 * @param javaCodeGeneratorInfo YANG java file info node
63 - * @param codeGenDir code generation directory 64 + * @param yangPlugin YANG plugin config
64 * @throws IOException IO operations fails 65 * @throws IOException IO operations fails
65 */ 66 */
66 - private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir, String pkg) 67 + private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
68 + String pkg)
67 throws IOException { 69 throws IOException {
68 javaCodeGeneratorInfo.getJavaFileInfo() 70 javaCodeGeneratorInfo.getJavaFileInfo()
69 - .setJavaName(getCaptialCase(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName()))); 71 + .setJavaName(getCaptialCase(
72 + getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), yangPlugin.getConflictResolver())));
70 javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg); 73 javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
71 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath( 74 javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
72 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage())); 75 getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
73 - javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(codeGenDir); 76 + javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
74 } 77 }
75 78
76 /** 79 /**
...@@ -96,7 +99,6 @@ public final class YangJavaModelUtils { ...@@ -96,7 +99,6 @@ public final class YangJavaModelUtils {
96 */ 99 */
97 private static void updateLeafInfoInTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo) 100 private static void updateLeafInfoInTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo)
98 throws IOException { 101 throws IOException {
99 -
100 if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { 102 if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
101 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() 103 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
102 .addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo); 104 .addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo);
...@@ -127,17 +129,17 @@ public final class YangJavaModelUtils { ...@@ -127,17 +129,17 @@ public final class YangJavaModelUtils {
127 * Process generate code entry of YANG node. 129 * Process generate code entry of YANG node.
128 * 130 *
129 * @param javaCodeGeneratorInfo YANG java file info node 131 * @param javaCodeGeneratorInfo YANG java file info node
130 - * @param codeGenDir code generation directory 132 + * @param yangPlugin YANG plugin config
131 * @param isMultiInstance flag to indicate whether it's a list 133 * @param isMultiInstance flag to indicate whether it's a list
132 * @throws IOException IO operations fails 134 * @throws IOException IO operations fails
133 */ 135 */
134 - public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir, 136 + public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
135 boolean isMultiInstance) throws IOException { 137 boolean isMultiInstance) throws IOException {
136 if (!(javaCodeGeneratorInfo instanceof YangNode)) { 138 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
137 // TODO:throw exception 139 // TODO:throw exception
138 } 140 }
139 - updatePackageInfo(javaCodeGeneratorInfo, codeGenDir); 141 + updatePackageInfo(javaCodeGeneratorInfo, yangPlugin);
140 - generateTempFiles(javaCodeGeneratorInfo, codeGenDir); 142 + generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
141 143
142 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() 144 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
143 .addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); 145 .addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
...@@ -147,16 +149,16 @@ public final class YangJavaModelUtils { ...@@ -147,16 +149,16 @@ public final class YangJavaModelUtils {
147 * Process generate code entry of root node. 149 * Process generate code entry of root node.
148 * 150 *
149 * @param javaCodeGeneratorInfo YANG java file info node 151 * @param javaCodeGeneratorInfo YANG java file info node
150 - * @param codeGenDir code generation directory 152 + * @param yangPlugin YANG plugin config
151 * @param rootPkg package of the root node 153 * @param rootPkg package of the root node
152 * @throws IOException IO operations fails 154 * @throws IOException IO operations fails
153 */ 155 */
154 - public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir, 156 + public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
155 String rootPkg) throws IOException { 157 String rootPkg) throws IOException {
156 if (!(javaCodeGeneratorInfo instanceof YangNode)) { 158 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
157 // TODO:throw exception 159 // TODO:throw exception
158 } 160 }
159 - updatePackageInfo(javaCodeGeneratorInfo, codeGenDir, rootPkg); 161 + updatePackageInfo(javaCodeGeneratorInfo, yangPlugin, rootPkg);
160 - generateTempFiles(javaCodeGeneratorInfo, codeGenDir); 162 + generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
161 } 163 }
162 } 164 }
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.translator.tojava.utils;
18 +
19 +/**
20 + * Representation of plugin configurations required for YANG utils.
21 + */
22 +public final class YangPluginConfig {
23 +
24 + /**
25 + * Creates an object for YANG plugin config.
26 + */
27 + public YangPluginConfig() {
28 + }
29 +
30 + /**
31 + * Contains the code generation directory.
32 + */
33 + private String codeGenDir;
34 +
35 + /**
36 + * Contains information of naming conflicts that can be resolved.
37 + */
38 + private YangToJavaNamingConflictUtil conflictResolver;
39 +
40 + /**
41 + * Sets the path of the java code where it has to be generated.
42 + *
43 + * @param codeGenDir path of the directory
44 + */
45 + public void setCodeGenDir(String codeGenDir) {
46 + this.codeGenDir = codeGenDir;
47 + }
48 +
49 + /**
50 + * Returns the code generation directory path.
51 + *
52 + * @return code generation directory
53 + */
54 + public String getCodeGenDir() {
55 + return codeGenDir;
56 + }
57 +
58 + /**
59 + * Sets the object.
60 + *
61 + * @param conflictResolver object of the class
62 + */
63 + public void setConflictResolver(YangToJavaNamingConflictUtil conflictResolver) {
64 + this.conflictResolver = conflictResolver;
65 + }
66 +
67 + /**
68 + * Returns the object.
69 + *
70 + * @return object of the class
71 + */
72 + public YangToJavaNamingConflictUtil getConflictResolver() {
73 + return conflictResolver;
74 + }
75 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.translator.tojava.utils;
18 +
19 +/**
20 + * Representation of YANG to java naming conflict resolver util.
21 + */
22 +public final class YangToJavaNamingConflictUtil {
23 +
24 + /**
25 + * Contains the replacement value for a period.
26 + */
27 + private static String replacementForPeriodInIdentifier;
28 +
29 + /**
30 + * Contains the replacement value for an underscore.
31 + */
32 + private static String replacementForUnderscoreInIdentifier;
33 +
34 + /**
35 + * Contains the replacement value for a hyphen.
36 + */
37 + private static String replacementForHyphenInIdentifier;
38 +
39 + /**
40 + * Creates an object for YANG to java naming conflict util.
41 + */
42 + public YangToJavaNamingConflictUtil() {
43 + }
44 +
45 + /**
46 + * Sets the replacement value for a period.
47 + *
48 + * @param periodReplacement replacement value for period
49 + */
50 + public void setReplacementForPeriod(String periodReplacement) {
51 + replacementForPeriodInIdentifier = periodReplacement;
52 + }
53 +
54 + /**
55 + * Returns the replaced period value.
56 + *
57 + * @return replaced period
58 + */
59 + public String getReplacementForPeriod() {
60 + return replacementForPeriodInIdentifier;
61 + }
62 +
63 + /**
64 + * Sets the replacement value for a hyphen.
65 + *
66 + * @param hyphenReplacement replacement value for hyphen
67 + */
68 + public void setReplacementForHyphen(String hyphenReplacement) {
69 + replacementForHyphenInIdentifier = hyphenReplacement;
70 + }
71 +
72 + /**
73 + * Returns the replaced hyphen value.
74 + *
75 + * @return replaced hyphen
76 + */
77 + public String getReplacementForHyphen() {
78 + return replacementForHyphenInIdentifier;
79 + }
80 +
81 + /**
82 + * Sets the replacement value for an underscore.
83 + *
84 + * @param underscoreReplacement replacement value for underscore
85 + */
86 + public void setReplacementForUnderscore(String underscoreReplacement) {
87 + replacementForUnderscoreInIdentifier = underscoreReplacement;
88 + }
89 +
90 + /**
91 + * Returns the replaced underscore value.
92 + *
93 + * @return replaced underscore
94 + */
95 + public String getReplacementForUnderscore() {
96 + return replacementForUnderscoreInIdentifier;
97 + }
98 +}
...@@ -408,6 +408,11 @@ public final class UtilConstants { ...@@ -408,6 +408,11 @@ public final class UtilConstants {
408 public static final String REVISION_PREFIX = "rev"; 408 public static final String REVISION_PREFIX = "rev";
409 409
410 /** 410 /**
411 + * Static attribute for YANG automatic prefix for identifiers with keywords and beginning with digits.
412 + */
413 + public static final String YANG_AUTO_PREFIX = "yangAutoPrefix";
414 +
415 + /**
411 * Static attribute for YANG version perifx. 416 * Static attribute for YANG version perifx.
412 */ 417 */
413 public static final String VERSION_PREFIX = "v"; 418 public static final String VERSION_PREFIX = "v";
...@@ -522,9 +527,29 @@ public final class UtilConstants { ...@@ -522,9 +527,29 @@ public final class UtilConstants {
522 "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"); 527 "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while");
523 528
524 /** 529 /**
525 - * Static attribute for regex for special char. 530 + * Static attribute for regex for all the special characters.
531 + */
532 + public static final String REGEX_WITH_ALL_SPECIAL_CHAR = "\\p{Punct}+";
533 +
534 + /**
535 + * Static attribute for regex for three special characters used in identifier.
526 */ 536 */
527 - public static final String REGEX_WITH_SPECIAL_CHAR = "[ : / - @ $ # ' * + , ; = ]+"; 537 + public static final String REGEX_FOR_IDENTIFIER_SPECIAL_CHAR = "[. _ -]+";
538 +
539 + /**
540 + * Static attribute for regex for period.
541 + */
542 + public static final String REGEX_FOR_PERIOD = "[.]";
543 +
544 + /**
545 + * Static attribute for regex for underscore.
546 + */
547 + public static final String REGEX_FOR_UNDERSCORE = "[_]";
548 +
549 + /**
550 + * Static attribute for regex for hyphen.
551 + */
552 + public static final String REGEX_FOR_HYPHEN = "[-]";
528 553
529 /** 554 /**
530 * Static attribute for regex for digits. 555 * Static attribute for regex for digits.
...@@ -532,6 +557,16 @@ public final class UtilConstants { ...@@ -532,6 +557,16 @@ public final class UtilConstants {
532 public static final String REGEX_FOR_FIRST_DIGIT = "\\d.*"; 557 public static final String REGEX_FOR_FIRST_DIGIT = "\\d.*";
533 558
534 /** 559 /**
560 + * Static attribute for regex for single letter.
561 + */
562 + public static final String REGEX_FOR_SINGLE_LETTER = "[a-zA-Z]";
563 +
564 + /**
565 + * Static attribute for regex for digits with single letter.
566 + */
567 + public static final String REGEX_FOR_DIGITS_WITH_SINGLE_LETTER = "[0-9]+[a-zA-Z]";
568 +
569 + /**
535 * Static attribute for class syntax. 570 * Static attribute for class syntax.
536 */ 571 */
537 public static final String CLASS = "class"; 572 public static final String CLASS = "class";
......
...@@ -140,7 +140,7 @@ public final class JavaDocGen { ...@@ -140,7 +140,7 @@ public final class JavaDocGen {
140 */ 140 */
141 public static String getJavaDoc(JavaDocType type, String name, boolean isList) { 141 public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
142 142
143 - name = JavaIdentifierSyntax.getSmallCase(JavaIdentifierSyntax.getCamelCase(name)); 143 + name = JavaIdentifierSyntax.getSmallCase(JavaIdentifierSyntax.getCamelCase(name, null));
144 String javaDoc = UtilConstants.EMPTY_STRING; 144 String javaDoc = UtilConstants.EMPTY_STRING;
145 if (type.equals(JavaDocType.IMPL_CLASS)) { 145 if (type.equals(JavaDocType.IMPL_CLASS)) {
146 javaDoc = generateForImplClass(name); 146 javaDoc = generateForImplClass(name);
......
...@@ -49,10 +49,18 @@ public final class JavaIdentifierSyntaxTest { ...@@ -49,10 +49,18 @@ public final class JavaIdentifierSyntaxTest {
49 private static final String VERSION_NUMBER = "v1"; 49 private static final String VERSION_NUMBER = "v1";
50 private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3"; 50 private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
51 private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3"; 51 private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
52 - private static final String VALID_NAME_SPACE1 = "_byte.test2._9test3"; 52 + private static final String VALID_NAME_SPACE1 = "yangautoprefixbyte.test2.yangautoprefix9test3";
53 - private static final String VALID_NAME_SPACE2 = "_const.test2._9test3"; 53 + private static final String VALID_NAME_SPACE2 = "yangautoprefixconst.test2.yangautoprefix9test3";
54 private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier"; 54 private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier";
55 private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier"; 55 private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier";
56 + private static final String WITHOUT_CAMEL_CASE1 = ".-_try-._-.123";
57 + private static final String WITH_CAMEL_CASE1 = "try123";
58 + private static final String WITHOUT_CAMEL_CASE2 = "_try";
59 + private static final String WITH_CAMEL_CASE2 = "yangAutoPrefixTry";
60 + private static final String WITHOUT_CAMEL_CASE3 = "-1-123g-123ga-a";
61 + private static final String WITH_CAMEL_CASE3 = "yangAutoPrefix1123G123Gaa";
62 + private static final String WITHOUT_CAMEL_CASE4 = "a-b-c-d-e-f-g-h";
63 + private static final String WITH_CAMEL_CASE4 = "aBcDeFgh";
56 private static final String WITHOUT_CAPITAL = "test_this"; 64 private static final String WITHOUT_CAPITAL = "test_this";
57 private static final String WITH_CAPITAL = "Test_this"; 65 private static final String WITH_CAPITAL = "Test_this";
58 private static final String WITH_SMALL = "test_this"; 66 private static final String WITH_SMALL = "test_this";
...@@ -130,8 +138,16 @@ public final class JavaIdentifierSyntaxTest { ...@@ -130,8 +138,16 @@ public final class JavaIdentifierSyntaxTest {
130 */ 138 */
131 @Test 139 @Test
132 public void getCamelCaseTest() { 140 public void getCamelCaseTest() {
133 - String camelCase = getCamelCase(WITHOUT_CAMEL_CASE); 141 + String camelCase = getCamelCase(WITHOUT_CAMEL_CASE, null);
134 assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true)); 142 assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true));
143 + String camelCase1 = getCamelCase(WITHOUT_CAMEL_CASE1, null);
144 + assertThat(camelCase1.equals(WITH_CAMEL_CASE1), is(true));
145 + String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE2, null);
146 + assertThat(camelCase2.equals(WITH_CAMEL_CASE2), is(true));
147 + String camelCase3 = getCamelCase(WITHOUT_CAMEL_CASE3, null);
148 + assertThat(camelCase3.equals(WITH_CAMEL_CASE3), is(true));
149 + String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, null);
150 + assertThat(camelCase4.equals(WITH_CAMEL_CASE4), is(true));
135 } 151 }
136 152
137 /** 153 /**
......