Commit 152388ba authored by Daniel Bluhm's avatar Daniel Bluhm

More PR cleanup

Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 97131c75
/*******************************************************************************
* Copyright (c) 2020- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Daniel Bluhm - Initial implementation
*******************************************************************************/
package org.eclipse.ice.dev.annotations.processors; package org.eclipse.ice.dev.annotations.processors;
import java.util.Arrays; import java.util.Arrays;
...@@ -17,13 +7,11 @@ import java.util.UUID; ...@@ -17,13 +7,11 @@ import java.util.UUID;
import org.eclipse.ice.data.JavascriptValidator; import org.eclipse.ice.data.JavascriptValidator;
/** /**
* Aggregation of fields generated and included in <code>@DataElement</code> by * Aggregation of fields generated and included in <code>@DataElement</code>
* default. * by default.
*/ */
public class DefaultFields { public class DefaultFields {
private DefaultFields() {}
/** /**
* The private UUID of this element. * The private UUID of this element.
* *
...@@ -45,71 +33,106 @@ public class DefaultFields { ...@@ -45,71 +33,106 @@ public class DefaultFields {
/** /**
* A unique identifier for this element. * A unique identifier for this element.
*/ */
private static Field id = Field.builder().name("id").type(long.class) private static Field id = Field.builder()
.docString("A unique identifier for this element.").defaultValue(javaSource(0L)).defaultField(true).build(); .name("id")
.type(long.class)
.docString("A unique identifier for this element.")
.defaultValue(javaSource(0L))
.defaultField(true)
.build();
/** /**
* A simple name for the data. * A simple name for the data.
*/ */
private static Field name = Field.builder().name("name").type(String.class).docString("A simple name for the data.") private static Field name = Field.builder()
.defaultValue(javaSource("name")).defaultField(true).build(); .name("name")
.type(String.class)
.docString("A simple name for the data.")
.defaultValue(javaSource("name"))
.defaultField(true)
.build();
/** /**
* A simple description of the data. * A simple description of the data.
*/ */
private static Field description = Field.builder().name("description").type(String.class) private static Field description = Field.builder()
.docString("A simple description of the data").defaultValue(javaSource("description")).defaultField(true) .name("description")
.build(); .type(String.class)
.docString("A simple description of the data")
.defaultValue(javaSource("description"))
.defaultField(true)
.build();
/** /**
* A comment that annotates the data in a meaningful way. * A comment that annotates the data in a meaningful way.
*/ */
private static Field comment = Field.builder().name("comment").type(String.class) private static Field comment = Field.builder()
.docString("A comment that annotates the data in a meaningful way.").defaultValue(javaSource("no comment")) .name("comment")
.defaultField(true).build(); .type(String.class)
.docString("A comment that annotates the data in a meaningful way.")
.defaultValue(javaSource("no comment"))
.defaultField(true)
.build();
/** /**
* The context (a tag) in which the data should be considered. * The context (a tag) in which the data should be considered.
*/ */
private static Field context = Field.builder().name("context").type(String.class) private static Field context = Field.builder()
.docString("The context (a tag) in which the data should be considered.") .name("context")
.defaultValue(javaSource("default")).defaultField(true).build(); .type(String.class)
.docString("The context (a tag) in which the data should be considered.")
.defaultValue(javaSource("default"))
.defaultField(true)
.build();
/** /**
* This value is true if the element should be regarded as a client as required. * This value is true if the element should be regarded as a client as required.
*/ */
private static Field required = Field.builder().name("required").type(boolean.class) private static Field required = Field.builder()
.docString("This value is true if the element should be regarded by the client as required.") .name("required")
.defaultValue(javaSource(false)).defaultField(true).build(); .type(boolean.class)
.docString("This value is true if the element should be regarded by the client as required.")
.defaultValue(javaSource(false))
.defaultField(true)
.build();
/** /**
* This value is true if the element should be regarded as a secret by a client, * This value is true if the element should be regarded as a secret by a client,
* such as for passwords. * such as for passwords.
*/ */
private static Field secret = Field.builder().name("secret").type(boolean.class).docString( private static Field secret = Field.builder()
"This value is true if the element should be regarded as a secret by the client, such as for passwords.") .name("secret")
.defaultValue(javaSource(false)).defaultField(true).build(); .type(boolean.class)
.docString("This value is true if the element should be regarded as a secret by the client, such as for passwords.")
.defaultValue(javaSource(false))
.defaultField(true)
.build();
/** /**
* The validator used to check the correctness of the data. * The validator used to check the correctness of the data.
*/ */
private static Field validator = Field.builder().name("validator") private static Field validator = Field.builder()
.type(JavascriptValidator.class.getCanonicalName() + "<$interface>") .name("validator")
.docString("The validator used to check the correctness of the data.").nullable(true).defaultField(true) .type(JavascriptValidator.class.getCanonicalName() + "<$interface>")
.searchable(false).build(); .docString("The validator used to check the correctness of the data.")
.nullable(true)
.defaultField(true)
.searchable(false)
.build();
/** /**
* Get the statically defined default fields. * Get the statically defined default fields.
*
* @return list of Fields * @return list of Fields
*/ */
public static List<Field> get() { public static List<Field> get() {
return Arrays.asList(privateId, id, name, description, comment, context, required, secret, validator); return Arrays.asList(
privateId, id, name, description, comment,
context, required, secret, validator
);
} }
/** /**
* Format long as String for use as default value initializer. * Format long as String for use as default value initializer.
*
* @param value the value to be formatted. * @param value the value to be formatted.
* @return String * @return String
*/ */
...@@ -119,7 +142,6 @@ public class DefaultFields { ...@@ -119,7 +142,6 @@ public class DefaultFields {
/** /**
* Format String as escaped String for use as default value initializer. * Format String as escaped String for use as default value initializer.
*
* @param value the value to be formatted. * @param value the value to be formatted.
* @return String * @return String
*/ */
...@@ -129,7 +151,6 @@ public class DefaultFields { ...@@ -129,7 +151,6 @@ public class DefaultFields {
/** /**
* Format boolean as String for use as default value initializer. * Format boolean as String for use as default value initializer.
*
* @param value the value to be formatted. * @param value the value to be formatted.
* @return String * @return String
*/ */
......
...@@ -299,7 +299,11 @@ public class Field { ...@@ -299,7 +299,11 @@ public class Field {
*/ */
@JsonIgnore @JsonIgnore
public FieldBuilder modifiersToString(Set<Modifier> modifiers) { public FieldBuilder modifiersToString(Set<Modifier> modifiers) {
return this.modifiers(modifiers.stream().map(Object::toString).collect(Collectors.toSet())); return this.modifiers(
modifiers.stream()
.map(Object::toString)
.collect(Collectors.toSet())
);
} }
} }
} }
...@@ -59,7 +59,9 @@ public class Fields implements Iterable<Field> { ...@@ -59,7 +59,9 @@ public class Fields implements Iterable<Field> {
* @see Field#isConstant() * @see Field#isConstant()
*/ */
public Iterator<Field> getConstants() { public Iterator<Field> getConstants() {
return fields.stream().filter(Field::isConstant).iterator(); return fields.stream()
.filter(Field::isConstant)
.iterator();
} }
/** /**
...@@ -69,7 +71,9 @@ public class Fields implements Iterable<Field> { ...@@ -69,7 +71,9 @@ public class Fields implements Iterable<Field> {
* @see Field#isConstant() * @see Field#isConstant()
*/ */
public Iterator<Field> getMutable() { public Iterator<Field> getMutable() {
return fields.stream().filter(field -> !field.isConstant()).iterator(); return fields.stream()
.filter(field -> !field.isConstant())
.iterator();
} }
/** /**
...@@ -79,7 +83,9 @@ public class Fields implements Iterable<Field> { ...@@ -79,7 +83,9 @@ public class Fields implements Iterable<Field> {
* @see org.eclipse.ice.data.IDataElement#matches(Object) * @see org.eclipse.ice.data.IDataElement#matches(Object)
*/ */
public Iterator<Field> getMatch() { public Iterator<Field> getMatch() {
return fields.stream().filter(Field::isMatch).iterator(); return fields.stream()
.filter(Field::isMatch)
.iterator();
} }
/** /**
...@@ -90,7 +96,9 @@ public class Fields implements Iterable<Field> { ...@@ -90,7 +96,9 @@ public class Fields implements Iterable<Field> {
* @see Field#isVarDifferent() * @see Field#isVarDifferent()
*/ */
public Iterator<Field> getVarNamesDiffer() { public Iterator<Field> getVarNamesDiffer() {
return fields.stream().filter(Field::isVarNameDifferent).iterator(); return fields.stream()
.filter(Field::isVarNameDifferent)
.iterator();
} }
/** /**
......
...@@ -97,6 +97,7 @@ public class PersistenceHandlerWriter ...@@ -97,6 +97,7 @@ public class PersistenceHandlerWriter
interfaceName, String implementation, String collection, @NonNull Fields interfaceName, String implementation, String collection, @NonNull Fields
fields, @NonNull Types types fields, @NonNull Types types
) { ) {
super();
this.template = TEMPLATE; this.template = TEMPLATE;
this.className = className; this.className = className;
this.context.put(PACKAGE, packageName); this.context.put(PACKAGE, packageName);
......
/**
* $name DataElement.
*/
import { DataElement } from "DataElement";
export class $name extends DataElement {
#foreach($field in $fields)
${field.VarName}?: $primitiveMap["${field.Type}"];
#end
constructor() {
super();
}
}
\ No newline at end of file
...@@ -48,9 +48,9 @@ ...@@ -48,9 +48,9 @@
#macro(fieldparametertype)#nonnull("", " ")#fieldtype#end #macro(fieldparametertype)#nonnull("", " ")#fieldtype#end
## Get field declaration ## Get field declaration
#macro(fielddecl $mutable) #macro(fielddecl)
#@settab(1) #@settab(1)
#if(${field.DefaultValue} && $mutable) @Builder.Default #end#join(" ", ${field.Annotations})#join(" ", ${field.Modifiers})#fieldtype() ${field.VarName}#if(${field.DefaultValue}) = #evaluate(${field.DefaultValue})#end; #join(" ", ${field.Annotations})#join(" ", ${field.Modifiers})#fieldtype() ${field.VarName}#if(${field.DefaultValue}) = #evaluate(${field.DefaultValue})#end;
#end #end
#end #end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment