Various code cleanups (#3709)

* For/while to foreach loop conversions

* Don't instantiate Booleans

* Remove redundant String.toString calls

* Remove redundant String instantiations

* Don't concatenate StringBuilder.append args

* Replace dangling javadoc comments with blocks

* Combine identical catch branches

* Remove redundant catch branch

* Remove unnecessary boxing

* Remove redundant casts

* Remove redundant null checks
This commit is contained in:
Ville Skyttä 2016-09-07 11:41:51 +03:00 committed by wing328
parent 3d1f621f8b
commit b8e8c7cdb5
32 changed files with 96 additions and 108 deletions

View File

@ -27,7 +27,7 @@ public class ConfigParser {
Iterator<Map.Entry<String, JsonNode>> optionNodes = rootNode.fields();
while (optionNodes.hasNext()) {
Map.Entry<String, JsonNode> optionNode = (Map.Entry<String, JsonNode>) optionNodes.next();
Map.Entry<String, JsonNode> optionNode = optionNodes.next();
if (optionNode.getValue().isValueNode()) {
config.setOption(optionNode.getKey(), optionNode.getValue().asText());

View File

@ -2,7 +2,6 @@ package io.swagger.codegen;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
@ -124,9 +123,8 @@ public class Codegen extends DefaultGenerator {
public static List<CodegenConfig> getExtensions() {
ServiceLoader<CodegenConfig> loader = ServiceLoader.load(CodegenConfig.class);
List<CodegenConfig> output = new ArrayList<CodegenConfig>();
Iterator<CodegenConfig> itr = loader.iterator();
while (itr.hasNext()) {
output.add(itr.next());
for (CodegenConfig aLoader : loader) {
output.add(aLoader);
}
return output;
}

View File

@ -30,9 +30,7 @@ public final class CodegenModelFactory {
Class<?> classType = typeMapping.get(type);
try {
return (T) (classType != null ? classType : type.getDefaultImplementation()).newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
} catch (IllegalAccessException | InstantiationException e) {
throw new RuntimeException(e);
}
}

View File

@ -281,7 +281,7 @@ public class CodegenOperation {
@Override
public int hashCode() {
int result = responseHeaders != null ? responseHeaders.hashCode() : 0;
int result = responseHeaders.hashCode();
result = 31 * result + (hasAuthMethods != null ? hasAuthMethods.hashCode() : 0);
result = 31 * result + (hasConsumes != null ? hasConsumes.hashCode() : 0);
result = 31 * result + (hasProduces != null ? hasProduces.hashCode() : 0);

View File

@ -35,7 +35,7 @@ public class CodegenResponse {
CodegenResponse that = (CodegenResponse) o;
if (headers != null ? !headers.equals(that.headers) : that.headers != null)
if (!headers.equals(that.headers))
return false;
if (code != null ? !code.equals(that.code) : that.code != null)
return false;
@ -71,7 +71,7 @@ public class CodegenResponse {
@Override
public int hashCode() {
int result = headers != null ? headers.hashCode() : 0;
int result = headers.hashCode();
result = 31 * result + (code != null ? code.hashCode() : 0);
result = 31 * result + (message != null ? message.hashCode() : 0);
result = 31 * result + (hasMore != null ? hasMore.hashCode() : 0);

View File

@ -886,7 +886,7 @@ public class DefaultCodegen {
paramPart.append(param.getName()).append("=");
paramPart.append("{");
if (qp.getCollectionFormat() != null) {
paramPart.append(param.getName() + "1");
paramPart.append(param.getName()).append("1");
if ("csv".equals(qp.getCollectionFormat())) {
paramPart.append(",");
} else if ("pipes".equals(qp.getCollectionFormat())) {
@ -895,7 +895,7 @@ public class DefaultCodegen {
paramPart.append("\t");
} else if ("multi".equals(qp.getCollectionFormat())) {
paramPart.append("&").append(param.getName()).append("=");
paramPart.append(param.getName() + "2");
paramPart.append(param.getName()).append("2");
}
} else {
paramPart.append(param.getName());
@ -1574,7 +1574,7 @@ public class DefaultCodegen {
List<String> _enum = sp.getEnum();
property._enum = new ArrayList<String>();
for(String i : _enum) {
property._enum.add(i.toString());
property._enum.add(i);
}
property.isEnum = true;
@ -1592,7 +1592,7 @@ public class DefaultCodegen {
List<String> _enum = sp.getEnum();
property._enum = new ArrayList<String>();
for(String i : _enum) {
property._enum.add(i.toString());
property._enum.add(i);
}
property.isEnum = true;
@ -2355,28 +2355,28 @@ public class DefaultCodegen {
} else if (Boolean.TRUE.equals(p.isString)) {
p.example = p.paramName + "_example";
} else if (Boolean.TRUE.equals(p.isBoolean)) {
p.example = new String("true");
p.example = "true";
} else if (Boolean.TRUE.equals(p.isLong)) {
p.example = new String("789");
p.example = "789";
} else if (Boolean.TRUE.equals(p.isInteger)) {
p.example = new String("56");
p.example = "56";
} else if (Boolean.TRUE.equals(p.isFloat)) {
p.example = new String("3.4");
p.example = "3.4";
} else if (Boolean.TRUE.equals(p.isDouble)) {
p.example = new String("1.2");
p.example = "1.2";
} else if (Boolean.TRUE.equals(p.isBinary)) {
p.example = new String("BINARY_DATA_HERE");
p.example = "BINARY_DATA_HERE";
} else if (Boolean.TRUE.equals(p.isByteArray)) {
p.example = new String("B");
p.example = "B";
} else if (Boolean.TRUE.equals(p.isDate)) {
p.example = new String("2013-10-20");
p.example = "2013-10-20";
} else if (Boolean.TRUE.equals(p.isDateTime)) {
p.example = new String("2013-10-20T19:20:30+01:00");
p.example = "2013-10-20T19:20:30+01:00";
} else if (param instanceof FormParameter &&
("file".equalsIgnoreCase(((FormParameter) param).getType()) ||
"file".equals(p.baseType))) {
p.isFile = true;
p.example = new String("/path/to/file.txt");
p.example = "/path/to/file.txt";
}
// set the parameter excample value
@ -2531,8 +2531,7 @@ public class DefaultCodegen {
// must be root tmpPath
builder.append("root");
}
for (int i = 0; i < parts.length; i++) {
String part = parts[i];
for (String part : parts) {
if (part.length() > 0) {
if (builder.toString().length() == 0) {
part = Character.toLowerCase(part.charAt(0)) + part.substring(1);
@ -2587,10 +2586,10 @@ public class DefaultCodegen {
if (objs != null) {
for (int i = 0; i < objs.size(); i++) {
if (i > 0) {
objs.get(i).secondaryParam = new Boolean(true);
objs.get(i).secondaryParam = true;
}
if (i < objs.size() - 1) {
objs.get(i).hasMore = new Boolean(true);
objs.get(i).hasMore = true;
}
}
}
@ -2601,7 +2600,7 @@ public class DefaultCodegen {
if (objs != null) {
for (int i = 0; i < objs.size() - 1; i++) {
if (i > 0) {
objs.put("secondaryParam", new Boolean(true));
objs.put("secondaryParam", true);
}
if (i < objs.size() - 1) {
objs.put("hasMore", true);

View File

@ -413,7 +413,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
// Pass sortParamsByRequiredFlag through to the Mustache template...
boolean sortParamsByRequiredFlag = true;
if (this.config.additionalProperties().containsKey(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG)) {
sortParamsByRequiredFlag = Boolean.valueOf((String)this.config.additionalProperties().get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG).toString());
sortParamsByRequiredFlag = Boolean.valueOf(this.config.additionalProperties().get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG).toString());
}
operation.put("sortParamsByRequiredFlag", sortParamsByRequiredFlag);

View File

@ -16,7 +16,6 @@ import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
@ -40,9 +39,8 @@ public class MetaGenerator extends AbstractGenerator {
public static List<CodegenConfig> getExtensions() {
ServiceLoader<CodegenConfig> loader = ServiceLoader.load(CodegenConfig.class);
List<CodegenConfig> output = new ArrayList<CodegenConfig>();
Iterator<CodegenConfig> itr = loader.iterator();
while (itr.hasNext()) {
output.add(itr.next());
for (CodegenConfig config : loader) {
output.add(config);
}
return output;
}

View File

@ -151,7 +151,7 @@ public class CodegenConfigurator {
File f = new File(templateDir);
// check to see if the folder exists
if (!(f != null && f.exists() && f.isDirectory())) {
if (!(f.exists() && f.isDirectory())) {
throw new IllegalArgumentException("Template directory " + templateDir + " does not exist.");
}
@ -414,7 +414,7 @@ public class CodegenConfigurator {
codegenConfig.additionalProperties().put(opt, dynamicProperties.get(opt));
}
else if(systemProperties.containsKey(opt)) {
codegenConfig.additionalProperties().put(opt, systemProperties.get(opt).toString());
codegenConfig.additionalProperties().put(opt, systemProperties.get(opt));
}
}
}

View File

@ -99,15 +99,15 @@ public class ExampleGenerator {
} else if (property instanceof DecimalProperty) {
return new BigDecimal(1.3579);
} else if (property instanceof DoubleProperty) {
return new Double(3.149);
return 3.149;
} else if (property instanceof FileProperty) {
return ""; // TODO
} else if (property instanceof FloatProperty) {
return new Float(1.23);
return 1.23f;
} else if (property instanceof IntegerProperty) {
return new Integer(123);
return 123;
} else if (property instanceof LongProperty) {
return new Long(123456789);
return 123456789L;
} else if (property instanceof MapProperty) {
Map<String, Object> mp = new HashMap<String, Object>();
if (property.getName() != null) {

View File

@ -26,10 +26,8 @@ public abstract class Rule {
if(syntax == null) return this.definition;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < syntax.size(); i++) {
Part current = syntax.get(i);
switch(current.getToken()){
for (Part current : syntax) {
switch (current.getToken()) {
case MATCH_ALL:
case MATCH_ANY:
case ESCAPED_EXCLAMATION:

View File

@ -466,7 +466,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
if (p instanceof StringProperty) {
StringProperty dp = (StringProperty) p;
if (dp.getDefault() != null) {
return "\"" + dp.getDefault().toString() + "\"";
return "\"" + dp.getDefault() + "\"";
}
} else if (p instanceof BooleanProperty) {
BooleanProperty dp = (BooleanProperty) p;

View File

@ -602,7 +602,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
if(codegenModel.description != null) {
codegenModel.imports.add("ApiModel");
}
if (allDefinitions != null && codegenModel != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
if (allDefinitions != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
final Model parentModel = allDefinitions.get(codegenModel.parentSchema);
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
codegenModel = AbstractJavaCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);

View File

@ -462,7 +462,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
if (p instanceof StringProperty) {
StringProperty dp = (StringProperty) p;
if (dp.getDefault() != null) {
return "'" + dp.getDefault().toString() + "'";
return "'" + dp.getDefault() + "'";
}
} else if (p instanceof BooleanProperty) {
BooleanProperty dp = (BooleanProperty) p;
@ -586,7 +586,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
// number
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
String varName = new String(name);
String varName = name;
varName = varName.replaceAll("-", "MINUS_");
varName = varName.replaceAll("\\+", "PLUS_");
varName = varName.replaceAll("\\.", "_DOT_");

View File

@ -144,7 +144,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
} else {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
Boolean.valueOf((String)additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
}
Boolean excludeTests = false;

View File

@ -67,7 +67,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
apiTemplateFiles.clear();
/**
/*
* Template Location. This is the location which templates will be read from. The generator
* will use the resource stream to attempt to read the templates.
*/
@ -81,14 +81,14 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
"return", "def", "for", "lambda", "try"));
/**
/*
* Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files
*/
additionalProperties.put("apiVersion", apiVersion);
additionalProperties.put("serverPort", serverPort);
/**
/*
* Supporting Files. You can write single files for the generator with the
* entire object tree available. If the input file has a suffix of `.mustache
* it will be processed by the template engine. Otherwise, it will be copied

View File

@ -132,7 +132,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
} else {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
Boolean.valueOf((String)additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
@ -373,7 +373,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String toOperationId(String operationId) {
String sanitizedOperationId = new String(sanitizeName(operationId));
String sanitizedOperationId = sanitizeName(operationId);
// method name cannot use reserved keyword, e.g. return
if (isReservedWord(sanitizedOperationId)) {

View File

@ -36,7 +36,7 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
// set the output folder here
outputFolder = "generated-code/go";
/**
/*
* Models. You can write model files using the modelTemplateFiles map.
* if you want to create one template for file, you can do so here.
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
@ -44,7 +44,7 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
*/
modelTemplateFiles.clear();
/**
/*
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
* as with models, add multiple entries with different extensions for multiple files per
* class
@ -53,13 +53,13 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
"controller.mustache", // the template to use
".go"); // the extension for each file to write
/**
/*
* Template Location. This is the location which templates will be read from. The generator
* will use the resource stream to attempt to read the templates.
*/
embeddedTemplateDir = templateDir = "go-server";
/**
/*
* Reserved words. Override this with reserved words specific to your language
*/
setReservedWordsLowerCase(
@ -126,14 +126,14 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
cliOptions.clear();
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).")
.defaultValue("swagger"));
/**
/*
* Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files
*/
additionalProperties.put("apiVersion", apiVersion);
additionalProperties.put("serverPort", serverPort);
additionalProperties.put("apiPath", apiPath);
/**
/*
* Supporting Files. You can write single files for the generator with the
* entire object tree available. If the input file has a suffix of `.mustache
* it will be processed by the template engine. Otherwise, it will be copied

View File

@ -53,7 +53,7 @@ public class JMeterCodegen extends DefaultCodegen implements CodegenConfig {
// set the output folder here
outputFolder = "generated-code/JMeterCodegen";
/**
/*
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
* as with models, add multiple entries with different extensions for multiple files per
* class
@ -64,23 +64,23 @@ public class JMeterCodegen extends DefaultCodegen implements CodegenConfig {
apiTemplateFiles.put("testdata-localhost.mustache", ".csv");
/**
/*
* Template Location. This is the location which templates will be read from. The generator
* will use the resource stream to attempt to read the templates.
*/
templateDir = "JMeter";
/**
/*
* Api Package. Optional, if needed, this can be used in templates
*/
apiPackage = "";
/**
/*
* Model Package. Optional, if needed, this can be used in templates
*/
modelPackage = "";
/**
/*
* Reserved words. Override this with reserved words specific to your language
*/
reservedWords = new HashSet<String> (
@ -89,7 +89,7 @@ public class JMeterCodegen extends DefaultCodegen implements CodegenConfig {
"sample2")
);
/**
/*
* Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files
*/

View File

@ -18,7 +18,6 @@ import io.swagger.models.Operation;
import io.swagger.models.Swagger;
import io.swagger.util.Json;
import org.apache.commons.io.FileUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
{
@ -135,8 +134,6 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
try {
String swaggerJson = Json.pretty(swagger);
FileUtils.writeStringToFile(new File(outputFolder + File.separator + "swagger.json"), swaggerJson);
} catch (JsonProcessingException e) {
throw new RuntimeException(e.getMessage(), e.getCause());
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e.getCause());
}

View File

@ -199,7 +199,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
} else {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
Boolean.valueOf((String)additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
}

View File

@ -50,18 +50,18 @@ public class LumenServerCodegen extends AbstractPhpCodegen
embeddedTemplateDir = templateDir = "lumen";
/**
/*
* packPath
*/
invokerPackage = "lumen";
packagePath = "";
/**
/*
* Api Package. Optional, if needed, this can be used in templates
*/
apiPackage = "app.Http.Controllers";
/**
/*
* Model Package. Optional, if needed, this can be used in templates
*/
modelPackage = "models";
@ -72,13 +72,13 @@ public class LumenServerCodegen extends AbstractPhpCodegen
apiDocTemplateFiles.clear();
modelDocTemplateFiles.clear();
/**
/*
* Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files
*/
additionalProperties.put("apiVersion", apiVersion);
/**
/*
* Supporting Files. You can write single files for the generator with the
* entire object tree available. If the input file has a suffix of `.mustache
* it will be processed by the template engine. Otherwise, it will be copied

View File

@ -34,7 +34,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
// set the output folder here
outputFolder = "generated-code/nodejs";
/**
/*
* Models. You can write model files using the modelTemplateFiles map.
* if you want to create one template for file, you can do so here.
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
@ -42,7 +42,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
*/
modelTemplateFiles.clear();
/**
/*
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
* as with models, add multiple entries with different extensions for multiple files per
* class
@ -51,13 +51,13 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
"controller.mustache", // the template to use
".js"); // the extension for each file to write
/**
/*
* Template Location. This is the location which templates will be read from. The generator
* will use the resource stream to attempt to read the templates.
*/
embeddedTemplateDir = templateDir = "nodejs";
/**
/*
* Reserved words. Override this with reserved words specific to your language
*/
setReservedWordsLowerCase(
@ -69,14 +69,14 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
"void", "while", "with", "yield")
);
/**
/*
* Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files
*/
additionalProperties.put("apiVersion", apiVersion);
additionalProperties.put("serverPort", serverPort);
/**
/*
* Supporting Files. You can write single files for the generator with the
* entire object tree available. If the input file has a suffix of `.mustache
* it will be processed by the template engine. Otherwise, it will be copied

View File

@ -195,7 +195,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
} else {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
Boolean.valueOf((String)additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
}
if (additionalProperties.containsKey(POD_NAME)) {
@ -514,8 +514,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
}
// if name starting with special word, escape with '_'
for(int i =0; i < specialWords.length; i++) {
if (name.matches("(?i:^" + specialWords[i] + ".*)"))
for (String specialWord : specialWords) {
if (name.matches("(?i:^" + specialWord + ".*)"))
name = escapeSpecialWord(name);
}
@ -624,7 +624,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
if (p instanceof StringProperty) {
StringProperty dp = (StringProperty) p;
if (dp.getDefault() != null) {
return "@\"" + dp.getDefault().toString() + "\"";
return "@\"" + dp.getDefault() + "\"";
}
} else if (p instanceof BooleanProperty) {
BooleanProperty dp = (BooleanProperty) p;

View File

@ -232,7 +232,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
if (p instanceof StringProperty) {
StringProperty dp = (StringProperty) p;
if (dp.getDefault() != null) {
return "'" + dp.getDefault().toString() + "'";
return "'" + dp.getDefault() + "'";
}
} else if (p instanceof BooleanProperty) {
BooleanProperty dp = (BooleanProperty) p;
@ -401,9 +401,9 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
p.example = "'" + p.example + "'";
} else if (Boolean.TRUE.equals(p.isBoolean)) {
if (Boolean.parseBoolean(p.example))
p.example = new String("1");
p.example = "1";
else
p.example = new String("0");
p.example = "0";
} else if (Boolean.TRUE.equals(p.isDateTime) || Boolean.TRUE.equals(p.isDate)) {
p.example = "DateTime->from_epoch(epoch => str2time('" + p.example + "'))";
}

View File

@ -211,7 +211,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
} else {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
Boolean.valueOf((String)additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
}
if (additionalProperties.containsKey(PACKAGE_PATH)) {
@ -517,7 +517,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
if (p instanceof StringProperty) {
StringProperty dp = (StringProperty) p;
if (dp.getDefault() != null) {
return "'" + dp.getDefault().toString() + "'";
return "'" + dp.getDefault() + "'";
}
} else if (p instanceof BooleanProperty) {
BooleanProperty dp = (BooleanProperty) p;
@ -636,7 +636,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
public String toEnumVarName(String name, String datatype) {
// number
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
String varName = new String(name);
String varName = name;
varName = varName.replaceAll("-", "MINUS_");
varName = varName.replaceAll("\\+", "PLUS_");
varName = varName.replaceAll("\\.", "_DOT_");

View File

@ -146,7 +146,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
} else {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
Boolean.valueOf((String)additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
}
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
@ -500,7 +500,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
if (p instanceof StringProperty) {
StringProperty dp = (StringProperty) p;
if (dp.getDefault() != null) {
return "'" + dp.getDefault().toString() + "'";
return "'" + dp.getDefault() + "'";
}
} else if (p instanceof BooleanProperty) {
BooleanProperty dp = (BooleanProperty) p;

View File

@ -41,7 +41,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
// set the output folder here
outputFolder = "generated-code/qt5cpp";
/**
/*
* Models. You can write model files using the modelTemplateFiles map.
* if you want to create one template for file, you can do so here.
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
@ -55,7 +55,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
"model-body.mustache",
".cpp");
/**
/*
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
* as with models, add multiple entries with different extensions for multiple files per
* class
@ -68,13 +68,13 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
"api-body.mustache", // the template to use
".cpp"); // the extension for each file to write
/**
/*
* Template Location. This is the location which templates will be read from. The generator
* will use the resource stream to attempt to read the templates.
*/
embeddedTemplateDir = templateDir = "qt5cpp";
/**
/*
* Reserved words. Override this with reserved words specific to your language
*/
setReservedWordsLowerCase(
@ -83,14 +83,14 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
"sample2")
);
/**
/*
* Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files
*/
additionalProperties.put("apiVersion", apiVersion);
additionalProperties().put("prefix", PREFIX);
/**
/*
* Language Specific Primitives. These types will not trigger imports by
* the client generator
*/

View File

@ -175,7 +175,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
} else {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
Boolean.valueOf((String)additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
}
if (additionalProperties.containsKey(GEM_NAME)) {
@ -568,7 +568,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
public String toEnumVarName(String name, String datatype) {
// number
if ("Integer".equals(datatype) || "Float".equals(datatype)) {
String varName = new String(name);
String varName = name;
varName = varName.replaceAll("-", "MINUS_");
varName = varName.replaceAll("\\+", "PLUS_");
varName = varName.replaceAll("\\.", "_DOT_");

View File

@ -233,7 +233,7 @@ public class SpringCodegen extends AbstractJavaCodegen {
}
this.additionalProperties.put("serverPort", port);
if (swagger != null && swagger.getPaths() != null) {
if (swagger.getPaths() != null) {
for (String pathname : swagger.getPaths().keySet()) {
Path path = swagger.getPath(pathname);
if (path.getOperations() != null) {

View File

@ -167,7 +167,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
} else {
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP,
Boolean.valueOf((String)additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
}
// Setup project name
@ -538,7 +538,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
// TODO: this code is probably useless, because the var name is computed from the value in map.put("enum", toSwiftyEnumName(value));
// number
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
String varName = new String(name);
String varName = name;
varName = varName.replaceAll("-", "MINUS_");
varName = varName.replaceAll("\\+", "PLUS_");
varName = varName.replaceAll("\\.", "_DOT_");

View File

@ -113,12 +113,12 @@ public class AssertFile {
if(!deltas.isEmpty()) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("files diff:\n");
stringBuilder.append("\tfile: '" + expected.toAbsolutePath().toString() + "' \n");
stringBuilder.append("\tfile: '" + actual.toAbsolutePath().toString() + "' \n");
stringBuilder.append("\tfile: '").append(expected.toAbsolutePath().toString()).append("' \n");
stringBuilder.append("\tfile: '").append(actual.toAbsolutePath().toString()).append("' \n");
stringBuilder.append("\tdiffs:\n");
for (Delta delta: deltas) {
stringBuilder.append(delta.toString() + "\n");
stringBuilder.append(delta.toString()).append("\n");
}
fail(stringBuilder.toString());