A formatter for the Ceylon programming language.
Note: if the ceylon format
plugin wasn’t installed by default
in your distribution, you can add it by running:
ceylon plugin install ceylon.formatter/1.3.1
To format all Ceylon code in the source
and test-source
directories:
ceylon format source test-source
To format all Ceylon code in the source
directory into the
source-formatted
directory:
ceylon format source --to source-formatted
To format all Ceylon code in the source
and test-source
directories
into the source-formatted
directory:
ceylon format source --and test-source --to source-formatted
(This results in two subdirectories source
and test-source
of source-formatted
.)
You can specify an arbitrary amount of these formatting commands:
ceylon format \ source --to source-formatted \ test-source --to test-source-formatted
(The line breaks are only included for clarity and not a part of the command line syntax.)
If no formatting commands are present, the formatter operates in “pipe mode”, reading code from standard input and writing to standard output.
You can specify formatting options using the following syntax:
--optionName=optionValue # or --optionName optionValue
For available option names, see FormattingOptions
.
The syntax of optionValue
is:
Boolean
or Integer
values, use a Ceylon-style literal (1
, true
)Range
values, use a Ceylon-style range operator x..y
Iterable
values, list the individual elements, separated by spacesdefault
lf
, all
)Use the format()
function to format any AST node.
This can be a compilation unit (simply speaking, a complete file)
or any other node.
If the node was parsed from an existing file, don’t forget
to pass the token stream to format()
–
without the token stream, the formatter can’t obtain the comments,
so they won’t be present in the formatted file.
To construct FormattingOptions, usage of named arguments is highly recommended:
FormattingOptions { indentMode = Spaces(8); maxLineLength = 80; }
You can also use SparseFormattingOptions and combinedOptions to compose several sets of options, like this:
combinedOptions { baseOptions = companyWideOptions; SparseFormattingOptions { indentMode = Spaces(1); // our department has very small screens :-( } }
Packages | |
ceylon.formatter | A formatter for the Ceylon programming language. |
ceylon.formatter.options | Options for the Ceylon formatter. |
Dependencies | ||
ceylon.collection | 1.3.1 | |
ceylon.file | 1.3.1 | |
ceylon.interop.java | 1.3.1 | |
com.redhat.ceylon.cli | 1.3.1 | |
com.redhat.ceylon.common | 1.3.1 | |
com.redhat.ceylon.typechecker | 1.3.1 | |
java.base | 7 |
A formatter for the Ceylon programming language.
The main class of this package is FormattingVisitor
, which visits an
AST Node
(typically
a CompilationUnit)
and writes it out to a Writer
. See the ceylon.formatter.options
package on how
to influence the format of the written code.
Values | |
always | shared always always Indicates that an indentation should always be stacked. |
ifApplied | shared ifApplied ifApplied Indicates that an indentation should be stacked if and only if it was applied, that is:
|
maxDesire | shared Integer maxDesiree = runtime.maxIntegerValue / The maximum value that is safe to use as Using a greater value risks inverting the intended result due to overflow. |
minDesire | shared Integer minDesireire = runtime.minIntegerValue/2 The minimum value that is safe to use as Using a smaller value risks inverting the intended result due to overflow. |
never | shared never never Indicates that an indentation should never be stacked. |
noLineBreak | shared Range<Integer> noLineBreak |
Functions | |
commonRoot | shared Path commonRoot([Path+] paths) Determines the common root of several paths.
For example, the common root of Parameters:
|
desire | shared Integer desire(Boolean|Integer desire) |
format | shared void format(Node node, FormattingOptions options = ..., Writer output = ..., TokenStream? tokens = ..., Integer initialIndentation = ...) Format the given CompilationUnit
and write it to the given Parameters:
|
help | shared String? help(String? topic) Returns a help string for the given Parameters:
|
parseTranslations | shared <String[]->String>[] parseTranslations(String[] arguments) Parses translations from the For example, the arguments a/b/c --and a/b/d --to x/a/b d/e f/g --to m/n/f/g correspond to the translations [ [a/b/c, a/b/d] -> x/a/b, d/e -> d/e, f/g -> m/n/f/g ] The special argument |
run | shared void run(String[] arguments = ...) Run the module Parameters:
|
Classes | |
CeylonFormatTool | shared CeylonFormatTool |
FormattingVisitor | shared FormattingVisitor A |
FormattingWriter | shared FormattingWriter Writes tokens to an underlying The
Additionally, it also writes comments if a token stream is given. IndentationTwo indentation levels are associated with each token: one before the token, and one after it. Each token also introduces a context which tracks these indentation levels if they stack. In this case, their indentation is applied to all subsequent lines until the context is closed. By default, the indentation before the token When the token is written, its context (instance of A context can be closed in two ways:
You can also obtain a context not associated with any token by calling Examples:
Line BreakingTwo The intersection of these ranges for the border between two tokens is then used to determine how many line breaks should be written before the token.
(Internally, the Additionally, the SpacingIf you’ve made it this far, relax, this is the easiest section :) Two To avoid inverting the intended result by numerical overflow, don’t use values outside the range
CommentsThe fast-forwarding of the token stream (if given) was already mentioned in the “Line Breaking” section. If comment tokens are encountered during the fast-forwarding, they are written out like tokens with
|
StackCondition | shared abstract StackCondition A condition that dictates when a token’s indentation stacks. |
always | shared always Indicates that an indentation should always be stacked. |
ifApplied | shared ifApplied Indicates that an indentation should be stacked if and only if it was applied, that is:
|
never | shared never Indicates that an indentation should never be stacked. |