NEW : REBASE THE ENTIRE WORKING PROJECT
This commit is contained in:
77
node_modules/prettier-plugin-java/dist/base-cst-printer.js
generated
vendored
Normal file
77
node_modules/prettier-plugin-java/dist/base-cst-printer.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BaseCstPrettierPrinter = void 0;
|
||||
var java_parser_1 = require("java-parser");
|
||||
var format_comments_1 = require("./printers/comments/format-comments");
|
||||
var BaseCstPrettierPrinter = /** @class */ (function (_super) {
|
||||
__extends(BaseCstPrettierPrinter, _super);
|
||||
function BaseCstPrettierPrinter() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.mapVisit = function (elements, params) {
|
||||
if (elements === undefined) {
|
||||
// TODO: can optimize this by returning an immutable empty array singleton.
|
||||
return [];
|
||||
}
|
||||
return elements.map(function (element) { return _this.visit(element, params); });
|
||||
};
|
||||
_this.getSingle = function (ctx) {
|
||||
var ctxKeys = Object.keys(ctx);
|
||||
if (ctxKeys.length !== 1) {
|
||||
throw Error("Expecting single key CST ctx but found: <" + ctxKeys.length + "> keys");
|
||||
}
|
||||
var singleElementKey = ctxKeys[0];
|
||||
var singleElementValues = ctx[singleElementKey];
|
||||
if ((singleElementValues === null || singleElementValues === void 0 ? void 0 : singleElementValues.length) !== 1) {
|
||||
throw Error("Expecting single item in CST ctx key but found: <" + (singleElementValues === null || singleElementValues === void 0 ? void 0 : singleElementValues.length) + "> items");
|
||||
}
|
||||
return singleElementValues[0];
|
||||
};
|
||||
// @ts-ignore
|
||||
_this.orgVisit = _this.visit;
|
||||
_this.visit = function (ctx, inParam) {
|
||||
if (ctx === undefined) {
|
||||
// empty Doc
|
||||
return "";
|
||||
}
|
||||
var node = Array.isArray(ctx) ? ctx[0] : ctx;
|
||||
if (node.ignore) {
|
||||
try {
|
||||
var startOffset = node.leadingComments !== undefined
|
||||
? node.leadingComments[0].startOffset
|
||||
: node.location.startOffset;
|
||||
var endOffset = (node.trailingComments !== undefined
|
||||
? node.trailingComments[node.trailingComments.length - 1].endOffset
|
||||
: node.location.endOffset);
|
||||
return this.prettierOptions.originalText.substring(startOffset, endOffset + 1);
|
||||
}
|
||||
catch (e) {
|
||||
throw Error(e +
|
||||
"\nThere might be a problem with prettier-ignore, please report an issue on https://github.com/jhipster/prettier-java/issues");
|
||||
}
|
||||
}
|
||||
return format_comments_1.printNodeWithComments(node, this.orgVisit.call(this, node, inParam));
|
||||
};
|
||||
_this.visitSingle = function (ctx, params) {
|
||||
var singleElement = this.getSingle(ctx);
|
||||
return this.visit(singleElement, params);
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
return BaseCstPrettierPrinter;
|
||||
}(java_parser_1.BaseJavaCstVisitor));
|
||||
exports.BaseCstPrettierPrinter = BaseCstPrettierPrinter;
|
37
node_modules/prettier-plugin-java/dist/cst-printer.js
generated
vendored
Normal file
37
node_modules/prettier-plugin-java/dist/cst-printer.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createPrettierDoc = void 0;
|
||||
var base_cst_printer_1 = require("./base-cst-printer");
|
||||
var arrays_1 = require("./printers/arrays");
|
||||
var blocks_and_statements_1 = require("./printers/blocks-and-statements");
|
||||
var classes_1 = require("./printers/classes");
|
||||
var expressions_1 = require("./printers/expressions");
|
||||
var interfaces_1 = require("./printers/interfaces");
|
||||
var lexical_structure_1 = require("./printers/lexical-structure");
|
||||
var names_1 = require("./printers/names");
|
||||
var types_values_and_variables_1 = require("./printers/types-values-and-variables");
|
||||
var packages_and_modules_1 = require("./printers/packages-and-modules");
|
||||
// Mixins for the win
|
||||
mixInMethods(arrays_1.ArraysPrettierVisitor, blocks_and_statements_1.BlocksAndStatementPrettierVisitor, classes_1.ClassesPrettierVisitor, expressions_1.ExpressionsPrettierVisitor, interfaces_1.InterfacesPrettierVisitor, lexical_structure_1.LexicalStructurePrettierVisitor, names_1.NamesPrettierVisitor, types_values_and_variables_1.TypesValuesAndVariablesPrettierVisitor, packages_and_modules_1.PackagesAndModulesPrettierVisitor);
|
||||
function mixInMethods() {
|
||||
var classesToMix = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
classesToMix[_i] = arguments[_i];
|
||||
}
|
||||
classesToMix.forEach(function (from) {
|
||||
var fromMethodsNames = Object.getOwnPropertyNames(from.prototype);
|
||||
var fromPureMethodsName = fromMethodsNames.filter(function (methodName) { return methodName !== "constructor"; });
|
||||
fromPureMethodsName.forEach(function (methodName) {
|
||||
// @ts-ignore
|
||||
base_cst_printer_1.BaseCstPrettierPrinter.prototype[methodName] = from.prototype[methodName];
|
||||
});
|
||||
});
|
||||
}
|
||||
var prettyPrinter = new base_cst_printer_1.BaseCstPrettierPrinter();
|
||||
// TODO: do we need the "path" and "print" arguments passed by prettier
|
||||
// see https://github.com/prettier/prettier/issues/5747
|
||||
function createPrettierDoc(cstNode, options) {
|
||||
prettyPrinter.prettierOptions = options;
|
||||
return prettyPrinter.visit(cstNode);
|
||||
}
|
||||
exports.createPrettierDoc = createPrettierDoc;
|
67
node_modules/prettier-plugin-java/dist/index.js
generated
vendored
Normal file
67
node_modules/prettier-plugin-java/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
var parse = require("./parser");
|
||||
var print = require("./printer");
|
||||
var options = require("./options");
|
||||
var languages = [
|
||||
{
|
||||
name: "Java",
|
||||
parsers: ["java"],
|
||||
group: "Java",
|
||||
tmScope: "text.html.vue",
|
||||
aceMode: "html",
|
||||
codemirrorMode: "clike",
|
||||
codemirrorMimeType: "text/x-java",
|
||||
extensions: [".java"],
|
||||
linguistLanguageId: 181,
|
||||
vscodeLanguageIds: ["java"]
|
||||
}
|
||||
];
|
||||
function locStart( /* node */) {
|
||||
return -1;
|
||||
}
|
||||
function locEnd( /* node */) {
|
||||
return -1;
|
||||
}
|
||||
function hasPragma( /* text */) {
|
||||
return false;
|
||||
}
|
||||
var parsers = {
|
||||
java: {
|
||||
parse: parse,
|
||||
astFormat: "java",
|
||||
locStart: locStart,
|
||||
locEnd: locEnd,
|
||||
hasPragma: hasPragma
|
||||
}
|
||||
};
|
||||
function canAttachComment(node) {
|
||||
return node.ast_type && node.ast_type !== "comment";
|
||||
}
|
||||
function printComment(commentPath) {
|
||||
var comment = commentPath.getValue();
|
||||
switch (comment.ast_type) {
|
||||
case "comment":
|
||||
return comment.value;
|
||||
default:
|
||||
throw new Error("Not a comment: " + JSON.stringify(comment));
|
||||
}
|
||||
}
|
||||
function clean(ast, newObj) {
|
||||
delete newObj.lineno;
|
||||
delete newObj.col_offset;
|
||||
}
|
||||
var printers = {
|
||||
java: {
|
||||
print: print,
|
||||
// hasPrettierIgnore,
|
||||
printComment: printComment,
|
||||
canAttachComment: canAttachComment,
|
||||
massageAstNode: clean
|
||||
}
|
||||
};
|
||||
module.exports = {
|
||||
languages: languages,
|
||||
printers: printers,
|
||||
parsers: parsers,
|
||||
options: options
|
||||
};
|
256
node_modules/prettier-plugin-java/dist/options.js
generated
vendored
Normal file
256
node_modules/prettier-plugin-java/dist/options.js
generated
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
"use strict";
|
||||
module.exports = {
|
||||
entrypoint: {
|
||||
type: "choice",
|
||||
category: "Global",
|
||||
default: "compilationUnit",
|
||||
// sed -nr 's/.*\.RULE\(([^,]+),.*/\1/p' $(ls path/to/java-parser/rules/folder/*)
|
||||
choices: [
|
||||
{ value: "arrayInitializer" },
|
||||
{ value: "variableInitializerList" },
|
||||
{ value: "block" },
|
||||
{ value: "blockStatements" },
|
||||
{ value: "blockStatement" },
|
||||
{ value: "localVariableDeclarationStatement" },
|
||||
{ value: "localVariableDeclaration" },
|
||||
{ value: "localVariableType" },
|
||||
{ value: "statement" },
|
||||
{ value: "statementWithoutTrailingSubstatement" },
|
||||
{ value: "emptyStatement" },
|
||||
{ value: "labeledStatement" },
|
||||
{ value: "expressionStatement" },
|
||||
{ value: "statementExpression" },
|
||||
{ value: "ifStatement" },
|
||||
{ value: "assertStatement" },
|
||||
{ value: "switchStatement" },
|
||||
{ value: "switchBlock" },
|
||||
{ value: "switchBlockStatementGroup" },
|
||||
{ value: "switchLabel" },
|
||||
{ value: "caseOrDefaultLabel" },
|
||||
{ value: "caseLabelElement" },
|
||||
{ value: "switchRule" },
|
||||
{ value: "caseConstant" },
|
||||
{ value: "whileStatement" },
|
||||
{ value: "doStatement" },
|
||||
{ value: "forStatement" },
|
||||
{ value: "basicForStatement" },
|
||||
{ value: "forInit" },
|
||||
{ value: "forUpdate" },
|
||||
{ value: "statementExpressionList" },
|
||||
{ value: "enhancedForStatement" },
|
||||
{ value: "breakStatement" },
|
||||
{ value: "continueStatement" },
|
||||
{ value: "returnStatement" },
|
||||
{ value: "throwStatement" },
|
||||
{ value: "synchronizedStatement" },
|
||||
{ value: "tryStatement" },
|
||||
{ value: "catches" },
|
||||
{ value: "catchClause" },
|
||||
{ value: "catchFormalParameter" },
|
||||
{ value: "catchType" },
|
||||
{ value: "finally" },
|
||||
{ value: "tryWithResourcesStatement" },
|
||||
{ value: "resourceSpecification" },
|
||||
{ value: "resourceList" },
|
||||
{ value: "resource" },
|
||||
{ value: "resourceInit" },
|
||||
{ value: "yieldStatement" },
|
||||
{ value: "variableAccess" },
|
||||
{ value: "isBasicForStatement" },
|
||||
{ value: "isLocalVariableDeclaration" },
|
||||
{ value: "isClassicSwitchLabel" },
|
||||
{ value: "classDeclaration" },
|
||||
{ value: "normalClassDeclaration" },
|
||||
{ value: "classModifier" },
|
||||
{ value: "typeParameters" },
|
||||
{ value: "typeParameterList" },
|
||||
{ value: "superclass" },
|
||||
{ value: "superinterfaces" },
|
||||
{ value: "interfaceTypeList" },
|
||||
{ value: "classPermits" },
|
||||
{ value: "classBody" },
|
||||
{ value: "classBodyDeclaration" },
|
||||
{ value: "classMemberDeclaration" },
|
||||
{ value: "fieldDeclaration" },
|
||||
{ value: "fieldModifier" },
|
||||
{ value: "variableDeclaratorList" },
|
||||
{ value: "variableDeclarator" },
|
||||
{ value: "variableDeclaratorId" },
|
||||
{ value: "variableInitializer" },
|
||||
{ value: "unannType" },
|
||||
{ value: "unannPrimitiveTypeWithOptionalDimsSuffix" },
|
||||
{ value: "unannPrimitiveType" },
|
||||
{ value: "unannReferenceType" },
|
||||
{ value: "unannClassOrInterfaceType" },
|
||||
{ value: "unannClassType" },
|
||||
{ value: "unannInterfaceType" },
|
||||
{ value: "unannTypeVariable" },
|
||||
{ value: "methodDeclaration" },
|
||||
{ value: "methodModifier" },
|
||||
{ value: "methodHeader" },
|
||||
{ value: "result" },
|
||||
{ value: "methodDeclarator" },
|
||||
{ value: "receiverParameter" },
|
||||
{ value: "formalParameterList" },
|
||||
{ value: "formalParameter" },
|
||||
{ value: "variableParaRegularParameter" },
|
||||
{ value: "variableArityParameter" },
|
||||
{ value: "variableModifier" },
|
||||
{ value: "throws" },
|
||||
{ value: "exceptionTypeList" },
|
||||
{ value: "exceptionType" },
|
||||
{ value: "methodBody" },
|
||||
{ value: "instanceInitializer" },
|
||||
{ value: "staticInitializer" },
|
||||
{ value: "constructorDeclaration" },
|
||||
{ value: "constructorModifier" },
|
||||
{ value: "constructorDeclarator" },
|
||||
{ value: "simpleTypeName" },
|
||||
{ value: "constructorBody" },
|
||||
{ value: "explicitConstructorInvocation" },
|
||||
{ value: "unqualifiedExplicitConstructorInvocation" },
|
||||
{ value: "qualifiedExplicitConstructorInvocation" },
|
||||
{ value: "enumDeclaration" },
|
||||
{ value: "enumBody" },
|
||||
{ value: "enumConstantList" },
|
||||
{ value: "enumConstant" },
|
||||
{ value: "enumConstantModifier" },
|
||||
{ value: "enumBodyDeclarations" },
|
||||
{ value: "recordDeclaration" },
|
||||
{ value: "recordHeader" },
|
||||
{ value: "recordComponentList" },
|
||||
{ value: "recordComponent" },
|
||||
{ value: "variableArityRecordComponent" },
|
||||
{ value: "recordComponentModifier" },
|
||||
{ value: "recordBody" },
|
||||
{ value: "recordBodyDeclaration" },
|
||||
{ value: "compactConstructorDeclaration" },
|
||||
{ value: "isClassDeclaration" },
|
||||
{ value: "identifyClassBodyDeclarationType" },
|
||||
{ value: "isDims" },
|
||||
{ value: "isCompactConstructorDeclaration" },
|
||||
{ value: "expression" },
|
||||
{ value: "lambdaExpression" },
|
||||
{ value: "lambdaParameters" },
|
||||
{ value: "lambdaParametersWithBraces" },
|
||||
{ value: "lambdaParameterList" },
|
||||
{ value: "inferredLambdaParameterList" },
|
||||
{ value: "explicitLambdaParameterList" },
|
||||
{ value: "lambdaParameter" },
|
||||
{ value: "regularLambdaParameter" },
|
||||
{ value: "lambdaParameterType" },
|
||||
{ value: "lambdaBody" },
|
||||
{ value: "ternaryExpression" },
|
||||
{ value: "binaryExpression" },
|
||||
{ value: "unaryExpression" },
|
||||
{ value: "unaryExpressionNotPlusMinus" },
|
||||
{ value: "primary" },
|
||||
{ value: "primaryPrefix" },
|
||||
{ value: "primarySuffix" },
|
||||
{ value: "fqnOrRefType" },
|
||||
{ value: "fqnOrRefTypePartRest" },
|
||||
{ value: "fqnOrRefTypePartCommon" },
|
||||
{ value: "fqnOrRefTypePartFirst" },
|
||||
{ value: "parenthesisExpression" },
|
||||
{ value: "castExpression" },
|
||||
{ value: "primitiveCastExpression" },
|
||||
{ value: "referenceTypeCastExpression" },
|
||||
{ value: "newExpression" },
|
||||
{ value: "unqualifiedClassInstanceCreationExpression" },
|
||||
{ value: "classOrInterfaceTypeToInstantiate" },
|
||||
{ value: "typeArgumentsOrDiamond" },
|
||||
{ value: "diamond" },
|
||||
{ value: "methodInvocationSuffix" },
|
||||
{ value: "argumentList" },
|
||||
{ value: "arrayCreationExpression" },
|
||||
{ value: "arrayCreationDefaultInitSuffix" },
|
||||
{ value: "arrayCreationExplicitInitSuffix" },
|
||||
{ value: "dimExprs" },
|
||||
{ value: "dimExpr" },
|
||||
{ value: "classLiteralSuffix" },
|
||||
{ value: "arrayAccessSuffix" },
|
||||
{ value: "methodReferenceSuffix" },
|
||||
{ value: "pattern" },
|
||||
{ value: "typePattern" },
|
||||
{ value: "identifyNewExpressionType" },
|
||||
{ value: "isLambdaExpression" },
|
||||
{ value: "isCastExpression" },
|
||||
{ value: "isPrimitiveCastExpression" },
|
||||
{ value: "isReferenceTypeCastExpression" },
|
||||
{ value: "isRefTypeInMethodRef" },
|
||||
{ value: "interfaceDeclaration" },
|
||||
{ value: "normalInterfaceDeclaration" },
|
||||
{ value: "interfaceModifier" },
|
||||
{ value: "extendsInterfaces" },
|
||||
{ value: "interfacePermits" },
|
||||
{ value: "interfaceBody" },
|
||||
{ value: "interfaceMemberDeclaration" },
|
||||
{ value: "constantDeclaration" },
|
||||
{ value: "constantModifier" },
|
||||
{ value: "interfaceMethodDeclaration" },
|
||||
{ value: "interfaceMethodModifier" },
|
||||
{ value: "annotationTypeDeclaration" },
|
||||
{ value: "annotationTypeBody" },
|
||||
{ value: "annotationTypeMemberDeclaration" },
|
||||
{ value: "annotationTypeElementDeclaration" },
|
||||
{ value: "annotationTypeElementModifier" },
|
||||
{ value: "defaultValue" },
|
||||
{ value: "annotation" },
|
||||
{ value: "elementValuePairList" },
|
||||
{ value: "elementValuePair" },
|
||||
{ value: "elementValue" },
|
||||
{ value: "elementValueArrayInitializer" },
|
||||
{ value: "elementValueList" },
|
||||
{ value: "identifyInterfaceBodyDeclarationType" },
|
||||
{ value: "identifyAnnotationBodyDeclarationType" },
|
||||
{ value: "isSimpleElementValueAnnotation" },
|
||||
{ value: "literal" },
|
||||
{ value: "integerLiteral" },
|
||||
{ value: "floatingPointLiteral" },
|
||||
{ value: "booleanLiteral" },
|
||||
{ value: "moduleName" },
|
||||
{ value: "packageName" },
|
||||
{ value: "typeName" },
|
||||
{ value: "expressionName" },
|
||||
{ value: "methodName" },
|
||||
{ value: "packageOrTypeName" },
|
||||
{ value: "ambiguousName" },
|
||||
{ value: "compilationUnit" },
|
||||
{ value: "ordinaryCompilationUnit" },
|
||||
{ value: "modularCompilationUnit" },
|
||||
{ value: "packageDeclaration" },
|
||||
{ value: "packageModifier" },
|
||||
{ value: "importDeclaration" },
|
||||
{ value: "typeDeclaration" },
|
||||
{ value: "moduleDeclaration" },
|
||||
{ value: "moduleDirective" },
|
||||
{ value: "requiresModuleDirective" },
|
||||
{ value: "exportsModuleDirective" },
|
||||
{ value: "opensModuleDirective" },
|
||||
{ value: "usesModuleDirective" },
|
||||
{ value: "providesModuleDirective" },
|
||||
{ value: "requiresModifier" },
|
||||
{ value: "isModuleCompilationUnit" },
|
||||
{ value: "primitiveType" },
|
||||
{ value: "numericType" },
|
||||
{ value: "integralType" },
|
||||
{ value: "floatingPointType" },
|
||||
{ value: "referenceType" },
|
||||
{ value: "classOrInterfaceType" },
|
||||
{ value: "classType" },
|
||||
{ value: "interfaceType" },
|
||||
{ value: "typeVariable" },
|
||||
{ value: "dims" },
|
||||
{ value: "typeParameter" },
|
||||
{ value: "typeParameterModifier" },
|
||||
{ value: "typeBound" },
|
||||
{ value: "additionalBound" },
|
||||
{ value: "typeArguments" },
|
||||
{ value: "typeArgumentList" },
|
||||
{ value: "typeArgument" },
|
||||
{ value: "wildcard" },
|
||||
{ value: "wildcardBounds" }
|
||||
],
|
||||
description: "Prettify from the entrypoint, allowing to use prettier on snippet."
|
||||
}
|
||||
};
|
7
node_modules/prettier-plugin-java/dist/parser.js
generated
vendored
Normal file
7
node_modules/prettier-plugin-java/dist/parser.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
var javaParser = require("java-parser");
|
||||
function parse(text, parsers, opts) {
|
||||
var cst = javaParser.parse(text, opts.entrypoint);
|
||||
return cst;
|
||||
}
|
||||
module.exports = parse;
|
28
node_modules/prettier-plugin-java/dist/printer.js
generated
vendored
Normal file
28
node_modules/prettier-plugin-java/dist/printer.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
var createPrettierDoc = require("./cst-printer").createPrettierDoc;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function genericPrint(path, options, print) {
|
||||
var node = path.getValue();
|
||||
// console.log(node);
|
||||
// if (node.comments) {
|
||||
// console.log(node.type, node.comments);
|
||||
// }
|
||||
// node["comments"] = [
|
||||
// {
|
||||
// ast_type: "comment",
|
||||
// value: "// a",
|
||||
// leading: false,
|
||||
// trailing: true,
|
||||
// printed: false
|
||||
// },
|
||||
// {
|
||||
// ast_type: "comment",
|
||||
// value: "// b",
|
||||
// leading: true,
|
||||
// trailing: false,
|
||||
// printed: false
|
||||
// }
|
||||
// ];
|
||||
return createPrettierDoc(node, options);
|
||||
}
|
||||
module.exports = genericPrint;
|
49
node_modules/prettier-plugin-java/dist/printers/arrays.js
generated
vendored
Normal file
49
node_modules/prettier-plugin-java/dist/printers/arrays.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArraysPrettierVisitor = void 0;
|
||||
var printer_utils_1 = require("./printer-utils");
|
||||
var doc_1 = require("prettier/doc");
|
||||
var base_cst_printer_1 = require("../base-cst-printer");
|
||||
var line = doc_1.builders.line;
|
||||
var ArraysPrettierVisitor = /** @class */ (function (_super) {
|
||||
__extends(ArraysPrettierVisitor, _super);
|
||||
function ArraysPrettierVisitor() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
ArraysPrettierVisitor.prototype.arrayInitializer = function (ctx) {
|
||||
var optionalVariableInitializerList = this.visit(ctx.variableInitializerList);
|
||||
return printer_utils_1.printArrayList({
|
||||
list: optionalVariableInitializerList,
|
||||
extraComma: ctx.Comma,
|
||||
LCurly: ctx.LCurly[0],
|
||||
RCurly: ctx.RCurly[0],
|
||||
trailingComma: this.prettierOptions.trailingComma
|
||||
});
|
||||
};
|
||||
ArraysPrettierVisitor.prototype.variableInitializerList = function (ctx) {
|
||||
var variableInitializers = this.mapVisit(ctx.variableInitializer);
|
||||
var commas = ctx.Comma
|
||||
? ctx.Comma.map(function (comma) {
|
||||
return printer_utils_1.rejectAndConcat([comma, line]);
|
||||
})
|
||||
: [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, variableInitializers);
|
||||
};
|
||||
return ArraysPrettierVisitor;
|
||||
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
||||
exports.ArraysPrettierVisitor = ArraysPrettierVisitor;
|
493
node_modules/prettier-plugin-java/dist/printers/blocks-and-statements.js
generated
vendored
Normal file
493
node_modules/prettier-plugin-java/dist/printers/blocks-and-statements.js
generated
vendored
Normal file
@@ -0,0 +1,493 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
||||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
||||
to[j] = from[i];
|
||||
return to;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BlocksAndStatementPrettierVisitor = void 0;
|
||||
var doc_1 = require("prettier/doc");
|
||||
var prettier_builder_1 = require("./prettier-builder");
|
||||
var format_comments_1 = require("./comments/format-comments");
|
||||
var comments_utils_1 = require("./comments/comments-utils");
|
||||
var printer_utils_1 = require("./printer-utils");
|
||||
var base_cst_printer_1 = require("../base-cst-printer");
|
||||
var line = doc_1.builders.line, softline = doc_1.builders.softline, hardline = doc_1.builders.hardline;
|
||||
var BlocksAndStatementPrettierVisitor = /** @class */ (function (_super) {
|
||||
__extends(BlocksAndStatementPrettierVisitor, _super);
|
||||
function BlocksAndStatementPrettierVisitor() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
BlocksAndStatementPrettierVisitor.prototype.block = function (ctx) {
|
||||
var blockStatements = this.visit(ctx.blockStatements);
|
||||
return printer_utils_1.putIntoBraces(blockStatements, hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.blockStatements = function (ctx) {
|
||||
var blockStatement = this.mapVisit(ctx.blockStatement);
|
||||
var separators = printer_utils_1.rejectSeparators(printer_utils_1.getBlankLinesSeparator(ctx.blockStatement), blockStatement);
|
||||
return printer_utils_1.rejectAndJoinSeps(separators, blockStatement);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.blockStatement = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.localVariableDeclarationStatement = function (ctx) {
|
||||
var localVariableDeclaration = this.visit(ctx.localVariableDeclaration);
|
||||
return printer_utils_1.rejectAndConcat([localVariableDeclaration, ctx.Semicolon[0]]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.localVariableDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.variableModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var finalModifiers = this.mapVisit(modifiers[1]);
|
||||
var localVariableType = this.visit(ctx.localVariableType);
|
||||
var variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", finalModifiers),
|
||||
localVariableType,
|
||||
variableDeclaratorList
|
||||
])
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.localVariableType = function (ctx) {
|
||||
if (ctx.unannType) {
|
||||
return this.visitSingle(ctx);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.statement = function (ctx, params) {
|
||||
// handling Labeled statements comments
|
||||
if (ctx.labeledStatement !== undefined) {
|
||||
var newLabelStatement = __assign({}, ctx.labeledStatement[0]);
|
||||
var newColon = __assign({}, ctx.labeledStatement[0].children.Colon[0]);
|
||||
var newStatement = __assign({}, ctx.labeledStatement[0].children.statement[0]);
|
||||
var labeledStatementLeadingComments = [];
|
||||
if (newColon.trailingComments !== undefined) {
|
||||
labeledStatementLeadingComments.push.apply(labeledStatementLeadingComments, newColon.trailingComments);
|
||||
delete newColon.trailingComments;
|
||||
}
|
||||
if (newStatement.leadingComments !== undefined) {
|
||||
labeledStatementLeadingComments.push.apply(labeledStatementLeadingComments, newStatement.leadingComments);
|
||||
delete newStatement.leadingComments;
|
||||
}
|
||||
if (labeledStatementLeadingComments.length !== 0) {
|
||||
newLabelStatement.leadingComments = labeledStatementLeadingComments;
|
||||
}
|
||||
newLabelStatement.children.Colon[0] = newColon;
|
||||
newLabelStatement.children.statement[0] = newStatement;
|
||||
return this.visit([newLabelStatement]);
|
||||
}
|
||||
return this.visitSingle(ctx, params);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.statementWithoutTrailingSubstatement = function (ctx, params) {
|
||||
return this.visitSingle(ctx, params);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.emptyStatement = function (ctx, params) {
|
||||
return printer_utils_1.displaySemicolon(ctx.Semicolon[0], params);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.labeledStatement = function (ctx) {
|
||||
var identifier = ctx.Identifier[0];
|
||||
var statement = this.visit(ctx.statement);
|
||||
return printer_utils_1.rejectAndJoin(ctx.Colon[0], [identifier, statement]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.expressionStatement = function (ctx) {
|
||||
var statementExpression = this.visit(ctx.statementExpression);
|
||||
return printer_utils_1.rejectAndConcat([statementExpression, ctx.Semicolon[0]]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.statementExpression = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.ifStatement = function (ctx) {
|
||||
var expression = this.visit(ctx.expression);
|
||||
var ifStatement = this.visit(ctx.statement[0], {
|
||||
allowEmptyStatement: true
|
||||
});
|
||||
var ifSeparator = printer_utils_1.isStatementEmptyStatement(ifStatement) ? "" : " ";
|
||||
var elsePart = "";
|
||||
if (ctx.Else !== undefined) {
|
||||
var elseStatement = this.visit(ctx.statement[1], {
|
||||
allowEmptyStatement: true
|
||||
});
|
||||
var elseSeparator = printer_utils_1.isStatementEmptyStatement(elseStatement) ? "" : " ";
|
||||
var elseOnSameLine = comments_utils_1.hasTrailingLineComments(ctx.statement[0]) ||
|
||||
comments_utils_1.hasLeadingLineComments(ctx.Else[0])
|
||||
? hardline
|
||||
: " ";
|
||||
elsePart = printer_utils_1.rejectAndJoin(elseSeparator, [
|
||||
prettier_builder_1.concat([elseOnSameLine, ctx.Else[0]]),
|
||||
elseStatement
|
||||
]);
|
||||
}
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.If[0],
|
||||
prettier_builder_1.concat([
|
||||
printer_utils_1.putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
|
||||
ifSeparator
|
||||
])
|
||||
]),
|
||||
ifStatement,
|
||||
elsePart
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.assertStatement = function (ctx) {
|
||||
var expressions = this.mapVisit(ctx.expression);
|
||||
var colon = ctx.Colon ? ctx.Colon[0] : ":";
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.concat([ctx.Assert[0], " "]),
|
||||
printer_utils_1.rejectAndJoin(prettier_builder_1.concat([" ", colon, " "]), expressions),
|
||||
ctx.Semicolon[0]
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.switchStatement = function (ctx) {
|
||||
var expression = this.visit(ctx.expression);
|
||||
var switchBlock = this.visit(ctx.switchBlock);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.Switch[0],
|
||||
printer_utils_1.putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
|
||||
switchBlock
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.switchBlock = function (ctx) {
|
||||
var switchCases = ctx.switchBlockStatementGroup !== undefined
|
||||
? this.mapVisit(ctx.switchBlockStatementGroup)
|
||||
: this.mapVisit(ctx.switchRule);
|
||||
return printer_utils_1.putIntoBraces(printer_utils_1.rejectAndJoin(hardline, switchCases), hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.switchBlockStatementGroup = function (ctx) {
|
||||
var switchLabel = this.visit(ctx.switchLabel);
|
||||
var blockStatements = this.visit(ctx.blockStatements);
|
||||
return prettier_builder_1.concat([
|
||||
switchLabel,
|
||||
ctx.Colon[0],
|
||||
blockStatements && prettier_builder_1.indent([hardline, blockStatements])
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.switchLabel = function (ctx) {
|
||||
var caseOrDefaultLabels = this.mapVisit(ctx.caseOrDefaultLabel);
|
||||
var colons = ctx.Colon
|
||||
? ctx.Colon.map(function (elt) {
|
||||
return prettier_builder_1.concat([elt, hardline]);
|
||||
})
|
||||
: [];
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(colons, caseOrDefaultLabels));
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.caseOrDefaultLabel = function (ctx) {
|
||||
if (ctx.Case) {
|
||||
var caseLabelElements = this.mapVisit(ctx.caseLabelElement);
|
||||
var commas = ctx.Comma
|
||||
? ctx.Comma.map(function (elt) {
|
||||
return prettier_builder_1.concat([elt, line]);
|
||||
})
|
||||
: [];
|
||||
return prettier_builder_1.group(prettier_builder_1.indent(printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.concat([ctx.Case[0], " "]),
|
||||
printer_utils_1.rejectAndJoinSeps(commas, caseLabelElements)
|
||||
])));
|
||||
}
|
||||
return prettier_builder_1.concat([ctx.Default[0]]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.caseLabelElement = function (ctx) {
|
||||
if (ctx.Default || ctx.Null) {
|
||||
return this.getSingle(ctx);
|
||||
}
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.switchRule = function (ctx) {
|
||||
var switchLabel = this.visit(ctx.switchLabel);
|
||||
var caseInstruction;
|
||||
if (ctx.throwStatement !== undefined) {
|
||||
caseInstruction = this.visit(ctx.throwStatement);
|
||||
}
|
||||
else if (ctx.block !== undefined) {
|
||||
caseInstruction = this.visit(ctx.block);
|
||||
}
|
||||
else {
|
||||
caseInstruction = prettier_builder_1.concat([this.visit(ctx.expression), ctx.Semicolon[0]]);
|
||||
}
|
||||
return prettier_builder_1.join(" ", [switchLabel, ctx.Arrow[0], caseInstruction]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.caseConstant = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.whileStatement = function (ctx) {
|
||||
var expression = this.visit(ctx.expression);
|
||||
var statement = this.visit(ctx.statement[0], {
|
||||
allowEmptyStatement: true
|
||||
});
|
||||
var statementSeparator = printer_utils_1.isStatementEmptyStatement(statement) ? "" : " ";
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.While[0],
|
||||
printer_utils_1.rejectAndJoin(statementSeparator, [
|
||||
printer_utils_1.putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
|
||||
statement
|
||||
])
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.doStatement = function (ctx) {
|
||||
var statement = this.visit(ctx.statement[0], {
|
||||
allowEmptyStatement: true
|
||||
});
|
||||
var statementSeparator = printer_utils_1.isStatementEmptyStatement(statement) ? "" : " ";
|
||||
var expression = this.visit(ctx.expression);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(statementSeparator, [ctx.Do[0], statement]),
|
||||
ctx.While[0],
|
||||
printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
|
||||
ctx.Semicolon[0]
|
||||
])
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.forStatement = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.basicForStatement = function (ctx) {
|
||||
var forInit = this.visit(ctx.forInit);
|
||||
var expression = this.visit(ctx.expression);
|
||||
var forUpdate = this.visit(ctx.forUpdate);
|
||||
var statement = this.visit(ctx.statement[0], {
|
||||
allowEmptyStatement: true
|
||||
});
|
||||
var statementSeparator = printer_utils_1.isStatementEmptyStatement(statement) ? "" : " ";
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.For[0],
|
||||
printer_utils_1.putIntoBraces(printer_utils_1.rejectAndConcat([
|
||||
forInit,
|
||||
printer_utils_1.rejectAndJoin(line, [ctx.Semicolon[0], expression]),
|
||||
printer_utils_1.rejectAndJoin(line, [ctx.Semicolon[1], forUpdate])
|
||||
]), softline, ctx.LBrace[0], ctx.RBrace[0])
|
||||
]),
|
||||
statementSeparator,
|
||||
statement
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.forInit = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.forUpdate = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.statementExpressionList = function (ctx) {
|
||||
var statementExpressions = this.mapVisit(ctx.statementExpression);
|
||||
var commas = ctx.Comma
|
||||
? ctx.Comma.map(function (elt) {
|
||||
return prettier_builder_1.concat([format_comments_1.printTokenWithComments(elt), " "]);
|
||||
})
|
||||
: [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, statementExpressions);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.enhancedForStatement = function (ctx) {
|
||||
var variableModifiers = this.mapVisit(ctx.variableModifier);
|
||||
var localVariableType = this.visit(ctx.localVariableType);
|
||||
var variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
|
||||
var expression = this.visit(ctx.expression);
|
||||
var statement = this.visit(ctx.statement[0], {
|
||||
allowEmptyStatement: true
|
||||
});
|
||||
var statementSeparator = printer_utils_1.isStatementEmptyStatement(statement) ? "" : " ";
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(" ", [ctx.For[0], ctx.LBrace[0]]),
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", variableModifiers),
|
||||
localVariableType,
|
||||
variableDeclaratorId
|
||||
]),
|
||||
prettier_builder_1.concat([" ", ctx.Colon[0], " "]),
|
||||
expression,
|
||||
prettier_builder_1.concat([ctx.RBrace[0], statementSeparator]),
|
||||
statement
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.breakStatement = function (ctx) {
|
||||
if (ctx.Identifier) {
|
||||
var identifier = ctx.Identifier[0];
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.concat([ctx.Break[0], " "]),
|
||||
identifier,
|
||||
ctx.Semicolon[0]
|
||||
]);
|
||||
}
|
||||
return prettier_builder_1.concat([ctx.Break[0], ctx.Semicolon[0]]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.continueStatement = function (ctx) {
|
||||
if (ctx.Identifier) {
|
||||
var identifier = ctx.Identifier[0];
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.concat([ctx.Continue[0], " "]),
|
||||
identifier,
|
||||
ctx.Semicolon[0]
|
||||
]);
|
||||
}
|
||||
return printer_utils_1.rejectAndConcat([ctx.Continue[0], ctx.Semicolon[0]]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.returnStatement = function (ctx) {
|
||||
if (ctx.expression) {
|
||||
var expression = this.visit(ctx.expression, {
|
||||
addParenthesisToWrapStatement: true
|
||||
});
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.concat([ctx.Return[0], " "]),
|
||||
expression,
|
||||
ctx.Semicolon[0]
|
||||
]);
|
||||
}
|
||||
return printer_utils_1.rejectAndConcat([ctx.Return[0], ctx.Semicolon[0]]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.throwStatement = function (ctx) {
|
||||
var expression = this.visit(ctx.expression);
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.concat([ctx.Throw[0], " "]),
|
||||
expression,
|
||||
ctx.Semicolon[0]
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.synchronizedStatement = function (ctx) {
|
||||
var expression = this.visit(ctx.expression);
|
||||
var block = this.visit(ctx.block);
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.join(" ", [
|
||||
ctx.Synchronized[0],
|
||||
prettier_builder_1.concat([
|
||||
printer_utils_1.putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]),
|
||||
" "
|
||||
])
|
||||
]),
|
||||
block
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.tryStatement = function (ctx) {
|
||||
if (ctx.tryWithResourcesStatement) {
|
||||
return this.visit(ctx.tryWithResourcesStatement);
|
||||
}
|
||||
var block = this.visit(ctx.block);
|
||||
var catches = this.visit(ctx.catches);
|
||||
var finallyBlock = this.visit(ctx.finally);
|
||||
return printer_utils_1.rejectAndJoin(" ", [ctx.Try[0], block, catches, finallyBlock]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.catches = function (ctx) {
|
||||
var catchClauses = this.mapVisit(ctx.catchClause);
|
||||
return printer_utils_1.rejectAndJoin(" ", catchClauses);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.catchClause = function (ctx) {
|
||||
var catchFormalParameter = this.visit(ctx.catchFormalParameter);
|
||||
var block = this.visit(ctx.block);
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.group(printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(" ", [ctx.Catch[0], ctx.LBrace[0]]),
|
||||
prettier_builder_1.indent(printer_utils_1.rejectAndConcat([softline, catchFormalParameter])),
|
||||
softline,
|
||||
prettier_builder_1.concat([ctx.RBrace[0], " "])
|
||||
])),
|
||||
block
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.catchFormalParameter = function (ctx) {
|
||||
var variableModifiers = this.mapVisit(ctx.variableModifier);
|
||||
var catchType = this.visit(ctx.catchType);
|
||||
var variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", variableModifiers),
|
||||
catchType,
|
||||
variableDeclaratorId
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.catchType = function (ctx) {
|
||||
var unannClassType = this.visit(ctx.unannClassType);
|
||||
var classTypes = this.mapVisit(ctx.classType);
|
||||
var ors = ctx.Or ? ctx.Or.map(function (elt) { return prettier_builder_1.concat([line, elt, " "]); }) : [];
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(ors, __spreadArray([unannClassType], classTypes)));
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.finally = function (ctx) {
|
||||
var block = this.visit(ctx.block);
|
||||
return printer_utils_1.rejectAndJoin(" ", [ctx.Finally[0], block]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.tryWithResourcesStatement = function (ctx) {
|
||||
var resourceSpecification = this.visit(ctx.resourceSpecification);
|
||||
var block = this.visit(ctx.block);
|
||||
var catches = this.visit(ctx.catches);
|
||||
var finallyBlock = this.visit(ctx.finally);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.Try[0],
|
||||
resourceSpecification,
|
||||
block,
|
||||
catches,
|
||||
finallyBlock
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.resourceSpecification = function (ctx) {
|
||||
var resourceList = this.visit(ctx.resourceList);
|
||||
var optionalSemicolon = ctx.Semicolon ? ctx.Semicolon[0] : "";
|
||||
return printer_utils_1.putIntoBraces(printer_utils_1.rejectAndConcat([resourceList, optionalSemicolon]), softline, ctx.LBrace[0], ctx.RBrace[0]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.resourceList = function (ctx) {
|
||||
var resources = this.mapVisit(ctx.resource);
|
||||
var semicolons = ctx.Semicolon
|
||||
? ctx.Semicolon.map(function (elt) {
|
||||
return prettier_builder_1.concat([elt, line]);
|
||||
})
|
||||
: [""];
|
||||
return printer_utils_1.rejectAndJoinSeps(semicolons, resources);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.resource = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.resourceInit = function (ctx) {
|
||||
var variableModifiers = this.mapVisit(ctx.variableModifier);
|
||||
var localVariableType = this.visit(ctx.localVariableType);
|
||||
var identifier = ctx.Identifier[0];
|
||||
var expression = this.visit(ctx.expression);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", variableModifiers),
|
||||
localVariableType,
|
||||
identifier,
|
||||
ctx.Equals[0],
|
||||
expression
|
||||
]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.yieldStatement = function (ctx) {
|
||||
var expression = this.visit(ctx.expression);
|
||||
return prettier_builder_1.join(" ", [ctx.Yield[0], prettier_builder_1.concat([expression, ctx.Semicolon[0]])]);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.variableAccess = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.isBasicForStatement = function () {
|
||||
return "isBasicForStatement";
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.isLocalVariableDeclaration = function () {
|
||||
return "isLocalVariableDeclaration";
|
||||
};
|
||||
BlocksAndStatementPrettierVisitor.prototype.isClassicSwitchLabel = function () {
|
||||
return "isClassicSwitchLabel";
|
||||
};
|
||||
return BlocksAndStatementPrettierVisitor;
|
||||
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
||||
exports.BlocksAndStatementPrettierVisitor = BlocksAndStatementPrettierVisitor;
|
724
node_modules/prettier-plugin-java/dist/printers/classes.js
generated
vendored
Normal file
724
node_modules/prettier-plugin-java/dist/printers/classes.js
generated
vendored
Normal file
@@ -0,0 +1,724 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ClassesPrettierVisitor = void 0;
|
||||
var forEach_1 = __importDefault(require("lodash/forEach"));
|
||||
var printer_utils_1 = require("./printer-utils");
|
||||
var prettier_builder_1 = require("./prettier-builder");
|
||||
var format_comments_1 = require("./comments/format-comments");
|
||||
var comments_utils_1 = require("./comments/comments-utils");
|
||||
var doc_1 = require("prettier/doc");
|
||||
var base_cst_printer_1 = require("../base-cst-printer");
|
||||
var utils_1 = require("../types/utils");
|
||||
var utils_2 = require("../utils");
|
||||
var line = doc_1.builders.line, softline = doc_1.builders.softline, hardline = doc_1.builders.hardline;
|
||||
var ClassesPrettierVisitor = /** @class */ (function (_super) {
|
||||
__extends(ClassesPrettierVisitor, _super);
|
||||
function ClassesPrettierVisitor() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
ClassesPrettierVisitor.prototype.classDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.classModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var classCST;
|
||||
if (ctx.normalClassDeclaration !== undefined) {
|
||||
classCST = ctx.normalClassDeclaration;
|
||||
}
|
||||
else if (ctx.enumDeclaration !== undefined) {
|
||||
classCST = ctx.enumDeclaration;
|
||||
}
|
||||
else {
|
||||
classCST = ctx.recordDeclaration;
|
||||
}
|
||||
var classDoc = this.visit(classCST);
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [prettier_builder_1.join(" ", otherModifiers), classDoc])
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.normalClassDeclaration = function (ctx) {
|
||||
var name = this.visit(ctx.typeIdentifier);
|
||||
var optionalTypeParams = this.visit(ctx.typeParameters);
|
||||
var optionalSuperClasses = this.visit(ctx.superclass);
|
||||
var optionalSuperInterfaces = this.visit(ctx.superinterfaces);
|
||||
var optionalClassPermits = this.visit(ctx.classPermits);
|
||||
var body = this.visit(ctx.classBody, { isNormalClassDeclaration: true });
|
||||
var superClassesPart = "";
|
||||
if (optionalSuperClasses) {
|
||||
superClassesPart = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, optionalSuperClasses]));
|
||||
}
|
||||
var superInterfacesPart = "";
|
||||
if (optionalSuperInterfaces) {
|
||||
superInterfacesPart = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, optionalSuperInterfaces]));
|
||||
}
|
||||
var classPermits = "";
|
||||
if (optionalClassPermits) {
|
||||
classPermits = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, optionalClassPermits]));
|
||||
}
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.group(printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(" ", [ctx.Class[0], name]),
|
||||
optionalTypeParams,
|
||||
superClassesPart,
|
||||
superInterfacesPart,
|
||||
classPermits
|
||||
])),
|
||||
body
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.classModifier = function (ctx) {
|
||||
if (ctx.annotation) {
|
||||
return this.visit(ctx.annotation);
|
||||
}
|
||||
// public | protected | private | ...
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.typeParameters = function (ctx) {
|
||||
var typeParameterList = this.visit(ctx.typeParameterList);
|
||||
return printer_utils_1.putIntoBraces(typeParameterList, softline, ctx.Less[0], ctx.Greater[0]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.typeParameterList = function (ctx) {
|
||||
var typeParameter = this.mapVisit(ctx.typeParameter);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(commas, typeParameter));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.superclass = function (ctx) {
|
||||
return prettier_builder_1.join(" ", [ctx.Extends[0], this.visit(ctx.classType)]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.superinterfaces = function (ctx) {
|
||||
var interfaceTypeList = this.visit(ctx.interfaceTypeList);
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndConcat([
|
||||
ctx.Implements[0],
|
||||
prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, interfaceTypeList]))
|
||||
]));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.classPermits = function (ctx) {
|
||||
var typeNames = this.mapVisit(ctx.typeName);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndConcat([
|
||||
ctx.Permits[0],
|
||||
prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(commas, typeNames))]))
|
||||
]));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.interfaceTypeList = function (ctx) {
|
||||
var interfaceType = this.mapVisit(ctx.interfaceType);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(commas, interfaceType));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.classBody = function (ctx, param) {
|
||||
var content = "";
|
||||
if (ctx.classBodyDeclaration !== undefined) {
|
||||
var classBodyDeclsVisited = printer_utils_1.reject(this.mapVisit(ctx.classBodyDeclaration));
|
||||
var separators = printer_utils_1.getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration);
|
||||
content = printer_utils_1.rejectAndJoinSeps(separators, classBodyDeclsVisited);
|
||||
// edge case when we have SemiColons
|
||||
var shouldHardline_1 = false;
|
||||
ctx.classBodyDeclaration.forEach(function (elt) {
|
||||
if ((elt.children.classMemberDeclaration &&
|
||||
!elt.children.classMemberDeclaration[0].children.Semicolon) ||
|
||||
elt.children.constructorDeclaration) {
|
||||
shouldHardline_1 = true;
|
||||
}
|
||||
});
|
||||
if ((ctx.classBodyDeclaration[0].children.classMemberDeclaration ||
|
||||
ctx.classBodyDeclaration[0].children.constructorDeclaration) &&
|
||||
shouldHardline_1 &&
|
||||
param &&
|
||||
param.isNormalClassDeclaration) {
|
||||
content = printer_utils_1.rejectAndConcat([hardline, content]);
|
||||
}
|
||||
}
|
||||
return printer_utils_1.putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.classBodyDeclaration = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.classMemberDeclaration = function (ctx) {
|
||||
if (ctx.Semicolon) {
|
||||
return printer_utils_1.displaySemicolon(ctx.Semicolon[0]);
|
||||
}
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.fieldDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.fieldModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var unannType = this.visit(ctx.unannType);
|
||||
var variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", otherModifiers),
|
||||
unannType,
|
||||
prettier_builder_1.concat([variableDeclaratorList, ctx.Semicolon[0]])
|
||||
])
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.fieldModifier = function (ctx) {
|
||||
if (ctx.annotation) {
|
||||
return this.visit(ctx.annotation);
|
||||
}
|
||||
// public | protected | private | ...
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.variableDeclaratorList = function (ctx) {
|
||||
var variableDeclarators = this.mapVisit(ctx.variableDeclarator);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, " "]); }) : [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, variableDeclarators);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.variableDeclarator = function (ctx) {
|
||||
var variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
|
||||
if (ctx.Equals) {
|
||||
var variableInitializer = this.visit(ctx.variableInitializer);
|
||||
if (comments_utils_1.hasLeadingLineComments(ctx.variableInitializer[0])) {
|
||||
return prettier_builder_1.group(prettier_builder_1.indent(printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]),
|
||||
variableInitializer
|
||||
])));
|
||||
}
|
||||
if (
|
||||
// Array Initialisation
|
||||
ctx.variableInitializer[0].children.arrayInitializer !== undefined ||
|
||||
// Lambda expression
|
||||
ctx.variableInitializer[0].children.expression[0].children
|
||||
.lambdaExpression !== undefined ||
|
||||
// Ternary Expression
|
||||
(ctx.variableInitializer[0].children.expression[0].children
|
||||
.ternaryExpression !== undefined &&
|
||||
ctx.variableInitializer[0].children.expression[0].children
|
||||
.ternaryExpression[0].children.QuestionMark !== undefined)) {
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
variableDeclaratorId,
|
||||
ctx.Equals[0],
|
||||
variableInitializer
|
||||
]);
|
||||
}
|
||||
if (ctx.variableInitializer[0].children.expression[0].children
|
||||
.ternaryExpression !== undefined) {
|
||||
var firstPrimary = ctx.variableInitializer[0].children.expression[0].children
|
||||
.ternaryExpression[0].children.binaryExpression[0].children
|
||||
.unaryExpression[0].children.primary[0];
|
||||
// Cast Expression
|
||||
if (firstPrimary.children.primaryPrefix[0].children.castExpression !==
|
||||
undefined) {
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
variableDeclaratorId,
|
||||
ctx.Equals[0],
|
||||
variableInitializer
|
||||
]);
|
||||
}
|
||||
// New Expression
|
||||
if (firstPrimary.children.primaryPrefix[0].children.newExpression !==
|
||||
undefined) {
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
variableDeclaratorId,
|
||||
ctx.Equals[0],
|
||||
variableInitializer
|
||||
]);
|
||||
}
|
||||
// Method Invocation
|
||||
var isMethodInvocation = firstPrimary.children.primarySuffix !== undefined &&
|
||||
firstPrimary.children.primarySuffix[0].children
|
||||
.methodInvocationSuffix !== undefined;
|
||||
var isUniqueUnaryExpression = ctx.variableInitializer[0].children.expression[0].children
|
||||
.ternaryExpression[0].children.binaryExpression[0].children
|
||||
.unaryExpression.length === 1;
|
||||
var isUniqueMethodInvocation = isMethodInvocation && isUniqueUnaryExpression;
|
||||
if (isUniqueMethodInvocation) {
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
variableDeclaratorId,
|
||||
ctx.Equals[0],
|
||||
variableInitializer
|
||||
]);
|
||||
}
|
||||
}
|
||||
return prettier_builder_1.group(prettier_builder_1.indent(printer_utils_1.rejectAndJoin(line, [
|
||||
printer_utils_1.rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]),
|
||||
variableInitializer
|
||||
])));
|
||||
}
|
||||
return variableDeclaratorId;
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.variableDeclaratorId = function (ctx) {
|
||||
var identifier = ctx.Identifier[0];
|
||||
var dims = this.visit(ctx.dims);
|
||||
return printer_utils_1.rejectAndConcat([identifier, dims]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.variableInitializer = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.unannType = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.unannPrimitiveTypeWithOptionalDimsSuffix = function (ctx) {
|
||||
var unannPrimitiveType = this.visit(ctx.unannPrimitiveType);
|
||||
var dims = this.visit(ctx.dims);
|
||||
return printer_utils_1.rejectAndConcat([unannPrimitiveType, dims]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.unannPrimitiveType = function (ctx) {
|
||||
if (ctx.numericType) {
|
||||
return this.visitSingle(ctx);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.unannReferenceType = function (ctx) {
|
||||
var unannClassOrInterfaceType = this.visit(ctx.unannClassOrInterfaceType);
|
||||
var dims = this.visit(ctx.dims);
|
||||
return printer_utils_1.rejectAndConcat([unannClassOrInterfaceType, dims]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.unannClassOrInterfaceType = function (ctx) {
|
||||
return this.visit(ctx.unannClassType);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.unannClassType = function (ctx) {
|
||||
var _this = this;
|
||||
var tokens = printer_utils_1.sortClassTypeChildren(ctx.annotation, ctx.typeArguments, ctx.Identifier);
|
||||
var segments = [];
|
||||
var currentSegment = [];
|
||||
forEach_1.default(tokens, function (token, i) {
|
||||
if (utils_1.isTypeArgumentsCstNode(token)) {
|
||||
currentSegment.push(_this.visit([token]));
|
||||
segments.push(printer_utils_1.rejectAndConcat(currentSegment));
|
||||
currentSegment = [];
|
||||
}
|
||||
else if (utils_1.isAnnotationCstNode(token)) {
|
||||
currentSegment.push(_this.visit([token]));
|
||||
currentSegment.push(" ");
|
||||
}
|
||||
else {
|
||||
currentSegment.push(token);
|
||||
if ((i + 1 < tokens.length && !utils_1.isTypeArgumentsCstNode(tokens[i + 1])) ||
|
||||
i + 1 === tokens.length) {
|
||||
segments.push(printer_utils_1.rejectAndConcat(currentSegment));
|
||||
currentSegment = [];
|
||||
}
|
||||
}
|
||||
});
|
||||
return printer_utils_1.rejectAndJoinSeps(ctx.Dot, segments);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.unannInterfaceType = function (ctx) {
|
||||
return this.visit(ctx.unannClassType);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.unannTypeVariable = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.methodDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.methodModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var header = this.visit(ctx.methodHeader);
|
||||
var body = this.visit(ctx.methodBody);
|
||||
var headerBodySeparator = printer_utils_1.isStatementEmptyStatement(body) ? "" : " ";
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", otherModifiers),
|
||||
printer_utils_1.rejectAndJoin(headerBodySeparator, [header, body])
|
||||
])
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.methodModifier = function (ctx) {
|
||||
if (ctx.annotation) {
|
||||
return this.visit(ctx.annotation);
|
||||
}
|
||||
// public | protected | private | Synchronized | ...
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.methodHeader = function (ctx) {
|
||||
var typeParameters = this.visit(ctx.typeParameters);
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var result = this.visit(ctx.result);
|
||||
var declarator = this.visit(ctx.methodDeclarator);
|
||||
var throws = this.visit(ctx.throws);
|
||||
return prettier_builder_1.group(prettier_builder_1.concat([
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
typeParameters,
|
||||
printer_utils_1.rejectAndJoin(line, annotations),
|
||||
result,
|
||||
declarator,
|
||||
throws
|
||||
])
|
||||
]));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.result = function (ctx) {
|
||||
if (ctx.unannType) {
|
||||
return this.visit(ctx.unannType);
|
||||
}
|
||||
// void
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.methodDeclarator = function (ctx) {
|
||||
var identifier = format_comments_1.printTokenWithComments(ctx.Identifier[0]);
|
||||
var formalParameterList = this.visit(ctx.formalParameterList);
|
||||
var dims = this.visit(ctx.dims);
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
identifier,
|
||||
printer_utils_1.putIntoBraces(formalParameterList, softline, ctx.LBrace[0], ctx.RBrace[0]),
|
||||
dims
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.receiverParameter = function (ctx) {
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var unannType = this.visit(ctx.unannType);
|
||||
var identifier = ctx.Identifier
|
||||
? prettier_builder_1.concat([ctx.Identifier[0], ctx.Dot[0]])
|
||||
: "";
|
||||
return printer_utils_1.rejectAndJoin("", [
|
||||
printer_utils_1.rejectAndJoin(" ", annotations),
|
||||
unannType,
|
||||
identifier,
|
||||
ctx.This[0]
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.formalParameterList = function (ctx) {
|
||||
var formalParameter = this.mapVisit(ctx.formalParameter);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, formalParameter);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.formalParameter = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.variableParaRegularParameter = function (ctx) {
|
||||
var variableModifier = this.mapVisit(ctx.variableModifier);
|
||||
var unannType = this.visit(ctx.unannType);
|
||||
var variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", variableModifier),
|
||||
unannType,
|
||||
variableDeclaratorId
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.variableArityParameter = function (ctx) {
|
||||
var variableModifier = this.mapVisit(ctx.variableModifier);
|
||||
var unannType = this.visit(ctx.unannType);
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var identifier = ctx.Identifier[0];
|
||||
var unannTypePrinted = ctx.annotation === undefined
|
||||
? prettier_builder_1.concat([unannType, ctx.DotDotDot[0]])
|
||||
: unannType;
|
||||
var annotationsPrinted = ctx.annotation === undefined
|
||||
? annotations
|
||||
: prettier_builder_1.concat([printer_utils_1.rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.join(" ", variableModifier),
|
||||
unannTypePrinted,
|
||||
annotationsPrinted,
|
||||
identifier
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.variableModifier = function (ctx) {
|
||||
if (ctx.annotation) {
|
||||
return this.visit(ctx.annotation);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.throws = function (ctx) {
|
||||
var exceptionTypeList = this.visit(ctx.exceptionTypeList);
|
||||
var throwsDeclaration = prettier_builder_1.join(" ", [ctx.Throws[0], exceptionTypeList]);
|
||||
return prettier_builder_1.group(prettier_builder_1.indent(printer_utils_1.rejectAndConcat([softline, throwsDeclaration])));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.exceptionTypeList = function (ctx) {
|
||||
var exceptionTypes = this.mapVisit(ctx.exceptionType);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, " "]); }) : [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, exceptionTypes);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.exceptionType = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.methodBody = function (ctx) {
|
||||
if (ctx.block) {
|
||||
return this.visit(ctx.block);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.instanceInitializer = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.staticInitializer = function (ctx) {
|
||||
var block = this.visit(ctx.block);
|
||||
return prettier_builder_1.join(" ", [ctx.Static[0], block]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.constructorDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.constructorModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var constructorDeclarator = this.visit(ctx.constructorDeclarator);
|
||||
var throws = this.visit(ctx.throws);
|
||||
var constructorBody = this.visit(ctx.constructorBody);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.group(printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.join(" ", otherModifiers),
|
||||
constructorDeclarator,
|
||||
throws
|
||||
])
|
||||
])),
|
||||
constructorBody
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.constructorModifier = function (ctx) {
|
||||
if (ctx.annotation) {
|
||||
return this.visit(ctx.annotation);
|
||||
}
|
||||
// public | protected | private | Synchronized | ...
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.constructorDeclarator = function (ctx) {
|
||||
var typeParameters = this.visit(ctx.typeParameters);
|
||||
var simpleTypeName = this.visit(ctx.simpleTypeName);
|
||||
var receiverParameter = this.visit(ctx.receiverParameter);
|
||||
var formalParameterList = this.visit(ctx.formalParameterList);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, " "]); }) : [];
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
typeParameters,
|
||||
prettier_builder_1.concat([
|
||||
simpleTypeName,
|
||||
printer_utils_1.putIntoBraces(printer_utils_1.rejectAndJoinSeps(commas, [receiverParameter, formalParameterList]), softline, ctx.LBrace[0], ctx.RBrace[0])
|
||||
])
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.simpleTypeName = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.constructorBody = function (ctx) {
|
||||
var explicitConstructorInvocation = this.visit(ctx.explicitConstructorInvocation);
|
||||
var blockStatements = this.visit(ctx.blockStatements);
|
||||
return printer_utils_1.putIntoBraces(printer_utils_1.rejectAndJoin(hardline, [explicitConstructorInvocation, blockStatements]), hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.explicitConstructorInvocation = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.unqualifiedExplicitConstructorInvocation = function (ctx) {
|
||||
var typeArguments = this.visit(ctx.typeArguments);
|
||||
var keyWord = ctx.This ? ctx.This[0] : ctx.Super[0];
|
||||
var argumentList = utils_2.printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
typeArguments,
|
||||
keyWord,
|
||||
prettier_builder_1.group(printer_utils_1.rejectAndConcat([argumentList, ctx.Semicolon[0]]))
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.qualifiedExplicitConstructorInvocation = function (ctx) {
|
||||
var expressionName = this.visit(ctx.expressionName);
|
||||
var typeArguments = this.visit(ctx.typeArguments);
|
||||
var argumentList = utils_2.printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
expressionName,
|
||||
ctx.Dot[0],
|
||||
typeArguments,
|
||||
ctx.Super[0],
|
||||
prettier_builder_1.group(printer_utils_1.rejectAndConcat([argumentList, ctx.Semicolon[0]]))
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.enumDeclaration = function (ctx) {
|
||||
var classModifier = this.mapVisit(ctx.classModifier);
|
||||
var typeIdentifier = this.visit(ctx.typeIdentifier);
|
||||
var superinterfaces = this.visit(ctx.superinterfaces);
|
||||
var enumBody = this.visit(ctx.enumBody);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.join(" ", classModifier),
|
||||
ctx.Enum[0],
|
||||
typeIdentifier,
|
||||
superinterfaces,
|
||||
enumBody
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.enumBody = function (ctx) {
|
||||
var enumConstantList = this.visit(ctx.enumConstantList);
|
||||
var enumBodyDeclarations = this.visit(ctx.enumBodyDeclarations);
|
||||
var hasEnumConstants = ctx.enumConstantList !== undefined;
|
||||
var hasNoClassBodyDeclarations = ctx.enumBodyDeclarations === undefined ||
|
||||
ctx.enumBodyDeclarations[0].children.classBodyDeclaration === undefined;
|
||||
// edge case: https://github.com/jhipster/prettier-java/issues/383
|
||||
var handleEnumBodyDeclarationsLeadingComments = !hasNoClassBodyDeclarations &&
|
||||
comments_utils_1.hasLeadingComments(ctx.enumBodyDeclarations[0])
|
||||
? hardline
|
||||
: "";
|
||||
var optionalComma;
|
||||
if (hasEnumConstants &&
|
||||
hasNoClassBodyDeclarations &&
|
||||
this.prettierOptions.trailingComma !== "none") {
|
||||
optionalComma = ctx.Comma ? ctx.Comma[0] : ",";
|
||||
}
|
||||
else {
|
||||
optionalComma = ctx.Comma ? __assign(__assign({}, ctx.Comma[0]), { image: "" }) : "";
|
||||
}
|
||||
return printer_utils_1.putIntoBraces(printer_utils_1.rejectAndConcat([
|
||||
enumConstantList,
|
||||
optionalComma,
|
||||
handleEnumBodyDeclarationsLeadingComments,
|
||||
enumBodyDeclarations
|
||||
]), hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.enumConstantList = function (ctx) {
|
||||
var enumConstants = this.mapVisit(ctx.enumConstant);
|
||||
var blankLineSeparators = printer_utils_1.getBlankLinesSeparator(ctx.enumConstant);
|
||||
var commas = ctx.Comma
|
||||
? ctx.Comma.map(function (elt, index) {
|
||||
return prettier_builder_1.concat([elt, blankLineSeparators[index]]);
|
||||
})
|
||||
: [];
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(commas, enumConstants));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.enumConstant = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.enumConstantModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var identifier = ctx.Identifier[0];
|
||||
var classBody = this.visit(ctx.classBody);
|
||||
var optionalBracesAndArgumentList = ctx.LBrace
|
||||
? utils_2.printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0])
|
||||
: "";
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", otherModifiers),
|
||||
printer_utils_1.rejectAndConcat([identifier, optionalBracesAndArgumentList]),
|
||||
classBody
|
||||
])
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.enumConstantModifier = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.enumBodyDeclarations = function (ctx) {
|
||||
if (ctx.classBodyDeclaration !== undefined) {
|
||||
var classBodyDeclaration = this.mapVisit(ctx.classBodyDeclaration);
|
||||
var separators = printer_utils_1.getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration);
|
||||
return printer_utils_1.rejectAndJoin(prettier_builder_1.concat([hardline, hardline]), [
|
||||
ctx.Semicolon[0],
|
||||
printer_utils_1.rejectAndJoinSeps(separators, classBodyDeclaration)
|
||||
]);
|
||||
}
|
||||
return __assign(__assign({}, ctx.Semicolon[0]), { image: "" });
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.recordDeclaration = function (ctx) {
|
||||
var name = this.visit(ctx.typeIdentifier);
|
||||
var optionalTypeParams = this.visit(ctx.typeParameters);
|
||||
var recordHeader = this.visit(ctx.recordHeader);
|
||||
var superInterfacesPart = "";
|
||||
var optionalSuperInterfaces = this.visit(ctx.superinterfaces);
|
||||
if (optionalSuperInterfaces) {
|
||||
superInterfacesPart = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, optionalSuperInterfaces]));
|
||||
}
|
||||
var body = this.visit(ctx.recordBody);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.group(printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(" ", [ctx.Record[0], name]),
|
||||
optionalTypeParams,
|
||||
recordHeader,
|
||||
superInterfacesPart
|
||||
])),
|
||||
body
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.recordHeader = function (ctx) {
|
||||
var recordComponentList = this.visit(ctx.recordComponentList);
|
||||
return printer_utils_1.putIntoBraces(recordComponentList, softline, ctx.LBrace[0], ctx.RBrace[0]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.recordComponentList = function (ctx) {
|
||||
var recordComponents = this.mapVisit(ctx.recordComponent);
|
||||
var blankLineSeparators = printer_utils_1.getBlankLinesSeparator(ctx.recordComponent, line);
|
||||
var commas = ctx.Comma
|
||||
? ctx.Comma.map(function (elt, index) {
|
||||
return prettier_builder_1.concat([elt, blankLineSeparators[index]]);
|
||||
})
|
||||
: [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, recordComponents);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.recordComponent = function (ctx) {
|
||||
var modifiers = this.mapVisit(ctx.recordComponentModifier);
|
||||
var unannType = this.visit(ctx.unannType);
|
||||
if (ctx.Identifier !== undefined) {
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndJoin(line, [
|
||||
prettier_builder_1.join(line, modifiers),
|
||||
prettier_builder_1.join(" ", [unannType, ctx.Identifier[0]])
|
||||
]));
|
||||
}
|
||||
var variableArityRecordComponent = this.visit(ctx.variableArityRecordComponent);
|
||||
if (ctx.variableArityRecordComponent[0].children.annotation !== undefined) {
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndJoin(line, [
|
||||
prettier_builder_1.join(line, modifiers),
|
||||
prettier_builder_1.join(" ", [unannType, variableArityRecordComponent])
|
||||
]));
|
||||
}
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndJoin(line, [
|
||||
prettier_builder_1.join(line, modifiers),
|
||||
prettier_builder_1.concat([unannType, variableArityRecordComponent])
|
||||
]));
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.variableArityRecordComponent = function (ctx) {
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var identifier = ctx.Identifier[0];
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndConcat([printer_utils_1.rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]),
|
||||
identifier
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.recordComponentModifier = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.recordBody = function (ctx) {
|
||||
return printer_utils_1.putIntoBraces(printer_utils_1.rejectAndJoinSeps(printer_utils_1.getBlankLinesSeparator(ctx.recordBodyDeclaration), this.mapVisit(ctx.recordBodyDeclaration)), hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.recordBodyDeclaration = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.compactConstructorDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.constructorModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var name = this.visit(ctx.simpleTypeName);
|
||||
var constructorBody = this.visit(ctx.constructorBody);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.group(printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [prettier_builder_1.join(" ", otherModifiers), name])
|
||||
])),
|
||||
constructorBody
|
||||
]);
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.isClassDeclaration = function () {
|
||||
return "isClassDeclaration";
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.identifyClassBodyDeclarationType = function () {
|
||||
return "identifyClassBodyDeclarationType";
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.isDims = function () {
|
||||
return "isDims";
|
||||
};
|
||||
ClassesPrettierVisitor.prototype.isCompactConstructorDeclaration = function () {
|
||||
return "isCompactConstructorDeclaration";
|
||||
};
|
||||
return ClassesPrettierVisitor;
|
||||
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
||||
exports.ClassesPrettierVisitor = ClassesPrettierVisitor;
|
29
node_modules/prettier-plugin-java/dist/printers/comments/comments-utils.js
generated
vendored
Normal file
29
node_modules/prettier-plugin-java/dist/printers/comments/comments-utils.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hasComments = exports.hasTrailingLineComments = exports.hasLeadingLineComments = exports.hasTrailingComments = exports.hasLeadingComments = void 0;
|
||||
function hasLeadingComments(token) {
|
||||
return token.leadingComments !== undefined;
|
||||
}
|
||||
exports.hasLeadingComments = hasLeadingComments;
|
||||
function hasTrailingComments(token) {
|
||||
return token.trailingComments !== undefined;
|
||||
}
|
||||
exports.hasTrailingComments = hasTrailingComments;
|
||||
function hasLeadingLineComments(token) {
|
||||
return (token.leadingComments !== undefined &&
|
||||
token.leadingComments.length !== 0 &&
|
||||
token.leadingComments[token.leadingComments.length - 1].tokenType.name ===
|
||||
"LineComment");
|
||||
}
|
||||
exports.hasLeadingLineComments = hasLeadingLineComments;
|
||||
function hasTrailingLineComments(token) {
|
||||
return (token.trailingComments !== undefined &&
|
||||
token.trailingComments.length !== 0 &&
|
||||
token.trailingComments[token.trailingComments.length - 1].tokenType.name ===
|
||||
"LineComment");
|
||||
}
|
||||
exports.hasTrailingLineComments = hasTrailingLineComments;
|
||||
function hasComments(token) {
|
||||
return hasLeadingComments(token) || hasTrailingComments(token);
|
||||
}
|
||||
exports.hasComments = hasComments;
|
179
node_modules/prettier-plugin-java/dist/printers/comments/format-comments.js
generated
vendored
Normal file
179
node_modules/prettier-plugin-java/dist/printers/comments/format-comments.js
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
"use strict";
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
||||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
||||
to[j] = from[i];
|
||||
return to;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.processComments = exports.getTokenLeadingComments = exports.printNodeWithComments = exports.printTokenWithComments = void 0;
|
||||
var doc_1 = require("prettier/doc");
|
||||
var utils_1 = require("../../types/utils");
|
||||
var concat = doc_1.builders.concat, hardline = doc_1.builders.hardline, lineSuffix = doc_1.builders.lineSuffix, breakParent = doc_1.builders.breakParent, literalline = doc_1.builders.literalline;
|
||||
/**
|
||||
* Takes a token and return a doc with:
|
||||
* - concatenated leading comments
|
||||
* - the token image
|
||||
* - concatenated trailing comments
|
||||
*
|
||||
* @param {IToken} token
|
||||
* @return a doc with the token and its comments
|
||||
*/
|
||||
function printTokenWithComments(token) {
|
||||
return printWithComments(token, token.image, getTokenLeadingComments, getTokenTrailingComments);
|
||||
}
|
||||
exports.printTokenWithComments = printTokenWithComments;
|
||||
/**
|
||||
* Takes a node and return a doc with:
|
||||
* - concatenated leading comments
|
||||
* - the node doc value
|
||||
* - concatenated trailing comments
|
||||
*
|
||||
* @param {CstNode} node
|
||||
* @param {Doc} value - the converted node value
|
||||
* @return a doc with the token and its comments
|
||||
*/
|
||||
function printNodeWithComments(node, value) {
|
||||
return printWithComments(node, value, getNodeLeadingComments, getNodeTrailingComments);
|
||||
}
|
||||
exports.printNodeWithComments = printNodeWithComments;
|
||||
function printWithComments(nodeOrToken, value, getLeadingComments, getTrailingComments) {
|
||||
var leadingComments = getLeadingComments(nodeOrToken);
|
||||
var trailingComments = getTrailingComments(nodeOrToken, value);
|
||||
return leadingComments.length === 0 && trailingComments.length === 0
|
||||
? value
|
||||
: concat(__spreadArray(__spreadArray(__spreadArray([], leadingComments), [value]), trailingComments));
|
||||
}
|
||||
/**
|
||||
* @param {IToken} token
|
||||
* @return an array containing processed leading comments and separators
|
||||
*/
|
||||
function getTokenLeadingComments(token) {
|
||||
return getLeadingComments(token, token);
|
||||
}
|
||||
exports.getTokenLeadingComments = getTokenLeadingComments;
|
||||
/**
|
||||
* @param {CstNode} node
|
||||
* @return an array containing processed leading comments and separators
|
||||
*/
|
||||
function getNodeLeadingComments(node) {
|
||||
return getLeadingComments(node, node.location);
|
||||
}
|
||||
function getLeadingComments(nodeOrToken, location) {
|
||||
var arr = [];
|
||||
if (nodeOrToken.leadingComments !== undefined) {
|
||||
var previousEndLine = nodeOrToken.leadingComments[0].endLine;
|
||||
var step = void 0;
|
||||
arr.push(concat(formatComment(nodeOrToken.leadingComments[0])));
|
||||
for (var i = 1; i < nodeOrToken.leadingComments.length; i++) {
|
||||
step = nodeOrToken.leadingComments[i].startLine - previousEndLine;
|
||||
if (step === 1 ||
|
||||
nodeOrToken.leadingComments[i].startOffset > location.startOffset) {
|
||||
arr.push(hardline);
|
||||
}
|
||||
else if (step > 1) {
|
||||
arr.push(hardline, hardline);
|
||||
}
|
||||
arr.push(concat(formatComment(nodeOrToken.leadingComments[i])));
|
||||
previousEndLine = nodeOrToken.leadingComments[i].endLine;
|
||||
}
|
||||
step = location.startLine - previousEndLine;
|
||||
if (step === 1 ||
|
||||
nodeOrToken.leadingComments[nodeOrToken.leadingComments.length - 1]
|
||||
.startOffset > location.startOffset) {
|
||||
arr.push(hardline);
|
||||
}
|
||||
else if (step > 1) {
|
||||
arr.push(hardline, hardline);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
/**
|
||||
* @param {IToken} token
|
||||
* @return an array containing processed trailing comments and separators
|
||||
*/
|
||||
function getTokenTrailingComments(token) {
|
||||
return getTrailingComments(token, token.image, token);
|
||||
}
|
||||
/**
|
||||
* @param {CstNode} node
|
||||
* @param {string} value
|
||||
* @return an array containing processed trailing comments and separators
|
||||
*/
|
||||
function getNodeTrailingComments(node, value) {
|
||||
return getTrailingComments(node, value, node.location);
|
||||
}
|
||||
function getTrailingComments(nodeOrToken, value, location) {
|
||||
var arr = [];
|
||||
var previousEndLine = location.endLine;
|
||||
if (nodeOrToken.trailingComments !== undefined) {
|
||||
nodeOrToken.trailingComments.forEach(function (comment, idx) {
|
||||
var separator = "";
|
||||
if (comment.startLine !== previousEndLine) {
|
||||
arr.push(hardline);
|
||||
}
|
||||
else if (value !== "" && idx === 0) {
|
||||
separator = " ";
|
||||
}
|
||||
if (comment.tokenType.name === "LineComment") {
|
||||
arr.push(lineSuffix(concat([separator, concat(formatComment(comment)), breakParent])));
|
||||
}
|
||||
else {
|
||||
arr.push(concat(formatComment(comment)));
|
||||
}
|
||||
previousEndLine = comment.endLine;
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
function isJavaDoc(comment, lines) {
|
||||
var isJavaDoc = true;
|
||||
if (comment.tokenType.name === "TraditionalComment" && lines.length > 1) {
|
||||
for (var i = 1; i < lines.length; i++) {
|
||||
if (lines[i].trim().charAt(0) !== "*") {
|
||||
isJavaDoc = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
isJavaDoc = false;
|
||||
}
|
||||
return isJavaDoc;
|
||||
}
|
||||
function formatJavaDoc(lines) {
|
||||
var res = [lines[0].trim()];
|
||||
for (var i = 1; i < lines.length; i++) {
|
||||
res.push(hardline);
|
||||
res.push(" " + lines[i].trim());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
function formatComment(comment) {
|
||||
var res = [];
|
||||
var lines = comment.image.split("\n");
|
||||
if (isJavaDoc(comment, lines)) {
|
||||
return formatJavaDoc(lines);
|
||||
}
|
||||
lines.forEach(function (line) {
|
||||
res.push(line);
|
||||
res.push(literalline);
|
||||
});
|
||||
res.pop();
|
||||
return res;
|
||||
}
|
||||
function processComments(docs) {
|
||||
if (!Array.isArray(docs)) {
|
||||
if (utils_1.isCstElementOrUndefinedIToken(docs)) {
|
||||
return printTokenWithComments(docs);
|
||||
}
|
||||
return docs;
|
||||
}
|
||||
return docs.map(function (elt) {
|
||||
if (utils_1.isCstElementOrUndefinedIToken(elt)) {
|
||||
return printTokenWithComments(elt);
|
||||
}
|
||||
return elt;
|
||||
});
|
||||
}
|
||||
exports.processComments = processComments;
|
38
node_modules/prettier-plugin-java/dist/printers/comments/handle-comments.js
generated
vendored
Normal file
38
node_modules/prettier-plugin-java/dist/printers/comments/handle-comments.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.handleCommentsBinaryExpression = void 0;
|
||||
var comments_utils_1 = require("./comments-utils");
|
||||
function handleCommentsBinaryExpression(ctx) {
|
||||
var unaryExpressionIndex = 1;
|
||||
if (ctx.BinaryOperator !== undefined) {
|
||||
ctx.BinaryOperator.forEach(function (binaryOperator) {
|
||||
var _a;
|
||||
if (comments_utils_1.hasLeadingComments(binaryOperator)) {
|
||||
while (ctx.unaryExpression[unaryExpressionIndex].location.startOffset <
|
||||
binaryOperator.endOffset) {
|
||||
unaryExpressionIndex++;
|
||||
}
|
||||
// Adapt the position of the operator and its leading comments
|
||||
var shiftUp = binaryOperator.leadingComments[0].startLine -
|
||||
1 -
|
||||
binaryOperator.startLine;
|
||||
if (binaryOperator.startLine !==
|
||||
ctx.unaryExpression[unaryExpressionIndex].location.startLine) {
|
||||
binaryOperator.leadingComments.forEach(function (comment) {
|
||||
comment.startLine += 1;
|
||||
comment.endLine += 1;
|
||||
});
|
||||
}
|
||||
binaryOperator.startLine += shiftUp;
|
||||
binaryOperator.endLine += shiftUp;
|
||||
// Assign the leading comments & trailing comments of the binaryOperator
|
||||
// to the following unaryExpression as leading comments
|
||||
ctx.unaryExpression[unaryExpressionIndex].leadingComments =
|
||||
ctx.unaryExpression[unaryExpressionIndex].leadingComments || [];
|
||||
(_a = ctx.unaryExpression[unaryExpressionIndex].leadingComments).unshift.apply(_a, binaryOperator.leadingComments);
|
||||
delete binaryOperator.leadingComments;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.handleCommentsBinaryExpression = handleCommentsBinaryExpression;
|
549
node_modules/prettier-plugin-java/dist/printers/expressions.js
generated
vendored
Normal file
549
node_modules/prettier-plugin-java/dist/printers/expressions.js
generated
vendored
Normal file
@@ -0,0 +1,549 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
||||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
||||
to[j] = from[i];
|
||||
return to;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ExpressionsPrettierVisitor = void 0;
|
||||
var forEach_1 = __importDefault(require("lodash/forEach"));
|
||||
var doc_1 = require("prettier/doc");
|
||||
var base_cst_printer_1 = require("../base-cst-printer");
|
||||
var utils_1 = require("../types/utils");
|
||||
var expressions_utils_1 = require("../utils/expressions-utils");
|
||||
var utils_2 = require("../utils");
|
||||
var format_comments_1 = require("./comments/format-comments");
|
||||
var handle_comments_1 = require("./comments/handle-comments");
|
||||
var prettier_builder_1 = require("./prettier-builder");
|
||||
var printer_utils_1 = require("./printer-utils");
|
||||
var ifBreak = doc_1.builders.ifBreak, line = doc_1.builders.line, softline = doc_1.builders.softline, indentIfBreak = doc_1.builders.indentIfBreak;
|
||||
var ExpressionsPrettierVisitor = /** @class */ (function (_super) {
|
||||
__extends(ExpressionsPrettierVisitor, _super);
|
||||
function ExpressionsPrettierVisitor() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
ExpressionsPrettierVisitor.prototype.expression = function (ctx, params) {
|
||||
return this.visitSingle(ctx, params);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.lambdaExpression = function (ctx, params) {
|
||||
var lambdaParameters = prettier_builder_1.group(this.visit(ctx.lambdaParameters, params), params ? { id: params.lambdaParametersGroupId } : undefined);
|
||||
var lambdaBody = this.visit(ctx.lambdaBody);
|
||||
var isLambdaBodyABlock = ctx.lambdaBody[0].children.block !== undefined;
|
||||
if (isLambdaBodyABlock) {
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
lambdaParameters,
|
||||
ctx.Arrow[0],
|
||||
(params === null || params === void 0 ? void 0 : params.lambdaParametersGroupId) !== undefined
|
||||
? indentIfBreak(lambdaBody, {
|
||||
groupId: params.lambdaParametersGroupId
|
||||
})
|
||||
: lambdaBody
|
||||
]);
|
||||
}
|
||||
return prettier_builder_1.group(prettier_builder_1.indent(printer_utils_1.rejectAndJoin(line, [
|
||||
printer_utils_1.rejectAndJoin(" ", [lambdaParameters, ctx.Arrow[0]]),
|
||||
lambdaBody
|
||||
])));
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.lambdaParameters = function (ctx, params) {
|
||||
if (ctx.lambdaParametersWithBraces) {
|
||||
return this.visitSingle(ctx, params);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.lambdaParametersWithBraces = function (ctx, params) {
|
||||
var lambdaParameterList = this.visit(ctx.lambdaParameterList);
|
||||
if (printer_utils_1.findDeepElementInPartsArray(lambdaParameterList, ",")) {
|
||||
var content = printer_utils_1.putIntoBraces(lambdaParameterList, softline, ctx.LBrace[0], ctx.RBrace[0]);
|
||||
if ((params === null || params === void 0 ? void 0 : params.isInsideMethodInvocationSuffix) === true) {
|
||||
return prettier_builder_1.indent(prettier_builder_1.concat([softline, content]));
|
||||
}
|
||||
return content;
|
||||
}
|
||||
// removing braces when only no comments attached
|
||||
if ((ctx.LBrace &&
|
||||
ctx.RBrace &&
|
||||
(!lambdaParameterList || printer_utils_1.isExplicitLambdaParameter(ctx))) ||
|
||||
ctx.LBrace[0].leadingComments ||
|
||||
ctx.LBrace[0].trailingComments ||
|
||||
ctx.RBrace[0].leadingComments ||
|
||||
ctx.RBrace[0].trailingComments) {
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
ctx.LBrace[0],
|
||||
lambdaParameterList,
|
||||
ctx.RBrace[0]
|
||||
]);
|
||||
}
|
||||
return lambdaParameterList;
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.lambdaParameterList = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.inferredLambdaParameterList = function (ctx) {
|
||||
var commas = ctx.Comma
|
||||
? ctx.Comma.map(function (elt) {
|
||||
return prettier_builder_1.concat([elt, line]);
|
||||
})
|
||||
: [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, ctx.Identifier);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.explicitLambdaParameterList = function (ctx) {
|
||||
var lambdaParameter = this.mapVisit(ctx.lambdaParameter);
|
||||
var commas = ctx.Comma
|
||||
? ctx.Comma.map(function (elt) {
|
||||
return prettier_builder_1.concat([elt, line]);
|
||||
})
|
||||
: [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, lambdaParameter);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.lambdaParameter = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.regularLambdaParameter = function (ctx) {
|
||||
var variableModifier = this.mapVisit(ctx.variableModifier);
|
||||
var lambdaParameterType = this.visit(ctx.lambdaParameterType);
|
||||
var variableDeclaratorId = this.visit(ctx.variableDeclaratorId);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", variableModifier),
|
||||
lambdaParameterType,
|
||||
variableDeclaratorId
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.lambdaParameterType = function (ctx) {
|
||||
if (ctx.unannType) {
|
||||
return this.visitSingle(ctx);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.lambdaBody = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.ternaryExpression = function (ctx, params) {
|
||||
var binaryExpression = this.visit(ctx.binaryExpression, params);
|
||||
if (ctx.QuestionMark) {
|
||||
var expression1 = this.visit(ctx.expression[0]);
|
||||
var expression2 = this.visit(ctx.expression[1]);
|
||||
return prettier_builder_1.indent(prettier_builder_1.group(printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(line, [
|
||||
binaryExpression,
|
||||
printer_utils_1.rejectAndJoin(" ", [ctx.QuestionMark[0], expression1]),
|
||||
printer_utils_1.rejectAndJoin(" ", [ctx.Colon[0], expression2])
|
||||
])
|
||||
])));
|
||||
}
|
||||
return binaryExpression;
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.binaryExpression = function (ctx, params) {
|
||||
handle_comments_1.handleCommentsBinaryExpression(ctx);
|
||||
var instanceofReferences = this.mapVisit(printer_utils_1.sortNodes([ctx.pattern, ctx.referenceType]));
|
||||
var expression = this.mapVisit(ctx.expression);
|
||||
var unaryExpression = this.mapVisit(ctx.unaryExpression);
|
||||
var _a = printer_utils_1.separateTokensIntoGroups(ctx), groupsOfOperator = _a.groupsOfOperator, sortedBinaryOperators = _a.sortedBinaryOperators;
|
||||
var segmentsSplitByBinaryOperator = [];
|
||||
var currentSegment = [];
|
||||
if (groupsOfOperator.length === 1 && groupsOfOperator[0].length === 0) {
|
||||
return unaryExpression.shift();
|
||||
}
|
||||
groupsOfOperator.forEach(function (subgroup) {
|
||||
currentSegment = [unaryExpression.shift()];
|
||||
for (var i = 0; i < subgroup.length; i++) {
|
||||
var token = subgroup[i];
|
||||
var shiftOperator = printer_utils_1.isShiftOperator(subgroup, i);
|
||||
if (token.tokenType.name === "Instanceof") {
|
||||
currentSegment.push(printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.Instanceof[0],
|
||||
instanceofReferences.shift()
|
||||
]));
|
||||
}
|
||||
else if (printer_utils_1.matchCategory(token, "'AssignmentOperator'")) {
|
||||
currentSegment.push(prettier_builder_1.indent(printer_utils_1.rejectAndJoin(line, [token, expression.shift()])));
|
||||
}
|
||||
else if (shiftOperator === "leftShift" ||
|
||||
shiftOperator === "rightShift") {
|
||||
currentSegment.push(printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndConcat([token, subgroup[i + 1]]),
|
||||
unaryExpression.shift()
|
||||
]));
|
||||
i++;
|
||||
}
|
||||
else if (shiftOperator === "doubleRightShift") {
|
||||
currentSegment.push(printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndConcat([token, subgroup[i + 1], subgroup[i + 2]]),
|
||||
unaryExpression.shift()
|
||||
]));
|
||||
i += 2;
|
||||
}
|
||||
else if (printer_utils_1.matchCategory(token, "'BinaryOperator'")) {
|
||||
currentSegment.push(printer_utils_1.rejectAndJoin(line, [token, unaryExpression.shift()]));
|
||||
}
|
||||
}
|
||||
segmentsSplitByBinaryOperator.push(prettier_builder_1.group(printer_utils_1.rejectAndJoin(" ", currentSegment)));
|
||||
});
|
||||
if (params !== undefined && params.addParenthesisToWrapStatement) {
|
||||
return prettier_builder_1.group(prettier_builder_1.concat([
|
||||
ifBreak("(", ""),
|
||||
prettier_builder_1.indent(prettier_builder_1.concat([
|
||||
softline,
|
||||
prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(sortedBinaryOperators.map(function (elt) { return prettier_builder_1.concat([" ", elt, line]); }), segmentsSplitByBinaryOperator))
|
||||
])),
|
||||
softline,
|
||||
ifBreak(")")
|
||||
]));
|
||||
}
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndJoinSeps(sortedBinaryOperators.map(function (elt) { return prettier_builder_1.concat([" ", elt, line]); }), segmentsSplitByBinaryOperator));
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.unaryExpression = function (ctx) {
|
||||
var unaryPrefixOperator = ctx.UnaryPrefixOperator
|
||||
? ctx.UnaryPrefixOperator
|
||||
: [];
|
||||
var primary = this.visit(ctx.primary);
|
||||
var unarySuffixOperator = ctx.UnarySuffixOperator
|
||||
? ctx.UnarySuffixOperator
|
||||
: [];
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndConcat(unaryPrefixOperator),
|
||||
primary,
|
||||
printer_utils_1.rejectAndConcat(unarySuffixOperator)
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.unaryExpressionNotPlusMinus = function (ctx) {
|
||||
var unaryPrefixOperatorNotPlusMinus = ctx.UnaryPrefixOperatorNotPlusMinus // changed when moved to TS
|
||||
? printer_utils_1.rejectAndJoin(" ", ctx.UnaryPrefixOperatorNotPlusMinus) // changed when moved to TS
|
||||
: "";
|
||||
var primary = this.visit(ctx.primary);
|
||||
var unarySuffixOperator = ctx.UnarySuffixOperator // changed when moved to TS
|
||||
? printer_utils_1.rejectAndJoin(" ", ctx.UnarySuffixOperator) // changed when moved to TS
|
||||
: "";
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
unaryPrefixOperatorNotPlusMinus,
|
||||
primary,
|
||||
unarySuffixOperator
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.primary = function (ctx) {
|
||||
var countMethodInvocation = printer_utils_1.isUniqueMethodInvocation(ctx.primarySuffix);
|
||||
var primaryPrefix = this.visit(ctx.primaryPrefix, {
|
||||
shouldBreakBeforeFirstMethodInvocation: countMethodInvocation > 1
|
||||
});
|
||||
var suffixes = [];
|
||||
if (ctx.primarySuffix !== undefined) {
|
||||
// edge case: https://github.com/jhipster/prettier-java/issues/381
|
||||
var hasFirstInvocationArg = true;
|
||||
if (ctx.primarySuffix.length > 1 &&
|
||||
ctx.primarySuffix[1].children.methodInvocationSuffix &&
|
||||
Object.keys(ctx.primarySuffix[1].children.methodInvocationSuffix[0].children).length === 2) {
|
||||
hasFirstInvocationArg = false;
|
||||
}
|
||||
if (ctx.primarySuffix[0].children.Dot !== undefined &&
|
||||
ctx.primaryPrefix[0].children.newExpression !== undefined) {
|
||||
suffixes.push(softline);
|
||||
}
|
||||
suffixes.push(this.visit(ctx.primarySuffix[0], {
|
||||
shouldDedent:
|
||||
// dedent when simple method invocation
|
||||
countMethodInvocation !== 1 &&
|
||||
// dedent when (chain) method invocation
|
||||
ctx.primaryPrefix[0] &&
|
||||
ctx.primaryPrefix[0].children.fqnOrRefType &&
|
||||
!(ctx.primaryPrefix[0].children.fqnOrRefType[0].children.Dot !==
|
||||
undefined) &&
|
||||
// indent when lambdaExpression
|
||||
ctx.primarySuffix[0].children.methodInvocationSuffix &&
|
||||
ctx.primarySuffix[0].children.methodInvocationSuffix[0].children
|
||||
.argumentList &&
|
||||
ctx.primarySuffix[0].children.methodInvocationSuffix[0].children
|
||||
.argumentList[0].children.expression &&
|
||||
ctx.primarySuffix[0].children.methodInvocationSuffix[0].children
|
||||
.argumentList[0].children.expression[0].children
|
||||
.lambdaExpression === undefined
|
||||
}));
|
||||
for (var i = 1; i < ctx.primarySuffix.length; i++) {
|
||||
if (ctx.primarySuffix[i].children.Dot !== undefined &&
|
||||
ctx.primarySuffix[i - 1].children.methodInvocationSuffix !== undefined) {
|
||||
suffixes.push(softline);
|
||||
}
|
||||
suffixes.push(this.visit(ctx.primarySuffix[i]));
|
||||
}
|
||||
if (countMethodInvocation === 1 &&
|
||||
ctx.primaryPrefix[0].children.newExpression === undefined) {
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndConcat([
|
||||
primaryPrefix,
|
||||
hasFirstInvocationArg ? suffixes[0] : prettier_builder_1.indent(suffixes[0]),
|
||||
prettier_builder_1.indent(printer_utils_1.rejectAndConcat(suffixes.slice(1)))
|
||||
]));
|
||||
}
|
||||
}
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndConcat([primaryPrefix, prettier_builder_1.indent(printer_utils_1.rejectAndConcat(suffixes))]));
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.primaryPrefix = function (ctx, params) {
|
||||
if (ctx.This || ctx.Void) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
}
|
||||
return this.visitSingle(ctx, params);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.primarySuffix = function (ctx, params) {
|
||||
if (ctx.Dot) {
|
||||
if (ctx.This) {
|
||||
return printer_utils_1.rejectAndConcat([ctx.Dot[0], ctx.This[0]]);
|
||||
}
|
||||
else if (ctx.Identifier) {
|
||||
var typeArguments = this.visit(ctx.typeArguments);
|
||||
return printer_utils_1.rejectAndConcat([ctx.Dot[0], typeArguments, ctx.Identifier[0]]);
|
||||
}
|
||||
var unqualifiedClassInstanceCreationExpression = this.visit(ctx.unqualifiedClassInstanceCreationExpression);
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
ctx.Dot[0],
|
||||
unqualifiedClassInstanceCreationExpression
|
||||
]);
|
||||
}
|
||||
return this.visitSingle(ctx, params);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.fqnOrRefType = function (ctx, params) {
|
||||
var fqnOrRefTypePartFirst = this.visit(ctx.fqnOrRefTypePartFirst);
|
||||
var fqnOrRefTypePartRest = this.mapVisit(ctx.fqnOrRefTypePartRest);
|
||||
var dims = this.visit(ctx.dims);
|
||||
var dots = ctx.Dot ? ctx.Dot : [];
|
||||
var isMethodInvocation = ctx.Dot && ctx.Dot.length === 1;
|
||||
if (params !== undefined &&
|
||||
params.shouldBreakBeforeFirstMethodInvocation === true) {
|
||||
// when fqnOrRefType is a method call from an object
|
||||
if (isMethodInvocation) {
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.indent(printer_utils_1.rejectAndJoin(prettier_builder_1.concat([softline, dots[0]]), [
|
||||
fqnOrRefTypePartFirst,
|
||||
printer_utils_1.rejectAndJoinSeps(dots.slice(1), fqnOrRefTypePartRest),
|
||||
dims
|
||||
]))
|
||||
]);
|
||||
// otherwise it is a fully qualified name but we need to exclude when it is just a method call
|
||||
}
|
||||
else if (ctx.Dot) {
|
||||
return prettier_builder_1.indent(printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoinSeps(dots.slice(0, dots.length - 1), __spreadArray([
|
||||
fqnOrRefTypePartFirst
|
||||
], fqnOrRefTypePartRest.slice(0, fqnOrRefTypePartRest.length - 1))),
|
||||
softline,
|
||||
printer_utils_1.rejectAndConcat([
|
||||
dots[dots.length - 1],
|
||||
fqnOrRefTypePartRest[fqnOrRefTypePartRest.length - 1]
|
||||
]),
|
||||
dims
|
||||
]));
|
||||
}
|
||||
}
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoinSeps(dots, __spreadArray([fqnOrRefTypePartFirst], fqnOrRefTypePartRest)),
|
||||
dims
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.fqnOrRefTypePartFirst = function (ctx) {
|
||||
var annotation = this.mapVisit(ctx.annotation);
|
||||
var fqnOrRefTypeCommon = this.visit(ctx.fqnOrRefTypePartCommon);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", annotation),
|
||||
fqnOrRefTypeCommon
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.fqnOrRefTypePartRest = function (ctx) {
|
||||
var annotation = this.mapVisit(ctx.annotation);
|
||||
var fqnOrRefTypeCommon = this.visit(ctx.fqnOrRefTypePartCommon);
|
||||
var typeArguments = this.visit(ctx.typeArguments);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", annotation),
|
||||
printer_utils_1.rejectAndConcat([typeArguments, fqnOrRefTypeCommon])
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.fqnOrRefTypePartCommon = function (ctx) {
|
||||
var keyWord = null;
|
||||
if (ctx.Identifier) {
|
||||
keyWord = ctx.Identifier[0];
|
||||
}
|
||||
else {
|
||||
keyWord = ctx.Super[0];
|
||||
}
|
||||
var typeArguments = this.visit(ctx.typeArguments);
|
||||
return printer_utils_1.rejectAndConcat([keyWord, typeArguments]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.parenthesisExpression = function (ctx) {
|
||||
var expression = this.visit(ctx.expression);
|
||||
return printer_utils_1.putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.castExpression = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.primitiveCastExpression = function (ctx) {
|
||||
var primitiveType = this.visit(ctx.primitiveType);
|
||||
var unaryExpression = this.visit(ctx.unaryExpression);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndConcat([ctx.LBrace[0], primitiveType, ctx.RBrace[0]]),
|
||||
unaryExpression
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.referenceTypeCastExpression = function (ctx) {
|
||||
var referenceType = this.visit(ctx.referenceType);
|
||||
var hasAdditionalBounds = ctx.additionalBound !== undefined;
|
||||
var additionalBounds = printer_utils_1.rejectAndJoin(line, this.mapVisit(ctx.additionalBound));
|
||||
var expression = ctx.lambdaExpression
|
||||
? this.visit(ctx.lambdaExpression)
|
||||
: this.visit(ctx.unaryExpressionNotPlusMinus);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.putIntoBraces(printer_utils_1.rejectAndJoin(line, [referenceType, additionalBounds]), hasAdditionalBounds ? softline : "", ctx.LBrace[0], ctx.RBrace[0]),
|
||||
expression
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.newExpression = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.unqualifiedClassInstanceCreationExpression = function (ctx) {
|
||||
var typeArguments = this.visit(ctx.typeArguments);
|
||||
var classOrInterfaceTypeToInstantiate = this.visit(ctx.classOrInterfaceTypeToInstantiate);
|
||||
var content = utils_2.printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
|
||||
var classBody = this.visit(ctx.classBody);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.New[0],
|
||||
printer_utils_1.rejectAndConcat([
|
||||
typeArguments,
|
||||
classOrInterfaceTypeToInstantiate,
|
||||
content
|
||||
]),
|
||||
classBody
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.classOrInterfaceTypeToInstantiate = function (ctx) {
|
||||
var _this = this;
|
||||
var tokens = printer_utils_1.sortAnnotationIdentifier(ctx.annotation, ctx.Identifier);
|
||||
var segments = [];
|
||||
var currentSegment = [];
|
||||
forEach_1.default(tokens, function (token) {
|
||||
if (utils_1.isAnnotationCstNode(token)) {
|
||||
currentSegment.push(_this.visit([token]));
|
||||
}
|
||||
else {
|
||||
currentSegment.push(token);
|
||||
segments.push(printer_utils_1.rejectAndJoin(" ", currentSegment));
|
||||
currentSegment = [];
|
||||
}
|
||||
});
|
||||
var typeArgumentsOrDiamond = this.visit(ctx.typeArgumentsOrDiamond);
|
||||
var dots = ctx.Dot ? ctx.Dot : [];
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoinSeps(dots, segments),
|
||||
typeArgumentsOrDiamond
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.typeArgumentsOrDiamond = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.diamond = function (ctx) {
|
||||
return prettier_builder_1.concat([ctx.Less[0], ctx.Greater[0]]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.methodInvocationSuffix = function (ctx, params) {
|
||||
var isSingleLambda = expressions_utils_1.isArgumentListSingleLambda(ctx.argumentList);
|
||||
if (isSingleLambda) {
|
||||
return utils_2.printSingleLambdaInvocation.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]);
|
||||
}
|
||||
var argumentList = this.visit(ctx.argumentList);
|
||||
if (params && params.shouldDedent) {
|
||||
return prettier_builder_1.dedent(printer_utils_1.putIntoBraces(argumentList, softline, ctx.LBrace[0], ctx.RBrace[0]));
|
||||
}
|
||||
return printer_utils_1.putIntoBraces(argumentList, softline, ctx.LBrace[0], ctx.RBrace[0]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.argumentList = function (ctx, params) {
|
||||
var expressions = this.mapVisit(ctx.expression, params);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, expressions);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.arrayCreationExpression = function (ctx) {
|
||||
var type = ctx.primitiveType
|
||||
? this.visit(ctx.primitiveType)
|
||||
: this.visit(ctx.classOrInterfaceType);
|
||||
var suffix = ctx.arrayCreationDefaultInitSuffix
|
||||
? this.visit(ctx.arrayCreationDefaultInitSuffix)
|
||||
: this.visit(ctx.arrayCreationExplicitInitSuffix);
|
||||
return printer_utils_1.rejectAndConcat([prettier_builder_1.concat([ctx.New[0], " "]), type, suffix]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.arrayCreationDefaultInitSuffix = function (ctx) {
|
||||
var dimExprs = this.visit(ctx.dimExprs);
|
||||
var dims = this.visit(ctx.dims);
|
||||
return printer_utils_1.rejectAndConcat([dimExprs, dims]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.arrayCreationExplicitInitSuffix = function (ctx) {
|
||||
var dims = this.visit(ctx.dims);
|
||||
var arrayInitializer = this.visit(ctx.arrayInitializer);
|
||||
return printer_utils_1.rejectAndJoin(" ", [dims, arrayInitializer]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.dimExprs = function (ctx) {
|
||||
var dimExpr = this.mapVisit(ctx.dimExpr);
|
||||
return printer_utils_1.rejectAndConcat(dimExpr);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.dimExpr = function (ctx) {
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var expression = this.visit(ctx.expression);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", annotations),
|
||||
printer_utils_1.rejectAndConcat([ctx.LSquare[0], expression, ctx.RSquare[0]])
|
||||
]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.classLiteralSuffix = function (ctx) {
|
||||
var squares = [];
|
||||
if (ctx.LSquare) {
|
||||
for (var i = 0; i < ctx.LSquare.length; i++) {
|
||||
squares.push(prettier_builder_1.concat([ctx.LSquare[i], ctx.RSquare[i]]));
|
||||
}
|
||||
}
|
||||
return printer_utils_1.rejectAndConcat(__spreadArray(__spreadArray([], squares), [ctx.Dot[0], ctx.Class[0]]));
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.arrayAccessSuffix = function (ctx) {
|
||||
var expression = this.visit(ctx.expression);
|
||||
return printer_utils_1.rejectAndConcat([ctx.LSquare[0], expression, ctx.RSquare[0]]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.methodReferenceSuffix = function (ctx) {
|
||||
var typeArguments = this.visit(ctx.typeArguments);
|
||||
var identifierOrNew = ctx.New ? ctx.New[0] : ctx.Identifier[0];
|
||||
return printer_utils_1.rejectAndConcat([ctx.ColonColon[0], typeArguments, identifierOrNew]);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.pattern = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.typePattern = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.identifyNewExpressionType = function () {
|
||||
return "identifyNewExpressionType";
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.isLambdaExpression = function () {
|
||||
return "isLambdaExpression";
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.isCastExpression = function () {
|
||||
return "isCastExpression";
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.isPrimitiveCastExpression = function () {
|
||||
return "isPrimitiveCastExpression";
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.isReferenceTypeCastExpression = function () {
|
||||
return "isReferenceTypeCastExpression";
|
||||
};
|
||||
ExpressionsPrettierVisitor.prototype.isRefTypeInMethodRef = function () {
|
||||
return "isRefTypeInMethodRef";
|
||||
};
|
||||
return ExpressionsPrettierVisitor;
|
||||
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
||||
exports.ExpressionsPrettierVisitor = ExpressionsPrettierVisitor;
|
251
node_modules/prettier-plugin-java/dist/printers/interfaces.js
generated
vendored
Normal file
251
node_modules/prettier-plugin-java/dist/printers/interfaces.js
generated
vendored
Normal file
@@ -0,0 +1,251 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InterfacesPrettierVisitor = void 0;
|
||||
var prettier_builder_1 = require("./prettier-builder");
|
||||
var format_comments_1 = require("./comments/format-comments");
|
||||
var printer_utils_1 = require("./printer-utils");
|
||||
var doc_1 = require("prettier/doc");
|
||||
var base_cst_printer_1 = require("../base-cst-printer");
|
||||
var line = doc_1.builders.line, softline = doc_1.builders.softline, hardline = doc_1.builders.hardline;
|
||||
var InterfacesPrettierVisitor = /** @class */ (function (_super) {
|
||||
__extends(InterfacesPrettierVisitor, _super);
|
||||
function InterfacesPrettierVisitor() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
InterfacesPrettierVisitor.prototype.interfaceDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.interfaceModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var declaration = ctx.normalInterfaceDeclaration
|
||||
? this.visit(ctx.normalInterfaceDeclaration)
|
||||
: this.visit(ctx.annotationTypeDeclaration);
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [printer_utils_1.rejectAndJoin(" ", otherModifiers), declaration])
|
||||
]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.normalInterfaceDeclaration = function (ctx) {
|
||||
var typeIdentifier = this.visit(ctx.typeIdentifier);
|
||||
var typeParameters = this.visit(ctx.typeParameters);
|
||||
var extendsInterfaces = this.visit(ctx.extendsInterfaces);
|
||||
var optionalInterfacePermits = this.visit(ctx.interfacePermits);
|
||||
var interfaceBody = this.visit(ctx.interfaceBody);
|
||||
var extendsInterfacesPart = "";
|
||||
if (extendsInterfaces) {
|
||||
extendsInterfacesPart = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([softline, extendsInterfaces]));
|
||||
}
|
||||
var interfacePermits = "";
|
||||
if (optionalInterfacePermits) {
|
||||
interfacePermits = prettier_builder_1.indent(printer_utils_1.rejectAndConcat([softline, optionalInterfacePermits]));
|
||||
}
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.group(printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.Interface[0],
|
||||
prettier_builder_1.concat([typeIdentifier, typeParameters]),
|
||||
extendsInterfacesPart,
|
||||
interfacePermits
|
||||
])),
|
||||
interfaceBody
|
||||
]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.interfaceModifier = function (ctx) {
|
||||
if (ctx.annotation) {
|
||||
return this.visitSingle(ctx);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.extendsInterfaces = function (ctx) {
|
||||
var interfaceTypeList = this.visit(ctx.interfaceTypeList);
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndConcat([
|
||||
ctx.Extends[0],
|
||||
prettier_builder_1.indent(printer_utils_1.rejectAndConcat([line, interfaceTypeList]))
|
||||
]));
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.interfacePermits = function (ctx) {
|
||||
return this.classPermits(ctx);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.interfaceBody = function (ctx) {
|
||||
var joinedInterfaceMemberDeclaration = "";
|
||||
if (ctx.interfaceMemberDeclaration !== undefined) {
|
||||
var interfaceMemberDeclaration = this.mapVisit(ctx.interfaceMemberDeclaration);
|
||||
var separators = printer_utils_1.getInterfaceBodyDeclarationsSeparator(ctx.interfaceMemberDeclaration);
|
||||
joinedInterfaceMemberDeclaration = printer_utils_1.rejectAndJoinSeps(separators, interfaceMemberDeclaration);
|
||||
}
|
||||
return printer_utils_1.putIntoBraces(joinedInterfaceMemberDeclaration, hardline, ctx.LCurly[0], ctx.RCurly[0]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.interfaceMemberDeclaration = function (ctx) {
|
||||
if (ctx.Semicolon) {
|
||||
return printer_utils_1.displaySemicolon(ctx.Semicolon[0]);
|
||||
}
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.constantDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.constantModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var unannType = this.visit(ctx.unannType);
|
||||
var variableDeclaratorList = this.visit(ctx.variableDeclaratorList);
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", otherModifiers),
|
||||
unannType,
|
||||
printer_utils_1.rejectAndConcat([variableDeclaratorList, ctx.Semicolon[0]])
|
||||
])
|
||||
]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.constantModifier = function (ctx) {
|
||||
if (ctx.annotation) {
|
||||
return this.visitSingle(ctx);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.interfaceMethodDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.interfaceMethodModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var methodHeader = this.visit(ctx.methodHeader);
|
||||
var methodBody = this.visit(ctx.methodBody);
|
||||
var separator = printer_utils_1.isStatementEmptyStatement(methodBody) ? "" : " ";
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", otherModifiers),
|
||||
printer_utils_1.rejectAndJoin(separator, [methodHeader, methodBody])
|
||||
])
|
||||
]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.interfaceMethodModifier = function (ctx) {
|
||||
if (ctx.annotation) {
|
||||
return this.visitSingle(ctx);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.annotationTypeDeclaration = function (ctx) {
|
||||
var typeIdentifier = this.visit(ctx.typeIdentifier);
|
||||
var annotationTypeBody = this.visit(ctx.annotationTypeBody);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.concat([ctx.At[0], ctx.Interface[0]]),
|
||||
typeIdentifier,
|
||||
annotationTypeBody
|
||||
]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.annotationTypeBody = function (ctx) {
|
||||
var annotationTypeMemberDeclaration = this.mapVisit(ctx.annotationTypeMemberDeclaration);
|
||||
return printer_utils_1.rejectAndJoin(line, [
|
||||
prettier_builder_1.indent(printer_utils_1.rejectAndJoin(line, [
|
||||
ctx.LCurly[0],
|
||||
printer_utils_1.rejectAndJoin(prettier_builder_1.concat([line, line]), annotationTypeMemberDeclaration)
|
||||
])),
|
||||
ctx.RCurly[0]
|
||||
]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.annotationTypeMemberDeclaration = function (ctx) {
|
||||
if (ctx.Semicolon) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
}
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.annotationTypeElementDeclaration = function (ctx) {
|
||||
var modifiers = printer_utils_1.sortModifiers(ctx.annotationTypeElementModifier);
|
||||
var firstAnnotations = this.mapVisit(modifiers[0]);
|
||||
var otherModifiers = this.mapVisit(modifiers[1]);
|
||||
var unannType = this.visit(ctx.unannType);
|
||||
var identifier = ctx.Identifier[0];
|
||||
var dims = this.visit(ctx.dims);
|
||||
var defaultValue = ctx.defaultValue
|
||||
? prettier_builder_1.concat([" ", this.visit(ctx.defaultValue)])
|
||||
: "";
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, firstAnnotations),
|
||||
printer_utils_1.rejectAndJoin(" ", [
|
||||
printer_utils_1.rejectAndJoin(" ", otherModifiers),
|
||||
unannType,
|
||||
printer_utils_1.rejectAndConcat([
|
||||
identifier,
|
||||
prettier_builder_1.concat([ctx.LBrace[0], ctx.RBrace[0]]),
|
||||
dims,
|
||||
defaultValue,
|
||||
ctx.Semicolon[0]
|
||||
])
|
||||
])
|
||||
]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.annotationTypeElementModifier = function (ctx) {
|
||||
if (ctx.annotation) {
|
||||
return this.visitSingle(ctx);
|
||||
}
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.defaultValue = function (ctx) {
|
||||
var elementValue = this.visit(ctx.elementValue);
|
||||
return printer_utils_1.rejectAndJoin(" ", [ctx.Default[0], elementValue]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.annotation = function (ctx) {
|
||||
var fqn = this.visit(ctx.typeName);
|
||||
var annoArgs = "";
|
||||
if (ctx.LBrace) {
|
||||
if (ctx.elementValuePairList) {
|
||||
annoArgs = printer_utils_1.putIntoBraces(this.visit(ctx.elementValuePairList), softline, ctx.LBrace[0], ctx.RBrace[0]);
|
||||
}
|
||||
else if (ctx.elementValue) {
|
||||
annoArgs = printer_utils_1.putIntoBraces(this.visit(ctx.elementValue), softline, ctx.LBrace[0], ctx.RBrace[0]);
|
||||
}
|
||||
}
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndConcat([ctx.At[0], fqn, annoArgs]));
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.elementValuePairList = function (ctx) {
|
||||
var elementValuePairs = this.mapVisit(ctx.elementValuePair);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, elementValuePairs);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.elementValuePair = function (ctx) {
|
||||
var identifier = ctx.Identifier[0];
|
||||
var elementValue = this.visit(ctx.elementValue);
|
||||
return printer_utils_1.rejectAndJoin(" ", [identifier, ctx.Equals[0], elementValue]);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.elementValue = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.elementValueArrayInitializer = function (ctx) {
|
||||
var elementValueList = this.visit(ctx.elementValueList);
|
||||
return printer_utils_1.printArrayList({
|
||||
list: elementValueList,
|
||||
extraComma: ctx.Comma,
|
||||
LCurly: ctx.LCurly[0],
|
||||
RCurly: ctx.RCurly[0],
|
||||
trailingComma: this.prettierOptions.trailingComma
|
||||
});
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.elementValueList = function (ctx) {
|
||||
var elementValues = this.mapVisit(ctx.elementValue);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return prettier_builder_1.group(printer_utils_1.rejectAndConcat([printer_utils_1.rejectAndJoinSeps(commas, elementValues)]));
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.identifyInterfaceBodyDeclarationType = function () {
|
||||
return "identifyInterfaceBodyDeclarationType";
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.identifyAnnotationBodyDeclarationType = function () {
|
||||
return "identifyAnnotationBodyDeclarationType";
|
||||
};
|
||||
InterfacesPrettierVisitor.prototype.isSimpleElementValueAnnotation = function () {
|
||||
return "isSimpleElementValueAnnotation";
|
||||
};
|
||||
return InterfacesPrettierVisitor;
|
||||
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
||||
exports.InterfacesPrettierVisitor = InterfacesPrettierVisitor;
|
43
node_modules/prettier-plugin-java/dist/printers/lexical-structure.js
generated
vendored
Normal file
43
node_modules/prettier-plugin-java/dist/printers/lexical-structure.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LexicalStructurePrettierVisitor = void 0;
|
||||
var format_comments_1 = require("./comments/format-comments");
|
||||
var base_cst_printer_1 = require("../base-cst-printer");
|
||||
var LexicalStructurePrettierVisitor = /** @class */ (function (_super) {
|
||||
__extends(LexicalStructurePrettierVisitor, _super);
|
||||
function LexicalStructurePrettierVisitor() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
LexicalStructurePrettierVisitor.prototype.literal = function (ctx) {
|
||||
if (ctx.CharLiteral || ctx.TextBlock || ctx.StringLiteral || ctx.Null) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
}
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
LexicalStructurePrettierVisitor.prototype.integerLiteral = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
LexicalStructurePrettierVisitor.prototype.floatingPointLiteral = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
LexicalStructurePrettierVisitor.prototype.booleanLiteral = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
return LexicalStructurePrettierVisitor;
|
||||
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
||||
exports.LexicalStructurePrettierVisitor = LexicalStructurePrettierVisitor;
|
53
node_modules/prettier-plugin-java/dist/printers/names.js
generated
vendored
Normal file
53
node_modules/prettier-plugin-java/dist/printers/names.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NamesPrettierVisitor = void 0;
|
||||
var printer_utils_1 = require("./printer-utils");
|
||||
var format_comments_1 = require("./comments/format-comments");
|
||||
var base_cst_printer_1 = require("../base-cst-printer");
|
||||
var NamesPrettierVisitor = /** @class */ (function (_super) {
|
||||
__extends(NamesPrettierVisitor, _super);
|
||||
function NamesPrettierVisitor() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
NamesPrettierVisitor.prototype.typeIdentifier = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(ctx.Identifier[0]);
|
||||
};
|
||||
NamesPrettierVisitor.prototype.moduleName = function (ctx) {
|
||||
return printer_utils_1.buildFqn(ctx.Identifier, ctx.Dot);
|
||||
};
|
||||
NamesPrettierVisitor.prototype.packageName = function (ctx) {
|
||||
return printer_utils_1.buildFqn(ctx.Identifier, ctx.Dot);
|
||||
};
|
||||
NamesPrettierVisitor.prototype.typeName = function (ctx) {
|
||||
return printer_utils_1.buildFqn(ctx.Identifier, ctx.Dot);
|
||||
};
|
||||
NamesPrettierVisitor.prototype.expressionName = function (ctx) {
|
||||
return printer_utils_1.buildFqn(ctx.Identifier, ctx.Dot);
|
||||
};
|
||||
NamesPrettierVisitor.prototype.methodName = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(ctx.Identifier[0]);
|
||||
};
|
||||
NamesPrettierVisitor.prototype.packageOrTypeName = function (ctx) {
|
||||
return printer_utils_1.buildFqn(ctx.Identifier, ctx.Dot);
|
||||
};
|
||||
NamesPrettierVisitor.prototype.ambiguousName = function (ctx) {
|
||||
return printer_utils_1.buildFqn(ctx.Identifier, ctx.Dot);
|
||||
};
|
||||
return NamesPrettierVisitor;
|
||||
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
||||
exports.NamesPrettierVisitor = NamesPrettierVisitor;
|
185
node_modules/prettier-plugin-java/dist/printers/packages-and-modules.js
generated
vendored
Normal file
185
node_modules/prettier-plugin-java/dist/printers/packages-and-modules.js
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PackagesAndModulesPrettierVisitor = void 0;
|
||||
var prettier_builder_1 = require("./prettier-builder");
|
||||
var format_comments_1 = require("./comments/format-comments");
|
||||
var printer_utils_1 = require("./printer-utils");
|
||||
var doc_1 = require("prettier/doc");
|
||||
var base_cst_printer_1 = require("../base-cst-printer");
|
||||
var utils_1 = require("../types/utils");
|
||||
var line = doc_1.builders.line, hardline = doc_1.builders.hardline, indent = doc_1.builders.indent, group = doc_1.builders.group;
|
||||
var PackagesAndModulesPrettierVisitor = /** @class */ (function (_super) {
|
||||
__extends(PackagesAndModulesPrettierVisitor, _super);
|
||||
function PackagesAndModulesPrettierVisitor() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
PackagesAndModulesPrettierVisitor.prototype.compilationUnit = function (ctx) {
|
||||
var compilationUnit = utils_1.isOrdinaryCompilationUnitCtx(ctx)
|
||||
? ctx.ordinaryCompilationUnit
|
||||
: ctx.modularCompilationUnit;
|
||||
return prettier_builder_1.concat([this.visit(compilationUnit[0]), line]);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.ordinaryCompilationUnit = function (ctx) {
|
||||
var packageDecl = this.visit(ctx.packageDeclaration);
|
||||
var sortedImportsDecl = printer_utils_1.sortImports(ctx.importDeclaration);
|
||||
var nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
|
||||
var staticImports = this.mapVisit(sortedImportsDecl.staticImports);
|
||||
var typesDecl = this.mapVisit(ctx.typeDeclaration);
|
||||
// TODO: utility to add item+line (or multiple lines) but only if an item exists
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(prettier_builder_1.concat([hardline, hardline]), [
|
||||
packageDecl,
|
||||
printer_utils_1.rejectAndJoin(hardline, staticImports),
|
||||
printer_utils_1.rejectAndJoin(hardline, nonStaticImports),
|
||||
printer_utils_1.rejectAndJoin(prettier_builder_1.concat([hardline, hardline]), typesDecl)
|
||||
])
|
||||
]);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.modularCompilationUnit = function (ctx) {
|
||||
var sortedImportsDecl = printer_utils_1.sortImports(ctx.importDeclaration);
|
||||
var nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports);
|
||||
var staticImports = this.mapVisit(sortedImportsDecl.staticImports);
|
||||
var moduleDeclaration = this.visit(ctx.moduleDeclaration);
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(prettier_builder_1.concat([hardline, hardline]), [
|
||||
printer_utils_1.rejectAndJoin(hardline, staticImports),
|
||||
printer_utils_1.rejectAndJoin(hardline, nonStaticImports),
|
||||
moduleDeclaration
|
||||
])
|
||||
]);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.packageDeclaration = function (ctx) {
|
||||
var modifiers = this.mapVisit(ctx.packageModifier);
|
||||
var name = printer_utils_1.buildFqn(ctx.Identifier, ctx.Dot);
|
||||
return printer_utils_1.rejectAndJoin(hardline, [
|
||||
printer_utils_1.rejectAndJoin(hardline, modifiers),
|
||||
prettier_builder_1.concat([ctx.Package[0], " ", name, ctx.Semicolon[0]])
|
||||
]);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.packageModifier = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.importDeclaration = function (ctx) {
|
||||
if (ctx.emptyStatement !== undefined) {
|
||||
return this.visit(ctx.emptyStatement);
|
||||
}
|
||||
var optionalStatic = ctx.Static ? ctx.Static[0] : "";
|
||||
var packageOrTypeName = this.visit(ctx.packageOrTypeName);
|
||||
var optionalDotStar = ctx.Dot ? prettier_builder_1.concat([ctx.Dot[0], ctx.Star[0]]) : "";
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.Import[0],
|
||||
optionalStatic,
|
||||
printer_utils_1.rejectAndConcat([packageOrTypeName, optionalDotStar, ctx.Semicolon[0]])
|
||||
]);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.typeDeclaration = function (ctx) {
|
||||
if (ctx.Semicolon) {
|
||||
return printer_utils_1.displaySemicolon(ctx.Semicolon[0]);
|
||||
}
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.moduleDeclaration = function (ctx) {
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var optionalOpen = ctx.Open ? ctx.Open[0] : "";
|
||||
var name = printer_utils_1.buildFqn(ctx.Identifier, ctx.Dot);
|
||||
var moduleDirectives = this.mapVisit(ctx.moduleDirective);
|
||||
var content = printer_utils_1.rejectAndJoinSeps(printer_utils_1.getBlankLinesSeparator(ctx.moduleDirective), moduleDirectives);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.join(" ", annotations),
|
||||
optionalOpen,
|
||||
ctx.Module[0],
|
||||
name,
|
||||
printer_utils_1.putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0])
|
||||
]);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.moduleDirective = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.requiresModuleDirective = function (ctx) {
|
||||
var modifiers = this.mapVisit(ctx.requiresModifier);
|
||||
var moduleName = this.visit(ctx.moduleName);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.Requires[0],
|
||||
prettier_builder_1.join(" ", modifiers),
|
||||
prettier_builder_1.concat([moduleName, ctx.Semicolon[0]])
|
||||
]);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.exportsModuleDirective = function (ctx) {
|
||||
var packageName = this.visit(ctx.packageName);
|
||||
var to = ctx.To ? ctx.To[0] : "";
|
||||
var moduleNames = this.mapVisit(ctx.moduleName);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return group(printer_utils_1.rejectAndConcat([
|
||||
indent(printer_utils_1.rejectAndJoin(line, [
|
||||
printer_utils_1.rejectAndJoin(" ", [ctx.Exports[0], packageName]),
|
||||
group(indent(printer_utils_1.rejectAndJoin(line, [
|
||||
to,
|
||||
printer_utils_1.rejectAndJoinSeps(commas, moduleNames)
|
||||
])))
|
||||
])),
|
||||
ctx.Semicolon[0]
|
||||
]));
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.opensModuleDirective = function (ctx) {
|
||||
var packageName = this.visit(ctx.packageName);
|
||||
var to = ctx.To ? ctx.To[0] : "";
|
||||
var moduleNames = this.mapVisit(ctx.moduleName);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return group(printer_utils_1.rejectAndConcat([
|
||||
indent(printer_utils_1.rejectAndJoin(line, [
|
||||
printer_utils_1.rejectAndJoin(" ", [ctx.Opens[0], packageName]),
|
||||
group(indent(printer_utils_1.rejectAndJoin(line, [
|
||||
to,
|
||||
printer_utils_1.rejectAndJoinSeps(commas, moduleNames)
|
||||
])))
|
||||
])),
|
||||
ctx.Semicolon[0]
|
||||
]));
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.usesModuleDirective = function (ctx) {
|
||||
var typeName = this.visit(ctx.typeName);
|
||||
return printer_utils_1.rejectAndConcat([
|
||||
prettier_builder_1.concat([ctx.Uses[0], " "]),
|
||||
typeName,
|
||||
ctx.Semicolon[0]
|
||||
]);
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.providesModuleDirective = function (ctx) {
|
||||
var firstTypeName = this.visit(ctx.typeName[0]);
|
||||
var otherTypeNames = this.mapVisit(ctx.typeName.slice(1));
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, line]); }) : [];
|
||||
return group(printer_utils_1.rejectAndConcat([
|
||||
indent(printer_utils_1.rejectAndJoin(line, [
|
||||
printer_utils_1.rejectAndJoin(" ", [ctx.Provides[0], firstTypeName]),
|
||||
group(indent(printer_utils_1.rejectAndJoin(line, [
|
||||
ctx.With[0],
|
||||
printer_utils_1.rejectAndJoinSeps(commas, otherTypeNames)
|
||||
])))
|
||||
])),
|
||||
ctx.Semicolon[0]
|
||||
]));
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.requiresModifier = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
PackagesAndModulesPrettierVisitor.prototype.isModuleCompilationUnit = function () {
|
||||
return "isModuleCompilationUnit";
|
||||
};
|
||||
return PackagesAndModulesPrettierVisitor;
|
||||
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
||||
exports.PackagesAndModulesPrettierVisitor = PackagesAndModulesPrettierVisitor;
|
44
node_modules/prettier-plugin-java/dist/printers/prettier-builder.js
generated
vendored
Normal file
44
node_modules/prettier-plugin-java/dist/printers/prettier-builder.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
var prettier = require("prettier").doc.builders;
|
||||
var processComments = require("./comments/format-comments").processComments;
|
||||
/*
|
||||
* ------------------------------------------------------------------
|
||||
* Wraps the Prettier builder functions to print tokens with comments
|
||||
* ------------------------------------------------------------------
|
||||
*/
|
||||
function concat(docs) {
|
||||
var concatenation = prettier.concat(processComments(docs));
|
||||
return concatenation.parts.length === 0 ? "" : concatenation;
|
||||
}
|
||||
function join(sep, docs) {
|
||||
var concatenation = prettier.join(processComments(sep), processComments(docs));
|
||||
return concatenation.parts.length === 0 ? "" : concatenation;
|
||||
}
|
||||
function group(doc, opts) {
|
||||
var group = prettier.group(processComments(doc), opts);
|
||||
return group.contents === undefined ? "" : group;
|
||||
}
|
||||
function fill(docs) {
|
||||
var fill = prettier.fill(processComments(docs));
|
||||
return fill.parts.length === 0 ? "" : fill;
|
||||
}
|
||||
function indent(doc) {
|
||||
var indentedDoc = prettier.indent(processComments(doc));
|
||||
return indentedDoc.contents.length === 0 ? "" : indentedDoc;
|
||||
}
|
||||
function dedent(doc) {
|
||||
var indentedDoc = prettier.dedent(processComments(doc));
|
||||
return indentedDoc.contents.length === 0 ? "" : indentedDoc;
|
||||
}
|
||||
function ifBreak(breakContents, flatContents) {
|
||||
return prettier.ifBreak(processComments(breakContents), processComments(flatContents));
|
||||
}
|
||||
module.exports = {
|
||||
concat: concat,
|
||||
join: join,
|
||||
group: group,
|
||||
fill: fill,
|
||||
indent: indent,
|
||||
dedent: dedent,
|
||||
ifBreak: ifBreak
|
||||
};
|
565
node_modules/prettier-plugin-java/dist/printers/printer-utils.js
generated
vendored
Normal file
565
node_modules/prettier-plugin-java/dist/printers/printer-utils.js
generated
vendored
Normal file
@@ -0,0 +1,565 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
||||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
||||
to[j] = from[i];
|
||||
return to;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.printArrayList = exports.isUniqueMethodInvocation = exports.sortImports = exports.isStatementEmptyStatement = exports.isShiftOperator = exports.separateTokensIntoGroups = exports.putIntoBraces = exports.getInterfaceBodyDeclarationsSeparator = exports.getClassBodyDeclarationsSeparator = exports.getBlankLinesSeparator = exports.isExplicitLambdaParameter = exports.displaySemicolon = exports.findDeepElementInPartsArray = exports.sortModifiers = exports.sortClassTypeChildren = exports.matchCategory = exports.sortNodes = exports.sortAnnotationIdentifier = exports.rejectAndConcat = exports.rejectAndJoin = exports.rejectSeparators = exports.reject = exports.rejectAndJoinSeps = exports.buildFqn = void 0;
|
||||
var forEach_1 = __importDefault(require("lodash/forEach"));
|
||||
var forEachRight_1 = __importDefault(require("lodash/forEachRight"));
|
||||
var findLastIndex_1 = __importDefault(require("lodash/findLastIndex"));
|
||||
var findIndex_1 = __importDefault(require("lodash/findIndex"));
|
||||
var includes_1 = __importDefault(require("lodash/includes"));
|
||||
var prettier_builder_1 = require("./prettier-builder");
|
||||
var format_comments_1 = require("./comments/format-comments");
|
||||
var comments_utils_1 = require("./comments/comments-utils");
|
||||
var doc_1 = require("prettier/doc");
|
||||
var utils_1 = require("../types/utils");
|
||||
var indent = doc_1.builders.indent, hardline = doc_1.builders.hardline, line = doc_1.builders.line;
|
||||
var isConcat = doc_1.utils.isConcat;
|
||||
var orderedModifiers = [
|
||||
"Public",
|
||||
"Protected",
|
||||
"Private",
|
||||
"Abstract",
|
||||
"Default",
|
||||
"Static",
|
||||
"Final",
|
||||
"Transient",
|
||||
"Volatile",
|
||||
"Synchronized",
|
||||
"Native",
|
||||
"Sealed",
|
||||
"NonSealed",
|
||||
"Strictfp"
|
||||
];
|
||||
function buildFqn(tokens, dots) {
|
||||
return rejectAndJoinSeps(dots ? dots : [], tokens);
|
||||
}
|
||||
exports.buildFqn = buildFqn;
|
||||
function rejectAndJoinSeps(sepTokens, elems, sep) {
|
||||
if (!Array.isArray(sepTokens)) {
|
||||
return rejectAndJoin(sepTokens, elems);
|
||||
}
|
||||
var actualElements = reject(elems);
|
||||
var res = [];
|
||||
for (var i = 0; i < sepTokens.length; i++) {
|
||||
res.push(actualElements[i], sepTokens[i]);
|
||||
if (sep) {
|
||||
res.push(sep);
|
||||
}
|
||||
}
|
||||
res.push.apply(res, actualElements.slice(sepTokens.length));
|
||||
return prettier_builder_1.concat(res);
|
||||
}
|
||||
exports.rejectAndJoinSeps = rejectAndJoinSeps;
|
||||
function reject(elems) {
|
||||
return elems.filter(function (item) {
|
||||
if (typeof item === "string") {
|
||||
return item !== "";
|
||||
}
|
||||
// eslint-ignore next - We want the conversion to boolean!
|
||||
// @ts-ignore
|
||||
return item != false && item !== undefined;
|
||||
});
|
||||
}
|
||||
exports.reject = reject;
|
||||
function rejectSeparators(separators, elems) {
|
||||
var realElements = reject(elems);
|
||||
var realSeparators = [];
|
||||
for (var i = 0; i < realElements.length - 1; i++) {
|
||||
if (realElements[i] !== "") {
|
||||
realSeparators.push(separators[i]);
|
||||
}
|
||||
}
|
||||
return realSeparators;
|
||||
}
|
||||
exports.rejectSeparators = rejectSeparators;
|
||||
function rejectAndJoin(sep, elems) {
|
||||
var actualElements = reject(elems);
|
||||
return prettier_builder_1.join(sep, actualElements);
|
||||
}
|
||||
exports.rejectAndJoin = rejectAndJoin;
|
||||
function rejectAndConcat(elems) {
|
||||
var actualElements = reject(elems);
|
||||
return prettier_builder_1.concat(actualElements);
|
||||
}
|
||||
exports.rejectAndConcat = rejectAndConcat;
|
||||
function sortAnnotationIdentifier(annotations, identifiers) {
|
||||
var tokens = __spreadArray([], identifiers);
|
||||
if (annotations && annotations.length > 0) {
|
||||
tokens = __spreadArray(__spreadArray([], tokens), annotations);
|
||||
}
|
||||
return tokens.sort(function (a, b) {
|
||||
var startOffset1 = utils_1.isCstNode(a)
|
||||
? a.children.At[0].startOffset
|
||||
: a.startOffset;
|
||||
var startOffset2 = utils_1.isCstNode(b)
|
||||
? b.children.At[0].startOffset
|
||||
: b.startOffset;
|
||||
return startOffset1 - startOffset2;
|
||||
});
|
||||
}
|
||||
exports.sortAnnotationIdentifier = sortAnnotationIdentifier;
|
||||
function sortTokens(values) {
|
||||
var tokens = [];
|
||||
forEach_1.default(values, function (argument) {
|
||||
if (argument) {
|
||||
tokens = tokens.concat(argument);
|
||||
}
|
||||
});
|
||||
return tokens.sort(function (a, b) {
|
||||
return a.startOffset - b.startOffset;
|
||||
});
|
||||
}
|
||||
function sortNodes(values) {
|
||||
var nodes = [];
|
||||
forEach_1.default(values, function (argument) {
|
||||
if (argument) {
|
||||
nodes = nodes.concat(argument);
|
||||
}
|
||||
});
|
||||
return nodes.sort(function (a, b) {
|
||||
var aOffset = a.location.startOffset;
|
||||
var bOffset = b.location.startOffset;
|
||||
return aOffset - bOffset;
|
||||
});
|
||||
}
|
||||
exports.sortNodes = sortNodes;
|
||||
function matchCategory(token, categoryName) {
|
||||
var labels = (token.tokenType.CATEGORIES || []).map(function (category) {
|
||||
return category.LABEL;
|
||||
});
|
||||
return labels.indexOf(categoryName) !== -1;
|
||||
}
|
||||
exports.matchCategory = matchCategory;
|
||||
function sortClassTypeChildren(annotations, typeArguments, identifiers, dots) {
|
||||
var tokens = __spreadArray([], identifiers);
|
||||
if (annotations && annotations.length > 0) {
|
||||
tokens = __spreadArray(__spreadArray([], tokens), annotations);
|
||||
}
|
||||
if (typeArguments && typeArguments.length > 0) {
|
||||
tokens = __spreadArray(__spreadArray([], tokens), typeArguments);
|
||||
}
|
||||
if (dots && dots.length > 0) {
|
||||
tokens = __spreadArray(__spreadArray([], tokens), dots);
|
||||
}
|
||||
return tokens.sort(function (a, b) {
|
||||
var startOffsetA = utils_1.isCstNode(a)
|
||||
? a.children.At
|
||||
? a.children.At[0].startOffset
|
||||
: a.children.Less[0].startOffset
|
||||
: a.startOffset;
|
||||
var startOffsetB = utils_1.isCstNode(b)
|
||||
? b.children.At
|
||||
? b.children.At[0].startOffset
|
||||
: b.children.Less[0].startOffset
|
||||
: b.startOffset;
|
||||
return startOffsetA - startOffsetB;
|
||||
});
|
||||
}
|
||||
exports.sortClassTypeChildren = sortClassTypeChildren;
|
||||
function sortModifiers(modifiers) {
|
||||
var firstAnnotations = [];
|
||||
var otherModifiers = [];
|
||||
var lastAnnotations = [];
|
||||
var hasOtherModifier = false;
|
||||
/**
|
||||
* iterate in reverse order because we special-case
|
||||
* method annotations which come after all other
|
||||
* modifiers
|
||||
*/
|
||||
forEachRight_1.default(modifiers, function (modifier) {
|
||||
var isAnnotation = modifier.children.annotation !== undefined;
|
||||
var isMethodAnnotation = isAnnotation &&
|
||||
(modifier.name === "methodModifier" ||
|
||||
modifier.name === "interfaceMethodModifier");
|
||||
if (isAnnotation) {
|
||||
if (isMethodAnnotation && !hasOtherModifier) {
|
||||
lastAnnotations.unshift(modifier);
|
||||
}
|
||||
else {
|
||||
firstAnnotations.unshift(modifier);
|
||||
}
|
||||
}
|
||||
else {
|
||||
otherModifiers.unshift(modifier);
|
||||
hasOtherModifier = true;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* if there are only annotations, move everything from
|
||||
* lastAnnotations to firstAnnotations
|
||||
*/
|
||||
if (!hasOtherModifier) {
|
||||
firstAnnotations = firstAnnotations.concat(lastAnnotations);
|
||||
lastAnnotations = [];
|
||||
}
|
||||
otherModifiers.sort(function (a, b) {
|
||||
var modifierIndexA = orderedModifiers.indexOf(Object.keys(a.children)[0]);
|
||||
var modifierIndexB = orderedModifiers.indexOf(Object.keys(b.children)[0]);
|
||||
return modifierIndexA - modifierIndexB;
|
||||
});
|
||||
return [firstAnnotations, otherModifiers.concat(lastAnnotations)];
|
||||
}
|
||||
exports.sortModifiers = sortModifiers;
|
||||
function findDeepElementInPartsArray(item, elt) {
|
||||
if (Array.isArray(item)) {
|
||||
if (includes_1.default(item, elt)) {
|
||||
return true;
|
||||
}
|
||||
for (var i = 0; i < item.length; i++) {
|
||||
if (findDeepElementInPartsArray(item[i], elt)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var key in item) {
|
||||
if (typeof item[key] === "object" &&
|
||||
findDeepElementInPartsArray(item[key], elt)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.findDeepElementInPartsArray = findDeepElementInPartsArray;
|
||||
function displaySemicolon(token, params) {
|
||||
if (params !== undefined && params.allowEmptyStatement) {
|
||||
return format_comments_1.printTokenWithComments(token);
|
||||
}
|
||||
if (!comments_utils_1.hasComments(token)) {
|
||||
return "";
|
||||
}
|
||||
token.image = "";
|
||||
return format_comments_1.printTokenWithComments(token);
|
||||
}
|
||||
exports.displaySemicolon = displaySemicolon;
|
||||
function isExplicitLambdaParameter(ctx) {
|
||||
return (ctx &&
|
||||
ctx.lambdaParameterList &&
|
||||
ctx.lambdaParameterList[0] &&
|
||||
ctx.lambdaParameterList[0].children &&
|
||||
ctx.lambdaParameterList[0].children.explicitLambdaParameterList);
|
||||
}
|
||||
exports.isExplicitLambdaParameter = isExplicitLambdaParameter;
|
||||
function getBlankLinesSeparator(ctx, separator) {
|
||||
if (separator === void 0) { separator = hardline; }
|
||||
if (ctx === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
var separators = [];
|
||||
for (var i = 0; i < ctx.length - 1; i++) {
|
||||
var node = ctx[i];
|
||||
var previousRuleEndLineWithComment = comments_utils_1.hasTrailingComments(node)
|
||||
? node.trailingComments[node.trailingComments.length - 1].endLine
|
||||
: node.location.endLine;
|
||||
var nextNode = ctx[i + 1];
|
||||
var nextRuleStartLineWithComment = comments_utils_1.hasLeadingComments(nextNode)
|
||||
? nextNode.leadingComments[0].startLine
|
||||
: nextNode.location.startLine;
|
||||
if (nextRuleStartLineWithComment - previousRuleEndLineWithComment > 1) {
|
||||
separators.push(prettier_builder_1.concat([hardline, hardline]));
|
||||
}
|
||||
else {
|
||||
separators.push(separator);
|
||||
}
|
||||
}
|
||||
return separators;
|
||||
}
|
||||
exports.getBlankLinesSeparator = getBlankLinesSeparator;
|
||||
function getDeclarationsSeparator(declarations, needLineDeclaration, isSemicolon) {
|
||||
var declarationsWithoutEmptyStatements = declarations.filter(function (declaration) { return !isSemicolon(declaration); });
|
||||
var userBlankLinesSeparators = getBlankLinesSeparator(declarationsWithoutEmptyStatements);
|
||||
var additionalBlankLines = declarationsWithoutEmptyStatements.map(needLineDeclaration);
|
||||
var separators = [];
|
||||
var indexNextNotEmptyDeclaration = 0;
|
||||
for (var i = 0; i < declarations.length - 1; i++) {
|
||||
// if the empty statement has comments
|
||||
// we want to print them on their own line
|
||||
if (isSemicolon(declarations[i])) {
|
||||
if (comments_utils_1.hasComments(declarations[i])) {
|
||||
separators.push(hardline);
|
||||
}
|
||||
}
|
||||
else if (indexNextNotEmptyDeclaration <
|
||||
declarationsWithoutEmptyStatements.length - 1) {
|
||||
var isTwoHardLines =
|
||||
// @ts-ignore
|
||||
userBlankLinesSeparators[indexNextNotEmptyDeclaration].parts[0].type ===
|
||||
"concat";
|
||||
var additionalSep = !isTwoHardLines &&
|
||||
(additionalBlankLines[indexNextNotEmptyDeclaration + 1] ||
|
||||
additionalBlankLines[indexNextNotEmptyDeclaration])
|
||||
? hardline
|
||||
: "";
|
||||
separators.push(prettier_builder_1.concat([
|
||||
userBlankLinesSeparators[indexNextNotEmptyDeclaration],
|
||||
additionalSep
|
||||
]));
|
||||
indexNextNotEmptyDeclaration += 1;
|
||||
}
|
||||
}
|
||||
return separators;
|
||||
}
|
||||
function needLineClassBodyDeclaration(declaration) {
|
||||
if (declaration.children.classMemberDeclaration === undefined) {
|
||||
return true;
|
||||
}
|
||||
var classMemberDeclaration = declaration.children.classMemberDeclaration[0];
|
||||
if (classMemberDeclaration.children.fieldDeclaration !== undefined) {
|
||||
var fieldDeclaration = classMemberDeclaration.children.fieldDeclaration[0];
|
||||
if (fieldDeclaration.children.fieldModifier !== undefined &&
|
||||
hasAnnotation(fieldDeclaration.children.fieldModifier)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (classMemberDeclaration.children.Semicolon !== undefined) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function needLineInterfaceMemberDeclaration(declaration) {
|
||||
if (declaration.children.constantDeclaration !== undefined) {
|
||||
var constantDeclaration = declaration.children.constantDeclaration[0];
|
||||
if (constantDeclaration.children.constantModifier !== undefined &&
|
||||
hasAnnotation(constantDeclaration.children.constantModifier)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (declaration.children.interfaceMethodDeclaration !== undefined) {
|
||||
var interfaceMethodDeclaration = declaration.children.interfaceMethodDeclaration[0];
|
||||
if (interfaceMethodDeclaration.children.interfaceMethodModifier !==
|
||||
undefined &&
|
||||
hasNonTrailingAnnotation(interfaceMethodDeclaration.children.interfaceMethodModifier)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function isClassBodyDeclarationASemicolon(classBodyDeclaration) {
|
||||
if (classBodyDeclaration.children.classMemberDeclaration) {
|
||||
if (classBodyDeclaration.children.classMemberDeclaration[0].children
|
||||
.Semicolon !== undefined) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isInterfaceMemberASemicolon(interfaceMemberDeclaration) {
|
||||
return interfaceMemberDeclaration.children.Semicolon !== undefined;
|
||||
}
|
||||
function hasAnnotation(modifiers) {
|
||||
return modifiers.some(function (modifier) { return modifier.children.annotation !== undefined; });
|
||||
}
|
||||
/**
|
||||
* Return true if there is a method modifier that does not come after all other modifiers
|
||||
* It is useful to know if sortModifiers will add an annotation before other modifiers
|
||||
*
|
||||
* @param methodModifiers
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasNonTrailingAnnotation(methodModifiers) {
|
||||
var firstAnnotationIndex = findIndex_1.default(methodModifiers, function (modifier) { return modifier.children.annotation !== undefined; });
|
||||
var lastNonAnnotationIndex = findLastIndex_1.default(methodModifiers, function (modifier) { return modifier.children.annotation === undefined; });
|
||||
return (firstAnnotationIndex < lastNonAnnotationIndex ||
|
||||
lastNonAnnotationIndex === -1);
|
||||
}
|
||||
function getClassBodyDeclarationsSeparator(classBodyDeclarationContext) {
|
||||
return getDeclarationsSeparator(classBodyDeclarationContext, needLineClassBodyDeclaration, isClassBodyDeclarationASemicolon);
|
||||
}
|
||||
exports.getClassBodyDeclarationsSeparator = getClassBodyDeclarationsSeparator;
|
||||
function getInterfaceBodyDeclarationsSeparator(interfaceMemberDeclarationContext) {
|
||||
return getDeclarationsSeparator(interfaceMemberDeclarationContext, needLineInterfaceMemberDeclaration, isInterfaceMemberASemicolon);
|
||||
}
|
||||
exports.getInterfaceBodyDeclarationsSeparator = getInterfaceBodyDeclarationsSeparator;
|
||||
function putIntoBraces(argument, separator, LBrace, RBrace) {
|
||||
var rightBraceLeadingComments = format_comments_1.getTokenLeadingComments(RBrace);
|
||||
var lastBreakLine =
|
||||
// check if last element of the array is a line
|
||||
rightBraceLeadingComments.length !== 0 &&
|
||||
rightBraceLeadingComments[rightBraceLeadingComments.length - 1] === hardline
|
||||
? rightBraceLeadingComments.pop()
|
||||
: separator;
|
||||
delete RBrace.leadingComments;
|
||||
var contentInsideBraces;
|
||||
if (argument === undefined || argument === "") {
|
||||
if (rightBraceLeadingComments.length === 0) {
|
||||
return prettier_builder_1.concat([LBrace, RBrace]);
|
||||
}
|
||||
contentInsideBraces = __spreadArray([separator], rightBraceLeadingComments);
|
||||
}
|
||||
else if (rightBraceLeadingComments.length !== 0) {
|
||||
contentInsideBraces = __spreadArray([
|
||||
separator,
|
||||
argument,
|
||||
separator
|
||||
], rightBraceLeadingComments);
|
||||
}
|
||||
else {
|
||||
contentInsideBraces = [separator, argument];
|
||||
}
|
||||
return prettier_builder_1.group(rejectAndConcat([
|
||||
LBrace,
|
||||
indent(prettier_builder_1.concat(contentInsideBraces)),
|
||||
lastBreakLine,
|
||||
RBrace
|
||||
]));
|
||||
}
|
||||
exports.putIntoBraces = putIntoBraces;
|
||||
var andOrBinaryOperators = ["&&", "||", "&", "|", "^"];
|
||||
function separateTokensIntoGroups(ctx) {
|
||||
/**
|
||||
* separate tokens into groups by andOrBinaryOperators ("&&", "||", "&", "|", "^")
|
||||
* in order to break those operators in priority.
|
||||
*/
|
||||
var tokens = sortTokens([
|
||||
ctx.Instanceof,
|
||||
ctx.AssignmentOperator,
|
||||
ctx.Less,
|
||||
ctx.Greater,
|
||||
ctx.BinaryOperator
|
||||
]);
|
||||
var groupsOfOperator = [];
|
||||
var sortedBinaryOperators = [];
|
||||
var tmpGroup = [];
|
||||
tokens.forEach(function (token) {
|
||||
if (matchCategory(token, "'BinaryOperator'") &&
|
||||
includes_1.default(andOrBinaryOperators, token.image)) {
|
||||
sortedBinaryOperators.push(token);
|
||||
groupsOfOperator.push(tmpGroup);
|
||||
tmpGroup = [];
|
||||
}
|
||||
else {
|
||||
tmpGroup.push(token);
|
||||
}
|
||||
});
|
||||
groupsOfOperator.push(tmpGroup);
|
||||
return {
|
||||
groupsOfOperator: groupsOfOperator,
|
||||
sortedBinaryOperators: sortedBinaryOperators
|
||||
};
|
||||
}
|
||||
exports.separateTokensIntoGroups = separateTokensIntoGroups;
|
||||
function isShiftOperator(tokens, index) {
|
||||
if (tokens.length <= index + 1) {
|
||||
return "none";
|
||||
}
|
||||
if (tokens[index].image === "<" &&
|
||||
tokens[index + 1].image === "<" &&
|
||||
tokens[index].startOffset === tokens[index + 1].startOffset - 1) {
|
||||
return "leftShift";
|
||||
}
|
||||
if (tokens[index].image === ">" &&
|
||||
tokens[index + 1].image === ">" &&
|
||||
tokens[index].startOffset === tokens[index + 1].startOffset - 1) {
|
||||
if (tokens.length > index + 2 &&
|
||||
tokens[index + 2].image === ">" &&
|
||||
tokens[index + 1].startOffset === tokens[index + 2].startOffset - 1) {
|
||||
return "doubleRightShift";
|
||||
}
|
||||
return "rightShift";
|
||||
}
|
||||
return "none";
|
||||
}
|
||||
exports.isShiftOperator = isShiftOperator;
|
||||
function isStatementEmptyStatement(statement) {
|
||||
return (statement === ";" ||
|
||||
// @ts-ignore
|
||||
(isConcat(statement) && statement.parts[0] === ";"));
|
||||
}
|
||||
exports.isStatementEmptyStatement = isStatementEmptyStatement;
|
||||
function sortImports(imports) {
|
||||
var staticImports = [];
|
||||
var nonStaticImports = [];
|
||||
if (imports !== undefined) {
|
||||
for (var i = 0; i < imports.length; i++) {
|
||||
if (imports[i].children.Static !== undefined) {
|
||||
staticImports.push(imports[i]);
|
||||
}
|
||||
else if (imports[i].children.emptyStatement === undefined) {
|
||||
nonStaticImports.push(imports[i]);
|
||||
}
|
||||
}
|
||||
// TODO: Could be optimized as we could expect that the array is already almost sorted
|
||||
var comparator = function (first, second) {
|
||||
return compareFqn(first.children.packageOrTypeName[0], second.children.packageOrTypeName[0]);
|
||||
};
|
||||
staticImports.sort(comparator);
|
||||
nonStaticImports.sort(comparator);
|
||||
}
|
||||
return {
|
||||
staticImports: staticImports,
|
||||
nonStaticImports: nonStaticImports
|
||||
};
|
||||
}
|
||||
exports.sortImports = sortImports;
|
||||
function compareFqn(packageOrTypeNameFirst, packageOrTypeNameSecond) {
|
||||
var identifiersFirst = packageOrTypeNameFirst.children.Identifier;
|
||||
var identifiersSecond = packageOrTypeNameSecond.children.Identifier;
|
||||
var minParts = Math.min(identifiersFirst.length, identifiersSecond.length);
|
||||
for (var i = 0; i < minParts; i++) {
|
||||
if (identifiersFirst[i].image < identifiersSecond[i].image) {
|
||||
return -1;
|
||||
}
|
||||
else if (identifiersFirst[i].image > identifiersSecond[i].image) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (identifiersFirst.length < identifiersSecond.length) {
|
||||
return -1;
|
||||
}
|
||||
else if (identifiersFirst.length > identifiersSecond.length) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
function isUniqueMethodInvocation(primarySuffixes) {
|
||||
if (primarySuffixes === undefined) {
|
||||
return 0;
|
||||
}
|
||||
var count = 0;
|
||||
primarySuffixes.forEach(function (primarySuffix) {
|
||||
if (primarySuffix.children.methodInvocationSuffix !== undefined) {
|
||||
count++;
|
||||
if (count > 1) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
});
|
||||
return count;
|
||||
}
|
||||
exports.isUniqueMethodInvocation = isUniqueMethodInvocation;
|
||||
function printArrayList(_a) {
|
||||
var list = _a.list, extraComma = _a.extraComma, LCurly = _a.LCurly, RCurly = _a.RCurly, trailingComma = _a.trailingComma;
|
||||
var optionalComma;
|
||||
if (trailingComma !== "none" && list !== "") {
|
||||
optionalComma = extraComma
|
||||
? prettier_builder_1.ifBreak(extraComma[0], __assign(__assign({}, extraComma[0]), { image: "" }))
|
||||
: prettier_builder_1.ifBreak(",", "");
|
||||
}
|
||||
else {
|
||||
optionalComma = extraComma ? __assign(__assign({}, extraComma[0]), { image: "" }) : "";
|
||||
}
|
||||
return putIntoBraces(rejectAndConcat([list, optionalComma]), line, LCurly, RCurly);
|
||||
}
|
||||
exports.printArrayList = printArrayList;
|
183
node_modules/prettier-plugin-java/dist/printers/types-values-and-variables.js
generated
vendored
Normal file
183
node_modules/prettier-plugin-java/dist/printers/types-values-and-variables.js
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
||||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
||||
to[j] = from[i];
|
||||
return to;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TypesValuesAndVariablesPrettierVisitor = void 0;
|
||||
var forEach_1 = __importDefault(require("lodash/forEach"));
|
||||
var prettier_builder_1 = require("./prettier-builder");
|
||||
var format_comments_1 = require("./comments/format-comments");
|
||||
var printer_utils_1 = require("./printer-utils");
|
||||
var base_cst_printer_1 = require("../base-cst-printer");
|
||||
var utils_1 = require("../types/utils");
|
||||
var TypesValuesAndVariablesPrettierVisitor = /** @class */ (function (_super) {
|
||||
__extends(TypesValuesAndVariablesPrettierVisitor, _super);
|
||||
function TypesValuesAndVariablesPrettierVisitor() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.primitiveType = function (ctx) {
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var type = ctx.numericType
|
||||
? this.visit(ctx.numericType)
|
||||
: this.getSingle(ctx);
|
||||
return printer_utils_1.rejectAndJoin(" ", [prettier_builder_1.join(" ", annotations), type]);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.numericType = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.integralType = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.floatingPointType = function (ctx) {
|
||||
return format_comments_1.printTokenWithComments(this.getSingle(ctx));
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.referenceType = function (ctx) {
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var type = ctx.primitiveType
|
||||
? this.visit(ctx.primitiveType)
|
||||
: this.visit(ctx.classOrInterfaceType);
|
||||
var dims = this.visit(ctx.dims);
|
||||
return printer_utils_1.rejectAndJoin(" ", [prettier_builder_1.join(" ", annotations), prettier_builder_1.concat([type, dims])]);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.classOrInterfaceType = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.classType = function (ctx) {
|
||||
var _this = this;
|
||||
var tokens = printer_utils_1.sortClassTypeChildren(ctx.annotation, ctx.typeArguments, ctx.Identifier);
|
||||
var segments = [];
|
||||
var currentSegment = [];
|
||||
forEach_1.default(tokens, function (token, i) {
|
||||
if (utils_1.isTypeArgumentsCstNode(token)) {
|
||||
currentSegment.push(_this.visit([token]));
|
||||
segments.push(printer_utils_1.rejectAndConcat(currentSegment));
|
||||
currentSegment = [];
|
||||
}
|
||||
else if (utils_1.isAnnotationCstNode(token)) {
|
||||
currentSegment.push(_this.visit([token]));
|
||||
}
|
||||
else {
|
||||
currentSegment.push(token);
|
||||
if ((i + 1 < tokens.length && !utils_1.isTypeArgumentsCstNode(tokens[i + 1])) ||
|
||||
i + 1 === tokens.length) {
|
||||
segments.push(printer_utils_1.rejectAndConcat(currentSegment));
|
||||
currentSegment = [];
|
||||
}
|
||||
}
|
||||
});
|
||||
return printer_utils_1.rejectAndJoinSeps(ctx.Dot, segments);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.interfaceType = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.typeVariable = function (ctx) {
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var identifier = this.getSingle(ctx);
|
||||
return printer_utils_1.rejectAndJoin(" ", [prettier_builder_1.join(" ", annotations), identifier]);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.dims = function (ctx) {
|
||||
var _this = this;
|
||||
var tokens = __spreadArray([], ctx.LSquare);
|
||||
if (ctx.annotation) {
|
||||
tokens = __spreadArray(__spreadArray([], tokens), ctx.annotation);
|
||||
}
|
||||
tokens = tokens.sort(function (a, b) {
|
||||
var startOffset1 = utils_1.isCstNode(a)
|
||||
? a.children.At[0].startOffset
|
||||
: a.startOffset;
|
||||
var startOffset2 = utils_1.isCstNode(b)
|
||||
? b.children.At[0].startOffset
|
||||
: b.startOffset;
|
||||
return startOffset1 - startOffset2;
|
||||
});
|
||||
var segments = [];
|
||||
var currentSegment = [];
|
||||
forEach_1.default(tokens, function (token) {
|
||||
if (utils_1.isCstNode(token)) {
|
||||
currentSegment.push(_this.visit([token]));
|
||||
}
|
||||
else {
|
||||
segments.push(printer_utils_1.rejectAndConcat([
|
||||
printer_utils_1.rejectAndJoin(" ", currentSegment),
|
||||
prettier_builder_1.concat([ctx.LSquare[0], ctx.RSquare[0]])
|
||||
]));
|
||||
currentSegment = [];
|
||||
}
|
||||
});
|
||||
return printer_utils_1.rejectAndConcat(segments);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.typeParameter = function (ctx) {
|
||||
var typeParameterModifiers = this.mapVisit(ctx.typeParameterModifier);
|
||||
var typeIdentifier = this.visit(ctx.typeIdentifier);
|
||||
var typeBound = this.visit(ctx.typeBound);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.join(" ", typeParameterModifiers),
|
||||
typeIdentifier,
|
||||
typeBound
|
||||
]);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.typeParameterModifier = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.typeBound = function (ctx) {
|
||||
var classOrInterfaceType = this.visit(ctx.classOrInterfaceType);
|
||||
var additionalBound = this.mapVisit(ctx.additionalBound);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
ctx.Extends[0],
|
||||
classOrInterfaceType,
|
||||
prettier_builder_1.join(" ", additionalBound)
|
||||
]);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.additionalBound = function (ctx) {
|
||||
var interfaceType = this.visit(ctx.interfaceType);
|
||||
return prettier_builder_1.join(" ", [ctx.And[0], interfaceType]);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.typeArguments = function (ctx) {
|
||||
var typeArgumentList = this.visit(ctx.typeArgumentList);
|
||||
return printer_utils_1.rejectAndConcat([ctx.Less[0], typeArgumentList, ctx.Greater[0]]);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.typeArgumentList = function (ctx) {
|
||||
var typeArguments = this.mapVisit(ctx.typeArgument);
|
||||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return prettier_builder_1.concat([elt, " "]); }) : [];
|
||||
return printer_utils_1.rejectAndJoinSeps(commas, typeArguments);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.typeArgument = function (ctx) {
|
||||
return this.visitSingle(ctx);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.wildcard = function (ctx) {
|
||||
var annotations = this.mapVisit(ctx.annotation);
|
||||
var wildcardBounds = this.visit(ctx.wildcardBounds);
|
||||
return printer_utils_1.rejectAndJoin(" ", [
|
||||
prettier_builder_1.join(" ", annotations),
|
||||
ctx.QuestionMark[0],
|
||||
wildcardBounds
|
||||
]);
|
||||
};
|
||||
TypesValuesAndVariablesPrettierVisitor.prototype.wildcardBounds = function (ctx) {
|
||||
var keyWord = ctx.Extends ? ctx.Extends[0] : ctx.Super[0];
|
||||
var referenceType = this.visit(ctx.referenceType);
|
||||
return prettier_builder_1.join(" ", [keyWord, referenceType]);
|
||||
};
|
||||
return TypesValuesAndVariablesPrettierVisitor;
|
||||
}(base_cst_printer_1.BaseCstPrettierPrinter));
|
||||
exports.TypesValuesAndVariablesPrettierVisitor = TypesValuesAndVariablesPrettierVisitor;
|
29
node_modules/prettier-plugin-java/dist/types/utils.js
generated
vendored
Normal file
29
node_modules/prettier-plugin-java/dist/types/utils.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isOrdinaryCompilationUnitCtx = exports.isAnnotationCstNode = exports.isTypeArgumentsCstNode = exports.isCstElementOrUndefinedIToken = exports.isIToken = exports.isCstNode = void 0;
|
||||
function isCstNode(tokenOrNode) {
|
||||
return !isIToken(tokenOrNode);
|
||||
}
|
||||
exports.isCstNode = isCstNode;
|
||||
function isIToken(tokenOrNode) {
|
||||
return (tokenOrNode.tokenType !== undefined &&
|
||||
tokenOrNode.image !== undefined);
|
||||
}
|
||||
exports.isIToken = isIToken;
|
||||
function isCstElementOrUndefinedIToken(tokenOrNode) {
|
||||
return tokenOrNode !== undefined && isIToken(tokenOrNode);
|
||||
}
|
||||
exports.isCstElementOrUndefinedIToken = isCstElementOrUndefinedIToken;
|
||||
var isTypeArgumentsCstNode = function (cstElement) {
|
||||
return cstElement.name === "typeArguments";
|
||||
};
|
||||
exports.isTypeArgumentsCstNode = isTypeArgumentsCstNode;
|
||||
var isAnnotationCstNode = function (cstElement) {
|
||||
return cstElement.name === "annotation";
|
||||
};
|
||||
exports.isAnnotationCstNode = isAnnotationCstNode;
|
||||
var isOrdinaryCompilationUnitCtx = function (ctx) {
|
||||
return (ctx.ordinaryCompilationUnit !==
|
||||
undefined);
|
||||
};
|
||||
exports.isOrdinaryCompilationUnitCtx = isOrdinaryCompilationUnitCtx;
|
4
node_modules/prettier-plugin-java/dist/utils/constants.js
generated
vendored
Normal file
4
node_modules/prettier-plugin-java/dist/utils/constants.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.whitespace = void 0;
|
||||
exports.whitespace = " ";
|
29
node_modules/prettier-plugin-java/dist/utils/expressions-utils.js
generated
vendored
Normal file
29
node_modules/prettier-plugin-java/dist/utils/expressions-utils.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isSingleArgumentLambdaExpressionWithBlock = exports.isArgumentListSingleLambda = void 0;
|
||||
function isArgumentListSingleLambda(argumentList) {
|
||||
if (argumentList === undefined) {
|
||||
return false;
|
||||
}
|
||||
var args = argumentList[0].children.expression;
|
||||
if (args.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
var argument = args[0];
|
||||
return argument.children.lambdaExpression !== undefined;
|
||||
}
|
||||
exports.isArgumentListSingleLambda = isArgumentListSingleLambda;
|
||||
var isSingleArgumentLambdaExpressionWithBlock = function (argumentList) {
|
||||
if (argumentList === undefined) {
|
||||
return false;
|
||||
}
|
||||
var args = argumentList[0].children.expression;
|
||||
if (args.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
var argument = args[0];
|
||||
return (argument.children.lambdaExpression !== undefined &&
|
||||
argument.children.lambdaExpression[0].children.lambdaBody[0].children
|
||||
.block !== undefined);
|
||||
};
|
||||
exports.isSingleArgumentLambdaExpressionWithBlock = isSingleArgumentLambdaExpressionWithBlock;
|
10
node_modules/prettier-plugin-java/dist/utils/index.js
generated
vendored
Normal file
10
node_modules/prettier-plugin-java/dist/utils/index.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.printSingleLambdaInvocation = exports.printArgumentListWithBraces = void 0;
|
||||
var printArgumentListWithBraces_1 = require("./printArgumentListWithBraces");
|
||||
Object.defineProperty(exports, "printArgumentListWithBraces", { enumerable: true, get: function () { return __importDefault(printArgumentListWithBraces_1).default; } });
|
||||
var printSingleLambdaInvocation_1 = require("./printSingleLambdaInvocation");
|
||||
Object.defineProperty(exports, "printSingleLambdaInvocation", { enumerable: true, get: function () { return __importDefault(printSingleLambdaInvocation_1).default; } });
|
21
node_modules/prettier-plugin-java/dist/utils/printArgumentListWithBraces.js
generated
vendored
Normal file
21
node_modules/prettier-plugin-java/dist/utils/printArgumentListWithBraces.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var doc_1 = require("prettier/doc");
|
||||
var expressions_utils_1 = require("./expressions-utils");
|
||||
var printer_utils_1 = require("../printers/printer-utils");
|
||||
var printSingleLambdaInvocation_1 = __importDefault(require("./printSingleLambdaInvocation"));
|
||||
var softline = doc_1.builders.softline;
|
||||
function printArgumentListWithBraces(argumentListCtx, rBrace, lBrace) {
|
||||
var isSingleLambda = expressions_utils_1.isArgumentListSingleLambda(argumentListCtx);
|
||||
if (isSingleLambda) {
|
||||
return printSingleLambdaInvocation_1.default.call(this, argumentListCtx, rBrace, lBrace);
|
||||
}
|
||||
var argumentList = this.visit(argumentListCtx, {
|
||||
isInsideMethodInvocationSuffix: true
|
||||
});
|
||||
return printer_utils_1.putIntoBraces(argumentList, softline, lBrace, rBrace);
|
||||
}
|
||||
exports.default = printArgumentListWithBraces;
|
20
node_modules/prettier-plugin-java/dist/utils/printSingleLambdaInvocation.js
generated
vendored
Normal file
20
node_modules/prettier-plugin-java/dist/utils/printSingleLambdaInvocation.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var doc_1 = require("prettier/doc");
|
||||
var expressions_utils_1 = require("./expressions-utils");
|
||||
var format_comments_1 = require("../printers/comments/format-comments");
|
||||
var prettier_builder_1 = require("../printers/prettier-builder");
|
||||
var printer_utils_1 = require("../printers/printer-utils");
|
||||
var softline = doc_1.builders.softline, ifBreak = doc_1.builders.ifBreak;
|
||||
function printSingleLambdaInvocation(argumentListCtx, rBrace, lBrace) {
|
||||
var lambdaParametersGroupId = Symbol("lambdaParameters");
|
||||
var argumentList = this.visit(argumentListCtx, {
|
||||
lambdaParametersGroupId: lambdaParametersGroupId,
|
||||
isInsideMethodInvocationSuffix: true
|
||||
});
|
||||
var formattedRBrace = expressions_utils_1.isSingleArgumentLambdaExpressionWithBlock(argumentListCtx)
|
||||
? ifBreak(prettier_builder_1.indent(prettier_builder_1.concat([softline, rBrace])), format_comments_1.printTokenWithComments(rBrace), { groupId: lambdaParametersGroupId })
|
||||
: prettier_builder_1.indent(prettier_builder_1.concat([softline, rBrace]));
|
||||
return prettier_builder_1.dedent(printer_utils_1.putIntoBraces(argumentList, "", lBrace, formattedRBrace));
|
||||
}
|
||||
exports.default = printSingleLambdaInvocation;
|
Reference in New Issue
Block a user