Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/prettier-plugin-java/src/printers/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ export default {
(operators.length > 0 && !children.AssignmentOperator) ||
(children.expression !== undefined &&
isBinaryExpression(children.expression[0]));
const isInList =
(path.getNode(4) as JavaNonTerminal | null)?.name === "elementValue" ||
(path.getNode(6) as JavaNonTerminal | null)?.name === "argumentList";
return binary(operands, operators, {
hasNonAssignmentOperators,
isInList,
isRoot: true,
operatorPosition: options.experimentalOperatorPosition
});
Expand Down Expand Up @@ -627,10 +631,12 @@ function binary(
operators: { image: string; doc: Doc }[],
{
hasNonAssignmentOperators = false,
isInList = false,
isRoot = false,
operatorPosition
}: {
hasNonAssignmentOperators?: boolean;
isInList?: boolean;
isRoot?: boolean;
operatorPosition: "end" | "start";
}
Expand Down Expand Up @@ -686,7 +692,9 @@ function binary(
level.push(operands.shift()!);
if (
!levelOperator ||
(!isAssignmentOperator(levelOperator) && levelOperator !== "instanceof")
(!isInList &&
!isAssignmentOperator(levelOperator) &&
levelOperator !== "instanceof")
) {
return group(level);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public void binaryOperation() {

@Annotation(
"This operation with two very long string should break" +
"in a very nice way"
"in a very nice way"
)
public String binaryOperationThatShouldBreak() {
System.out.println(
"This operation with two very long string should break" +
"in a very nice way"
"in a very nice way"
);
return (
"This operation with two very long string should break" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public void binaryOperation() {

@Annotation(
"This operation with two very long string should break"
+ "in a very nice way"
+ "in a very nice way"
)
public String binaryOperationThatShouldBreak() {
System.out.println(
"This operation with two very long string should break"
+ "in a very nice way"
+ "in a very nice way"
);
return (
"This operation with two very long string should break"
Expand Down