Skip to content

Commit

Permalink
Update to codegen data object changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 16, 2015
1 parent 22e9d50 commit 5f096d2
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 469 deletions.
610 changes: 300 additions & 310 deletions src/main/asciidoc/dataobjects.adoc

Large diffs are not rendered by default.

Expand Up @@ -31,7 +31,7 @@ public static void fromJson(JsonObject json, DeploymentOptions obj) {
obj.setConfig(((JsonObject)json.getValue("config")).copy());
}
if (json.getValue("extraClasspath") instanceof JsonArray) {
java.util.List<java.lang.String> list = new java.util.ArrayList<>();
java.util.ArrayList<java.lang.String> list = new java.util.ArrayList<>();
json.getJsonArray("extraClasspath").forEach( item -> {
if (item instanceof String)
list.add((String)item);
Expand All @@ -45,7 +45,7 @@ public static void fromJson(JsonObject json, DeploymentOptions obj) {
obj.setInstances(((Number)json.getValue("instances")).intValue());
}
if (json.getValue("isolatedClasses") instanceof JsonArray) {
java.util.List<java.lang.String> list = new java.util.ArrayList<>();
java.util.ArrayList<java.lang.String> list = new java.util.ArrayList<>();
json.getJsonArray("isolatedClasses").forEach( item -> {
if (item instanceof String)
list.add((String)item);
Expand Down
10 changes: 10 additions & 0 deletions src/main/generated/io/vertx/core/cli/OptionConverter.java
Expand Up @@ -72,6 +72,13 @@ public static void toJson(Option obj, JsonObject json) {
if (obj.getArgName() != null) {
json.put("argName", obj.getArgName());
}
if (obj.getChoices() != null) {
json.put("choices", new JsonArray(
obj.getChoices().
stream().
map(item -> item).
collect(java.util.stream.Collectors.toList())));
}
if (obj.getDefaultValue() != null) {
json.put("defaultValue", obj.getDefaultValue());
}
Expand All @@ -85,6 +92,9 @@ public static void toJson(Option obj, JsonObject json) {
json.put("longName", obj.getLongName());
}
json.put("multiValued", obj.isMultiValued());
if (obj.getName() != null) {
json.put("name", obj.getName());
}
json.put("required", obj.isRequired());
if (obj.getShortName() != null) {
json.put("shortName", obj.getShortName());
Expand Down
Expand Up @@ -98,6 +98,13 @@ public static void toJson(TCPSSLOptions obj, JsonObject json) {
map(item -> item.getBytes()).
collect(java.util.stream.Collectors.toList())));
}
if (obj.getEnabledCipherSuites() != null) {
json.put("enabledCipherSuites", new JsonArray(
obj.getEnabledCipherSuites().
stream().
map(item -> item).
collect(java.util.stream.Collectors.toList())));
}
json.put("idleTimeout", obj.getIdleTimeout());
json.put("soLinger", obj.getSoLinger());
json.put("ssl", obj.isSsl());
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/io/vertx/core/net/KeyCertOptions.java
Expand Up @@ -15,14 +15,11 @@
*/
package io.vertx.core.net;

import io.vertx.codegen.annotations.DataObject;

/**
* Key/cert configuration options.
*
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
@DataObject
public interface KeyCertOptions {

/**
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/io/vertx/core/net/TrustOptions.java
Expand Up @@ -15,14 +15,11 @@
*/
package io.vertx.core.net;

import io.vertx.codegen.annotations.DataObject;

/**
* Certification authority configuration options.
*
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
@DataObject
public interface TrustOptions {

/**
Expand Down
Expand Up @@ -70,7 +70,7 @@
^|Name | Type ^| Description\n
@foreach{property:properties}
@code{propertyType=getDataType(property.type)}
@code{arrayPrefix = property.array ? 'Array of ' : ''}
@code{arrayPrefix = (property.list || property.set) ? 'Array of ' : ''}
@if{propertyType != null}
|[[@{property.name}]]`@{property.name}`
|`@{arrayPrefix}@{getDataType(property.type)}`
Expand Down
53 changes: 29 additions & 24 deletions src/main/resources/vertx-java/template/dataObjectConverter.templ
@@ -1,35 +1,40 @@
@includeNamed{'common-lib.templ'}

@declare{'genPropFromJson'}
@if{property.array}
@if{property.list || property.set}
@{indent}if (json.getValue("@{property.name}") instanceof JsonArray) {\n
@if{property.adder}
@{indent} json.getJsonArray("@{property.name}").forEach(item -> {\n
@{indent} if (item instanceof @{cast})\n
@{indent} obj.@{property.writerMethod}(@{before}item@{after});\n
@{indent} obj.@{property.adderMethod}(@{before}item@{after});\n
@{indent} });\n
@else{}
@{indent} java.util.List<@{propType.name}> list = new java.util.ArrayList<>();\n
@else{property.setter}
@code{coll = property.list ? 'java.util.ArrayList' : 'java.util.HashSet'}
@{indent} @{coll}<@{propType.name}> list = new @{coll}<>();\n
@{indent} json.getJsonArray("@{property.name}").forEach( item -> {\n
@{indent} if (item instanceof @{cast})\n
@{indent} list.add(@{before}item@{after});\n
@{indent} });\n
@{indent} obj.@{property.writerMethod}(list);\n
@{indent} obj.@{property.setterMethod}(list);\n
@end{}
@{indent}}\n
@else{property.map}
@{indent}if (json.getValue("@{property.name}") instanceof JsonObject) {\n
@{indent} java.util.Map<String, @{propType.name}> map = new java.util.LinkedHashMap<>();\n
@{indent} json.getJsonObject("@{property.name}").forEach(entry -> {\n
@{indent} if (entry.getValue() instanceof @{cast})\n
@{indent} map.put(entry.getKey(), @{before}entry.getValue()@{after});\n
@{indent} });\n
@{indent} obj.@{property.writerMethod}(map);\n
@{indent}}\n
@if{property.setter}
@{indent}if (json.getValue("@{property.name}") instanceof JsonObject) {\n
@{indent} java.util.Map<String, @{propType.name}> map = new java.util.LinkedHashMap<>();\n
@{indent} json.getJsonObject("@{property.name}").forEach(entry -> {\n
@{indent} if (entry.getValue() instanceof @{cast})\n
@{indent} map.put(entry.getKey(), @{before}entry.getValue()@{after});\n
@{indent} });\n
@{indent} obj.@{property.setterMethod}(map);\n
@{indent}}\n
@end{}
@else{}
@{indent}if (json.getValue("@{property.name}") instanceof @{cast}) {\n
@{indent} obj.@{property.writerMethod}(@{before}json.getValue("@{property.name}")@{after});\n
@{indent}}\n
@if{property.setter}
@{indent}if (json.getValue("@{property.name}") instanceof @{cast}) {\n
@{indent} obj.@{property.setterMethod}(@{before}json.getValue("@{property.name}")@{after});\n
@{indent}}\n
@end{}
@end{}
@end{}

Expand Down Expand Up @@ -116,31 +121,31 @@ public class @{type.simpleName}Converter {\n
}\n

@declare{'genPropToJson'}
@if{property.array}
@{indent}if (obj.@{property.readerMethod}() != null) {\n
@if{property.list || property.set}
@{indent}if (obj.@{property.getterMethod}() != null) {\n
@{indent} json.put("@{property.name}", new JsonArray(\n
@{indent} obj.@{property.readerMethod}().\n
@{indent} obj.@{property.getterMethod}().\n
@{indent} stream().\n
@{indent} map(item -> @{before}item@{after}).\n
@{indent} collect(java.util.stream.Collectors.toList())));\n
@{indent}}\n
@else{property.map}
@{indent}if (obj.@{property.readerMethod}() != null) {\n
@{indent}if (obj.@{property.getterMethod}() != null) {\n
@{indent} JsonObject map = new JsonObject();\n
@{indent} obj.@{property.readerMethod}().forEach((key,value) -> map.put(key, @{before}value@{after}));\n
@{indent} obj.@{property.getterMethod}().forEach((key,value) -> map.put(key, @{before}value@{after}));\n
@{indent} json.put("@{property.name}", map);\n
@{indent}}\n
@else{}
@if{property.type.kind != CLASS_PRIMITIVE}@{indent}if (obj.@{property.readerMethod}() != null) {\n @end{}
@{indent}json.put("@{property.name}", @{before}obj.@{property.readerMethod}()@{after});\n
@if{property.type.kind != CLASS_PRIMITIVE}@{indent}if (obj.@{property.getterMethod}() != null) {\n @end{}
@{indent}json.put("@{property.name}", @{before}obj.@{property.getterMethod}()@{after});\n
@if{property.type.kind != CLASS_PRIMITIVE}@{indent}}\n@end{}
@end{}
@end{}

\n
public static void toJson(@{type.simpleName} obj, JsonObject json) {\n
@foreach{property:properties}
@if{(property.declared || inheritConverter) && property.readerMethod != null && property.jsonifiable}
@if{(property.declared || inheritConverter) && property.getterMethod != null && property.jsonifiable}
@code{propType=property.type}
@code{propKind=propType.kind}
@if{propKind == CLASS_API}
Expand Down
37 changes: 15 additions & 22 deletions src/test/asciidoc/dataobjects.adoc
Expand Up @@ -30,6 +30,21 @@
^|Name | Type ^| Description
|===

[[ParentDataObject]]
== ParentDataObject

++++
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
++++
'''

[cols=">25%,^25%,50%"]
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[parentProperty]]`parentProperty`|`String`|-
|===

[[TestDataObject]]
== TestDataObject

Expand All @@ -43,7 +58,6 @@
|===
^|Name | Type ^| Description
|[[addedAggregatedDataObjects]]`addedAggregatedDataObjects`|`Array of link:dataobjects.html#AggregatedDataObject[AggregatedDataObject]`|-
|[[addedBooleanValues]]`addedBooleanValues`|`Array of Boolean`|-
|[[addedBoxedBooleanValues]]`addedBoxedBooleanValues`|`Array of Boolean`|-
|[[addedBoxedByteValues]]`addedBoxedByteValues`|`Array of Number (Byte)`|-
|[[addedBoxedCharValues]]`addedBoxedCharValues`|`Array of Char`|-
Expand All @@ -53,15 +67,9 @@
|[[addedBoxedLongValues]]`addedBoxedLongValues`|`Array of Number (Long)`|-
|[[addedBoxedShortValues]]`addedBoxedShortValues`|`Array of Number (Short)`|-
|[[addedBuffers]]`addedBuffers`|`Array of Buffer`|-
|[[addedByteValues]]`addedByteValues`|`Array of Number (byte)`|-
|[[addedDoubleValues]]`addedDoubleValues`|`Array of Number (double)`|-
|[[addedFloatValues]]`addedFloatValues`|`Array of Number (float)`|-
|[[addedHttpMethods]]`addedHttpMethods`|`Array of link:enums.html#HttpMethod[HttpMethod]`|-
|[[addedIntValues]]`addedIntValues`|`Array of Number (int)`|-
|[[addedJsonArrays]]`addedJsonArrays`|`Array of Json array`|-
|[[addedJsonObjects]]`addedJsonObjects`|`Array of Json object`|-
|[[addedLongValues]]`addedLongValues`|`Array of Number (long)`|-
|[[addedShortValues]]`addedShortValues`|`Array of Number (short)`|-
|[[addedStringValues]]`addedStringValues`|`Array of String`|-
|[[aggregatedDataObject]]`aggregatedDataObject`|`link:dataobjects.html#AggregatedDataObject[AggregatedDataObject]`|-
|[[aggregatedDataObjectMap]]`aggregatedDataObjectMap`|`link:dataobjects.html#AggregatedDataObject[AggregatedDataObject]`|-
Expand Down Expand Up @@ -114,21 +122,6 @@
|[[stringValues]]`stringValues`|`Array of String`|-
|===

[[ParentDataObject]]
== ParentDataObject

++++
@author <a href="mailto:julien@julienviet.com">Julien Viet</a>
++++
'''

[cols=">25%,^25%,50%"]
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[parentProperty]]`parentProperty`|`String`|-
|===

[[AggregatedDataObject]]
== AggregatedDataObject

Expand Down
80 changes: 0 additions & 80 deletions src/test/java/io/vertx/test/codegen/TestDataObject.java
Expand Up @@ -72,14 +72,6 @@ public class TestDataObject {
private List<Object> objects;

private List<String> addedStringValues = new ArrayList<>();
private List<Boolean> addedBooleanValues = new ArrayList<>();
private List<Byte> addedByteValues = new ArrayList<>();
private List<Short> addedShortValues = new ArrayList<>();
private List<Integer> addedIntValues = new ArrayList<>();
private List<Long> addedLongValues = new ArrayList<>();
private List<Float> addedFloatValues = new ArrayList<>();
private List<Double> addedDoubleValues = new ArrayList<>();
private List<Character> addedCharValues = new ArrayList<>();
private List<Boolean> addedBoxedBooleanValues = new ArrayList<>();
private List<Byte> addedBoxedByteValues = new ArrayList<>();
private List<Short> addedBoxedShortValues = new ArrayList<>();
Expand Down Expand Up @@ -462,78 +454,6 @@ public TestDataObject addAddedStringValue(String addedStringValue) {
return this;
}

public List<Boolean> getAddedBooleanValues() {
return addedBooleanValues;
}

public TestDataObject addAddedBooleanValue(boolean addedBoxedBooleanValue) {
this.addedBooleanValues.add(addedBoxedBooleanValue);
return this;
}

public List<Byte> getAddedByteValues() {
return addedByteValues;
}

public TestDataObject addAddedByteValue(byte addedBoxedByteValue) {
this.addedByteValues.add(addedBoxedByteValue);
return this;
}

public List<Short> getAddedShortValues() {
return addedShortValues;
}

public TestDataObject addAddedShortValue(short addedBoxedShortValue) {
this.addedShortValues.add(addedBoxedShortValue);
return this;
}

public List<Integer> getAddedIntValues() {
return addedIntValues;
}

public TestDataObject addAddedIntValue(int addedBoxedIntValue) {
this.addedIntValues.add(addedBoxedIntValue);
return this;
}

public List<Long> getAddedLongValues() {
return addedLongValues;
}

public TestDataObject addAddedLongValue(long addedBoxedLongValue) {
this.addedLongValues.add(addedBoxedLongValue);
return this;
}

public List<Float> getAddedFloatValues() {
return addedFloatValues;
}

public TestDataObject addAddedFloatValue(float addedBoxedFloatValue) {
this.addedFloatValues.add(addedBoxedFloatValue);
return this;
}

public List<Double> getAddedDoubleValues() {
return addedDoubleValues;
}

public TestDataObject addAddedDoubleValue(double addedBoxedDoubleValue) {
this.addedDoubleValues.add(addedBoxedDoubleValue);
return this;
}

public List<Character> getAddedCharValues() {
return addedCharValues;
}

public TestDataObject addAddedCharValue(char addedBoxedCharValue) {
this.addedCharValues.add(addedBoxedCharValue);
return this;
}

public List<Boolean> getAddedBoxedBooleanValues() {
return addedBoxedBooleanValues;
}
Expand Down
24 changes: 0 additions & 24 deletions src/test/java/io/vertx/test/core/DataObjectTest.java
Expand Up @@ -201,14 +201,6 @@ public void testJsonToDataObject() {
assertEquals(Collections.singletonList(httpMethod), obj.getHttpMethods());
assertEquals(list, obj.getObjects());
assertEquals(Collections.singletonList(stringValue), obj.getAddedStringValues());
assertEquals(Collections.singletonList(boxedBooleanValue), obj.getAddedBooleanValues());
assertEquals(Collections.singletonList(boxedByteValue), obj.getAddedByteValues());
assertEquals(Collections.singletonList(boxedShortValue), obj.getAddedShortValues());
assertEquals(Collections.singletonList(boxedIntValue), obj.getAddedIntValues());
assertEquals(Collections.singletonList(boxedLongValue), obj.getAddedLongValues());
assertEquals(Collections.singletonList(boxedFloatValue), obj.getAddedFloatValues());
assertEquals(Collections.singletonList(boxedDoubleValue), obj.getAddedDoubleValues());
assertEquals(Collections.singletonList(boxedCharValue), obj.getAddedCharValues());
assertEquals(Collections.singletonList(boxedBooleanValue), obj.getAddedBoxedBooleanValues());
assertEquals(Collections.singletonList(boxedByteValue), obj.getAddedBoxedByteValues());
assertEquals(Collections.singletonList(boxedShortValue), obj.getAddedBoxedShortValues());
Expand Down Expand Up @@ -296,14 +288,6 @@ public void testEmptyJsonToDataObject() {
assertEquals(null, obj.getHttpMethods());
assertEquals(null, obj.getObjects());
assertEquals(Collections.emptyList(), obj.getAddedStringValues());
assertEquals(Collections.emptyList(), obj.getAddedBooleanValues());
assertEquals(Collections.emptyList(), obj.getAddedByteValues());
assertEquals(Collections.emptyList(), obj.getAddedShortValues());
assertEquals(Collections.emptyList(), obj.getAddedIntValues());
assertEquals(Collections.emptyList(), obj.getAddedLongValues());
assertEquals(Collections.emptyList(), obj.getAddedFloatValues());
assertEquals(Collections.emptyList(), obj.getAddedDoubleValues());
assertEquals(Collections.emptyList(), obj.getAddedCharValues());
assertEquals(Collections.emptyList(), obj.getAddedBoxedBooleanValues());
assertEquals(Collections.emptyList(), obj.getAddedBoxedByteValues());
assertEquals(Collections.emptyList(), obj.getAddedBoxedShortValues());
Expand Down Expand Up @@ -533,14 +517,6 @@ public void testEmptyDataObjectToJson() {
assertEquals(null, json.getJsonArray("httpMethods"));
assertEquals(null, json.getJsonArray("objects"));
assertEquals(new JsonArray(), json.getJsonArray("addedStringValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedBooleanValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedByteValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedShortValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedIntValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedLongValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedFloatValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedDoubleValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedCharValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedBoxedBooleanValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedBoxedByteValues"));
assertEquals(new JsonArray(), json.getJsonArray("addedBoxedShortValues"));
Expand Down

0 comments on commit 5f096d2

Please sign in to comment.