Top Description Fields Constructors Methods
io.vertx.codegen.writer

public Class CodeWriter

extends PrintWriter
Class Inheritance
Imports
java.io.PrintWriter, .Writer, java.util.Locale, java.util.stream.Collectors, .Stream

Class to simplify code write that maintains indentation status
Author
Francesco Guardiani @slinkydeveloper

Field Summary

Modifier and TypeField and Description
private boolean
private int
private int
Inherited from java.io.PrintWriter:
out

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public CodeWriter
append(CharSequence
The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
csq
)

Overrides java.io.PrintWriter.append.

Implements java.lang.Appendable.append.

Appends the specified character sequence to this writer.

public CodeWriter
append(CharSequence
The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".
csq
,
int
The index of the first character in the subsequence
start
,
int
The index of the character following the last character in the subsequence
end
)

Overrides java.io.PrintWriter.append.

Implements java.lang.Appendable.append.

Appends a subsequence of the specified character sequence to this writer.

public CodeWriter
append(char
The 16-bit character to append
c
)

Overrides java.io.PrintWriter.append.

Implements java.lang.Appendable.append.

Appends the specified character to this writer.

public CodeWriter

Returns:

this object
code
(String
the string to print
string
)

Print the specified string with an indent prefix.

public CodeWriter

Returns:

this object
codeln
(String
the line to print
line
)

Print the specified line with an indent prefix and end with a new line char.

public CodeWriter
format(String
A format string as described in Format string syntax.
format
,
Object...
Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
args
)

Overrides java.io.PrintWriter.format.

Writes a formatted string to this writer using the specified format string and arguments.

public CodeWriter
format(Locale
The locale to apply during formatting. If l is null then no localization is applied.
l
,
String
A format string as described in Format string syntax.
format
,
Object...
Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
args
)

Overrides java.io.PrintWriter.format.

Writes a formatted string to this writer using the specified format string and arguments.

public CodeWriter

Returns:

this object
indent
()

Increment the current indentation.

public String

Returns:

the current indentation string
indentation
()

public CodeWriter
public int

Returns:

the current indentation size
indentSize
()

public CodeWriter

Returns:

this object
indentSize
(int
the new size
size
)

Set the current indentation size, this can only be done when the current indentation is 0.

public CodeWriter

Returns:

this object
javaImport
(String name)

Append the name as a java package import.

public CodeWriter

Returns:

this object
newLine
()

Hides java.io.PrintWriter.newLine.

Print a new line char.

public void
println()

Overrides java.io.PrintWriter.println.

Terminates the current line by writing the line separator string.

public CodeWriter

Returns:

this object
stmt
(String
the statement
statement
)

This function prints an indentation before the statement and a semicolon followed by a newline after.

public CodeWriter

Returns:

this object
unindent
()

Decrement the current indentation.

