janani b
Committed by Gerrit Code Review

[ONOS-4412]Defect fix for uppercase presence in identifier

Change-Id: Iee7f6a47230652833799e0303606d786d55f5dd8
......@@ -21,7 +21,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
/**
* Represents a utility which provides valid name for generated java file for augment node.
......@@ -110,9 +110,9 @@ public final class AugmentJavaFileNameGenUtil {
*/
private static String createName(YangNodeIdentifier nodeId, boolean isPrefix) {
if (isPrefix) {
return AUGMENTED + getCaptialCase(nodeId.getPrefix()) + getCaptialCase(nodeId.getName());
return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + getCapitalCase(nodeId.getName());
} else {
return AUGMENTED + getCaptialCase(nodeId.getName());
return AUGMENTED + getCapitalCase(nodeId.getName());
}
}
......
......@@ -57,10 +57,9 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
......@@ -382,7 +381,7 @@ public class TempJavaFragmentFiles {
* @return mapped Java class name
*/
String getGeneratedJavaClassName() {
return getJavaFileInfo().getJavaName();
return getCapitalCase(getJavaFileInfo().getJavaName());
}
/**
......@@ -865,8 +864,9 @@ public class TempJavaFragmentFiles {
appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
getGeneratedJavaFiles()) + NEW_LINE);
} else {
appendToFile(getGetterImplTempFileHandle(), getJavaDoc(GETTER_METHOD, attr.getAttributeName(), false)
+ getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
appendToFile(getGetterImplTempFileHandle(),
getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false)
+ getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
}
}
......@@ -1034,7 +1034,7 @@ public class TempJavaFragmentFiles {
/*
* TODO: check if this utility needs to be called or move to the caller
*/
String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()), null);
String attributeName = getCamelCase(attr.getAttributeName(), null);
if (attr.isQualifiedName()) {
return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
attr.getImportInfo().getClassInfo(),
......@@ -1104,7 +1104,7 @@ public class TempJavaFragmentFiles {
* generated java files or qualified access
*/
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode,
curNodeName);
getCapitalCase(curNodeName));
if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
throw new TranslatorException("Parent node does not have file info");
}
......@@ -1156,7 +1156,7 @@ public class TempJavaFragmentFiles {
throw new TranslatorException("missing java file information to get the package details "
+ "of attribute corresponding to child node");
}
caseImportInfo.setClassInfo(getCaptialCase(getCamelCase(parent.getName(), null)));
caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(), null)));
caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo);
......@@ -1298,7 +1298,7 @@ public class TempJavaFragmentFiles {
* @return java class name
*/
String getJavaClassName(String suffix) {
return getCaptialCase(getJavaFileInfo().getJavaName()) + suffix;
return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix;
}
/**
......
......@@ -28,6 +28,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
......@@ -235,10 +236,10 @@ public class TempJavaServiceFragmentFiles
String rpcInput = EMPTY_STRING;
String rpcOutput = VOID;
if (javaAttributeInfoOfInput != null) {
rpcInput = javaAttributeInfoOfInput.getAttributeName();
rpcInput = getCapitalCase(javaAttributeInfoOfInput.getAttributeName());
}
if (javaAttributeInfoOfOutput != null) {
rpcOutput = javaAttributeInfoOfOutput.getAttributeName();
rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName());
}
appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, RPC_INPUT_VAR_NAME, rpcOutput)
+ getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
......
......@@ -37,6 +37,7 @@ import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
......@@ -157,7 +158,7 @@ public class YangJavaRpc
* generated java files or qualified access
*/
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(currentNode,
childNodeName);
getCapitalCase(childNodeName));
if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
throw new TranslatorException("Parent node does not have file info");
}
......
......@@ -24,6 +24,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
......@@ -85,7 +86,7 @@ public class YangJavaUnion
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("Missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
+ getCapitalCase(getJavaFileInfo().getJavaName()));
}
return tempFileHandle;
}
......
......@@ -31,7 +31,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
......@@ -189,7 +189,7 @@ public final class AttributesJavaDataType {
case BOOLEAN:
return BOOLEAN_WRAPPER;
case ENUMERATION:
return getCaptialCase(
return getCapitalCase(
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null));
case BITS:
//TODO:BITS
......@@ -206,12 +206,12 @@ public final class AttributesJavaDataType {
case EMPTY:
return BOOLEAN_WRAPPER;
case UNION:
return getCaptialCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
null));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
case DERIVED:
return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null));
default:
throw new TranslatorException("given data type is not supported.");
}
......@@ -225,7 +225,7 @@ public final class AttributesJavaDataType {
case STRING:
return STRING_DATA_TYPE;
case ENUMERATION:
return getCaptialCase(
return getCapitalCase(
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null));
case BITS:
//TODO:BITS
......@@ -243,13 +243,13 @@ public final class AttributesJavaDataType {
//TODO:EMPTY
break;
case UNION:
return getCaptialCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
null));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
break;
case DERIVED:
return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null));
default:
return null;
}
......
......@@ -57,8 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetG
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
......@@ -171,7 +170,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName());
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path);
......@@ -209,7 +208,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName());
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path);
......@@ -268,7 +267,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName());
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, BUILDER_CLASS_MASK, imports, path);
......@@ -343,7 +342,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName());
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path);
......@@ -407,7 +406,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName());
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path);
......@@ -517,7 +516,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName());
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path);
......@@ -621,7 +620,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName());
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path);
......@@ -725,10 +724,10 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName());
String className = javaFileInfo.getJavaName();
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_ENUM_CLASS, null, path);
initiateJavaFileGeneration(file, getCapitalCase(className), GENERATE_ENUM_CLASS, null, path);
/**
* Add attribute strings.
*/
......@@ -739,7 +738,7 @@ public final class JavaFileGenerator {
.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()), COMMA), NEW_LINE)
+ SEMI_COLAN + NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
throw new IOException("No data found in temporary java code fragment files for " + getCapitalCase(className)
+ " while enum class file generation");
}
......@@ -747,13 +746,13 @@ public final class JavaFileGenerator {
* Add an
* attribute to get the enum's values.
*/
insertDataIntoJavaFile(file, getEnumsValueAttribute(className));
insertDataIntoJavaFile(file, getEnumsValueAttribute(getCapitalCase(className)));
/**
* Add a constructor for enum.
*/
insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, getSmallCase(className), false)
+ getEnumsConstrcutor(className) + NEW_LINE);
insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false)
+ getEnumsConstrcutor(getCapitalCase(className)) + NEW_LINE);
TempJavaEnumerationFragmentFiles enumFragFiles =
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
......@@ -767,18 +766,18 @@ public final class JavaFileGenerator {
/**
* Add a getter method for enum.
*/
insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, getSmallCase(className), false)
+ getGetter(INT, getSmallCase(className), GENERATE_ENUM_CLASS) + NEW_LINE);
insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false)
+ getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
try {
insertDataIntoJavaFile(file, getFromStringMethodSignature(className)
insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className))
+ getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getEnumerationTempFiles())
+ getFromStringMethodClose());
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while enum class file generation");
throw new IOException("No data found in temporary java code fragment files for " +
getCapitalCase(className) + " while enum class file generation");
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
......@@ -802,7 +801,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING;
String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path);
......@@ -859,7 +858,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName()) + EVENT_STRING;
String className = getCapitalCase(javaFileInfo.getJavaName()) + EVENT_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_EVENT_CLASS, imports, path);
......@@ -913,7 +912,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName()) + EVENT_LISTENER_STRING;
String className = getCapitalCase(javaFileInfo.getJavaName()) + EVENT_LISTENER_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_EVENT_LISTENER_INTERFACE, imports, path);
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
......@@ -39,6 +40,10 @@ 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.REGEX_WITH_DIGITS;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_UPPERCASE;
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;
......@@ -231,7 +236,7 @@ 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
* @param conflictResolver object of YANG to java naming conflict util
* @return corresponding java identifier
*/
public static String getCamelCase(String yangIdentifier, YangToJavaNamingConflictUtil conflictResolver) {
......@@ -262,7 +267,57 @@ public final class JavaIdentifierSyntax {
}
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
return applyCamelCaseRule(strArray);
return upperCaseConflictResolver(strArray);
}
/**
* Resolves the conflict when input has uppercase.
*
* @param stringArray containing strings for uppercase conflict resolver
* @return camel cased string
*/
private static String upperCaseConflictResolver(String[] stringArray) {
for (int l = 0; l < stringArray.length; l++) {
String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE);
for (int m = 0; m < upperCaseSplitArray.length; m++) {
if (upperCaseSplitArray[m].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
int check = m;
while (check + 1 < upperCaseSplitArray.length) {
if (upperCaseSplitArray[check + 1].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
check = check + 1;
} else if (upperCaseSplitArray[check + 1]
.matches(REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES)) {
upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
break;
} else {
break;
}
}
}
}
StringBuilder strBuilder = new StringBuilder();
for (String element : upperCaseSplitArray) {
strBuilder.append(element);
}
stringArray[l] = strBuilder.toString();
}
List<String> result = new ArrayList<String>();
for (String element : stringArray) {
String[] capitalCaseSplitArray = element.split(REGEX_WITH_UPPERCASE);
for (String letter : capitalCaseSplitArray) {
String[] arrayForAddition = letter.split(REGEX_WITH_DIGITS);
List<String> list = Arrays.asList(arrayForAddition);
for (String str : list) {
if (str != null && !str.isEmpty()) {
result.add(str);
}
}
}
}
stringArray = result.toArray(new String[result.size()]);
return applyCamelCaseRule(stringArray);
}
/**
......@@ -270,11 +325,11 @@ public final class JavaIdentifierSyntax {
* the letter next to a number in an array.
*
* @param stringArray containing strings for camel case separation
* @return camel cased string
* @return camel case rule checked string
*/
public static String applyCamelCaseRule(String[] stringArray) {
private static String applyCamelCaseRule(String[] stringArray) {
String ruleChecker = stringArray[0];
String ruleChecker = stringArray[0].toLowerCase();
int i;
if (ruleChecker.matches(REGEX_FOR_FIRST_DIGIT)) {
i = 0;
......@@ -286,7 +341,7 @@ public final class JavaIdentifierSyntax {
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];
ruleChecker = ruleChecker + stringArray[i].toLowerCase();
break;
}
}
......@@ -311,19 +366,19 @@ public final class JavaIdentifierSyntax {
/**
* Adds prefix YANG auto prefix if the string begins with digit or is a java key word.
*
* @param camelCasePrefixer string for adding prefix
* @param camelCasePrefix string for adding prefix
* @return prefixed camel case string
*/
public static String addPrefix(String camelCasePrefixer) {
private static String addPrefix(String camelCasePrefix) {
if (camelCasePrefixer.matches(REGEX_FOR_FIRST_DIGIT)) {
camelCasePrefixer = YANG_AUTO_PREFIX + camelCasePrefixer;
if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) {
camelCasePrefix = YANG_AUTO_PREFIX + camelCasePrefix;
}
if (JAVA_KEY_WORDS.contains(camelCasePrefixer)) {
camelCasePrefixer = YANG_AUTO_PREFIX + camelCasePrefixer.substring(0, 1).toUpperCase()
+ camelCasePrefixer.substring(1);
if (JAVA_KEY_WORDS.contains(camelCasePrefix.toLowerCase())) {
camelCasePrefix = YANG_AUTO_PREFIX + camelCasePrefix.substring(0, 1).toUpperCase()
+ camelCasePrefix.substring(1);
}
return camelCasePrefixer;
return camelCasePrefix;
}
/**
......@@ -332,7 +387,7 @@ public final class JavaIdentifierSyntax {
* @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
* @return string without consecutive capital case
*/
public static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
private static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
if (k + 1 < consecCapitalCaseRemover.length()) {
......@@ -350,13 +405,14 @@ public final class JavaIdentifierSyntax {
/**
* Returns the YANG identifier name as java identifier with first letter
* in caps.
* in capital.
*
* @param yangIdentifier identifier in YANG file
* @return corresponding java identifier
*/
public static String getCaptialCase(String yangIdentifier) {
return yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
public static String getCapitalCase(String yangIdentifier) {
yangIdentifier = yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
return restrictConsecutiveCapitalCase(yangIdentifier);
}
/**
......
......@@ -40,7 +40,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChil
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
......@@ -69,9 +69,8 @@ public final class YangJavaModelUtils {
YangPluginConfig yangPluginConfig)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCaptialCase(
getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
yangPluginConfig.getConflictResolver())));
.setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
yangPluginConfig.getConflictResolver()));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
......@@ -89,8 +88,8 @@ public final class YangJavaModelUtils {
String pkg)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCaptialCase(
getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), yangPlugin.getConflictResolver())));
.setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
yangPlugin.getConflictResolver()));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
......@@ -236,7 +235,7 @@ public final class YangJavaModelUtils {
YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
String curNodeName = ((YangCase) javaCodeGeneratorInfo).getName();
if (!parent.getName().equals(curNodeName)) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(getCaptialCase(getCamelCase(
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(getCapitalCase(getCamelCase(
parent.getName(), null)));
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
.addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo);
......
......@@ -687,6 +687,11 @@ public final class UtilConstants {
public static final String REGEX_FOR_FIRST_DIGIT = "\\d.*";
/**
* Static attribute for regex with digits.
*/
public static final String REGEX_WITH_DIGITS = "(?=\\d+)";
/**
* Static attribute for regex for single letter.
*/
public static final String REGEX_FOR_SINGLE_LETTER = "[a-zA-Z]";
......@@ -697,6 +702,21 @@ public final class UtilConstants {
public static final String REGEX_FOR_DIGITS_WITH_SINGLE_LETTER = "[0-9]+[a-zA-Z]";
/**
* Static attribute for regex with uppercase.
*/
public static final String REGEX_WITH_UPPERCASE = "(?=\\p{Upper})";
/**
* Static attribute for regex for single capital case letter.
*/
public static final String REGEX_WITH_SINGLE_CAPITAL_CASE = "[A-Z]";
/**
* Static attribute for regex for capital case letter with any number of digits and small case letters.
*/
public static final String REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES = "[A-Z][0-9a-z]+";
/**
* Static attribute for class syntax.
*/
public static final String CLASS = "class";
......
......@@ -25,7 +25,7 @@ import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
......@@ -61,6 +61,22 @@ public final class JavaIdentifierSyntaxTest {
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_CAMEL_CASE5 = "TestName";
private static final String WITH_CAMEL_CASE5 = "testName";
private static final String WITHOUT_CAMEL_CASE6 = "TEST-NAME";
private static final String WITH_CAMEL_CASE6 = "testName";
private static final String WITHOUT_CAMEL_CASE7 = "TESTNAME";
private static final String WITH_CAMEL_CASE7 = "testname";
private static final String WITHOUT_CAMEL_CASE8 = "TE-ST-NA-ME";
private static final String WITH_CAMEL_CASE8 = "teStNaMe";
private static final String WITHOUT_CAMEL_CASE9 = "TEST3NAME";
private static final String WITH_CAMEL_CASE9 = "test3Name";
private static final String WITHOUT_CAMEL_CASE10 = "TEST3";
private static final String WITH_CAMEL_CASE10 = "test3";
private static final String WITHOUT_CAMEL_CASE11 = "TEST3nAMe";
private static final String WITH_CAMEL_CASE11 = "test3Name";
private static final String WITHOUT_CAMEL_CASE12 = "TEST3name";
private static final String WITH_CAMEL_CASE12 = "test3Name";
private static final String WITHOUT_CAPITAL = "test_this";
private static final String WITH_CAPITAL = "Test_this";
private static final String WITH_SMALL = "test_this";
......@@ -129,7 +145,7 @@ public final class JavaIdentifierSyntaxTest {
*/
@Test
public void getCapitalCaseTest() {
String capitalCase = getCaptialCase(WITHOUT_CAPITAL);
String capitalCase = getCapitalCase(WITHOUT_CAPITAL);
assertThat(capitalCase.equals(WITH_CAPITAL), is(true));
}
......@@ -148,6 +164,22 @@ public final class JavaIdentifierSyntaxTest {
assertThat(camelCase3.equals(WITH_CAMEL_CASE3), is(true));
String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, null);
assertThat(camelCase4.equals(WITH_CAMEL_CASE4), is(true));
String camelCase5 = getCamelCase(WITHOUT_CAMEL_CASE5, null);
assertThat(camelCase5.equals(WITH_CAMEL_CASE5), is(true));
String camelCase6 = getCamelCase(WITHOUT_CAMEL_CASE6, null);
assertThat(camelCase6.equals(WITH_CAMEL_CASE6), is(true));
String camelCase7 = getCamelCase(WITHOUT_CAMEL_CASE7, null);
assertThat(camelCase7.equals(WITH_CAMEL_CASE7), is(true));
String camelCase8 = getCamelCase(WITHOUT_CAMEL_CASE8, null);
assertThat(camelCase8.equals(WITH_CAMEL_CASE8), is(true));
String camelCase9 = getCamelCase(WITHOUT_CAMEL_CASE9, null);
assertThat(camelCase9.equals(WITH_CAMEL_CASE9), is(true));
String camelCase10 = getCamelCase(WITHOUT_CAMEL_CASE10, null);
assertThat(camelCase10.equals(WITH_CAMEL_CASE10), is(true));
String camelCase11 = getCamelCase(WITHOUT_CAMEL_CASE11, null);
assertThat(camelCase11.equals(WITH_CAMEL_CASE11), is(true));
String camelCase12 = getCamelCase(WITHOUT_CAMEL_CASE12, null);
assertThat(camelCase12.equals(WITH_CAMEL_CASE12), is(true));
}
/**
......