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

Now DataObject allows set/get package-private & protected #264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/codegen/DataObjectModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private void processMethods(List<ExecutableElement> methodsElt) {
ExecutableElement methodElt = methodsElt.remove(0);
if (((TypeElement) methodElt.getEnclosingElement()).getQualifiedName().toString().equals("java.lang.Object") ||
methodElt.getModifiers().contains(Modifier.STATIC) ||
!methodElt.getModifiers().contains(Modifier.PUBLIC)) {
methodElt.getModifiers().contains(Modifier.PRIVATE)) {
continue;
}
String methodName = methodElt.getSimpleName().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,16 @@ public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json,
obj.setObjects(list);
}
break;
case "packagePrivateValue":
if (member.getValue() instanceof Number) {
obj.setPackagePrivateValue(((Number)member.getValue()).intValue());
}
break;
case "protectedValue":
if (member.getValue() instanceof Number) {
obj.setProtectedValue(((Number)member.getValue()).intValue());
}
break;
case "shortValue":
if (member.getValue() instanceof Number) {
obj.setShortValue(((Number)member.getValue()).shortValue());
Expand Down Expand Up @@ -1350,6 +1360,8 @@ public static void toJson(TestDataObject obj, java.util.Map<String, Object> json
obj.getObjects().forEach(item -> array.add(item));
json.put("objects", array);
}
json.put("packagePrivateValue", obj.getPackagePrivateValue());
json.put("protectedValue", obj.getProtectedValue());
json.put("shortValue", obj.getShortValue());
if (obj.getStringSet() != null) {
JsonArray array = new JsonArray();
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/io/vertx/test/codegen/DataObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testObjectProperty() throws Exception {
public void testPropertySetters() throws Exception {
DataObjectModel model = new GeneratorHelper().generateDataObject(PropertySetters.class);
assertNotNull(model);
assertEquals(14, model.getPropertyMap().size());
assertEquals(16, model.getPropertyMap().size());
assertProperty(model.getPropertyMap().get("string"), "string", "setString", null, null, TypeReflectionFactory.create(String.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("boxedInteger"), "boxedInteger", "setBoxedInteger", null, null, TypeReflectionFactory.create(Integer.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("primitiveInteger"), "primitiveInteger", "setPrimitiveInteger", null, null, TypeReflectionFactory.create(int.class), true, PropertyKind.VALUE, true);
Expand All @@ -101,6 +101,8 @@ public void testPropertySetters() throws Exception {
assertProperty(model.getPropertyMap().get("jsonObject"), "jsonObject", "setJsonObject", null, null, TypeReflectionFactory.create(JsonObject.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("jsonArray"), "jsonArray", "setJsonArray", null, null, TypeReflectionFactory.create(JsonArray.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("enumerated"), "enumerated", "setEnumerated", null, null, TypeReflectionFactory.create(Enumerated.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("protectedString"), "protectedString", "setProtectedString", null, null, TypeReflectionFactory.create(String.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("packagePrivateString"), "packagePrivateString", "setPackagePrivateString", null, null, TypeReflectionFactory.create(String.class), true, PropertyKind.VALUE, true);
}

@Test
Expand Down Expand Up @@ -256,7 +258,7 @@ public void testPropertyMapSetterAdders() throws Exception {
public void testPropertyGetters() throws Exception {
DataObjectModel model = new GeneratorHelper().generateDataObject(PropertyGetters.class);
assertNotNull(model);
assertEquals(14, model.getPropertyMap().size());
assertEquals(16, model.getPropertyMap().size());
assertProperty(model.getPropertyMap().get("string"), "string", null, null, "getString", TypeReflectionFactory.create(String.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("boxedInteger"), "boxedInteger", null, null, "getBoxedInteger", TypeReflectionFactory.create(Integer.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("primitiveInteger"), "primitiveInteger", null, null, "getPrimitiveInteger", TypeReflectionFactory.create(int.class), true, PropertyKind.VALUE, true);
Expand All @@ -271,6 +273,8 @@ public void testPropertyGetters() throws Exception {
assertProperty(model.getPropertyMap().get("jsonObject"), "jsonObject", null, null, "getJsonObject", TypeReflectionFactory.create(JsonObject.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("jsonArray"), "jsonArray", null, null, "getJsonArray", TypeReflectionFactory.create(JsonArray.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("enumerated"), "enumerated", null, null, "getEnumerated", TypeReflectionFactory.create(Enumerated.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("protectedString"), "protectedString", null, null, "getProtectedString", TypeReflectionFactory.create(String.class), true, PropertyKind.VALUE, true);
assertProperty(model.getPropertyMap().get("packagePrivateString"), "packagePrivateString", null, null, "getPackagePrivateString", TypeReflectionFactory.create(String.class), true, PropertyKind.VALUE, true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public void testJsonToDataObject() {
json.put("keyedEnumValues", new JsonObject().put(key, httpMethod.name()));
json.put("keyedDateTimeValues", new JsonObject().put(key, zonedDateTimeCodec.encode(dateTime)));
json.put("keyedObjectValues", toJson(map));
json.put("packagePrivateValue", intValue);
json.put("protectedValue", intValue);

TestDataObject obj = new TestDataObject();
TestDataObjectConverter.fromJson(json, obj);
Expand Down Expand Up @@ -290,6 +292,8 @@ public void testJsonToDataObject() {
assertEquals(Collections.singletonMap(key, httpMethod), obj.getKeyedEnumValues());
assertEquals(Collections.singletonMap(key, dateTime), obj.getKeyedDateTimeValues());
assertEquals(map, obj.getObjectMap());
assertEquals(intValue, obj.getPackagePrivateValue());
assertEquals(intValue, obj.getProtectedValue());

// Sometimes json can use java collections so test it runs fine in this case
// json = new JsonObject();
Expand Down Expand Up @@ -524,6 +528,8 @@ public void testDataObjectToJson() {
obj.addKeyedEnumValue(key, httpMethod);
obj.addKeyedDateTimeValue(key, dateTime);
map.forEach(obj::addKeyedObjectValue);
obj.setPackagePrivateValue(intValue);
obj.setProtectedValue(intValue);

Map<String, Object> json = new HashMap<>();
TestDataObjectConverter.toJson(obj, json);
Expand Down Expand Up @@ -623,6 +629,8 @@ public void testDataObjectToJson() {
assertEquals(new JsonObject().put(key, httpMethod.name()), json.get("keyedEnumValues"));
assertEquals(new JsonObject().put(key, zonedDateTimeCodec.encode(dateTime)), json.get("keyedDateTimeValues"));
assertEquals(toJson(map), json.get("keyedObjectValues"));
assertEquals(intValue, json.get("packagePrivateValue"));
assertEquals(intValue, json.get("protectedValue"));
}

@Test
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/io/vertx/test/codegen/converter/TestDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class TestDataObject {
private TimeUnit httpMethod;
private ZonedDateTime dateTime;
private NoConverterDataObject notEncodableDataObject;
private int packagePrivateValue;
private int protectedValue;

private List<String> stringValues;
private List<Boolean> boxedBooleanValues;
Expand Down Expand Up @@ -1113,4 +1115,20 @@ public TestDataObject setNotEncodableDataObjectMap(Map<String, NoConverterDataOb
this.notEncodableDataObjectMap = notEncodableDataObjectMap;
return this;
}

int getPackagePrivateValue() {
return packagePrivateValue;
}

void setPackagePrivateValue(int packagePrivateValue) {
this.packagePrivateValue = packagePrivateValue;
}

protected int getProtectedValue() {
return protectedValue;
}

protected void setProtectedValue(int protectedValue) {
this.protectedValue = protectedValue;
}
}