From ea7f195c774d2c6b4e2a546e90d4d02a190180b9 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 27 May 2020 17:14:29 -0400 Subject: [PATCH] Generate comments for the default fields Signed-off-by: Daniel Bluhm --- .../ice/dev/annotations/processors/DefaultFields.java | 9 +++++++++ .../eclipse/ice/dev/annotations/processors/Field.java | 5 +++++ .../src/main/resources/templates/DataElement.vm | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/DefaultFields.java b/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/DefaultFields.java index 58d716f96..8ef124498 100644 --- a/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/DefaultFields.java +++ b/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/DefaultFields.java @@ -18,6 +18,7 @@ public class DefaultFields { private static Field privateId = Field.builder() .name("privateId") .type(UUID.class) + .comment("The private UUID of this element. This field is left out of matches().") .defaultValue(Field.raw("UUID.randomUUID()")) .match(false) .build(); @@ -28,6 +29,7 @@ public class DefaultFields { private static Field id = Field.builder() .name("id") .type(long.class) + .comment("A unique identifier for this element.") .defaultValue(0L) .build(); @@ -37,6 +39,7 @@ public class DefaultFields { private static Field name = Field.builder() .name("name") .type(String.class) + .comment("A simple name for the data.") .defaultValue("name") .build(); @@ -46,6 +49,7 @@ public class DefaultFields { private static Field description = Field.builder() .name("description") .type(String.class) + .comment("A simple description of the data") .defaultValue("description") .build(); @@ -55,6 +59,7 @@ public class DefaultFields { private static Field comment = Field.builder() .name("comment") .type(String.class) + .comment("A comment that annotates the data in a meaningful way.") .defaultValue("no comment") .build(); @@ -64,6 +69,7 @@ public class DefaultFields { private static Field context = Field.builder() .name("context") .type(String.class) + .comment("The context (a tag) in which the data should be considered.") .defaultValue("default") .build(); @@ -73,6 +79,7 @@ public class DefaultFields { private static Field required = Field.builder() .name("required") .type(boolean.class) + .comment("This value is true if the element should be regarded by the client as required.") .defaultValue(false) .build(); @@ -83,6 +90,7 @@ public class DefaultFields { private static Field secret = Field.builder() .name("secret") .type(boolean.class) + .comment("This value is true if the element should be regarded as a secret by the client, such as for passwords.") .defaultValue(false) .build(); @@ -92,6 +100,7 @@ public class DefaultFields { private static Field validator = Field.builder() .name("validator") .type(Field.raw("JavascriptValidator<$class>")) + .comment("The validator used to check the correctness of the data.") .nullable(true) .build(); diff --git a/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/Field.java b/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/Field.java index 009844b6c..dc98d15bc 100644 --- a/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/Field.java +++ b/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/Field.java @@ -28,6 +28,11 @@ public class Field { */ String defaultValue; + /** + * Comment to add to the field declaration. + */ + String comment; + /** * Whether or not this field can be null. * diff --git a/org.eclipse.ice.dev.annotations/src/main/resources/templates/DataElement.vm b/org.eclipse.ice.dev.annotations/src/main/resources/templates/DataElement.vm index 174b57eb9..3a6655ce8 100644 --- a/org.eclipse.ice.dev.annotations/src/main/resources/templates/DataElement.vm +++ b/org.eclipse.ice.dev.annotations/src/main/resources/templates/DataElement.vm @@ -34,6 +34,12 @@ public class ${class} implements ${interface}, Serializable, IDataElement { private static final Logger logger = LoggerFactory.getLogger(${class}.class); #foreach($field in $fields) + + #if(${field.Comment}) + /** + * ${field.Comment} + */ + #end #if(!${field.Nullable} && !${field.Primitive}) @NonNull #else #{end}protected #evaluate(${field.Type}) ${field.Name}#if(${field.DefaultValue}) = #evaluate(${field.DefaultValue})#end; #end