From f03da9f9dce05f9c58dbb636e606cb2f2d0d75e1 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Wed, 26 Jun 2019 12:00:19 +0200 Subject: [PATCH] Now DataObject allows set/get package-private & protected Signed-off-by: slinkydeveloper --- .../java/io/vertx/codegen/DataObjectModel.java | 2 +- .../converter/TestDataObjectConverter.java | 12 ++++++++++++ .../io/vertx/test/codegen/DataObjectTest.java | 8 ++++++-- .../test/codegen/converter/DataObjectTest.java | 8 ++++++++ .../test/codegen/converter/TestDataObject.java | 18 ++++++++++++++++++ 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/vertx/codegen/DataObjectModel.java b/src/main/java/io/vertx/codegen/DataObjectModel.java index da175b175..b385dd7c6 100644 --- a/src/main/java/io/vertx/codegen/DataObjectModel.java +++ b/src/main/java/io/vertx/codegen/DataObjectModel.java @@ -349,7 +349,7 @@ private void processMethods(List 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(); diff --git a/src/test/generated/io/vertx/test/codegen/converter/TestDataObjectConverter.java b/src/test/generated/io/vertx/test/codegen/converter/TestDataObjectConverter.java index 09975fe06..daff5fa46 100644 --- a/src/test/generated/io/vertx/test/codegen/converter/TestDataObjectConverter.java +++ b/src/test/generated/io/vertx/test/codegen/converter/TestDataObjectConverter.java @@ -867,6 +867,16 @@ public static void fromJson(Iterable> 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()); @@ -1350,6 +1360,8 @@ public static void toJson(TestDataObject obj, java.util.Map 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(); diff --git a/src/test/java/io/vertx/test/codegen/DataObjectTest.java b/src/test/java/io/vertx/test/codegen/DataObjectTest.java index 9e2fd0608..682d7005f 100644 --- a/src/test/java/io/vertx/test/codegen/DataObjectTest.java +++ b/src/test/java/io/vertx/test/codegen/DataObjectTest.java @@ -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); @@ -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 @@ -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); @@ -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 diff --git a/src/test/java/io/vertx/test/codegen/converter/DataObjectTest.java b/src/test/java/io/vertx/test/codegen/converter/DataObjectTest.java index fd0884c81..bb4fcea54 100644 --- a/src/test/java/io/vertx/test/codegen/converter/DataObjectTest.java +++ b/src/test/java/io/vertx/test/codegen/converter/DataObjectTest.java @@ -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); @@ -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(); @@ -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 json = new HashMap<>(); TestDataObjectConverter.toJson(obj, json); @@ -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 diff --git a/src/test/java/io/vertx/test/codegen/converter/TestDataObject.java b/src/test/java/io/vertx/test/codegen/converter/TestDataObject.java index f453a17e6..5c21a3559 100644 --- a/src/test/java/io/vertx/test/codegen/converter/TestDataObject.java +++ b/src/test/java/io/vertx/test/codegen/converter/TestDataObject.java @@ -50,6 +50,8 @@ public class TestDataObject { private TimeUnit httpMethod; private ZonedDateTime dateTime; private NoConverterDataObject notEncodableDataObject; + private int packagePrivateValue; + private int protectedValue; private List stringValues; private List boxedBooleanValues; @@ -1113,4 +1115,20 @@ public TestDataObject setNotEncodableDataObjectMap(Map