Package spoon.support
Class JavaOutputProcessor
- All Implemented Interfaces:
FactoryAccessor,FileGenerator<CtNamedElement>,Processor<CtNamedElement>
public class JavaOutputProcessor
extends AbstractProcessor<CtNamedElement>
implements FileGenerator<CtNamedElement>
A processor that generates compilable Java source files from the meta-model.
-
Constructor Summary
ConstructorsConstructorDescriptionSuch processor will use printer created byEnvironment.createPrettyPrinter()JavaOutputProcessor(PrettyPrinter printer) -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateJavaFile(CtType<?> element)Creates the Java file associated to the given element.Gets the charset.Gets the created files.Gets the environment of this processor.Gets the root directory where files are created.Gets the model's traversal strategy for this processor (default isTraversalStrategy.POST_ORDER).voidinit()This method is called to initialize the processor before each processing round.booleanisToBeProcessed(CtNamedElement candidate)Tells if this element is to be processed (returnstruein the default implementation).voidprocess(CtNamedElement nameElement)Creates a source file for each processed top-level type and pretty prints its contents.voidsetCharset(Charset charset)Sets the charset.Methods inherited from class spoon.processing.AbstractProcessor
addProcessedElementType, clearProcessedElementType, getFactory, getProcessedElementTypes, initProperties, interrupt, loadProperties, process, processingDone, removeProcessedElementType, setFactoryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactoryMethods inherited from interface spoon.processing.Processor
getProcessedElementTypes, initProperties, interrupt, process, processingDone
-
Constructor Details
-
JavaOutputProcessor
- Parameters:
printer- the PrettyPrinter to use for written the files
-
JavaOutputProcessor
public JavaOutputProcessor()Such processor will use printer created byEnvironment.createPrettyPrinter()
-
-
Method Details
-
getEnvironment
Description copied from interface:ProcessorGets the environment of this processor.- Specified by:
getEnvironmentin interfaceProcessor<CtNamedElement>- Overrides:
getEnvironmentin classAbstractProcessor<CtNamedElement>
-
getPrinter
-
getCreatedFiles
Description copied from interface:FileGeneratorGets the created files.- Specified by:
getCreatedFilesin interfaceFileGenerator<CtNamedElement>
-
getOutputDirectory
Description copied from interface:FileGeneratorGets the root directory where files are created.- Specified by:
getOutputDirectoryin interfaceFileGenerator<CtNamedElement>
-
getCharset
Gets the charset.- Returns:
- the charset used for processed source code.
-
setCharset
Sets the charset.- Parameters:
charset- the charset used for processed source code.
-
init
public void init()Description copied from interface:ProcessorThis method is called to initialize the processor before each processing round. It is convenient to override this method rather than using a default constructor to initialize the processor, since the factory is not initialized at construction time. When overriding, do not forget to call super.init() first so that all the initializations performed by superclasses are also applied.- Specified by:
initin interfaceProcessor<CtNamedElement>- Overrides:
initin classAbstractProcessor<CtNamedElement>
-
createJavaFile
Creates the Java file associated to the given element. Splits top-level classes in different files (even if they are in the same file in the original sources). -
isToBeProcessed
Description copied from interface:ProcessorTells if this element is to be processed (returnstruein the default implementation).- Specified by:
isToBeProcessedin interfaceProcessor<CtNamedElement>- Overrides:
isToBeProcessedin classAbstractProcessor<CtNamedElement>- Parameters:
candidate- the candidate- Returns:
- true if the candidate is to be processed by the
Processor.process(CtElement)
-
process
Creates a source file for each processed top-level type and pretty prints its contents.- Specified by:
processin interfaceProcessor<CtNamedElement>- Parameters:
nameElement- the element that is currently being scanned
-
getLineNumberMappings
-
getTraversalStrategy
Description copied from interface:ProcessorGets the model's traversal strategy for this processor (default isTraversalStrategy.POST_ORDER). Programmers should override this method to return another strategy if needed.- Specified by:
getTraversalStrategyin interfaceProcessor<CtNamedElement>- Overrides:
getTraversalStrategyin classAbstractProcessor<CtNamedElement>
-