Skip to content

Don't split a short line static method to two lines. #626

Closed
@xenoterracide

Description

@xenoterracide

putting Try and of on separate lines here seems weird.

Input:

    private static <T extends Group> Function<Constructor<?>, T> createInstance(Group entity) {
        return ctor -> Try.of(() -> {
                    @SuppressWarnings("unchecked")
                    var ng = (T) ctor.newInstance(entity.getId(), entity.getSystemGenerated(), entity.getVersionKey());
                    return ng;
                })
                .getOrElseThrow(ex -> new RuntimeException(ex));
    }

Output:

  private static <T extends Group> Function<Constructor<?>, T> createInstance(Group entity) {
    return ctor ->
      Try
        .of(() -> {
          @SuppressWarnings("unchecked")
          var ng = (T) ctor.newInstance(entity.getId(), entity.getSystemGenerated(), entity.getVersionKey());
          return ng;
        })
        .getOrElseThrow(ex -> new RuntimeException(ex));
  }

Expected behavior:

  private static <T extends Group> Function<Constructor<?>, T> createInstance(Group entity) {
    return ctor ->
      Try.of(() -> {
          @SuppressWarnings("unchecked")
          var ng = (T) ctor.newInstance(entity.getId(), entity.getSystemGenerated(), entity.getVersionKey());
          return ng;
        })
        .getOrElseThrow(ex -> new RuntimeException(ex));
  }

or perhaps even this since the return is implicit.

    return ctor -> Try.of(() -> {

Configuration:

  "dependencies": {
    "prettier": "^3.1.1",
    "prettier-plugin-java": "^2.5.0"
  }
printWidth: 120
plugins:
  - prettier-plugin-java
root = true

[*]
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2

[*.bat]
end_of_line = crlf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions