Commit 9ca3eb31 authored by Daniel Bluhm's avatar Daniel Bluhm
Browse files

Pass types to source writers


Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 071f99b6
......@@ -149,6 +149,7 @@ public class DataElementProcessor extends AbstractProcessor {
.className(element.getImplName())
.interfaceName(element.getName())
.fields(fields)
.types(fields.getTypes())
.build()
.write(writer);
}
......@@ -178,6 +179,7 @@ public class DataElementProcessor extends AbstractProcessor {
.implementation(element.getImplName())
.collection(collectionName)
.fields(fields)
.types(fields.getTypes())
.build()
.write(writer);
}
......@@ -200,6 +202,7 @@ public class DataElementProcessor extends AbstractProcessor {
.packageName(element.getPackageName())
.interfaceName(element.getName())
.fields(fields)
.types(new Types(fields.getInterfaceFields()))
.build()
.write(writer);
}
......
......@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* A collection of Field objects to be used especially in template rendering.
......@@ -86,6 +87,24 @@ public class Fields implements Iterable<Field> {
.iterator();
}
/**
* Return iterable of fields needed for interface.
* @return Iterable of fields needed for interface.
*/
public Iterable<Field> getInterfaceFields() {
return fields.stream()
.filter(field -> !field.isDefaultField())
.collect(Collectors.toList());
}
/**
* Return Types instance for this set of Fields.
* @return Types instance
*/
public Types getTypes() {
return new Types(this);
}
/**
* Returns an iterator over the mutable fields found in this collection. The
* mutable fields are the default set iterated over because they are the most
......
......@@ -12,6 +12,7 @@
package org.eclipse.ice.dev.annotations.processors;
import lombok.Builder;
import lombok.NonNull;
/**
* Writer for DataElement Implementation classes.
......@@ -42,6 +43,11 @@ public class ImplementationWriter extends VelocitySourceWriter {
*/
private static final String FIELDS = "fields";
/**
* Context key for types.
*/
private static final String TYPES = "types";
/**
* Context key for class.
*/
......@@ -49,7 +55,8 @@ public class ImplementationWriter extends VelocitySourceWriter {
@Builder
public ImplementationWriter(
String packageName, String interfaceName, String className, Fields fields
String packageName, String interfaceName, String className,
@NonNull Fields fields, @NonNull Types types
) {
super();
this.template = IMPL_TEMPLATE;
......@@ -57,5 +64,7 @@ public class ImplementationWriter extends VelocitySourceWriter {
this.context.put(INTERFACE, interfaceName);
this.context.put(CLASS, className);
this.context.put(FIELDS, fields);
this.context.put(FIELDS, fields);
this.context.put(TYPES, types);
}
}
......@@ -43,14 +43,21 @@ public class InterfaceWriter extends VelocitySourceWriter {
*/
private static final String FIELDS = "fields";
/**
* Context key for types.
*/
private static final String TYPES = "types";
@Builder
public InterfaceWriter(
String packageName, String interfaceName, @NonNull Fields fields
String packageName, String interfaceName, @NonNull Fields fields,
@NonNull Types types
) {
super();
this.template = TEMPLATE;
context.put(PACKAGE, packageName);
context.put(INTERFACE, interfaceName);
context.put(FIELDS, fields);
context.put(TYPES, types);
}
}
......@@ -63,11 +63,16 @@ public class PersistenceHandlerWriter extends VelocitySourceWriter {
*/
private static final String FIELDS = "fields";
/**
* Context key for types.
*/
private static final String TYPES = "types";
@Builder
public PersistenceHandlerWriter(
String packageName, String elementInterface, String interfaceName,
String className, String implementation, String collection,
@NonNull Fields fields
@NonNull Fields fields, @NonNull Types types
) {
super();
this.template = PERSISTENCE_HANDLER_TEMPLATE;
......@@ -78,5 +83,6 @@ public class PersistenceHandlerWriter extends VelocitySourceWriter {
this.context.put(COLLECTION, collection);
this.context.put(IMPLEMENTATION, implementation);
this.context.put(FIELDS, fields);
this.context.put(TYPES, types);
}
}
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