Commit cc7b0c47 authored by Daniel Bluhm's avatar Daniel Bluhm

Clean up DataElementAnntoationExtractor

And WriterGenerator
Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 1daa1454
......@@ -22,6 +22,8 @@ import javax.lang.model.element.Element;
import org.eclipse.ice.dev.annotations.DataField;
import lombok.Builder;
/**
* Flavor of ICEAnnotationExtractionService that specializes in extracting data
* from Spec classes with the class level annotation of {@link DataElement}
......@@ -47,11 +49,17 @@ public class DataElementAnnotationExtractor {
* used for extracting and preparing data for writer generation
*/
private ICEAnnotationExtractionService annotationExtractionService;
/**
* Filer used for generating files.
*/
private Filer filer;
/**
* used to generate writers based on the output of the annotation extraction
* service
*/
private DataElementWriterGenerator writerGenerator;
private WriterGenerator<AnnotationExtractionResponse> writerGenerator;
/**
* Constructor that lets you initialize the {@link DataElementAnnotationExtractor} with different
......@@ -59,11 +67,14 @@ public class DataElementAnnotationExtractor {
* @param annotationExtractionService
* @param writerGenerator
*/
@Builder
DataElementAnnotationExtractor(
ICEAnnotationExtractionService annotationExtractionService,
DataElementWriterGenerator writerGenerator
Filer filer,
WriterGenerator<AnnotationExtractionResponse> writerGenerator
) {
this.annotationExtractionService = annotationExtractionService;
this.filer = filer;
this.writerGenerator = writerGenerator;
this.annotationExtractionService.setNonTransferableAnnotations(nonTransferableAnnotations);
this.annotationExtractionService.setFieldFilter(DataElementAnnotationExtractor::isDataField);
......@@ -91,7 +102,6 @@ public class DataElementAnnotationExtractor {
* @throws IOException
*/
public void generateAndWrite(AnnotationExtractionRequest request) throws IOException {
Filer filer = writerGenerator.processingEnv.getFiler();
generateWriters(request)
.forEach(writer -> {
try (Writer file = writer.openWriter(filer)) {
......
......@@ -14,7 +14,6 @@ package org.eclipse.ice.dev.annotations.processors;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Properties;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
......@@ -30,12 +29,7 @@ import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
import javax.tools.JavaFileManager.Location;
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;
import org.apache.velocity.app.Velocity;
import org.eclipse.ice.dev.annotations.DataElement;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -112,10 +106,11 @@ public class DataElementProcessor extends AbstractProcessor {
new DefaultNameGenerator()
);
DataElementWriterGenerator writerGenerator = new DataElementWriterGenerator(env);
this.extractor = new DataElementAnnotationExtractor(
extractionService, writerGenerator
);
this.extractor = DataElementAnnotationExtractor.builder()
.annotationExtractionService(extractionService)
.filer(env.getFiler())
.writerGenerator(new DataElementWriterGenerator())
.build();
super.init(env);
}
......
......@@ -10,46 +10,20 @@
*******************************************************************************/
package org.eclipse.ice.dev.annotations.processors;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.tools.FileObject;
import org.eclipse.ice.dev.annotations.Persisted;
/**
* Uses metadata extracted from spec classes annotated with @DataElement to
* generate the interface, implementation, and persistence handler.
*
*/
public class DataElementWriterGenerator
extends AbstractWriterGenerator
implements WriterGenerator<AnnotationExtractionResponse>
{
/**
* Map of file name key to the respective file's writer initializer
*/
private Map<TemplateProperty, BiFunction<FileObject, Map, List<SelfInitializingWriter>>> writerInitializers =
new HashMap<>();
/**
* Util instance for extracting specific data from Element objects
*/
protected SpecExtractionHelper specExtractionHelper = new SpecExtractionHelper();
DataElementWriterGenerator(ProcessingEnvironment processingEnv) {
super(processingEnv);
}
@Override
public List<GeneratedFileWriter> generate(AnnotationExtractionResponse response) {
List<GeneratedFileWriter> writers = new ArrayList<>();
......
package org.eclipse.ice.dev.annotations.processors;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import javax.tools.FileObject;
/**
* Temporary class for keeping things working while changing interfaces.
* @author Daniel Bluhm
*/
public abstract class SelfInitializingWriter extends VelocitySourceWriter {
protected FileObject generatedFile;
public SelfInitializingWriter(FileObject generatedFile) {
super();
this.generatedFile = generatedFile;
}
public SelfInitializingWriter() {
super();
}
public void write() throws IOException {
try (Writer writer = generatedFile.openWriter()) {
this.write(writer);
}
}
public abstract BiFunction<FileObject, Map, List<SelfInitializingWriter>> getInitializer();
}
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