title |
---|
15. Formatter |
A formatter allows to reformat the code automatically based on code style settings.
The formatter uses the blocks to receive formatting rules for each PSI element. Our goal is to cover each PSI element with such block. Since each block builds own children blocks we can generate extra blocks or skip any PSI elements.
{% include /code_samples/simple_language_plugin/src/com/simpleplugin/SimpleBlock.java %}
Let's define a formatter which removes extra spaces except the single ones around the property separator.
{% include /code_samples/simple_language_plugin/src/com/simpleplugin/SimpleFormattingModelBuilder.java %}
<lang.formatter language="Simple" implementationClass="com.simpleplugin.SimpleFormattingModelBuilder"/>
Now add some extra spaces and reformat the code via Code | Reformat Code.