prettier-plugin-java 2.6.5 → 2.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/index.js +2 -2
- package/dist/printers/classes.js +3 -0
- package/dist/printers/expressions.js +52 -69
- package/dist/utils/expressions-utils.js +25 -0
- package/dist/utils/printSingleLambdaInvocation.js +18 -0
- package/index.d.ts +4 -0
- package/package.json +22 -16
package/LICENSE
CHANGED
package/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ const languages = [
|
|
|
6
6
|
name: "Java",
|
|
7
7
|
parsers: ["java"],
|
|
8
8
|
group: "Java",
|
|
9
|
-
tmScope: "text.html.vue",
|
|
10
|
-
aceMode: "html",
|
|
9
|
+
tmScope: "text.html.vue", // FIXME
|
|
10
|
+
aceMode: "html", // FIXME
|
|
11
11
|
codemirrorMode: "clike",
|
|
12
12
|
codemirrorMimeType: "text/x-java",
|
|
13
13
|
extensions: [".java"],
|
package/dist/printers/classes.js
CHANGED
|
@@ -3,6 +3,7 @@ import { builders, utils } from "prettier/doc";
|
|
|
3
3
|
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
4
4
|
import { isAnnotationCstNode } from "../types/utils.js";
|
|
5
5
|
import { printArgumentListWithBraces } from "../utils/index.js";
|
|
6
|
+
import { hasLeadingComments } from "./comments/comments-utils.js";
|
|
6
7
|
import { printTokenWithComments } from "./comments/format-comments.js";
|
|
7
8
|
import { handleCommentsBinaryExpression, handleCommentsParameters } from "./comments/handle-comments.js";
|
|
8
9
|
import { concat, dedent, group, indent, indentIfBreak } from "./prettier-builder.js";
|
|
@@ -209,47 +210,23 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter {
|
|
|
209
210
|
const newExpression = (_a = ctx.primaryPrefix[0].children.newExpression) === null || _a === void 0 ? void 0 : _a[0].children;
|
|
210
211
|
const isBreakableNewExpression = countMethodInvocation <= 1 &&
|
|
211
212
|
this.isBreakableNewExpression(newExpression);
|
|
212
|
-
const
|
|
213
|
-
const
|
|
213
|
+
const firstMethodInvocation = (_b = ctx.primarySuffix) === null || _b === void 0 ? void 0 : _b.map(suffix => { var _a; return (_a = suffix.children.methodInvocationSuffix) === null || _a === void 0 ? void 0 : _a[0].children; }).find(methodInvocationSuffix => methodInvocationSuffix);
|
|
214
|
+
const fqnOrRefType = (_c = ctx.primaryPrefix[0].children.fqnOrRefType) === null || _c === void 0 ? void 0 : _c[0].children;
|
|
215
|
+
const hasFqnRefPart = (fqnOrRefType === null || fqnOrRefType === void 0 ? void 0 : fqnOrRefType.fqnOrRefTypePartRest) !== undefined;
|
|
214
216
|
const isCapitalizedIdentifier = this.isCapitalizedIdentifier(fqnOrRefType);
|
|
215
|
-
const shouldBreakBeforeFirstMethodInvocation = countMethodInvocation > 1 &&
|
|
216
|
-
!(isCapitalizedIdentifier !== null && isCapitalizedIdentifier !== void 0 ? isCapitalizedIdentifier : true) &&
|
|
217
|
-
firstMethodInvocation !== undefined;
|
|
217
|
+
const shouldBreakBeforeFirstMethodInvocation = countMethodInvocation > 1 && hasFqnRefPart && !isCapitalizedIdentifier;
|
|
218
218
|
const shouldBreakBeforeMethodInvocations = shouldBreakBeforeFirstMethodInvocation ||
|
|
219
219
|
countMethodInvocation > 2 ||
|
|
220
|
-
(countMethodInvocation > 1 && newExpression) ||
|
|
220
|
+
(countMethodInvocation > 1 && !!newExpression) ||
|
|
221
221
|
!(firstMethodInvocation === null || firstMethodInvocation === void 0 ? void 0 : firstMethodInvocation.argumentList);
|
|
222
222
|
const primaryPrefix = this.visit(ctx.primaryPrefix, Object.assign(Object.assign({}, params), { shouldBreakBeforeFirstMethodInvocation }));
|
|
223
|
-
const suffixes =
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
hasFirstInvocationArg = false;
|
|
231
|
-
}
|
|
232
|
-
if (newExpression &&
|
|
233
|
-
!isBreakableNewExpression &&
|
|
234
|
-
ctx.primarySuffix[0].children.Dot !== undefined) {
|
|
235
|
-
suffixes.push(softline);
|
|
236
|
-
}
|
|
237
|
-
suffixes.push(this.visit(ctx.primarySuffix[0]));
|
|
238
|
-
for (let i = 1; i < ctx.primarySuffix.length; i++) {
|
|
239
|
-
if (shouldBreakBeforeMethodInvocations &&
|
|
240
|
-
ctx.primarySuffix[i].children.Dot !== undefined &&
|
|
241
|
-
ctx.primarySuffix[i - 1].children.methodInvocationSuffix !== undefined) {
|
|
242
|
-
suffixes.push(softline);
|
|
243
|
-
}
|
|
244
|
-
suffixes.push(this.visit(ctx.primarySuffix[i]));
|
|
245
|
-
}
|
|
246
|
-
if (!newExpression && countMethodInvocation === 1) {
|
|
247
|
-
return group(rejectAndConcat([
|
|
248
|
-
primaryPrefix,
|
|
249
|
-
hasFirstInvocationArg ? suffixes[0] : indent(suffixes[0]),
|
|
250
|
-
indent(rejectAndConcat(suffixes.slice(1)))
|
|
251
|
-
]));
|
|
252
|
-
}
|
|
223
|
+
const suffixes = this.getPrimarySuffixes(ctx, newExpression, isBreakableNewExpression, shouldBreakBeforeMethodInvocations);
|
|
224
|
+
if (!newExpression && countMethodInvocation === 1) {
|
|
225
|
+
return group(rejectAndConcat([
|
|
226
|
+
primaryPrefix,
|
|
227
|
+
suffixes[0],
|
|
228
|
+
indent(rejectAndConcat(suffixes.slice(1)))
|
|
229
|
+
]));
|
|
253
230
|
}
|
|
254
231
|
const methodInvocation = (_d = ctx.primarySuffix) === null || _d === void 0 ? void 0 : _d[0].children.methodInvocationSuffix;
|
|
255
232
|
const isMethodInvocationWithArguments = (methodInvocation === null || methodInvocation === void 0 ? void 0 : methodInvocation[0].children.argumentList) !== undefined;
|
|
@@ -290,40 +267,25 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter {
|
|
|
290
267
|
const fqnOrRefTypePartFirst = this.visit(ctx.fqnOrRefTypePartFirst);
|
|
291
268
|
const fqnOrRefTypePartRest = this.mapVisit(ctx.fqnOrRefTypePartRest);
|
|
292
269
|
const dims = this.visit(ctx.dims);
|
|
293
|
-
const dots = ctx.Dot
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
]))
|
|
305
|
-
]);
|
|
306
|
-
// otherwise it is a fully qualified name but we need to exclude when it is just a method call
|
|
307
|
-
}
|
|
308
|
-
else if (ctx.Dot) {
|
|
309
|
-
return indent(rejectAndConcat([
|
|
310
|
-
rejectAndJoinSeps(dots.slice(0, dots.length - 1), [
|
|
311
|
-
fqnOrRefTypePartFirst,
|
|
312
|
-
...fqnOrRefTypePartRest.slice(0, fqnOrRefTypePartRest.length - 1)
|
|
313
|
-
]),
|
|
314
|
-
softline,
|
|
315
|
-
rejectAndConcat([
|
|
316
|
-
dots[dots.length - 1],
|
|
317
|
-
fqnOrRefTypePartRest[fqnOrRefTypePartRest.length - 1]
|
|
318
|
-
]),
|
|
319
|
-
dims
|
|
320
|
-
]));
|
|
321
|
-
}
|
|
270
|
+
const dots = ctx.Dot
|
|
271
|
+
? ctx.Dot.map(dot => {
|
|
272
|
+
if (hasLeadingComments(dot)) {
|
|
273
|
+
return concat([softline, dot]);
|
|
274
|
+
}
|
|
275
|
+
return dot;
|
|
276
|
+
})
|
|
277
|
+
: [];
|
|
278
|
+
if ((params === null || params === void 0 ? void 0 : params.shouldBreakBeforeFirstMethodInvocation) === true &&
|
|
279
|
+
ctx.Dot !== undefined) {
|
|
280
|
+
dots[dots.length - 1] = concat([softline, ctx.Dot[ctx.Dot.length - 1]]);
|
|
322
281
|
}
|
|
323
|
-
return rejectAndConcat([
|
|
324
|
-
rejectAndJoinSeps(dots, [
|
|
282
|
+
return indent(rejectAndConcat([
|
|
283
|
+
rejectAndJoinSeps(dots, [
|
|
284
|
+
fqnOrRefTypePartFirst,
|
|
285
|
+
...fqnOrRefTypePartRest
|
|
286
|
+
]),
|
|
325
287
|
dims
|
|
326
|
-
]);
|
|
288
|
+
]));
|
|
327
289
|
}
|
|
328
290
|
fqnOrRefTypePartFirst(ctx) {
|
|
329
291
|
const annotation = this.mapVisit(ctx.annotation);
|
|
@@ -608,7 +570,28 @@ export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter {
|
|
|
608
570
|
...((_a = fqnOrRefType === null || fqnOrRefType === void 0 ? void 0 : fqnOrRefType.fqnOrRefTypePartRest) !== null && _a !== void 0 ? _a : [])
|
|
609
571
|
];
|
|
610
572
|
const nextToLastIdentifier = (_c = (_b = fqnOrRefTypeParts[fqnOrRefTypeParts.length - 2]) === null || _b === void 0 ? void 0 : _b.children.fqnOrRefTypePartCommon[0].children.Identifier) === null || _c === void 0 ? void 0 : _c[0].image;
|
|
611
|
-
return (nextToLastIdentifier &&
|
|
573
|
+
return (!!nextToLastIdentifier &&
|
|
612
574
|
/^\p{Uppercase_Letter}/u.test(nextToLastIdentifier));
|
|
613
575
|
}
|
|
576
|
+
getPrimarySuffixes(ctx, newExpression, isBreakableNewExpression, shouldBreakBeforeMethodInvocations) {
|
|
577
|
+
if (ctx.primarySuffix === undefined) {
|
|
578
|
+
return [];
|
|
579
|
+
}
|
|
580
|
+
const suffixes = [];
|
|
581
|
+
if (newExpression &&
|
|
582
|
+
!isBreakableNewExpression &&
|
|
583
|
+
ctx.primarySuffix[0].children.Dot !== undefined) {
|
|
584
|
+
suffixes.push(softline);
|
|
585
|
+
}
|
|
586
|
+
suffixes.push(this.visit(ctx.primarySuffix[0]));
|
|
587
|
+
for (let i = 1; i < ctx.primarySuffix.length; i++) {
|
|
588
|
+
if (shouldBreakBeforeMethodInvocations &&
|
|
589
|
+
ctx.primarySuffix[i].children.Dot !== undefined &&
|
|
590
|
+
ctx.primarySuffix[i - 1].children.methodInvocationSuffix !== undefined) {
|
|
591
|
+
suffixes.push(softline);
|
|
592
|
+
}
|
|
593
|
+
suffixes.push(this.visit(ctx.primarySuffix[i]));
|
|
594
|
+
}
|
|
595
|
+
return suffixes;
|
|
596
|
+
}
|
|
614
597
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function isArgumentListSingleLambda(argumentList) {
|
|
2
|
+
if (argumentList === undefined) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const args = argumentList[0].children.expression;
|
|
6
|
+
if (args.length !== 1) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const argument = args[0];
|
|
10
|
+
return argument.children.lambdaExpression !== undefined;
|
|
11
|
+
}
|
|
12
|
+
export const isSingleArgumentLambdaExpressionWithBlock = (argumentList) => {
|
|
13
|
+
if (argumentList === undefined) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const args = argumentList[0].children.expression;
|
|
17
|
+
if (args.length !== 1) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const argument = args[0];
|
|
21
|
+
return (argument.children.lambdaExpression !== undefined &&
|
|
22
|
+
argument.children.lambdaExpression[0].children.lambdaBody[0].children
|
|
23
|
+
.block !== undefined);
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhwcmVzc2lvbnMtdXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvZXhwcmVzc2lvbnMtdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsTUFBTSxVQUFVLDBCQUEwQixDQUN4QyxZQUErQztJQUUvQyxJQUFJLFlBQVksS0FBSyxTQUFTLEVBQUU7UUFDOUIsT0FBTyxLQUFLLENBQUM7S0FDZDtJQUVELE1BQU0sSUFBSSxHQUFHLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQyxRQUFRLENBQUMsVUFBVSxDQUFDO0lBQ2pELElBQUksSUFBSSxDQUFDLE1BQU0sS0FBSyxDQUFDLEVBQUU7UUFDckIsT0FBTyxLQUFLLENBQUM7S0FDZDtJQUVELE1BQU0sUUFBUSxHQUFHLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN6QixPQUFPLFFBQVEsQ0FBQyxRQUFRLENBQUMsZ0JBQWdCLEtBQUssU0FBUyxDQUFDO0FBQzFELENBQUM7QUFFRCxNQUFNLENBQUMsTUFBTSx5Q0FBeUMsR0FBRyxDQUN2RCxZQUErQyxFQUMvQyxFQUFFO0lBQ0YsSUFBSSxZQUFZLEtBQUssU0FBUyxFQUFFO1FBQzlCLE9BQU8sS0FBSyxDQUFDO0tBQ2Q7SUFFRCxNQUFNLElBQUksR0FBRyxZQUFZLENBQUMsQ0FBQyxDQUFDLENBQUMsUUFBUSxDQUFDLFVBQVUsQ0FBQztJQUNqRCxJQUFJLElBQUksQ0FBQyxNQUFNLEtBQUssQ0FBQyxFQUFFO1FBQ3JCLE9BQU8sS0FBSyxDQUFDO0tBQ2Q7SUFFRCxNQUFNLFFBQVEsR0FBRyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDekIsT0FBTyxDQUNMLFFBQVEsQ0FBQyxRQUFRLENBQUMsZ0JBQWdCLEtBQUssU0FBUztRQUNoRCxRQUFRLENBQUMsUUFBUSxDQUFDLGdCQUFnQixDQUFDLENBQUMsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDLENBQUMsUUFBUTthQUNsRSxLQUFLLEtBQUssU0FBUyxDQUN2QixDQUFDO0FBQ0osQ0FBQyxDQUFDIn0=
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { builders } from "prettier/doc";
|
|
2
|
+
import { isSingleArgumentLambdaExpressionWithBlock } from "./expressions-utils.js";
|
|
3
|
+
import { printTokenWithComments } from "../printers/comments/format-comments.js";
|
|
4
|
+
import { concat, dedent, indent } from "../printers/prettier-builder.js";
|
|
5
|
+
import { putIntoBraces } from "../printers/printer-utils.js";
|
|
6
|
+
const { softline, ifBreak } = builders;
|
|
7
|
+
export default function printSingleLambdaInvocation(argumentListCtx, rBrace, lBrace) {
|
|
8
|
+
const lambdaParametersGroupId = Symbol("lambdaParameters");
|
|
9
|
+
const argumentList = this.visit(argumentListCtx, {
|
|
10
|
+
lambdaParametersGroupId,
|
|
11
|
+
isInsideMethodInvocationSuffix: true
|
|
12
|
+
});
|
|
13
|
+
const formattedRBrace = isSingleArgumentLambdaExpressionWithBlock(argumentListCtx)
|
|
14
|
+
? ifBreak(indent(concat([softline, rBrace])), printTokenWithComments(rBrace), { groupId: lambdaParametersGroupId })
|
|
15
|
+
: indent(concat([softline, rBrace]));
|
|
16
|
+
return dedent(putIntoBraces(argumentList, "", lBrace, formattedRBrace));
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJpbnRTaW5nbGVMYW1iZGFJbnZvY2F0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL3ByaW50U2luZ2xlTGFtYmRhSW52b2NhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sY0FBYyxDQUFDO0FBQ3hDLE9BQU8sRUFBRSx5Q0FBeUMsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ25GLE9BQU8sRUFBRSxzQkFBc0IsRUFBRSxNQUFNLHlDQUF5QyxDQUFDO0FBQ2pGLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ3pFLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUU3RCxNQUFNLEVBQUUsUUFBUSxFQUFFLE9BQU8sRUFBRSxHQUFHLFFBQVEsQ0FBQztBQUV2QyxNQUFNLENBQUMsT0FBTyxVQUFVLDJCQUEyQixDQUNqRCxlQUFrRCxFQUNsRCxNQUFjLEVBQ2QsTUFBYztJQUVkLE1BQU0sdUJBQXVCLEdBQUcsTUFBTSxDQUFDLGtCQUFrQixDQUFDLENBQUM7SUFDM0QsTUFBTSxZQUFZLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxlQUFlLEVBQUU7UUFDL0MsdUJBQXVCO1FBQ3ZCLDhCQUE4QixFQUFFLElBQUk7S0FDckMsQ0FBQyxDQUFDO0lBRUgsTUFBTSxlQUFlLEdBQUcseUNBQXlDLENBQy9ELGVBQWUsQ0FDaEI7UUFDQyxDQUFDLENBQUMsT0FBTyxDQUNMLE1BQU0sQ0FBQyxNQUFNLENBQUMsQ0FBQyxRQUFRLEVBQUUsTUFBTSxDQUFDLENBQUMsQ0FBQyxFQUNsQyxzQkFBc0IsQ0FBQyxNQUFNLENBQUMsRUFDOUIsRUFBRSxPQUFPLEVBQUUsdUJBQXVCLEVBQUUsQ0FDckM7UUFDSCxDQUFDLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDLFFBQVEsRUFBRSxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDdkMsT0FBTyxNQUFNLENBQUMsYUFBYSxDQUFDLFlBQVksRUFBRSxFQUFFLEVBQUUsTUFBTSxFQUFFLGVBQWUsQ0FBQyxDQUFDLENBQUM7QUFDMUUsQ0FBQyJ9
|
package/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-java",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.7",
|
|
4
4
|
"description": "Prettier Java Plugin",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"exports":
|
|
6
|
+
"exports": {
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"default": "./dist/index.js"
|
|
9
|
+
},
|
|
7
10
|
"files": [
|
|
8
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"index.d.ts"
|
|
9
13
|
],
|
|
10
14
|
"homepage": "https://jhipster.github.io/prettier-java/",
|
|
11
15
|
"repository": "https://github.com/jhipster/prettier-java",
|
|
12
16
|
"license": "Apache-2.0",
|
|
13
17
|
"dependencies": {
|
|
14
|
-
"java-parser": "2.3.
|
|
15
|
-
"lodash": "4.17.21"
|
|
16
|
-
"prettier": "3.2.5"
|
|
18
|
+
"java-parser": "2.3.3",
|
|
19
|
+
"lodash": "4.17.21"
|
|
17
20
|
},
|
|
18
21
|
"scripts": {
|
|
19
22
|
"test": "yarn run test:unit && yarn run test:e2e-core",
|
|
@@ -28,15 +31,18 @@
|
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
33
|
"@chevrotain/types": "11.0.3",
|
|
31
|
-
"@types/chai": "
|
|
32
|
-
"@types/fs-extra": "
|
|
33
|
-
"@types/jest": "29.
|
|
34
|
-
"@types/klaw-sync": "6.0.
|
|
35
|
-
"@types/lodash": "4.
|
|
36
|
-
"@types/node": "18.
|
|
37
|
-
"@types/sinon": "
|
|
38
|
-
"ts-node": "10.9.
|
|
39
|
-
"typescript": "
|
|
34
|
+
"@types/chai": "5.0.1",
|
|
35
|
+
"@types/fs-extra": "11.0.4",
|
|
36
|
+
"@types/jest": "29.5.14",
|
|
37
|
+
"@types/klaw-sync": "6.0.5",
|
|
38
|
+
"@types/lodash": "4.17.13",
|
|
39
|
+
"@types/node": "18.19.64",
|
|
40
|
+
"@types/sinon": "17.0.3",
|
|
41
|
+
"ts-node": "10.9.2",
|
|
42
|
+
"typescript": "5.6.3"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"prettier": "^3.0.0"
|
|
40
46
|
},
|
|
41
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "79c4d9f960374cf7a2c67fff83efb6e605c41163"
|
|
42
48
|
}
|