prettier-plugin-java 2.8.1 → 2.9.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 (39) hide show
  1. package/README.md +42 -102
  2. package/dist/index.cjs +2215 -0
  3. package/dist/index.d.cts +1630 -0
  4. package/dist/index.d.mts +1633 -0
  5. package/dist/index.mjs +2215 -0
  6. package/dist/tree-sitter-java_orchard.wasm +0 -0
  7. package/package.json +62 -24
  8. package/dist/comments.d.ts +0 -17
  9. package/dist/comments.js +0 -229
  10. package/dist/index.d.ts +0 -563
  11. package/dist/index.js +0 -29
  12. package/dist/options.d.ts +0 -43
  13. package/dist/options.js +0 -284
  14. package/dist/parser.d.ts +0 -9
  15. package/dist/parser.js +0 -24
  16. package/dist/printer.d.ts +0 -18
  17. package/dist/printer.js +0 -40
  18. package/dist/printers/arrays.d.ts +0 -9
  19. package/dist/printers/arrays.js +0 -9
  20. package/dist/printers/blocks-and-statements.d.ts +0 -117
  21. package/dist/printers/blocks-and-statements.js +0 -340
  22. package/dist/printers/classes.d.ts +0 -157
  23. package/dist/printers/classes.js +0 -485
  24. package/dist/printers/expressions.d.ts +0 -134
  25. package/dist/printers/expressions.js +0 -627
  26. package/dist/printers/helpers.d.ts +0 -73
  27. package/dist/printers/helpers.js +0 -273
  28. package/dist/printers/index.d.ts +0 -2
  29. package/dist/printers/index.js +0 -13
  30. package/dist/printers/interfaces.d.ts +0 -62
  31. package/dist/printers/interfaces.js +0 -175
  32. package/dist/printers/lexical-structure.d.ts +0 -14
  33. package/dist/printers/lexical-structure.js +0 -29
  34. package/dist/printers/names.d.ts +0 -12
  35. package/dist/printers/names.js +0 -11
  36. package/dist/printers/packages-and-modules.d.ts +0 -46
  37. package/dist/printers/packages-and-modules.js +0 -169
  38. package/dist/printers/types-values-and-variables.d.ts +0 -46
  39. package/dist/printers/types-values-and-variables.js +0 -90
