开箱即用的IntelliJ 13可能会为您工作。
如果我这样写:
// Mulit-Line StatementString[] ppl = new String[] { "Karen (F)", "Kevin (M)", "Lee (M)", "Joan (F)", "Des (M)", "Rick (M)" };List<String> strings = Arrays.stream(ppl) .filter( (x) -> { return x.contains("(M)"); } ).collect(Collectors.toList());strings.stream().forEach(System.out::println);然后应用自动格式化程序(无更改):
// Mulit-Line StatementString[] ppl = new String[]{"Karen (F)", "Kevin (M)", "Lee (M)", "Joan (F)", "Des (M)", "Rick (M)"};List<String> strings = Arrays.stream(ppl) .filter( (x) -> { return x.contains("(M)"); } ).collect(Collectors.toList());strings.stream().forEach(System.out::println);单行语句也是如此。我的经验是,IntelliJ在应用其自动格式化方面更加灵活。IntelliJ不太可能删除或添加换行符,如果将其放到那里,则假定您打算将其放到那里。IntelliJ会很高兴为您调整选项卡空间。
IntelliJ也可以配置为您执行某些操作。在“设置”->“代码样式”->“
java”下,在“包装和花括号”选项卡中,可以将“链方法调用”设置为“总是包装”。
自动格式化之前
// Mulit-Line StatementList<String> strings = Arrays.stream(ppl).filter((x) -> { return x.contains("(M)"); }).collect(Collectors.toList());// Single-Line StatementList<String> strings = Arrays.stream(ppl).map((x) -> x.toUpperCase()).filter((x) -> x.contains("(M)")).collect(Collectors.toList());自动格式化后
// Mulit-Line StatementList<String> strings = Arrays.stream(ppl) .filter((x) -> { return x.contains("(M)"); }) .collect(Collectors.toList());// Single-Line StatementList<String> strings = Arrays.stream(ppl) .map((x) -> x.toUpperCase()) .filter((x) -> x.contains("(M)")) .collect(Collectors.toList());


