Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java Play Framework] Remove most warnings + bug fixes #6275

Merged
merged 11 commits into from
Aug 11, 2017
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -638,19 +638,39 @@ public String toDefaultValue(Property p) {
if (ap.getItems() == null) {
return null;
}
return String.format(pattern, getTypeDeclaration(ap.getItems()));

String typeDeclaration = getTypeDeclaration(ap.getItems());
Object java8obj = additionalProperties.get("java8");
if (java8obj != null) {
Boolean java8 = Boolean.valueOf(java8obj.toString());
if (java8 != null && java8) {
typeDeclaration = "";
}
}

return String.format(pattern, typeDeclaration);
} else if (p instanceof MapProperty) {
final MapProperty ap = (MapProperty) p;
final String pattern;
if (fullJavaUtil) {
pattern = "new java.util.HashMap<String, %s>()";
pattern = "new java.util.HashMap<%s>()";
} else {
pattern = "new HashMap<String, %s>()";
pattern = "new HashMap<%s>()";
}
if (ap.getAdditionalProperties() == null) {
return null;
}
return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties()));

String typeDeclaration = String.format("String, %s", getTypeDeclaration(ap.getAdditionalProperties()));
Object java8obj = additionalProperties.get("java8");
if (java8obj != null) {
Boolean java8 = Boolean.valueOf(java8obj.toString());
if (java8 != null && java8) {
typeDeclaration = "";
}
}

