Package spoon.reflect.visitor
Class DefaultJavaPrettyPrinter
java.lang.Object
spoon.reflect.visitor.DefaultJavaPrettyPrinter
- All Implemented Interfaces:
CtVisitor
,PrettyPrinter
- Direct Known Subclasses:
SniperJavaPrettyPrinter
A visitor for generating Java code from the program compile-time model.
-
Field Summary
Modifier and TypeFieldDescriptionstatic String
The end of a block/JavaDoc commentstatic String
The beginning of a block commentstatic String
The star at the beginning of a block/JavaDoc comment lineprotected Environment
Environment which Spoon is executed.static String
protected boolean
If true: always prints fully qualified names by ignoring the isImplicit attribute of AST nodes Default value is "true" for backward compatibility.static String
The beginning of an inline commentboolean
static String
Java file extension (.java).static String
Module declaration file name.static String
Package declaration file name.static String
The beginning of a JavaDoc commentstatic String
Line separator which is used by the systemprotected static org.slf4j.Logger
Handle imports of classes.protected CtCompilationUnit
Compilation unit we are printing. -
Constructor Summary
ConstructorDescriptionCreates a new code generator visitor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Warning, this may change the state of the objectvoid
calculate(CtCompilationUnit sourceCompilationUnit, List<CtType<?>> types)
Calculates the resulting source file for a list of types.protected void
This method is called byscan(CtElement)
when entering a scanned element.protected void
enterCtExpression(CtExpression<?> e)
Enters an expression.protected void
Enters a statement.protected void
This method is called byscan(CtElement)
when entering a scanned element.protected void
exitCtExpression(CtExpression<?> e)
Exits an expression.protected void
exitCtStatement(CtStatement statement)
Exits a statement.getImports(CtCompilationUnit compilationUnit)
Gets the line number mapping between the generated code and the original code.protected TokenWriter
Gets the contents of the compilation unit.protected boolean
prettyprint(CtElement e)
pretty-prints the element, call#toString()
to get the resultprintCompilationUnit(CtCompilationUnit compilationUnit)
Prints the compilation unit of module-info, package-info or types.printElement(CtElement element)
Prints an element.printModuleInfo(CtModule module)
Prints the module info.printPackageInfo(CtPackage pack)
Prints the package info.printTypes(CtType<?>... type)
Prints the types of one compilation unit It always resets the printing context at the beginning of this process.void
reset()
The generic scan method for an element.void
setIgnoreImplicit(boolean ignoreImplicit)
setLineSeparator(String lineSeparator)
protected void
setMinimizeRoundBrackets(boolean minimizeRoundBrackets)
When set to true, this activates round bracket minimization for expressions.void
setPreprocessors(List<Processor<CtElement>> preprocessors)
Set preprocessors that the printer automatically runs on the model before printing it.setPrinterTokenWriter(TokenWriter tokenWriter)
SetTokenWriter
, which has to be used to print tokensprotected String
stripLeadingDigits(String simpleName)
toString()
Gets the currently pretty-printed string.<A extends Annotation>
voidvisitCtAnnotation(CtAnnotation<A> annotation)
Visits an annotation.<T> void
visitCtAnnotationFieldAccess(CtAnnotationFieldAccess<T> annotationFieldAccess)
Visits a field of an annotation.<T> void
visitCtAnnotationMethod(CtAnnotationMethod<T> annotationMethod)
Visits an annotation method declaration.<A extends Annotation>
voidvisitCtAnnotationType(CtAnnotationType<A> annotationType)
Visits an annotation type declaration.void
Visits an anonymous executable.<T> void
visitCtArrayRead(CtArrayRead<T> arrayRead)
Visits an array read access.<T> void
visitCtArrayTypeReference(CtArrayTypeReference<T> reference)
Visits a reference to an array type.<T> void
visitCtArrayWrite(CtArrayWrite<T> arrayWrite)
Visits an array write access.<T> void
visitCtAssert(CtAssert<T> asserted)
Visits an assert.<T, A extends T>
voidvisitCtAssignment(CtAssignment<T,A> assignement)
Visits an assignment.<T> void
visitCtBinaryOperator(CtBinaryOperator<T> operator)
Visits a binary operator.<R> void
visitCtBlock(CtBlock<R> block)
Visits a block of code.void
visitCtBreak(CtBreak breakStatement)
Visits abreak
statement.<E> void
visitCtCase(CtCase<E> caseStatement)
Visits acase
clause.void
visitCtCatch(CtCatch catchBlock)
Visits acatch
clause.<T> void
visitCtCatchVariable(CtCatchVariable<T> catchVariable)
Visits a catch variable declaration.<T> void
visitCtCatchVariableReference(CtCatchVariableReference<T> reference)
Visits a reference to a catch variable.<T> void
visitCtClass(CtClass<T> ctClass)
Visits a class declaration.<T> void
visitCtCodeSnippetExpression(CtCodeSnippetExpression<T> expression)
Visits a code snippet expression.void
visitCtCodeSnippetStatement(CtCodeSnippetStatement statement)
Visits a code snippet statement.void
visitCtComment(CtComment comment)
Visits a commentvoid
visitCtCompilationUnit(CtCompilationUnit compilationUnit)
Visits a compilation unit<T> void
visitCtConditional(CtConditional<T> conditional)
Visits a conditional expression<T> void
visitCtConstructor(CtConstructor<T> constructor)
Visits a constructor declaration.<T> void
visitCtConstructorCall(CtConstructorCall<T> ctConstructorCall)
Visits a call to a constructor.void
visitCtContinue(CtContinue continueStatement)
Visits acontinue
statement.void
Visits ado
loop.<T extends Enum<?>>
voidvisitCtEnum(CtEnum<T> ctEnum)
Visits an enumeration declaration.<T> void
visitCtEnumValue(CtEnumValue<T> enumValue)
Visits an enum value declaration.<T> void
visitCtExecutableReference(CtExecutableReference<T> reference)
Visits a reference to an executable.<T, E extends CtExpression<?>>
voidvisitCtExecutableReferenceExpression(CtExecutableReferenceExpression<T,E> expression)
Visits a reference to an executable.<T> void
visitCtField(CtField<T> f)
Visits a field declaration.<T> void
visitCtFieldRead(CtFieldRead<T> fieldRead)
Visits a field read access.<T> void
visitCtFieldReference(CtFieldReference<T> reference)
Visits a reference to a field.<T> void
visitCtFieldWrite(CtFieldWrite<T> fieldWrite)
Visits a field write access.void
visitCtFor(CtFor forLoop)
Visits afor
loop.void
visitCtForEach(CtForEach foreach)
Visits an enhancedfor
loop.void
Visits anif
statement.void
visitCtImport(CtImport ctImport)
Visits an import declaration<T> void
visitCtInterface(CtInterface<T> intrface)
Visits an interface declaration.<T> void
visitCtIntersectionTypeReference(CtIntersectionTypeReference<T> reference)
Visits an intersection type.<T> void
visitCtInvocation(CtInvocation<T> invocation)
Visits an executable invocation.void
visitCtJavaDoc(CtJavaDoc comment)
Visits a javadoc commentvoid
visitCtJavaDocTag(CtJavaDocTag docTag)
Visits a javadoc tag<T> void
visitCtLambda(CtLambda<T> lambda)
Visits an anonymous method construction.<T> void
visitCtLiteral(CtLiteral<T> literal)
Visits a literal expression.<T> void
visitCtLocalVariable(CtLocalVariable<T> localVariable)
Visits a local variable declaration.<T> void
visitCtLocalVariableReference(CtLocalVariableReference<T> reference)
Visits a reference to a local variable.<T> void
visitCtMethod(CtMethod<T> m)
Visits a method declaration.void
visitCtModule(CtModule module)
Visits a module declarationvoid
visitCtModuleReference(CtModuleReference moduleReference)
Visits a module referencevoid
visitCtModuleRequirement(CtModuleRequirement moduleRequirement)
Visits a "require" directive in a module declaration.<T> void
visitCtNewArray(CtNewArray<T> newArray)
Visits an array construction.<T> void
visitCtNewClass(CtNewClass<T> newClass)
Visits an anonymous class construction.<T, A extends T>
voidvisitCtOperatorAssignment(CtOperatorAssignment<T,A> assignment)
Visits an operator assignment.void
visitCtPackage(CtPackage ctPackage)
Visits a package declaration.void
visitCtPackageDeclaration(CtPackageDeclaration packageDeclaration)
Visits a package declarationvoid
visitCtPackageExport(CtPackageExport moduleExport)
Visits a package export in a module declaration.void
visitCtPackageReference(CtPackageReference reference)
Visits a reference to a package.<T> void
visitCtParameter(CtParameter<T> parameter)
Visits a parameter declaration.<T> void
visitCtParameterReference(CtParameterReference<T> reference)
Visits a reference to a parameter.void
visitCtProvidedService(CtProvidedService moduleProvidedService)
Visits a "provides" directive in a module declaration.void
visitCtRecord(CtRecord recordType)
Visits a record.void
visitCtRecordComponent(CtRecordComponent recordComponent)
Visits a record component.<R> void
visitCtReturn(CtReturn<R> returnStatement)
Visits areturn
statement.void
visitCtStatementList(CtStatementList statements)
Visits a statement list.<T> void
visitCtSuperAccess(CtSuperAccess<T> f)
Visits an access to a super invocation.<E> void
visitCtSwitch(CtSwitch<E> switchStatement)
Visits aswitch
statement.<T, S> void
visitCtSwitchExpression(CtSwitchExpression<T,S> switchExpression)
Visits aswitch
expression.void
visitCtSynchronized(CtSynchronized synchro)
Visits asynchronized
modifier.void
visitCtTextBlock(CtTextBlock ctTextBlock)
Visits a literal TextBlock string.<T> void
visitCtThisAccess(CtThisAccess<T> thisAccess)
Visits a this access.void
visitCtThrow(CtThrow throwStatement)
Visits athrow
statement.void
visitCtTry(CtTry tryBlock)
Visits atry
statement.void
visitCtTryWithResource(CtTryWithResource tryWithResource)
Visits atry
with resource statement.<T> void
visitCtTypeAccess(CtTypeAccess<T> typeAccess)
Visits a type access.void
visitCtTypeMemberWildcardImportReference(CtTypeMemberWildcardImportReference wildcardReference)
Visits an import wildcard static type member referencevoid
visitCtTypeParameter(CtTypeParameter typeParameter)
Visits a type parameter declaration.void
Visits a reference to a type parameter.void
visitCtTypePattern(CtTypePattern pattern)
Visits a pattern.<T> void
visitCtTypeReference(CtTypeReference<T> ref)
Visits a reference to a type.<T> void
visitCtUnaryOperator(CtUnaryOperator<T> operator)
Visits a unary operator.<T> void
visitCtUnboundVariableReference(CtUnboundVariableReference<T> reference)
Visits a reference to an unbound fieldvoid
visitCtUsedService(CtUsedService usedService)
Visits a "uses" directive in a module declaration.<T> void
visitCtVariableRead(CtVariableRead<T> variableRead)
Visits a variable read access.<T> void
visitCtVariableWrite(CtVariableWrite<T> variableWrite)
Visits a variable write access.void
visitCtWhile(CtWhile whileLoop)
Visits awhile
loop.void
visitCtWildcardReference(CtWildcardReference wildcardReference)
Visits a reference to a wildcard.void
visitCtYieldStatement(CtYieldStatement statement)
Visits a yield statement.
-
Field Details
-
JAVA_FILE_EXTENSION
Java file extension (.java).- See Also:
- Constant Field Values
-
JAVA_PACKAGE_DECLARATION
Package declaration file name.- See Also:
- Constant Field Values
-
JAVA_MODULE_DECLARATION
Module declaration file name.- See Also:
- Constant Field Values
-
LINE_SEPARATOR
Line separator which is used by the system -
COMMENT_STAR
The star at the beginning of a block/JavaDoc comment line- See Also:
- Constant Field Values
-
BLOCK_COMMENT_END
The end of a block/JavaDoc comment- See Also:
- Constant Field Values
-
JAVADOC_START
The beginning of a JavaDoc comment- See Also:
- Constant Field Values
-
INLINE_COMMENT_START
The beginning of an inline comment- See Also:
- Constant Field Values
-
BLOCK_COMMENT_START
The beginning of a block comment- See Also:
- Constant Field Values
-
preprocessors
Handle imports of classes. -
env
Environment which Spoon is executed. -
sourceCompilationUnit
Compilation unit we are printing. -
ignoreImplicit
protected boolean ignoreImplicitIf true: always prints fully qualified names by ignoring the isImplicit attribute of AST nodes Default value is "true" for backward compatibility. If false: obey "implicit" directive -
inlineElseIf
public boolean inlineElseIf -
LOGGER
protected static final org.slf4j.Logger LOGGER -
ERROR_MESSAGE_TO_STRING
- See Also:
- Constant Field Values
-
-
Constructor Details
-
DefaultJavaPrettyPrinter
Creates a new code generator visitor.
-
-
Method Details
-
getLineSeparator
- Returns:
- current line separator. By default there is CR LF, LF or CR depending on the Operation system defined by System.getProperty("line.separator")
-
setLineSeparator
- Parameters:
lineSeparator
- characters which will be printed as End of line. By default there is System.getProperty("line.separator")
-
printElement
Prints an element. This method shall be called by the toString() method of an element. It is responsible for any initialization required to print an arbitrary element.- Specified by:
printElement
in interfacePrettyPrinter
- Parameters:
element
-- Returns:
- A string containing the pretty printed element (and descendants).
-
enterCtExpression
Enters an expression. -
enterCtStatement
Enters a statement. -
exitCtStatement
Exits a statement. -
exitCtExpression
Exits an expression. -
enter
This method is called byscan(CtElement)
when entering a scanned element. To be overridden to implement specific behavior. Same KISS design as forCtScanner
. -
exit
This method is called byscan(CtElement)
when entering a scanned element. To be overridden to implement specific behavior. -
prettyprint
Description copied from interface:PrettyPrinter
pretty-prints the element, call#toString()
to get the result- Specified by:
prettyprint
in interfacePrettyPrinter
-
scan
The generic scan method for an element. -
toString
Gets the currently pretty-printed string. -
visitCtAnnotation
Description copied from interface:CtVisitor
Visits an annotation.- Specified by:
visitCtAnnotation
in interfaceCtVisitor
-
visitCtAnnotationType
Description copied from interface:CtVisitor
Visits an annotation type declaration.- Specified by:
visitCtAnnotationType
in interfaceCtVisitor
-
visitCtAnonymousExecutable
Description copied from interface:CtVisitor
Visits an anonymous executable.- Specified by:
visitCtAnonymousExecutable
in interfaceCtVisitor
-
visitCtArrayRead
Description copied from interface:CtVisitor
Visits an array read access.- Specified by:
visitCtArrayRead
in interfaceCtVisitor
-
visitCtArrayWrite
Description copied from interface:CtVisitor
Visits an array write access.- Specified by:
visitCtArrayWrite
in interfaceCtVisitor
-
visitCtArrayTypeReference
Description copied from interface:CtVisitor
Visits a reference to an array type.- Specified by:
visitCtArrayTypeReference
in interfaceCtVisitor
-
visitCtAssert
Description copied from interface:CtVisitor
Visits an assert.- Specified by:
visitCtAssert
in interfaceCtVisitor
-
visitCtAssignment
Description copied from interface:CtVisitor
Visits an assignment.- Specified by:
visitCtAssignment
in interfaceCtVisitor
-
visitCtBinaryOperator
Description copied from interface:CtVisitor
Visits a binary operator.- Specified by:
visitCtBinaryOperator
in interfaceCtVisitor
-
visitCtBlock
Description copied from interface:CtVisitor
Visits a block of code.- Specified by:
visitCtBlock
in interfaceCtVisitor
-
visitCtBreak
Description copied from interface:CtVisitor
Visits abreak
statement.- Specified by:
visitCtBreak
in interfaceCtVisitor
-
visitCtCase
Description copied from interface:CtVisitor
Visits acase
clause.- Specified by:
visitCtCase
in interfaceCtVisitor
-
visitCtCatch
Description copied from interface:CtVisitor
Visits acatch
clause.- Specified by:
visitCtCatch
in interfaceCtVisitor
-
visitCtClass
Description copied from interface:CtVisitor
Visits a class declaration.- Specified by:
visitCtClass
in interfaceCtVisitor
-
visitCtTypeParameter
Description copied from interface:CtVisitor
Visits a type parameter declaration.- Specified by:
visitCtTypeParameter
in interfaceCtVisitor
-
visitCtConditional
Description copied from interface:CtVisitor
Visits a conditional expression- Specified by:
visitCtConditional
in interfaceCtVisitor
-
visitCtConstructor
Description copied from interface:CtVisitor
Visits a constructor declaration.- Specified by:
visitCtConstructor
in interfaceCtVisitor
-
visitCtContinue
Description copied from interface:CtVisitor
Visits acontinue
statement.- Specified by:
visitCtContinue
in interfaceCtVisitor
-
visitCtDo
Description copied from interface:CtVisitor
Visits ado
loop. -
visitCtEnum
Description copied from interface:CtVisitor
Visits an enumeration declaration.- Specified by:
visitCtEnum
in interfaceCtVisitor
-
visitCtExecutableReference
Description copied from interface:CtVisitor
Visits a reference to an executable.- Specified by:
visitCtExecutableReference
in interfaceCtVisitor
-
visitCtField
Description copied from interface:CtVisitor
Visits a field declaration.- Specified by:
visitCtField
in interfaceCtVisitor
-
visitCtEnumValue
Description copied from interface:CtVisitor
Visits an enum value declaration.- Specified by:
visitCtEnumValue
in interfaceCtVisitor
-
visitCtFieldRead
Description copied from interface:CtVisitor
Visits a field read access.- Specified by:
visitCtFieldRead
in interfaceCtVisitor
-
visitCtFieldWrite
Description copied from interface:CtVisitor
Visits a field write access.- Specified by:
visitCtFieldWrite
in interfaceCtVisitor
-
visitCtThisAccess
Description copied from interface:CtVisitor
Visits a this access.- Specified by:
visitCtThisAccess
in interfaceCtVisitor
-
visitCtSuperAccess
Description copied from interface:CtVisitor
Visits an access to a super invocation.- Specified by:
visitCtSuperAccess
in interfaceCtVisitor
-
visitCtJavaDoc
Description copied from interface:CtVisitor
Visits a javadoc comment- Specified by:
visitCtJavaDoc
in interfaceCtVisitor
-
visitCtJavaDocTag
Description copied from interface:CtVisitor
Visits a javadoc tag- Specified by:
visitCtJavaDocTag
in interfaceCtVisitor
-
visitCtImport
Description copied from interface:CtVisitor
Visits an import declaration- Specified by:
visitCtImport
in interfaceCtVisitor
-
visitCtModule
Description copied from interface:CtVisitor
Visits a module declaration- Specified by:
visitCtModule
in interfaceCtVisitor
-
visitCtModuleReference
Description copied from interface:CtVisitor
Visits a module reference- Specified by:
visitCtModuleReference
in interfaceCtVisitor
-
visitCtPackageExport
Description copied from interface:CtVisitor
Visits a package export in a module declaration.- Specified by:
visitCtPackageExport
in interfaceCtVisitor
-
visitCtModuleRequirement
Description copied from interface:CtVisitor
Visits a "require" directive in a module declaration.- Specified by:
visitCtModuleRequirement
in interfaceCtVisitor
-
visitCtProvidedService
Description copied from interface:CtVisitor
Visits a "provides" directive in a module declaration.- Specified by:
visitCtProvidedService
in interfaceCtVisitor
-
visitCtUsedService
Description copied from interface:CtVisitor
Visits a "uses" directive in a module declaration.- Specified by:
visitCtUsedService
in interfaceCtVisitor
-
visitCtCompilationUnit
Description copied from interface:CtVisitor
Visits a compilation unit- Specified by:
visitCtCompilationUnit
in interfaceCtVisitor
-
getImports
-
visitCtPackageDeclaration
Description copied from interface:CtVisitor
Visits a package declaration- Specified by:
visitCtPackageDeclaration
in interfaceCtVisitor
-
visitCtTypeMemberWildcardImportReference
public void visitCtTypeMemberWildcardImportReference(CtTypeMemberWildcardImportReference wildcardReference)Description copied from interface:CtVisitor
Visits an import wildcard static type member reference- Specified by:
visitCtTypeMemberWildcardImportReference
in interfaceCtVisitor
-
visitCtComment
Description copied from interface:CtVisitor
Visits a comment- Specified by:
visitCtComment
in interfaceCtVisitor
-
visitCtAnnotationFieldAccess
Description copied from interface:CtVisitor
Visits a field of an annotation.- Specified by:
visitCtAnnotationFieldAccess
in interfaceCtVisitor
-
visitCtFieldReference
Description copied from interface:CtVisitor
Visits a reference to a field.- Specified by:
visitCtFieldReference
in interfaceCtVisitor
-
visitCtFor
Description copied from interface:CtVisitor
Visits afor
loop.- Specified by:
visitCtFor
in interfaceCtVisitor
-
visitCtForEach
Description copied from interface:CtVisitor
Visits an enhancedfor
loop.- Specified by:
visitCtForEach
in interfaceCtVisitor
-
visitCtIf
Description copied from interface:CtVisitor
Visits anif
statement. -
visitCtInterface
Description copied from interface:CtVisitor
Visits an interface declaration.- Specified by:
visitCtInterface
in interfaceCtVisitor
-
visitCtInvocation
Description copied from interface:CtVisitor
Visits an executable invocation.- Specified by:
visitCtInvocation
in interfaceCtVisitor
-
visitCtLiteral
Description copied from interface:CtVisitor
Visits a literal expression.- Specified by:
visitCtLiteral
in interfaceCtVisitor
-
visitCtTextBlock
Description copied from interface:CtVisitor
Visits a literal TextBlock string.- Specified by:
visitCtTextBlock
in interfaceCtVisitor
-
visitCtLocalVariable
Description copied from interface:CtVisitor
Visits a local variable declaration.- Specified by:
visitCtLocalVariable
in interfaceCtVisitor
-
visitCtLocalVariableReference
Description copied from interface:CtVisitor
Visits a reference to a local variable.- Specified by:
visitCtLocalVariableReference
in interfaceCtVisitor
-
visitCtCatchVariable
Description copied from interface:CtVisitor
Visits a catch variable declaration.- Specified by:
visitCtCatchVariable
in interfaceCtVisitor
-
visitCtCatchVariableReference
Description copied from interface:CtVisitor
Visits a reference to a catch variable.- Specified by:
visitCtCatchVariableReference
in interfaceCtVisitor
-
visitCtMethod
Description copied from interface:CtVisitor
Visits a method declaration.- Specified by:
visitCtMethod
in interfaceCtVisitor
-
visitCtAnnotationMethod
Description copied from interface:CtVisitor
Visits an annotation method declaration.- Specified by:
visitCtAnnotationMethod
in interfaceCtVisitor
-
visitCtNewArray
Description copied from interface:CtVisitor
Visits an array construction.- Specified by:
visitCtNewArray
in interfaceCtVisitor
-
visitCtConstructorCall
Description copied from interface:CtVisitor
Visits a call to a constructor.- Specified by:
visitCtConstructorCall
in interfaceCtVisitor
-
visitCtNewClass
Description copied from interface:CtVisitor
Visits an anonymous class construction.- Specified by:
visitCtNewClass
in interfaceCtVisitor
-
visitCtLambda
Description copied from interface:CtVisitor
Visits an anonymous method construction.- Specified by:
visitCtLambda
in interfaceCtVisitor
-
visitCtExecutableReferenceExpression
public <T, E extends CtExpression<?>> void visitCtExecutableReferenceExpression(CtExecutableReferenceExpression<T,E> expression)Description copied from interface:CtVisitor
Visits a reference to an executable.- Specified by:
visitCtExecutableReferenceExpression
in interfaceCtVisitor
-
visitCtOperatorAssignment
Description copied from interface:CtVisitor
Visits an operator assignment.- Specified by:
visitCtOperatorAssignment
in interfaceCtVisitor
-
visitCtPackage
Description copied from interface:CtVisitor
Visits a package declaration.- Specified by:
visitCtPackage
in interfaceCtVisitor
-
visitCtPackageReference
Description copied from interface:CtVisitor
Visits a reference to a package.- Specified by:
visitCtPackageReference
in interfaceCtVisitor
-
visitCtParameter
Description copied from interface:CtVisitor
Visits a parameter declaration.- Specified by:
visitCtParameter
in interfaceCtVisitor
-
visitCtParameterReference
Description copied from interface:CtVisitor
Visits a reference to a parameter.- Specified by:
visitCtParameterReference
in interfaceCtVisitor
-
visitCtReturn
Description copied from interface:CtVisitor
Visits areturn
statement.- Specified by:
visitCtReturn
in interfaceCtVisitor
-
visitCtStatementList
Description copied from interface:CtVisitor
Visits a statement list.- Specified by:
visitCtStatementList
in interfaceCtVisitor
-
visitCtSwitch
Description copied from interface:CtVisitor
Visits aswitch
statement.- Specified by:
visitCtSwitch
in interfaceCtVisitor
-
visitCtSwitchExpression
Description copied from interface:CtVisitor
Visits aswitch
expression.- Specified by:
visitCtSwitchExpression
in interfaceCtVisitor
-
visitCtSynchronized
Description copied from interface:CtVisitor
Visits asynchronized
modifier.- Specified by:
visitCtSynchronized
in interfaceCtVisitor
-
visitCtThrow
Description copied from interface:CtVisitor
Visits athrow
statement.- Specified by:
visitCtThrow
in interfaceCtVisitor
-
visitCtTry
Description copied from interface:CtVisitor
Visits atry
statement.- Specified by:
visitCtTry
in interfaceCtVisitor
-
visitCtTryWithResource
Description copied from interface:CtVisitor
Visits atry
with resource statement.- Specified by:
visitCtTryWithResource
in interfaceCtVisitor
-
visitCtTypeParameterReference
Description copied from interface:CtVisitor
Visits a reference to a type parameter.- Specified by:
visitCtTypeParameterReference
in interfaceCtVisitor
-
visitCtWildcardReference
Description copied from interface:CtVisitor
Visits a reference to a wildcard.- Specified by:
visitCtWildcardReference
in interfaceCtVisitor
-
visitCtIntersectionTypeReference
Description copied from interface:CtVisitor
Visits an intersection type.- Specified by:
visitCtIntersectionTypeReference
in interfaceCtVisitor
-
visitCtTypeReference
Description copied from interface:CtVisitor
Visits a reference to a type.- Specified by:
visitCtTypeReference
in interfaceCtVisitor
-
visitCtTypeAccess
Description copied from interface:CtVisitor
Visits a type access.- Specified by:
visitCtTypeAccess
in interfaceCtVisitor
-
visitCtUnaryOperator
Description copied from interface:CtVisitor
Visits a unary operator.- Specified by:
visitCtUnaryOperator
in interfaceCtVisitor
-
visitCtVariableRead
Description copied from interface:CtVisitor
Visits a variable read access.- Specified by:
visitCtVariableRead
in interfaceCtVisitor
-
visitCtVariableWrite
Description copied from interface:CtVisitor
Visits a variable write access.- Specified by:
visitCtVariableWrite
in interfaceCtVisitor
-
visitCtWhile
Description copied from interface:CtVisitor
Visits awhile
loop.- Specified by:
visitCtWhile
in interfaceCtVisitor
-
visitCtCodeSnippetExpression
Description copied from interface:CtVisitor
Visits a code snippet expression.- Specified by:
visitCtCodeSnippetExpression
in interfaceCtVisitor
-
visitCtCodeSnippetStatement
Description copied from interface:CtVisitor
Visits a code snippet statement.- Specified by:
visitCtCodeSnippetStatement
in interfaceCtVisitor
-
getElementPrinterHelper
-
getContext
-
visitCtUnboundVariableReference
Description copied from interface:CtVisitor
Visits a reference to an unbound field- Specified by:
visitCtUnboundVariableReference
in interfaceCtVisitor
-
printCompilationUnit
Description copied from interface:PrettyPrinter
Prints the compilation unit of module-info, package-info or types.- Specified by:
printCompilationUnit
in interfacePrettyPrinter
-
applyPreProcessors
Warning, this may change the state of the object -
printPackageInfo
Description copied from interface:PrettyPrinter
Prints the package info. It always resets the printing context at the beginning of this process.- Specified by:
printPackageInfo
in interfacePrettyPrinter
-
printModuleInfo
Description copied from interface:PrettyPrinter
Prints the module info. It always resets the printing context at the beginning of this process.- Specified by:
printModuleInfo
in interfacePrettyPrinter
-
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
-
getResult
Description copied from interface:PrettyPrinter
Gets the contents of the compilation unit.- Specified by:
getResult
in interfacePrettyPrinter
-
reset
public void reset() -
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
-
getLineNumberMapping
Description copied from interface:PrettyPrinter
Gets the line number mapping between the generated code and the original code.- Specified by:
getLineNumberMapping
in interfacePrettyPrinter
-
getPrinterTokenWriter
- Returns:
- current
TokenWriter
, so the subclasses ofDefaultJavaPrettyPrinter
can print tokens too
-
setPrinterTokenWriter
SetTokenWriter
, which has to be used to print tokens -
setPreprocessors
Set preprocessors that the printer automatically runs on the model before printing it. Typically, such preprocessors validate or adjust the model before printing.- Parameters:
preprocessors
- list of processors to run on the model before printing
-
getPreprocessors
- Returns:
- all processors currently set to run on the model before printing
-
setIgnoreImplicit
public void setIgnoreImplicit(boolean ignoreImplicit)- Parameters:
ignoreImplicit
- true to ignore `isImplicit` attribute on model and always print fully qualified names
-
visitCtYieldStatement
Description copied from interface:CtVisitor
Visits a yield statement.- Specified by:
visitCtYieldStatement
in interfaceCtVisitor
-
visitCtTypePattern
Description copied from interface:CtVisitor
Visits a pattern.- Specified by:
visitCtTypePattern
in interfaceCtVisitor
- Parameters:
pattern
- the pattern to visit.
-
isMinimizeRoundBrackets
protected boolean isMinimizeRoundBrackets()- Returns:
- true if the printer is minimizing the amount of round brackets in expressions
-
setMinimizeRoundBrackets
protected void setMinimizeRoundBrackets(boolean minimizeRoundBrackets)When set to true, this activates round bracket minimization for expressions. This means that the printer will attempt to only write round brackets strictly necessary for preserving syntactical structure (and by extension, semantics). As an example, the expression1 + 2 + 3 + 4
is written as((1 + 2) + 3) + 4
without round bracket minimization, but entirely without parentheses when minimization is enabled. However, an expression1 + 2 + (3 + 4)
is still written as1 + 2 + (3 + 4)
to preserve syntactical structure, even though the brackets are semantically redundant.- Parameters:
minimizeRoundBrackets
- set whether or not to minimize round brackets in expressions
-
stripLeadingDigits
-
visitCtRecord
Description copied from interface:CtVisitor
Visits a record.- Specified by:
visitCtRecord
in interfaceCtVisitor
- Parameters:
recordType
- the record to visit.
-
visitCtRecordComponent
Description copied from interface:CtVisitor
Visits a record component.- Specified by:
visitCtRecordComponent
in interfaceCtVisitor
- Parameters:
recordComponent
- the record component to visit.
-