Skip to content

Commit 4d366ee

Browse files
refactor: simplify logic for printing fqn parts
1 parent 2a1c78e commit 4d366ee

1 file changed

Lines changed: 6 additions & 37 deletions

File tree

packages/prettier-plugin-java/src/printers/expressions.ts

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -457,43 +457,12 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter {
457457
return dot;
458458
})
459459
: [];
460-
const isMethodInvocation = ctx.Dot && ctx.Dot.length === 1;
461-
462-
if (params?.shouldBreakBeforeFirstMethodInvocation === true) {
463-
// when fqnOrRefType is a method call from an object
464-
if (isMethodInvocation) {
465-
const separator = hasLeadingComments(ctx.Dot![0])
466-
? dots[0]
467-
: concat([softline, dots[0]]);
468-
return rejectAndConcat([
469-
indent(
470-
rejectAndConcat([
471-
fqnOrRefTypePartFirst,
472-
separator,
473-
rejectAndJoinSeps(dots.slice(1), fqnOrRefTypePartRest),
474-
dims
475-
])
476-
)
477-
]);
478-
// otherwise it is a fully qualified name but we need to exclude when it is just a method call
479-
} else if (ctx.Dot) {
480-
const lastDot = ctx.Dot[ctx.Dot.length - 1];
481-
const separator = hasLeadingComments(lastDot)
482-
? dots[dots.length - 1]
483-
: concat([softline, lastDot]);
484-
485-
return indent(
486-
rejectAndConcat([
487-
rejectAndJoinSeps(dots.slice(0, dots.length - 1), [
488-
fqnOrRefTypePartFirst,
489-
...fqnOrRefTypePartRest.slice(0, fqnOrRefTypePartRest.length - 1)
490-
]),
491-
separator,
492-
fqnOrRefTypePartRest[fqnOrRefTypePartRest.length - 1],
493-
dims
494-
])
495-
);
496-
}
460+
461+
if (
462+
params?.shouldBreakBeforeFirstMethodInvocation === true &&
463+
ctx.Dot !== undefined
464+
) {
465+
dots[dots.length - 1] = concat([softline, ctx.Dot[ctx.Dot.length - 1]]);
497466
}
498467

499468
return indent(

0 commit comments

Comments
 (0)