prettier-plugin-java 2.6.3 → 2.6.4
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/dist/base-cst-printer.js +55 -0
- package/dist/cst-printer.js +29 -0
- package/dist/index.js +66 -0
- package/dist/options.js +256 -0
- package/dist/parser.js +4 -0
- package/dist/printer.js +6 -0
- package/dist/printers/arrays.js +25 -0
- package/dist/printers/blocks-and-statements.js +432 -0
- package/dist/printers/classes.js +709 -0
- package/dist/printers/comments/comments-utils.js +21 -0
- package/dist/printers/comments/format-comments.js +171 -0
- package/dist/printers/comments/handle-comments.js +102 -0
- package/dist/printers/expressions.js +590 -0
- package/dist/printers/interfaces.js +222 -0
- package/dist/printers/lexical-structure.js +31 -0
- package/dist/printers/names.js +29 -0
- package/dist/printers/packages-and-modules.js +171 -0
- package/dist/printers/prettier-builder.js +45 -0
- package/dist/printers/printer-utils.js +596 -0
- package/dist/printers/types-values-and-variables.js +153 -0
- package/dist/types/utils.js +20 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/isEmptyDoc.js +4 -0
- package/dist/utils/printArgumentListWithBraces.js +37 -0
- package/package.json +2 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BaseJavaCstVisitor } from "java-parser";
|
|
2
|
+
import { printNodeWithComments } from "./printers/comments/format-comments.js";
|
|
3
|
+
export class BaseCstPrettierPrinter extends BaseJavaCstVisitor {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.mapVisit = (elements, params) => {
|
|
7
|
+
if (elements === undefined) {
|
|
8
|
+
// TODO: can optimize this by returning an immutable empty array singleton.
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
return elements.map(element => this.visit(element, params));
|
|
12
|
+
};
|
|
13
|
+
this.getSingle = (ctx) => {
|
|
14
|
+
const ctxKeys = Object.keys(ctx);
|
|
15
|
+
if (ctxKeys.length !== 1) {
|
|
16
|
+
throw Error(`Expecting single key CST ctx but found: <${ctxKeys.length}> keys`);
|
|
17
|
+
}
|
|
18
|
+
const singleElementKey = ctxKeys[0];
|
|
19
|
+
const singleElementValues = ctx[singleElementKey];
|
|
20
|
+
if ((singleElementValues === null || singleElementValues === void 0 ? void 0 : singleElementValues.length) !== 1) {
|
|
21
|
+
throw Error(`Expecting single item in CST ctx key but found: <${singleElementValues === null || singleElementValues === void 0 ? void 0 : singleElementValues.length}> items`);
|
|
22
|
+
}
|
|
23
|
+
return singleElementValues[0];
|
|
24
|
+
};
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
this.orgVisit = this.visit;
|
|
27
|
+
this.visit = function (ctx, inParam) {
|
|
28
|
+
if (ctx === undefined) {
|
|
29
|
+
// empty Doc
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
const node = Array.isArray(ctx) ? ctx[0] : ctx;
|
|
33
|
+
if (node.ignore) {
|
|
34
|
+
try {
|
|
35
|
+
const startOffset = node.leadingComments !== undefined
|
|
36
|
+
? node.leadingComments[0].startOffset
|
|
37
|
+
: node.location.startOffset;
|
|
38
|
+
const endOffset = (node.trailingComments !== undefined
|
|
39
|
+
? node.trailingComments[node.trailingComments.length - 1].endOffset
|
|
40
|
+
: node.location.endOffset);
|
|
41
|
+
return this.prettierOptions.originalText.substring(startOffset, endOffset + 1);
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
throw Error(e +
|
|
45
|
+
"\nThere might be a problem with prettier-ignore, please report an issue on https://github.com/jhipster/prettier-java/issues");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return printNodeWithComments(node, this.orgVisit.call(this, node, inParam));
|
|
49
|
+
};
|
|
50
|
+
this.visitSingle = function (ctx, params) {
|
|
51
|
+
const singleElement = this.getSingle(ctx);
|
|
52
|
+
return this.visit(singleElement, params);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseCstPrettierPrinter } from "./base-cst-printer.js";
|
|
2
|
+
import { ArraysPrettierVisitor } from "./printers/arrays.js";
|
|
3
|
+
import { BlocksAndStatementPrettierVisitor } from "./printers/blocks-and-statements.js";
|
|
4
|
+
import { ClassesPrettierVisitor } from "./printers/classes.js";
|
|
5
|
+
import { ExpressionsPrettierVisitor } from "./printers/expressions.js";
|
|
6
|
+
import { InterfacesPrettierVisitor } from "./printers/interfaces.js";
|
|
7
|
+
import { LexicalStructurePrettierVisitor } from "./printers/lexical-structure.js";
|
|
8
|
+
import { NamesPrettierVisitor } from "./printers/names.js";
|
|
9
|
+
import { TypesValuesAndVariablesPrettierVisitor } from "./printers/types-values-and-variables.js";
|
|
10
|
+
import { PackagesAndModulesPrettierVisitor } from "./printers/packages-and-modules.js";
|
|
11
|
+
// Mixins for the win
|
|
12
|
+
mixInMethods(ArraysPrettierVisitor, BlocksAndStatementPrettierVisitor, ClassesPrettierVisitor, ExpressionsPrettierVisitor, InterfacesPrettierVisitor, LexicalStructurePrettierVisitor, NamesPrettierVisitor, TypesValuesAndVariablesPrettierVisitor, PackagesAndModulesPrettierVisitor);
|
|
13
|
+
function mixInMethods(...classesToMix) {
|
|
14
|
+
classesToMix.forEach(from => {
|
|
15
|
+
const fromMethodsNames = Object.getOwnPropertyNames(from.prototype);
|
|
16
|
+
const fromPureMethodsName = fromMethodsNames.filter(methodName => methodName !== "constructor");
|
|
17
|
+
fromPureMethodsName.forEach(methodName => {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
BaseCstPrettierPrinter.prototype[methodName] = from.prototype[methodName];
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const prettyPrinter = new BaseCstPrettierPrinter();
|
|
24
|
+
// TODO: do we need the "path" and "print" arguments passed by prettier
|
|
25
|
+
// see https://github.com/prettier/prettier/issues/5747
|
|
26
|
+
export function createPrettierDoc(cstNode, options) {
|
|
27
|
+
prettyPrinter.prettierOptions = options;
|
|
28
|
+
return prettyPrinter.visit(cstNode);
|
|
29
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import parse from "./parser.js";
|
|
2
|
+
import print from "./printer.js";
|
|
3
|
+
import options from "./options.js";
|
|
4
|
+
const languages = [
|
|
5
|
+
{
|
|
6
|
+
name: "Java",
|
|
7
|
+
parsers: ["java"],
|
|
8
|
+
group: "Java",
|
|
9
|
+
tmScope: "text.html.vue",
|
|
10
|
+
aceMode: "html",
|
|
11
|
+
codemirrorMode: "clike",
|
|
12
|
+
codemirrorMimeType: "text/x-java",
|
|
13
|
+
extensions: [".java"],
|
|
14
|
+
linguistLanguageId: 181,
|
|
15
|
+
vscodeLanguageIds: ["java"]
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
function locStart( /* node */) {
|
|
19
|
+
return -1;
|
|
20
|
+
}
|
|
21
|
+
function locEnd( /* node */) {
|
|
22
|
+
return -1;
|
|
23
|
+
}
|
|
24
|
+
function hasPragma(text) {
|
|
25
|
+
return /^\/\*\*[\n][\t\s]+\*\s@(prettier|format)[\n][\t\s]+\*\//.test(text);
|
|
26
|
+
}
|
|
27
|
+
const parsers = {
|
|
28
|
+
java: {
|
|
29
|
+
parse,
|
|
30
|
+
astFormat: "java",
|
|
31
|
+
locStart,
|
|
32
|
+
locEnd,
|
|
33
|
+
hasPragma
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function canAttachComment(node) {
|
|
37
|
+
return node.ast_type && node.ast_type !== "comment";
|
|
38
|
+
}
|
|
39
|
+
function printComment(commentPath) {
|
|
40
|
+
const comment = commentPath.getValue();
|
|
41
|
+
switch (comment.ast_type) {
|
|
42
|
+
case "comment":
|
|
43
|
+
return comment.value;
|
|
44
|
+
default:
|
|
45
|
+
throw new Error("Not a comment: " + JSON.stringify(comment));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function clean(ast, newObj) {
|
|
49
|
+
delete newObj.lineno;
|
|
50
|
+
delete newObj.col_offset;
|
|
51
|
+
}
|
|
52
|
+
const printers = {
|
|
53
|
+
java: {
|
|
54
|
+
print,
|
|
55
|
+
// hasPrettierIgnore,
|
|
56
|
+
printComment,
|
|
57
|
+
canAttachComment,
|
|
58
|
+
massageAstNode: clean
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export default {
|
|
62
|
+
languages,
|
|
63
|
+
printers,
|
|
64
|
+
parsers,
|
|
65
|
+
options
|
|
66
|
+
};
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
entrypoint: {
|
|
3
|
+
type: "choice",
|
|
4
|
+
category: "Global",
|
|
5
|
+
default: "compilationUnit",
|
|
6
|
+
// sed -nr 's/.*\.RULE\(([^,]+),.*/\1/p' $(ls path/to/java-parser/rules/folder/*)
|
|
7
|
+
choices: [
|
|
8
|
+
{ value: "arrayInitializer" },
|
|
9
|
+
{ value: "variableInitializerList" },
|
|
10
|
+
{ value: "block" },
|
|
11
|
+
{ value: "blockStatements" },
|
|
12
|
+
{ value: "blockStatement" },
|
|
13
|
+
{ value: "localVariableDeclarationStatement" },
|
|
14
|
+
{ value: "localVariableDeclaration" },
|
|
15
|
+
{ value: "localVariableType" },
|
|
16
|
+
{ value: "statement" },
|
|
17
|
+
{ value: "statementWithoutTrailingSubstatement" },
|
|
18
|
+
{ value: "emptyStatement" },
|
|
19
|
+
{ value: "labeledStatement" },
|
|
20
|
+
{ value: "expressionStatement" },
|
|
21
|
+
{ value: "statementExpression" },
|
|
22
|
+
{ value: "ifStatement" },
|
|
23
|
+
{ value: "assertStatement" },
|
|
24
|
+
{ value: "switchStatement" },
|
|
25
|
+
{ value: "switchBlock" },
|
|
26
|
+
{ value: "switchBlockStatementGroup" },
|
|
27
|
+
{ value: "switchLabel" },
|
|
28
|
+
{ value: "switchRule" },
|
|
29
|
+
{ value: "caseConstant" },
|
|
30
|
+
{ value: "casePattern" },
|
|
31
|
+
{ value: "whileStatement" },
|
|
32
|
+
{ value: "doStatement" },
|
|
33
|
+
{ value: "forStatement" },
|
|
34
|
+
{ value: "basicForStatement" },
|
|
35
|
+
{ value: "forInit" },
|
|
36
|
+
{ value: "forUpdate" },
|
|
37
|
+
{ value: "statementExpressionList" },
|
|
38
|
+
{ value: "enhancedForStatement" },
|
|
39
|
+
{ value: "breakStatement" },
|
|
40
|
+
{ value: "continueStatement" },
|
|
41
|
+
{ value: "returnStatement" },
|
|
42
|
+
{ value: "throwStatement" },
|
|
43
|
+
{ value: "synchronizedStatement" },
|
|
44
|
+
{ value: "tryStatement" },
|
|
45
|
+
{ value: "catches" },
|
|
46
|
+
{ value: "catchClause" },
|
|
47
|
+
{ value: "catchFormalParameter" },
|
|
48
|
+
{ value: "catchType" },
|
|
49
|
+
{ value: "finally" },
|
|
50
|
+
{ value: "tryWithResourcesStatement" },
|
|
51
|
+
{ value: "resourceSpecification" },
|
|
52
|
+
{ value: "resourceList" },
|
|
53
|
+
{ value: "resource" },
|
|
54
|
+
{ value: "yieldStatement" },
|
|
55
|
+
{ value: "variableAccess" },
|
|
56
|
+
{ value: "classDeclaration" },
|
|
57
|
+
{ value: "normalClassDeclaration" },
|
|
58
|
+
{ value: "classModifier" },
|
|
59
|
+
{ value: "typeParameters" },
|
|
60
|
+
{ value: "typeParameterList" },
|
|
61
|
+
{ value: "classExtends" },
|
|
62
|
+
{ value: "classImplements" },
|
|
63
|
+
{ value: "interfaceTypeList" },
|
|
64
|
+
{ value: "classPermits" },
|
|
65
|
+
{ value: "classBody" },
|
|
66
|
+
{ value: "classBodyDeclaration" },
|
|
67
|
+
{ value: "classMemberDeclaration" },
|
|
68
|
+
{ value: "fieldDeclaration" },
|
|
69
|
+
{ value: "fieldModifier" },
|
|
70
|
+
{ value: "variableDeclaratorList" },
|
|
71
|
+
{ value: "variableDeclarator" },
|
|
72
|
+
{ value: "variableDeclaratorId" },
|
|
73
|
+
{ value: "variableInitializer" },
|
|
74
|
+
{ value: "unannType" },
|
|
75
|
+
{ value: "unannPrimitiveTypeWithOptionalDimsSuffix" },
|
|
76
|
+
{ value: "unannPrimitiveType" },
|
|
77
|
+
{ value: "unannReferenceType" },
|
|
78
|
+
{ value: "unannClassOrInterfaceType" },
|
|
79
|
+
{ value: "unannClassType" },
|
|
80
|
+
{ value: "unannInterfaceType" },
|
|
81
|
+
{ value: "unannTypeVariable" },
|
|
82
|
+
{ value: "methodDeclaration" },
|
|
83
|
+
{ value: "methodModifier" },
|
|
84
|
+
{ value: "methodHeader" },
|
|
85
|
+
{ value: "result" },
|
|
86
|
+
{ value: "methodDeclarator" },
|
|
87
|
+
{ value: "receiverParameter" },
|
|
88
|
+
{ value: "formalParameterList" },
|
|
89
|
+
{ value: "formalParameter" },
|
|
90
|
+
{ value: "variableParaRegularParameter" },
|
|
91
|
+
{ value: "variableArityParameter" },
|
|
92
|
+
{ value: "variableModifier" },
|
|
93
|
+
{ value: "throws" },
|
|
94
|
+
{ value: "exceptionTypeList" },
|
|
95
|
+
{ value: "exceptionType" },
|
|
96
|
+
{ value: "methodBody" },
|
|
97
|
+
{ value: "instanceInitializer" },
|
|
98
|
+
{ value: "staticInitializer" },
|
|
99
|
+
{ value: "constructorDeclaration" },
|
|
100
|
+
{ value: "constructorModifier" },
|
|
101
|
+
{ value: "constructorDeclarator" },
|
|
102
|
+
{ value: "simpleTypeName" },
|
|
103
|
+
{ value: "constructorBody" },
|
|
104
|
+
{ value: "explicitConstructorInvocation" },
|
|
105
|
+
{ value: "unqualifiedExplicitConstructorInvocation" },
|
|
106
|
+
{ value: "qualifiedExplicitConstructorInvocation" },
|
|
107
|
+
{ value: "enumDeclaration" },
|
|
108
|
+
{ value: "enumBody" },
|
|
109
|
+
{ value: "enumConstantList" },
|
|
110
|
+
{ value: "enumConstant" },
|
|
111
|
+
{ value: "enumConstantModifier" },
|
|
112
|
+
{ value: "enumBodyDeclarations" },
|
|
113
|
+
{ value: "recordDeclaration" },
|
|
114
|
+
{ value: "recordHeader" },
|
|
115
|
+
{ value: "recordComponentList" },
|
|
116
|
+
{ value: "recordComponent" },
|
|
117
|
+
{ value: "variableArityRecordComponent" },
|
|
118
|
+
{ value: "recordComponentModifier" },
|
|
119
|
+
{ value: "recordBody" },
|
|
120
|
+
{ value: "recordBodyDeclaration" },
|
|
121
|
+
{ value: "compactConstructorDeclaration" },
|
|
122
|
+
{ value: "isDims" },
|
|
123
|
+
{ value: "expression" },
|
|
124
|
+
{ value: "lambdaExpression" },
|
|
125
|
+
{ value: "lambdaParameters" },
|
|
126
|
+
{ value: "lambdaParametersWithBraces" },
|
|
127
|
+
{ value: "lambdaParameterList" },
|
|
128
|
+
{ value: "conciseLambdaParameterList" },
|
|
129
|
+
{ value: "normalLambdaParameterList" },
|
|
130
|
+
{ value: "normalLambdaParameter" },
|
|
131
|
+
{ value: "regularLambdaParameter" },
|
|
132
|
+
{ value: "lambdaParameterType" },
|
|
133
|
+
{ value: "conciseLambdaParameter" },
|
|
134
|
+
{ value: "lambdaBody" },
|
|
135
|
+
{ value: "conditionalExpression" },
|
|
136
|
+
{ value: "binaryExpression" },
|
|
137
|
+
{ value: "unaryExpression" },
|
|
138
|
+
{ value: "unaryExpressionNotPlusMinus" },
|
|
139
|
+
{ value: "primary" },
|
|
140
|
+
{ value: "primaryPrefix" },
|
|
141
|
+
{ value: "primarySuffix" },
|
|
142
|
+
{ value: "fqnOrRefType" },
|
|
143
|
+
{ value: "fqnOrRefTypePartRest" },
|
|
144
|
+
{ value: "fqnOrRefTypePartCommon" },
|
|
145
|
+
{ value: "fqnOrRefTypePartFirst" },
|
|
146
|
+
{ value: "parenthesisExpression" },
|
|
147
|
+
{ value: "castExpression" },
|
|
148
|
+
{ value: "primitiveCastExpression" },
|
|
149
|
+
{ value: "referenceTypeCastExpression" },
|
|
150
|
+
{ value: "newExpression" },
|
|
151
|
+
{ value: "unqualifiedClassInstanceCreationExpression" },
|
|
152
|
+
{ value: "classOrInterfaceTypeToInstantiate" },
|
|
153
|
+
{ value: "typeArgumentsOrDiamond" },
|
|
154
|
+
{ value: "diamond" },
|
|
155
|
+
{ value: "methodInvocationSuffix" },
|
|
156
|
+
{ value: "argumentList" },
|
|
157
|
+
{ value: "arrayCreationExpression" },
|
|
158
|
+
{ value: "arrayCreationExpressionWithoutInitializerSuffix" },
|
|
159
|
+
{ value: "arrayCreationWithInitializerSuffix" },
|
|
160
|
+
{ value: "dimExprs" },
|
|
161
|
+
{ value: "dimExpr" },
|
|
162
|
+
{ value: "classLiteralSuffix" },
|
|
163
|
+
{ value: "arrayAccessSuffix" },
|
|
164
|
+
{ value: "methodReferenceSuffix" },
|
|
165
|
+
{ value: "templateArgument" },
|
|
166
|
+
{ value: "template" },
|
|
167
|
+
{ value: "stringTemplate" },
|
|
168
|
+
{ value: "textBlockTemplate" },
|
|
169
|
+
{ value: "embeddedExpression" },
|
|
170
|
+
{ value: "pattern" },
|
|
171
|
+
{ value: "typePattern" },
|
|
172
|
+
{ value: "recordPattern" },
|
|
173
|
+
{ value: "componentPatternList" },
|
|
174
|
+
{ value: "componentPattern" },
|
|
175
|
+
{ value: "matchAllPattern" },
|
|
176
|
+
{ value: "guard" },
|
|
177
|
+
{ value: "isRefTypeInMethodRef" },
|
|
178
|
+
{ value: "interfaceDeclaration" },
|
|
179
|
+
{ value: "normalInterfaceDeclaration" },
|
|
180
|
+
{ value: "interfaceModifier" },
|
|
181
|
+
{ value: "interfaceExtends" },
|
|
182
|
+
{ value: "interfacePermits" },
|
|
183
|
+
{ value: "interfaceBody" },
|
|
184
|
+
{ value: "interfaceMemberDeclaration" },
|
|
185
|
+
{ value: "constantDeclaration" },
|
|
186
|
+
{ value: "constantModifier" },
|
|
187
|
+
{ value: "interfaceMethodDeclaration" },
|
|
188
|
+
{ value: "interfaceMethodModifier" },
|
|
189
|
+
{ value: "annotationInterfaceDeclaration" },
|
|
190
|
+
{ value: "annotationInterfaceBody" },
|
|
191
|
+
{ value: "annotationInterfaceMemberDeclaration" },
|
|
192
|
+
{ value: "annotationInterfaceElementDeclaration" },
|
|
193
|
+
{ value: "annotationInterfaceElementModifier" },
|
|
194
|
+
{ value: "defaultValue" },
|
|
195
|
+
{ value: "annotation" },
|
|
196
|
+
{ value: "elementValuePairList" },
|
|
197
|
+
{ value: "elementValuePair" },
|
|
198
|
+
{ value: "elementValue" },
|
|
199
|
+
{ value: "elementValueArrayInitializer" },
|
|
200
|
+
{ value: "elementValueList" },
|
|
201
|
+
{ value: "literal" },
|
|
202
|
+
{ value: "integerLiteral" },
|
|
203
|
+
{ value: "floatingPointLiteral" },
|
|
204
|
+
{ value: "booleanLiteral" },
|
|
205
|
+
{ value: "moduleName" },
|
|
206
|
+
{ value: "packageName" },
|
|
207
|
+
{ value: "typeName" },
|
|
208
|
+
{ value: "expressionName" },
|
|
209
|
+
{ value: "methodName" },
|
|
210
|
+
{ value: "packageOrTypeName" },
|
|
211
|
+
{ value: "ambiguousName" },
|
|
212
|
+
{ value: "compilationUnit" },
|
|
213
|
+
{ value: "ordinaryCompilationUnit" },
|
|
214
|
+
{ value: "modularCompilationUnit" },
|
|
215
|
+
{ value: "packageDeclaration" },
|
|
216
|
+
{ value: "packageModifier" },
|
|
217
|
+
{ value: "importDeclaration" },
|
|
218
|
+
{ value: "typeDeclaration" },
|
|
219
|
+
{ value: "moduleDeclaration" },
|
|
220
|
+
{ value: "moduleDirective" },
|
|
221
|
+
{ value: "requiresModuleDirective" },
|
|
222
|
+
{ value: "exportsModuleDirective" },
|
|
223
|
+
{ value: "opensModuleDirective" },
|
|
224
|
+
{ value: "usesModuleDirective" },
|
|
225
|
+
{ value: "providesModuleDirective" },
|
|
226
|
+
{ value: "requiresModifier" },
|
|
227
|
+
{ value: "primitiveType" },
|
|
228
|
+
{ value: "numericType" },
|
|
229
|
+
{ value: "integralType" },
|
|
230
|
+
{ value: "floatingPointType" },
|
|
231
|
+
{ value: "referenceType" },
|
|
232
|
+
{ value: "classOrInterfaceType" },
|
|
233
|
+
{ value: "classType" },
|
|
234
|
+
{ value: "interfaceType" },
|
|
235
|
+
{ value: "typeVariable" },
|
|
236
|
+
{ value: "dims" },
|
|
237
|
+
{ value: "typeParameter" },
|
|
238
|
+
{ value: "typeParameterModifier" },
|
|
239
|
+
{ value: "typeBound" },
|
|
240
|
+
{ value: "additionalBound" },
|
|
241
|
+
{ value: "typeArguments" },
|
|
242
|
+
{ value: "typeArgumentList" },
|
|
243
|
+
{ value: "typeArgument" },
|
|
244
|
+
{ value: "wildcard" },
|
|
245
|
+
{ value: "wildcardBounds" }
|
|
246
|
+
],
|
|
247
|
+
description: "Prettify from the entrypoint, allowing to use prettier on snippet."
|
|
248
|
+
},
|
|
249
|
+
trailingComma: {
|
|
250
|
+
type: "choice",
|
|
251
|
+
category: "Java",
|
|
252
|
+
default: "all",
|
|
253
|
+
choices: ["all", "es5", "none"],
|
|
254
|
+
description: "Print trailing commas wherever possible when multi-line."
|
|
255
|
+
}
|
|
256
|
+
};
|
package/dist/parser.js
ADDED
package/dist/printer.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { printArrayList, rejectAndConcat, rejectAndJoinSeps } from "./printer-utils.js";
|
|
2
|
+
import { builders } from "prettier/doc";
|
|
3
|
+
import { BaseCstPrettierPrinter } from "../base-cst-printer.js";
|
|
4
|
+
const { line } = builders;
|
|
5
|
+
export class ArraysPrettierVisitor extends BaseCstPrettierPrinter {
|
|
6
|
+
arrayInitializer(ctx) {
|
|
7
|
+
const optionalVariableInitializerList = this.visit(ctx.variableInitializerList);
|
|
8
|
+
return printArrayList({
|
|
9
|
+
list: optionalVariableInitializerList,
|
|
10
|
+
extraComma: ctx.Comma,
|
|
11
|
+
LCurly: ctx.LCurly[0],
|
|
12
|
+
RCurly: ctx.RCurly[0],
|
|
13
|
+
trailingComma: this.prettierOptions.trailingComma
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
variableInitializerList(ctx) {
|
|
17
|
+
const variableInitializers = this.mapVisit(ctx.variableInitializer);
|
|
18
|
+
const commas = ctx.Comma
|
|
19
|
+
? ctx.Comma.map(comma => {
|
|
20
|
+
return rejectAndConcat([comma, line]);
|
|
21
|
+
})
|
|
22
|
+
: [];
|
|
23
|
+
return rejectAndJoinSeps(commas, variableInitializers);
|
|
24
|
+
}
|
|
25
|
+
}
|