public class PrettyPrinter extends Object
Modifier and Type | Field and Description |
---|---|
private static char[] |
BLANKS |
protected Type |
classToPrint
Enforces the output of real Java syntax that can be compiled.
|
private int |
column
Column number.
|
protected boolean |
endAlreadyMarked |
private static char[] |
FEEDS |
protected Object |
firstStatement |
protected int |
firstStatementEnd |
protected int |
firstStatementStart |
private int |
indentation
Indentation (cached).
|
protected HashMap<SourceElement,Position> |
indentMap |
protected SVInstantiations |
instantiations |
private boolean |
isPrintingSingleLineComments
Flag to indicate if a single line comment is being put out.
|
private ArrayList<Range> |
keywordRanges
Contains the java keyword ranges.
|
private Stack<Integer> |
keywordStarts
Remembers the start of a keyword to create a range.
|
protected int |
level
Level.
|
private int |
line
Line number, not directly used.
|
protected boolean |
noLinefeed |
protected boolean |
noSemicolons |
protected Writer |
out |
protected StringBuffer |
outBuf |
private boolean |
overwriteIndentation
Overwrite indentation flag (cached).
|
private boolean |
overwriteParsePositions
Overwrite parse positions flag (cached).
|
protected boolean |
startAlreadyMarked |
protected int |
writtenCharacters
The number of charcters that have been send to the writer
|
Constructor and Description |
---|
PrettyPrinter(Writer o)
creates a new PrettyPrinter
|
PrettyPrinter(Writer o,
boolean noLinefeed) |
PrettyPrinter(Writer o,
boolean noLinefeed,
SVInstantiations svi) |
PrettyPrinter(Writer o,
SVInstantiations svi) |
private int line
private int column
protected int level
protected Writer out
protected StringBuffer outBuf
protected boolean noLinefeed
protected boolean noSemicolons
protected Type classToPrint
de.uka.ilkd.key.testgen.pp.unittest.ppAndJavaASTExtension.CompilableJavaCardPP
protected int firstStatementStart
protected int firstStatementEnd
protected boolean startAlreadyMarked
protected boolean endAlreadyMarked
protected Object firstStatement
protected SVInstantiations instantiations
private final Stack<Integer> keywordStarts
protected int writtenCharacters
private boolean isPrintingSingleLineComments
protected HashMap<SourceElement,Position> indentMap
private static final char[] BLANKS
private static final char[] FEEDS
private int indentation
private boolean overwriteIndentation
private boolean overwriteParsePositions
public PrettyPrinter(Writer o)
public PrettyPrinter(Writer o, SVInstantiations svi)
public PrettyPrinter(Writer o, boolean noLinefeed)
public PrettyPrinter(Writer o, boolean noLinefeed, SVInstantiations svi)
protected void output() throws IOException
IOException
protected int getCurrentPos()
protected void markStart(int n, Object stmt)
n
- offset from the current positionstmt
- current statement;protected void markEnd(int n, Object stmt)
n
- offset from the current positionpublic Range getRangeOfFirstExecutableStatement()
protected final void markKeywordStart()
protected final void markKeywordEnd()
public final Range[] getKeywordRanges()
public void reset()
public void setWriter(Writer out)
public int getLine()
public int getColumn()
public int getIndentationLevel()
public void setIndentationLevel(int level)
level
- an int value.public int getTotalIndentation()
public void changeLevel(int delta)
delta
- an int value.protected void writeIndentation(int lf, int blanks) throws IOException
IOException
protected void writeIndentation(Position relative) throws IOException
IOException
protected void writeIndentation(SourceElement elem) throws IOException
elem
- a source element.IOException
- occasionally thrown.protected void writeInternalIndentation(SourceElement elem) throws IOException
elem
- a source element.IOException
- occasionally thrown.protected void writeSymbol(int lf, int levelChange, String symbol) throws IOException
lf
- an int value.levelChange
- an int value.symbol
- a string.IOException
- occasionally thrown.protected static String encodeUnicodeChars(String str)
str
- the input string.protected void scheduleComment(SingleLineComment slc)
slc
- the comment to delay.protected void writeElement(int lf, int levelChange, int blanks, SourceElement elem) throws IOException
IOException
protected Position getRelativePosition(SourceElement first)
protected void writeToken(int lf, int blanks, String image, NonTerminalProgramElement parent) throws IOException
protected final void writeToken(int blanks, String image, NonTerminalProgramElement parent) throws IOException
IOException
protected final void writeToken(String image, NonTerminalProgramElement parent) throws IOException
IOException
protected void writeElement(int lf, int blanks, SourceElement elem) throws IOException
lf
- an int value.blanks
- an int value.elem
- a source element.IOException
- occasionally thrown.protected void writeElement(int blanks, SourceElement elem) throws IOException
blanks
- an int value.elem
- a source element.IOException
- occasionally thrown.protected void writeElement(SourceElement elem) throws IOException
elem
- a source element.IOException
- occasionally thrown.protected void writeImmutableArrayOfProgramElement(int firstLF, int levelChange, int firstBlanks, String separationSymbol, int separationLF, int separationBlanks, ImmutableArray<? extends ProgramElement> list) throws IOException
IOException
protected void writeKeywordList(int firstLF, int levelChange, int firstBlanks, ImmutableArray<? extends ProgramElement> list) throws IOException
IOException
protected void writeKeywordList(ImmutableArray<? extends ProgramElement> list) throws IOException
list
- a program element list.IOException
- occasionally thrown.protected void writeCommaList(int firstLF, int levelChange, int firstBlanks, ImmutableArray<? extends ProgramElement> list) throws IOException
IOException
protected void writeCommaList(int separationBlanks, ImmutableArray<? extends ProgramElement> list) throws IOException
list
- a program element list.IOException
- occasionally thrown.protected void writeCommaList(ImmutableArray<? extends ProgramElement> list) throws IOException
list
- a program element list.IOException
- occasionally thrown.protected void writeLineList(int firstLF, int levelChange, int firstBlanks, ImmutableArray<? extends ProgramElement> list) throws IOException
IOException
protected void writeLineList(ImmutableArray<? extends ProgramElement> list) throws IOException
list
- a program element list.IOException
- occasionally thrown.protected void writeBlockList(int firstLF, int levelChange, int firstBlanks, ImmutableArray<? extends ProgramElement> list) throws IOException
IOException
protected void writeBlockList(ImmutableArray<? extends ProgramElement> list) throws IOException
list
- a program element list.IOException
- occasionally thrown.private void dumpComments() throws IOException
IOException
public void write(int c) throws IOException
c
- an int value.IOException
- occasionally thrown.public void write(char[] cbuf) throws IOException
cbuf
- a char value.IOException
- occasionally thrown.public void write(char[] cbuf, int off, int len) throws IOException
cbuf
- an array of char.off
- an int value.len
- an int value.IOException
- occasionally thrown.public void write(String str) throws IOException
str
- a string.IOException
- occasionally thrown.public void write(String str, int off, int len) throws IOException
str
- a string.off
- an int value.len
- an int value.IOException
- occasionally thrown.protected int getIndentation()
protected boolean isOverwritingIndentation()
protected boolean isOverwritingParsePositions()
protected void printHeader(int lf, int blanks, ProgramElement elem) throws IOException
lf
- an int value.blanks
- an int value.elem
- a program element.IOException
- occasionally thrown.protected void printHeader(int blanks, ProgramElement elem) throws IOException
blanks
- an int value.elem
- a program element.IOException
- occasionally thrown.protected void printHeader(ProgramElement elem) throws IOException
elem
- a program element.IOException
- occasionally thrown.protected void printHeader(int lf, int levelChange, int blanks, ProgramElement x) throws IOException
lf
- number of line feeds.levelChange
- the level change.blanks
- number of white spaces.x
- the program element.IOException
- occasionally thrown.protected void printFooter(ProgramElement x) throws IOException
x
- the program element.IOException
- occasionally thrown.protected void printOperator(Operator x, String symbol) throws IOException
IOException
public void printProgramElementName(ProgramElementName x) throws IOException
IOException
public void printProgramVariable(ProgramVariable x) throws IOException
IOException
public void printProgramMethod(IProgramMethod x) throws IOException
IOException
public void printProgramMetaConstruct(ProgramTransformer x) throws IOException
IOException
public void printContextStatementBlock(ContextStatementBlock x) throws IOException
IOException
public void printIntLiteral(IntLiteral x) throws IOException
IOException
public void printBigintLiteral(BigintLiteral x) throws IOException
IOException
public void printBooleanLiteral(BooleanLiteral x) throws IOException
IOException
public void printEmptySetLiteral(EmptySetLiteral x) throws IOException
IOException
public void printSingleton(Singleton x) throws IOException
IOException
public void printSetUnion(SetUnion x) throws IOException
IOException
public void printIntersect(Intersect x) throws IOException
IOException
public void printSetMinus(SetMinus x) throws IOException
IOException
public void printAllFields(AllFields x) throws IOException
IOException
public void printAllObjects(AllObjects x) throws IOException
IOException
public void printEmptySeqLiteral(EmptySeqLiteral x) throws IOException
IOException
public void printSeqLength(SeqLength x) throws IOException
IOException
public void printSeqGet(SeqGet x) throws IOException
IOException
public void printSeqSingleton(SeqSingleton x) throws IOException
IOException
public void printSeqConcat(SeqConcat x) throws IOException
IOException
public void printIndexOf(SeqIndexOf x) throws IOException
IOException
public void printSeqSub(SeqSub x) throws IOException
IOException
public void printSeqReverse(SeqReverse x) throws IOException
IOException
public void printDLEmbeddedExpression(DLEmbeddedExpression x) throws IOException
IOException
public void printStringLiteral(StringLiteral x) throws IOException
IOException
public void printNullLiteral(NullLiteral x) throws IOException
IOException
public void printCharLiteral(CharLiteral x) throws IOException
IOException
public void printDoubleLiteral(DoubleLiteral x) throws IOException
IOException
public void printLongLiteral(LongLiteral x) throws IOException
IOException
public void printFloatLiteral(FloatLiteral x) throws IOException
IOException
public void printPackageSpecification(PackageSpecification x) throws IOException
IOException
public void printAssert(Assert x) throws IOException
IOException
public void printArrayDeclaration(ArrayDeclaration type) throws IOException
IOException
public void printTypeReference(TypeReference x) throws IOException
IOException
public void printTypeReference(TypeReference x, boolean fullTypeNames) throws IOException
IOException
public void printSchemaTypeReference(SchemaTypeReference x) throws IOException
IOException
public void printFieldReference(FieldReference x) throws IOException
IOException
public void printPackageReference(PackageReference x) throws IOException
IOException
public void printThrows(Throws x) throws IOException
IOException
public void printArrayInitializer(ArrayInitializer x) throws IOException
IOException
public void printCompilationUnit(CompilationUnit x) throws IOException
IOException
public void printClassDeclaration(ClassDeclaration x) throws IOException
IOException
protected boolean containsDefaultConstructor(ImmutableArray<MemberDeclaration> members)
public void printInterfaceDeclaration(InterfaceDeclaration x) throws IOException
IOException
protected ImmutableArray<Modifier> removeFinal(ImmutableArray<Modifier> ma)
protected ImmutableArray<Modifier> replacePrivateByPublic(ImmutableArray<Modifier> ma)
public void printFieldDeclaration(FieldDeclaration x) throws IOException
IOException
public void printLocalVariableDeclaration(LocalVariableDeclaration x) throws IOException
IOException
public void printVariableDeclaration(VariableDeclaration x) throws IOException
IOException
public void printMethodDeclaration(MethodDeclaration x) throws IOException
IOException
public void printClassInitializer(ClassInitializer x) throws IOException
IOException
public void printStatementBlock(StatementBlock x) throws IOException
IOException
public void printBreak(Break x) throws IOException
IOException
public void printContinue(Continue x) throws IOException
IOException
public void printReturn(Return x) throws IOException
IOException
public void printThrow(Throw x) throws IOException
IOException
public void printDo(Do x) throws IOException
IOException
public void printDo(Do x, boolean includeBody) throws IOException
IOException
private static void removeChar(StringBuffer sb, char c)
public void printEnhancedFor(EnhancedFor x) throws IOException
IOException
public void printEnhancedFor(EnhancedFor x, boolean includeBody) throws IOException
IOException
public void printFor(For x) throws IOException
IOException
public void printFor(For x, boolean includeBody) throws IOException
IOException
public void printWhile(While x) throws IOException
IOException
public void printWhile(While x, boolean includeBody) throws IOException
IOException
public void printIf(If x) throws IOException
IOException
public void printIf(If x, boolean includeBranches) throws IOException
IOException
public void printSwitch(Switch x) throws IOException
IOException
public void printSwitch(Switch x, boolean includeBranches) throws IOException
IOException
public void printTry(Try x) throws IOException
IOException
public void printLabeledStatement(LabeledStatement x) throws IOException
IOException
public void printMethodFrame(MethodFrame x) throws IOException
IOException
public void printCatchAllStatement(CatchAllStatement x) throws IOException
IOException
public void printMethodBodyStatement(MethodBodyStatement x) throws IOException
IOException
public void printSynchronizedBlock(SynchronizedBlock x) throws IOException
IOException
public void printImport(Import x) throws IOException
IOException
public void printExtends(Extends x) throws IOException
IOException
public void printImplements(Implements x) throws IOException
IOException
public void printVariableSpecification(VariableSpecification x) throws IOException
IOException
public void printBinaryAnd(BinaryAnd x) throws IOException
IOException
public void printBinaryAndAssignment(BinaryAndAssignment x) throws IOException
IOException
public void printBinaryOrAssignment(BinaryOrAssignment x) throws IOException
IOException
public void printBinaryXOrAssignment(BinaryXOrAssignment x) throws IOException
IOException
public void printCopyAssignment(CopyAssignment x) throws IOException
IOException
public void printDivideAssignment(DivideAssignment x) throws IOException
IOException
public void printMinusAssignment(MinusAssignment x) throws IOException
IOException
public void printModuloAssignment(ModuloAssignment x) throws IOException
IOException
public void printPlusAssignment(PlusAssignment x) throws IOException
IOException
public void printPostDecrement(PostDecrement x) throws IOException
IOException
public void printPostIncrement(PostIncrement x) throws IOException
IOException
public void printPreDecrement(PreDecrement x) throws IOException
IOException
public void printPreIncrement(PreIncrement x) throws IOException
IOException
public void printShiftLeftAssignment(ShiftLeftAssignment x) throws IOException
IOException
public void printShiftRightAssignment(ShiftRightAssignment x) throws IOException
IOException
public void printTimesAssignment(TimesAssignment x) throws IOException
IOException
public void printUnsignedShiftRightAssignment(UnsignedShiftRightAssignment x) throws IOException
IOException
public void printBinaryNot(BinaryNot x) throws IOException
IOException
public void printBinaryOr(BinaryOr x) throws IOException
IOException
public void printBinaryXOr(BinaryXOr x) throws IOException
IOException
public void printConditional(Conditional x) throws IOException
IOException
public void printDivide(Divide x) throws IOException
IOException
public void printEquals(Equals x) throws IOException
IOException
public void printGreaterOrEquals(GreaterOrEquals x) throws IOException
IOException
public void printGreaterThan(GreaterThan x) throws IOException
IOException
public void printLessOrEquals(LessOrEquals x) throws IOException
IOException
public void printLessThan(LessThan x) throws IOException
IOException
public void printNotEquals(NotEquals x) throws IOException
IOException
public void printNewArray(NewArray x) throws IOException
IOException
public void printInstanceof(Instanceof x) throws IOException
IOException
public void printExactInstanceof(ExactInstanceof x) throws IOException
IOException
public void printNew(New x) throws IOException
IOException
public void printTypeCast(TypeCast x) throws IOException
IOException
public void printLogicalAnd(LogicalAnd x) throws IOException
IOException
public void printLogicalNot(LogicalNot x) throws IOException
IOException
public void printLogicalOr(LogicalOr x) throws IOException
IOException
public void printMinus(Minus x) throws IOException
IOException
public void printModulo(Modulo x) throws IOException
IOException
public void printNegative(Negative x) throws IOException
IOException
public void printPlus(Plus x) throws IOException
IOException
public void printPositive(Positive x) throws IOException
IOException
public void printShiftLeft(ShiftLeft x) throws IOException
IOException
public void printShiftRight(ShiftRight x) throws IOException
IOException
public void printTimes(Times x) throws IOException
IOException
public void printUnsignedShiftRight(UnsignedShiftRight x) throws IOException
IOException
public void printArrayReference(ArrayReference x) throws IOException
IOException
public void printMetaClassReference(MetaClassReference x) throws IOException
IOException
public void printMethodReference(MethodReference x) throws IOException
IOException
protected void printMethodReference(MethodReference x, boolean withSemicolon) throws IOException
IOException
public void printMethod(IProgramMethod x) throws IOException
IOException
public void printFullMethodSignature(IProgramMethod x) throws IOException
IOException
protected void writeFullMethodSignature(IProgramMethod x) throws IOException
IOException
public void printExecutionContext(ExecutionContext x) throws IOException
IOException
public void printSuperConstructorReference(SuperConstructorReference x) throws IOException
IOException
public void printThisConstructorReference(ThisConstructorReference x) throws IOException
IOException
public void printSuperReference(SuperReference x) throws IOException
IOException
public void printThisReference(ThisReference x) throws IOException
IOException
public void printArrayLengthReference(ArrayLengthReference x) throws IOException
IOException
public void printThen(Then x) throws IOException
IOException
public void printElse(Else x) throws IOException
IOException
public void printCase(Case x) throws IOException
IOException
public void printCatch(Catch x) throws IOException
IOException
public void printDefault(Default x) throws IOException
IOException
public void printFinally(Finally x) throws IOException
IOException
public void printModifier(Modifier x) throws IOException
IOException
public void printSchemaVariable(SchemaVariable x) throws IOException
IOException
public void printEmptyStatement(EmptyStatement x) throws IOException
IOException
public void printComment(Comment x) throws IOException
IOException
public void printParenthesizedExpression(ParenthesizedExpression x) throws IOException
IOException
public void printPassiveExpression(PassiveExpression x) throws IOException
IOException
public void printTransactionStatement(TransactionStatement x) throws IOException
IOException
public void printEmptyMapLiteral(EmptyMapLiteral x) throws IOException
IOException