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
ConstructorDescriptionSuch processor will use printer created byEnvironment.createPrettyPrinter()
JavaOutputProcessor(PrettyPrinter printer)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
createJavaFile(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
).void
init()
This method is called to initialize the processor before each processing round.boolean
isToBeProcessed(CtNamedElement candidate)
Tells if this element is to be processed (returnstrue
in the default implementation).void
process(CtNamedElement nameElement)
Creates a source file for each processed top-level type and pretty prints its contents.void
setCharset(Charset charset)
Sets the charset.Methods inherited from class spoon.processing.AbstractProcessor
addProcessedElementType, clearProcessedElementType, getFactory, getProcessedElementTypes, initProperties, interrupt, loadProperties, process, processingDone, removeProcessedElementType, setFactory
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
Methods 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:Processor
Gets the environment of this processor.- Specified by:
getEnvironment
in interfaceProcessor<CtNamedElement>
- Overrides:
getEnvironment
in classAbstractProcessor<CtNamedElement>
-
getPrinter
-
getCreatedFiles
Description copied from interface:FileGenerator
Gets the created files.- Specified by:
getCreatedFiles
in interfaceFileGenerator<CtNamedElement>
-
getOutputDirectory
Description copied from interface:FileGenerator
Gets the root directory where files are created.- Specified by:
getOutputDirectory
in 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:Processor
This 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:
init
in interfaceProcessor<CtNamedElement>
- Overrides:
init
in 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:Processor
Tells if this element is to be processed (returnstrue
in the default implementation).- Specified by:
isToBeProcessed
in interfaceProcessor<CtNamedElement>
- Overrides:
isToBeProcessed
in 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:
process
in interfaceProcessor<CtNamedElement>
- Parameters:
nameElement
- the element that is currently being scanned
-
getLineNumberMappings
-
getTraversalStrategy
Description copied from interface:Processor
Gets 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:
getTraversalStrategy
in interfaceProcessor<CtNamedElement>
- Overrides:
getTraversalStrategy
in classAbstractProcessor<CtNamedElement>
-