Line breaks not working properly in code formatting

已回答

Whenever I hit the reformat code hotkey twice, it asks if I want to format custom line breaks too. When I do this, the result is completely unacceptable. There's probably some setting somewhere to fix this, but I can't seem to locate it.

Manually formatted code, as desired:

public String newJsonValue() throws JsonProcessingException {
if (dataSets.stream().allMatch(set -> set.dataPoints.isEmpty())) {
return null;
}
DateFormat timeJsonFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
List<CategoryDto> categories = new ArrayList<>();
for (DataSet dataSet : dataSets) {
List<PointDto> points = new ArrayList<>();
for (DataPoint dataPoint : dataSet.dataPoints) {
double y = dataSet.getNormalizedValue(dataPoint.value);
points.add(new PointDto(timeJsonFormat.format(new Date(dataPoint.millis)), y,
dataPoint.getInfo()));
}
categories.add(
new CategoryDto(new PopulationDto(points, dataSet.getLabel(), dataSet.get_id())));
}

...<truncated>

 

After hitting the reformat code hotkey twice, and clicking yes on the dialog that asks if custom line breaks should be removed:

public String newJsonValue() throws JsonProcessingException {
if (dataSets.stream().allMatch(set -> set.dataPoints.isEmpty())) {
return null;
} DateFormat timeJsonFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
List<CategoryDto> categories = new ArrayList<>(); for (DataSet dataSet : dataSets) {
List<PointDto> points = new ArrayList<>();
for (DataPoint dataPoint : dataSet.dataPoints) {
double y = dataSet.getNormalizedValue(dataPoint.value); points.add(
new PointDto(timeJsonFormat.format(new Date(dataPoint.millis)), y,
dataPoint.getInfo()));
} categories.add(
new CategoryDto(new PopulationDto(points, dataSet.getLabel(), dataSet.get_id())));
}

...<truncated>

Note how multiple statements are now suddenly on the same line.

 

评论操作 固定链接

Please make sure that Settings (Preferences on macOS) | Editor | Code Style | Java | Wrapping and Braces | Keep when reformatting | Multiple expressions in one line is disabled.

1
评论操作 固定链接

Thanks! That was it.

Seems obvious in retrospect but I just couldn't find it.

0

请先登录再写评论。