make sure to camelize properly before checking for reserved words (#4302)

This commit is contained in:
jaz-ah
2016-11-30 19:49:56 -08:00
committed by wing328
parent fbe4feedd4
commit 0a97b9c568
2 changed files with 23 additions and 5 deletions

View File

@@ -518,25 +518,33 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase()), true);
}
// Camelize only when we have a structure defined below
Boolean camelized = false;
if (name.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
name = camelize(name, true);
camelized = true;
}
// Reserved Name
if (isReservedWord(name)) {
return escapeReservedWord(name);
}
// Check for numerical conversions
if ("Int".equals(datatype) || "Int32".equals(datatype) || "Int64".equals(datatype) ||
"Float".equals(datatype) || "Double".equals(datatype)) {
String varName = "number" + camelize(name);
varName = varName.replaceAll("-", "minus");
varName = varName.replaceAll("\\+", "plus");
varName = varName.replaceAll("\\.", "dot");
return varName;
}
// Prevent from breaking properly cased identifier
if (name.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
return camelize(name, true);
}
// If we have already camelized the word, don't progress
// any further
if (camelized) {
return name;
}
char[] separators = {'-', '_', ' ', ':', '(', ')'};
return camelize(WordUtils.capitalizeFully(StringUtils.lowerCase(name), separators).replaceAll("[-_ :\\(\\)]", ""), true);