我知道可以通过包含代码来阻止eclipse中的代码格式化
// @formatter:off // my awesome formatted code... public SettransformCustomersToPersons(List customers){ Set persons = new HashSet (); 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
但我不想一直手动编写它.只需标记代码,按热键即可防止格式化,这将是完美的.
谁知道怎么样?谢谢!
是的,这是可能的:
创建新模板:(
Windows->Preferences->Java->Editor->Templates->New
截图)
给模板命名,non-formater
然后放置Pattern:
// @formatter:off ${line_selection}${cursor} // @formatter:on
现在,您可以选择文本并键入Alt+ Shift+ Z和一些模板 - 此处4