Skip to content

Commit

Permalink
fix: correct indentation of assignment operations
Browse files Browse the repository at this point in the history
closes #601
  • Loading branch information
jtkiesel committed Aug 28, 2023
1 parent fce16b9 commit 8c997e9
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 8c997e9

Please sign in to comment.