The format task applies 4 non-trivial formatting rules. It parses the text to format into separate words and formats them separately. The word separators are any non-alphanumeric characters, which as a result are skipped. In addition:
- when a lower case letter is followed by a capital letter, the lower case one is treated as ending the previous word, whereas the next letter starts the next word.
- when more than one capital letters are followed by a lower case letter, the last capital letter is treated as start letter of a new word. For example: “SQLPlus” is split into two words – “SQL” and “Plus”
The formatting rules are:
- firstCapital – concatenates the words where the first letter of each word is capitalized and the other letters are converted to lower case. Applied to “SQLPlus” it gives “SqlPlus”. This conforms to the Java Class names formatting convention.
- firstLower – similar to firstCapital rule, but the first word is all with lower case. Applied to “SQLPlus” it gives “sqlPlus”. This conforms to the Java variable names formatting convention.
- allCapital – concatenates all words with all letters are capitalized and put “_” as a word separator. Applied to “SQLPlus” it gives “SQL_PLUS”. This conforms to the Java Constant names formatting convention.
- allLower – concatenates all words converted to lower case. Applied to “SQLPlus” it gives “sqlplus”. This conforms to the Java package names formatting convention.
The use of this task is vastly demonstrated in the demo code generation component, where it formats uniformly the class, variable, constant and package names, while allowing the model not to take care for that formatting, this way keeping the model abstracted from any implementation.