I knew one can prevent the code formatting in eclipse by surrounding the code with
// @formatter:off
// my awesome formatted code...
public Set<Person> transformCustomersToPersons(List<Customer> customers){
Set<Person> persons = new HashSet<Person>();
for (Customer customer : customers) {
persons.add(new Person(
customer.getFirstname(),
customer.getLastname(),
customer.getTitle(),
customer.getBirthday(),
customer.getAddress(0).getCity(),
customer.getAddress(0).getStreet(),
customer.getAddress(0).getHousenumber(),
customer.isMan() ? "m" : "w",
customer.getCardNumber())
);
}
return persons;
}
// @formatter:on
But I don't want to write it manually all the time. It would be perfect just mark the code, press a hotkey and the code gets prevented from formatting.
Anybody knows how? Thx!
To format your whole script: Open the required file. Go to Source | Format Document or press Ctrl+Shift+F.
Preferences-> C/C++-> Editor-> Typing-> Automatically indent-> UNCHECK "new lines and braces" 4. Click mouse beyond end of any indented source-code line.
Importing preferences for automatic formatting. Eclipse has the capability to do so some automatic formatting whenever a file that is being edited is saved. This automatic formatting can make programs more readable and understandable.
Yes, that is possible:
Create new template:
Windows->Preferences->Java->Editor->Templates->New
(screenshot)
Give a name to the template something like non-formater
and put the Pattern:
// @formatter:off
${line_selection}${cursor}
// @formatter:on
Now, you can select the text and type Alt+Shift+Z and a number of the template - here 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With