[feature #1255] make JavaClientCodegen.toModelName independent from super implementation.

As pointed out in the review, using a super.toModelName call makes future changes harder
to review, therefore we are implementing the addition of suffix and prefix here again.

In addition, I fixed the FIXME about assigning the parameter.
This commit is contained in:
Paul Ebermann
2016-02-24 16:47:08 +01:00
parent 70bcf22c82
commit 36f7ffd6eb

View File

@@ -376,22 +376,21 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
}
@Override
public String toModelName(String name) {
name = super.toModelName(name);
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
public String toModelName(final String name) {
final String sanitizedName = sanitizeName(modelNamePrefix + name + modelNameSuffix);
// camelize the model name
// phone_number => PhoneNumber
name = camelize(name);
final String camelizedName = camelize(sanitizedName);
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
String modelName = "Object" + name;
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
if (isReservedWord(camelizedName)) {
final String modelName = "Object" + camelizedName;
LOGGER.warn(camelizedName + " (reserved word) cannot be used as model name. Renamed to " + modelName);
return modelName;
}
return name;
return camelizedName;
}
@Override