return String.format(pattern, typeDeclaration);
} else if (p instanceof IntegerProperty) {
IntegerProperty dp = (IntegerProperty) p;
if (dp.getDefault() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public JavaPlayFrameworkCodegen() {

additionalProperties.put(CONFIG_PACKAGE, configPackage);
additionalProperties.put(BASE_PACKAGE, basePackage);

additionalProperties.put("java8", true);
additionalProperties.put("jackson", "true");

cliOptions.add(new CliOption(TITLE, "server title name or client service name"));
Expand Down Expand Up @@ -263,7 +263,7 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
}
}

Pattern pathVariableMatcher = Pattern.compile("\\{(.+)}");
Pattern pathVariableMatcher = Pattern.compile("\\{([^}]+)}");
Matcher match = pathVariableMatcher.matcher(operation.path);
while (match.find()) {
String completeMatch = match.group();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isBoolean}}Boolean.valueOf({{/isBoolean}}{{#isInteger}}Integer.parseInt({{/isInteger}}{{#isDouble}}Double.parseDouble({{/isDouble}}{{#isLong}}Long.parseLong({{/isLong}}{{#isFloat}}Float.parseFloat({{/isFloat}}{{#isString}}(String){{/isString}}{{#isDateTime}}OffsetDateTime.parse({{/isDateTime}}
{{#isBoolean}}Boolean.valueOf({{/isBoolean}}{{#isInteger}}Integer.parseInt({{/isInteger}}{{#isDouble}}Double.parseDouble({{/isDouble}}{{#isLong}}Long.parseLong({{/isLong}}{{#isFloat}}Float.parseFloat({{/isFloat}}{{#isDateTime}}OffsetDateTime.parse({{/isDateTime}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isBoolean}}){{/isBoolean}}{{#isInteger}}){{/isInteger}}{{#isDouble}}){{/isDouble}}{{#isLong}}){{/isLong}}{{#isFloat}}){{/isFloat}}{{#isString}}{{/isString}}{{#isDateTime}}){{/isDateTime}}
{{#isBoolean}}){{/isBoolean}}{{#isInteger}}){{/isInteger}}{{#isDouble}}){{/isDouble}}{{#isLong}}){{/isLong}}{{#isFloat}}){{/isFloat}}{{#isDateTime}}){{/isDateTime}}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{{/allowableValues}}
{{/gson}}

private {{{datatype}}} value;
private final {{{datatype}}} value;

{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{datatype}}} value) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
{{/gson}}

private {{{dataType}}} value;
private final {{{dataType}}} value;

{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package {{package}};

import java.util.Objects;
{{#imports}}import {{import}};
{{/imports}}
{{#serializableModel}}
import java.io.Serializable;
{{/serializableModel}}
import com.fasterxml.jackson.annotation.*;
{{#useBeanValidation}}
import java.util.Set;
import javax.validation.*;
import javax.validation.constraints.*;
{{/useBeanValidation}}
{{#models}}
{{#model}}
{{#isEnum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import java.util.ArrayList;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.inject.Inject;
import java.io.File;
{{^handleExceptions}}
import java.io.IOException;
{{/handleExceptions}}
import swagger.SwaggerUtils;
import com.fasterxml.jackson.core.type.TypeReference;

Expand Down Expand Up @@ -90,7 +93,8 @@ public class {{classname}}Controller extends Controller {
{{#formParams}}
{{^notFile}}
{{{dataType}}} {{paramName}} = request().body().asMultipartFormData().getFile("{{baseName}}");
{{#required}}if (({{paramName}} == null || ((File) {{paramName}}.getFile()).length() == 0)) {
{{#required}}
if (({{paramName}} == null || ((File) {{paramName}}.getFile()).length() == 0)) {
throw new RuntimeException("File cannot be empty");
}
{{/required}}
Expand Down Expand Up @@ -148,10 +152,21 @@ public class {{classname}}Controller extends Controller {
entry.getValue().validate();
}
{{/isMapContainer}}{{^returnContainer}}obj.validate();{{/returnContainer}}{{/useBeanValidation}}{{/returnTypeIsPrimitive}}{{/isResponseFile}}{{/returnType}}
{{#returnType}}{{^isResponseFile}}JsonNode result = mapper.valueToTree(obj);
return ok(result);{{/isResponseFile}}{{#isResponseFile}}return ok(obj);{{/isResponseFile}}{{/returnType}}
{{^returnType}}return ok();{{/returnType}}{{/controllerOnly}}
{{#controllerOnly}}return ok();{{/controllerOnly}}
{{#returnType}}
{{^isResponseFile}}JsonNode result = mapper.valueToTree(obj);
return ok(result);
{{/isResponseFile}}
{{#isResponseFile}}
return ok(obj);
{{/isResponseFile}}
{{/returnType}}
{{^returnType}}
return ok();
{{/returnType}}
{{/controllerOnly}}
{{#controllerOnly}}
return ok();
{{/controllerOnly}}
}
{{/operation}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import javax.validation.constraints.*;
{{/useBeanValidation}}

{{#operations}}
@SuppressWarnings("RedundantThrows")
public interface {{classname}}ControllerImpInterface {
{{#operation}}
{{>returnTypes}} {{operationId}}({{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{#handleExceptions}}throws Exception{{/handleExceptions}};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import java.util.Objects;
{{#useBeanValidation}}
import javax.validation.constraints.*;
{{/useBeanValidation}}
/**
* {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
*/
{{>generatedAnnotation}}
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
{{#vars}}
{{#isEnum}}
Expand Down Expand Up @@ -39,11 +44,11 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali

public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
{{^required}}
if (this.{{name}} == null) {
this.{{name}} = {{{defaultValue}}};
if ({{name}} == null) {
{{name}} = {{{defaultValue}}};
}
{{/required}}
this.{{name}}.add({{name}}Item);
{{name}}.add({{name}}Item);
return this;
}
{{/isListContainer}}
Expand Down Expand Up @@ -97,7 +102,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
return false;
}{{#hasVars}}
{{classname}} {{classVarName}} = ({{classname}}) o;
return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
{{/hasMore}}{{/vars}}{{#parent}} &&
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
return true;{{/hasVars}}
Expand All @@ -108,6 +113,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
}

@SuppressWarnings("StringBufferReplaceableByString")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package apimodels;

import java.util.Objects;
import com.fasterxml.jackson.annotation.*;
import java.util.Set;
import javax.validation.*;
import java.util.Objects;
import javax.validation.constraints.*;
/**
* A category for a pet
*/

@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
public class Category {
@JsonProperty("id")
private Long id = null;
Expand Down Expand Up @@ -60,15 +61,16 @@ public boolean equals(java.lang.Object o) {
return false;
}
Category category = (Category) o;
return Objects.equals(this.id, category.id) &&
Objects.equals(this.name, category.name);
return Objects.equals(id, category.id) &&
Objects.equals(name, category.name);
}

@Override
public int hashCode() {
return Objects.hash(id, name);
}

@SuppressWarnings("StringBufferReplaceableByString")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package apimodels;

import java.util.Objects;
import com.fasterxml.jackson.annotation.*;
import java.util.Set;
import javax.validation.*;
import java.util.Objects;
import javax.validation.constraints.*;
/**
* Describes the result of uploading an image resource
*/

@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
public class ModelApiResponse {
@JsonProperty("code")
private Integer code = null;
Expand Down Expand Up @@ -80,16 +81,17 @@ public boolean equals(java.lang.Object o) {
return false;
}
ModelApiResponse _apiResponse = (ModelApiResponse) o;
return Objects.equals(this.code, _apiResponse.code) &&
Objects.equals(this.type, _apiResponse.type) &&
Objects.equals(this.message, _apiResponse.message);
return Objects.equals(code, _apiResponse.code) &&
Objects.equals(type, _apiResponse.type) &&
Objects.equals(message, _apiResponse.message);
}

@Override
public int hashCode() {
return Objects.hash(code, type, message);
}

@SuppressWarnings("StringBufferReplaceableByString")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package apimodels;

import java.util.Objects;
import java.time.OffsetDateTime;
import com.fasterxml.jackson.annotation.*;
import java.util.Set;
import javax.validation.*;
import java.util.Objects;
import javax.validation.constraints.*;
/**
* An order for a pets from the pet store
*/

@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
public class Order {
@JsonProperty("id")
private Long id = null;
Expand All @@ -33,7 +34,7 @@ public enum StatusEnum {

DELIVERED("delivered");

private String value;
private final String value;

StatusEnum(String value) {
this.value = value;
Expand Down Expand Up @@ -175,19 +176,20 @@ public boolean equals(java.lang.Object o) {
return false;
}
Order order = (Order) o;
return Objects.equals(this.id, order.id) &&
Objects.equals(this.petId, order.petId) &&
Objects.equals(this.quantity, order.quantity) &&
Objects.equals(this.shipDate, order.shipDate) &&
Objects.equals(this.status, order.status) &&
Objects.equals(this.complete, order.complete);
return Objects.equals(id, order.id) &&
Objects.equals(petId, order.petId) &&
Objects.equals(quantity, order.quantity) &&
Objects.equals(shipDate, order.shipDate) &&
Objects.equals(status, order.status) &&
Objects.equals(complete, order.complete);
}

@Override
public int hashCode() {
return Objects.hash(id, petId, quantity, shipDate, status, complete);
}

@SuppressWarnings("StringBufferReplaceableByString")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
Loading