The formatter modifies only the characters between blocks, and the tree of blocks must be built so that the bottom-level blocks cover all non-whitespace characters in the file. Its children cover individual classes in the file, blocks on the next level cover methods inside classes, etc. The structure of blocks is usually built so that it mirrors the PSI structure of the file – for example, in Java code, the top-level formatting block covers the entire file. The formatting model is requested to insert the calculated whitespace characters at necessary positions in the file. The formatting engine calculates the sequence of whitespace characters (spaces, tabs, and/or line breaks) that needs to be placed at every block boundary, based on the plugin's formatting model. The formatting model is requested to build the structure of the file as applies to formatting, as a tree of blocks ( Block) with an associated indent, wrap, alignment, and spacing settings. The formatting model builder ( FormattingModelBuilder), implemented by the plugin, provides a formatting model ( FormattingModel) for the document to be formatted. The process of formatting a file or a file fragment consists of the following main steps: The formatting engine, provided by the IDE, calculates the smallest number of whitespace modifications that need to be performed on the file to make it match the constraints. In this framework, the plugin specifies the constraints on the whitespaces between different syntax elements. The IntelliJ Platform includes a powerful framework for implementing custom language formatters.
0 Comments
Leave a Reply. |