public void
write(String
A String
s
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Overrides java.io.PrintWriter.write.

Writes a portion of a string.

public void
write(int
int specifying a character to be written.
c
)

Overrides java.io.PrintWriter.write.

Writes a single character.

public Writer

Returns:

the current underlying writer
writer
()

public CodeWriter

Returns:

this object
writeSeq
(Stream<String> sequence, String delimiter)

Write a sequence delimited by a delimiter.

Inherited from java.io.PrintWriter:
checkErrorclearErrorcloseflushprintprintprintprintprintprintprintprintprintprintfprintfprintlnprintlnprintlnprintlnprintlnprintlnprintlnprintlnprintlnsetErrorwritewritewrite

Field Detail

firstback to summary
private boolean first
indentback to summary
private int indent
indentSizeback to summary
private int indentSize

Constructor Detail

CodeWriterback to summary
public CodeWriter(Writer out)

Method Detail

appendback to summary
public CodeWriter append(CharSequence csq)

Overrides java.io.PrintWriter.append.

Implements java.lang.Appendable.append.

Doc from java.io.PrintWriter.append.

Appends the specified character sequence to this writer.

An invocation of this method of the form out.append(csq) when csq is not null, behaves in exactly the same way as the invocation

out.write(csq.toString())
out.write(csq.toString())

Depending on the specification of toString for the character sequence csq, the entire sequence may not be appended. For instance, invoking the toString method of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.

Parameters
csq:CharSequence

The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.

Returns:CodeWriter

This writer

Annotations
@Override
appendback to summary
public CodeWriter append(CharSequence csq, int start, int end)

Overrides java.io.PrintWriter.append.

Implements java.lang.Appendable.append.

Doc from java.io.PrintWriter.append.

Appends a subsequence of the specified character sequence to this writer.

An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation

out.write(csq.subSequence(start, end).toString())
out.write(csq.subSequence(start, end).toString())
Parameters
csq:CharSequence

The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".

start:int

The index of the first character in the subsequence

end:int

The index of the character following the last character in the subsequence

Returns:CodeWriter

This writer

Annotations
@Override
appendback to summary
public CodeWriter append(char c)

Overrides java.io.PrintWriter.append.

Implements java.lang.Appendable.append.

Doc from java.io.PrintWriter.append.

Appends the specified character to this writer.

An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation

out.write(c)
out.write(c)
Parameters
c:char

The 16-bit character to append

Returns:CodeWriter

This writer

Annotations
@Override
codeback to summary
public CodeWriter code(String string)

Print the specified string with an indent prefix. This method forces the writer to be the first line

Parameters
string:String

the string to print

Returns:CodeWriter

this object

codelnback to summary
public CodeWriter codeln(String line)

Print the specified line with an indent prefix and end with a new line char.

Parameters
line:String

the line to print

Returns:CodeWriter

this object

formatback to summary
public CodeWriter format(String format, Object... args)

Overrides java.io.PrintWriter.format.

Doc from java.io.PrintWriter.format.

Writes a formatted string to this writer using the specified format string and arguments. If automatic flushing is enabled, calls to this method will flush the output buffer.

The locale always used is the one returned by Locale.getDefault(), regardless of any previous invocations of other formatting methods on this object.

Parameters
format:String

A format string as described in Format string syntax.

args:Object[]

Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.

Returns:CodeWriter

This writer

Annotations
@Override
formatback to summary
public CodeWriter format(Locale l, String format, Object... args)

Overrides java.io.PrintWriter.format.

Doc from java.io.PrintWriter.format.

Writes a formatted string to this writer using the specified format string and arguments. If automatic flushing is enabled, calls to this method will flush the output buffer.

Parameters
l:Locale

The locale to apply during formatting. If l is null then no localization is applied.

format:String

A format string as described in Format string syntax.

args:Object[]

Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.

Returns:CodeWriter

This writer

Annotations
@Override
indentback to summary
public CodeWriter indent()

Increment the current indentation.

Returns:CodeWriter

this object

indentationback to summary
public String indentation()
Returns:String

the current indentation string

indentedback to summary
public CodeWriter indented(Runnable block)
indentSizeback to summary
public int indentSize()
Returns:int

the current indentation size

indentSizeback to summary
public CodeWriter indentSize(int size)

Set the current indentation size, this can only be done when the current indentation is 0.

Parameters
size:int

the new size

Returns:CodeWriter

this object

javaImportback to summary
public CodeWriter javaImport(String name)

Append the name as a java package import.

Returns:CodeWriter

this object

newLineback to summary
public CodeWriter newLine()

Hides java.io.PrintWriter.newLine.

Print a new line char.

Returns:CodeWriter

this object

printlnback to summary
public void println()

Overrides java.io.PrintWriter.println.

Doc from java.io.PrintWriter.println.

Terminates the current line by writing the line separator string. The line separator is System#lineSeparator() and is not necessarily a single newline character ('\n').

stmtback to summary
public CodeWriter stmt(String statement)

This function prints an indentation before the statement and a semicolon followed by a newline after.

Parameters
statement:String

the statement

Returns:CodeWriter

this object

unindentback to summary
public CodeWriter unindent()

Decrement the current indentation.

Returns:CodeWriter

this object

writeback to summary
public void write(String s, int off, int len)

Overrides java.io.PrintWriter.write.

Doc from java.io.PrintWriter.write.

Writes a portion of a string.

Parameters
s:String

A String

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
writeback to summary
public void write(int c)

Overrides java.io.PrintWriter.write.

Doc from java.io.PrintWriter.write.

Writes a single character.

Parameters
c:int

int specifying a character to be written.

Annotations
@Override
writerback to summary
public Writer writer()
Returns:Writer

the current underlying writer

writeSeqback to summary
public CodeWriter writeSeq(Stream<String> sequence, String delimiter)

Write a sequence delimited by a delimiter.

Returns:CodeWriter

this object