prettier-plugin-java 2.4.0 → 2.6.0

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 (120) hide show
  1. package/LICENSE +1 -1
  2. package/dist/base-cst-printer.js +22 -44
  3. package/dist/cst-printer.js +19 -27
  4. package/dist/index.js +19 -20
  5. package/dist/options.js +16 -21
  6. package/dist/parser.js +2 -4
  7. package/dist/printer.js +3 -5
  8. package/dist/printers/arrays.js +17 -41
  9. package/dist/printers/blocks-and-statements.js +289 -356
  10. package/dist/printers/classes.js +451 -495
  11. package/dist/printers/comments/comments-utils.js +5 -13
  12. package/dist/printers/comments/format-comments.js +34 -50
  13. package/dist/printers/comments/handle-comments.js +17 -23
  14. package/dist/printers/expressions.js +378 -386
  15. package/dist/printers/interfaces.js +148 -181
  16. package/dist/printers/lexical-structure.js +26 -58
  17. package/dist/printers/names.js +29 -53
  18. package/dist/printers/packages-and-modules.js +116 -143
  19. package/dist/printers/prettier-builder.js +21 -31
  20. package/dist/printers/printer-utils.js +173 -221
  21. package/dist/printers/types-values-and-variables.js +111 -149
  22. package/dist/types/utils.js +6 -15
  23. package/dist/utils/expressions-utils.js +7 -11
  24. package/dist/utils/index.js +2 -12
  25. package/dist/utils/isEmptyDoc.js +2 -4
  26. package/dist/utils/printArgumentListWithBraces.js +29 -19
  27. package/dist/utils/printSingleLambdaInvocation.js +15 -17
  28. package/package.json +10 -13
  29. package/dist/src/base-cst-printer.js +0 -77
  30. package/dist/src/cst-printer.js +0 -37
  31. package/dist/src/index.js +0 -67
  32. package/dist/src/options.js +0 -256
  33. package/dist/src/parser.js +0 -7
  34. package/dist/src/printer.js +0 -28
  35. package/dist/src/printers/arrays.js +0 -49
  36. package/dist/src/printers/blocks-and-statements.js +0 -493
  37. package/dist/src/printers/classes.js +0 -724
  38. package/dist/src/printers/comments/comments-utils.js +0 -29
  39. package/dist/src/printers/comments/format-comments.js +0 -187
  40. package/dist/src/printers/comments/handle-comments.js +0 -38
  41. package/dist/src/printers/expressions.js +0 -549
  42. package/dist/src/printers/interfaces.js +0 -251
  43. package/dist/src/printers/lexical-structure.js +0 -43
  44. package/dist/src/printers/names.js +0 -53
  45. package/dist/src/printers/packages-and-modules.js +0 -185
  46. package/dist/src/printers/prettier-builder.js +0 -47
  47. package/dist/src/printers/printer-utils.js +0 -577
  48. package/dist/src/printers/types-values-and-variables.js +0 -183
  49. package/dist/src/types/utils.js +0 -29
  50. package/dist/src/utils/expressions-utils.js +0 -29
  51. package/dist/src/utils/index.js +0 -10
  52. package/dist/src/utils/printArgumentListWithBraces.js +0 -21
  53. package/dist/src/utils/printSingleLambdaInvocation.js +0 -20
  54. package/dist/test/babel-register.js +0 -3
  55. package/dist/test/repository-test/core-test.js +0 -12
  56. package/dist/test/repository-test/jhipster-1-test.js +0 -17
  57. package/dist/test/repository-test/jhipster-2-test.js +0 -16
  58. package/dist/test/test-utils.js +0 -215
  59. package/dist/test/unit-test/annotation_type_declaration/annotation_type_declaration-spec.js +0 -6
  60. package/dist/test/unit-test/args/args-spec.js +0 -6
  61. package/dist/test/unit-test/assert/assert-spec.js +0 -6
  62. package/dist/test/unit-test/binary_expressions/binary_expressions-spec.js +0 -6
  63. package/dist/test/unit-test/blank_lines/blank_lines-spec.js +0 -6
  64. package/dist/test/unit-test/bug-fixes/bug-fixes-spec.js +0 -6
  65. package/dist/test/unit-test/cast/cast-spec.js +0 -6
  66. package/dist/test/unit-test/char_literal/char_literal-spec.js +0 -6
  67. package/dist/test/unit-test/classes/multiple_classes-spec.js +0 -6
  68. package/dist/test/unit-test/comments/comments-spec.js +0 -14
  69. package/dist/test/unit-test/complex_generic_class/complex_generic_class-spec.js +0 -6
  70. package/dist/test/unit-test/constructors/constructors-spec.js +0 -6
  71. package/dist/test/unit-test/empty_statement/empty_statement-spec.js +0 -6
  72. package/dist/test/unit-test/enum/enum-spec.js +0 -6
  73. package/dist/test/unit-test/expressions/expressions-spec.js +0 -6
  74. package/dist/test/unit-test/extends_abstract_class/extends_abstract_class-spec.js +0 -6
  75. package/dist/test/unit-test/extends_abstract_class_and_implements_interfaces/extends_abstract_class_and_implements_interfaces-spec.js +0 -6
  76. package/dist/test/unit-test/for/for-spec.js +0 -6
  77. package/dist/test/unit-test/generic_class/generic_class-spec.js +0 -6
  78. package/dist/test/unit-test/generic_questionmark/generic_questionmark-spec.js +0 -6
  79. package/dist/test/unit-test/hello-world/hello-word-spec.js +0 -6
  80. package/dist/test/unit-test/if/if-spec.js +0 -6
  81. package/dist/test/unit-test/indent/indent-spec.js +0 -6
  82. package/dist/test/unit-test/instantiation/instantiation-spec.js +0 -6
  83. package/dist/test/unit-test/interface/interface-spec.js +0 -6
  84. package/dist/test/unit-test/lambda/lambda-spec.js +0 -6
  85. package/dist/test/unit-test/marker_annotations/marker_annotations-spec.js +0 -6
  86. package/dist/test/unit-test/member_chain/member_chain-spec.js +0 -6
  87. package/dist/test/unit-test/method_reference/method_reference-spec.js +0 -6
  88. package/dist/test/unit-test/modifiers/modifiers-spec.js +0 -6
  89. package/dist/test/unit-test/modules/modules-spec.js +0 -6
  90. package/dist/test/unit-test/package_and_imports/package_and_imports-spec.js +0 -34
  91. package/dist/test/unit-test/pattern-matching/pattern-matching-spec.js +0 -6
  92. package/dist/test/unit-test/prettier-ignore/prettier-ignore-spec.js +0 -28
  93. package/dist/test/unit-test/records/records-spec.js +0 -6
  94. package/dist/test/unit-test/return/return-spec.js +0 -6
  95. package/dist/test/unit-test/sealed/sealed-spec.js +0 -6
  96. package/dist/test/unit-test/snippets/arrays/array-initializer.spec.js +0 -94
  97. package/dist/test/unit-test/snippets/arrays/variable-initializer-list.spec.js +0 -19
  98. package/dist/test/unit-test/snippets/blocks-and-statements/switch.spec.js +0 -26
  99. package/dist/test/unit-test/snippets/classes/class-body.spec.js +0 -181
  100. package/dist/test/unit-test/snippets/classes/enum-body.spec.js +0 -87
  101. package/dist/test/unit-test/snippets/classes/variableDeclarator/test.spec.js +0 -186
  102. package/dist/test/unit-test/snippets/interfaces/element-value-array-initializer.spec.js +0 -85
  103. package/dist/test/unit-test/snippets/names/ambiguousName/test.spec.js +0 -19
  104. package/dist/test/unit-test/snippets/names/expressionName/test.spec.js +0 -19
  105. package/dist/test/unit-test/snippets/names/methodName/test.spec.js +0 -12
  106. package/dist/test/unit-test/snippets/names/packageOrTypeName/test.spec.js +0 -19
  107. package/dist/test/unit-test/snippets/types-values-and-variables/floatingPointType/test.spec.js +0 -19
  108. package/dist/test/unit-test/snippets/types-values-and-variables/integralType/test.spec.js +0 -40
  109. package/dist/test/unit-test/snippets/types-values-and-variables/numericType/test.spec.js +0 -88
  110. package/dist/test/unit-test/snippets/types-values-and-variables/wildcard/test.spec.js +0 -112
  111. package/dist/test/unit-test/snippets/types-values-and-variables/wildcardBounds/test.spec.js +0 -81
  112. package/dist/test/unit-test/switch/switch-spec.js +0 -6
  113. package/dist/test/unit-test/synchronized/synchronized-spec.js +0 -6
  114. package/dist/test/unit-test/text-blocks/text-block-spec.js +0 -6
  115. package/dist/test/unit-test/throws/throws-spec.js +0 -6
  116. package/dist/test/unit-test/try_catch/try_catch-spec.js +0 -6
  117. package/dist/test/unit-test/types/types-spec.js +0 -6
  118. package/dist/test/unit-test/variables/variables-spec.js +0 -6
  119. package/dist/test/unit-test/while/while-spec.js +0 -6
  120. package/dist/test/unit-test/yield-statement/yield-statement-spec.js +0 -6
