Interface CodeBlock
- All Known Implementing Classes:
CodeBlockImpl
The definition of a fragment for a *.java
file,
potentially containing declarations, statements, and documentation. Code
blocks are not necessarily well-formed Java code, and they are not
validated. Implementations of this interface assume that javac
will
check correctness later!
Code blocks do support placeholders like
Format
.
Where
String.format()
uses percent %
to reference target values, this class uses dollar
sign $
and has its own set of permitted placeholders:
$L
emits a literal value with no escaping. Arguments for literals may be strings, primitives, type declarations, annotations and even other code blocks.$N
emits a name, using name collision avoidance where necessary. Arguments for names may be Strings (actually any character sequence), parameters, fields, methods, and types.$S
escapes the value as a String, wraps it with double quotes, and emits that. For example,6" sandwich
is emitted"6\" sandwich"
.$T
emits a type reference. Types will be imported if possible. Arguments for types may be classes, type mirrors, and elements.$$
emits a dollar sign.$W
emits a space or a newline, depending on its position on the line. This prefers to wrap lines before 100 columns.$Z
acts as a zero-width space. This prefers to wrap lines before 100 columns.$>
increases the indentation level.$<
decreases the indentation level.$[
begins a statement. For multi-line statements, every line after the first line is double-indented.$]
ends a statement.
- Author:
- Square,Inc.
- Modified by:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: CodeBlock.java 1085 2024-01-05 16:23:28Z tquadrat $
- Since:
- 0.0.5
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.javacomposer.CodeBlock"
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
The definition of a builder for a new instance of an implementation ofCodeBlock
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
hashCode()
boolean
isEmpty()
Checks whether this code block is empty.Joins this code block with the given code blocks into a single newCodeBlock
instance, each separated by the given separator.Joins this code block with the given code blocks into a single newCodeBlock
instance, each separated by the given separator.Creates a new builder that is initialised with the components of this code block.toString()
-
Method Details
-
equals
-
hashCode
int hashCode() -
isEmpty
boolean isEmpty()Checks whether this code block is empty.- Returns:
true
if the code block is empty,false
otherwise.
-
join
Joins this code block with the given code blocks into a single new
CodeBlock
instance, each separated by the given separator.For example, joining "
String s
", "Object o
" and "int i
" using ",
" as the separator would produce "String s, Object o, int i
".- Parameters:
separator
- The separator.codeBlocks
- The code blocks to join with this one.- Returns:
- The new code block.
-
join
@API(status=STABLE, since="0.2.0") CodeBlock join(String separator, String prefix, String suffix, CodeBlock... codeBlocks) Joins this code block with the given code blocks into a single new
CodeBlock
instance, each separated by the given separator. The given prefix will be prepended to the newCodeBloc
, and the given suffix will be appended to it.For example, joining "
String s
", "Object o
" and "int i
" using ",
" as the separator would produce "String s, Object o, int i
".- Parameters:
separator
- The separator.prefix
- The prefix.suffix
- The suffix.codeBlocks
- The code blocks to join.- Returns:
- The new code block.
-
toBuilder
Creates a new builder that is initialised with the components of this code block.- Returns:
- The new builder.
-
toString
-