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; ...@@ -23,7 +23,7 @@ import javax.tools.StandardLocation;
* *
* @author Michael Walsh * @author Michael Walsh
*/ */
public abstract class AbstractWriterGenerator implements WriterGenerator { public abstract class AbstractWriterGenerator {
/** /**
* Used to create JavaFileObjects * 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 { ...@@ -49,7 +49,7 @@ public class DataElementAnnotationExtractor {
* used to generate writers based on the output of the annotation extraction * used to generate writers based on the output of the annotation extraction
* service * service
*/ */
private WriterGenerator writerGenerator; private DataElementWriterGenerator writerGenerator;
/** /**
* Constructor that lets you initialize the {@link DataElementAnnotationExtractor} with different * Constructor that lets you initialize the {@link DataElementAnnotationExtractor} with different
...@@ -59,7 +59,7 @@ public class DataElementAnnotationExtractor { ...@@ -59,7 +59,7 @@ public class DataElementAnnotationExtractor {
*/ */
DataElementAnnotationExtractor( DataElementAnnotationExtractor(
ICEAnnotationExtractionService annotationExtractionService, ICEAnnotationExtractionService annotationExtractionService,
WriterGenerator writerGenerator DataElementWriterGenerator writerGenerator
) { ) {
this.annotationExtractionService = annotationExtractionService; this.annotationExtractionService = annotationExtractionService;
this.writerGenerator = writerGenerator; this.writerGenerator = writerGenerator;
......
...@@ -106,9 +106,13 @@ public class DataElementProcessor extends AbstractProcessor { ...@@ -106,9 +106,13 @@ public class DataElementProcessor extends AbstractProcessor {
elementUtils = env.getElementUtils(); elementUtils = env.getElementUtils();
mapper = new ObjectMapper(); mapper = new ObjectMapper();
ICEAnnotationExtractionService extractionService = new ICEAnnotationExtractionService(elementUtils, mapper, env, ICEAnnotationExtractionService extractionService =
new DefaultNameGenerator()); new ICEAnnotationExtractionService(
WriterGenerator writerGenerator = new DataElementWriterGenerator(env); elementUtils, mapper, env,
new DefaultNameGenerator()
);
DataElementWriterGenerator writerGenerator = new DataElementWriterGenerator(env);
this.extractor = new DataElementAnnotationExtractor( this.extractor = new DataElementAnnotationExtractor(
extractionService, writerGenerator extractionService, writerGenerator
); );
......
...@@ -29,7 +29,7 @@ import org.eclipse.ice.dev.annotations.Persisted; ...@@ -29,7 +29,7 @@ import org.eclipse.ice.dev.annotations.Persisted;
* generate the interface, implementation, and persistence handler. * 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 * Map of file name key to the respective file's writer initializer
...@@ -66,7 +66,6 @@ public class DataElementWriterGenerator extends AbstractWriterGenerator implemen ...@@ -66,7 +66,6 @@ public class DataElementWriterGenerator extends AbstractWriterGenerator implemen
* DataElement specific method of class generation. Includes interfaces, * DataElement specific method of class generation. Includes interfaces,
* implementation, and possibly a persistence handler * implementation, and possibly a persistence handler
*/ */
@Override
public List<VelocitySourceWriter> generateWriters( public List<VelocitySourceWriter> generateWriters(
Element element, AnnotationExtractionResponse response 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 @@ ...@@ -7,36 +7,25 @@
* *
* Contributors: * Contributors:
* Michael Walsh - Initial implementation * Michael Walsh - Initial implementation
* Daniel Bluhm
*******************************************************************************/ *******************************************************************************/
package org.eclipse.ice.dev.annotations.processors; package org.eclipse.ice.dev.annotations.processors;
import java.io.IOException;
import java.util.List; import java.util.List;
import javax.lang.model.element.Element;
/** /**
* Interface implemented with the purpose of generating specific files given the * Interface for classes that generate one or more file writers from a given
* annotation data extracted. * set of data.
*
* This type of class serves as the configuration for which {@link VelocitySourceWriter}s to generate
* and how to generate them.
* *
* Implementations of this interface include: * @author Michael Walsh
* {@link org.eclipse.ice.dev.annotations.processors.AbstractWriterGenerator} * @author Daniel Bluhm
* {@link org.eclipse.ice.dev.annotations.processors.DataElementWriterGenerator}
*
*/ */
public interface WriterGenerator { public interface WriterGenerator<T> {
/** /**
* Generates a list of VelocitySourceWriters based on data extracted from a Spec * Generate one or more FileWriters from the passed data.
* class * @param data from which file writers will be generated.
* * @return
* @param element
* @param response
* @return List of generated Writers
* @throws IOException due to file writing
*/ */
public List<VelocitySourceWriter> generateWriters(Element element, AnnotationExtractionResponse response) public List<FileWriter> generate(T data);
throws IOException; }
} \ 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