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;
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 @@ public class YangUtilManager extends AbstractMojo {
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 @@ public class YangUtilManager extends AbstractMojo {
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 @@ public class YangUtilManager extends AbstractMojo {
*
* @param rootNode current root YANG node of data-model tree
*/
public void setRootNode(YangNode rootNode) {
this.rootNode = rootNode;
}
......
......@@ -276,7 +276,7 @@ public final class JavaAttributeInfo {
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);
......
......@@ -18,6 +18,8 @@ package org.onosproject.yangutils.translator.tojava;
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 @@ public interface JavaCodeGenerator {
/**
* 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.
......
......@@ -21,6 +21,7 @@ import java.io.IOException;
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 @@ public final class JavaCodeGeneratorUtil {
* 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 @@ public final class JavaCodeGeneratorUtil {
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 @@ public final class JavaCodeGeneratorUtil {
*
* @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");
......
......@@ -923,7 +923,7 @@ public class TempJavaCodeFragmentFiles {
/*
* 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());
......
......@@ -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.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 @@ public class YangJavaAugment extends YangAugment implements JavaCodeGeneratorInf
* 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);
}
/**
......
......@@ -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.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 @@ public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, Jav
* 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);
}
/**
......
......@@ -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.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 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo,
* 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);
}
......
......@@ -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.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 @@ public class YangJavaContainer extends YangContainer implements JavaCodeGenerato
* 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);
}
/**
......
......@@ -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.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 @@ public class YangJavaGrouping extends YangGrouping implements JavaCodeGeneratorI
* 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);
}
/**
......
......@@ -23,6 +23,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.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 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J
* 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);
}
/**
......
......@@ -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.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 @@ public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, Jav
* 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);
}
/**
......
......@@ -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.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 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo,
/**
* 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
......
......@@ -27,6 +27,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.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 @@ public class YangJavaNotification extends YangNotification
* 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(),
......
......@@ -23,6 +23,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.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 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo,
* 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);
}
/**
......
......@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
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 @@ public class YangJavaRpc extends YangRpc implements JavaCodeGenerator {
* 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
}
......
......@@ -24,6 +24,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.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 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato
* 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);
}
/**
......
......@@ -26,6 +26,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.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 @@ public class YangJavaTypeDef extends YangTypeDef
* 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());
......
......@@ -22,6 +22,7 @@ import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
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 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava
* 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);
}
......
......@@ -196,7 +196,7 @@ public final class AttributesJavaDataType {
} 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 @@ public final class AttributesJavaDataType {
} 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;
......
......@@ -79,7 +79,7 @@ public final class JavaCodeSnippetGen {
/*
* get the camel case name for java class / interface.
*/
yangName = getCamelCase(yangName);
yangName = getCamelCase(yangName, null);
return generateClassDefinition(genFileTypes, yangName);
}
......
......@@ -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.HYPHEN;
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 @@ public final class JavaIdentifierSyntax {
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 @@ public final class JavaIdentifierSyntax {
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 @@ public final class JavaIdentifierSyntax {
* 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) {
String[] strArray = yangIdentifier.split(HYPHEN);
String camelCase = strArray[0];
public static String getCamelCase(String yangIdentifier, YangToJavaNamingConflictUtil conflictResolver) {
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);
}
}
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++) {
camelCase = camelCase + strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1);
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 camelCase;
return consecCapitalCaseRemover;
}
/**
......
......@@ -447,9 +447,9 @@ public final class MethodsGenerator {
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;
......
......@@ -43,34 +43,37 @@ public final class YangJavaModelUtils {
* 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 @@ public final class YangJavaModelUtils {
*/
private static void updateLeafInfoInTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo)
throws IOException {
if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo);
......@@ -127,17 +129,17 @@ public final class YangJavaModelUtils {
* 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 @@ public final class YangJavaModelUtils {
* 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());
}
}
......
/*
* 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;
}
}
/*
* 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;
}
}
......@@ -408,6 +408,11 @@ public final class UtilConstants {
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 @@ public final class UtilConstants {
"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_ALL_SPECIAL_CHAR = "\\p{Punct}+";
/**
* Static attribute for regex for three special characters used in identifier.
*/
public static final String REGEX_WITH_SPECIAL_CHAR = "[ : / - @ $ # ' * + , ; = ]+";
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 final class UtilConstants {
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";
......
......@@ -140,7 +140,7 @@ public final class JavaDocGen {
*/
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);
......
......@@ -49,10 +49,18 @@ public final class JavaIdentifierSyntaxTest {
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 @@ public final class JavaIdentifierSyntaxTest {
*/
@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));
}
/**
......