Package spoon.support.sniper
Class SniperJavaPrettyPrinter
java.lang.Object
spoon.reflect.visitor.DefaultJavaPrettyPrinter
spoon.support.sniper.SniperJavaPrettyPrinter
- All Implemented Interfaces:
CtVisitor
,PrettyPrinter
,TokenWriterProxy.Listener
public class SniperJavaPrettyPrinter
extends DefaultJavaPrettyPrinter
implements TokenWriterProxy.Listener
PrettyPrinter
implementation, which copies as much as possible from the origin sources
and tries to only print the changed elements.-
Field Summary
Fields inherited from class spoon.reflect.visitor.DefaultJavaPrettyPrinter
BLOCK_COMMENT_END, BLOCK_COMMENT_START, COMMENT_STAR, env, ERROR_MESSAGE_TO_STRING, ignoreImplicit, INLINE_COMMENT_START, inlineElseIf, JAVA_FILE_EXTENSION, JAVA_MODULE_DECLARATION, JAVA_PACKAGE_DECLARATION, JAVADOC_START, LINE_SEPARATOR, LOGGER, preprocessors, sourceCompilationUnit
-
Constructor Summary
ConstructorDescriptionCreates a newPrettyPrinter
which copies origin sources and prints only changes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
calculate(CtCompilationUnit compilationUnit, List<CtType<?>> types)
Calculates the resulting source file for a list of types.getImports(CtCompilationUnit compilationUnit)
static boolean
Warning, not in the API, public for testing purposesvoid
onTokenWriterWrite(TokenType tokenType, String token, CtComment comment, Runnable printAction)
Called for each printed tokenprintElement(CtElement element)
The sniper mode only works from JavaOutputProcessorprintElementSniper(CtElement element)
Warning: debug and test method only, not part of the public APIprintTypes(CtType<?>... type)
Prints the types of one compilation unit It always resets the printing context at the beginning of this process.Called wheneverDefaultJavaPrettyPrinter
scans/prints an element Warning: DO not call on a cloned element.Methods inherited from class spoon.reflect.visitor.DefaultJavaPrettyPrinter
applyPreProcessors, enter, enterCtExpression, enterCtStatement, exit, exitCtExpression, exitCtStatement, getContext, getElementPrinterHelper, getLineNumberMapping, getLineSeparator, getPreprocessors, getPrinterTokenWriter, getResult, isMinimizeRoundBrackets, prettyprint, printCompilationUnit, printModuleInfo, printPackageInfo, reset, setIgnoreImplicit, setLineSeparator, setMinimizeRoundBrackets, setPreprocessors, setPrinterTokenWriter, stripLeadingDigits, toString, visitCtAnnotation, visitCtAnnotationFieldAccess, visitCtAnnotationMethod, visitCtAnnotationType, visitCtAnonymousExecutable, visitCtArrayRead, visitCtArrayTypeReference, visitCtArrayWrite, visitCtAssert, visitCtAssignment, visitCtBinaryOperator, visitCtBlock, visitCtBreak, visitCtCase, visitCtCatch, visitCtCatchVariable, visitCtCatchVariableReference, visitCtClass, visitCtCodeSnippetExpression, visitCtCodeSnippetStatement, visitCtComment, visitCtCompilationUnit, visitCtConditional, visitCtConstructor, visitCtConstructorCall, visitCtContinue, visitCtDo, visitCtEnum, visitCtEnumValue, visitCtExecutableReference, visitCtExecutableReferenceExpression, visitCtField, visitCtFieldRead, visitCtFieldReference, visitCtFieldWrite, visitCtFor, visitCtForEach, visitCtIf, visitCtImport, visitCtInterface, visitCtIntersectionTypeReference, visitCtInvocation, visitCtJavaDoc, visitCtJavaDocTag, visitCtLambda, visitCtLiteral, visitCtLocalVariable, visitCtLocalVariableReference, visitCtMethod, visitCtModule, visitCtModuleReference, visitCtModuleRequirement, visitCtNewArray, visitCtNewClass, visitCtOperatorAssignment, visitCtPackage, visitCtPackageDeclaration, visitCtPackageExport, visitCtPackageReference, visitCtParameter, visitCtParameterReference, visitCtProvidedService, visitCtRecord, visitCtRecordComponent, visitCtReturn, visitCtStatementList, visitCtSuperAccess, visitCtSwitch, visitCtSwitchExpression, visitCtSynchronized, visitCtTextBlock, visitCtThisAccess, visitCtThrow, visitCtTry, visitCtTryWithResource, visitCtTypeAccess, visitCtTypeMemberWildcardImportReference, visitCtTypeParameter, visitCtTypeParameterReference, visitCtTypePattern, visitCtTypeReference, visitCtUnaryOperator, visitCtUnboundVariableReference, visitCtUsedService, visitCtVariableRead, visitCtVariableWrite, visitCtWhile, visitCtWildcardReference, visitCtYieldStatement
-
Constructor Details
-
SniperJavaPrettyPrinter
Creates a newPrettyPrinter
which copies origin sources and prints only changes.
-
-
Method Details
-
printTypes
Description copied from interface:PrettyPrinter
Prints the types of one compilation unit It always resets the printing context at the beginning of this process.- Specified by:
printTypes
in interfacePrettyPrinter
- Overrides:
printTypes
in classDefaultJavaPrettyPrinter
-
calculate
Description copied from interface:PrettyPrinter
Calculates the resulting source file for a list of types. The source compilation unit is required for calculating the line numbers mapping. It always resets the printing context at the beginning of this process.- Specified by:
calculate
in interfacePrettyPrinter
- Overrides:
calculate
in classDefaultJavaPrettyPrinter
-
onTokenWriterWrite
public void onTokenWriterWrite(TokenType tokenType, String token, CtComment comment, Runnable printAction)Called for each printed token- Specified by:
onTokenWriterWrite
in interfaceTokenWriterProxy.Listener
- Parameters:
tokenType
- the type ofTokenWriter
methodtoken
- the actual token value. It may be null for some `tokenWriterMethodName`comment
- the comment when `tokenType` == `COMMENT`printAction
- the executor of the action, we are listening for. Call it send token to output
-
hasImplicitAncestor
Warning, not in the API, public for testing purposes -
printElement
The sniper mode only works from JavaOutputProcessor- Specified by:
printElement
in interfacePrettyPrinter
- Overrides:
printElement
in classDefaultJavaPrettyPrinter
- Returns:
- A string containing the pretty printed element (and descendants).
-
printElementSniper
Warning: debug and test method only, not part of the public API -
scan
Called wheneverDefaultJavaPrettyPrinter
scans/prints an element Warning: DO not call on a cloned element. Use scanClone instead.- Overrides:
scan
in classDefaultJavaPrettyPrinter
-
getImports
- Overrides:
getImports
in classDefaultJavaPrettyPrinter
-