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
40 changes: 22 additions & 18 deletions packages/prettier-plugin-java/src/printers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,26 +304,30 @@ export function printClassType(
path: AstPath<JavaNonTerminal & { children: ClassTypeCtx }>,
print: JavaPrintFn
) {
return flatMap(
path,
childPath => {
const { node, isLast } = childPath;
const child = [print(childPath)];
if (isTerminal(node)) {
if (!isLast) {
child.push(".");
const { children } = path.node;
return definedKeys(children, ["annotation", "Identifier", "typeArguments"])
.flatMap(child =>
children[child]!.map((node, index) => ({
child,
index,
startOffset: parser.locStart(node)
}))
)
.sort((a, b) => a.startOffset - b.startOffset)
.flatMap(({ child, index: childIndex }, index, array) => {
const node = children[child]![childIndex];
const next = array.at(index + 1);
const nextNode = next && children[next.child]![next.index];
const docs = [call(path, print, child, childIndex)];
if (nextNode) {
if (isNonTerminal(node)) {
docs.push(node.name === "annotation" ? " " : ".");
} else if (isTerminal(nextNode) || nextNode.name === "annotation") {
docs.push(".");
}
} else if (node.name === "annotation") {
child.push(" ");
}
return child;
},
definedKeys(path.node.children, [
"annotation",
"Identifier",
"typeArguments"
])
);
return docs;
});
}

export function isBinaryExpression(expression: ExpressionCstNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ public void dataTypes() {
String stringVariable;
}

public void complexTypes() {
@A B.C<D>.@E @F G.H h;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public void dataTypes() {
Boolean booleanVariable;
String stringVariable;
}

public void complexTypes() {
@A
B.C<D>.@E @F G.H h;
}
}