Continuation indent in conditional statements and chained method calls

Answered

Is there a way to keep indentation like Eclipse does?

 

Eclipse

public boolean isEnabled() {
  return tree.getSelectionCount() > 0
      && toolsModel.isDeleteActionAvailable(tree
          .getSelectionPaths()); // 2 + 4 + 4 spaces
}

IntelliJ IDEA 2017.3.5

public boolean isEnabled() {
  return tree.getSelectionCount() > 0
      && toolsModel.isDeleteActionAvailable(tree
      .getSelectionPaths()); // 2 + 4 + 0 spaces
}

 

Eclipse

IntStream.range(0, getModel().getRowCount())
    .filter(row -> !getModel().getObject(row).getExcludedRegions().isEmpty()
        && !Collections.disjoint(getModel().getObject(row).getIncludedRegions(),
            getModel().getObject(row).getExcludedRegions())) // 4 + 4 + 4 spaces
    .map(row -> row + 1)
    .mapToObj(String::valueOf)
    .forEach(rowsWithInvalidExcludes::add);

IntelliJ IDEA 2017.3.5

IntStream.range(0, getModel().getRowCount())
    .filter(row -> !getModel().getObject(row).getExcludedRegions().isEmpty()
        && !Collections.disjoint(getModel().getObject(row).getIncludedRegions(),
        getModel().getObject(row).getExcludedRegions())) // 4 + 4 + 0 spaces
    .map(row -> row + 1)
    .mapToObj(String::valueOf)
    .forEach(rowsWithInvalidExcludes::add);

 

Eclipse

public static final RowMapper<
    CompanyItem> ITEM_MAPPER = (rs, rowNum) -> CompanyItem.builder()
        .setId(rs.getString("id")) // 4 + 4 spaces
        .setReportId(rs.getString("report_id")) // 4 + 4 spaces
        .setName(rs.getString("name")) // 4 + 4 spaces
        .setSectorId(rs.getString("sector_id")) // 4 + 4 spaces
        .build(); // 4 + 4 spaces

IntelliJ IDEA 2017.3.5

public static final RowMapper<
    CompanyItem> ITEM_MAPPER = (rs, rowNum) -> CompanyItem.builder()
    .setId(rs.getString("id")) // 4 + 0 spaces
    .setReportId(rs.getString("report_id")) // 4 + 0 spaces
    .setName(rs.getString("name")) // 4 + 0 spaces
    .setSectorId(rs.getString("sector_id")) // 4 + 0 spaces
    .build(); // 4 + 0 spaces

0
3 comments
0

Petr, thanks for the proposal. It really works but it looks like a short term solution. Is there any way to do such formatting using IntelliJ IDEA's native formatter?

0

There is a ticket to provide built in Eclipse formatting options, please upvote:

https://youtrack.jetbrains.com/issue/IDEA-166332

0

Please sign in to leave a comment.