Commit cacb2c24 authored by Daniel Bluhm's avatar Daniel Bluhm
Browse files

Add AnnotationExtractor, FileWriter interfaces



Modify WriterGenerator interface
Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 88a975ac
......@@ -23,7 +23,7 @@ import javax.tools.StandardLocation;
*
* @author Michael Walsh
*/
public abstract class AbstractWriterGenerator implements WriterGenerator {
public abstract class AbstractWriterGenerator {
/**
* Used to create JavaFileObjects
......
package org.eclipse.ice.dev.annotations.processors;
import javax.lang.model.element.Element;
/**
* Interface for classes acting as extractors of annotation info.
* @author Daniel Bluhm
*
* @param <T> the type of the information extracted by this annotation
* extractor.
*/
public interface AnnotationExtractor<T> {
/**
* Extract information from element and annotations found on or within
* element. The subclass of element is dependent on the annotation and
* implementation of the extractor.
* @param element from which information will be extracted.
* @return extracted information
*/
public T extract(Element element);
}
\ No newline at end of file
......@@ -49,7 +49,7 @@ public class DataElementAnnotationExtractor {
* used to generate writers based on the output of the annotation extraction
* service
*/
private WriterGenerator writerGenerator;
private DataElementWriterGenerator writerGenerator;
/**
* Constructor that lets you initialize the {@link DataElementAnnotationExtractor} with different
......@@ -59,7 +59,7 @@ public class DataElementAnnotationExtractor {
*/
DataElementAnnotationExtractor(
ICEAnnotationExtractionService annotationExtractionService,
WriterGenerator writerGenerator
DataElementWriterGenerator writerGenerator
) {
this.annotationExtractionService = annotationExtractionService;
this.writerGenerator = writerGenerator;
......
......@@ -106,9 +106,13 @@ public class DataElementProcessor extends AbstractProcessor {
elementUtils = env.getElementUtils();
mapper = new ObjectMapper();
ICEAnnotationExtractionService extractionService = new ICEAnnotationExtractionService(elementUtils, mapper, env,
new DefaultNameGenerator());
WriterGenerator writerGenerator = new DataElementWriterGenerator(env);
ICEAnnotationExtractionService extractionService =
new ICEAnnotationExtractionService(
elementUtils, mapper, env,
new DefaultNameGenerator()
);
DataElementWriterGenerator writerGenerator = new DataElementWriterGenerator(env);
this.extractor = new DataElementAnnotationExtractor(
extractionService, writerGenerator
);
......
......@@ -29,7 +29,7 @@ import org.eclipse.ice.dev.annotations.Persisted;
* generate the interface, implementation, and persistence handler.
*
*/
public class DataElementWriterGenerator extends AbstractWriterGenerator implements WriterGenerator {
public class DataElementWriterGenerator extends AbstractWriterGenerator {
/**
* Map of file name key to the respective file's writer initializer
......@@ -66,7 +66,6 @@ public class DataElementWriterGenerator extends AbstractWriterGenerator implemen
* DataElement specific method of class generation. Includes interfaces,
* implementation, and possibly a persistence handler
*/
@Override
public List<VelocitySourceWriter> generateWriters(
Element element, AnnotationExtractionResponse response
) {
......
package org.eclipse.ice.dev.annotations.processors;
import java.io.Writer;
/**
* Interface for classes that generate a file. In general, FileWriters will
* have additional methods and operations to determine the contents of the
* file to be written.
* @author Daniel Bluhm
*/
public interface FileWriter {
/**
* Get the filename suggested by this file generator.
* @return suggested file name.
*/
public String suggestedFileName();
/**
* Write the file to the open writer.
* @param writer to which the file will be written.
*/
public void write(Writer writer);
}
\ No newline at end of file
......@@ -7,36 +7,25 @@
*
* Contributors:
* Michael Walsh - Initial implementation
* Daniel Bluhm
*******************************************************************************/
package org.eclipse.ice.dev.annotations.processors;
import java.io.IOException;
import java.util.List;
import javax.lang.model.element.Element;
/**
* Interface implemented with the purpose of generating specific files given the
* annotation data extracted.
*
* This type of class serves as the configuration for which {@link VelocitySourceWriter}s to generate
* and how to generate them.
* Interface for classes that generate one or more file writers from a given
* set of data.
*
* Implementations of this interface include:
* {@link org.eclipse.ice.dev.annotations.processors.AbstractWriterGenerator}
* {@link org.eclipse.ice.dev.annotations.processors.DataElementWriterGenerator}
*
* @author Michael Walsh
* @author Daniel Bluhm
*/
public interface WriterGenerator {
public interface WriterGenerator<T> {
/**
* Generates a list of VelocitySourceWriters based on data extracted from a Spec
* class
*
* @param element
* @param response
* @return List of generated Writers
* @throws IOException due to file writing
* Generate one or more FileWriters from the passed data.
* @param data from which file writers will be generated.
* @return
*/
public List<VelocitySourceWriter> generateWriters(Element element, AnnotationExtractionResponse response)
throws IOException;
}
public List<FileWriter> generate(T data);
}
\ No newline at end of file
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