prettier-plugin-java 2.6.0 → 2.6.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.
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "prettier-plugin-java",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "Prettier Java Plugin",
5
5
  "type": "module",
6
- "exports": "./dist/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./src/index.d.ts",
9
+ "default": "./src/index.js"
10
+ }
11
+ },
7
12
  "files": [
8
13
  "dist"
9
14
  ],
@@ -11,7 +16,7 @@
11
16
  "repository": "https://github.com/jhipster/prettier-java",
12
17
  "license": "Apache-2.0",
13
18
  "dependencies": {
14
- "java-parser": "2.3.0",
19
+ "java-parser": "2.3.1",
15
20
  "lodash": "4.17.21",
16
21
  "prettier": "3.2.5"
17
22
  },
@@ -38,5 +43,5 @@
38
43
  "ts-node": "10.9.1",
39
44
  "typescript": "4.9.3"
40
45
  },
41
- "gitHead": "30e1cad12e8936df43c25eeb9dad5aef20d9af6c"
46
+ "gitHead": "8ee70accfbc3eecd5fb1c5da430701ca4765c994"
42
47
  }
@@ -1,55 +0,0 @@
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
- }
@@ -1,29 +0,0 @@
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 DELETED
@@ -1,66 +0,0 @@
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 DELETED
@@ -1,254 +0,0 @@
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: "whileStatement" },
31
- { value: "doStatement" },
32
- { value: "forStatement" },
33
- { value: "basicForStatement" },
34
- { value: "forInit" },
35
- { value: "forUpdate" },
36
- { value: "statementExpressionList" },
37
- { value: "enhancedForStatement" },
38
- { value: "breakStatement" },
39
- { value: "continueStatement" },
40
- { value: "returnStatement" },
41
- { value: "throwStatement" },
42
- { value: "synchronizedStatement" },
43
- { value: "tryStatement" },
44
- { value: "catches" },
45
- { value: "catchClause" },
46
- { value: "catchFormalParameter" },
47
- { value: "catchType" },
48
- { value: "finally" },
49
- { value: "tryWithResourcesStatement" },
50
- { value: "resourceSpecification" },
51
- { value: "resourceList" },
52
- { value: "resource" },
53
- { value: "yieldStatement" },
54
- { value: "variableAccess" },
55
- { value: "classDeclaration" },
56
- { value: "normalClassDeclaration" },
57
- { value: "classModifier" },
58
- { value: "typeParameters" },
59
- { value: "typeParameterList" },
60
- { value: "superclass" },
61
- { value: "superinterfaces" },
62
- { value: "interfaceTypeList" },
63
- { value: "classPermits" },
64
- { value: "classBody" },
65
- { value: "classBodyDeclaration" },
66
- { value: "classMemberDeclaration" },
67
- { value: "fieldDeclaration" },
68
- { value: "fieldModifier" },
69
- { value: "variableDeclaratorList" },
70
- { value: "variableDeclarator" },
71
- { value: "variableDeclaratorId" },
72
- { value: "variableInitializer" },
73
- { value: "unannType" },
74
- { value: "unannPrimitiveTypeWithOptionalDimsSuffix" },
75
- { value: "unannPrimitiveType" },
76
- { value: "unannReferenceType" },
77
- { value: "unannClassOrInterfaceType" },
78
- { value: "unannClassType" },
79
- { value: "unannInterfaceType" },
80
- { value: "unannTypeVariable" },
81
- { value: "methodDeclaration" },
82
- { value: "methodModifier" },
83
- { value: "methodHeader" },
84
- { value: "result" },
85
- { value: "methodDeclarator" },
86
- { value: "receiverParameter" },
87
- { value: "formalParameterList" },
88
- { value: "formalParameter" },
89
- { value: "variableParaRegularParameter" },
90
- { value: "variableArityParameter" },
91
- { value: "variableModifier" },
92
- { value: "throws" },
93
- { value: "exceptionTypeList" },
94
- { value: "exceptionType" },
95
- { value: "methodBody" },
96
- { value: "instanceInitializer" },
97
- { value: "staticInitializer" },
98
- { value: "constructorDeclaration" },
99
- { value: "constructorModifier" },
100
- { value: "constructorDeclarator" },
101
- { value: "simpleTypeName" },
102
- { value: "constructorBody" },
103
- { value: "explicitConstructorInvocation" },
104
- { value: "unqualifiedExplicitConstructorInvocation" },
105
- { value: "qualifiedExplicitConstructorInvocation" },
106
- { value: "enumDeclaration" },
107
- { value: "enumBody" },
108
- { value: "enumConstantList" },
109
- { value: "enumConstant" },
110
- { value: "enumConstantModifier" },
111
- { value: "enumBodyDeclarations" },
112
- { value: "recordDeclaration" },
113
- { value: "recordHeader" },
114
- { value: "recordComponentList" },
115
- { value: "recordComponent" },
116
- { value: "variableArityRecordComponent" },
117
- { value: "recordComponentModifier" },
118
- { value: "recordBody" },
119
- { value: "recordBodyDeclaration" },
120
- { value: "compactConstructorDeclaration" },
121
- { value: "isDims" },
122
- { value: "expression" },
123
- { value: "lambdaExpression" },
124
- { value: "lambdaParameters" },
125
- { value: "lambdaParametersWithBraces" },
126
- { value: "lambdaParameterList" },
127
- { value: "inferredLambdaParameterList" },
128
- { value: "explicitLambdaParameterList" },
129
- { value: "lambdaParameter" },
130
- { value: "regularLambdaParameter" },
131
- { value: "lambdaParameterType" },
132
- { value: "lambdaBody" },
133
- { value: "ternaryExpression" },
134
- { value: "binaryExpression" },
135
- { value: "unaryExpression" },
136
- { value: "unaryExpressionNotPlusMinus" },
137
- { value: "primary" },
138
- { value: "primaryPrefix" },
139
- { value: "primarySuffix" },
140
- { value: "fqnOrRefType" },
141
- { value: "fqnOrRefTypePartRest" },
142
- { value: "fqnOrRefTypePartCommon" },
143
- { value: "fqnOrRefTypePartFirst" },
144
- { value: "parenthesisExpression" },
145
- { value: "castExpression" },
146
- { value: "primitiveCastExpression" },
147
- { value: "referenceTypeCastExpression" },
148
- { value: "newExpression" },
149
- { value: "unqualifiedClassInstanceCreationExpression" },
150
- { value: "classOrInterfaceTypeToInstantiate" },
151
- { value: "typeArgumentsOrDiamond" },
152
- { value: "diamond" },
153
- { value: "methodInvocationSuffix" },
154
- { value: "argumentList" },
155
- { value: "arrayCreationExpression" },
156
- { value: "arrayCreationDefaultInitSuffix" },
157
- { value: "arrayCreationExplicitInitSuffix" },
158
- { value: "dimExprs" },
159
- { value: "dimExpr" },
160
- { value: "classLiteralSuffix" },
161
- { value: "arrayAccessSuffix" },
162
- { value: "methodReferenceSuffix" },
163
- { value: "templateArgument" },
164
- { value: "template" },
165
- { value: "stringTemplate" },
166
- { value: "textBlockTemplate" },
167
- { value: "embeddedExpression" },
168
- { value: "pattern" },
169
- { value: "typePattern" },
170
- { value: "recordPattern" },
171
- { value: "componentPatternList" },
172
- { value: "componentPattern" },
173
- { value: "unnamedPattern" },
174
- { value: "guard" },
175
- { value: "isRefTypeInMethodRef" },
176
- { value: "interfaceDeclaration" },
177
- { value: "normalInterfaceDeclaration" },
178
- { value: "interfaceModifier" },
179
- { value: "extendsInterfaces" },
180
- { value: "interfacePermits" },
181
- { value: "interfaceBody" },
182
- { value: "interfaceMemberDeclaration" },
183
- { value: "constantDeclaration" },
184
- { value: "constantModifier" },
185
- { value: "interfaceMethodDeclaration" },
186
- { value: "interfaceMethodModifier" },
187
- { value: "annotationTypeDeclaration" },
188
- { value: "annotationTypeBody" },
189
- { value: "annotationTypeMemberDeclaration" },
190
- { value: "annotationTypeElementDeclaration" },
191
- { value: "annotationTypeElementModifier" },
192
- { value: "defaultValue" },
193
- { value: "annotation" },
194
- { value: "elementValuePairList" },
195
- { value: "elementValuePair" },
196
- { value: "elementValue" },
197
- { value: "elementValueArrayInitializer" },
198
- { value: "elementValueList" },
199
- { value: "literal" },
200
- { value: "integerLiteral" },
201
- { value: "floatingPointLiteral" },
202
- { value: "booleanLiteral" },
203
- { value: "moduleName" },
204
- { value: "packageName" },
205
- { value: "typeName" },
206
- { value: "expressionName" },
207
- { value: "methodName" },
208
- { value: "packageOrTypeName" },
209
- { value: "ambiguousName" },
210
- { value: "compilationUnit" },
211
- { value: "ordinaryCompilationUnit" },
212
- { value: "modularCompilationUnit" },
213
- { value: "packageDeclaration" },
214
- { value: "packageModifier" },
215
- { value: "importDeclaration" },
216
- { value: "typeDeclaration" },
217
- { value: "moduleDeclaration" },
218
- { value: "moduleDirective" },
219
- { value: "requiresModuleDirective" },
220
- { value: "exportsModuleDirective" },
221
- { value: "opensModuleDirective" },
222
- { value: "usesModuleDirective" },
223
- { value: "providesModuleDirective" },
224
- { value: "requiresModifier" },
225
- { value: "primitiveType" },
226
- { value: "numericType" },
227
- { value: "integralType" },
228
- { value: "floatingPointType" },
229
- { value: "referenceType" },
230
- { value: "classOrInterfaceType" },
231
- { value: "classType" },
232
- { value: "interfaceType" },
233
- { value: "typeVariable" },
234
- { value: "dims" },
235
- { value: "typeParameter" },
236
- { value: "typeParameterModifier" },
237
- { value: "typeBound" },
238
- { value: "additionalBound" },
239
- { value: "typeArguments" },
240
- { value: "typeArgumentList" },
241
- { value: "typeArgument" },
242
- { value: "wildcard" },
243
- { value: "wildcardBounds" }
244
- ],
245
- description: "Prettify from the entrypoint, allowing to use prettier on snippet."
246
- },
247
- trailingComma: {
248
- type: "choice",
249
- category: "Java",
250
- default: "all",
251
- choices: ["all", "none"],
252
- description: "Print trailing commas wherever possible when multi-line."
253
- }
254
- };
package/dist/parser.js DELETED
@@ -1,4 +0,0 @@
1
- import javaParser from "java-parser";
2
- export default function parse(text, parsers, opts) {
3
- return javaParser.parse(text, opts.entrypoint);
4
- }
package/dist/printer.js DELETED
@@ -1,6 +0,0 @@
1
- import { createPrettierDoc } from "./cst-printer.js";
2
- // eslint-disable-next-line no-unused-vars
3
- export default function genericPrint(path, options, print) {
4
- const node = path.getValue();
5
- return createPrettierDoc(node, options);
6
- }
@@ -1,25 +0,0 @@
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
- }