mic*_*ael 6 java eclipse optimization formatting hotkeys
我知道可以通过包含代码来阻止eclipse中的代码格式化
// @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
Run Code Online (Sandbox Code Playgroud)
但我不想一直手动编写它.只需标记代码,按热键即可防止格式化,这将是完美的.
谁知道怎么样?谢谢!
是的,这是可能的:
创建新模板:(
Windows->Preferences->Java->Editor->Templates->New截图)

给模板命名,non-formater然后放置Pattern:
// @formatter:off
${line_selection}${cursor}
// @formatter:on
Run Code Online (Sandbox Code Playgroud)
现在,您可以选择文本并键入Alt+ Shift+ Z和一些模板 - 此处4