@@ -1,11 +0,0 @@
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
- };
@@ -1,46 +0,0 @@
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;
@@ -1,169 +0,0 @@
1
- import { builders } from "prettier/doc";
2
- import { call, lineEndWithComments, lineStartWithComments, map, printBlock, printDanglingComments, printName, printSingle } from "./helpers.js";
3
- const { group, hardline, indent, join, line } = builders;
4
- export default {
5
- compilationUnit(path, print) {
6
- return [...printDanglingComments(path), printSingle(path, print), hardline];
7
- },
8
- ordinaryCompilationUnit(path, print) {
9
- const { children } = path.node;
10
- const declarations = [];
11
- if (children.packageDeclaration) {
12
- declarations.push(call(path, print, "packageDeclaration"));
13
- }
14
- if (children.importDeclaration) {
15
- const staticCount = sortImports(children.importDeclaration);
16
- const importDeclarations = map(path, print, "importDeclaration").filter(doc => doc !== "");
17
- const staticDeclarations = importDeclarations.slice(0, staticCount);
18
- const nonStaticDeclarations = importDeclarations.slice(staticCount);
19
- declarations.push(...[staticDeclarations, nonStaticDeclarations]
20
- .filter(({ length }) => length)
21
- .map(declarations => join(hardline, declarations)));
22
- }
23
- if (children.typeDeclaration) {
24
- declarations.push(...map(path, print, "typeDeclaration").filter(declaration => declaration !== ""));
25
- }
26
- return join([hardline, hardline], declarations);
27
- },
28
- modularCompilationUnit(path, print) {
29
- const { children } = path.node;
30
- const declarations = [];
31
- if (children.importDeclaration) {
32
- const staticCount = sortImports(children.importDeclaration);
33
- const importDeclarations = map(path, print, "importDeclaration").filter(doc => doc !== "");
34
- const staticDeclarations = importDeclarations.slice(0, staticCount);
35
- const nonStaticDeclarations = importDeclarations.slice(staticCount);
36
- declarations.push(...[staticDeclarations, nonStaticDeclarations]
37
- .filter(({ length }) => length)
38
- .map(declarations => join(hardline, declarations)));
39
- }
40
- declarations.push(call(path, print, "moduleDeclaration"));
41
- return join([hardline, hardline], declarations);
42
- },
43
- packageDeclaration(path, print) {
44
- return join(hardline, [
45
- ...map(path, print, "packageModifier"),
46
- ["package ", printName(path, print), ";"]
47
- ]);
48
- },
49
- packageModifier: printSingle,
50
- importDeclaration(path, print) {
51
- const { children } = path.node;
52
- if (children.emptyStatement) {
53
- return call(path, print, "emptyStatement");
54
- }
55
- const declaration = ["import "];
56
- if (children.Static) {
57
- declaration.push("static ");
58
- }
59
- declaration.push(call(path, print, "packageOrTypeName"));
60
- if (children.Star) {
61
- declaration.push(".*");
62
- }
63
- declaration.push(";");
64
- return declaration;
65
- },
66
- typeDeclaration(path, print) {
67
- return path.node.children.Semicolon ? "" : printSingle(path, print);
68
- },
69
- moduleDeclaration(path, print) {
70
- const { annotation, Open } = path.node.children;
71
- const prefix = [];
72
- if (annotation) {
73
- prefix.push(...map(path, print, "annotation"));
74
- }
75
- if (Open) {
76
- prefix.push("open");
77
- }
78
- const declarations = map(path, declarationPath => {
79
- const declaration = print(declarationPath);
80
- const { node, previous } = declarationPath;
81
- return !previous ||
82
- lineStartWithComments(node) <= lineEndWithComments(previous) + 1
83
- ? declaration
84
- : [hardline, declaration];
85
- }, "moduleDirective");
86
- return join(" ", [
87
- ...prefix,
88
- "module",
89
- printName(path, print),
90
- printBlock(path, declarations)
91
- ]);
92
- },
93
- moduleDirective: printSingle,
94
- requiresModuleDirective(path, print) {
95
- return join(" ", [
96
- "requires",
97
- ...map(path, print, "requiresModifier"),
98
- [call(path, print, "moduleName"), ";"]
99
- ]);
100
- },
101
- exportsModuleDirective(path, print) {
102
- return printToModuleNamesDirective(path, print, "exports");
103
- },
104
- opensModuleDirective(path, print) {
105
- return printToModuleNamesDirective(path, print, "opens");
106
- },
107
- usesModuleDirective(path, print) {
108
- return ["uses ", call(path, print, "typeName"), ";"];
109
- },
110
- providesModuleDirective(path, print) {
111
- const [firstTypeName, ...restTypeNames] = map(path, print, "typeName");
112
- return [
113
- "provides ",
114
- firstTypeName,
115
- group(indent([
116
- line,
117
- group(indent(["with", line, ...join([",", line], restTypeNames)]))
118
- ])),
119
- ";"
120
- ];
121
- },
122
- requiresModifier: printSingle
123
- };
124
- function sortImports(importDeclarations) {
125
- importDeclarations.sort(({ children: a }, { children: b }) => {
126
- if (a.Static && !b.Static) {
127
- return -1;
128
- }
129
- else if (b.Static && !a.Static) {
130
- return 1;
131
- }
132
- if (!b.packageOrTypeName) {
133
- if (a.packageOrTypeName) {
134
- return -1;
135
- }
136
- return 0;
137
- }
138
- else if (!a.packageOrTypeName) {
139
- return 1;
140
- }
141
- return compareFqn(a.packageOrTypeName[0], b.packageOrTypeName[0]);
142
- });
143
- return importDeclarations.reduce((staticCount, importDeclaration) => importDeclaration.children.Static ? staticCount + 1 : staticCount, 0);
144
- }
145
- function compareFqn(a, b) {
146
- const identifiersA = a.children.Identifier;
147
- const identifiersB = b.children.Identifier;
148
- const minParts = Math.min(identifiersA.length, identifiersB.length);
149
- for (let i = 0; i < minParts; i++) {
150
- const imageA = identifiersA[i].image;
151
- const imageB = identifiersB[i].image;
152
- if (imageA < imageB) {
153
- return -1;
154
- }
155
- else if (imageA > imageB) {
156
- return 1;
157
- }
158
- }
159
- return identifiersA.length - identifiersB.length;
160
- }
161
- function printToModuleNamesDirective(path, print, prefix) {
162
- const directive = [prefix, " ", call(path, print, "packageName")];
163
- if (path.node.children.moduleName) {
164
- const moduleNames = join([",", line], map(path, print, "moduleName"));
165
- directive.push(group(indent([line, group(indent(["to", line, ...moduleNames]))])));
166
- }
167
- directive.push(";");
168
- return directive;
169
- }
@@ -1,46 +0,0 @@
1
- import { builders } from "prettier/doc";
2
- import { printClassType, printSingle } from "./helpers.js";
3
- declare const _default: {
4
- primitiveType(path: import("prettier").AstPath<import("java-parser").PrimitiveTypeCstNode & {
5
- comments?: import("../comments.js").JavaComment[];
6
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
7
- numericType: typeof printSingle;
8
- integralType: typeof printSingle;
9
- floatingPointType: typeof printSingle;
10
- referenceType(path: import("prettier").AstPath<import("java-parser").ReferenceTypeCstNode & {
11
- comments?: import("../comments.js").JavaComment[];
12
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
13
- classOrInterfaceType: typeof printSingle;
14
- classType: typeof printClassType;
15
- interfaceType: typeof printSingle;
16
- typeVariable(path: import("prettier").AstPath<import("java-parser").TypeVariableCstNode & {
17
- comments?: import("../comments.js").JavaComment[];
18
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
19
- dims(path: import("prettier").AstPath<import("java-parser").DimsCstNode & {
20
- comments?: import("../comments.js").JavaComment[];
21
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
22
- typeParameter(path: import("prettier").AstPath<import("java-parser").TypeParameterCstNode & {
23
- comments?: import("../comments.js").JavaComment[];
24
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
25
- typeParameterModifier: typeof printSingle;
26
- typeBound(path: import("prettier").AstPath<import("java-parser").TypeBoundCstNode & {
27
- comments?: import("../comments.js").JavaComment[];
28
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
29
- additionalBound(path: import("prettier").AstPath<import("java-parser").AdditionalBoundCstNode & {
30
- comments?: import("../comments.js").JavaComment[];
31
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
32
- typeArguments(path: import("prettier").AstPath<import("java-parser").TypeArgumentsCstNode & {
33
- comments?: import("../comments.js").JavaComment[];
34
- }>, print: import("./helpers.js").JavaPrintFn): builders.Group;
35
- typeArgumentList(path: import("prettier").AstPath<import("java-parser").TypeArgumentListCstNode & {
36
- comments?: import("../comments.js").JavaComment[];
37
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
38
- typeArgument: typeof printSingle;
39
- wildcard(path: import("prettier").AstPath<import("java-parser").WildcardCstNode & {
40
- comments?: import("../comments.js").JavaComment[];
41
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
42
- wildcardBounds(path: import("prettier").AstPath<import("java-parser").WildcardBoundsCstNode & {
43
- comments?: import("../comments.js").JavaComment[];
44
- }>, print: import("./helpers.js").JavaPrintFn): builders.Doc[];
45
- };
46
- export default _default;
@@ -1,90 +0,0 @@
1
- import { builders } from "prettier/doc";
2
- import { call, definedKeys, flatMap, isNonTerminal, map, onlyDefinedKey, printClassType, printList, printSingle } from "./helpers.js";
3
- const { group, indent, join, line, softline } = builders;
4
- export default {
5
- primitiveType(path, print) {
6
- const { children } = path.node;
7
- const typeKey = onlyDefinedKey(children, ["Boolean", "numericType"]);
8
- return join(" ", [
9
- ...map(path, print, "annotation"),
10
- call(path, print, typeKey)
11
- ]);
12
- },
13
- numericType: printSingle,
14
- integralType: printSingle,
15
- floatingPointType: printSingle,
16
- referenceType(path, print) {
17
- const { children } = path.node;
18
- const typeKey = onlyDefinedKey(children, [
19
- "primitiveType",
20
- "classOrInterfaceType"
21
- ]);
22
- const type = call(path, print, typeKey);
23
- return join(" ", [
24
- ...map(path, print, "annotation"),
25
- children.dims ? [type, call(path, print, "dims")] : type
26
- ]);
27
- },
28
- classOrInterfaceType: printSingle,
29
- classType: printClassType,
30
- interfaceType: printSingle,
31
- typeVariable(path, print) {
32
- return join(" ", [
33
- ...map(path, print, "annotation"),
34
- call(path, print, "Identifier")
35
- ]);
36
- },
37
- dims(path, print) {
38
- return flatMap(path, childPath => {
39
- const child = print(childPath);
40
- return isNonTerminal(childPath.node) ? [child, " "] : child;
41
- }, definedKeys(path.node.children, ["annotation", "LSquare", "RSquare"]));
42
- },
43
- typeParameter(path, print) {
44
- const parameter = [
45
- ...map(path, print, "typeParameterModifier"),
46
- call(path, print, "typeIdentifier")
47
- ];
48
- if (path.node.children.typeBound) {
49
- parameter.push(call(path, print, "typeBound"));
50
- }
51
- return join(" ", parameter);
52
- },
53
- typeParameterModifier: printSingle,
54
- typeBound(path, print) {
55
- const bound = ["extends ", call(path, print, "classOrInterfaceType")];
56
- if (path.node.children.additionalBound) {
57
- bound.push(group(indent([line, ...join(line, map(path, print, "additionalBound"))])));
58
- }
59
- return bound;
60
- },
61
- additionalBound(path, print) {
62
- return ["& ", call(path, print, "interfaceType")];
63
- },
64
- typeArguments(path, print) {
65
- return group([
66
- "<",
67
- indent([softline, call(path, print, "typeArgumentList")]),
68
- softline,
69
- ">"
70
- ]);
71
- },
72
- typeArgumentList(path, print) {
73
- return printList(path, print, "typeArgument");
74
- },
75
- typeArgument: printSingle,
76
- wildcard(path, print) {
77
- const wildcard = [...map(path, print, "annotation"), "?"];
78
- if (path.node.children.wildcardBounds) {
79
- wildcard.push(call(path, print, "wildcardBounds"));
80
- }
81
- return join(" ", wildcard);
82
- },
83
- wildcardBounds(path, print) {
84
- return [
85
- path.node.children.Extends ? "extends" : "super",
86
- " ",
87
- call(path, print, "referenceType")
88
- ];
89
- }
90
- };