Commit 88a975ac authored by Daniel Bluhm's avatar Daniel Bluhm
Browse files

Fix formatting and trailing whitespace


Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent e8d5db61
...@@ -23,7 +23,7 @@ import org.eclipse.ice.dev.annotations.DataField; ...@@ -23,7 +23,7 @@ import org.eclipse.ice.dev.annotations.DataField;
/** /**
* Flavor of ICEAnnotationExtractionService that specializes in extracting data * Flavor of ICEAnnotationExtractionService that specializes in extracting data
* from Spec classes with the class level annotation of {@link DataElement} * from Spec classes with the class level annotation of {@link DataElement}
* *
* @author Michael Walsh * @author Michael Walsh
*/ */
public class DataElementAnnotationExtractor { public class DataElementAnnotationExtractor {
...@@ -32,9 +32,14 @@ public class DataElementAnnotationExtractor { ...@@ -32,9 +32,14 @@ public class DataElementAnnotationExtractor {
* Annotations to not be transfered from member variables of Spec classes to * Annotations to not be transfered from member variables of Spec classes to
* final generated classes * final generated classes
*/ */
private static final List<String> nonTransferableAnnotations = Stream.of(DataField.class, DataField.Default.class) private static final List<String> nonTransferableAnnotations =
Stream.of(DataField.class, DataField.Default.class)
.map(Class::getCanonicalName) .map(Class::getCanonicalName)
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); .collect(
Collectors.collectingAndThen(
Collectors.toList(), Collections::unmodifiableList
)
);
/** /**
* used for extracting and preparing data for writer generation * used for extracting and preparing data for writer generation
...@@ -48,12 +53,14 @@ public class DataElementAnnotationExtractor { ...@@ -48,12 +53,14 @@ public class DataElementAnnotationExtractor {
/** /**
* Constructor that lets you initialize the {@link DataElementAnnotationExtractor} with different * Constructor that lets you initialize the {@link DataElementAnnotationExtractor} with different
* implementations of {@link ICEAnnotationExtractionService} and {@link WriterGenerator} * implementations of {@link ICEAnnotationExtractionService} and {@link WriterGenerator}
* @param annotationExtractionService * @param annotationExtractionService
* @param writerGenerator * @param writerGenerator
*/ */
DataElementAnnotationExtractor(ICEAnnotationExtractionService annotationExtractionService, DataElementAnnotationExtractor(
WriterGenerator writerGenerator) { ICEAnnotationExtractionService annotationExtractionService,
WriterGenerator writerGenerator
) {
this.annotationExtractionService = annotationExtractionService; this.annotationExtractionService = annotationExtractionService;
this.writerGenerator = writerGenerator; this.writerGenerator = writerGenerator;
this.annotationExtractionService.setNonTransferableAnnotations(nonTransferableAnnotations); this.annotationExtractionService.setNonTransferableAnnotations(nonTransferableAnnotations);
...@@ -61,22 +68,23 @@ public class DataElementAnnotationExtractor { ...@@ -61,22 +68,23 @@ public class DataElementAnnotationExtractor {
} }
/** /**
* For a given request it will extract data from client classes * For a given request it will extract data from client classes
* and generate a list of {@link VelocitySourceWriter} * and generate a list of {@link VelocitySourceWriter}
* *
* @param request * @param request
* @return list of generated SourceWriters * @return list of generated SourceWriters
* @throws IOException due to {@link ICEAnnotationExtractionService#extract(AnnotationExtractionRequest)} * @throws IOException due to {@link ICEAnnotationExtractionService#extract(AnnotationExtractionRequest)}
*/ */
public List<VelocitySourceWriter> generateWriters(AnnotationExtractionRequest request) throws IOException { public List<VelocitySourceWriter> generateWriters(
AnnotationExtractionRequest request
) throws IOException {
AnnotationExtractionResponse response = annotationExtractionService.extract(request); AnnotationExtractionResponse response = annotationExtractionService.extract(request);
List<VelocitySourceWriter> writerList = writerGenerator.generateWriters(request.getElement(),response); return writerGenerator.generateWriters(request.getElement(),response);
return writerList;
} }
/** /**
* For a given request it will generate then execute writers * For a given request it will generate then execute writers
* *
* @param request * @param request
* @throws IOException * @throws IOException
*/ */
...@@ -92,12 +100,11 @@ public class DataElementAnnotationExtractor { ...@@ -92,12 +100,11 @@ public class DataElementAnnotationExtractor {
/** /**
* Determine if the passed field is a DataField. * Determine if the passed field is a DataField.
* *
* @param element to check * @param element to check
* @return whether element is a DataField * @return whether element is a DataField
*/ */
public static boolean isDataField(Element element) { public static boolean isDataField(Element element) {
return element.getAnnotation(DataField.class) != null; return element.getAnnotation(DataField.class) != null;
} }
} }
...@@ -30,9 +30,6 @@ public class DataElementImplementationWriter extends ImplementationWriter { ...@@ -30,9 +30,6 @@ public class DataElementImplementationWriter extends ImplementationWriter {
/** /**
* Location of DataElement template for use with velocity. * Location of DataElement template for use with velocity.
*
* Use of Velocity ClasspathResourceLoader means files are discovered relative
* to the src/main/resources folder.
*/ */
private static final String IMPL_TEMPLATE = "templates/DataElement.vm"; private static final String IMPL_TEMPLATE = "templates/DataElement.vm";
...@@ -46,8 +43,10 @@ public class DataElementImplementationWriter extends ImplementationWriter { ...@@ -46,8 +43,10 @@ public class DataElementImplementationWriter extends ImplementationWriter {
* @param generatedFile * @param generatedFile
*/ */
@Builder @Builder
public DataElementImplementationWriter(String packageName, String interfaceName, String className, Fields fields, public DataElementImplementationWriter(
Types types, FileObject generatedFile) { String packageName, String interfaceName, String className, Fields
fields, Types types, FileObject generatedFile
) {
super(packageName, interfaceName, className, fields, types, generatedFile); super(packageName, interfaceName, className, fields, types, generatedFile);
this.template = IMPL_TEMPLATE; this.template = IMPL_TEMPLATE;
} }
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2020- UT-Battelle, LLC. * Copyright (c) 2020- UT-Battelle, LLC. All rights reserved. This program and
* All rights reserved. This program and the accompanying materials * the accompanying materials are made available under the terms of the Eclipse
* are made available under the terms of the Eclipse Public License v1.0 * Public License v1.0 which accompanies this distribution, and is available at
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors: Michael Walsh - Initial implementation
* Michael Walsh - Initial implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.ice.dev.annotations.processors; package org.eclipse.ice.dev.annotations.processors;
...@@ -24,7 +22,7 @@ import lombok.NonNull; ...@@ -24,7 +22,7 @@ import lombok.NonNull;
/** /**
* Implementation of the VelocitySourceWriter that handles generating the * Implementation of the VelocitySourceWriter that handles generating the
* DataElementInterfaceWriter * DataElementInterfaceWriter
* *
* @author Michael Walsh * @author Michael Walsh
*/ */
public class DataElementInterfaceWriter extends InterfaceWriter { public class DataElementInterfaceWriter extends InterfaceWriter {
...@@ -32,22 +30,24 @@ public class DataElementInterfaceWriter extends InterfaceWriter { ...@@ -32,22 +30,24 @@ public class DataElementInterfaceWriter extends InterfaceWriter {
/** /**
* Location of Interface template for use with velocity. * Location of Interface template for use with velocity.
* *
* Use of Velocity ClasspathResourceLoader means files are discovered relative * Use of Velocity ClasspathResourceLoader means files are discovered
* to the src/main/resources folder. * relative to the src/main/resources folder.
*/ */
private static final String TEMPLATE = "templates/ElementInterface.vm"; private static final String TEMPLATE = "templates/ElementInterface.vm";
/** /**
* Constructor * Constructor
* *
* @param packageName * @param packageName
* @param interfaceName * @param interfaceName
* @param fields * @param fields
* @param generatedFile * @param generatedFile
*/ */
@Builder @Builder
public DataElementInterfaceWriter(String packageName, String interfaceName, @NonNull Fields fields, public DataElementInterfaceWriter(
Types types, FileObject generatedFile) { String packageName, String interfaceName, @NonNull Fields fields,
Types types, FileObject generatedFile
) {
super(packageName, interfaceName, fields, types, generatedFile); super(packageName, interfaceName, fields, types, generatedFile);
this.template = TEMPLATE; this.template = TEMPLATE;
} }
...@@ -77,11 +77,10 @@ public class DataElementInterfaceWriter extends InterfaceWriter { ...@@ -77,11 +77,10 @@ public class DataElementInterfaceWriter extends InterfaceWriter {
/** /**
* Static method for cleanly fetching an initializer * Static method for cleanly fetching an initializer
* *
* @return DataElementInterfaceWriter init lambda * @return DataElementInterfaceWriter init lambda
*/ */
public static BiFunction<FileObject, Map, List<VelocitySourceWriter>> getContextInitializer() { public static BiFunction<FileObject, Map, List<VelocitySourceWriter>> getContextInitializer() {
return new DataElementInterfaceWriter().getInitializer(); return new DataElementInterfaceWriter().getInitializer();
} }
} }
...@@ -24,7 +24,7 @@ import lombok.NonNull; ...@@ -24,7 +24,7 @@ import lombok.NonNull;
/** /**
* Implementation of the VelocitySourceWriter that handles generating the * Implementation of the VelocitySourceWriter that handles generating the
* DataElementPersistenceHandlerWriter * DataElementPersistenceHandlerWriter
* *
* @author Michael Walsh * @author Michael Walsh
*/ */
public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWriter { public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWriter {
...@@ -39,7 +39,7 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite ...@@ -39,7 +39,7 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite
/** /**
* Constructor * Constructor
* *
* @param packageName * @param packageName
* @param elementInterface * @param elementInterface
* @param className * @param className
...@@ -50,11 +50,15 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite ...@@ -50,11 +50,15 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite
* @param generatedFile * @param generatedFile
*/ */
@Builder @Builder
public DataElementPersistenceHandlerWriter(String packageName, String elementInterface, String className, public DataElementPersistenceHandlerWriter(
String interfaceName, String implementation, String collection, @NonNull Fields fields, String packageName, String elementInterface, String className,
Types types, FileObject generatedFile) { String interfaceName, String implementation, String collection,
super(packageName, elementInterface, className, interfaceName, implementation, collection, fields, @NonNull Fields fields, Types types, FileObject generatedFile
types, generatedFile); ) {
super(
packageName, elementInterface, className, interfaceName,
implementation, collection, fields, types, generatedFile
);
this.template = PERSISTENCE_HANDLER_TEMPLATE; this.template = PERSISTENCE_HANDLER_TEMPLATE;
} }
...@@ -72,26 +76,27 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite ...@@ -72,26 +76,27 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite
*/ */
@Override @Override
public BiFunction<FileObject, Map, List<VelocitySourceWriter>> getInitializer() { public BiFunction<FileObject, Map, List<VelocitySourceWriter>> getInitializer() {
return (fileObject, context) -> return (fileObject, context) -> Arrays.asList(
Arrays.asList(DataElementPersistenceHandlerWriter.builder() DataElementPersistenceHandlerWriter.builder()
.packageName((String) context.get(MetaTemplateProperty.PACKAGE)) .packageName((String) context.get(MetaTemplateProperty.PACKAGE))
.className((String) context.get(PersistenceHandlerTemplateProperty.CLASS)) .className((String) context.get(PersistenceHandlerTemplateProperty.CLASS))
.types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes()) .interfaceName((String) context.get(PersistenceHandlerTemplateProperty.INTERFACE)) .types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes())
.fields((Fields) context.get(MetaTemplateProperty.FIELDS)) .interfaceName((String) context.get(PersistenceHandlerTemplateProperty.INTERFACE))
.types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes()) .fields((Fields) context.get(MetaTemplateProperty.FIELDS))
.elementInterface((String) context.get(PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE)) .types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes())
.collection((String) context.get(PersistenceHandlerTemplateProperty.COLLECTION)) .elementInterface((String) context.get(PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE))
.implementation((String) context.get(PersistenceHandlerTemplateProperty.IMPLEMENTATION)) .collection((String) context.get(PersistenceHandlerTemplateProperty.COLLECTION))
.generatedFile(fileObject).build()); .implementation((String) context.get(PersistenceHandlerTemplateProperty.IMPLEMENTATION))
.generatedFile(fileObject).build()
);
} }
/** /**
* Static method for cleanly fetching an initializer * Static method for cleanly fetching an initializer
* *
* @return DataElementPersistenceHandlerWriter init lambda * @return DataElementPersistenceHandlerWriter init lambda
*/ */
public static BiFunction<FileObject, Map, List<VelocitySourceWriter>> getContextInitializer() { public static BiFunction<FileObject, Map, List<VelocitySourceWriter>> getContextInitializer() {
return new DataElementPersistenceHandlerWriter().getInitializer(); return new DataElementPersistenceHandlerWriter().getInitializer();
} }
} }
...@@ -109,12 +109,9 @@ public class DataElementProcessor extends AbstractProcessor { ...@@ -109,12 +109,9 @@ public class DataElementProcessor extends AbstractProcessor {
ICEAnnotationExtractionService extractionService = new ICEAnnotationExtractionService(elementUtils, mapper, env, ICEAnnotationExtractionService extractionService = new ICEAnnotationExtractionService(elementUtils, mapper, env,
new DefaultNameGenerator()); new DefaultNameGenerator());
WriterGenerator writerGenerator = new DataElementWriterGenerator(env); WriterGenerator writerGenerator = new DataElementWriterGenerator(env);
this.extractor = new DataElementAnnotationExtractor(extractionService, writerGenerator); this.extractor = new DataElementAnnotationExtractor(
extractionService, writerGenerator
// Set up Velocity using the Singleton approach; ClasspathResourceLoader allows );
// us to load templates from src/main/resources
final Properties p = VelocityProperties.get();
Velocity.init(p);
super.init(env); super.init(env);
} }
......
...@@ -67,7 +67,9 @@ public class DataElementWriterGenerator extends AbstractWriterGenerator implemen ...@@ -67,7 +67,9 @@ public class DataElementWriterGenerator extends AbstractWriterGenerator implemen
* implementation, and possibly a persistence handler * implementation, and possibly a persistence handler
*/ */
@Override @Override
public List<VelocitySourceWriter> generateWriters(Element element, AnnotationExtractionResponse response) { public List<VelocitySourceWriter> generateWriters(
Element element, AnnotationExtractionResponse response
) {
List<VelocitySourceWriter> writers = new ArrayList<>(); List<VelocitySourceWriter> writers = new ArrayList<>();
Map<TemplateProperty, Object> classMetadata = response.getClassMetadata(); Map<TemplateProperty, Object> classMetadata = response.getClassMetadata();
boolean hasAnnotation = specExtractionHelper.hasAnnotation(element, Persisted.class); boolean hasAnnotation = specExtractionHelper.hasAnnotation(element, Persisted.class);
......
...@@ -90,7 +90,7 @@ public class ICEAnnotationExtractionService { ...@@ -90,7 +90,7 @@ public class ICEAnnotationExtractionService {
this.processingEnv = processingEnv; this.processingEnv = processingEnv;
this.nameGenerator = new DefaultNameGenerator(); this.nameGenerator = new DefaultNameGenerator();
} }
/** /**
* Constructor * Constructor
*/ */
...@@ -104,63 +104,78 @@ public class ICEAnnotationExtractionService { ...@@ -104,63 +104,78 @@ public class ICEAnnotationExtractionService {
/** /**
* Main entry point into the metadata extraction flow * Main entry point into the metadata extraction flow
* *
* @param request * @param request
* @return Extracted metadata * @return Extracted metadata
* @throws IOException * @throws IOException
*/ */
public AnnotationExtractionResponse extract(AnnotationExtractionRequest request) throws IOException { public AnnotationExtractionResponse extract(
AnnotationExtractionRequest request
) throws IOException {
Fields fields = extractFields(request); Fields fields = extractFields(request);
Map<TemplateProperty, Object> metaData = extractClassMetadata(request, fields); Map<TemplateProperty, Object> metaData = extractClassMetadata(request, fields);
return AnnotationExtractionResponse.builder().fields(fields).classMetadata(metaData).build(); return AnnotationExtractionResponse
.builder()
.fields(fields)
.classMetadata(metaData)
.build();
} }
/** /**
* Collect fields from Spec class, static default field collection, and json if * Collect fields from Spec class, static default field collection, and json if
* applicable * applicable
* *
* @param request * @param request
* @return Fields of the Spec class * @return Fields of the Spec class
* @throws IOException * @throws IOException
*/ */
public Fields extractFields(AnnotationExtractionRequest request) throws IOException { public Fields extractFields(
AnnotationExtractionRequest request
) throws IOException {
Fields fields = new Fields(); Fields fields = new Fields();
Element element = request.getElement(); Element element = request.getElement();
if (request.isIncludeDefaults()) if (request.isIncludeDefaults()) {
fields.collect(DefaultFields.get()); fields.collect(DefaultFields.get());
}
fields.collect( fields.collect(
specExtractionHelper.getAllFields(element, elementUtils, fieldFilter, nonTransferableAnnotations)); // get specExtractionHelper.getAllFields(
// all element, elementUtils, fieldFilter, nonTransferableAnnotations
// members )
// with ); // get all members with given filter
// given fields.collect(
// filter jsonExtractionHelper.collectFromDataFieldJson(
fields.collect(jsonExtractionHelper.collectFromDataFieldJson(element, processingEnv, mapper)); element, processingEnv, mapper
)
);
return fields; return fields;
} }
/** /**
* Parse, generate, and store class metadata in a map. * Parse, generate, and store class metadata in a map.
* *
* @param request * @param request
* @param fields * @param fields
* @return metadata map * @return metadata map
*/ */
public Map<TemplateProperty, Object> extractClassMetadata(AnnotationExtractionRequest request, Fields fields) { public Map<TemplateProperty, Object> extractClassMetadata(
AnnotationExtractionRequest request, Fields fields
) {
SpecClassMetadata specData = extractSpecData(request, fields); SpecClassMetadata specData = extractSpecData(request, fields);
Map<TemplateProperty, Object> context = generateClassMetadata(specData); return generateClassMetadata(specData);
return context;
} }
/** /**
* Given seed data extracted from a spec class, this method generates the * Given seed data extracted from a spec class, this method generates the
* necessary metadata for class generation * necessary metadata for class generation
* *
* @param specData * @param specData
* @return enum keyed map of extracted and processed class metadata * @return enum keyed map of extracted and processed class metadata
*/ */
protected Map<TemplateProperty, Object> generateClassMetadata(SpecClassMetadata specData) { protected Map<TemplateProperty, Object> generateClassMetadata(
SpecClassMetadata specData
) {
Map<TemplateProperty, Object> context = new HashMap<>(); Map<TemplateProperty, Object> context = new HashMap<>();
generateMetaTemplateData(specData, context); generateMetaTemplateData(specData, context);
...@@ -170,46 +185,83 @@ public class ICEAnnotationExtractionService { ...@@ -170,46 +185,83 @@ public class ICEAnnotationExtractionService {
}