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.
- package/LICENSE +1 -1
- package/dist/base-cst-printer.js +22 -44
- package/dist/cst-printer.js +19 -27
- package/dist/index.js +19 -20
- package/dist/options.js +16 -21
- package/dist/parser.js +2 -4
- package/dist/printer.js +3 -5
- package/dist/printers/arrays.js +17 -41
- package/dist/printers/blocks-and-statements.js +289 -356
- package/dist/printers/classes.js +451 -495
- package/dist/printers/comments/comments-utils.js +5 -13
- package/dist/printers/comments/format-comments.js +34 -50
- package/dist/printers/comments/handle-comments.js +17 -23
- package/dist/printers/expressions.js +378 -386
- package/dist/printers/interfaces.js +148 -181
- package/dist/printers/lexical-structure.js +26 -58
- package/dist/printers/names.js +29 -53
- package/dist/printers/packages-and-modules.js +116 -143
- package/dist/printers/prettier-builder.js +21 -31
- package/dist/printers/printer-utils.js +173 -221
- package/dist/printers/types-values-and-variables.js +111 -149
- package/dist/types/utils.js +6 -15
- package/dist/utils/expressions-utils.js +7 -11
- package/dist/utils/index.js +2 -12
- package/dist/utils/isEmptyDoc.js +2 -4
- package/dist/utils/printArgumentListWithBraces.js +29 -19
- package/dist/utils/printSingleLambdaInvocation.js +15 -17
- package/package.json +10 -13
- package/dist/src/base-cst-printer.js +0 -77
- package/dist/src/cst-printer.js +0 -37
- package/dist/src/index.js +0 -67
- package/dist/src/options.js +0 -256
- package/dist/src/parser.js +0 -7
- package/dist/src/printer.js +0 -28
- package/dist/src/printers/arrays.js +0 -49
- package/dist/src/printers/blocks-and-statements.js +0 -493
- package/dist/src/printers/classes.js +0 -724
- package/dist/src/printers/comments/comments-utils.js +0 -29
- package/dist/src/printers/comments/format-comments.js +0 -187
- package/dist/src/printers/comments/handle-comments.js +0 -38
- package/dist/src/printers/expressions.js +0 -549
- package/dist/src/printers/interfaces.js +0 -251
- package/dist/src/printers/lexical-structure.js +0 -43
- package/dist/src/printers/names.js +0 -53
- package/dist/src/printers/packages-and-modules.js +0 -185
- package/dist/src/printers/prettier-builder.js +0 -47
- package/dist/src/printers/printer-utils.js +0 -577
- package/dist/src/printers/types-values-and-variables.js +0 -183
- package/dist/src/types/utils.js +0 -29
- package/dist/src/utils/expressions-utils.js +0 -29
- package/dist/src/utils/index.js +0 -10
- package/dist/src/utils/printArgumentListWithBraces.js +0 -21
- package/dist/src/utils/printSingleLambdaInvocation.js +0 -20
- package/dist/test/babel-register.js +0 -3
- package/dist/test/repository-test/core-test.js +0 -12
- package/dist/test/repository-test/jhipster-1-test.js +0 -17
- package/dist/test/repository-test/jhipster-2-test.js +0 -16
- package/dist/test/test-utils.js +0 -215
- package/dist/test/unit-test/annotation_type_declaration/annotation_type_declaration-spec.js +0 -6
- package/dist/test/unit-test/args/args-spec.js +0 -6
- package/dist/test/unit-test/assert/assert-spec.js +0 -6
- package/dist/test/unit-test/binary_expressions/binary_expressions-spec.js +0 -6
- package/dist/test/unit-test/blank_lines/blank_lines-spec.js +0 -6
- package/dist/test/unit-test/bug-fixes/bug-fixes-spec.js +0 -6
- package/dist/test/unit-test/cast/cast-spec.js +0 -6
- package/dist/test/unit-test/char_literal/char_literal-spec.js +0 -6
- package/dist/test/unit-test/classes/multiple_classes-spec.js +0 -6
- package/dist/test/unit-test/comments/comments-spec.js +0 -14
- package/dist/test/unit-test/complex_generic_class/complex_generic_class-spec.js +0 -6
- package/dist/test/unit-test/constructors/constructors-spec.js +0 -6
- package/dist/test/unit-test/empty_statement/empty_statement-spec.js +0 -6
- package/dist/test/unit-test/enum/enum-spec.js +0 -6
- package/dist/test/unit-test/expressions/expressions-spec.js +0 -6
- package/dist/test/unit-test/extends_abstract_class/extends_abstract_class-spec.js +0 -6
- package/dist/test/unit-test/extends_abstract_class_and_implements_interfaces/extends_abstract_class_and_implements_interfaces-spec.js +0 -6
- package/dist/test/unit-test/for/for-spec.js +0 -6
- package/dist/test/unit-test/generic_class/generic_class-spec.js +0 -6
- package/dist/test/unit-test/generic_questionmark/generic_questionmark-spec.js +0 -6
- package/dist/test/unit-test/hello-world/hello-word-spec.js +0 -6
- package/dist/test/unit-test/if/if-spec.js +0 -6
- package/dist/test/unit-test/indent/indent-spec.js +0 -6
- package/dist/test/unit-test/instantiation/instantiation-spec.js +0 -6
- package/dist/test/unit-test/interface/interface-spec.js +0 -6
- package/dist/test/unit-test/lambda/lambda-spec.js +0 -6
- package/dist/test/unit-test/marker_annotations/marker_annotations-spec.js +0 -6
- package/dist/test/unit-test/member_chain/member_chain-spec.js +0 -6
- package/dist/test/unit-test/method_reference/method_reference-spec.js +0 -6
- package/dist/test/unit-test/modifiers/modifiers-spec.js +0 -6
- package/dist/test/unit-test/modules/modules-spec.js +0 -6
- package/dist/test/unit-test/package_and_imports/package_and_imports-spec.js +0 -34
- package/dist/test/unit-test/pattern-matching/pattern-matching-spec.js +0 -6
- package/dist/test/unit-test/prettier-ignore/prettier-ignore-spec.js +0 -28
- package/dist/test/unit-test/records/records-spec.js +0 -6
- package/dist/test/unit-test/return/return-spec.js +0 -6
- package/dist/test/unit-test/sealed/sealed-spec.js +0 -6
- package/dist/test/unit-test/snippets/arrays/array-initializer.spec.js +0 -94
- package/dist/test/unit-test/snippets/arrays/variable-initializer-list.spec.js +0 -19
- package/dist/test/unit-test/snippets/blocks-and-statements/switch.spec.js +0 -26
- package/dist/test/unit-test/snippets/classes/class-body.spec.js +0 -181
- package/dist/test/unit-test/snippets/classes/enum-body.spec.js +0 -87
- package/dist/test/unit-test/snippets/classes/variableDeclarator/test.spec.js +0 -186
- package/dist/test/unit-test/snippets/interfaces/element-value-array-initializer.spec.js +0 -85
- package/dist/test/unit-test/snippets/names/ambiguousName/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/names/expressionName/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/names/methodName/test.spec.js +0 -12
- package/dist/test/unit-test/snippets/names/packageOrTypeName/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/types-values-and-variables/floatingPointType/test.spec.js +0 -19
- package/dist/test/unit-test/snippets/types-values-and-variables/integralType/test.spec.js +0 -40
- package/dist/test/unit-test/snippets/types-values-and-variables/numericType/test.spec.js +0 -88
- package/dist/test/unit-test/snippets/types-values-and-variables/wildcard/test.spec.js +0 -112
- package/dist/test/unit-test/snippets/types-values-and-variables/wildcardBounds/test.spec.js +0 -81
- package/dist/test/unit-test/switch/switch-spec.js +0 -6
- package/dist/test/unit-test/synchronized/synchronized-spec.js +0 -6
- package/dist/test/unit-test/text-blocks/text-block-spec.js +0 -6
- package/dist/test/unit-test/throws/throws-spec.js +0 -6
- package/dist/test/unit-test/try_catch/try_catch-spec.js +0 -6
- package/dist/test/unit-test/types/types-spec.js +0 -6
- package/dist/test/unit-test/variables/variables-spec.js +0 -6
- package/dist/test/unit-test/while/while-spec.js +0 -6
- package/dist/test/unit-test/yield-statement/yield-statement-spec.js +0 -6
package/LICENSE
CHANGED
package/dist/base-cst-printer.js
CHANGED
|
@@ -1,60 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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.BaseCstPrettierPrinter = void 0;
|
|
19
|
-
var java_parser_1 = require("java-parser");
|
|
20
|
-
var format_comments_1 = require("./printers/comments/format-comments");
|
|
21
|
-
var BaseCstPrettierPrinter = /** @class */ (function (_super) {
|
|
22
|
-
__extends(BaseCstPrettierPrinter, _super);
|
|
23
|
-
function BaseCstPrettierPrinter() {
|
|
24
|
-
var _this = _super.call(this) || this;
|
|
25
|
-
_this.mapVisit = function (elements, params) {
|
|
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) => {
|
|
26
7
|
if (elements === undefined) {
|
|
27
8
|
// TODO: can optimize this by returning an immutable empty array singleton.
|
|
28
9
|
return [];
|
|
29
10
|
}
|
|
30
|
-
return elements.map(
|
|
11
|
+
return elements.map(element => this.visit(element, params));
|
|
31
12
|
};
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
this.getSingle = (ctx) => {
|
|
14
|
+
const ctxKeys = Object.keys(ctx);
|
|
34
15
|
if (ctxKeys.length !== 1) {
|
|
35
|
-
throw Error(
|
|
16
|
+
throw Error(`Expecting single key CST ctx but found: <${ctxKeys.length}> keys`);
|
|
36
17
|
}
|
|
37
|
-
|
|
38
|
-
|
|
18
|
+
const singleElementKey = ctxKeys[0];
|
|
19
|
+
const singleElementValues = ctx[singleElementKey];
|
|
39
20
|
if ((singleElementValues === null || singleElementValues === void 0 ? void 0 : singleElementValues.length) !== 1) {
|
|
40
|
-
throw Error(
|
|
21
|
+
throw Error(`Expecting single item in CST ctx key but found: <${singleElementValues === null || singleElementValues === void 0 ? void 0 : singleElementValues.length}> items`);
|
|
41
22
|
}
|
|
42
23
|
return singleElementValues[0];
|
|
43
24
|
};
|
|
44
25
|
// @ts-ignore
|
|
45
|
-
|
|
46
|
-
|
|
26
|
+
this.orgVisit = this.visit;
|
|
27
|
+
this.visit = function (ctx, inParam) {
|
|
47
28
|
if (ctx === undefined) {
|
|
48
29
|
// empty Doc
|
|
49
30
|
return "";
|
|
50
31
|
}
|
|
51
|
-
|
|
32
|
+
const node = Array.isArray(ctx) ? ctx[0] : ctx;
|
|
52
33
|
if (node.ignore) {
|
|
53
34
|
try {
|
|
54
|
-
|
|
35
|
+
const startOffset = node.leadingComments !== undefined
|
|
55
36
|
? node.leadingComments[0].startOffset
|
|
56
37
|
: node.location.startOffset;
|
|
57
|
-
|
|
38
|
+
const endOffset = (node.trailingComments !== undefined
|
|
58
39
|
? node.trailingComments[node.trailingComments.length - 1].endOffset
|
|
59
40
|
: node.location.endOffset);
|
|
60
41
|
return this.prettierOptions.originalText.substring(startOffset, endOffset + 1);
|
|
@@ -64,14 +45,11 @@ var BaseCstPrettierPrinter = /** @class */ (function (_super) {
|
|
|
64
45
|
"\nThere might be a problem with prettier-ignore, please report an issue on https://github.com/jhipster/prettier-java/issues");
|
|
65
46
|
}
|
|
66
47
|
}
|
|
67
|
-
return
|
|
48
|
+
return printNodeWithComments(node, this.orgVisit.call(this, node, inParam));
|
|
68
49
|
};
|
|
69
|
-
|
|
70
|
-
|
|
50
|
+
this.visitSingle = function (ctx, params) {
|
|
51
|
+
const singleElement = this.getSingle(ctx);
|
|
71
52
|
return this.visit(singleElement, params);
|
|
72
53
|
};
|
|
73
|
-
return _this;
|
|
74
54
|
}
|
|
75
|
-
|
|
76
|
-
}(java_parser_1.BaseJavaCstVisitor));
|
|
77
|
-
exports.BaseCstPrettierPrinter = BaseCstPrettierPrinter;
|
|
55
|
+
}
|
package/dist/cst-printer.js
CHANGED
|
@@ -1,37 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var names_1 = require("./printers/names");
|
|
12
|
-
var types_values_and_variables_1 = require("./printers/types-values-and-variables");
|
|
13
|
-
var packages_and_modules_1 = require("./printers/packages-and-modules");
|
|
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";
|
|
14
11
|
// Mixins for the win
|
|
15
|
-
mixInMethods(
|
|
16
|
-
function mixInMethods() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
classesToMix.forEach(function (from) {
|
|
22
|
-
var fromMethodsNames = Object.getOwnPropertyNames(from.prototype);
|
|
23
|
-
var fromPureMethodsName = fromMethodsNames.filter(function (methodName) { return methodName !== "constructor"; });
|
|
24
|
-
fromPureMethodsName.forEach(function (methodName) {
|
|
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 => {
|
|
25
18
|
// @ts-ignore
|
|
26
|
-
|
|
19
|
+
BaseCstPrettierPrinter.prototype[methodName] = from.prototype[methodName];
|
|
27
20
|
});
|
|
28
21
|
});
|
|
29
22
|
}
|
|
30
|
-
|
|
23
|
+
const prettyPrinter = new BaseCstPrettierPrinter();
|
|
31
24
|
// TODO: do we need the "path" and "print" arguments passed by prettier
|
|
32
25
|
// see https://github.com/prettier/prettier/issues/5747
|
|
33
|
-
function createPrettierDoc(cstNode, options) {
|
|
26
|
+
export function createPrettierDoc(cstNode, options) {
|
|
34
27
|
prettyPrinter.prettierOptions = options;
|
|
35
28
|
return prettyPrinter.visit(cstNode);
|
|
36
29
|
}
|
|
37
|
-
exports.createPrettierDoc = createPrettierDoc;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var languages = [
|
|
1
|
+
import parse from "./parser.js";
|
|
2
|
+
import print from "./printer.js";
|
|
3
|
+
import options from "./options.js";
|
|
4
|
+
const languages = [
|
|
6
5
|
{
|
|
7
6
|
name: "Java",
|
|
8
7
|
parsers: ["java"],
|
|
@@ -25,20 +24,20 @@ function locEnd( /* node */) {
|
|
|
25
24
|
function hasPragma(text) {
|
|
26
25
|
return /^\/\*\*[\n][\t\s]+\*\s@(prettier|format)[\n][\t\s]+\*\//.test(text);
|
|
27
26
|
}
|
|
28
|
-
|
|
27
|
+
const parsers = {
|
|
29
28
|
java: {
|
|
30
|
-
parse
|
|
29
|
+
parse,
|
|
31
30
|
astFormat: "java",
|
|
32
|
-
locStart
|
|
33
|
-
locEnd
|
|
34
|
-
hasPragma
|
|
31
|
+
locStart,
|
|
32
|
+
locEnd,
|
|
33
|
+
hasPragma
|
|
35
34
|
}
|
|
36
35
|
};
|
|
37
36
|
function canAttachComment(node) {
|
|
38
37
|
return node.ast_type && node.ast_type !== "comment";
|
|
39
38
|
}
|
|
40
39
|
function printComment(commentPath) {
|
|
41
|
-
|
|
40
|
+
const comment = commentPath.getValue();
|
|
42
41
|
switch (comment.ast_type) {
|
|
43
42
|
case "comment":
|
|
44
43
|
return comment.value;
|
|
@@ -50,18 +49,18 @@ function clean(ast, newObj) {
|
|
|
50
49
|
delete newObj.lineno;
|
|
51
50
|
delete newObj.col_offset;
|
|
52
51
|
}
|
|
53
|
-
|
|
52
|
+
const printers = {
|
|
54
53
|
java: {
|
|
55
|
-
print
|
|
54
|
+
print,
|
|
56
55
|
// hasPrettierIgnore,
|
|
57
|
-
printComment
|
|
58
|
-
canAttachComment
|
|
56
|
+
printComment,
|
|
57
|
+
canAttachComment,
|
|
59
58
|
massageAstNode: clean
|
|
60
59
|
}
|
|
61
60
|
};
|
|
62
|
-
|
|
63
|
-
languages
|
|
64
|
-
printers
|
|
65
|
-
parsers
|
|
66
|
-
options
|
|
61
|
+
export default {
|
|
62
|
+
languages,
|
|
63
|
+
printers,
|
|
64
|
+
parsers,
|
|
65
|
+
options
|
|
67
66
|
};
|
package/dist/options.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = {
|
|
1
|
+
export default {
|
|
3
2
|
entrypoint: {
|
|
4
3
|
type: "choice",
|
|
5
4
|
category: "Global",
|
|
@@ -26,8 +25,6 @@ module.exports = {
|
|
|
26
25
|
{ value: "switchBlock" },
|
|
27
26
|
{ value: "switchBlockStatementGroup" },
|
|
28
27
|
{ value: "switchLabel" },
|
|
29
|
-
{ value: "caseOrDefaultLabel" },
|
|
30
|
-
{ value: "caseLabelElement" },
|
|
31
28
|
{ value: "switchRule" },
|
|
32
29
|
{ value: "caseConstant" },
|
|
33
30
|
{ value: "whileStatement" },
|
|
@@ -53,12 +50,8 @@ module.exports = {
|
|
|
53
50
|
{ value: "resourceSpecification" },
|
|
54
51
|
{ value: "resourceList" },
|
|
55
52
|
{ value: "resource" },
|
|
56
|
-
{ value: "resourceInit" },
|
|
57
53
|
{ value: "yieldStatement" },
|
|
58
54
|
{ value: "variableAccess" },
|
|
59
|
-
{ value: "isBasicForStatement" },
|
|
60
|
-
{ value: "isLocalVariableDeclaration" },
|
|
61
|
-
{ value: "isClassicSwitchLabel" },
|
|
62
55
|
{ value: "classDeclaration" },
|
|
63
56
|
{ value: "normalClassDeclaration" },
|
|
64
57
|
{ value: "classModifier" },
|
|
@@ -125,10 +118,7 @@ module.exports = {
|
|
|
125
118
|
{ value: "recordBody" },
|
|
126
119
|
{ value: "recordBodyDeclaration" },
|
|
127
120
|
{ value: "compactConstructorDeclaration" },
|
|
128
|
-
{ value: "isClassDeclaration" },
|
|
129
|
-
{ value: "identifyClassBodyDeclarationType" },
|
|
130
121
|
{ value: "isDims" },
|
|
131
|
-
{ value: "isCompactConstructorDeclaration" },
|
|
132
122
|
{ value: "expression" },
|
|
133
123
|
{ value: "lambdaExpression" },
|
|
134
124
|
{ value: "lambdaParameters" },
|
|
@@ -170,16 +160,18 @@ module.exports = {
|
|
|
170
160
|
{ value: "classLiteralSuffix" },
|
|
171
161
|
{ value: "arrayAccessSuffix" },
|
|
172
162
|
{ value: "methodReferenceSuffix" },
|
|
163
|
+
{ value: "templateArgument" },
|
|
164
|
+
{ value: "template" },
|
|
165
|
+
{ value: "stringTemplate" },
|
|
166
|
+
{ value: "textBlockTemplate" },
|
|
167
|
+
{ value: "embeddedExpression" },
|
|
173
168
|
{ value: "pattern" },
|
|
174
169
|
{ value: "typePattern" },
|
|
175
170
|
{ value: "recordPattern" },
|
|
176
|
-
{ value: "
|
|
171
|
+
{ value: "componentPatternList" },
|
|
172
|
+
{ value: "componentPattern" },
|
|
173
|
+
{ value: "unnamedPattern" },
|
|
177
174
|
{ value: "guard" },
|
|
178
|
-
{ value: "identifyNewExpressionType" },
|
|
179
|
-
{ value: "isLambdaExpression" },
|
|
180
|
-
{ value: "isCastExpression" },
|
|
181
|
-
{ value: "isPrimitiveCastExpression" },
|
|
182
|
-
{ value: "isReferenceTypeCastExpression" },
|
|
183
175
|
{ value: "isRefTypeInMethodRef" },
|
|
184
176
|
{ value: "interfaceDeclaration" },
|
|
185
177
|
{ value: "normalInterfaceDeclaration" },
|
|
@@ -204,9 +196,6 @@ module.exports = {
|
|
|
204
196
|
{ value: "elementValue" },
|
|
205
197
|
{ value: "elementValueArrayInitializer" },
|
|
206
198
|
{ value: "elementValueList" },
|
|
207
|
-
{ value: "identifyInterfaceBodyDeclarationType" },
|
|
208
|
-
{ value: "identifyAnnotationBodyDeclarationType" },
|
|
209
|
-
{ value: "isSimpleElementValueAnnotation" },
|
|
210
199
|
{ value: "literal" },
|
|
211
200
|
{ value: "integerLiteral" },
|
|
212
201
|
{ value: "floatingPointLiteral" },
|
|
@@ -233,7 +222,6 @@ module.exports = {
|
|
|
233
222
|
{ value: "usesModuleDirective" },
|
|
234
223
|
{ value: "providesModuleDirective" },
|
|
235
224
|
{ value: "requiresModifier" },
|
|
236
|
-
{ value: "isModuleCompilationUnit" },
|
|
237
225
|
{ value: "primitiveType" },
|
|
238
226
|
{ value: "numericType" },
|
|
239
227
|
{ value: "integralType" },
|
|
@@ -255,5 +243,12 @@ module.exports = {
|
|
|
255
243
|
{ value: "wildcardBounds" }
|
|
256
244
|
],
|
|
257
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."
|
|
258
253
|
}
|
|
259
254
|
};
|
package/dist/parser.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function parse(text, parsers, opts) {
|
|
1
|
+
import javaParser from "java-parser";
|
|
2
|
+
export default function parse(text, parsers, opts) {
|
|
4
3
|
return javaParser.parse(text, opts.entrypoint);
|
|
5
4
|
}
|
|
6
|
-
module.exports = parse;
|
package/dist/printer.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
var createPrettierDoc = require("./cst-printer").createPrettierDoc;
|
|
1
|
+
import { createPrettierDoc } from "./cst-printer.js";
|
|
3
2
|
// eslint-disable-next-line no-unused-vars
|
|
4
|
-
function genericPrint(path, options, print) {
|
|
5
|
-
|
|
3
|
+
export default function genericPrint(path, options, print) {
|
|
4
|
+
const node = path.getValue();
|
|
6
5
|
return createPrettierDoc(node, options);
|
|
7
6
|
}
|
|
8
|
-
module.exports = genericPrint;
|
package/dist/printers/arrays.js
CHANGED
|
@@ -1,49 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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.ArraysPrettierVisitor = void 0;
|
|
19
|
-
var printer_utils_1 = require("./printer-utils");
|
|
20
|
-
var doc_1 = require("prettier/doc");
|
|
21
|
-
var base_cst_printer_1 = require("../base-cst-printer");
|
|
22
|
-
var line = doc_1.builders.line;
|
|
23
|
-
var ArraysPrettierVisitor = /** @class */ (function (_super) {
|
|
24
|
-
__extends(ArraysPrettierVisitor, _super);
|
|
25
|
-
function ArraysPrettierVisitor() {
|
|
26
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
27
|
-
}
|
|
28
|
-
ArraysPrettierVisitor.prototype.arrayInitializer = function (ctx) {
|
|
29
|
-
var optionalVariableInitializerList = this.visit(ctx.variableInitializerList);
|
|
30
|
-
return (0, printer_utils_1.printArrayList)({
|
|
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({
|
|
31
9
|
list: optionalVariableInitializerList,
|
|
32
10
|
extraComma: ctx.Comma,
|
|
33
11
|
LCurly: ctx.LCurly[0],
|
|
34
12
|
RCurly: ctx.RCurly[0],
|
|
35
13
|
trailingComma: this.prettierOptions.trailingComma
|
|
36
14
|
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
? ctx.Comma.map(
|
|
42
|
-
return
|
|
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]);
|
|
43
21
|
})
|
|
44
22
|
: [];
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
|
49
|
-
exports.ArraysPrettierVisitor = ArraysPrettierVisitor;
|
|
23
|
+
return rejectAndJoinSeps(commas, variableInitializers);
|
|
24
|
+
}
|
|
25
|
+
}
|