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
...@@ -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
...@@ -52,8 +57,10 @@ public class DataElementAnnotationExtractor { ...@@ -52,8 +57,10 @@ public class DataElementAnnotationExtractor {
* @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);
...@@ -68,10 +75,11 @@ public class DataElementAnnotationExtractor { ...@@ -68,10 +75,11 @@ public class DataElementAnnotationExtractor {
* @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;
} }
/** /**
...@@ -99,5 +107,4 @@ public class DataElementAnnotationExtractor { ...@@ -99,5 +107,4 @@ public class DataElementAnnotationExtractor {
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;
...@@ -32,8 +30,8 @@ public class DataElementInterfaceWriter extends InterfaceWriter { ...@@ -32,8 +30,8 @@ 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";
...@@ -46,8 +44,10 @@ public class DataElementInterfaceWriter extends InterfaceWriter { ...@@ -46,8 +44,10 @@ public class DataElementInterfaceWriter extends InterfaceWriter {
* @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;
} }
...@@ -83,5 +83,4 @@ public class DataElementInterfaceWriter extends InterfaceWriter { ...@@ -83,5 +83,4 @@ public class DataElementInterfaceWriter extends InterfaceWriter {
public static BiFunction<FileObject, Map, List<VelocitySourceWriter>> getContextInitializer() { public static BiFunction<FileObject, Map, List<VelocitySourceWriter>> getContextInitializer() {
return new DataElementInterfaceWriter().getInitializer(); return new DataElementInterfaceWriter().getInitializer();
} }
} }
...@@ -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,17 +76,19 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite ...@@ -72,17 +76,19 @@ 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())
.interfaceName((String) context.get(PersistenceHandlerTemplateProperty.INTERFACE))
.fields((Fields) context.get(MetaTemplateProperty.FIELDS)) .fields((Fields) context.get(MetaTemplateProperty.FIELDS))
.types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes()) .types(((Fields) context.get(MetaTemplateProperty.FIELDS)).getTypes())
.elementInterface((String) context.get(PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE)) .elementInterface((String) context.get(PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE))
.collection((String) context.get(PersistenceHandlerTemplateProperty.COLLECTION)) .collection((String) context.get(PersistenceHandlerTemplateProperty.COLLECTION))
.implementation((String) context.get(PersistenceHandlerTemplateProperty.IMPLEMENTATION)) .implementation((String) context.get(PersistenceHandlerTemplateProperty.IMPLEMENTATION))
.generatedFile(fileObject).build()); .generatedFile(fileObject).build()
);
} }
/** /**
...@@ -93,5 +99,4 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite ...@@ -93,5 +99,4 @@ public class DataElementPersistenceHandlerWriter extends PersistenceHandlerWrite
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);
......
...@@ -109,10 +109,16 @@ public class ICEAnnotationExtractionService { ...@@ -109,10 +109,16 @@ public class ICEAnnotationExtractionService {
* @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();
} }
/** /**
...@@ -123,20 +129,26 @@ public class ICEAnnotationExtractionService { ...@@ -123,20 +129,26 @@ public class ICEAnnotationExtractionService {
* @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;
} }
...@@ -147,10 +159,11 @@ public class ICEAnnotationExtractionService { ...@@ -147,10 +159,11 @@ public class ICEAnnotationExtractionService {
* @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;
} }
/** /**
...@@ -160,7 +173,9 @@ public class ICEAnnotationExtractionService { ...@@ -160,7 +173,9 @@ public class ICEAnnotationExtractionService {
* @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);
...@@ -177,14 +192,33 @@ public class ICEAnnotationExtractionService { ...@@ -177,14 +192,33 @@ public class ICEAnnotationExtractionService {
* @param context map to store the processed metadata harvested from * @param context map to store the processed metadata harvested from
* the client Spec class * the client Spec class
*/ */
protected void generateMetaTemplateData(SpecClassMetadata specData, Map<TemplateProperty, Object> context) { protected void generateMetaTemplateData(
context.put(MetaTemplateProperty.PACKAGE, specData.getPackageName()); SpecClassMetadata specData, Map<TemplateProperty, Object> context
context.put(MetaTemplateProperty.INTERFACE, specData.getName()); ) {
context.put(MetaTemplateProperty.CLASS, nameGenerator.getImplName(specData.getName())); context.put(
context.put(MetaTemplateProperty.FIELDS, specData.getFields()); MetaTemplateProperty.PACKAGE,
context.put(MetaTemplateProperty.QUALIFIED, specData.getFullyQualifiedName()); specData.getPackageName()
context.put(MetaTemplateProperty.QUALIFIEDIMPL, );
nameGenerator.getQualifiedImplName(specData.getFullyQualifiedName())); 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())
);
} }
/** /**
...@@ -194,16 +228,34 @@ public class ICEAnnotationExtractionService { ...@@ -194,16 +228,34 @@ public class ICEAnnotationExtractionService {
* @param context map to store the processed metadata harvested from * @param context map to store the processed metadata harvested from
* the client Spec class * the client Spec class
*/ */
protected void generatePersistenceHandlerTemplateData(SpecClassMetadata specData, protected void generatePersistenceHandlerTemplateData(
Map<TemplateProperty, Object> context) { SpecClassMetadata specData,
context.put(PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE, specData.getName()); Map<TemplateProperty, Object> context
context.put(PersistenceHandlerTemplateProperty.COLLECTION, specData.getCollectionName()); ) {
context.put(PersistenceHandlerTemplateProperty.IMPLEMENTATION, nameGenerator.getImplName(specData.getName())); context.put(
context.put(PersistenceHandlerTemplateProperty.QUALIFIED, PersistenceHandlerTemplateProperty.ELEMENT_INTERFACE,
nameGenerator.getQualifiedPersistenceHandlerName(specData.getFullyQualifiedName())); 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, context.put(PersistenceHandlerTemplateProperty.CLASS,
nameGenerator.getPersistenceHandlerName(specData.getName())); nameGenerator.getPersistenceHandlerName(specData.getName()));
context.put(PersistenceHandlerTemplateProperty.INTERFACE, nameGenerator.getPersistenceHandlerInterfaceName()); context.put(
PersistenceHandlerTemplateProperty.INTERFACE,
nameGenerator.getPersistenceHandlerInterfaceName()
);
} }
/** /**
...@@ -219,8 +271,9 @@ public class ICEAnnotationExtractionService { ...@@ -219,8 +271,9 @@ public class ICEAnnotationExtractionService {
String packageName = null; String packageName = null;
String fullyQualifiedName; String fullyQualifiedName;
String name = request.getClassName(); String name = request.getClassName();
String elementFQN = (element instanceof TypeElement) ? ((TypeElement) element).getQualifiedName().toString() String elementFQN = (element instanceof TypeElement) ?
: element.getClass().getName(); ((TypeElement) element).getQualifiedName().toString() :
element.getClass().getName();
String collectionName; String collectionName;
final int lastDot = elementFQN.lastIndexOf('.'); final int lastDot = elementFQN.lastIndexOf('.');
...@@ -232,8 +285,13 @@ public class ICEAnnotationExtractionService { ...@@ -232,8 +285,13 @@ public class ICEAnnotationExtractionService {
} }
collectionName = nameGenerator.extractCollectionName(element); collectionName = nameGenerator.extractCollectionName(element);
return SpecClassMetadata.builder().name(name).packageName(packageName).fullyQualifiedName(fullyQualifiedName) return SpecClassMetadata.builder()
.collectionName(collectionName).fields(fields).build(); .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