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;
/**
* Flavor of ICEAnnotationExtractionService that specializes in extracting data
* from Spec classes with the class level annotation of {@link DataElement}
*
*
* @author Michael Walsh
*/
public class DataElementAnnotationExtractor {
......@@ -32,9 +32,14 @@ public class DataElementAnnotationExtractor {
* Annotations to not be transfered from member variables of Spec classes to
* 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)
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
.collect(
Collectors.collectingAndThen(
Collectors.toList(), Collections::unmodifiableList
)
);
/**
* used for extracting and preparing data for writer generation
......@@ -48,12 +53,14 @@ public class DataElementAnnotationExtractor {
/**
* 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 writerGenerator
*/
DataElementAnnotationExtractor(ICEAnnotationExtractionService annotationExtractionService,
WriterGenerator writerGenerator) {
DataElementAnnotationExtractor(
ICEAnnotationExtractionService annotationExtractionService,
WriterGenerator writerGenerator
) {
this.annotationExtractionService = annotationExtractionService;
this.writerGenerator = writerGenerator;
this.annotationExtractionService.setNonTransferableAnnotations(nonTransferableAnnotations);
......@@ -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}
*
*
* @param request
* @return list of generated SourceWriters
* @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);
List<VelocitySourceWriter> writerList = writerGenerator.generateWriters(request.getElement(),response);
return writerList;
return writerGenerator.generateWriters(request.getElement(),response);
}
/**
* For a given request it will generate then execute writers
*
*
* @param request
* @throws IOException
*/
......@@ -92,12 +100,11 @@ public class DataElementAnnotationExtractor {
/**
* Determine if the passed field is a DataField.
*
*
* @param element to check
* @return whether element is a DataField
*/
public static boolean isDataField(Element element) {
return element.getAnnotation(DataField.class) != null;
}
}
......@@ -30,9 +30,6 @@ public class DataElementImplementationWriter extends ImplementationWriter {
/**
* 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";
......@@ -46,8 +43,10 @@ public class DataElementImplementationWriter extends ImplementationWriter {
* @param generatedFile
*/
@Builder
public DataElementImplementationWriter(String packageName, String interfaceName, String className, Fields fields,
Types types, FileObject generatedFile) {
public DataElementImplementationWriter(
String packageName, String interfaceName, String className, Fields
fields, Types types, FileObject generatedFile
) {
super(packageName, interfaceName, className, fields, types, generatedFile);
this.template = IMPL_TEMPLATE;
}
......
/*******************************************************************************
* 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
* 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:
* Michael Walsh - Initial implementation
* Contributors: Michael Walsh - Initial implementation
*******************************************************************************/
package org.eclipse.ice.dev.annotations.processors;
......@@ -24,7 +22,7 @@ import lombok.NonNull;
/**
* Implementation of the VelocitySourceWriter that handles generating the
* DataElementInterfaceWriter
*
*
* @author Michael Walsh
*/
public class DataElementInterfaceWriter extends InterfaceWriter {
......@@ -32,22 +30,24 @@ public class DataElementInterfaceWriter extends InterfaceWriter {
/**
* Location of Interface template for use with velocity.
*
* Use of Velocity ClasspathResourceLoader means files are discovered relative
* to the src/main/resources folder.
* Use of Velocity ClasspathResourceLoader means files are discovered
* relative to the src/main/resources folder.
*/
private static final String TEMPLATE = "templates/ElementInterface.vm";
/**
* Constructor
*
*
* @param packageName
* @param interfaceName
* @param fields
* @param generatedFile
*/
@Builder
public DataElementInterfaceWriter(String packageName, String interfaceName, @NonNull Fields fields,
Types types, FileObject generatedFile) {
public DataElementInterfaceWriter(
String packageName, String interfaceName, @NonNull Fields fields,
Types types, FileObject generatedFile
) {
super(packageName, interfaceName, fields, types, generatedFile);
this.template = TEMPLATE;
}
......@@ -77,11 +77,10 @@ public class DataElementInterfaceWriter extends InterfaceWriter {
/**
* Static method for cleanly fetching an initializer
*
*
* @return DataElementInterfaceWriter init lambda
*/
public static BiFunction<FileObject, Map, List<VelocitySourceWriter>> getContextInitializer() {
return new DataElementInterfaceWriter().getInitializer();
}
}
......@@ -24,7 +24,7 @@ import lombok.NonNull;
/**
* Implementation of the VelocitySourceWriter that handles generating the
* DataElementPersistenceHandlerWriter
*
*
* @author Michael Walsh
*/
public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWriter {
......@@ -39,7 +39,7 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite
/**
* Constructor
*
*
* @param packageName
* @param elementInterface
* @param className
......@@ -50,11 +50,15 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite
* @param generatedFile
*/
@Builder
public DataElementPersistenceHandlerWriter(String packageName, String elementInterface, String className,
String interfaceName, String implementation, String collection, @NonNull Fields fields,
Types types, FileObject generatedFile) {
super(packageName, elementInterface, className, interfaceName, implementation, collection, fields,
types, generatedFile);
public DataElementPersistenceHandlerWriter(
String packageName, String elementInterface, String className,
String interfaceName, String implementation, String collection,
@NonNull Fields fields, Types types, FileObject generatedFile
) {
super(
packageName, elementInterface, className, interfaceName,
implementation, collection, fields, types, generatedFile
);
this.template = PERSISTENCE_HANDLER_TEMPLATE;
}
......@@ -72,26 +76,27 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite
*/
@Override
public BiFunction<FileObject, Map, List<VelocitySourceWriter>> getInitializer() {
return (fileObject, context) ->
Arrays.asList(DataElementPersistenceHandlerWriter.builder()
.packageName((String) context.get(MetaTemplateProperty.PACKAGE))
.className((String) context.get(PersistenceHandlerTemplateProperty.CLASS))
.types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes()) .interfaceName((String) context.get(PersistenceHandlerTemplateProperty.INTERFACE))
.fields((Fields) context.get(MetaTemplateProperty.FIELDS))
.types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes())
.elementInterface((String) context.get(PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE))
.collection((String) context.get(PersistenceHandlerTemplateProperty.COLLECTION))
.implementation((String) context.get(PersistenceHandlerTemplateProperty.IMPLEMENTATION))
.generatedFile(fileObject).build());
return (fileObject, context) -> Arrays.asList(
DataElementPersistenceHandlerWriter.builder()
.packageName((String) context.get(MetaTemplateProperty.PACKAGE))
.className((String) context.get(PersistenceHandlerTemplateProperty.CLASS))
.types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes())
.interfaceName((String) context.get(PersistenceHandlerTemplateProperty.INTERFACE))
.fields((Fields) context.get(MetaTemplateProperty.FIELDS))
.types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes())
.elementInterface((String) context.get(PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE))
.collection((String) context.get(PersistenceHandlerTemplateProperty.COLLECTION))
.implementation((String) context.get(PersistenceHandlerTemplateProperty.IMPLEMENTATION))
.generatedFile(fileObject).build()
);
}
/**
* Static method for cleanly fetching an initializer
*
*
* @return DataElementPersistenceHandlerWriter init lambda
*/
public static BiFunction<FileObject, Map, List<VelocitySourceWriter>> getContextInitializer() {
return new DataElementPersistenceHandlerWriter().getInitializer();
}
}
......@@ -109,12 +109,9 @@ public class DataElementProcessor extends AbstractProcessor {
ICEAnnotationExtractionService extractionService = new ICEAnnotationExtractionService(elementUtils, mapper, env,
new DefaultNameGenerator());
WriterGenerator writerGenerator = new DataElementWriterGenerator(env);
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);
this.extractor = new DataElementAnnotationExtractor(
extractionService, writerGenerator
);
super.init(env);
}
......
......@@ -67,7 +67,9 @@ public class DataElementWriterGenerator extends AbstractWriterGenerator implemen
* implementation, and possibly a persistence handler
*/
@Override
public List<VelocitySourceWriter> generateWriters(Element element, AnnotationExtractionResponse response) {
public List<VelocitySourceWriter> generateWriters(
Element element, AnnotationExtractionResponse response
) {
List<VelocitySourceWriter> writers = new ArrayList<>();
Map<TemplateProperty, Object> classMetadata = response.getClassMetadata();
boolean hasAnnotation = specExtractionHelper.hasAnnotation(element, Persisted.class);
......
......@@ -90,7 +90,7 @@ public class ICEAnnotationExtractionService {
this.processingEnv = processingEnv;
this.nameGenerator = new DefaultNameGenerator();
}
/**
* Constructor
*/
......@@ -104,63 +104,78 @@ public class ICEAnnotationExtractionService {
/**
* Main entry point into the metadata extraction flow
*
*
* @param request
* @return Extracted metadata
* @throws IOException
*/
public AnnotationExtractionResponse extract(AnnotationExtractionRequest request) throws IOException {
public AnnotationExtractionResponse extract(
AnnotationExtractionRequest request
) throws IOException {
Fields fields = extractFields(request);
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
* applicable
*
*
* @param request
* @return Fields of the Spec class
* @throws IOException
*/
public Fields extractFields(AnnotationExtractionRequest request) throws IOException {
public Fields extractFields(
AnnotationExtractionRequest request
) throws IOException {
Fields fields = new Fields();
Element element = request.getElement();
if (request.isIncludeDefaults())
if (request.isIncludeDefaults()) {
fields.collect(DefaultFields.get());
}
fields.collect(
specExtractionHelper.getAllFields(element, elementUtils, fieldFilter, nonTransferableAnnotations)); // get
// all
// members
// with
// given
// filter
fields.collect(jsonExtractionHelper.collectFromDataFieldJson(element, processingEnv, mapper));
specExtractionHelper.getAllFields(
element, elementUtils, fieldFilter, nonTransferableAnnotations
)
); // get all members with given filter
fields.collect(
jsonExtractionHelper.collectFromDataFieldJson(
element, processingEnv, mapper
)
);
return fields;
}
/**
* Parse, generate, and store class metadata in a map.
*
*
* @param request
* @param fields
* @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);
Map<TemplateProperty, Object> context = generateClassMetadata(specData);
return context;
return generateClassMetadata(specData);
}
/**
* Given seed data extracted from a spec class, this method generates the
* necessary metadata for class generation
*
*
* @param specData
* @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<>();
generateMetaTemplateData(specData, context);
......@@ -170,46 +185,83 @@ public class ICEAnnotationExtractionService {
}
/**
* Package meta data for class interface and implementation into the supplied
* Package meta data for class interface and implementation into the supplied
* map context
*
*
* @param specData metadata extracted from the client Spec class
* @param context map to store the processed metadata harvested from
* the client Spec class
*/
protected void generateMetaTemplateData(SpecClassMetadata specData, Map<TemplateProperty, Object> context) {
context.put(MetaTemplateProperty.PACKAGE, specData.getPackageName());
context.put(MetaTemplateProperty.INTERFACE, specData.getName());
context.put(MetaTemplateProperty.CLASS, nameGenerator.getImplName(specData.getName()));
context.put(MetaTemplateProperty.FIELDS, specData.getFields());
context.put(MetaTemplateProperty.QUALIFIED, specData.getFullyQualifiedName());
context.put(MetaTemplateProperty.QUALIFIEDIMPL,
nameGenerator.getQualifiedImplName(specData.getFullyQualifiedName()));
protected void generateMetaTemplateData(
SpecClassMetadata specData, Map<TemplateProperty, Object> context
) {
context.put(
MetaTemplateProperty.PACKAGE,
specData.getPackageName()
);
context.put(
MetaTemplateProperty.INTERFACE,
specData.getName()
);
context.put(
MetaTemplateProperty.CLASS,
nameGenerator.getImplName(specData.getName())
);
context.put(
MetaTemplateProperty.FIELDS,
specData.getFields()
);
context.put(
MetaTemplateProperty.QUALIFIED,
specData.getFullyQualifiedName()
);
context.put(
MetaTemplateProperty.QUALIFIEDIMPL,
nameGenerator.getQualifiedImplName(specData.getFullyQualifiedName())
);
}
/**
* Package metadata for class persistence handler into the supplied map context
*
*
* @param specData metadata extracted from the client Spec class
* @param context map to store the processed metadata harvested from
* the client Spec class
*/
protected void generatePersistenceHandlerTemplateData(SpecClassMetadata specData,
Map<TemplateProperty, Object> context) {
context.put(PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE, specData.getName());
context.put(PersistenceHandlerTemplateProperty.COLLECTION, specData.getCollectionName());
context.put(PersistenceHandlerTemplateProperty.IMPLEMENTATION, nameGenerator.getImplName(specData.getName()));
context.put(PersistenceHandlerTemplateProperty.QUALIFIED,
nameGenerator.getQualifiedPersistenceHandlerName(specData.getFullyQualifiedName()));
protected void generatePersistenceHandlerTemplateData(
SpecClassMetadata specData,
Map<TemplateProperty, Object> context
) {
context.put(
PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE,
specData.getName()
);
context.put(
PersistenceHandlerTemplateProperty.COLLECTION,
specData.getCollectionName()
);
context.put(
PersistenceHandlerTemplateProperty.IMPLEMENTATION,
nameGenerator.getImplName(specData.getName())
);
context.put(
PersistenceHandlerTemplateProperty.QUALIFIED,
nameGenerator.getQualifiedPersistenceHandlerName(
specData.getFullyQualifiedName()
)
);
context.put(PersistenceHandlerTemplateProperty.CLASS,
nameGenerator.getPersistenceHandlerName(specData.getName()));
context.put(PersistenceHandlerTemplateProperty.INTERFACE, nameGenerator.getPersistenceHandlerInterfaceName());
context.put(
PersistenceHandlerTemplateProperty.INTERFACE,
nameGenerator.getPersistenceHandlerInterfaceName()
);
}
/**
* Extract and package seed data given an element(via request) and a list of
* extracted fields
*
*
* @param request
* @param fields
* @return extracted, unprocessed data from the Spec class
......@@ -219,8 +271,9 @@ public class ICEAnnotationExtractionService {
String packageName = null;
String fullyQualifiedName;
String name = request.getClassName();
String elementFQN = (element instanceof TypeElement) ? ((TypeElement) element).getQualifiedName().toString()
: element.getClass().getName();
String elementFQN = (element instanceof TypeElement) ?
((TypeElement) element).getQualifiedName().toString() :
element.getClass().getName();
String collectionName;
final int lastDot = elementFQN.lastIndexOf('.');
......@@ -232,8 +285,13 @@ public class ICEAnnotationExtractionService {
}
collectionName = nameGenerator.extractCollectionName(element);
return SpecClassMetadata.builder().name(name).packageName(packageName).fullyQualifiedName(fullyQualifiedName)
.collectionName(collectionName).fields(fields).build();
return SpecClassMetadata.builder()
.name(name)
.packageName(packageName)
.fullyQualifiedName(fullyQualifiedName)
.collectionName(collectionName)
.fields(fields)
.build();
}
}
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