Skip to content

Commit

Permalink
Merge pull request #602 from jtkiesel/fix/assignment-indentation
Browse files Browse the repository at this point in the history
fix: correct indentation of assignment operations
  • Loading branch information
pascalgrimaud authored Aug 29, 2023
2 parents fce16b9 + 8c997e9 commit f74555d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/prettier-plugin-java/src/printers/printer-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ export function binary(nodes: Doc[], tokens: IToken[], isRoot = false): Doc {
}
}
level.push(nodes.shift()!);
return group(join(line, level));
const content = group(join(line, level));
return levelOperator === "=" ? indent(content) : content;
}

function getOperator(tokens: IToken[]) {
Expand Down
17 changes: 17 additions & 0 deletions packages/prettier-plugin-java/test/unit-test/variables/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,21 @@ public methodWithVariableInitializationWithComments() {
someRandomMethodThatReturnsTheInitialMapThatWeWantToMutate()
);
}

void assignment() {
fileSystemDetails =
FileHandlerDetails
.builder()
.fileSystemType(
EntityUtils.update(
entity.getFileSystemDetails().getFileSystemType(),
update.getFileSystemDetails().getFileSystemType()
)
);

aaaaaaaaaaaaaaaaa =
bbbbbbbbbbbbbbbbb ? ccccccccccccccccc : ddddddddddddddddd;

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = ccccccccccccccccccccccccccccccccccccccc + ddddddddddddddddddddddddddddddddd;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,24 @@ public methodWithVariableInitializationWithComments() {
someRandomMethodThatReturnsTheInitialMapThatWeWantToMutate()
);
}

void assignment() {
fileSystemDetails =
FileHandlerDetails
.builder()
.fileSystemType(
EntityUtils.update(
entity.getFileSystemDetails().getFileSystemType(),
update.getFileSystemDetails().getFileSystemType()
)
);

aaaaaaaaaaaaaaaaa =
bbbbbbbbbbbbbbbbb ? ccccccccccccccccc : ddddddddddddddddd;

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb =
ccccccccccccccccccccccccccccccccccccccc +
ddddddddddddddddddddddddddddddddd;
}
}

0 comments on commit f74555d

Please sign in to comment.