prettier-plugin-java 2.6.8 → 2.7.1

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.
Files changed (45) hide show
  1. package/dist/comments.d.ts +17 -0
  2. package/dist/comments.js +199 -0
  3. package/dist/index.d.ts +543 -0
  4. package/dist/index.js +26 -63
  5. package/dist/options.d.ts +23 -0
  6. package/dist/options.js +247 -239
  7. package/dist/parser.d.ts +9 -0
  8. package/dist/parser.js +24 -4
  9. package/dist/printer.d.ts +18 -0
  10. package/dist/printer.js +39 -5
  11. package/dist/printers/arrays.d.ts +9 -0
  12. package/dist/printers/arrays.js +8 -24
  13. package/dist/printers/blocks-and-statements.d.ts +117 -0
  14. package/dist/printers/blocks-and-statements.js +316 -412
  15. package/dist/printers/classes.d.ts +157 -0
  16. package/dist/printers/classes.js +422 -685
  17. package/dist/printers/expressions.d.ts +134 -0
  18. package/dist/printers/expressions.js +549 -555
  19. package/dist/printers/helpers.d.ts +71 -0
  20. package/dist/printers/helpers.js +233 -0
  21. package/dist/printers/index.d.ts +2 -0
  22. package/dist/printers/index.js +13 -0
  23. package/dist/printers/interfaces.d.ts +62 -0
  24. package/dist/printers/interfaces.js +146 -211
  25. package/dist/printers/lexical-structure.d.ts +14 -0
  26. package/dist/printers/lexical-structure.js +26 -28
  27. package/dist/printers/names.d.ts +12 -0
  28. package/dist/printers/names.js +11 -29
  29. package/dist/printers/packages-and-modules.d.ts +46 -0
  30. package/dist/printers/packages-and-modules.js +157 -159
  31. package/dist/printers/types-values-and-variables.d.ts +46 -0
  32. package/dist/printers/types-values-and-variables.js +86 -149
  33. package/package.json +5 -8
  34. package/dist/base-cst-printer.js +0 -55
  35. package/dist/cst-printer.js +0 -29
  36. package/dist/printers/comments/comments-utils.js +0 -21
  37. package/dist/printers/comments/format-comments.js +0 -171
  38. package/dist/printers/comments/handle-comments.js +0 -102
  39. package/dist/printers/prettier-builder.js +0 -45
  40. package/dist/printers/printer-utils.js +0 -598
  41. package/dist/types/utils.js +0 -20
  42. package/dist/utils/index.js +0 -2
  43. package/dist/utils/isEmptyDoc.js +0 -4
  44. package/dist/utils/printArgumentListWithBraces.js +0 -37
  45. package/index.d.ts +0 -4
@@ -1,222 +1,157 @@
1
- import { concat, group, indent } from "./prettier-builder.js";
2
- import { printTokenWithComments } from "./comments/format-comments.js";
3
- import { handleCommentsParameters } from "./comments/handle-comments.js";
4
- import { displaySemicolon, getInterfaceBodyDeclarationsSeparator, isStatementEmptyStatement, printArrayList, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortModifiers } from "./printer-utils.js";
5
1
  import { builders } from "prettier/doc";
