public interface Environment
Factory.getEnvironment()
. Its
primary use is to report messages, warnings, and errors.Modifier and Type | Interface and Description |
---|---|
static class |
Environment.PRETTY_PRINTING_MODE
Drives how the model is pretty-printed to disk, or when
CtElement.prettyprint() is called |
Modifier and Type | Method and Description |
---|---|
boolean |
checksAreSkipped()
Tells whether Spoon does no checks at all.
|
PrettyPrinter |
createPrettyPrinter() |
PrettyPrinter |
createPrettyPrinterAutoImport() |
void |
debugMessage(java.lang.String message)
Logs a debug message
|
void |
disableConsistencyChecks()
Disable all consistency checks on the AST.
|
java.lang.String |
getBinaryOutputDirectory()
Set the directory where binary .class files are created
|
int |
getComplianceLevel()
Gets the Java version compliance level.
|
CompressionType |
getCompressionType()
Get the type of serialization to be used by default
|
FileGenerator<? extends CtElement> |
getDefaultFileGenerator()
Returns the default file generator for this environment (gives the
default output directory for the created files).
|
java.nio.charset.Charset |
getEncoding()
Get the encoding used inside the project
|
EncodingProvider |
getEncodingProvider()
Get encoding provider, which is used to detect encoding for each file separately
|
int |
getErrorCount()
Gets the error count from building, processing, and compiling within this
environment.
|
java.lang.ClassLoader |
getInputClassLoader()
Returns the
ClassLoader which is used by JDT and to resolve classes from references. |
org.slf4j.event.Level |
getLevel()
Gets the level of loggers asked by the user.
|
ProcessingManager |
getManager()
Gets the processing manager.
|
FineModelChangeListener |
getModelChangeListener()
get the model change listener that is used to follow the change of the AST.
|
boolean |
getNoClasspath()
Returns the value ot the option noclasspath
|
OutputDestinationHandler |
getOutputDestinationHandler()
Returns the output destination that handles where source files are written
|
OutputType |
getOutputType()
Get the output type
|
Environment.PRETTY_PRINTING_MODE |
getPrettyPrintingMode() |
ProcessorProperties |
getProcessorProperties(java.lang.String processorName)
Returns the properties for a given processor.
|
java.lang.String[] |
getSourceClasspath()
Returns the source class path of the Spoon model.
|
java.io.File |
getSourceOutputDirectory()
Returns the directory where source files are written
|
SpoonProgress |
getSpoonProgress()
Get the spoonProgress logger.
|
int |
getTabulationSize()
Gets the size of the tabulations in the generated source code.
|
int |
getWarningCount()
Gets the warning count from building, processing, and compiling within
this environment.
|
boolean |
isAutoImports()
Returns true is we let Spoon handle imports
|
boolean |
isCommentsEnabled()
Returns the value of the option enable-comments.
|
boolean |
isCopyResources()
Returns the value of the option copy-resources.
|
boolean |
isIgnoreDuplicateDeclarations() |
boolean |
isPreserveLineNumbers()
Tells if the source generator will try to preserve the original line numbers.
|
boolean |
isPreviewFeaturesEnabled()
Returns true if preview language features are enabled.
|
boolean |
isProcessingStopped()
Tells if the processing is stopped, generally because one of the
processors called
setProcessingStopped(boolean) after reporting
an error. |
boolean |
isUsingTabulations()
Tells if Spoon uses tabulations in the source code.
|
void |
report(Processor<?> processor,
org.slf4j.event.Level level,
CtElement element,
java.lang.String message)
Helper method called by a processor to report an error, warning or
message as dictated by the severity parameter.
|
void |
report(Processor<?> processor,
org.slf4j.event.Level level,
java.lang.String message)
This method should be called to print out a message during the
processing.
|
void |
reportEnd()
This method should be called to report the end of the processing.
|
void |
reportProgressMessage(java.lang.String message)
This method should be called to print out a progress message during the
processing.
|
void |
setAutoImports(boolean autoImports)
Tell to the Java printer to automatically generate imports and use simple
names instead of fully-qualified name.
|
void |
setBinaryOutputDirectory(java.lang.String directory)
Return the directory where binary .class files are created
|
void |
setCommentEnabled(boolean commentEnabled)
Sets the option enable-comments to parse comments of the target project.
|
void |
setComplianceLevel(int level)
Sets the Java version compliance level.
|
void |
setCompressionType(CompressionType serializationType)
Set the type of serialization to be used by default
|
void |
setCopyResources(boolean copyResources)
Sets the option copy-resources to copy all resources in a project on the folder destination.
|
void |
setDefaultFileGenerator(FileGenerator<? extends CtElement> generator)
Sets the default file generator for this environment.
|
void |
setEncoding(java.nio.charset.Charset encoding)
Set the encoding to use for parsing source code
|
void |
setEncodingProvider(EncodingProvider encodingProvider)
Set encoding provider, which is used to detect encoding for each file separately
|
void |
setIgnoreDuplicateDeclarations(boolean ignoreDuplicateDeclarations) |
void |
setInputClassLoader(java.lang.ClassLoader classLoader)
Sets a specific classloader for JDT and reference resolution
|
void |
setLevel(java.lang.String level)
Sets the level of loggers asked by the user.
|
void |
setManager(ProcessingManager manager)
Sets the processing manager of this environment.
|
void |
setModelChangeListener(FineModelChangeListener modelChangeListener)
set the model change listener
|
void |
setNoClasspath(boolean option)
Sets the option "noclasspath", use with caution (see explanation below).
|
void |
setOutputDestinationHandler(OutputDestinationHandler outputDestinationHandler)
Set the output destination that handles where source files are written
|
void |
setOutputType(OutputType outputType)
Set the output type used for processing files
|
void |
setPreserveLineNumbers(boolean preserveLineNumbers)
When set, the generated source code will try to generate code that
preserves the line numbers of the original source code.
|
void |
setPrettyPrinterCreator(java.util.function.Supplier<PrettyPrinter> creator) |
void |
setPrettyPrintingMode(Environment.PRETTY_PRINTING_MODE prettyPrintingMode) |
void |
setPreviewFeaturesEnabled(boolean enabled)
Set to true to enable latest preview language features.
|
void |
setProcessingStopped(boolean processingStopped)
This method can be called to stop the processing and all the remaining
tasks.
|
void |
setProcessorProperties(java.lang.String processorName,
ProcessorProperties prop)
Sets the properties for a given processor.
|
void |
setShouldCompile(boolean shouldCompile)
Sets the compile argument.
|
void |
setSourceClasspath(java.lang.String[] sourceClasspath)
Sets the source class path of the Spoon model.
|
void |
setSourceOutputDirectory(java.io.File directory)
Sets the directory where source files are written
|
void |
setSpoonProgress(SpoonProgress spoonProgress) |
void |
setTabulationSize(int size)
Sets the size of the tabulations in the generated source code.
|
boolean |
shouldCompile()
Checks if we want compile the target source code and get their binary.
|
void |
useTabulations(boolean b)
Sets Spoon to use tabulations in the source code.
|
int getComplianceLevel()
void setComplianceLevel(int level)
boolean isPreviewFeaturesEnabled()
void setPreviewFeaturesEnabled(boolean enabled)
Environment.PRETTY_PRINTING_MODE getPrettyPrintingMode()
Environment.PRETTY_PRINTING_MODE.DEBUG
most sophisticated: Environment.PRETTY_PRINTING_MODE.AUTOIMPORT
void setPrettyPrintingMode(Environment.PRETTY_PRINTING_MODE prettyPrintingMode)
void debugMessage(java.lang.String message)
FileGenerator<? extends CtElement> getDefaultFileGenerator()
ProcessingManager getManager()
ProcessorProperties getProcessorProperties(java.lang.String processorName)
void setProcessorProperties(java.lang.String processorName, ProcessorProperties prop)
boolean isAutoImports()
boolean isProcessingStopped()
setProcessingStopped(boolean)
after reporting
an error.void report(Processor<?> processor, org.slf4j.event.Level level, CtElement element, java.lang.String message)
setProcessingStopped(boolean)
.processor
- The processor that report this message. Can be null.level
- The level of the reportelement
- The CtElement to which the report is associatedmessage
- The message to reportvoid report(Processor<?> processor, org.slf4j.event.Level level, java.lang.String message)
processor
- The processor that report this message. Can be null.level
- The level of the reportmessage
- The message to reportvoid reportEnd()
void reportProgressMessage(java.lang.String message)
void setDefaultFileGenerator(FileGenerator<? extends CtElement> generator)
void setManager(ProcessingManager manager)
void setProcessingStopped(boolean processingStopped)
int getTabulationSize()
void setTabulationSize(int size)
boolean isUsingTabulations()
void useTabulations(boolean b)
void setAutoImports(boolean autoImports)
int getErrorCount()
int getWarningCount()
java.lang.ClassLoader getInputClassLoader()
ClassLoader
which is used by JDT and to resolve classes from references.
By default, returns a class loader able to load classes from the
Spoon-specific class path set with setSourceClasspath(String[])
void setInputClassLoader(java.lang.ClassLoader classLoader)
void setPreserveLineNumbers(boolean preserveLineNumbers)
boolean isPreserveLineNumbers()
java.lang.String[] getSourceClasspath()
void setSourceClasspath(java.lang.String[] sourceClasspath)
getSourceClasspath()
. Only .jar files or directories with *.class files are accepted.
The *.jar or *.java files contained in given directories are ignored.InvalidClassPathException
- if a given classpath does not exists or
does not have the right format (.jar file or directory)void setNoClasspath(boolean option)
boolean getNoClasspath()
boolean isCopyResources()
void setCopyResources(boolean copyResources)
boolean isCommentsEnabled()
void setCommentEnabled(boolean commentEnabled)
org.slf4j.event.Level getLevel()
void setLevel(java.lang.String level)
boolean shouldCompile()
void setShouldCompile(boolean shouldCompile)
boolean checksAreSkipped()
AstParentConsistencyChecker
)
- hashcode violation (see CtElementImpl.equals(Object)
)
- method violation (see CtType.addMethod(CtMethod)
)
are active or not.
By default all checks are enabled and checksAreSkipped()
return false.void disableConsistencyChecks()
void setBinaryOutputDirectory(java.lang.String directory)
java.lang.String getBinaryOutputDirectory()
void setSourceOutputDirectory(java.io.File directory)
java.io.File getSourceOutputDirectory()
void setOutputDestinationHandler(OutputDestinationHandler outputDestinationHandler)
OutputDestinationHandler getOutputDestinationHandler()
FineModelChangeListener getModelChangeListener()
void setModelChangeListener(FineModelChangeListener modelChangeListener)
java.nio.charset.Charset getEncoding()
EncodingProvider getEncodingProvider()
void setEncoding(java.nio.charset.Charset encoding)
void setEncodingProvider(EncodingProvider encodingProvider)
void setOutputType(OutputType outputType)
OutputType getOutputType()
SpoonProgress getSpoonProgress()
void setSpoonProgress(SpoonProgress spoonProgress)
CompressionType getCompressionType()
void setCompressionType(CompressionType serializationType)
PrettyPrinter createPrettyPrinter()
PrettyPrinter
which is configured for this environmentPrettyPrinter createPrettyPrinterAutoImport()
PrettyPrinter
which prints nice codevoid setPrettyPrinterCreator(java.util.function.Supplier<PrettyPrinter> creator)
creator
- a Supplier
, which creates new instance of pretty printer.
Can be used to create a SniperJavaPrettyPrinter
for enabling the sniper mode.boolean isIgnoreDuplicateDeclarations()
void setIgnoreDuplicateDeclarations(boolean ignoreDuplicateDeclarations)
ignoreDuplicateDeclarations
- (default false) set to true to allow spoon to create a model of a project that
contains multiple times the same classCopyright © 2007–2021 Inria. All rights reserved.