@@ -1,251 +1,218 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.InterfacesPrettierVisitor = void 0;
19
- var prettier_builder_1 = require("./prettier-builder");
20
- var format_comments_1 = require("./comments/format-comments");
21
- var printer_utils_1 = require("./printer-utils");
22
- var doc_1 = require("prettier/doc");
23
- var base_cst_printer_1 = require("../base-cst-printer");
24
- var line = doc_1.builders.line, softline = doc_1.builders.softline, hardline = doc_1.builders.hardline;
25
- var InterfacesPrettierVisitor = /** @class */ (function (_super) {
26
- __extends(InterfacesPrettierVisitor, _super);
27
- function InterfacesPrettierVisitor() {
28
- return _super !== null && _super.apply(this, arguments) || this;
29
- }
30
- InterfacesPrettierVisitor.prototype.interfaceDeclaration = function (ctx) {
31
- var modifiers = (0, printer_utils_1.sortModifiers)(ctx.interfaceModifier);
32
- var firstAnnotations = this.mapVisit(modifiers[0]);
33
- var otherModifiers = this.mapVisit(modifiers[1]);
34
- var declaration = ctx.normalInterfaceDeclaration
1
+ import { concat, group, indent } from "./prettier-builder.js";
2
+ import { printTokenWithComments } from "./comments/format-comments.js";
3
+ import { displaySemicolon, getInterfaceBodyDeclarationsSeparator, isStatementEmptyStatement, printArrayList, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortModifiers } from "./printer-utils.js";
4
+ import { builders } from "prettier/doc";
5
+ import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
6
+ const { line, softline, hardline } = builders;
7
+ export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter {
8
+ interfaceDeclaration(ctx) {
9
+ const modifiers = sortModifiers(ctx.interfaceModifier);
10
+ const firstAnnotations = this.mapVisit(modifiers[0]);
11
+ const otherModifiers = this.mapVisit(modifiers[1]);
12
+ const declaration = ctx.normalInterfaceDeclaration
35
13
  ? this.visit(ctx.normalInterfaceDeclaration)
36
14
  : this.visit(ctx.annotationTypeDeclaration);
37
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
38
- (0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations),
39
- (0, printer_utils_1.rejectAndJoin)(" ", [(0, printer_utils_1.rejectAndJoin)(" ", otherModifiers), declaration])
15
+ return rejectAndJoin(hardline, [
16
+ rejectAndJoin(hardline, firstAnnotations),
17
+ rejectAndJoin(" ", [rejectAndJoin(" ", otherModifiers), declaration])
40
18
  ]);
41
- };
42
- InterfacesPrettierVisitor.prototype.normalInterfaceDeclaration = function (ctx) {
43
- var typeIdentifier = this.visit(ctx.typeIdentifier);
44
- var typeParameters = this.visit(ctx.typeParameters);
45
- var extendsInterfaces = this.visit(ctx.extendsInterfaces);
46
- var optionalInterfacePermits = this.visit(ctx.interfacePermits);
47
- var interfaceBody = this.visit(ctx.interfaceBody);
48
- var extendsInterfacesPart = "";
19
+ }
20
+ normalInterfaceDeclaration(ctx) {
21
+ const typeIdentifier = this.visit(ctx.typeIdentifier);
22
+ const typeParameters = this.visit(ctx.typeParameters);
23
+ const extendsInterfaces = this.visit(ctx.extendsInterfaces);
24
+ const optionalInterfacePermits = this.visit(ctx.interfacePermits);
25
+ const interfaceBody = this.visit(ctx.interfaceBody);
26
+ let extendsInterfacesPart = "";
49
27
  if (extendsInterfaces) {
50
- extendsInterfacesPart = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([softline, extendsInterfaces]));
28
+ extendsInterfacesPart = indent(rejectAndConcat([softline, extendsInterfaces]));
51
29
  }
52
- var interfacePermits = "";
30
+ let interfacePermits = "";
53
31
  if (optionalInterfacePermits) {
54
- interfacePermits = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([softline, optionalInterfacePermits]));
32
+ interfacePermits = indent(rejectAndConcat([softline, optionalInterfacePermits]));
55
33
  }
56
- return (0, printer_utils_1.rejectAndJoin)(" ", [
57
- (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(" ", [
34
+ return rejectAndJoin(" ", [
35
+ group(rejectAndJoin(" ", [
58
36
  ctx.Interface[0],
59
- (0, prettier_builder_1.concat)([typeIdentifier, typeParameters]),
37
+ concat([typeIdentifier, typeParameters]),
60
38
  extendsInterfacesPart,
61
39
  interfacePermits
62
40
  ])),
63
41
  interfaceBody
64
42
  ]);
65
- };
66
- InterfacesPrettierVisitor.prototype.interfaceModifier = function (ctx) {
43
+ }
44
+ interfaceModifier(ctx) {
67
45
  if (ctx.annotation) {
68
46
  return this.visitSingle(ctx);
69
47
  }
70
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
71
- };
72
- InterfacesPrettierVisitor.prototype.extendsInterfaces = function (ctx) {
73
- var interfaceTypeList = this.visit(ctx.interfaceTypeList);
74
- return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([
48
+ return printTokenWithComments(this.getSingle(ctx));
49
+ }
50
+ extendsInterfaces(ctx) {
51
+ const interfaceTypeList = this.visit(ctx.interfaceTypeList);
52
+ return group(rejectAndConcat([
75
53
  ctx.Extends[0],
76
- (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([line, interfaceTypeList]))
54
+ indent(rejectAndConcat([line, interfaceTypeList]))
77
55
  ]));
78
- };
79
- InterfacesPrettierVisitor.prototype.interfacePermits = function (ctx) {
56
+ }
57
+ interfacePermits(ctx) {
80
58
  return this.classPermits(ctx);
81
- };
82
- InterfacesPrettierVisitor.prototype.interfaceBody = function (ctx) {
83
- var joinedInterfaceMemberDeclaration = "";
59
+ }
60
+ interfaceBody(ctx) {
61
+ let joinedInterfaceMemberDeclaration = "";
84
62
  if (ctx.interfaceMemberDeclaration !== undefined) {
85
- var interfaceMemberDeclaration = this.mapVisit(ctx.interfaceMemberDeclaration);
86
- var separators = (0, printer_utils_1.getInterfaceBodyDeclarationsSeparator)(ctx.interfaceMemberDeclaration);
87
- joinedInterfaceMemberDeclaration = (0, printer_utils_1.rejectAndJoinSeps)(separators, interfaceMemberDeclaration);
63
+ const interfaceMemberDeclaration = this.mapVisit(ctx.interfaceMemberDeclaration);
64
+ const separators = getInterfaceBodyDeclarationsSeparator(ctx.interfaceMemberDeclaration);
65
+ joinedInterfaceMemberDeclaration = rejectAndJoinSeps(separators, interfaceMemberDeclaration);
88
66
  }
89
- return (0, printer_utils_1.putIntoBraces)(joinedInterfaceMemberDeclaration, hardline, ctx.LCurly[0], ctx.RCurly[0]);
90
- };
91
- InterfacesPrettierVisitor.prototype.interfaceMemberDeclaration = function (ctx) {
67
+ return putIntoBraces(joinedInterfaceMemberDeclaration, hardline, ctx.LCurly[0], ctx.RCurly[0]);
68
+ }
69
+ interfaceMemberDeclaration(ctx) {
92
70
  if (ctx.Semicolon) {
93
- return (0, printer_utils_1.displaySemicolon)(ctx.Semicolon[0]);
71
+ return displaySemicolon(ctx.Semicolon[0]);
94
72
  }
95
73
  return this.visitSingle(ctx);
96
- };
97
- InterfacesPrettierVisitor.prototype.constantDeclaration = function (ctx) {
98
- var modifiers = (0, printer_utils_1.sortModifiers)(ctx.constantModifier);
99
- var firstAnnotations = this.mapVisit(modifiers[0]);
100
- var otherModifiers = this.mapVisit(modifiers[1]);
101
- var unannType = this.visit(ctx.unannType);
102
- var variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
103
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
104
- (0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations),
105
- (0, printer_utils_1.rejectAndJoin)(" ", [
106
- (0, printer_utils_1.rejectAndJoin)(" ", otherModifiers),
74
+ }
75
+ constantDeclaration(ctx) {
76
+ const modifiers = sortModifiers(ctx.constantModifier);
77
+ const firstAnnotations = this.mapVisit(modifiers[0]);
78
+ const otherModifiers = this.mapVisit(modifiers[1]);
79
+ const unannType = this.visit(ctx.unannType);
80
+ const variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
81
+ return rejectAndJoin(hardline, [
82
+ rejectAndJoin(hardline, firstAnnotations),
83
+ rejectAndJoin(" ", [
84
+ rejectAndJoin(" ", otherModifiers),
107
85
  unannType,
108
- (0, printer_utils_1.rejectAndConcat)([variableDeclaratorList, ctx.Semicolon[0]])
86
+ rejectAndConcat([variableDeclaratorList, ctx.Semicolon[0]])
109
87
  ])
110
88
  ]);
111
- };
112
- InterfacesPrettierVisitor.prototype.constantModifier = function (ctx) {
89
+ }
90
+ constantModifier(ctx) {
113
91
  if (ctx.annotation) {
114
92
  return this.visitSingle(ctx);
115
93
  }
116
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
117
- };
118
- InterfacesPrettierVisitor.prototype.interfaceMethodDeclaration = function (ctx) {
119
- var modifiers = (0, printer_utils_1.sortModifiers)(ctx.interfaceMethodModifier);
120
- var firstAnnotations = this.mapVisit(modifiers[0]);
121
- var otherModifiers = this.mapVisit(modifiers[1]);
122
- var methodHeader = this.visit(ctx.methodHeader);
123
- var methodBody = this.visit(ctx.methodBody);
124
- var separator = (0, printer_utils_1.isStatementEmptyStatement)(methodBody) ? "" : " ";
125
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
126
- (0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations),
127
- (0, printer_utils_1.rejectAndJoin)(" ", [
128
- (0, printer_utils_1.rejectAndJoin)(" ", otherModifiers),
129
- (0, printer_utils_1.rejectAndJoin)(separator, [methodHeader, methodBody])
94
+ return printTokenWithComments(this.getSingle(ctx));
95
+ }
96
+ interfaceMethodDeclaration(ctx) {
97
+ const modifiers = sortModifiers(ctx.interfaceMethodModifier);
98
+ const firstAnnotations = this.mapVisit(modifiers[0]);
99
+ const otherModifiers = this.mapVisit(modifiers[1]);
100
+ const methodHeader = this.visit(ctx.methodHeader);
101
+ const methodBody = this.visit(ctx.methodBody);
102
+ const separator = isStatementEmptyStatement(methodBody) ? "" : " ";
103
+ return rejectAndJoin(hardline, [
104
+ rejectAndJoin(hardline, firstAnnotations),
105
+ rejectAndJoin(" ", [
106
+ rejectAndJoin(" ", otherModifiers),
107
+ rejectAndJoin(separator, [methodHeader, methodBody])
130
108
  ])
131
109
  ]);
132
- };
133
- InterfacesPrettierVisitor.prototype.interfaceMethodModifier = function (ctx) {
110
+ }
111
+ interfaceMethodModifier(ctx) {
134
112
  if (ctx.annotation) {
135
113
  return this.visitSingle(ctx);
136
114
  }
137
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
138
- };
139
- InterfacesPrettierVisitor.prototype.annotationTypeDeclaration = function (ctx) {
140
- var typeIdentifier = this.visit(ctx.typeIdentifier);
141
- var annotationTypeBody = this.visit(ctx.annotationTypeBody);
142
- return (0, printer_utils_1.rejectAndJoin)(" ", [
143
- (0, prettier_builder_1.concat)([ctx.At[0], ctx.Interface[0]]),
115
+ return printTokenWithComments(this.getSingle(ctx));
116
+ }
117
+ annotationTypeDeclaration(ctx) {
118
+ const typeIdentifier = this.visit(ctx.typeIdentifier);
119
+ const annotationTypeBody = this.visit(ctx.annotationTypeBody);
120
+ return rejectAndJoin(" ", [
121
+ concat([ctx.At[0], ctx.Interface[0]]),
144
122
  typeIdentifier,
145
123
  annotationTypeBody
146
124
  ]);
147
- };
148
- InterfacesPrettierVisitor.prototype.annotationTypeBody = function (ctx) {
149
- var annotationTypeMemberDeclaration = this.mapVisit(ctx.annotationTypeMemberDeclaration);
150
- return (0, printer_utils_1.rejectAndJoin)(line, [
151
- (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndJoin)(line, [
125
+ }
126
+ annotationTypeBody(ctx) {
127
+ const annotationTypeMemberDeclaration = this.mapVisit(ctx.annotationTypeMemberDeclaration);
128
+ return rejectAndJoin(line, [
129
+ indent(rejectAndJoin(line, [
152
130
  ctx.LCurly[0],
153
- (0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([line, line]), annotationTypeMemberDeclaration)
131
+ rejectAndJoin(concat([line, line]), annotationTypeMemberDeclaration)
154
132
  ])),
155
133
  ctx.RCurly[0]
156
134
  ]);
157
- };
158
- InterfacesPrettierVisitor.prototype.annotationTypeMemberDeclaration = function (ctx) {
135
+ }
136
+ annotationTypeMemberDeclaration(ctx) {
159
137
  if (ctx.Semicolon) {
160
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
138
+ return printTokenWithComments(this.getSingle(ctx));
161
139
  }
162
140
  return this.visitSingle(ctx);
163
- };
164
- InterfacesPrettierVisitor.prototype.annotationTypeElementDeclaration = function (ctx) {
165
- var modifiers = (0, printer_utils_1.sortModifiers)(ctx.annotationTypeElementModifier);
166
- var firstAnnotations = this.mapVisit(modifiers[0]);
167
- var otherModifiers = this.mapVisit(modifiers[1]);
168
- var unannType = this.visit(ctx.unannType);
169
- var identifier = ctx.Identifier[0];
170
- var dims = this.visit(ctx.dims);
171
- var defaultValue = ctx.defaultValue
172
- ? (0, prettier_builder_1.concat)([" ", this.visit(ctx.defaultValue)])
141
+ }
142
+ annotationTypeElementDeclaration(ctx) {
143
+ const modifiers = sortModifiers(ctx.annotationTypeElementModifier);
144
+ const firstAnnotations = this.mapVisit(modifiers[0]);
145
+ const otherModifiers = this.mapVisit(modifiers[1]);
146
+ const unannType = this.visit(ctx.unannType);
147
+ const identifier = ctx.Identifier[0];
148
+ const dims = this.visit(ctx.dims);
149
+ const defaultValue = ctx.defaultValue
150
+ ? concat([" ", this.visit(ctx.defaultValue)])
173
151
  : "";
174
- return (0, printer_utils_1.rejectAndJoin)(hardline, [
175
- (0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations),
176
- (0, printer_utils_1.rejectAndJoin)(" ", [
177
- (0, printer_utils_1.rejectAndJoin)(" ", otherModifiers),
152
+ return rejectAndJoin(hardline, [
153
+ rejectAndJoin(hardline, firstAnnotations),
154
+ rejectAndJoin(" ", [
155
+ rejectAndJoin(" ", otherModifiers),
178
156
  unannType,
179
- (0, printer_utils_1.rejectAndConcat)([
157
+ rejectAndConcat([
180
158
  identifier,
181
- (0, prettier_builder_1.concat)([ctx.LBrace[0], ctx.RBrace[0]]),
159
+ concat([ctx.LBrace[0], ctx.RBrace[0]]),
182
160
  dims,
183
161
  defaultValue,
184
162
  ctx.Semicolon[0]
185
163
  ])
186
164
  ])
187
165
  ]);
188
- };
189
- InterfacesPrettierVisitor.prototype.annotationTypeElementModifier = function (ctx) {
166
+ }
167
+ annotationTypeElementModifier(ctx) {
190
168
  if (ctx.annotation) {
191
169
  return this.visitSingle(ctx);
192
170
  }
193
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
194
- };
195
- InterfacesPrettierVisitor.prototype.defaultValue = function (ctx) {
196
- var elementValue = this.visit(ctx.elementValue);
197
- return (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Default[0], elementValue]);
198
- };
199
- InterfacesPrettierVisitor.prototype.annotation = function (ctx) {
200
- var fqn = this.visit(ctx.typeName);
201
- var annoArgs = "";
171
+ return printTokenWithComments(this.getSingle(ctx));
172
+ }
173
+ defaultValue(ctx) {
174
+ const elementValue = this.visit(ctx.elementValue);
175
+ return rejectAndJoin(" ", [ctx.Default[0], elementValue]);
176
+ }
177
+ annotation(ctx) {
178
+ const fqn = this.visit(ctx.typeName);
179
+ let annoArgs = "";
202
180
  if (ctx.LBrace) {
203
181
  if (ctx.elementValuePairList) {
204
- annoArgs = (0, printer_utils_1.putIntoBraces)(this.visit(ctx.elementValuePairList), softline, ctx.LBrace[0], ctx.RBrace[0]);
182
+ annoArgs = putIntoBraces(this.visit(ctx.elementValuePairList), softline, ctx.LBrace[0], ctx.RBrace[0]);
205
183
  }
206
184
  else if (ctx.elementValue) {
207
- annoArgs = (0, printer_utils_1.putIntoBraces)(this.visit(ctx.elementValue), softline, ctx.LBrace[0], ctx.RBrace[0]);
185
+ annoArgs = putIntoBraces(this.visit(ctx.elementValue), softline, ctx.LBrace[0], ctx.RBrace[0]);
208
186
  }
209
187
  }
210
- return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ctx.At[0], fqn, annoArgs]));
211
- };
212
- InterfacesPrettierVisitor.prototype.elementValuePairList = function (ctx) {
213
- var elementValuePairs = this.mapVisit(ctx.elementValuePair);
214
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : [];
215
- return (0, printer_utils_1.rejectAndJoinSeps)(commas, elementValuePairs);
216
- };
217
- InterfacesPrettierVisitor.prototype.elementValuePair = function (ctx) {
218
- var identifier = ctx.Identifier[0];
219
- var elementValue = this.visit(ctx.elementValue);
220
- return (0, printer_utils_1.rejectAndJoin)(" ", [identifier, ctx.Equals[0], elementValue]);
221
- };
222
- InterfacesPrettierVisitor.prototype.elementValue = function (ctx) {
188
+ return group(rejectAndConcat([ctx.At[0], fqn, annoArgs]));
189
+ }
190
+ elementValuePairList(ctx) {
191
+ const elementValuePairs = this.mapVisit(ctx.elementValuePair);
192
+ const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
193
+ return rejectAndJoinSeps(commas, elementValuePairs);
194
+ }
195
+ elementValuePair(ctx) {
196
+ const identifier = ctx.Identifier[0];
197
+ const elementValue = this.visit(ctx.elementValue);
198
+ return rejectAndJoin(" ", [identifier, ctx.Equals[0], elementValue]);
199
+ }
200
+ elementValue(ctx) {
223
201
  return this.visitSingle(ctx);
224
- };
225
- InterfacesPrettierVisitor.prototype.elementValueArrayInitializer = function (ctx) {
226
- var elementValueList = this.visit(ctx.elementValueList);
227
- return (0, printer_utils_1.printArrayList)({
202
+ }
203
+ elementValueArrayInitializer(ctx) {
204
+ const elementValueList = this.visit(ctx.elementValueList);
205
+ return printArrayList({
228
206
  list: elementValueList,
229
207
  extraComma: ctx.Comma,
230
208
  LCurly: ctx.LCurly[0],
231
209
  RCurly: ctx.RCurly[0],
232
210
  trailingComma: this.prettierOptions.trailingComma
233
211
  });
234
- };
235
- InterfacesPrettierVisitor.prototype.elementValueList = function (ctx) {
236
- var elementValues = this.mapVisit(ctx.elementValue);
237
- var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : [];
238
- return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([(0, printer_utils_1.rejectAndJoinSeps)(commas, elementValues)]));
239
- };
240
- InterfacesPrettierVisitor.prototype.identifyInterfaceBodyDeclarationType = function () {
241
- return "identifyInterfaceBodyDeclarationType";
242
- };
243
- InterfacesPrettierVisitor.prototype.identifyAnnotationBodyDeclarationType = function () {
244
- return "identifyAnnotationBodyDeclarationType";
245
- };
246
- InterfacesPrettierVisitor.prototype.isSimpleElementValueAnnotation = function () {
247
- return "isSimpleElementValueAnnotation";
248
- };
249
- return InterfacesPrettierVisitor;
250
- }(base_cst_printer_1.BaseCstPrettierPrinter));
251
- exports.InterfacesPrettierVisitor = InterfacesPrettierVisitor;
212
+ }
213
+ elementValueList(ctx) {
214
+ const elementValues = this.mapVisit(ctx.elementValue);
215
+ const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : [];
216
+ return group(rejectAndConcat([rejectAndJoinSeps(commas, elementValues)]));
217
+ }
218
+ }
@@ -1,63 +1,31 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
- if (ar || !(i in from)) {
20
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
- ar[i] = from[i];
22
- }
23
- }
24
- return to.concat(ar || Array.prototype.slice.call(from));
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.LexicalStructurePrettierVisitor = void 0;
28
- var format_comments_1 = require("./comments/format-comments");
29
- var prettier_builder_1 = require("./prettier-builder");
30
- var base_cst_printer_1 = require("../base-cst-printer");
31
- var doc_1 = require("prettier/doc");
32
- var hardline = doc_1.builders.hardline;
33
- var LexicalStructurePrettierVisitor = /** @class */ (function (_super) {
34
- __extends(LexicalStructurePrettierVisitor, _super);
35
- function LexicalStructurePrettierVisitor() {
36
- return _super !== null && _super.apply(this, arguments) || this;
37
- }
38
- LexicalStructurePrettierVisitor.prototype.literal = function (ctx) {
1
+ import { printTokenWithComments } from "./comments/format-comments.js";
2
+ import { join } from "./prettier-builder.js";
3
+ import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
4
+ import { builders } from "prettier/doc";
5
+ const { hardline } = builders;
6
+ export class LexicalStructurePrettierVisitor extends BaseCstPrettierPrinter {
7
+ literal(ctx) {
39
8
  if (ctx.TextBlock) {
40
- var lines = ctx.TextBlock[0].image.split("\n");
41
- var open_1 = lines.shift();
42
- var baseIndent_1 = Math.min.apply(Math, lines.map(function (line) { return line.search(/\S/); }).filter(function (indent) { return indent >= 0; }));
43
- return (0, prettier_builder_1.join)(hardline, __spreadArray([
44
- open_1
45
- ], lines.map(function (line) { return line.slice(baseIndent_1); }), true));
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
+ ]);
46
16
  }
47
17
  if (ctx.CharLiteral || ctx.StringLiteral || ctx.Null) {
48
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
18
+ return printTokenWithComments(this.getSingle(ctx));
49
19
  }
50
20
  return this.visitSingle(ctx);
51
- };
52
- LexicalStructurePrettierVisitor.prototype.integerLiteral = function (ctx) {
53
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
54
- };
55
- LexicalStructurePrettierVisitor.prototype.floatingPointLiteral = function (ctx) {
56
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
57
- };
58
- LexicalStructurePrettierVisitor.prototype.booleanLiteral = function (ctx) {
59
- return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx));
60
- };
61
- return LexicalStructurePrettierVisitor;
62
- }(base_cst_printer_1.BaseCstPrettierPrinter));
63
- exports.LexicalStructurePrettierVisitor = LexicalStructurePrettierVisitor;
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));
30
+ }
31
+ }
@@ -1,53 +1,29 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.NamesPrettierVisitor = void 0;
19
- var printer_utils_1 = require("./printer-utils");
20
- var format_comments_1 = require("./comments/format-comments");
21
- var base_cst_printer_1 = require("../base-cst-printer");
22
- var NamesPrettierVisitor = /** @class */ (function (_super) {
23
- __extends(NamesPrettierVisitor, _super);
24
- function NamesPrettierVisitor() {
25
- return _super !== null && _super.apply(this, arguments) || this;
26
- }
27
- NamesPrettierVisitor.prototype.typeIdentifier = function (ctx) {
28
- return (0, format_comments_1.printTokenWithComments)(ctx.Identifier[0]);
29
- };
30
- NamesPrettierVisitor.prototype.moduleName = function (ctx) {
31
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
32
- };
33
- NamesPrettierVisitor.prototype.packageName = function (ctx) {
34
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
35
- };
36
- NamesPrettierVisitor.prototype.typeName = function (ctx) {
37
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
38
- };
39
- NamesPrettierVisitor.prototype.expressionName = function (ctx) {
40
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
41
- };
42
- NamesPrettierVisitor.prototype.methodName = function (ctx) {
43
- return (0, format_comments_1.printTokenWithComments)(ctx.Identifier[0]);
44
- };
45
- NamesPrettierVisitor.prototype.packageOrTypeName = function (ctx) {
46
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
47
- };
48
- NamesPrettierVisitor.prototype.ambiguousName = function (ctx) {
49
- return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot);
50
- };
51
- return NamesPrettierVisitor;
52
- }(base_cst_printer_1.BaseCstPrettierPrinter));
53
- exports.NamesPrettierVisitor = NamesPrettierVisitor;
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
+ }