6
- import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
7
- const { line, softline, hardline } = builders;
8
- export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter {
9
- interfaceDeclaration(ctx) {
10
- const modifiers = sortModifiers(ctx.interfaceModifier);
11
- const firstAnnotations = this.mapVisit(modifiers[0]);
12
- const otherModifiers = this.mapVisit(modifiers[1]);
13
- const declaration = ctx.normalInterfaceDeclaration
14
- ? this.visit(ctx.normalInterfaceDeclaration)
15
- : this.visit(ctx.annotationInterfaceDeclaration);
16
- return rejectAndJoin(hardline, [
17
- rejectAndJoin(hardline, firstAnnotations),
18
- rejectAndJoin(" ", [rejectAndJoin(" ", otherModifiers), declaration])
2
+ import { call, each, hasDeclarationAnnotations, indentInParentheses, lineEndWithComments, lineStartWithComments, onlyDefinedKey, printArrayInitializer, printBlock, printClassPermits, printList, printSingle, printWithModifiers } from "./helpers.js";
3
+ const { group, hardline, indent, join, line } = builders;
4
+ export default {
5
+ interfaceDeclaration(path, print) {
6
+ const declarationKey = onlyDefinedKey(path.node.children, [
7
+ "annotationInterfaceDeclaration",
8
+ "normalInterfaceDeclaration"
19
9
  ]);
20
- }
21
- normalInterfaceDeclaration(ctx) {
22
- const typeIdentifier = this.visit(ctx.typeIdentifier);
23
- const typeParameters = this.visit(ctx.typeParameters);
24
- const interfaceExtends = this.visit(ctx.interfaceExtends);
25
- const optionalInterfacePermits = this.visit(ctx.interfacePermits);
26
- const interfaceBody = this.visit(ctx.interfaceBody);
27
- let interfaceExtendsPart = "";
10
+ return printWithModifiers(path, print, "interfaceModifier", call(path, print, declarationKey), true);
11
+ },
12
+ normalInterfaceDeclaration(path, print) {
13
+ const { interfaceExtends, interfacePermits, typeParameters } = path.node.children;
14
+ const header = ["interface ", call(path, print, "typeIdentifier")];
15
+ if (typeParameters) {
16
+ header.push(call(path, print, "typeParameters"));
17
+ }
28
18
  if (interfaceExtends) {
29
- interfaceExtendsPart = indent(rejectAndConcat([softline, interfaceExtends]));
19
+ header.push(indent([line, call(path, print, "interfaceExtends")]));
30
20
  }
31
- let interfacePermits = "";
32
- if (optionalInterfacePermits) {
33
- interfacePermits = indent(rejectAndConcat([softline, optionalInterfacePermits]));
21
+ if (interfacePermits) {
22
+ header.push(indent([line, call(path, print, "interfacePermits")]));
34
23
  }
35
- return rejectAndJoin(" ", [
36
- group(rejectAndJoin(" ", [
37
- ctx.Interface[0],
38
- concat([typeIdentifier, typeParameters]),
39
- interfaceExtendsPart,
40
- interfacePermits
41
- ])),
42
- interfaceBody
24
+ return [group(header), " ", call(path, print, "interfaceBody")];
25
+ },
26
+ interfaceModifier: printSingle,
27
+ interfaceExtends(path, print) {
28
+ return group([
29
+ "extends",
30
+ indent([line, call(path, print, "interfaceTypeList")])
43
31
  ]);
44
- }
45
- interfaceModifier(ctx) {
46
- if (ctx.annotation) {
47
- return this.visitSingle(ctx);
48
- }
49
- return printTokenWithComments(this.getSingle(ctx));
50
- }
51
- interfaceExtends(ctx) {
52
- const interfaceTypeList = this.visit(ctx.interfaceTypeList);
53
- return group(rejectAndConcat([
54
- ctx.Extends[0],
55
- indent(rejectAndConcat([line, interfaceTypeList]))
56
- ]));
57
- }
58
- interfacePermits(ctx) {
59
- return this.classPermits(ctx);
60
- }
61
- interfaceBody(ctx) {
62
- let joinedInterfaceMemberDeclaration = "";
63
- if (ctx.interfaceMemberDeclaration !== undefined) {
64
- const interfaceMemberDeclaration = this.mapVisit(ctx.interfaceMemberDeclaration);
65
- const separators = getInterfaceBodyDeclarationsSeparator(ctx.interfaceMemberDeclaration);
66
- joinedInterfaceMemberDeclaration = rejectAndJoinSeps(separators, interfaceMemberDeclaration);
67
- }
68
- return putIntoBraces(joinedInterfaceMemberDeclaration, hardline, ctx.LCurly[0], ctx.RCurly[0]);
69
- }
70
- interfaceMemberDeclaration(ctx) {
71
- if (ctx.Semicolon) {
72
- return displaySemicolon(ctx.Semicolon[0]);
73
- }
74
- return this.visitSingle(ctx);
75
- }
76
- constantDeclaration(ctx) {
77
- const modifiers = sortModifiers(ctx.constantModifier);
78
- const firstAnnotations = this.mapVisit(modifiers[0]);
79
- const otherModifiers = this.mapVisit(modifiers[1]);
80
- const unannType = this.visit(ctx.unannType);
81
- const variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
82
- return rejectAndJoin(hardline, [
83
- rejectAndJoin(hardline, firstAnnotations),
84
- rejectAndJoin(" ", [
85
- rejectAndJoin(" ", otherModifiers),
86
- unannType,
87
- rejectAndConcat([variableDeclaratorList, ctx.Semicolon[0]])
88
- ])
32
+ },
33
+ interfacePermits: printClassPermits,
34
+ interfaceBody(path, print) {
35
+ const declarations = [];
36
+ let previousRequiresPadding = false;
37
+ each(path, declarationPath => {
38
+ var _a, _b, _c, _d;
39
+ const declaration = print(declarationPath);
40
+ if (declaration === "") {
41
+ return;
42
+ }
43
+ const { node, previous } = declarationPath;
44
+ const constantDeclaration = (_a = node.children.constantDeclaration) === null || _a === void 0 ? void 0 : _a[0].children;
45
+ const methodDeclaration = (_b = node.children.interfaceMethodDeclaration) === null || _b === void 0 ? void 0 : _b[0].children;
46
+ const currentRequiresPadding = (!constantDeclaration && !methodDeclaration) ||
47
+ (methodDeclaration === null || methodDeclaration === void 0 ? void 0 : methodDeclaration.methodBody[0].children.block) !== undefined ||
48
+ hasDeclarationAnnotations((_d = (_c = constantDeclaration === null || constantDeclaration === void 0 ? void 0 : constantDeclaration.constantModifier) !== null && _c !== void 0 ? _c : methodDeclaration === null || methodDeclaration === void 0 ? void 0 : methodDeclaration.interfaceMethodModifier) !== null && _d !== void 0 ? _d : []);
49
+ const blankLine = declarations.length > 0 &&
50
+ (previousRequiresPadding ||
51
+ currentRequiresPadding ||
52
+ lineStartWithComments(node) > lineEndWithComments(previous) + 1);
53
+ declarations.push(blankLine ? [hardline, declaration] : declaration);
54
+ previousRequiresPadding = currentRequiresPadding;
55
+ }, "interfaceMemberDeclaration");
56
+ return printBlock(path, declarations);
57
+ },
58
+ interfaceMemberDeclaration(path, print) {
59
+ const { children } = path.node;
60
+ return children.Semicolon
61
+ ? ""
62
+ : call(path, print, onlyDefinedKey(children));
63
+ },
64
+ constantDeclaration(path, print) {
65
+ const declaration = [
66
+ call(path, print, "unannType"),
67
+ " ",
68
+ call(path, print, "variableDeclaratorList"),
69
+ ";"
70
+ ];
71
+ return printWithModifiers(path, print, "constantModifier", declaration);
72
+ },
73
+ constantModifier: printSingle,
74
+ interfaceMethodDeclaration(path, print) {
75
+ const declaration = [
76
+ call(path, print, "methodHeader"),
77
+ path.node.children.methodBody[0].children.Semicolon ? "" : " ",
78
+ call(path, print, "methodBody")
79
+ ];
80
+ return printWithModifiers(path, print, "interfaceMethodModifier", declaration);
81
+ },
82
+ interfaceMethodModifier: printSingle,
83
+ annotationInterfaceDeclaration(path, print) {
84
+ return join(" ", [
85
+ "@interface",
86
+ call(path, print, "typeIdentifier"),
87
+ call(path, print, "annotationInterfaceBody")
89
88
  ]);
90
- }
91
- constantModifier(ctx) {
92
- if (ctx.annotation) {
93
- return this.visitSingle(ctx);
89
+ },
90
+ annotationInterfaceBody(path, print) {
91
+ const declarations = [];
92
+ each(path, declarationPath => {
93
+ const declaration = print(declarationPath);
94
+ if (declaration === "") {
95
+ return;
96
+ }
97
+ declarations.push(declarationPath.isFirst ? declaration : [hardline, declaration]);
98
+ }, "annotationInterfaceMemberDeclaration");
99
+ return printBlock(path, declarations);
100
+ },
101
+ annotationInterfaceMemberDeclaration(path, print) {
102
+ const { children } = path.node;
103
+ return children.Semicolon
104
+ ? ""
105
+ : call(path, print, onlyDefinedKey(children));
106
+ },
107
+ annotationInterfaceElementDeclaration(path, print) {
108
+ const { dims, defaultValue } = path.node.children;
109
+ const declaration = [
110
+ call(path, print, "unannType"),
111
+ " ",
112
+ call(path, print, "Identifier"),
113
+ "()"
114
+ ];
115
+ if (dims) {
116
+ declaration.push(call(path, print, "dims"));
94
117
  }
95
- return printTokenWithComments(this.getSingle(ctx));
96
- }
97
- interfaceMethodDeclaration(ctx) {
98
- const modifiers = sortModifiers(ctx.interfaceMethodModifier);
99
- const firstAnnotations = this.mapVisit(modifiers[0]);
100
- const otherModifiers = this.mapVisit(modifiers[1]);
101
- const methodHeader = this.visit(ctx.methodHeader);
102
- const methodBody = this.visit(ctx.methodBody);
103
- const separator = isStatementEmptyStatement(methodBody) ? "" : " ";
104
- return rejectAndJoin(hardline, [
105
- rejectAndJoin(hardline, firstAnnotations),
106
- rejectAndJoin(" ", [
107
- rejectAndJoin(" ", otherModifiers),
108
- rejectAndJoin(separator, [methodHeader, methodBody])
109
- ])
110
- ]);
111
- }
112
- interfaceMethodModifier(ctx) {
113
- if (ctx.annotation) {
114
- return this.visitSingle(ctx);
118
+ if (defaultValue) {
119
+ declaration.push(" ", call(path, print, "defaultValue"));
115
120
  }
116
- return printTokenWithComments(this.getSingle(ctx));
117
- }
118
- annotationInterfaceDeclaration(ctx) {
119
- const typeIdentifier = this.visit(ctx.typeIdentifier);
120
- const annotationInterfaceBody = this.visit(ctx.annotationInterfaceBody);
121
- return rejectAndJoin(" ", [
122
- concat([ctx.At[0], ctx.Interface[0]]),
123
- typeIdentifier,
124
- annotationInterfaceBody
125
- ]);
126
- }
127
- annotationInterfaceBody(ctx) {
128
- const annotationInterfaceMemberDeclaration = this.mapVisit(ctx.annotationInterfaceMemberDeclaration);
129
- return rejectAndJoin(line, [
130
- indent(rejectAndJoin(line, [
131
- ctx.LCurly[0],
132
- rejectAndJoin(concat([line, line]), annotationInterfaceMemberDeclaration)
133
- ])),
134
- ctx.RCurly[0]
135
- ]);
136
- }
137
- annotationInterfaceMemberDeclaration(ctx) {
138
- if (ctx.Semicolon) {
139
- return printTokenWithComments(this.getSingle(ctx));
121
+ declaration.push(";");
122
+ return printWithModifiers(path, print, "annotationInterfaceElementModifier", declaration);
123
+ },
124
+ annotationInterfaceElementModifier: printSingle,
125
+ defaultValue(path, print) {
126
+ return ["default ", call(path, print, "elementValue")];
127
+ },
128
+ annotation(path, print) {
129
+ const { children } = path.node;
130
+ const annotation = ["@", call(path, print, "typeName")];
131
+ if (children.elementValue || children.elementValuePairList) {
132
+ const valuesKey = onlyDefinedKey(children, [
133
+ "elementValue",
134
+ "elementValuePairList"
135
+ ]);
136
+ annotation.push(indentInParentheses(call(path, print, valuesKey)));
140
137
  }
141
- return this.visitSingle(ctx);
142
- }
143
- annotationInterfaceElementDeclaration(ctx) {
144
- const modifiers = sortModifiers(ctx.annotationInterfaceElementModifier);
145
- const firstAnnotations = this.mapVisit(modifiers[0]);
146
- const otherModifiers = this.mapVisit(modifiers[1]);
147
- const unannType = this.visit(ctx.unannType);
148
- const identifier = ctx.Identifier[0];
149
- const dims = this.visit(ctx.dims);
150
- const defaultValue = ctx.defaultValue
151
- ? concat([" ", this.visit(ctx.defaultValue)])
152
- : "";
153
- return rejectAndJoin(hardline, [
154
- rejectAndJoin(hardline, firstAnnotations),
155
- rejectAndJoin(" ", [
156
- rejectAndJoin(" ", otherModifiers),
157
- unannType,
158
- rejectAndConcat([
159
- identifier,
160
- concat([ctx.LBrace[0], ctx.RBrace[0]]),
161
- dims,
162
- defaultValue,
163
- ctx.Semicolon[0]
164
- ])
165
- ])
138
+ return annotation;
139
+ },
140
+ elementValuePairList(path, print) {
141
+ return printList(path, print, "elementValuePair");
142
+ },
143
+ elementValuePair(path, print) {
144
+ return join(" ", [
145
+ call(path, print, "Identifier"),
146
+ call(path, print, "Equals"),
147
+ call(path, print, "elementValue")
166
148
  ]);
167
- }
168
- annotationInterfaceElementModifier(ctx) {
169
- if (ctx.annotation) {
170
- return this.visitSingle(ctx);
171
- }
172
- return printTokenWithComments(this.getSingle(ctx));
173
- }
174
- defaultValue(ctx) {
175
- const elementValue = this.visit(ctx.elementValue);
176
- return rejectAndJoin(" ", [ctx.Default[0], elementValue]);
177
- }
178
- annotation(ctx) {
179
- var _a, _b, _c;
180
- const fqn = this.visit(ctx.typeName);
181
- let annoArgs = "";
182
- if (ctx.LBrace) {
183
- const elementValues = (_c = (_b = (_a = ctx.elementValuePairList) === null || _a === void 0 ? void 0 : _a[0].children.elementValuePair) !== null && _b !== void 0 ? _b : ctx.elementValue) !== null && _c !== void 0 ? _c : [];
184
- handleCommentsParameters(ctx.LBrace[0], elementValues, ctx.RBrace[0]);
185
- if (ctx.elementValuePairList) {
186
- annoArgs = putIntoBraces(this.visit(ctx.elementValuePairList), softline, ctx.LBrace[0], ctx.RBrace[0]);
187
- }
188
- else if (ctx.elementValue) {
189
- annoArgs = putIntoBraces(this.visit(ctx.elementValue), softline, ctx.LBrace[0], ctx.RBrace[0]);
190
- }
191
- }
192
- return group(rejectAndConcat([ctx.At[0], fqn, annoArgs]));
193
- }
194
- elementValuePairList(ctx) {
195
- const elementValuePairs = this.mapVisit(ctx.elementValuePair);
196
- const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
197
- return rejectAndJoinSeps(commas, elementValuePairs);
198
- }
199
- elementValuePair(ctx) {
200
- const identifier = ctx.Identifier[0];
201
- const elementValue = this.visit(ctx.elementValue);
202
- return rejectAndJoin(" ", [identifier, ctx.Equals[0], elementValue]);
203
- }
204
- elementValue(ctx) {
205
- return this.visitSingle(ctx);
206
- }
207
- elementValueArrayInitializer(ctx) {
208
- const elementValueList = this.visit(ctx.elementValueList);
209
- return printArrayList({
210
- list: elementValueList,
211
- extraComma: ctx.Comma,
212
- LCurly: ctx.LCurly[0],
213
- RCurly: ctx.RCurly[0],
214
- trailingComma: this.prettierOptions.trailingComma
215
- });
216
- }
217
- elementValueList(ctx) {
218
- const elementValues = this.mapVisit(ctx.elementValue);
219
- const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
220
- return group(rejectAndConcat([rejectAndJoinSeps(commas, elementValues)]));
221
- }
222
- }
149
+ },
150
+ elementValue: printSingle,
151
+ elementValueArrayInitializer(path, print, options) {
152
+ return printArrayInitializer(path, print, options, "elementValueList");
153
+ },
154
+ elementValueList(path, print) {
155
+ return group(printList(path, print, "elementValue"));
156
+ }
157
+ };
@@ -0,0 +1,14 @@
1
+ import { builders } from "prettier/doc";
2
+ import { printSingle } from "./helpers.js";
3
+ declare const _default: {
4
+ literal(path: import("prettier").AstPath<import("../../../java-parser/api.js").LiteralCstNode & {
5
+ comments?: import("../comments.js").JavaComment[];
6
+ }>, print: import("./helpers.js").JavaPrintFn): builders.Doc;
7
+ integerLiteral: typeof printSingle;
8
+ floatingPointLiteral: typeof printSingle;
9
+ booleanLiteral: typeof printSingle;
10
+ shiftOperator(path: import("prettier").AstPath<import("../../../java-parser/api.js").ShiftOperatorCstNode & {
11
+ comments?: import("../comments.js").JavaComment[];
12
+ }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
13
+ };
14
+ export default _default;
@@ -1,31 +1,29 @@
1
- import { printTokenWithComments } from "./comments/format-comments.js";
2
- import { join } from "./prettier-builder.js";
3
- import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
4
1
  import { builders } from "prettier/doc";
5
- const { hardline } = builders;
6
- export class LexicalStructurePrettierVisitor extends BaseCstPrettierPrinter {
7
- literal(ctx) {
8
- if (ctx.TextBlock) {
9
- const lines = ctx.TextBlock[0].image.split("\n");
10
- const open = lines.shift();
11
- const baseIndent = Math.min(...lines.map(line => line.search(/\S/)).filter(indent => indent >= 0));
12
- return join(hardline, [
13
- open,
14
- ...lines.map(line => line.slice(baseIndent))
15
- ]);
2
+ import { findBaseIndent, map, onlyDefinedKey, printSingle } from "./helpers.js";
3
+ const { hardline, indent, join } = builders;
4
+ export default {
5
+ literal(path, print) {
6
+ const { TextBlock } = path.node.children;
7
+ if (!TextBlock) {
8
+ return printSingle(path, print);
16
9
  }
17
- if (ctx.CharLiteral || ctx.StringLiteral || ctx.Null) {
18
- return printTokenWithComments(this.getSingle(ctx));
19
- }
20
- return this.visitSingle(ctx);
21
- }
22
- integerLiteral(ctx) {
23
- return printTokenWithComments(this.getSingle(ctx));
24
- }
25
- floatingPointLiteral(ctx) {
26
- return printTokenWithComments(this.getSingle(ctx));
27
- }
28
- booleanLiteral(ctx) {
29
- return printTokenWithComments(this.getSingle(ctx));
10
+ const [open, ...lines] = TextBlock[0].image.split("\n");
11
+ const baseIndent = findBaseIndent(lines);
12
+ const textBlock = join(hardline, [
13
+ open,
14
+ ...lines.map(line => line.slice(baseIndent))
15
+ ]);
16
+ const ancestor = path.getNode(14);
17
+ return (ancestor === null || ancestor === void 0 ? void 0 : ancestor.name) === "variableInitializer" ||
18
+ ((ancestor === null || ancestor === void 0 ? void 0 : ancestor.name) === "binaryExpression" &&
19
+ ancestor.children.AssignmentOperator)
20
+ ? indent(textBlock)
21
+ : textBlock;
22
+ },
23
+ integerLiteral: printSingle,
24
+ floatingPointLiteral: printSingle,
25
+ booleanLiteral: printSingle,
26
+ shiftOperator(path, print) {
27
+ return map(path, print, onlyDefinedKey(path.node.children));
30
28
  }
31
- }
29
+ };
@@ -0,0 +1,12 @@
1
+ import { printName, printSingle } from "./helpers.js";
2
+ declare const _default: {
3
+ typeIdentifier: typeof printSingle;
4
+ moduleName: typeof printName;
5
+ packageName: typeof printName;
6
+ typeName: typeof printName;
7
+ expressionName: typeof printName;
8
+ methodName: typeof printSingle;
9
+ packageOrTypeName: typeof printName;
10
+ ambiguousName: typeof printName;
11
+ };
12
+ export default _default;
@@ -1,29 +1,11 @@
1
- import { buildFqn } from "./printer-utils.js";
2
- import { printTokenWithComments } from "./comments/format-comments.js";
3
- import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
4
- export class NamesPrettierVisitor extends BaseCstPrettierPrinter {
5
- typeIdentifier(ctx) {
6
- return printTokenWithComments(ctx.Identifier[0]);
7
- }
8
- moduleName(ctx) {
9
- return buildFqn(ctx.Identifier, ctx.Dot);
10
- }
11
- packageName(ctx) {
12
- return buildFqn(ctx.Identifier, ctx.Dot);
13
- }
14
- typeName(ctx) {
15
- return buildFqn(ctx.Identifier, ctx.Dot);
16
- }
17
- expressionName(ctx) {
18
- return buildFqn(ctx.Identifier, ctx.Dot);
19
- }
20
- methodName(ctx) {
21
- return printTokenWithComments(ctx.Identifier[0]);
22
- }
23
- packageOrTypeName(ctx) {
24
- return buildFqn(ctx.Identifier, ctx.Dot);
25
- }
26
- ambiguousName(ctx) {
27
- return buildFqn(ctx.Identifier, ctx.Dot);
28
- }
29
- }
1
+ import { printName, printSingle } from "./helpers.js";
2
+ export default {
3
+ typeIdentifier: printSingle,
4
+ moduleName: printName,
5
+ packageName: printName,
6
+ typeName: printName,
7
+ expressionName: printName,
8
+ methodName: printSingle,
9
+ packageOrTypeName: printName,
10
+ ambiguousName: printName
11
+ };
@@ -0,0 +1,46 @@
1
+ import type { ExportsModuleDirectiveCstNode, ImportDeclarationCstNode, OpensModuleDirectiveCstNode } from "java-parser";
2
+ import type { AstPath } from "prettier";
3
+ import { builders } from "prettier/doc";
4
+ import { printSingle, type JavaPrintFn } from "./helpers.js";
5
+ declare const _default: {
6
+ compilationUnit(path: AstPath<import("java-parser").CompilationUnitCstNode & {
7
+ comments?: import("../comments.js").JavaComment[];
8
+ }>, print: JavaPrintFn): builders.Doc[];
9
+ ordinaryCompilationUnit(path: AstPath<import("java-parser").OrdinaryCompilationUnitCstNode & {
10
+ comments?: import("../comments.js").JavaComment[];
11
+ }>, print: JavaPrintFn): builders.Doc[];
12
+ modularCompilationUnit(path: AstPath<import("java-parser").ModularCompilationUnitCstNode & {
13
+ comments?: import("../comments.js").JavaComment[];
14
+ }>, print: JavaPrintFn): builders.Doc[];
15
+ packageDeclaration(path: AstPath<import("java-parser").PackageDeclarationCstNode & {
16
+ comments?: import("../comments.js").JavaComment[];
17
+ }>, print: JavaPrintFn): builders.Doc[];
18
+ packageModifier: typeof printSingle;
19
+ importDeclaration(path: AstPath<ImportDeclarationCstNode & {
20
+ comments?: import("../comments.js").JavaComment[];
21
+ }>, print: JavaPrintFn): builders.Doc;
22
+ typeDeclaration(path: AstPath<import("java-parser").TypeDeclarationCstNode & {
23
+ comments?: import("../comments.js").JavaComment[];
24
+ }>, print: JavaPrintFn): builders.Doc;
25
+ moduleDeclaration(path: AstPath<import("java-parser").ModuleDeclarationCstNode & {
26
+ comments?: import("../comments.js").JavaComment[];
27
+ }>, print: JavaPrintFn): builders.Doc[];
28
+ moduleDirective: typeof printSingle;
29
+ requiresModuleDirective(path: AstPath<import("java-parser").RequiresModuleDirectiveCstNode & {
30
+ comments?: import("../comments.js").JavaComment[];
31
+ }>, print: JavaPrintFn): builders.Doc[];
32
+ exportsModuleDirective(path: AstPath<ExportsModuleDirectiveCstNode & {
33
+ comments?: import("../comments.js").JavaComment[];
34
+ }>, print: JavaPrintFn): builders.Doc[];
35
+ opensModuleDirective(path: AstPath<OpensModuleDirectiveCstNode & {
36
+ comments?: import("../comments.js").JavaComment[];
37
+ }>, print: JavaPrintFn): builders.Doc[];
38
+ usesModuleDirective(path: AstPath<import("java-parser").UsesModuleDirectiveCstNode & {
39
+ comments?: import("../comments.js").JavaComment[];
40
+ }>, print: JavaPrintFn): builders.Doc[];
41
+ providesModuleDirective(path: AstPath<import("java-parser").ProvidesModuleDirectiveCstNode & {
42
+ comments?: import("../comments.js").JavaComment[];
43
+ }>, print: JavaPrintFn): builders.Doc[];
44
+ requiresModifier: typeof printSingle;
45
+ };
46
+ export default _default;