Skip to content

Ugly formatting of a method reference of an expression #765

@boris-petrov

Description

@boris-petrov

Prettier-Java 2.7.3

Playground link

--print-width 100

Input:

public abstract class Foo implements MyInterface {
	@Override
	public String foo() {
		Iterable<Map.Entry<String, Object>> iterable = (sortMapKeys && value.size() > 1
			? value.entrySet().stream().sorted(Map.Entry.comparingByKey())
			: value.entrySet().stream())::iterator;
	}
}

Output:

public abstract class Foo implements MyInterface {

	@Override
	public String foo() {
		Iterable<Map.Entry<String, Object>> iterable = (sortMapKeys && value.size() > 1
				? value.entrySet().stream().sorted(Map.Entry.comparingByKey())
				: value.entrySet().stream())::iterator;
	}
}

Expected behavior:
Unsure how but prettier. 😄 Perhaps:

Iterable<Map.Entry<String, Object>> iterable = (
	sortMapKeys && value.size() > 1
		? value.entrySet().stream().sorted(Map.Entry.comparingByKey())
		: value.entrySet().stream()
	)
	::iterator;

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