prettier-plugin-java
Advanced tools
Comparing version 2.5.0 to 2.6.0
@@ -1,26 +0,7 @@ | ||
"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) { | ||
import { BaseJavaCstVisitor } from "java-parser"; | ||
import { printNodeWithComments } from "./printers/comments/format-comments.js"; | ||
export class BaseCstPrettierPrinter extends BaseJavaCstVisitor { | ||
constructor() { | ||
super(); | ||
this.mapVisit = (elements, params) => { | ||
if (elements === undefined) { | ||
@@ -30,13 +11,13 @@ // TODO: can optimize this by returning an immutable empty array singleton. | ||
} | ||
return elements.map(function (element) { return _this.visit(element, params); }); | ||
return elements.map(element => this.visit(element, params)); | ||
}; | ||
_this.getSingle = function (ctx) { | ||
var ctxKeys = Object.keys(ctx); | ||
this.getSingle = (ctx) => { | ||
const ctxKeys = Object.keys(ctx); | ||
if (ctxKeys.length !== 1) { | ||
throw Error("Expecting single key CST ctx but found: <".concat(ctxKeys.length, "> keys")); | ||
throw Error(`Expecting single key CST ctx but found: <${ctxKeys.length}> keys`); | ||
} | ||
var singleElementKey = ctxKeys[0]; | ||
var singleElementValues = ctx[singleElementKey]; | ||
const singleElementKey = ctxKeys[0]; | ||
const 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: <".concat(singleElementValues === null || singleElementValues === void 0 ? void 0 : singleElementValues.length, "> items")); | ||
throw Error(`Expecting single item in CST ctx key but found: <${singleElementValues === null || singleElementValues === void 0 ? void 0 : singleElementValues.length}> items`); | ||
} | ||
@@ -46,4 +27,4 @@ return singleElementValues[0]; | ||
// @ts-ignore | ||
_this.orgVisit = _this.visit; | ||
_this.visit = function (ctx, inParam) { | ||
this.orgVisit = this.visit; | ||
this.visit = function (ctx, inParam) { | ||
if (ctx === undefined) { | ||
@@ -53,9 +34,9 @@ // empty Doc | ||
} | ||
var node = Array.isArray(ctx) ? ctx[0] : ctx; | ||
const node = Array.isArray(ctx) ? ctx[0] : ctx; | ||
if (node.ignore) { | ||
try { | ||
var startOffset = node.leadingComments !== undefined | ||
const startOffset = node.leadingComments !== undefined | ||
? node.leadingComments[0].startOffset | ||
: node.location.startOffset; | ||
var endOffset = (node.trailingComments !== undefined | ||
const endOffset = (node.trailingComments !== undefined | ||
? node.trailingComments[node.trailingComments.length - 1].endOffset | ||
@@ -70,12 +51,9 @@ : node.location.endOffset); | ||
} | ||
return (0, format_comments_1.printNodeWithComments)(node, this.orgVisit.call(this, node, inParam)); | ||
return printNodeWithComments(node, this.orgVisit.call(this, node, inParam)); | ||
}; | ||
_this.visitSingle = function (ctx, params) { | ||
var singleElement = this.getSingle(ctx); | ||
this.visitSingle = function (ctx, params) { | ||
const singleElement = this.getSingle(ctx); | ||
return this.visit(singleElement, params); | ||
}; | ||
return _this; | ||
} | ||
return BaseCstPrettierPrinter; | ||
}(java_parser_1.BaseJavaCstVisitor)); | ||
exports.BaseCstPrettierPrinter = BaseCstPrettierPrinter; | ||
} |
@@ -1,37 +0,29 @@ | ||
"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"); | ||
import { BaseCstPrettierPrinter } from "./base-cst-printer.js"; | ||
import { ArraysPrettierVisitor } from "./printers/arrays.js"; | ||
import { BlocksAndStatementPrettierVisitor } from "./printers/blocks-and-statements.js"; | ||
import { ClassesPrettierVisitor } from "./printers/classes.js"; | ||
import { ExpressionsPrettierVisitor } from "./printers/expressions.js"; | ||
import { InterfacesPrettierVisitor } from "./printers/interfaces.js"; | ||
import { LexicalStructurePrettierVisitor } from "./printers/lexical-structure.js"; | ||
import { NamesPrettierVisitor } from "./printers/names.js"; | ||
import { TypesValuesAndVariablesPrettierVisitor } from "./printers/types-values-and-variables.js"; | ||
import { PackagesAndModulesPrettierVisitor } from "./printers/packages-and-modules.js"; | ||
// 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) { | ||
mixInMethods(ArraysPrettierVisitor, BlocksAndStatementPrettierVisitor, ClassesPrettierVisitor, ExpressionsPrettierVisitor, InterfacesPrettierVisitor, LexicalStructurePrettierVisitor, NamesPrettierVisitor, TypesValuesAndVariablesPrettierVisitor, PackagesAndModulesPrettierVisitor); | ||
function mixInMethods(...classesToMix) { | ||
classesToMix.forEach(from => { | ||
const fromMethodsNames = Object.getOwnPropertyNames(from.prototype); | ||
const fromPureMethodsName = fromMethodsNames.filter(methodName => methodName !== "constructor"); | ||
fromPureMethodsName.forEach(methodName => { | ||
// @ts-ignore | ||
base_cst_printer_1.BaseCstPrettierPrinter.prototype[methodName] = from.prototype[methodName]; | ||
BaseCstPrettierPrinter.prototype[methodName] = from.prototype[methodName]; | ||
}); | ||
}); | ||
} | ||
var prettyPrinter = new base_cst_printer_1.BaseCstPrettierPrinter(); | ||
const prettyPrinter = new 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) { | ||
export function createPrettierDoc(cstNode, options) { | ||
prettyPrinter.prettierOptions = options; | ||
return prettyPrinter.visit(cstNode); | ||
} | ||
exports.createPrettierDoc = createPrettierDoc; |
@@ -1,6 +0,5 @@ | ||
"use strict"; | ||
var parse = require("./parser"); | ||
var print = require("./printer"); | ||
var options = require("./options"); | ||
var languages = [ | ||
import parse from "./parser.js"; | ||
import print from "./printer.js"; | ||
import options from "./options.js"; | ||
const languages = [ | ||
{ | ||
@@ -28,9 +27,9 @@ name: "Java", | ||
} | ||
var parsers = { | ||
const parsers = { | ||
java: { | ||
parse: parse, | ||
parse, | ||
astFormat: "java", | ||
locStart: locStart, | ||
locEnd: locEnd, | ||
hasPragma: hasPragma | ||
locStart, | ||
locEnd, | ||
hasPragma | ||
} | ||
@@ -42,3 +41,3 @@ }; | ||
function printComment(commentPath) { | ||
var comment = commentPath.getValue(); | ||
const comment = commentPath.getValue(); | ||
switch (comment.ast_type) { | ||
@@ -55,16 +54,16 @@ case "comment": | ||
} | ||
var printers = { | ||
const printers = { | ||
java: { | ||
print: print, | ||
print, | ||
// hasPrettierIgnore, | ||
printComment: printComment, | ||
canAttachComment: canAttachComment, | ||
printComment, | ||
canAttachComment, | ||
massageAstNode: clean | ||
} | ||
}; | ||
module.exports = { | ||
languages: languages, | ||
printers: printers, | ||
parsers: parsers, | ||
options: options | ||
export default { | ||
languages, | ||
printers, | ||
parsers, | ||
options | ||
}; |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
module.exports = { | ||
export default { | ||
entrypoint: { | ||
@@ -56,5 +55,2 @@ type: "choice", | ||
{ value: "variableAccess" }, | ||
{ value: "isBasicForStatement" }, | ||
{ value: "isLocalVariableDeclaration" }, | ||
{ value: "isClassicSwitchLabel" }, | ||
{ value: "classDeclaration" }, | ||
@@ -126,6 +122,3 @@ { value: "normalClassDeclaration" }, | ||
{ value: "compactConstructorDeclaration" }, | ||
{ value: "isClassDeclaration" }, | ||
{ value: "identifyClassBodyDeclarationType" }, | ||
{ value: "isDims" }, | ||
{ value: "isCompactConstructorDeclaration" }, | ||
{ value: "expression" }, | ||
@@ -172,2 +165,7 @@ { value: "lambdaExpression" }, | ||
{ value: "methodReferenceSuffix" }, | ||
{ value: "templateArgument" }, | ||
{ value: "template" }, | ||
{ value: "stringTemplate" }, | ||
{ value: "textBlockTemplate" }, | ||
{ value: "embeddedExpression" }, | ||
{ value: "pattern" }, | ||
@@ -180,7 +178,2 @@ { value: "typePattern" }, | ||
{ value: "guard" }, | ||
{ value: "identifyNewExpressionType" }, | ||
{ value: "isLambdaExpression" }, | ||
{ value: "isCastExpression" }, | ||
{ value: "isPrimitiveCastExpression" }, | ||
{ value: "isReferenceTypeCastExpression" }, | ||
{ value: "isRefTypeInMethodRef" }, | ||
@@ -210,5 +203,2 @@ { value: "interfaceDeclaration" }, | ||
{ value: "elementValueList" }, | ||
{ value: "identifyInterfaceBodyDeclarationType" }, | ||
{ value: "identifyAnnotationBodyDeclarationType" }, | ||
{ value: "isSimpleElementValueAnnotation" }, | ||
{ value: "literal" }, | ||
@@ -240,3 +230,2 @@ { value: "integerLiteral" }, | ||
{ value: "requiresModifier" }, | ||
{ value: "isModuleCompilationUnit" }, | ||
{ value: "primitiveType" }, | ||
@@ -263,3 +252,10 @@ { value: "numericType" }, | ||
description: "Prettify from the entrypoint, allowing to use prettier on snippet." | ||
}, | ||
trailingComma: { | ||
type: "choice", | ||
category: "Java", | ||
default: "all", | ||
choices: ["all", "none"], | ||
description: "Print trailing commas wherever possible when multi-line." | ||
} | ||
}; |
@@ -1,6 +0,4 @@ | ||
"use strict"; | ||
var javaParser = require("java-parser"); | ||
function parse(text, parsers, opts) { | ||
import javaParser from "java-parser"; | ||
export default function parse(text, parsers, opts) { | ||
return javaParser.parse(text, opts.entrypoint); | ||
} | ||
module.exports = parse; |
@@ -1,8 +0,6 @@ | ||
"use strict"; | ||
var createPrettierDoc = require("./cst-printer").createPrettierDoc; | ||
import { createPrettierDoc } from "./cst-printer.js"; | ||
// eslint-disable-next-line no-unused-vars | ||
function genericPrint(path, options, print) { | ||
var node = path.getValue(); | ||
export default function genericPrint(path, options, print) { | ||
const node = path.getValue(); | ||
return createPrettierDoc(node, options); | ||
} | ||
module.exports = genericPrint; |
@@ -1,31 +0,9 @@ | ||
"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 (0, printer_utils_1.printArrayList)({ | ||
import { printArrayList, rejectAndConcat, rejectAndJoinSeps } from "./printer-utils.js"; | ||
import { builders } from "prettier/doc"; | ||
import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; | ||
const { line } = builders; | ||
export class ArraysPrettierVisitor extends BaseCstPrettierPrinter { | ||
arrayInitializer(ctx) { | ||
const optionalVariableInitializerList = this.visit(ctx.variableInitializerList); | ||
return printArrayList({ | ||
list: optionalVariableInitializerList, | ||
@@ -37,14 +15,12 @@ extraComma: ctx.Comma, | ||
}); | ||
}; | ||
ArraysPrettierVisitor.prototype.variableInitializerList = function (ctx) { | ||
var variableInitializers = this.mapVisit(ctx.variableInitializer); | ||
var commas = ctx.Comma | ||
? ctx.Comma.map(function (comma) { | ||
return (0, printer_utils_1.rejectAndConcat)([comma, line]); | ||
} | ||
variableInitializerList(ctx) { | ||
const variableInitializers = this.mapVisit(ctx.variableInitializer); | ||
const commas = ctx.Comma | ||
? ctx.Comma.map(comma => { | ||
return rejectAndConcat([comma, line]); | ||
}) | ||
: []; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(commas, variableInitializers); | ||
}; | ||
return ArraysPrettierVisitor; | ||
}(base_cst_printer_1.BaseCstPrettierPrinter)); | ||
exports.ArraysPrettierVisitor = ArraysPrettierVisitor; | ||
return rejectAndJoinSeps(commas, variableInitializers); | ||
} | ||
} |
@@ -1,77 +0,35 @@ | ||
"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, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
import { builders } from "prettier/doc"; | ||
import { concat, group, indent, join } from "./prettier-builder.js"; | ||
import { printTokenWithComments } from "./comments/format-comments.js"; | ||
import { hasLeadingLineComments, hasTrailingLineComments } from "./comments/comments-utils.js"; | ||
import { displaySemicolon, getBlankLinesSeparator, isStatementEmptyStatement, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, rejectSeparators, sortModifiers } from "./printer-utils.js"; | ||
import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; | ||
const { line, softline, hardline } = builders; | ||
export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter { | ||
block(ctx) { | ||
const blockStatements = this.visit(ctx.blockStatements); | ||
return putIntoBraces(blockStatements, hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
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; | ||
blockStatements(ctx) { | ||
const blockStatement = this.mapVisit(ctx.blockStatement); | ||
const separators = rejectSeparators(getBlankLinesSeparator(ctx.blockStatement), blockStatement); | ||
return rejectAndJoinSeps(separators, blockStatement); | ||
} | ||
BlocksAndStatementPrettierVisitor.prototype.block = function (ctx) { | ||
var blockStatements = this.visit(ctx.blockStatements); | ||
return (0, 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 = (0, printer_utils_1.rejectSeparators)((0, printer_utils_1.getBlankLinesSeparator)(ctx.blockStatement), blockStatement); | ||
return (0, printer_utils_1.rejectAndJoinSeps)(separators, blockStatement); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.blockStatement = function (ctx) { | ||
blockStatement(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.localVariableDeclarationStatement = function (ctx) { | ||
var localVariableDeclaration = this.visit(ctx.localVariableDeclaration); | ||
return (0, printer_utils_1.rejectAndConcat)([localVariableDeclaration, ctx.Semicolon[0]]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.localVariableDeclaration = function (ctx) { | ||
var modifiers = (0, 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 (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", finalModifiers), | ||
} | ||
localVariableDeclarationStatement(ctx) { | ||
const localVariableDeclaration = this.visit(ctx.localVariableDeclaration); | ||
return rejectAndConcat([localVariableDeclaration, ctx.Semicolon[0]]); | ||
} | ||
localVariableDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.variableModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const finalModifiers = this.mapVisit(modifiers[1]); | ||
const localVariableType = this.visit(ctx.localVariableType); | ||
const variableDeclaratorList = this.visit(ctx.variableDeclaratorList); | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", finalModifiers), | ||
localVariableType, | ||
@@ -81,22 +39,22 @@ variableDeclaratorList | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.localVariableType = function (ctx) { | ||
} | ||
localVariableType(ctx) { | ||
if (ctx.unannType) { | ||
return this.visitSingle(ctx); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.statement = function (ctx, params) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
statement(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 = []; | ||
const newLabelStatement = Object.assign({}, ctx.labeledStatement[0]); | ||
const newColon = Object.assign({}, ctx.labeledStatement[0].children.Colon[0]); | ||
const newStatement = Object.assign({}, ctx.labeledStatement[0].children.statement[0]); | ||
const labeledStatementLeadingComments = []; | ||
if (newColon.trailingComments !== undefined) { | ||
labeledStatementLeadingComments.push.apply(labeledStatementLeadingComments, newColon.trailingComments); | ||
labeledStatementLeadingComments.push(...newColon.trailingComments); | ||
delete newColon.trailingComments; | ||
} | ||
if (newStatement.leadingComments !== undefined) { | ||
labeledStatementLeadingComments.push.apply(labeledStatementLeadingComments, newStatement.leadingComments); | ||
labeledStatementLeadingComments.push(...newStatement.leadingComments); | ||
delete newStatement.leadingComments; | ||
@@ -112,47 +70,49 @@ } | ||
return this.visitSingle(ctx, params); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.statementWithoutTrailingSubstatement = function (ctx, params) { | ||
} | ||
statementWithoutTrailingSubstatement(ctx, params) { | ||
return this.visitSingle(ctx, params); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.emptyStatement = function (ctx, params) { | ||
return (0, 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 (0, printer_utils_1.rejectAndJoin)(ctx.Colon[0], [identifier, statement]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.expressionStatement = function (ctx) { | ||
var statementExpression = this.visit(ctx.statementExpression); | ||
return (0, printer_utils_1.rejectAndConcat)([statementExpression, ctx.Semicolon[0]]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.statementExpression = function (ctx) { | ||
} | ||
emptyStatement(ctx, params) { | ||
return displaySemicolon(ctx.Semicolon[0], params); | ||
} | ||
labeledStatement(ctx) { | ||
const identifier = ctx.Identifier[0]; | ||
const statement = this.visit(ctx.statement); | ||
return rejectAndJoin(ctx.Colon[0], [identifier, statement]); | ||
} | ||
expressionStatement(ctx) { | ||
const statementExpression = this.visit(ctx.statementExpression); | ||
return rejectAndConcat([statementExpression, ctx.Semicolon[0]]); | ||
} | ||
statementExpression(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.ifStatement = function (ctx) { | ||
var expression = this.visit(ctx.expression); | ||
var ifStatement = this.visit(ctx.statement[0], { | ||
} | ||
ifStatement(ctx) { | ||
var _a; | ||
const expression = this.visit(ctx.expression); | ||
const ifStatement = this.visit(ctx.statement[0], { | ||
allowEmptyStatement: true | ||
}); | ||
var ifSeparator = (0, printer_utils_1.isStatementEmptyStatement)(ifStatement) ? "" : " "; | ||
var elsePart = ""; | ||
const ifSeparator = isStatementEmptyStatement(ifStatement) ? "" : " "; | ||
let elsePart = ""; | ||
if (ctx.Else !== undefined) { | ||
var elseStatement = this.visit(ctx.statement[1], { | ||
const elseStatement = this.visit(ctx.statement[1], { | ||
allowEmptyStatement: true | ||
}); | ||
var elseSeparator = (0, printer_utils_1.isStatementEmptyStatement)(elseStatement) ? "" : " "; | ||
var elseOnSameLine = (0, comments_utils_1.hasTrailingLineComments)(ctx.statement[0]) || | ||
(0, comments_utils_1.hasLeadingLineComments)(ctx.Else[0]) | ||
const elseSeparator = isStatementEmptyStatement(elseStatement) ? "" : " "; | ||
const elseOnSameLine = hasTrailingLineComments(ctx.statement[0]) || | ||
hasLeadingLineComments(ctx.Else[0]) || | ||
!((_a = ctx.statement[0].children.statementWithoutTrailingSubstatement) === null || _a === void 0 ? void 0 : _a[0].children.block) | ||
? hardline | ||
: " "; | ||
elsePart = (0, printer_utils_1.rejectAndJoin)(elseSeparator, [ | ||
(0, prettier_builder_1.concat)([elseOnSameLine, ctx.Else[0]]), | ||
elsePart = rejectAndJoin(elseSeparator, [ | ||
concat([elseOnSameLine, ctx.Else[0]]), | ||
elseStatement | ||
]); | ||
} | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
return rejectAndConcat([ | ||
rejectAndJoin(" ", [ | ||
ctx.If[0], | ||
(0, prettier_builder_1.concat)([ | ||
(0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
concat([ | ||
putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
ifSeparator | ||
@@ -164,65 +124,71 @@ ]) | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.assertStatement = function (ctx) { | ||
var expressions = this.mapVisit(ctx.expression); | ||
var colon = ctx.Colon ? ctx.Colon[0] : ":"; | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.concat)([ctx.Assert[0], " "]), | ||
(0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([" ", colon, " "]), expressions), | ||
} | ||
assertStatement(ctx) { | ||
const expressions = this.mapVisit(ctx.expression); | ||
const colon = ctx.Colon ? ctx.Colon[0] : ":"; | ||
return rejectAndConcat([ | ||
concat([ctx.Assert[0], " "]), | ||
rejectAndJoin(concat([" ", colon, " "]), expressions), | ||
ctx.Semicolon[0] | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.switchStatement = function (ctx) { | ||
var expression = this.visit(ctx.expression); | ||
var switchBlock = this.visit(ctx.switchBlock); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
} | ||
switchStatement(ctx) { | ||
const expression = this.visit(ctx.expression); | ||
const switchBlock = this.visit(ctx.switchBlock); | ||
return rejectAndJoin(" ", [ | ||
ctx.Switch[0], | ||
(0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
switchBlock | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.switchBlock = function (ctx) { | ||
var switchCases = ctx.switchBlockStatementGroup !== undefined | ||
} | ||
switchBlock(ctx) { | ||
const switchCases = ctx.switchBlockStatementGroup !== undefined | ||
? this.mapVisit(ctx.switchBlockStatementGroup) | ||
: this.mapVisit(ctx.switchRule); | ||
return (0, printer_utils_1.putIntoBraces)((0, 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 (0, prettier_builder_1.concat)([ | ||
return putIntoBraces(rejectAndJoin(hardline, switchCases), hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
} | ||
switchBlockStatementGroup(ctx) { | ||
var _a, _b, _c; | ||
const switchLabel = this.visit(ctx.switchLabel); | ||
const blockStatements = this.visit(ctx.blockStatements); | ||
const statements = (_a = ctx.blockStatements) === null || _a === void 0 ? void 0 : _a[0].children.blockStatement; | ||
const hasSingleStatementBlock = (statements === null || statements === void 0 ? void 0 : statements.length) === 1 && | ||
((_c = (_b = statements[0].children.statement) === null || _b === void 0 ? void 0 : _b[0].children.statementWithoutTrailingSubstatement) === null || _c === void 0 ? void 0 : _c[0].children.block) !== undefined; | ||
return concat([ | ||
switchLabel, | ||
ctx.Colon[0], | ||
blockStatements && (0, prettier_builder_1.indent)([hardline, blockStatements]) | ||
hasSingleStatementBlock | ||
? concat([" ", blockStatements]) | ||
: blockStatements && indent([hardline, blockStatements]) | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.switchLabel = function (ctx) { | ||
} | ||
switchLabel(ctx) { | ||
var _a, _b, _c; | ||
var Case = (_a = ctx.Case) === null || _a === void 0 ? void 0 : _a[0]; | ||
var commas = (_b = ctx.Comma) === null || _b === void 0 ? void 0 : _b.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }); | ||
const Case = (_a = ctx.Case) === null || _a === void 0 ? void 0 : _a[0]; | ||
const commas = (_b = ctx.Comma) === null || _b === void 0 ? void 0 : _b.map(elt => concat([elt, line])); | ||
if (ctx.caseConstant || ctx.Null) { | ||
var caseConstants = ctx.Null | ||
const caseConstants = ctx.Null | ||
? [ctx.Null[0], (_c = ctx.Default) === null || _c === void 0 ? void 0 : _c[0]] | ||
: this.mapVisit(ctx.caseConstant); | ||
return (0, prettier_builder_1.group)((0, prettier_builder_1.indent)((0, prettier_builder_1.join)(" ", [Case, (0, printer_utils_1.rejectAndJoinSeps)(commas, caseConstants)]))); | ||
return group(indent(join(" ", [Case, rejectAndJoinSeps(commas, caseConstants)]))); | ||
} | ||
else if (ctx.pattern) { | ||
var patterns = this.mapVisit(ctx.pattern); | ||
var guard = this.visit(ctx.guard); | ||
var multiplePatterns = ctx.pattern.length > 1; | ||
var separator = multiplePatterns ? line : " "; | ||
var contents = (0, prettier_builder_1.join)(separator, [ | ||
const patterns = this.mapVisit(ctx.pattern); | ||
const guard = this.visit(ctx.guard); | ||
const multiplePatterns = ctx.pattern.length > 1; | ||
const separator = multiplePatterns ? line : " "; | ||
const contents = join(separator, [ | ||
Case, | ||
(0, printer_utils_1.rejectAndJoinSeps)(commas, patterns) | ||
rejectAndJoinSeps(commas, patterns) | ||
]); | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(separator, [ | ||
multiplePatterns ? (0, prettier_builder_1.indent)(contents) : contents, | ||
return group(rejectAndJoin(separator, [ | ||
multiplePatterns ? indent(contents) : contents, | ||
guard | ||
])); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(ctx.Default[0]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.switchRule = function (ctx) { | ||
var switchLabel = this.visit(ctx.switchLabel); | ||
var caseInstruction; | ||
return printTokenWithComments(ctx.Default[0]); | ||
} | ||
switchRule(ctx) { | ||
const switchLabel = this.visit(ctx.switchLabel); | ||
let caseInstruction; | ||
if (ctx.throwStatement !== undefined) { | ||
@@ -235,56 +201,56 @@ caseInstruction = this.visit(ctx.throwStatement); | ||
else { | ||
caseInstruction = (0, prettier_builder_1.concat)([this.visit(ctx.expression), ctx.Semicolon[0]]); | ||
caseInstruction = concat([this.visit(ctx.expression), ctx.Semicolon[0]]); | ||
} | ||
return (0, prettier_builder_1.concat)([switchLabel, " ", ctx.Arrow[0], " ", caseInstruction]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.caseConstant = function (ctx) { | ||
return concat([switchLabel, " ", ctx.Arrow[0], " ", caseInstruction]); | ||
} | ||
caseConstant(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.whileStatement = function (ctx) { | ||
var expression = this.visit(ctx.expression); | ||
var statement = this.visit(ctx.statement[0], { | ||
} | ||
whileStatement(ctx) { | ||
const expression = this.visit(ctx.expression); | ||
const statement = this.visit(ctx.statement[0], { | ||
allowEmptyStatement: true | ||
}); | ||
var statementSeparator = (0, printer_utils_1.isStatementEmptyStatement)(statement) ? "" : " "; | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
const statementSeparator = isStatementEmptyStatement(statement) ? "" : " "; | ||
return rejectAndJoin(" ", [ | ||
ctx.While[0], | ||
(0, printer_utils_1.rejectAndJoin)(statementSeparator, [ | ||
(0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
rejectAndJoin(statementSeparator, [ | ||
putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
statement | ||
]) | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.doStatement = function (ctx) { | ||
var statement = this.visit(ctx.statement[0], { | ||
} | ||
doStatement(ctx) { | ||
const statement = this.visit(ctx.statement[0], { | ||
allowEmptyStatement: true | ||
}); | ||
var statementSeparator = (0, printer_utils_1.isStatementEmptyStatement)(statement) ? "" : " "; | ||
var expression = this.visit(ctx.expression); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(statementSeparator, [ctx.Do[0], statement]), | ||
const statementSeparator = isStatementEmptyStatement(statement) ? "" : " "; | ||
const expression = this.visit(ctx.expression); | ||
return rejectAndJoin(" ", [ | ||
rejectAndJoin(statementSeparator, [ctx.Do[0], statement]), | ||
ctx.While[0], | ||
(0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
rejectAndConcat([ | ||
putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
ctx.Semicolon[0] | ||
]) | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.forStatement = function (ctx) { | ||
} | ||
forStatement(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], { | ||
} | ||
basicForStatement(ctx) { | ||
const forInit = this.visit(ctx.forInit); | ||
const expression = this.visit(ctx.expression); | ||
const forUpdate = this.visit(ctx.forUpdate); | ||
const statement = this.visit(ctx.statement[0], { | ||
allowEmptyStatement: true | ||
}); | ||
var statementSeparator = (0, printer_utils_1.isStatementEmptyStatement)(statement) ? "" : " "; | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
const statementSeparator = isStatementEmptyStatement(statement) ? "" : " "; | ||
return rejectAndConcat([ | ||
rejectAndJoin(" ", [ | ||
ctx.For[0], | ||
(0, printer_utils_1.putIntoBraces)((0, printer_utils_1.rejectAndConcat)([ | ||
putIntoBraces(rejectAndConcat([ | ||
forInit, | ||
(0, printer_utils_1.rejectAndJoin)(line, [ctx.Semicolon[0], expression]), | ||
(0, printer_utils_1.rejectAndJoin)(line, [ctx.Semicolon[1], forUpdate]) | ||
rejectAndJoin(line, [ctx.Semicolon[0], expression]), | ||
rejectAndJoin(line, [ctx.Semicolon[1], forUpdate]) | ||
]), softline, ctx.LBrace[0], ctx.RBrace[0]) | ||
@@ -295,45 +261,45 @@ ]), | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.forInit = function (ctx) { | ||
} | ||
forInit(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.forUpdate = function (ctx) { | ||
} | ||
forUpdate(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 (0, prettier_builder_1.concat)([(0, format_comments_1.printTokenWithComments)(elt), " "]); | ||
} | ||
statementExpressionList(ctx) { | ||
const statementExpressions = this.mapVisit(ctx.statementExpression); | ||
const commas = ctx.Comma | ||
? ctx.Comma.map(elt => { | ||
return concat([printTokenWithComments(elt), " "]); | ||
}) | ||
: []; | ||
return (0, 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], { | ||
return rejectAndJoinSeps(commas, statementExpressions); | ||
} | ||
enhancedForStatement(ctx) { | ||
const variableModifiers = this.mapVisit(ctx.variableModifier); | ||
const localVariableType = this.visit(ctx.localVariableType); | ||
const variableDeclaratorId = this.visit(ctx.variableDeclaratorId); | ||
const expression = this.visit(ctx.expression); | ||
const statement = this.visit(ctx.statement[0], { | ||
allowEmptyStatement: true | ||
}); | ||
var statementSeparator = (0, printer_utils_1.isStatementEmptyStatement)(statement) ? "" : " "; | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.For[0], ctx.LBrace[0]]), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", variableModifiers), | ||
const statementSeparator = isStatementEmptyStatement(statement) ? "" : " "; | ||
return rejectAndConcat([ | ||
rejectAndJoin(" ", [ctx.For[0], ctx.LBrace[0]]), | ||
rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", variableModifiers), | ||
localVariableType, | ||
variableDeclaratorId | ||
]), | ||
(0, prettier_builder_1.concat)([" ", ctx.Colon[0], " "]), | ||
concat([" ", ctx.Colon[0], " "]), | ||
expression, | ||
(0, prettier_builder_1.concat)([ctx.RBrace[0], statementSeparator]), | ||
concat([ctx.RBrace[0], statementSeparator]), | ||
statement | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.breakStatement = function (ctx) { | ||
} | ||
breakStatement(ctx) { | ||
if (ctx.Identifier) { | ||
var identifier = ctx.Identifier[0]; | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.concat)([ctx.Break[0], " "]), | ||
const identifier = ctx.Identifier[0]; | ||
return rejectAndConcat([ | ||
concat([ctx.Break[0], " "]), | ||
identifier, | ||
@@ -343,9 +309,9 @@ ctx.Semicolon[0] | ||
} | ||
return (0, prettier_builder_1.concat)([ctx.Break[0], ctx.Semicolon[0]]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.continueStatement = function (ctx) { | ||
return concat([ctx.Break[0], ctx.Semicolon[0]]); | ||
} | ||
continueStatement(ctx) { | ||
if (ctx.Identifier) { | ||
var identifier = ctx.Identifier[0]; | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.concat)([ctx.Continue[0], " "]), | ||
const identifier = ctx.Identifier[0]; | ||
return rejectAndConcat([ | ||
concat([ctx.Continue[0], " "]), | ||
identifier, | ||
@@ -355,11 +321,11 @@ ctx.Semicolon[0] | ||
} | ||
return (0, printer_utils_1.rejectAndConcat)([ctx.Continue[0], ctx.Semicolon[0]]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.returnStatement = function (ctx) { | ||
return rejectAndConcat([ctx.Continue[0], ctx.Semicolon[0]]); | ||
} | ||
returnStatement(ctx) { | ||
if (ctx.expression) { | ||
var expression = this.visit(ctx.expression, { | ||
const expression = this.visit(ctx.expression, { | ||
addParenthesisToWrapStatement: true | ||
}); | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.concat)([ctx.Return[0], " "]), | ||
return rejectAndConcat([ | ||
concat([ctx.Return[0], " "]), | ||
expression, | ||
@@ -369,20 +335,20 @@ ctx.Semicolon[0] | ||
} | ||
return (0, printer_utils_1.rejectAndConcat)([ctx.Return[0], ctx.Semicolon[0]]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.throwStatement = function (ctx) { | ||
var expression = this.visit(ctx.expression); | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.concat)([ctx.Throw[0], " "]), | ||
return rejectAndConcat([ctx.Return[0], ctx.Semicolon[0]]); | ||
} | ||
throwStatement(ctx) { | ||
const expression = this.visit(ctx.expression); | ||
return rejectAndConcat([ | ||
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 (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.join)(" ", [ | ||
} | ||
synchronizedStatement(ctx) { | ||
const expression = this.visit(ctx.expression); | ||
const block = this.visit(ctx.block); | ||
return rejectAndConcat([ | ||
join(" ", [ | ||
ctx.Synchronized[0], | ||
(0, prettier_builder_1.concat)([ | ||
(0, printer_utils_1.putIntoBraces)(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
concat([ | ||
putIntoBraces(expression, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
" " | ||
@@ -393,55 +359,55 @@ ]) | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.tryStatement = function (ctx) { | ||
} | ||
tryStatement(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 (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Try[0], block, catches, finallyBlock]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.catches = function (ctx) { | ||
var catchClauses = this.mapVisit(ctx.catchClause); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", catchClauses); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.catchClause = function (ctx) { | ||
var catchFormalParameter = this.visit(ctx.catchFormalParameter); | ||
var block = this.visit(ctx.block); | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.Catch[0], ctx.LBrace[0]]), | ||
(0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([softline, catchFormalParameter])), | ||
const block = this.visit(ctx.block); | ||
const catches = this.visit(ctx.catches); | ||
const finallyBlock = this.visit(ctx.finally); | ||
return rejectAndJoin(" ", [ctx.Try[0], block, catches, finallyBlock]); | ||
} | ||
catches(ctx) { | ||
const catchClauses = this.mapVisit(ctx.catchClause); | ||
return rejectAndJoin(" ", catchClauses); | ||
} | ||
catchClause(ctx) { | ||
const catchFormalParameter = this.visit(ctx.catchFormalParameter); | ||
const block = this.visit(ctx.block); | ||
return rejectAndConcat([ | ||
group(rejectAndConcat([ | ||
rejectAndJoin(" ", [ctx.Catch[0], ctx.LBrace[0]]), | ||
indent(rejectAndConcat([softline, catchFormalParameter])), | ||
softline, | ||
(0, prettier_builder_1.concat)([ctx.RBrace[0], " "]) | ||
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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", variableModifiers), | ||
} | ||
catchFormalParameter(ctx) { | ||
const variableModifiers = this.mapVisit(ctx.variableModifier); | ||
const catchType = this.visit(ctx.catchType); | ||
const variableDeclaratorId = this.visit(ctx.variableDeclaratorId); | ||
return rejectAndJoin(" ", [ | ||
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 (0, prettier_builder_1.concat)([line, elt, " "]); }) : []; | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoinSeps)(ors, __spreadArray([unannClassType], classTypes, true))); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.finally = function (ctx) { | ||
var block = this.visit(ctx.block); | ||
return (0, 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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
} | ||
catchType(ctx) { | ||
const unannClassType = this.visit(ctx.unannClassType); | ||
const classTypes = this.mapVisit(ctx.classType); | ||
const ors = ctx.Or ? ctx.Or.map(elt => concat([line, elt, " "])) : []; | ||
return group(rejectAndJoinSeps(ors, [unannClassType, ...classTypes])); | ||
} | ||
finally(ctx) { | ||
const block = this.visit(ctx.block); | ||
return rejectAndJoin(" ", [ctx.Finally[0], block]); | ||
} | ||
tryWithResourcesStatement(ctx) { | ||
const resourceSpecification = this.visit(ctx.resourceSpecification); | ||
const block = this.visit(ctx.block); | ||
const catches = this.visit(ctx.catches); | ||
const finallyBlock = this.visit(ctx.finally); | ||
return rejectAndJoin(" ", [ | ||
ctx.Try[0], | ||
@@ -453,38 +419,27 @@ resourceSpecification, | ||
]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.resourceSpecification = function (ctx) { | ||
var resourceList = this.visit(ctx.resourceList); | ||
var optionalSemicolon = ctx.Semicolon ? ctx.Semicolon[0] : ""; | ||
return (0, printer_utils_1.putIntoBraces)((0, 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 (0, prettier_builder_1.concat)([elt, line]); | ||
} | ||
resourceSpecification(ctx) { | ||
const resourceList = this.visit(ctx.resourceList); | ||
const optionalSemicolon = ctx.Semicolon ? ctx.Semicolon[0] : ""; | ||
return putIntoBraces(rejectAndConcat([resourceList, optionalSemicolon]), softline, ctx.LBrace[0], ctx.RBrace[0]); | ||
} | ||
resourceList(ctx) { | ||
const resources = this.mapVisit(ctx.resource); | ||
const semicolons = ctx.Semicolon | ||
? ctx.Semicolon.map(elt => { | ||
return concat([elt, line]); | ||
}) | ||
: [""]; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(semicolons, resources); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.resource = function (ctx) { | ||
return rejectAndJoinSeps(semicolons, resources); | ||
} | ||
resource(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.yieldStatement = function (ctx) { | ||
var expression = this.visit(ctx.expression); | ||
return (0, prettier_builder_1.join)(" ", [ctx.Yield[0], (0, prettier_builder_1.concat)([expression, ctx.Semicolon[0]])]); | ||
}; | ||
BlocksAndStatementPrettierVisitor.prototype.variableAccess = function (ctx) { | ||
} | ||
yieldStatement(ctx) { | ||
const expression = this.visit(ctx.expression); | ||
return join(" ", [ctx.Yield[0], concat([expression, ctx.Semicolon[0]])]); | ||
} | ||
variableAccess(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; | ||
} | ||
} |
@@ -1,53 +0,17 @@ | ||
"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, lineSuffixBoundary = doc_1.builders.lineSuffixBoundary; | ||
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 = (0, printer_utils_1.sortModifiers)(ctx.classModifier); | ||
var firstAnnotations = this.mapVisit(modifiers[0]); | ||
var otherModifiers = this.mapVisit(modifiers[1]); | ||
var classCST; | ||
import forEach from "lodash/forEach.js"; | ||
import { displaySemicolon, getBlankLinesSeparator, getClassBodyDeclarationsSeparator, isStatementEmptyStatement, putIntoBraces, reject, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortClassTypeChildren, sortModifiers } from "./printer-utils.js"; | ||
import { concat, group, indent, join, indentIfBreak } from "./prettier-builder.js"; | ||
import { printTokenWithComments } from "./comments/format-comments.js"; | ||
import { hasLeadingComments, hasLeadingLineComments } from "./comments/comments-utils.js"; | ||
import { builders } from "prettier/doc"; | ||
import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; | ||
import { isAnnotationCstNode, isTypeArgumentsCstNode } from "../types/utils.js"; | ||
import { printArgumentListWithBraces } from "../utils/index.js"; | ||
const { line, softline, hardline, lineSuffixBoundary } = builders; | ||
export class ClassesPrettierVisitor extends BaseCstPrettierPrinter { | ||
classDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.classModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
let classCST; | ||
if (ctx.normalClassDeclaration !== undefined) { | ||
@@ -62,30 +26,30 @@ classCST = ctx.normalClassDeclaration; | ||
} | ||
var classDoc = this.visit(classCST); | ||
return (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [(0, prettier_builder_1.join)(" ", otherModifiers), classDoc]) | ||
const classDoc = this.visit(classCST); | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [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 = ""; | ||
} | ||
normalClassDeclaration(ctx) { | ||
const name = this.visit(ctx.typeIdentifier); | ||
const optionalTypeParams = this.visit(ctx.typeParameters); | ||
const optionalSuperClasses = this.visit(ctx.superclass); | ||
const optionalSuperInterfaces = this.visit(ctx.superinterfaces); | ||
const optionalClassPermits = this.visit(ctx.classPermits); | ||
const body = this.visit(ctx.classBody, { isNormalClassDeclaration: true }); | ||
let superClassesPart = ""; | ||
if (optionalSuperClasses) { | ||
superClassesPart = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([line, optionalSuperClasses])); | ||
superClassesPart = indent(rejectAndConcat([line, optionalSuperClasses])); | ||
} | ||
var superInterfacesPart = ""; | ||
let superInterfacesPart = ""; | ||
if (optionalSuperInterfaces) { | ||
superInterfacesPart = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([line, optionalSuperInterfaces])); | ||
superInterfacesPart = indent(rejectAndConcat([line, optionalSuperInterfaces])); | ||
} | ||
var classPermits = ""; | ||
let classPermits = ""; | ||
if (optionalClassPermits) { | ||
classPermits = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([line, optionalClassPermits])); | ||
classPermits = indent(rejectAndConcat([line, optionalClassPermits])); | ||
} | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.Class[0], name]), | ||
return rejectAndJoin(" ", [ | ||
group(rejectAndConcat([ | ||
rejectAndJoin(" ", [ctx.Class[0], name]), | ||
optionalTypeParams, | ||
@@ -98,4 +62,4 @@ superClassesPart, | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.classModifier = function (ctx) { | ||
} | ||
classModifier(ctx) { | ||
if (ctx.annotation) { | ||
@@ -105,49 +69,49 @@ return this.visit(ctx.annotation); | ||
// public | protected | private | ... | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
ClassesPrettierVisitor.prototype.typeParameters = function (ctx) { | ||
var typeParameterList = this.visit(ctx.typeParameterList); | ||
return (0, 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 (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoinSeps)(commas, typeParameter)); | ||
}; | ||
ClassesPrettierVisitor.prototype.superclass = function (ctx) { | ||
return (0, prettier_builder_1.join)(" ", [ctx.Extends[0], this.visit(ctx.classType)]); | ||
}; | ||
ClassesPrettierVisitor.prototype.superinterfaces = function (ctx) { | ||
var interfaceTypeList = this.visit(ctx.interfaceTypeList); | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
typeParameters(ctx) { | ||
const typeParameterList = this.visit(ctx.typeParameterList); | ||
return putIntoBraces(typeParameterList, softline, ctx.Less[0], ctx.Greater[0]); | ||
} | ||
typeParameterList(ctx) { | ||
const typeParameter = this.mapVisit(ctx.typeParameter); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
return group(rejectAndJoinSeps(commas, typeParameter)); | ||
} | ||
superclass(ctx) { | ||
return join(" ", [ctx.Extends[0], this.visit(ctx.classType)]); | ||
} | ||
superinterfaces(ctx) { | ||
const interfaceTypeList = this.visit(ctx.interfaceTypeList); | ||
return group(rejectAndConcat([ | ||
ctx.Implements[0], | ||
(0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([line, interfaceTypeList])) | ||
indent(rejectAndConcat([line, interfaceTypeList])) | ||
])); | ||
}; | ||
ClassesPrettierVisitor.prototype.classPermits = function (ctx) { | ||
var typeNames = this.mapVisit(ctx.typeName); | ||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ | ||
} | ||
classPermits(ctx) { | ||
const typeNames = this.mapVisit(ctx.typeName); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
return group(rejectAndConcat([ | ||
ctx.Permits[0], | ||
(0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([line, (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoinSeps)(commas, typeNames))])) | ||
indent(rejectAndConcat([line, group(rejectAndJoinSeps(commas, typeNames))])) | ||
])); | ||
}; | ||
ClassesPrettierVisitor.prototype.interfaceTypeList = function (ctx) { | ||
var interfaceType = this.mapVisit(ctx.interfaceType); | ||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoinSeps)(commas, interfaceType)); | ||
}; | ||
ClassesPrettierVisitor.prototype.classBody = function (ctx, param) { | ||
var content = ""; | ||
} | ||
interfaceTypeList(ctx) { | ||
const interfaceType = this.mapVisit(ctx.interfaceType); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
return group(rejectAndJoinSeps(commas, interfaceType)); | ||
} | ||
classBody(ctx, param) { | ||
let content = ""; | ||
if (ctx.classBodyDeclaration !== undefined) { | ||
var classBodyDeclsVisited = (0, printer_utils_1.reject)(this.mapVisit(ctx.classBodyDeclaration)); | ||
var separators = (0, printer_utils_1.getClassBodyDeclarationsSeparator)(ctx.classBodyDeclaration); | ||
content = (0, printer_utils_1.rejectAndJoinSeps)(separators, classBodyDeclsVisited); | ||
const classBodyDeclsVisited = reject(this.mapVisit(ctx.classBodyDeclaration)); | ||
const separators = getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration); | ||
content = rejectAndJoinSeps(separators, classBodyDeclsVisited); | ||
// edge case when we have SemiColons | ||
var shouldHardline_1 = false; | ||
ctx.classBodyDeclaration.forEach(function (elt) { | ||
let shouldHardline = false; | ||
ctx.classBodyDeclaration.forEach(elt => { | ||
if ((elt.children.classMemberDeclaration && | ||
!elt.children.classMemberDeclaration[0].children.Semicolon) || | ||
elt.children.constructorDeclaration) { | ||
shouldHardline_1 = true; | ||
shouldHardline = true; | ||
} | ||
@@ -157,35 +121,35 @@ }); | ||
ctx.classBodyDeclaration[0].children.constructorDeclaration) && | ||
shouldHardline_1 && | ||
shouldHardline && | ||
param && | ||
param.isNormalClassDeclaration) { | ||
content = (0, printer_utils_1.rejectAndConcat)([hardline, content]); | ||
content = rejectAndConcat([hardline, content]); | ||
} | ||
} | ||
return (0, printer_utils_1.putIntoBraces)(content, hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
}; | ||
ClassesPrettierVisitor.prototype.classBodyDeclaration = function (ctx) { | ||
return putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
} | ||
classBodyDeclaration(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ClassesPrettierVisitor.prototype.classMemberDeclaration = function (ctx) { | ||
} | ||
classMemberDeclaration(ctx) { | ||
if (ctx.Semicolon) { | ||
return (0, printer_utils_1.displaySemicolon)(ctx.Semicolon[0]); | ||
return displaySemicolon(ctx.Semicolon[0]); | ||
} | ||
return this.visitSingle(ctx); | ||
}; | ||
ClassesPrettierVisitor.prototype.fieldDeclaration = function (ctx) { | ||
var modifiers = (0, 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 (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", otherModifiers), | ||
} | ||
fieldDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.fieldModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
const unannType = this.visit(ctx.unannType); | ||
const variableDeclaratorList = this.visit(ctx.variableDeclaratorList); | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", otherModifiers), | ||
unannType, | ||
(0, prettier_builder_1.concat)([variableDeclaratorList, ctx.Semicolon[0]]) | ||
concat([variableDeclaratorList, ctx.Semicolon[0]]) | ||
]) | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.fieldModifier = function (ctx) { | ||
} | ||
fieldModifier(ctx) { | ||
if (ctx.annotation) { | ||
@@ -195,16 +159,16 @@ return this.visit(ctx.annotation); | ||
// public | protected | private | ... | ||
return (0, 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 (0, prettier_builder_1.concat)([elt, " "]); }) : []; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(commas, variableDeclarators); | ||
}; | ||
ClassesPrettierVisitor.prototype.variableDeclarator = function (ctx) { | ||
var variableDeclaratorId = this.visit(ctx.variableDeclaratorId); | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
variableDeclaratorList(ctx) { | ||
const variableDeclarators = this.mapVisit(ctx.variableDeclarator); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, " "])) : []; | ||
return rejectAndJoinSeps(commas, variableDeclarators); | ||
} | ||
variableDeclarator(ctx) { | ||
const variableDeclaratorId = this.visit(ctx.variableDeclaratorId); | ||
if (ctx.Equals) { | ||
var variableInitializer = this.visit(ctx.variableInitializer); | ||
if ((0, comments_utils_1.hasLeadingLineComments)(ctx.variableInitializer[0])) { | ||
return (0, prettier_builder_1.group)((0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [variableDeclaratorId, ctx.Equals[0]]), | ||
const variableInitializer = this.visit(ctx.variableInitializer); | ||
if (hasLeadingLineComments(ctx.variableInitializer[0])) { | ||
return group(indent(rejectAndJoin(hardline, [ | ||
rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]), | ||
variableInitializer | ||
@@ -224,10 +188,10 @@ ]))); | ||
.ternaryExpression[0].children.QuestionMark !== undefined)) { | ||
var groupId = Symbol("assignment"); | ||
return (0, prettier_builder_1.group)([ | ||
(0, prettier_builder_1.group)(variableDeclaratorId), | ||
const groupId = Symbol("assignment"); | ||
return group([ | ||
group(variableDeclaratorId), | ||
" ", | ||
ctx.Equals[0], | ||
(0, prettier_builder_1.group)((0, prettier_builder_1.indent)(line), { id: groupId }), | ||
group(indent(line), { id: groupId }), | ||
lineSuffixBoundary, | ||
(0, prettier_builder_1.indentIfBreak)(variableInitializer, { groupId: groupId }) | ||
indentIfBreak(variableInitializer, { groupId }) | ||
]); | ||
@@ -237,6 +201,6 @@ } | ||
.ternaryExpression !== undefined) { | ||
var unaryExpressions = ctx.variableInitializer[0].children.expression[0].children | ||
const unaryExpressions = ctx.variableInitializer[0].children.expression[0].children | ||
.ternaryExpression[0].children.binaryExpression[0].children | ||
.unaryExpression; | ||
var firstPrimary = unaryExpressions[0].children.primary[0]; | ||
const firstPrimary = unaryExpressions[0].children.primary[0]; | ||
// Cast Expression | ||
@@ -246,10 +210,10 @@ if (firstPrimary.children.primaryPrefix[0].children.castExpression !== | ||
unaryExpressions.length === 1) { | ||
var groupId = Symbol("assignment"); | ||
return (0, prettier_builder_1.group)([ | ||
(0, prettier_builder_1.group)(variableDeclaratorId), | ||
const groupId = Symbol("assignment"); | ||
return group([ | ||
group(variableDeclaratorId), | ||
" ", | ||
ctx.Equals[0], | ||
(0, prettier_builder_1.group)((0, prettier_builder_1.indent)(line), { id: groupId }), | ||
group(indent(line), { id: groupId }), | ||
lineSuffixBoundary, | ||
(0, prettier_builder_1.indentIfBreak)(variableInitializer, { groupId: groupId }) | ||
indentIfBreak(variableInitializer, { groupId }) | ||
]); | ||
@@ -260,34 +224,34 @@ } | ||
undefined) { | ||
var groupId = Symbol("assignment"); | ||
return (0, prettier_builder_1.group)([ | ||
(0, prettier_builder_1.group)(variableDeclaratorId), | ||
const groupId = Symbol("assignment"); | ||
return group([ | ||
group(variableDeclaratorId), | ||
" ", | ||
ctx.Equals[0], | ||
(0, prettier_builder_1.group)((0, prettier_builder_1.indent)(line), { id: groupId }), | ||
group(indent(line), { id: groupId }), | ||
lineSuffixBoundary, | ||
(0, prettier_builder_1.indentIfBreak)(variableInitializer, { groupId: groupId }) | ||
indentIfBreak(variableInitializer, { groupId }) | ||
]); | ||
} | ||
// Method Invocation | ||
var isMethodInvocation = firstPrimary.children.primarySuffix !== undefined && | ||
const isMethodInvocation = firstPrimary.children.primarySuffix !== undefined && | ||
firstPrimary.children.primarySuffix[0].children | ||
.methodInvocationSuffix !== undefined; | ||
var isUniqueUnaryExpression = ctx.variableInitializer[0].children.expression[0].children | ||
const isUniqueUnaryExpression = ctx.variableInitializer[0].children.expression[0].children | ||
.ternaryExpression[0].children.binaryExpression[0].children | ||
.unaryExpression.length === 1; | ||
var isUniqueMethodInvocation = isMethodInvocation && isUniqueUnaryExpression; | ||
const isUniqueMethodInvocation = isMethodInvocation && isUniqueUnaryExpression; | ||
if (isUniqueMethodInvocation) { | ||
var groupId = Symbol("assignment"); | ||
return (0, prettier_builder_1.group)([ | ||
(0, prettier_builder_1.group)(variableDeclaratorId), | ||
const groupId = Symbol("assignment"); | ||
return group([ | ||
group(variableDeclaratorId), | ||
" ", | ||
ctx.Equals[0], | ||
(0, prettier_builder_1.group)((0, prettier_builder_1.indent)(line), { id: groupId }), | ||
group(indent(line), { id: groupId }), | ||
lineSuffixBoundary, | ||
(0, prettier_builder_1.indentIfBreak)(variableInitializer, { groupId: groupId }) | ||
indentIfBreak(variableInitializer, { groupId }) | ||
]); | ||
} | ||
} | ||
return (0, prettier_builder_1.group)((0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndJoin)(line, [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [variableDeclaratorId, ctx.Equals[0]]), | ||
return group(indent(rejectAndJoin(line, [ | ||
rejectAndJoin(" ", [variableDeclaratorId, ctx.Equals[0]]), | ||
variableInitializer | ||
@@ -297,49 +261,48 @@ ]))); | ||
return variableDeclaratorId; | ||
}; | ||
ClassesPrettierVisitor.prototype.variableDeclaratorId = function (ctx) { | ||
} | ||
variableDeclaratorId(ctx) { | ||
if (ctx.Underscore) { | ||
return (0, format_comments_1.printTokenWithComments)(ctx.Underscore[0]); | ||
return printTokenWithComments(ctx.Underscore[0]); | ||
} | ||
var identifier = ctx.Identifier[0]; | ||
var dims = this.visit(ctx.dims); | ||
return (0, printer_utils_1.rejectAndConcat)([identifier, dims]); | ||
}; | ||
ClassesPrettierVisitor.prototype.variableInitializer = function (ctx) { | ||
const identifier = ctx.Identifier[0]; | ||
const dims = this.visit(ctx.dims); | ||
return rejectAndConcat([identifier, dims]); | ||
} | ||
variableInitializer(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ClassesPrettierVisitor.prototype.unannType = function (ctx) { | ||
} | ||
unannType(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ClassesPrettierVisitor.prototype.unannPrimitiveTypeWithOptionalDimsSuffix = function (ctx) { | ||
var unannPrimitiveType = this.visit(ctx.unannPrimitiveType); | ||
var dims = this.visit(ctx.dims); | ||
return (0, printer_utils_1.rejectAndConcat)([unannPrimitiveType, dims]); | ||
}; | ||
ClassesPrettierVisitor.prototype.unannPrimitiveType = function (ctx) { | ||
} | ||
unannPrimitiveTypeWithOptionalDimsSuffix(ctx) { | ||
const unannPrimitiveType = this.visit(ctx.unannPrimitiveType); | ||
const dims = this.visit(ctx.dims); | ||
return rejectAndConcat([unannPrimitiveType, dims]); | ||
} | ||
unannPrimitiveType(ctx) { | ||
if (ctx.numericType) { | ||
return this.visitSingle(ctx); | ||
} | ||
return (0, 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 (0, printer_utils_1.rejectAndConcat)([unannClassOrInterfaceType, dims]); | ||
}; | ||
ClassesPrettierVisitor.prototype.unannClassOrInterfaceType = function (ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
unannReferenceType(ctx) { | ||
const unannClassOrInterfaceType = this.visit(ctx.unannClassOrInterfaceType); | ||
const dims = this.visit(ctx.dims); | ||
return rejectAndConcat([unannClassOrInterfaceType, dims]); | ||
} | ||
unannClassOrInterfaceType(ctx) { | ||
return this.visit(ctx.unannClassType); | ||
}; | ||
ClassesPrettierVisitor.prototype.unannClassType = function (ctx) { | ||
var _this = this; | ||
var tokens = (0, printer_utils_1.sortClassTypeChildren)(ctx.annotation, ctx.typeArguments, ctx.Identifier); | ||
var segments = []; | ||
var currentSegment = []; | ||
(0, forEach_1.default)(tokens, function (token, i) { | ||
if ((0, utils_1.isTypeArgumentsCstNode)(token)) { | ||
currentSegment.push(_this.visit([token])); | ||
segments.push((0, printer_utils_1.rejectAndConcat)(currentSegment)); | ||
} | ||
unannClassType(ctx) { | ||
const tokens = sortClassTypeChildren(ctx.annotation, ctx.typeArguments, ctx.Identifier); | ||
const segments = []; | ||
let currentSegment = []; | ||
forEach(tokens, (token, i) => { | ||
if (isTypeArgumentsCstNode(token)) { | ||
currentSegment.push(this.visit([token])); | ||
segments.push(rejectAndConcat(currentSegment)); | ||
currentSegment = []; | ||
} | ||
else if ((0, utils_1.isAnnotationCstNode)(token)) { | ||
currentSegment.push(_this.visit([token])); | ||
else if (isAnnotationCstNode(token)) { | ||
currentSegment.push(this.visit([token])); | ||
currentSegment.push(" "); | ||
@@ -349,5 +312,5 @@ } | ||
currentSegment.push(token); | ||
if ((i + 1 < tokens.length && !(0, utils_1.isTypeArgumentsCstNode)(tokens[i + 1])) || | ||
if ((i + 1 < tokens.length && !isTypeArgumentsCstNode(tokens[i + 1])) || | ||
i + 1 === tokens.length) { | ||
segments.push((0, printer_utils_1.rejectAndConcat)(currentSegment)); | ||
segments.push(rejectAndConcat(currentSegment)); | ||
currentSegment = []; | ||
@@ -357,26 +320,26 @@ } | ||
}); | ||
return (0, printer_utils_1.rejectAndJoinSeps)(ctx.Dot, segments); | ||
}; | ||
ClassesPrettierVisitor.prototype.unannInterfaceType = function (ctx) { | ||
return rejectAndJoinSeps(ctx.Dot, segments); | ||
} | ||
unannInterfaceType(ctx) { | ||
return this.visit(ctx.unannClassType); | ||
}; | ||
ClassesPrettierVisitor.prototype.unannTypeVariable = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
ClassesPrettierVisitor.prototype.methodDeclaration = function (ctx) { | ||
var modifiers = (0, 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 = (0, printer_utils_1.isStatementEmptyStatement)(body) ? "" : " "; | ||
return (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", otherModifiers), | ||
(0, printer_utils_1.rejectAndJoin)(headerBodySeparator, [header, body]) | ||
} | ||
unannTypeVariable(ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
methodDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.methodModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
const header = this.visit(ctx.methodHeader); | ||
const body = this.visit(ctx.methodBody); | ||
const headerBodySeparator = isStatementEmptyStatement(body) ? "" : " "; | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", otherModifiers), | ||
rejectAndJoin(headerBodySeparator, [header, body]) | ||
]) | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.methodModifier = function (ctx) { | ||
} | ||
methodModifier(ctx) { | ||
if (ctx.annotation) { | ||
@@ -386,14 +349,14 @@ return this.visit(ctx.annotation); | ||
// public | protected | private | Synchronized | ... | ||
return (0, 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 (0, prettier_builder_1.group)((0, prettier_builder_1.concat)([ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
methodHeader(ctx) { | ||
const typeParameters = this.visit(ctx.typeParameters); | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const result = this.visit(ctx.result); | ||
const declarator = this.visit(ctx.methodDeclarator); | ||
const throws = this.visit(ctx.throws); | ||
return group(concat([ | ||
rejectAndJoin(" ", [ | ||
typeParameters, | ||
(0, printer_utils_1.rejectAndJoin)(line, annotations), | ||
rejectAndJoin(line, annotations), | ||
result, | ||
@@ -404,4 +367,4 @@ declarator, | ||
])); | ||
}; | ||
ClassesPrettierVisitor.prototype.result = function (ctx) { | ||
} | ||
result(ctx) { | ||
if (ctx.unannType) { | ||
@@ -411,58 +374,60 @@ return this.visit(ctx.unannType); | ||
// void | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
ClassesPrettierVisitor.prototype.methodDeclarator = function (ctx) { | ||
var identifier = (0, format_comments_1.printTokenWithComments)(ctx.Identifier[0]); | ||
var formalParameterList = this.visit(ctx.formalParameterList); | ||
var dims = this.visit(ctx.dims); | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
methodDeclarator(ctx) { | ||
var _a; | ||
const identifier = printTokenWithComments(ctx.Identifier[0]); | ||
const receiverParameter = this.visit(ctx.receiverParameter); | ||
const formalParameterList = this.visit(ctx.formalParameterList); | ||
const dims = this.visit(ctx.dims); | ||
return rejectAndConcat([ | ||
identifier, | ||
(0, printer_utils_1.putIntoBraces)(formalParameterList, softline, ctx.LBrace[0], ctx.RBrace[0]), | ||
putIntoBraces(rejectAndJoin(line, [ | ||
rejectAndConcat([receiverParameter, (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a[0]]), | ||
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 | ||
? (0, prettier_builder_1.concat)([ctx.Identifier[0], ctx.Dot[0]]) | ||
: ""; | ||
return (0, printer_utils_1.rejectAndJoin)("", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", annotations), | ||
} | ||
receiverParameter(ctx) { | ||
var _a, _b; | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const unannType = this.visit(ctx.unannType); | ||
return rejectAndJoin(" ", [ | ||
...annotations, | ||
unannType, | ||
identifier, | ||
ctx.This[0] | ||
rejectAndConcat([(_a = ctx.Identifier) === null || _a === void 0 ? void 0 : _a[0], (_b = ctx.Dot) === null || _b === void 0 ? void 0 : _b[0], ctx.This[0]]) | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.formalParameterList = function (ctx) { | ||
var formalParameter = this.mapVisit(ctx.formalParameter); | ||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(commas, formalParameter); | ||
}; | ||
ClassesPrettierVisitor.prototype.formalParameter = function (ctx) { | ||
} | ||
formalParameterList(ctx) { | ||
const formalParameter = this.mapVisit(ctx.formalParameter); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
return rejectAndJoinSeps(commas, formalParameter); | ||
} | ||
formalParameter(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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", variableModifier), | ||
} | ||
variableParaRegularParameter(ctx) { | ||
const variableModifier = this.mapVisit(ctx.variableModifier); | ||
const unannType = this.visit(ctx.unannType); | ||
const variableDeclaratorId = this.visit(ctx.variableDeclaratorId); | ||
return rejectAndJoin(" ", [ | ||
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 | ||
? (0, prettier_builder_1.concat)([unannType, ctx.DotDotDot[0]]) | ||
} | ||
variableArityParameter(ctx) { | ||
const variableModifier = this.mapVisit(ctx.variableModifier); | ||
const unannType = this.visit(ctx.unannType); | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const identifier = ctx.Identifier[0]; | ||
const unannTypePrinted = ctx.annotation === undefined | ||
? concat([unannType, ctx.DotDotDot[0]]) | ||
: unannType; | ||
var annotationsPrinted = ctx.annotation === undefined | ||
const annotationsPrinted = ctx.annotation === undefined | ||
? annotations | ||
: (0, prettier_builder_1.concat)([(0, printer_utils_1.rejectAndJoin)(" ", annotations), ctx.DotDotDot[0]]); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.join)(" ", variableModifier), | ||
: concat([rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]); | ||
return rejectAndJoin(" ", [ | ||
join(" ", variableModifier), | ||
unannTypePrinted, | ||
@@ -472,47 +437,47 @@ annotationsPrinted, | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.variableModifier = function (ctx) { | ||
} | ||
variableModifier(ctx) { | ||
if (ctx.annotation) { | ||
return this.visit(ctx.annotation); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
ClassesPrettierVisitor.prototype.throws = function (ctx) { | ||
var exceptionTypeList = this.visit(ctx.exceptionTypeList); | ||
var throwsDeclaration = (0, prettier_builder_1.join)(" ", [ctx.Throws[0], exceptionTypeList]); | ||
return (0, prettier_builder_1.group)((0, prettier_builder_1.indent)((0, 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 (0, prettier_builder_1.concat)([elt, " "]); }) : []; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(commas, exceptionTypes); | ||
}; | ||
ClassesPrettierVisitor.prototype.exceptionType = function (ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
throws(ctx) { | ||
const exceptionTypeList = this.visit(ctx.exceptionTypeList); | ||
const throwsDeclaration = join(" ", [ctx.Throws[0], exceptionTypeList]); | ||
return group(indent(rejectAndConcat([softline, throwsDeclaration]))); | ||
} | ||
exceptionTypeList(ctx) { | ||
const exceptionTypes = this.mapVisit(ctx.exceptionType); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, " "])) : []; | ||
return rejectAndJoinSeps(commas, exceptionTypes); | ||
} | ||
exceptionType(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ClassesPrettierVisitor.prototype.methodBody = function (ctx) { | ||
} | ||
methodBody(ctx) { | ||
if (ctx.block) { | ||
return this.visit(ctx.block); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
ClassesPrettierVisitor.prototype.instanceInitializer = function (ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
instanceInitializer(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ClassesPrettierVisitor.prototype.staticInitializer = function (ctx) { | ||
var block = this.visit(ctx.block); | ||
return (0, prettier_builder_1.join)(" ", [ctx.Static[0], block]); | ||
}; | ||
ClassesPrettierVisitor.prototype.constructorDeclaration = function (ctx) { | ||
var modifiers = (0, 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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.join)(" ", otherModifiers), | ||
} | ||
staticInitializer(ctx) { | ||
const block = this.visit(ctx.block); | ||
return join(" ", [ctx.Static[0], block]); | ||
} | ||
constructorDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.constructorModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
const constructorDeclarator = this.visit(ctx.constructorDeclarator); | ||
const throws = this.visit(ctx.throws); | ||
const constructorBody = this.visit(ctx.constructorBody); | ||
return rejectAndJoin(" ", [ | ||
group(rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [ | ||
join(" ", otherModifiers), | ||
constructorDeclarator, | ||
@@ -524,4 +489,4 @@ throws | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.constructorModifier = function (ctx) { | ||
} | ||
constructorModifier(ctx) { | ||
if (ctx.annotation) { | ||
@@ -531,44 +496,47 @@ return this.visit(ctx.annotation); | ||
// public | protected | private | Synchronized | ... | ||
return (0, 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 (0, prettier_builder_1.concat)([elt, " "]); }) : []; | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
constructorDeclarator(ctx) { | ||
var _a; | ||
const typeParameters = this.visit(ctx.typeParameters); | ||
const simpleTypeName = this.visit(ctx.simpleTypeName); | ||
const receiverParameter = this.visit(ctx.receiverParameter); | ||
const formalParameterList = this.visit(ctx.formalParameterList); | ||
return rejectAndJoin(" ", [ | ||
typeParameters, | ||
(0, prettier_builder_1.concat)([ | ||
concat([ | ||
simpleTypeName, | ||
(0, printer_utils_1.putIntoBraces)((0, printer_utils_1.rejectAndJoinSeps)(commas, [receiverParameter, formalParameterList]), softline, ctx.LBrace[0], ctx.RBrace[0]) | ||
putIntoBraces(rejectAndJoin(line, [ | ||
rejectAndConcat([receiverParameter, (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a[0]]), | ||
formalParameterList | ||
]), softline, ctx.LBrace[0], ctx.RBrace[0]) | ||
]) | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.simpleTypeName = function (ctx) { | ||
return (0, 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 (0, printer_utils_1.putIntoBraces)((0, printer_utils_1.rejectAndJoin)(hardline, [explicitConstructorInvocation, blockStatements]), hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
}; | ||
ClassesPrettierVisitor.prototype.explicitConstructorInvocation = function (ctx) { | ||
} | ||
simpleTypeName(ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
constructorBody(ctx) { | ||
const explicitConstructorInvocation = this.visit(ctx.explicitConstructorInvocation); | ||
const blockStatements = this.visit(ctx.blockStatements); | ||
return putIntoBraces(rejectAndJoin(hardline, [explicitConstructorInvocation, blockStatements]), hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
} | ||
explicitConstructorInvocation(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 (0, printer_utils_1.rejectAndConcat)([ | ||
} | ||
unqualifiedExplicitConstructorInvocation(ctx) { | ||
const typeArguments = this.visit(ctx.typeArguments); | ||
const keyWord = ctx.This ? ctx.This[0] : ctx.Super[0]; | ||
const argumentList = printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]); | ||
return rejectAndConcat([ | ||
typeArguments, | ||
keyWord, | ||
(0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([argumentList, ctx.Semicolon[0]])) | ||
group(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 (0, printer_utils_1.rejectAndConcat)([ | ||
} | ||
qualifiedExplicitConstructorInvocation(ctx) { | ||
const expressionName = this.visit(ctx.expressionName); | ||
const typeArguments = this.visit(ctx.typeArguments); | ||
const argumentList = printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]); | ||
return rejectAndConcat([ | ||
expressionName, | ||
@@ -578,12 +546,12 @@ ctx.Dot[0], | ||
ctx.Super[0], | ||
(0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([argumentList, ctx.Semicolon[0]])) | ||
group(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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.join)(" ", classModifier), | ||
} | ||
enumDeclaration(ctx) { | ||
const classModifier = this.mapVisit(ctx.classModifier); | ||
const typeIdentifier = this.visit(ctx.typeIdentifier); | ||
const superinterfaces = this.visit(ctx.superinterfaces); | ||
const enumBody = this.visit(ctx.enumBody); | ||
return rejectAndJoin(" ", [ | ||
join(" ", classModifier), | ||
ctx.Enum[0], | ||
@@ -594,15 +562,15 @@ typeIdentifier, | ||
]); | ||
}; | ||
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 || | ||
} | ||
enumBody(ctx) { | ||
const enumConstantList = this.visit(ctx.enumConstantList); | ||
const enumBodyDeclarations = this.visit(ctx.enumBodyDeclarations); | ||
const hasEnumConstants = ctx.enumConstantList !== undefined; | ||
const hasNoClassBodyDeclarations = ctx.enumBodyDeclarations === undefined || | ||
ctx.enumBodyDeclarations[0].children.classBodyDeclaration === undefined; | ||
// edge case: https://github.com/jhipster/prettier-java/issues/383 | ||
var handleEnumBodyDeclarationsLeadingComments = !hasNoClassBodyDeclarations && | ||
(0, comments_utils_1.hasLeadingComments)(ctx.enumBodyDeclarations[0]) | ||
const handleEnumBodyDeclarationsLeadingComments = !hasNoClassBodyDeclarations && | ||
hasLeadingComments(ctx.enumBodyDeclarations[0]) | ||
? hardline | ||
: ""; | ||
var optionalComma; | ||
let optionalComma; | ||
if (hasEnumConstants && | ||
@@ -614,5 +582,5 @@ hasNoClassBodyDeclarations && | ||
else { | ||
optionalComma = ctx.Comma ? __assign(__assign({}, ctx.Comma[0]), { image: "" }) : ""; | ||
optionalComma = ctx.Comma ? Object.assign(Object.assign({}, ctx.Comma[0]), { image: "" }) : ""; | ||
} | ||
return (0, printer_utils_1.putIntoBraces)((0, printer_utils_1.rejectAndConcat)([ | ||
return putIntoBraces(rejectAndConcat([ | ||
enumConstantList, | ||
@@ -623,58 +591,56 @@ optionalComma, | ||
]), hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
}; | ||
ClassesPrettierVisitor.prototype.enumConstantList = function (ctx) { | ||
var enumConstants = this.mapVisit(ctx.enumConstant); | ||
var blankLineSeparators = (0, printer_utils_1.getBlankLinesSeparator)(ctx.enumConstant); | ||
var commas = ctx.Comma | ||
? ctx.Comma.map(function (elt, index) { | ||
return (0, prettier_builder_1.concat)([elt, blankLineSeparators[index]]); | ||
}) | ||
} | ||
enumConstantList(ctx) { | ||
const enumConstants = this.mapVisit(ctx.enumConstant); | ||
const blankLineSeparators = getBlankLinesSeparator(ctx.enumConstant); | ||
const commas = ctx.Comma | ||
? ctx.Comma.map((elt, index) => concat([elt, blankLineSeparators[index]])) | ||
: []; | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoinSeps)(commas, enumConstants)); | ||
}; | ||
ClassesPrettierVisitor.prototype.enumConstant = function (ctx) { | ||
var modifiers = (0, 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 group(rejectAndJoinSeps(commas, enumConstants)); | ||
} | ||
enumConstant(ctx) { | ||
const modifiers = sortModifiers(ctx.enumConstantModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
const identifier = ctx.Identifier[0]; | ||
const classBody = this.visit(ctx.classBody); | ||
const optionalBracesAndArgumentList = ctx.LBrace | ||
? printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]) | ||
: ""; | ||
return (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", otherModifiers), | ||
(0, printer_utils_1.rejectAndConcat)([identifier, optionalBracesAndArgumentList]), | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", otherModifiers), | ||
rejectAndConcat([identifier, optionalBracesAndArgumentList]), | ||
classBody | ||
]) | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.enumConstantModifier = function (ctx) { | ||
} | ||
enumConstantModifier(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ClassesPrettierVisitor.prototype.enumBodyDeclarations = function (ctx) { | ||
} | ||
enumBodyDeclarations(ctx) { | ||
if (ctx.classBodyDeclaration !== undefined) { | ||
var classBodyDeclaration = this.mapVisit(ctx.classBodyDeclaration); | ||
var separators = (0, printer_utils_1.getClassBodyDeclarationsSeparator)(ctx.classBodyDeclaration); | ||
return (0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([hardline, hardline]), [ | ||
const classBodyDeclaration = this.mapVisit(ctx.classBodyDeclaration); | ||
const separators = getClassBodyDeclarationsSeparator(ctx.classBodyDeclaration); | ||
return rejectAndJoin(concat([hardline, hardline]), [ | ||
ctx.Semicolon[0], | ||
(0, printer_utils_1.rejectAndJoinSeps)(separators, classBodyDeclaration) | ||
rejectAndJoinSeps(separators, classBodyDeclaration) | ||
]); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(__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); | ||
return printTokenWithComments(Object.assign(Object.assign({}, ctx.Semicolon[0]), { image: "" })); | ||
} | ||
recordDeclaration(ctx) { | ||
const name = this.visit(ctx.typeIdentifier); | ||
const optionalTypeParams = this.visit(ctx.typeParameters); | ||
const recordHeader = this.visit(ctx.recordHeader); | ||
let superInterfacesPart = ""; | ||
const optionalSuperInterfaces = this.visit(ctx.superinterfaces); | ||
if (optionalSuperInterfaces) { | ||
superInterfacesPart = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([line, optionalSuperInterfaces])); | ||
superInterfacesPart = indent(rejectAndConcat([line, optionalSuperInterfaces])); | ||
} | ||
var body = this.visit(ctx.recordBody); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.Record[0], name]), | ||
const body = this.visit(ctx.recordBody); | ||
return rejectAndJoin(" ", [ | ||
group(rejectAndConcat([ | ||
rejectAndJoin(" ", [ctx.Record[0], name]), | ||
optionalTypeParams, | ||
@@ -686,83 +652,70 @@ recordHeader, | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.recordHeader = function (ctx) { | ||
var recordComponentList = this.visit(ctx.recordComponentList); | ||
return (0, 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 = (0, printer_utils_1.getBlankLinesSeparator)(ctx.recordComponent, line); | ||
var commas = ctx.Comma | ||
? ctx.Comma.map(function (elt, index) { | ||
return (0, prettier_builder_1.concat)([elt, blankLineSeparators[index]]); | ||
}) | ||
} | ||
recordHeader(ctx) { | ||
const recordComponentList = this.visit(ctx.recordComponentList); | ||
return putIntoBraces(recordComponentList, softline, ctx.LBrace[0], ctx.RBrace[0]); | ||
} | ||
recordComponentList(ctx) { | ||
const recordComponents = this.mapVisit(ctx.recordComponent); | ||
const blankLineSeparators = getBlankLinesSeparator(ctx.recordComponent, line); | ||
const commas = ctx.Comma | ||
? ctx.Comma.map((elt, index) => concat([elt, blankLineSeparators[index]])) | ||
: []; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(commas, recordComponents); | ||
}; | ||
ClassesPrettierVisitor.prototype.recordComponent = function (ctx) { | ||
var modifiers = this.mapVisit(ctx.recordComponentModifier); | ||
var unannType = this.visit(ctx.unannType); | ||
return rejectAndJoinSeps(commas, recordComponents); | ||
} | ||
recordComponent(ctx) { | ||
const modifiers = this.mapVisit(ctx.recordComponentModifier); | ||
const unannType = this.visit(ctx.unannType); | ||
if (ctx.Identifier !== undefined) { | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(line, [ | ||
(0, prettier_builder_1.join)(line, modifiers), | ||
(0, prettier_builder_1.join)(" ", [unannType, ctx.Identifier[0]]) | ||
return group(rejectAndJoin(line, [ | ||
join(line, modifiers), | ||
join(" ", [unannType, ctx.Identifier[0]]) | ||
])); | ||
} | ||
var variableArityRecordComponent = this.visit(ctx.variableArityRecordComponent); | ||
const variableArityRecordComponent = this.visit(ctx.variableArityRecordComponent); | ||
if (ctx.variableArityRecordComponent[0].children.annotation !== undefined) { | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(line, [ | ||
(0, prettier_builder_1.join)(line, modifiers), | ||
(0, prettier_builder_1.join)(" ", [unannType, variableArityRecordComponent]) | ||
return group(rejectAndJoin(line, [ | ||
join(line, modifiers), | ||
join(" ", [unannType, variableArityRecordComponent]) | ||
])); | ||
} | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(line, [ | ||
(0, prettier_builder_1.join)(line, modifiers), | ||
(0, prettier_builder_1.concat)([unannType, variableArityRecordComponent]) | ||
return group(rejectAndJoin(line, [ | ||
join(line, modifiers), | ||
concat([unannType, variableArityRecordComponent]) | ||
])); | ||
}; | ||
ClassesPrettierVisitor.prototype.variableArityRecordComponent = function (ctx) { | ||
var annotations = this.mapVisit(ctx.annotation); | ||
var identifier = ctx.Identifier[0]; | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndConcat)([(0, printer_utils_1.rejectAndJoin)(" ", annotations), ctx.DotDotDot[0]]), | ||
} | ||
variableArityRecordComponent(ctx) { | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const identifier = ctx.Identifier[0]; | ||
return rejectAndJoin(" ", [ | ||
rejectAndConcat([rejectAndJoin(" ", annotations), ctx.DotDotDot[0]]), | ||
identifier | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.recordComponentModifier = function (ctx) { | ||
} | ||
recordComponentModifier(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ClassesPrettierVisitor.prototype.recordBody = function (ctx) { | ||
return (0, printer_utils_1.putIntoBraces)((0, printer_utils_1.rejectAndJoinSeps)((0, printer_utils_1.getBlankLinesSeparator)(ctx.recordBodyDeclaration), this.mapVisit(ctx.recordBodyDeclaration)), hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
}; | ||
ClassesPrettierVisitor.prototype.recordBodyDeclaration = function (ctx) { | ||
} | ||
recordBody(ctx) { | ||
return putIntoBraces(rejectAndJoinSeps(getBlankLinesSeparator(ctx.recordBodyDeclaration), this.mapVisit(ctx.recordBodyDeclaration)), hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
} | ||
recordBodyDeclaration(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ClassesPrettierVisitor.prototype.compactConstructorDeclaration = function (ctx) { | ||
var modifiers = (0, 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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [(0, prettier_builder_1.join)(" ", otherModifiers), name]) | ||
} | ||
compactConstructorDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.constructorModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
const name = this.visit(ctx.simpleTypeName); | ||
const constructorBody = this.visit(ctx.constructorBody); | ||
return rejectAndJoin(" ", [ | ||
group(rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [join(" ", otherModifiers), name]) | ||
])), | ||
constructorBody | ||
]); | ||
}; | ||
ClassesPrettierVisitor.prototype.isClassDeclaration = function () { | ||
return "isClassDeclaration"; | ||
}; | ||
ClassesPrettierVisitor.prototype.identifyClassBodyDeclarationType = function () { | ||
return "identifyClassBodyDeclarationType"; | ||
}; | ||
ClassesPrettierVisitor.prototype.isDims = function () { | ||
} | ||
isDims() { | ||
return "isDims"; | ||
}; | ||
ClassesPrettierVisitor.prototype.isCompactConstructorDeclaration = function () { | ||
return "isCompactConstructorDeclaration"; | ||
}; | ||
return ClassesPrettierVisitor; | ||
}(base_cst_printer_1.BaseCstPrettierPrinter)); | ||
exports.ClassesPrettierVisitor = ClassesPrettierVisitor; | ||
} | ||
} |
@@ -1,13 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hasComments = exports.hasTrailingLineComments = exports.hasLeadingLineComments = exports.hasTrailingComments = exports.hasLeadingComments = void 0; | ||
function hasLeadingComments(token) { | ||
export function hasLeadingComments(token) { | ||
return token.leadingComments !== undefined; | ||
} | ||
exports.hasLeadingComments = hasLeadingComments; | ||
function hasTrailingComments(token) { | ||
export function hasTrailingComments(token) { | ||
return token.trailingComments !== undefined; | ||
} | ||
exports.hasTrailingComments = hasTrailingComments; | ||
function hasLeadingLineComments(token) { | ||
export function hasLeadingLineComments(token) { | ||
return (token.leadingComments !== undefined && | ||
@@ -18,4 +13,3 @@ token.leadingComments.length !== 0 && | ||
} | ||
exports.hasLeadingLineComments = hasLeadingLineComments; | ||
function hasTrailingLineComments(token) { | ||
export function hasTrailingLineComments(token) { | ||
return (token.trailingComments !== undefined && | ||
@@ -26,6 +20,4 @@ token.trailingComments.length !== 0 && | ||
} | ||
exports.hasTrailingLineComments = hasTrailingLineComments; | ||
function hasComments(token) { | ||
export function hasComments(token) { | ||
return hasLeadingComments(token) || hasTrailingComments(token); | ||
} | ||
exports.hasComments = hasComments; |
@@ -1,20 +0,6 @@ | ||
"use strict"; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
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 isEmptyDoc_1 = __importDefault(require("../../utils/isEmptyDoc")); | ||
var hardline = doc_1.builders.hardline, lineSuffix = doc_1.builders.lineSuffix, breakParent = doc_1.builders.breakParent, literalline = doc_1.builders.literalline; | ||
import { builders } from "prettier/doc"; | ||
import { isCstElementOrUndefinedIToken } from "../../types/utils.js"; | ||
import { doc } from "prettier"; | ||
import isEmptyDoc from "../../utils/isEmptyDoc.js"; | ||
const { hardline, lineSuffix, breakParent, literalline } = builders; | ||
/** | ||
@@ -29,6 +15,7 @@ * Takes a token and return a doc with: | ||
*/ | ||
function printTokenWithComments(token) { | ||
return printWithComments(token, token.image, getTokenLeadingComments, getTokenTrailingComments); | ||
export function printTokenWithComments(token) { | ||
return printWithComments(token, token.image.includes("\n") | ||
? doc.utils.replaceEndOfLine(token.image) | ||
: token.image, getTokenLeadingComments, getTokenTrailingComments); | ||
} | ||
exports.printTokenWithComments = printTokenWithComments; | ||
/** | ||
@@ -44,12 +31,11 @@ * Takes a node and return a doc with: | ||
*/ | ||
function printNodeWithComments(node, value) { | ||
export 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); | ||
const leadingComments = getLeadingComments(nodeOrToken); | ||
const trailingComments = getTrailingComments(nodeOrToken, value); | ||
return leadingComments.length === 0 && trailingComments.length === 0 | ||
? value | ||
: __spreadArray(__spreadArray(__spreadArray([], leadingComments, true), [value], false), trailingComments, true); | ||
: [...leadingComments, value, ...trailingComments]; | ||
} | ||
@@ -60,6 +46,5 @@ /** | ||
*/ | ||
function getTokenLeadingComments(token) { | ||
export function getTokenLeadingComments(token) { | ||
return getLeadingComments(token, token); | ||
} | ||
exports.getTokenLeadingComments = getTokenLeadingComments; | ||
/** | ||
@@ -73,8 +58,8 @@ * @param {CstNode} node | ||
function getLeadingComments(nodeOrToken, location) { | ||
var arr = []; | ||
const arr = []; | ||
if (nodeOrToken.leadingComments !== undefined) { | ||
var previousEndLine = nodeOrToken.leadingComments[0].endLine; | ||
var step = void 0; | ||
let previousEndLine = nodeOrToken.leadingComments[0].endLine; | ||
let step; | ||
arr.push(formatComment(nodeOrToken.leadingComments[0])); | ||
for (var i = 1; i < nodeOrToken.leadingComments.length; i++) { | ||
for (let i = 1; i < nodeOrToken.leadingComments.length; i++) { | ||
step = nodeOrToken.leadingComments[i].startLine - previousEndLine; | ||
@@ -119,11 +104,11 @@ if (step === 1 || | ||
function getTrailingComments(nodeOrToken, value, location) { | ||
var arr = []; | ||
var previousEndLine = location.endLine; | ||
const arr = []; | ||
let previousEndLine = location.endLine; | ||
if (nodeOrToken.trailingComments !== undefined) { | ||
nodeOrToken.trailingComments.forEach(function (comment, idx) { | ||
var separator = ""; | ||
nodeOrToken.trailingComments.forEach((comment, idx) => { | ||
let separator = ""; | ||
if (comment.startLine !== previousEndLine) { | ||
arr.push(hardline); | ||
} | ||
else if (!(0, isEmptyDoc_1.default)(value) && idx === 0) { | ||
else if (!isEmptyDoc(value) && idx === 0) { | ||
separator = " "; | ||
@@ -143,5 +128,5 @@ } | ||
function isJavaDoc(comment, lines) { | ||
var isJavaDoc = true; | ||
let isJavaDoc = true; | ||
if (comment.tokenType.name === "TraditionalComment" && lines.length > 1) { | ||
for (var i = 1; i < lines.length; i++) { | ||
for (let i = 1; i < lines.length; i++) { | ||
if (lines[i].trim().charAt(0) !== "*") { | ||
@@ -159,4 +144,4 @@ isJavaDoc = false; | ||
function formatJavaDoc(lines) { | ||
var res = [lines[0].trim()]; | ||
for (var i = 1; i < lines.length; i++) { | ||
const res = [lines[0].trim()]; | ||
for (let i = 1; i < lines.length; i++) { | ||
res.push(hardline); | ||
@@ -168,8 +153,8 @@ res.push(" " + lines[i].trim()); | ||
function formatComment(comment) { | ||
var res = []; | ||
var lines = comment.image.split("\n"); | ||
const res = []; | ||
const lines = comment.image.split("\n"); | ||
if (isJavaDoc(comment, lines)) { | ||
return formatJavaDoc(lines); | ||
} | ||
lines.forEach(function (line) { | ||
lines.forEach(line => { | ||
res.push(line); | ||
@@ -181,5 +166,5 @@ res.push(literalline); | ||
} | ||
function processComments(docs) { | ||
export function processComments(docs) { | ||
if (!Array.isArray(docs)) { | ||
if ((0, utils_1.isCstElementOrUndefinedIToken)(docs)) { | ||
if (isCstElementOrUndefinedIToken(docs)) { | ||
return printTokenWithComments(docs); | ||
@@ -189,4 +174,4 @@ } | ||
} | ||
return docs.map(function (elt) { | ||
if ((0, utils_1.isCstElementOrUndefinedIToken)(elt)) { | ||
return docs.map(elt => { | ||
if (isCstElementOrUndefinedIToken(elt)) { | ||
return printTokenWithComments(elt); | ||
@@ -197,2 +182,1 @@ } | ||
} | ||
exports.processComments = processComments; |
@@ -1,16 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleCommentsBinaryExpression = void 0; | ||
var comments_utils_1 = require("./comments-utils"); | ||
function handleCommentsBinaryExpression(ctx) { | ||
import { hasLeadingComments, hasTrailingComments } from "./comments-utils.js"; | ||
export function handleCommentsBinaryExpression(ctx) { | ||
moveOperatorLeadingCommentsToNextExpression(ctx); | ||
moveExpressionTrailingCommentsToNextOperator(ctx); | ||
} | ||
exports.handleCommentsBinaryExpression = handleCommentsBinaryExpression; | ||
function moveOperatorLeadingCommentsToNextExpression(ctx) { | ||
var _a; | ||
var unaryExpressionIndex = 1; | ||
(_a = ctx.BinaryOperator) === null || _a === void 0 ? void 0 : _a.forEach(function (binaryOperator) { | ||
var _a; | ||
if ((0, comments_utils_1.hasLeadingComments)(binaryOperator)) { | ||
let unaryExpressionIndex = 1; | ||
(_a = ctx.BinaryOperator) === null || _a === void 0 ? void 0 : _a.forEach(binaryOperator => { | ||
if (hasLeadingComments(binaryOperator)) { | ||
while (ctx.unaryExpression[unaryExpressionIndex].location.startOffset < | ||
@@ -21,3 +16,3 @@ binaryOperator.endOffset) { | ||
// Adapt the position of the operator and its leading comments | ||
var shiftUp = binaryOperator.leadingComments[0].startLine - | ||
const shiftUp = binaryOperator.leadingComments[0].startLine - | ||
1 - | ||
@@ -27,3 +22,3 @@ binaryOperator.startLine; | ||
ctx.unaryExpression[unaryExpressionIndex].location.startLine) { | ||
binaryOperator.leadingComments.forEach(function (comment) { | ||
binaryOperator.leadingComments.forEach(comment => { | ||
comment.startLine += 1; | ||
@@ -39,3 +34,3 @@ comment.endLine += 1; | ||
ctx.unaryExpression[unaryExpressionIndex].leadingComments || []; | ||
(_a = ctx.unaryExpression[unaryExpressionIndex].leadingComments).unshift.apply(_a, binaryOperator.leadingComments); | ||
ctx.unaryExpression[unaryExpressionIndex].leadingComments.unshift(...binaryOperator.leadingComments); | ||
delete binaryOperator.leadingComments; | ||
@@ -46,9 +41,8 @@ } | ||
function moveExpressionTrailingCommentsToNextOperator(ctx) { | ||
var binaryOperators = ctx.BinaryOperator; | ||
var binaryOperatorIndex = 1; | ||
const binaryOperators = ctx.BinaryOperator; | ||
let binaryOperatorIndex = 1; | ||
if (binaryOperators === null || binaryOperators === void 0 ? void 0 : binaryOperators.length) { | ||
ctx.unaryExpression.forEach(function (unaryExpression) { | ||
ctx.unaryExpression.forEach(unaryExpression => { | ||
var _a; | ||
var _b; | ||
if ((0, comments_utils_1.hasTrailingComments)(unaryExpression)) { | ||
if (hasTrailingComments(unaryExpression)) { | ||
while (binaryOperatorIndex < binaryOperators.length && | ||
@@ -60,9 +54,9 @@ unaryExpression.location.endOffset && | ||
} | ||
var binaryOperator = binaryOperators[binaryOperatorIndex]; | ||
const binaryOperator = binaryOperators[binaryOperatorIndex]; | ||
// Adapt the position of the expression and its trailing comments | ||
var shiftUp = unaryExpression.trailingComments[0].startLine - | ||
const shiftUp = unaryExpression.trailingComments[0].startLine - | ||
1 - | ||
unaryExpression.location.startLine; | ||
if (unaryExpression.location.startLine !== binaryOperator.startLine) { | ||
unaryExpression.trailingComments.forEach(function (comment) { | ||
unaryExpression.trailingComments.forEach(comment => { | ||
comment.startLine += 1; | ||
@@ -78,4 +72,4 @@ comment.endLine += 1; | ||
// binaryOperator | ||
binaryOperator.trailingComments = (_b = binaryOperator.trailingComments) !== null && _b !== void 0 ? _b : []; | ||
(_a = binaryOperator.trailingComments).unshift.apply(_a, unaryExpression.trailingComments); | ||
binaryOperator.trailingComments = (_a = binaryOperator.trailingComments) !== null && _a !== void 0 ? _a : []; | ||
binaryOperator.trailingComments.unshift(...unaryExpression.trailingComments); | ||
delete unaryExpression.trailingComments; | ||
@@ -82,0 +76,0 @@ } |
@@ -1,94 +0,38 @@ | ||
"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, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
import forEach from "lodash/forEach.js"; | ||
import { builders } from "prettier/doc"; | ||
import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; | ||
import { isAnnotationCstNode } from "../types/utils.js"; | ||
import { printArgumentListWithBraces } from "../utils/index.js"; | ||
import { printTokenWithComments } from "./comments/format-comments.js"; | ||
import { handleCommentsBinaryExpression } from "./comments/handle-comments.js"; | ||
import { concat, dedent, group, indent } from "./prettier-builder.js"; | ||
import { binary, findDeepElementInPartsArray, isExplicitLambdaParameter, isUniqueMethodInvocation, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortAnnotationIdentifier, sortNodes, sortTokens } from "./printer-utils.js"; | ||
const { hardline, ifBreak, line, lineSuffixBoundary, softline } = builders; | ||
export class ExpressionsPrettierVisitor extends BaseCstPrettierPrinter { | ||
expression(ctx, params) { | ||
return this.visitSingle(ctx, params); | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
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 = (0, 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; | ||
lambdaExpression(ctx, params) { | ||
const lambdaParameters = group(this.visit(ctx.lambdaParameters, params)); | ||
const lambdaBody = this.visit(ctx.lambdaBody); | ||
const isLambdaBodyABlock = ctx.lambdaBody[0].children.block !== undefined; | ||
if (isLambdaBodyABlock) { | ||
return (0, 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 rejectAndJoin(" ", [lambdaParameters, ctx.Arrow[0], lambdaBody]); | ||
} | ||
return (0, prettier_builder_1.group)((0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndJoin)(line, [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [lambdaParameters, ctx.Arrow[0]]), | ||
return group(indent(rejectAndJoin(line, [ | ||
rejectAndJoin(" ", [lambdaParameters, ctx.Arrow[0]]), | ||
lambdaBody | ||
]))); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.lambdaParameters = function (ctx, params) { | ||
} | ||
lambdaParameters(ctx, params) { | ||
if (ctx.lambdaParametersWithBraces) { | ||
return this.visitSingle(ctx, params); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.lambdaParametersWithBraces = function (ctx, params) { | ||
var lambdaParameterList = this.visit(ctx.lambdaParameterList); | ||
if ((0, printer_utils_1.findDeepElementInPartsArray)(lambdaParameterList, ",")) { | ||
var content = (0, printer_utils_1.putIntoBraces)(lambdaParameterList, softline, ctx.LBrace[0], ctx.RBrace[0]); | ||
if ((params === null || params === void 0 ? void 0 : params.isInsideMethodInvocationSuffix) === true) { | ||
return (0, prettier_builder_1.indent)((0, prettier_builder_1.concat)([softline, content])); | ||
} | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
lambdaParametersWithBraces(ctx, params) { | ||
const lambdaParameterList = this.visit(ctx.lambdaParameterList, params); | ||
if (findDeepElementInPartsArray(lambdaParameterList, ",")) { | ||
const separator = (params === null || params === void 0 ? void 0 : params.shouldBreak) === false ? "" : softline; | ||
const content = putIntoBraces(lambdaParameterList, separator, ctx.LBrace[0], ctx.RBrace[0]); | ||
return content; | ||
@@ -99,3 +43,3 @@ } | ||
ctx.RBrace && | ||
(!lambdaParameterList || (0, printer_utils_1.isExplicitLambdaParameter)(ctx))) || | ||
(!lambdaParameterList || isExplicitLambdaParameter(ctx))) || | ||
ctx.LBrace[0].leadingComments || | ||
@@ -105,3 +49,3 @@ ctx.LBrace[0].trailingComments || | ||
ctx.RBrace[0].trailingComments) { | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
return rejectAndConcat([ | ||
ctx.LBrace[0], | ||
@@ -113,55 +57,51 @@ lambdaParameterList, | ||
return lambdaParameterList; | ||
}; | ||
ExpressionsPrettierVisitor.prototype.lambdaParameterList = function (ctx) { | ||
} | ||
lambdaParameterList(ctx, params) { | ||
return this.visitSingle(ctx, params); | ||
} | ||
inferredLambdaParameterList(ctx, params) { | ||
var _a; | ||
const commaSuffix = (params === null || params === void 0 ? void 0 : params.shouldBreak) === false ? " " : line; | ||
const commas = (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a.map(comma => concat([comma, commaSuffix])); | ||
return rejectAndJoinSeps(commas, ctx.Identifier); | ||
} | ||
explicitLambdaParameterList(ctx, params) { | ||
var _a; | ||
const lambdaParameter = this.mapVisit(ctx.lambdaParameter); | ||
const commaSuffix = (params === null || params === void 0 ? void 0 : params.shouldBreak) === false ? " " : line; | ||
const commas = (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a.map(comma => concat([comma, commaSuffix])); | ||
return rejectAndJoinSeps(commas, lambdaParameter); | ||
} | ||
lambdaParameter(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.inferredLambdaParameterList = function (ctx) { | ||
var commas = ctx.Comma | ||
? ctx.Comma.map(function (elt) { | ||
return (0, prettier_builder_1.concat)([elt, line]); | ||
}) | ||
: []; | ||
return (0, 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 (0, prettier_builder_1.concat)([elt, line]); | ||
}) | ||
: []; | ||
return (0, 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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", variableModifier), | ||
} | ||
regularLambdaParameter(ctx) { | ||
const variableModifier = this.mapVisit(ctx.variableModifier); | ||
const lambdaParameterType = this.visit(ctx.lambdaParameterType); | ||
const variableDeclaratorId = this.visit(ctx.variableDeclaratorId); | ||
return rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", variableModifier), | ||
lambdaParameterType, | ||
variableDeclaratorId | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.lambdaParameterType = function (ctx) { | ||
} | ||
lambdaParameterType(ctx) { | ||
if (ctx.unannType) { | ||
return this.visitSingle(ctx); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.lambdaBody = function (ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
lambdaBody(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.ternaryExpression = function (ctx, params) { | ||
var binaryExpression = this.visit(ctx.binaryExpression, params); | ||
} | ||
ternaryExpression(ctx, params) { | ||
const binaryExpression = this.visit(ctx.binaryExpression, params); | ||
if (ctx.QuestionMark) { | ||
var expression1 = this.visit(ctx.expression[0]); | ||
var expression2 = this.visit(ctx.expression[1]); | ||
return (0, prettier_builder_1.indent)((0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)(line, [ | ||
const expression1 = this.visit(ctx.expression[0]); | ||
const expression2 = this.visit(ctx.expression[1]); | ||
return indent(group(rejectAndConcat([ | ||
rejectAndJoin(line, [ | ||
binaryExpression, | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.QuestionMark[0], expression1]), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.Colon[0], expression2]) | ||
rejectAndJoin(" ", [ctx.QuestionMark[0], expression1]), | ||
rejectAndJoin(" ", [ctx.Colon[0], expression2]) | ||
]) | ||
@@ -171,6 +111,6 @@ ]))); | ||
return binaryExpression; | ||
}; | ||
ExpressionsPrettierVisitor.prototype.binaryExpression = function (ctx, params) { | ||
(0, handle_comments_1.handleCommentsBinaryExpression)(ctx); | ||
var sortedNodes = (0, printer_utils_1.sortNodes)([ | ||
} | ||
binaryExpression(ctx, params) { | ||
handleCommentsBinaryExpression(ctx); | ||
const sortedNodes = sortNodes([ | ||
ctx.pattern, | ||
@@ -181,4 +121,4 @@ ctx.referenceType, | ||
]); | ||
var nodes = this.mapVisit(sortedNodes, sortedNodes.length === 1 ? params : undefined); | ||
var tokens = (0, printer_utils_1.sortTokens)([ | ||
const nodes = this.mapVisit(sortedNodes, sortedNodes.length === 1 ? params : undefined); | ||
const tokens = sortTokens([ | ||
ctx.Instanceof, | ||
@@ -190,8 +130,8 @@ ctx.AssignmentOperator, | ||
]); | ||
var hasTokens = tokens.length > 0; | ||
var content = (0, printer_utils_1.binary)(nodes, tokens, true); | ||
const hasTokens = tokens.length > 0; | ||
const content = binary(nodes, tokens, true); | ||
return hasTokens && (params === null || params === void 0 ? void 0 : params.addParenthesisToWrapStatement) | ||
? (0, prettier_builder_1.group)((0, prettier_builder_1.concat)([ | ||
? group(concat([ | ||
ifBreak("("), | ||
(0, prettier_builder_1.indent)((0, prettier_builder_1.concat)([softline, content])), | ||
indent(concat([softline, content])), | ||
softline, | ||
@@ -201,26 +141,26 @@ ifBreak(")") | ||
: content; | ||
}; | ||
ExpressionsPrettierVisitor.prototype.unaryExpression = function (ctx, params) { | ||
var unaryPrefixOperator = ctx.UnaryPrefixOperator | ||
} | ||
unaryExpression(ctx, params) { | ||
const unaryPrefixOperator = ctx.UnaryPrefixOperator | ||
? ctx.UnaryPrefixOperator | ||
: []; | ||
var primary = this.visit(ctx.primary, params); | ||
var unarySuffixOperator = ctx.UnarySuffixOperator | ||
const primary = this.visit(ctx.primary, params); | ||
const unarySuffixOperator = ctx.UnarySuffixOperator | ||
? ctx.UnarySuffixOperator | ||
: []; | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndConcat)(unaryPrefixOperator), | ||
return rejectAndConcat([ | ||
rejectAndConcat(unaryPrefixOperator), | ||
primary, | ||
(0, printer_utils_1.rejectAndConcat)(unarySuffixOperator) | ||
rejectAndConcat(unarySuffixOperator) | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.unaryExpressionNotPlusMinus = function (ctx) { | ||
var unaryPrefixOperatorNotPlusMinus = ctx.UnaryPrefixOperatorNotPlusMinus // changed when moved to TS | ||
? (0, printer_utils_1.rejectAndJoin)(" ", ctx.UnaryPrefixOperatorNotPlusMinus) // changed when moved to TS | ||
} | ||
unaryExpressionNotPlusMinus(ctx) { | ||
const unaryPrefixOperatorNotPlusMinus = ctx.UnaryPrefixOperatorNotPlusMinus // changed when moved to TS | ||
? rejectAndJoin(" ", ctx.UnaryPrefixOperatorNotPlusMinus) // changed when moved to TS | ||
: ""; | ||
var primary = this.visit(ctx.primary); | ||
var unarySuffixOperator = ctx.UnarySuffixOperator // changed when moved to TS | ||
? (0, printer_utils_1.rejectAndJoin)(" ", ctx.UnarySuffixOperator) // changed when moved to TS | ||
const primary = this.visit(ctx.primary); | ||
const unarySuffixOperator = ctx.UnarySuffixOperator // changed when moved to TS | ||
? rejectAndJoin(" ", ctx.UnarySuffixOperator) // changed when moved to TS | ||
: ""; | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
return rejectAndJoin(" ", [ | ||
unaryPrefixOperatorNotPlusMinus, | ||
@@ -230,10 +170,24 @@ primary, | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.primary = function (ctx, params) { | ||
var countMethodInvocation = (0, printer_utils_1.isUniqueMethodInvocation)(ctx.primarySuffix); | ||
var primaryPrefix = this.visit(ctx.primaryPrefix, __assign(__assign({}, params), { shouldBreakBeforeFirstMethodInvocation: countMethodInvocation > 1 })); | ||
var suffixes = []; | ||
} | ||
primary(ctx, params) { | ||
var _a, _b, _c, _d; | ||
const countMethodInvocation = isUniqueMethodInvocation(ctx.primarySuffix); | ||
const newExpression = (_a = ctx.primaryPrefix[0].children.newExpression) === null || _a === void 0 ? void 0 : _a[0].children; | ||
const isBreakableNewExpression = countMethodInvocation <= 1 && | ||
this.isBreakableNewExpression(newExpression); | ||
const fqnOrRefType = (_b = ctx.primaryPrefix[0].children.fqnOrRefType) === null || _b === void 0 ? void 0 : _b[0].children; | ||
const firstMethodInvocation = (_c = ctx.primarySuffix) === null || _c === void 0 ? void 0 : _c.map(suffix => { var _a; return (_a = suffix.children.methodInvocationSuffix) === null || _a === void 0 ? void 0 : _a[0].children; }).find(methodInvocationSuffix => methodInvocationSuffix); | ||
const isCapitalizedIdentifier = this.isCapitalizedIdentifier(fqnOrRefType); | ||
const shouldBreakBeforeFirstMethodInvocation = countMethodInvocation > 1 && | ||
!(isCapitalizedIdentifier !== null && isCapitalizedIdentifier !== void 0 ? isCapitalizedIdentifier : true) && | ||
firstMethodInvocation !== undefined; | ||
const shouldBreakBeforeMethodInvocations = shouldBreakBeforeFirstMethodInvocation || | ||
countMethodInvocation > 2 || | ||
(countMethodInvocation > 1 && newExpression) || | ||
!(firstMethodInvocation === null || firstMethodInvocation === void 0 ? void 0 : firstMethodInvocation.argumentList); | ||
const primaryPrefix = this.visit(ctx.primaryPrefix, Object.assign(Object.assign({}, params), { shouldBreakBeforeFirstMethodInvocation })); | ||
const suffixes = []; | ||
if (ctx.primarySuffix !== undefined) { | ||
// edge case: https://github.com/jhipster/prettier-java/issues/381 | ||
var hasFirstInvocationArg = true; | ||
let hasFirstInvocationArg = true; | ||
if (ctx.primarySuffix.length > 1 && | ||
@@ -244,27 +198,11 @@ ctx.primarySuffix[1].children.methodInvocationSuffix && | ||
} | ||
if (ctx.primarySuffix[0].children.Dot !== undefined && | ||
ctx.primaryPrefix[0].children.newExpression !== undefined) { | ||
if (newExpression && | ||
!isBreakableNewExpression && | ||
ctx.primarySuffix[0].children.Dot !== 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 && | ||
suffixes.push(this.visit(ctx.primarySuffix[0])); | ||
for (let i = 1; i < ctx.primarySuffix.length; i++) { | ||
if (shouldBreakBeforeMethodInvocations && | ||
ctx.primarySuffix[i].children.Dot !== undefined && | ||
ctx.primarySuffix[i - 1].children.methodInvocationSuffix !== undefined) { | ||
@@ -275,42 +213,51 @@ suffixes.push(softline); | ||
} | ||
if (countMethodInvocation === 1 && | ||
ctx.primaryPrefix[0].children.newExpression === undefined) { | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ | ||
if (!newExpression && countMethodInvocation === 1) { | ||
return group(rejectAndConcat([ | ||
primaryPrefix, | ||
hasFirstInvocationArg ? suffixes[0] : (0, prettier_builder_1.indent)(suffixes[0]), | ||
(0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)(suffixes.slice(1))) | ||
hasFirstInvocationArg ? suffixes[0] : indent(suffixes[0]), | ||
indent(rejectAndConcat(suffixes.slice(1))) | ||
])); | ||
} | ||
} | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([primaryPrefix, (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)(suffixes))])); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.primaryPrefix = function (ctx, params) { | ||
const methodInvocation = (_d = ctx.primarySuffix) === null || _d === void 0 ? void 0 : _d[0].children.methodInvocationSuffix; | ||
const isMethodInvocationWithArguments = (methodInvocation === null || methodInvocation === void 0 ? void 0 : methodInvocation[0].children.argumentList) !== undefined; | ||
const isUnqualifiedMethodInvocation = methodInvocation !== undefined && !(fqnOrRefType === null || fqnOrRefType === void 0 ? void 0 : fqnOrRefType.Dot); | ||
return group(rejectAndConcat([ | ||
primaryPrefix, | ||
isCapitalizedIdentifier || isUnqualifiedMethodInvocation | ||
? suffixes.shift() | ||
: "", | ||
!isBreakableNewExpression && | ||
(shouldBreakBeforeMethodInvocations || !isMethodInvocationWithArguments) | ||
? indent(concat(suffixes)) | ||
: concat(suffixes) | ||
])); | ||
} | ||
primaryPrefix(ctx, params) { | ||
if (ctx.This || ctx.Void) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
return this.visitSingle(ctx, params); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.primarySuffix = function (ctx, params) { | ||
} | ||
primarySuffix(ctx, params) { | ||
var _a; | ||
if (ctx.Dot) { | ||
if (ctx.This) { | ||
return (0, printer_utils_1.rejectAndConcat)([ctx.Dot[0], ctx.This[0]]); | ||
return rejectAndConcat([ctx.Dot[0], ctx.This[0]]); | ||
} | ||
else if (ctx.Identifier) { | ||
var typeArguments = this.visit(ctx.typeArguments); | ||
return (0, printer_utils_1.rejectAndConcat)([ctx.Dot[0], typeArguments, ctx.Identifier[0]]); | ||
const typeArguments = this.visit(ctx.typeArguments); | ||
return rejectAndConcat([ctx.Dot[0], typeArguments, ctx.Identifier[0]]); | ||
} | ||
var unqualifiedClassInstanceCreationExpression = this.visit(ctx.unqualifiedClassInstanceCreationExpression); | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
ctx.Dot[0], | ||
unqualifiedClassInstanceCreationExpression | ||
]); | ||
const suffix = this.visit((_a = ctx.unqualifiedClassInstanceCreationExpression) !== null && _a !== void 0 ? _a : ctx.templateArgument); | ||
return rejectAndConcat([ctx.Dot[0], suffix]); | ||
} | ||
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; | ||
} | ||
fqnOrRefType(ctx, params) { | ||
const fqnOrRefTypePartFirst = this.visit(ctx.fqnOrRefTypePartFirst); | ||
const fqnOrRefTypePartRest = this.mapVisit(ctx.fqnOrRefTypePartRest); | ||
const dims = this.visit(ctx.dims); | ||
const dots = ctx.Dot ? ctx.Dot : []; | ||
const isMethodInvocation = ctx.Dot && ctx.Dot.length === 1; | ||
if (params !== undefined && | ||
@@ -320,6 +267,6 @@ params.shouldBreakBeforeFirstMethodInvocation === true) { | ||
if (isMethodInvocation) { | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([softline, dots[0]]), [ | ||
return rejectAndConcat([ | ||
indent(rejectAndJoin(concat([softline, dots[0]]), [ | ||
fqnOrRefTypePartFirst, | ||
(0, printer_utils_1.rejectAndJoinSeps)(dots.slice(1), fqnOrRefTypePartRest), | ||
rejectAndJoinSeps(dots.slice(1), fqnOrRefTypePartRest), | ||
dims | ||
@@ -331,8 +278,9 @@ ])) | ||
else if (ctx.Dot) { | ||
return (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoinSeps)(dots.slice(0, dots.length - 1), __spreadArray([ | ||
fqnOrRefTypePartFirst | ||
], fqnOrRefTypePartRest.slice(0, fqnOrRefTypePartRest.length - 1), true)), | ||
return indent(rejectAndConcat([ | ||
rejectAndJoinSeps(dots.slice(0, dots.length - 1), [ | ||
fqnOrRefTypePartFirst, | ||
...fqnOrRefTypePartRest.slice(0, fqnOrRefTypePartRest.length - 1) | ||
]), | ||
softline, | ||
(0, printer_utils_1.rejectAndConcat)([ | ||
rejectAndConcat([ | ||
dots[dots.length - 1], | ||
@@ -345,26 +293,26 @@ fqnOrRefTypePartRest[fqnOrRefTypePartRest.length - 1] | ||
} | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoinSeps)(dots, __spreadArray([fqnOrRefTypePartFirst], fqnOrRefTypePartRest, true)), | ||
return rejectAndConcat([ | ||
rejectAndJoinSeps(dots, [fqnOrRefTypePartFirst, ...fqnOrRefTypePartRest]), | ||
dims | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.fqnOrRefTypePartFirst = function (ctx) { | ||
var annotation = this.mapVisit(ctx.annotation); | ||
var fqnOrRefTypeCommon = this.visit(ctx.fqnOrRefTypePartCommon); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", annotation), | ||
} | ||
fqnOrRefTypePartFirst(ctx) { | ||
const annotation = this.mapVisit(ctx.annotation); | ||
const fqnOrRefTypeCommon = this.visit(ctx.fqnOrRefTypePartCommon); | ||
return rejectAndJoin(" ", [ | ||
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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", annotation), | ||
(0, printer_utils_1.rejectAndConcat)([typeArguments, fqnOrRefTypeCommon]) | ||
} | ||
fqnOrRefTypePartRest(ctx) { | ||
const annotation = this.mapVisit(ctx.annotation); | ||
const fqnOrRefTypeCommon = this.visit(ctx.fqnOrRefTypePartCommon); | ||
const typeArguments = this.visit(ctx.typeArguments); | ||
return rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", annotation), | ||
rejectAndConcat([typeArguments, fqnOrRefTypeCommon]) | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.fqnOrRefTypePartCommon = function (ctx) { | ||
var keyWord = null; | ||
} | ||
fqnOrRefTypePartCommon(ctx) { | ||
let keyWord = null; | ||
if (ctx.Identifier) { | ||
@@ -376,44 +324,44 @@ keyWord = ctx.Identifier[0]; | ||
} | ||
var typeArguments = this.visit(ctx.typeArguments); | ||
return (0, printer_utils_1.rejectAndConcat)([keyWord, typeArguments]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.parenthesisExpression = function (ctx, params) { | ||
var expression = this.visit(ctx.expression); | ||
var separator = (params === null || params === void 0 ? void 0 : params.addParenthesisToWrapStatement) ? softline : ""; | ||
return (0, printer_utils_1.putIntoBraces)(expression, separator, ctx.LBrace[0], ctx.RBrace[0]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.castExpression = function (ctx) { | ||
const typeArguments = this.visit(ctx.typeArguments); | ||
return rejectAndConcat([keyWord, typeArguments]); | ||
} | ||
parenthesisExpression(ctx, params) { | ||
const expression = this.visit(ctx.expression); | ||
const separator = (params === null || params === void 0 ? void 0 : params.addParenthesisToWrapStatement) ? softline : ""; | ||
return putIntoBraces(expression, separator, ctx.LBrace[0], ctx.RBrace[0]); | ||
} | ||
castExpression(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.primitiveCastExpression = function (ctx) { | ||
var primitiveType = this.visit(ctx.primitiveType); | ||
var unaryExpression = this.visit(ctx.unaryExpression); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndConcat)([ctx.LBrace[0], primitiveType, ctx.RBrace[0]]), | ||
} | ||
primitiveCastExpression(ctx) { | ||
const primitiveType = this.visit(ctx.primitiveType); | ||
const unaryExpression = this.visit(ctx.unaryExpression); | ||
return rejectAndJoin(" ", [ | ||
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 = (0, printer_utils_1.rejectAndJoin)(line, this.mapVisit(ctx.additionalBound)); | ||
var expression = ctx.lambdaExpression | ||
} | ||
referenceTypeCastExpression(ctx) { | ||
const referenceType = this.visit(ctx.referenceType); | ||
const hasAdditionalBounds = ctx.additionalBound !== undefined; | ||
const additionalBounds = rejectAndJoin(line, this.mapVisit(ctx.additionalBound)); | ||
const expression = ctx.lambdaExpression | ||
? this.visit(ctx.lambdaExpression) | ||
: this.visit(ctx.unaryExpressionNotPlusMinus); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.putIntoBraces)((0, printer_utils_1.rejectAndJoin)(line, [referenceType, additionalBounds]), hasAdditionalBounds ? softline : "", ctx.LBrace[0], ctx.RBrace[0]), | ||
return rejectAndJoin(" ", [ | ||
putIntoBraces(rejectAndJoin(line, [referenceType, additionalBounds]), hasAdditionalBounds ? softline : "", ctx.LBrace[0], ctx.RBrace[0]), | ||
expression | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.newExpression = function (ctx) { | ||
} | ||
newExpression(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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
} | ||
unqualifiedClassInstanceCreationExpression(ctx) { | ||
const typeArguments = this.visit(ctx.typeArguments); | ||
const classOrInterfaceTypeToInstantiate = this.visit(ctx.classOrInterfaceTypeToInstantiate); | ||
let content = printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]); | ||
const classBody = this.visit(ctx.classBody); | ||
return rejectAndJoin(" ", [ | ||
ctx.New[0], | ||
(0, printer_utils_1.rejectAndConcat)([ | ||
rejectAndConcat([ | ||
typeArguments, | ||
@@ -425,148 +373,186 @@ classOrInterfaceTypeToInstantiate, | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.classOrInterfaceTypeToInstantiate = function (ctx) { | ||
var _this = this; | ||
var tokens = (0, printer_utils_1.sortAnnotationIdentifier)(ctx.annotation, ctx.Identifier); | ||
var segments = []; | ||
var currentSegment = []; | ||
(0, forEach_1.default)(tokens, function (token) { | ||
if ((0, utils_1.isAnnotationCstNode)(token)) { | ||
currentSegment.push(_this.visit([token])); | ||
} | ||
classOrInterfaceTypeToInstantiate(ctx) { | ||
const tokens = sortAnnotationIdentifier(ctx.annotation, ctx.Identifier); | ||
const segments = []; | ||
let currentSegment = []; | ||
forEach(tokens, token => { | ||
if (isAnnotationCstNode(token)) { | ||
currentSegment.push(this.visit([token])); | ||
} | ||
else { | ||
currentSegment.push(token); | ||
segments.push((0, printer_utils_1.rejectAndJoin)(" ", currentSegment)); | ||
segments.push(rejectAndJoin(" ", currentSegment)); | ||
currentSegment = []; | ||
} | ||
}); | ||
var typeArgumentsOrDiamond = this.visit(ctx.typeArgumentsOrDiamond); | ||
var dots = ctx.Dot ? ctx.Dot : []; | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoinSeps)(dots, segments), | ||
const typeArgumentsOrDiamond = this.visit(ctx.typeArgumentsOrDiamond); | ||
const dots = ctx.Dot ? ctx.Dot : []; | ||
return rejectAndConcat([ | ||
rejectAndJoinSeps(dots, segments), | ||
typeArgumentsOrDiamond | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.typeArgumentsOrDiamond = function (ctx) { | ||
} | ||
typeArgumentsOrDiamond(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.diamond = function (ctx) { | ||
return (0, prettier_builder_1.concat)([ctx.Less[0], ctx.Greater[0]]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.methodInvocationSuffix = function (ctx, params) { | ||
var isSingleLambda = (0, expressions_utils_1.isArgumentListSingleLambda)(ctx.argumentList); | ||
if (isSingleLambda) { | ||
return utils_2.printSingleLambdaInvocation.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]); | ||
} | ||
diamond(ctx) { | ||
return concat([ctx.Less[0], ctx.Greater[0]]); | ||
} | ||
methodInvocationSuffix(ctx) { | ||
return printArgumentListWithBraces.call(this, ctx.argumentList, ctx.RBrace[0], ctx.LBrace[0]); | ||
} | ||
argumentList(ctx, params) { | ||
var _a; | ||
const shouldBreak = params === null || params === void 0 ? void 0 : params.shouldBreak; | ||
const expressions = this.mapVisit(ctx.expression, params); | ||
const lastArgument = expressions.pop(); | ||
const commaSuffix = shouldBreak === true ? hardline : shouldBreak === false ? " " : line; | ||
const commas = (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a.map(comma => concat([comma, commaSuffix])); | ||
const otherArguments = rejectAndJoinSeps(commas, expressions); | ||
if (lastArgument && (params === null || params === void 0 ? void 0 : params.isHuggable)) { | ||
const argumentListGroupId = Symbol("argumentList"); | ||
const separator = shouldBreak === true ? hardline : shouldBreak === false ? "" : softline; | ||
return concat([ | ||
group([separator, otherArguments], { id: argumentListGroupId }), | ||
ifBreak([lastArgument, dedent(separator)], dedent(lastArgument), { | ||
groupId: argumentListGroupId | ||
}) | ||
]); | ||
} | ||
var argumentList = this.visit(ctx.argumentList); | ||
if (params && params.shouldDedent) { | ||
return (0, prettier_builder_1.dedent)((0, printer_utils_1.putIntoBraces)(argumentList, softline, ctx.LBrace[0], ctx.RBrace[0])); | ||
} | ||
return (0, 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 (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(commas, expressions); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.arrayCreationExpression = function (ctx) { | ||
var type = ctx.primitiveType | ||
return rejectAndConcat([otherArguments, lastArgument]); | ||
} | ||
arrayCreationExpression(ctx) { | ||
const type = ctx.primitiveType | ||
? this.visit(ctx.primitiveType) | ||
: this.visit(ctx.classOrInterfaceType); | ||
var suffix = ctx.arrayCreationDefaultInitSuffix | ||
const suffix = ctx.arrayCreationDefaultInitSuffix | ||
? this.visit(ctx.arrayCreationDefaultInitSuffix) | ||
: this.visit(ctx.arrayCreationExplicitInitSuffix); | ||
return (0, printer_utils_1.rejectAndConcat)([(0, 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 (0, printer_utils_1.rejectAndConcat)([dimExprs, dims]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.arrayCreationExplicitInitSuffix = function (ctx) { | ||
var dims = this.visit(ctx.dims); | ||
var arrayInitializer = this.visit(ctx.arrayInitializer); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [dims, arrayInitializer]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.dimExprs = function (ctx) { | ||
var dimExpr = this.mapVisit(ctx.dimExpr); | ||
return (0, printer_utils_1.rejectAndConcat)(dimExpr); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.dimExpr = function (ctx) { | ||
var annotations = this.mapVisit(ctx.annotation); | ||
var expression = this.visit(ctx.expression); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", annotations), | ||
(0, printer_utils_1.rejectAndConcat)([ctx.LSquare[0], expression, ctx.RSquare[0]]) | ||
return rejectAndConcat([concat([ctx.New[0], " "]), type, suffix]); | ||
} | ||
arrayCreationDefaultInitSuffix(ctx) { | ||
const dimExprs = this.visit(ctx.dimExprs); | ||
const dims = this.visit(ctx.dims); | ||
return rejectAndConcat([dimExprs, dims]); | ||
} | ||
arrayCreationExplicitInitSuffix(ctx) { | ||
const dims = this.visit(ctx.dims); | ||
const arrayInitializer = this.visit(ctx.arrayInitializer); | ||
return rejectAndJoin(" ", [dims, arrayInitializer]); | ||
} | ||
dimExprs(ctx) { | ||
const dimExpr = this.mapVisit(ctx.dimExpr); | ||
return rejectAndConcat(dimExpr); | ||
} | ||
dimExpr(ctx) { | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const expression = this.visit(ctx.expression); | ||
return rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", annotations), | ||
rejectAndConcat([ctx.LSquare[0], expression, ctx.RSquare[0]]) | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.classLiteralSuffix = function (ctx) { | ||
var squares = []; | ||
} | ||
classLiteralSuffix(ctx) { | ||
const squares = []; | ||
if (ctx.LSquare) { | ||
for (var i = 0; i < ctx.LSquare.length; i++) { | ||
squares.push((0, prettier_builder_1.concat)([ctx.LSquare[i], ctx.RSquare[i]])); | ||
for (let i = 0; i < ctx.LSquare.length; i++) { | ||
squares.push(concat([ctx.LSquare[i], ctx.RSquare[i]])); | ||
} | ||
} | ||
return (0, printer_utils_1.rejectAndConcat)(__spreadArray(__spreadArray([], squares, true), [ctx.Dot[0], ctx.Class[0]], false)); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.arrayAccessSuffix = function (ctx) { | ||
var expression = this.visit(ctx.expression); | ||
return (0, 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 (0, printer_utils_1.rejectAndConcat)([ctx.ColonColon[0], typeArguments, identifierOrNew]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.pattern = function (ctx) { | ||
return rejectAndConcat([...squares, ctx.Dot[0], ctx.Class[0]]); | ||
} | ||
arrayAccessSuffix(ctx) { | ||
const expression = this.visit(ctx.expression); | ||
return rejectAndConcat([ctx.LSquare[0], expression, ctx.RSquare[0]]); | ||
} | ||
methodReferenceSuffix(ctx) { | ||
const typeArguments = this.visit(ctx.typeArguments); | ||
const identifierOrNew = ctx.New ? ctx.New[0] : ctx.Identifier[0]; | ||
return rejectAndConcat([ctx.ColonColon[0], typeArguments, identifierOrNew]); | ||
} | ||
templateArgument(ctx) { | ||
var _a; | ||
return ctx.template | ||
? this.visit(ctx.template) | ||
: printTokenWithComments(((_a = ctx.StringLiteral) !== null && _a !== void 0 ? _a : ctx.TextBlock)[0]); | ||
} | ||
template(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.typePattern = function (ctx) { | ||
} | ||
stringTemplate(ctx) { | ||
const embeddedExpressions = this.mapVisit(ctx.embeddedExpression).flatMap(expression => group([softline, expression, lineSuffixBoundary, dedent(softline)])); | ||
return concat([ | ||
ctx.StringTemplateBegin[0], | ||
rejectAndJoinSeps(ctx.StringTemplateMid, embeddedExpressions), | ||
ctx.StringTemplateEnd[0] | ||
]); | ||
} | ||
textBlockTemplate(ctx) { | ||
const embeddedExpressions = this.mapVisit(ctx.embeddedExpression).flatMap(expression => group([softline, expression, lineSuffixBoundary, dedent(softline)])); | ||
return concat([ | ||
ctx.TextBlockTemplateBegin[0], | ||
rejectAndJoinSeps(ctx.TextBlockTemplateMid, embeddedExpressions), | ||
ctx.TextBlockTemplateEnd[0] | ||
]); | ||
} | ||
embeddedExpression(ctx) { | ||
return this.visit(ctx.expression); | ||
} | ||
pattern(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.recordPattern = function (ctx) { | ||
var referenceType = this.visit(ctx.referenceType); | ||
var componentPatternList = this.visit(ctx.componentPatternList); | ||
return (0, prettier_builder_1.concat)([ | ||
} | ||
typePattern(ctx) { | ||
return this.visitSingle(ctx); | ||
} | ||
recordPattern(ctx) { | ||
const referenceType = this.visit(ctx.referenceType); | ||
const componentPatternList = this.visit(ctx.componentPatternList); | ||
return concat([ | ||
referenceType, | ||
(0, printer_utils_1.putIntoBraces)(componentPatternList, softline, ctx.LBrace[0], ctx.RBrace[0]) | ||
putIntoBraces(componentPatternList, softline, ctx.LBrace[0], ctx.RBrace[0]) | ||
]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.componentPatternList = function (ctx) { | ||
} | ||
componentPatternList(ctx) { | ||
var _a, _b; | ||
var componentPatterns = this.mapVisit(ctx.componentPattern); | ||
var commas = (_b = (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); })) !== null && _b !== void 0 ? _b : []; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(commas, componentPatterns); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.componentPattern = function (ctx) { | ||
const componentPatterns = this.mapVisit(ctx.componentPattern); | ||
const commas = (_b = (_a = ctx.Comma) === null || _a === void 0 ? void 0 : _a.map(elt => concat([elt, line]))) !== null && _b !== void 0 ? _b : []; | ||
return rejectAndJoinSeps(commas, componentPatterns); | ||
} | ||
componentPattern(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.unnamedPattern = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(ctx.Underscore[0]); | ||
}; | ||
ExpressionsPrettierVisitor.prototype.guard = function (ctx) { | ||
var expression = this.visit(ctx.expression, { | ||
} | ||
unnamedPattern(ctx) { | ||
return printTokenWithComments(ctx.Underscore[0]); | ||
} | ||
guard(ctx) { | ||
const expression = this.visit(ctx.expression, { | ||
addParenthesisToWrapStatement: true | ||
}); | ||
return (0, prettier_builder_1.concat)([ctx.When[0], " ", expression]); | ||
}; | ||
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 concat([ctx.When[0], " ", expression]); | ||
} | ||
isRefTypeInMethodRef() { | ||
return "isRefTypeInMethodRef"; | ||
}; | ||
return ExpressionsPrettierVisitor; | ||
}(base_cst_printer_1.BaseCstPrettierPrinter)); | ||
exports.ExpressionsPrettierVisitor = ExpressionsPrettierVisitor; | ||
} | ||
isBreakableNewExpression(newExpression) { | ||
var _a, _b, _c, _d, _e; | ||
const arrayCreationExpression = (_a = newExpression === null || newExpression === void 0 ? void 0 : newExpression.arrayCreationExpression) === null || _a === void 0 ? void 0 : _a[0].children; | ||
const classInstanceCreationExpression = (_b = newExpression === null || newExpression === void 0 ? void 0 : newExpression.unqualifiedClassInstanceCreationExpression) === null || _b === void 0 ? void 0 : _b[0].children; | ||
return [ | ||
(_c = arrayCreationExpression === null || arrayCreationExpression === void 0 ? void 0 : arrayCreationExpression.classOrInterfaceType) === null || _c === void 0 ? void 0 : _c[0].children.classType[0].children.typeArguments, | ||
(_d = arrayCreationExpression === null || arrayCreationExpression === void 0 ? void 0 : arrayCreationExpression.arrayCreationExplicitInitSuffix) === null || _d === void 0 ? void 0 : _d[0].children.arrayInitializer[0].children.variableInitializerList, | ||
(_e = classInstanceCreationExpression === null || classInstanceCreationExpression === void 0 ? void 0 : classInstanceCreationExpression.classOrInterfaceTypeToInstantiate[0].children.typeArgumentsOrDiamond) === null || _e === void 0 ? void 0 : _e[0].children.typeArguments, | ||
classInstanceCreationExpression === null || classInstanceCreationExpression === void 0 ? void 0 : classInstanceCreationExpression.argumentList | ||
].some(breakablePart => breakablePart !== undefined); | ||
} | ||
isCapitalizedIdentifier(fqnOrRefType) { | ||
var _a, _b, _c; | ||
const fqnOrRefTypeParts = [ | ||
fqnOrRefType === null || fqnOrRefType === void 0 ? void 0 : fqnOrRefType.fqnOrRefTypePartFirst[0], | ||
...((_a = fqnOrRefType === null || fqnOrRefType === void 0 ? void 0 : fqnOrRefType.fqnOrRefTypePartRest) !== null && _a !== void 0 ? _a : []) | ||
]; | ||
const nextToLastIdentifier = (_c = (_b = fqnOrRefTypeParts[fqnOrRefTypeParts.length - 2]) === null || _b === void 0 ? void 0 : _b.children.fqnOrRefTypePartCommon[0].children.Identifier) === null || _c === void 0 ? void 0 : _c[0].image; | ||
return (nextToLastIdentifier && | ||
/^\p{Uppercase_Letter}/u.test(nextToLastIdentifier)); | ||
} | ||
} |
@@ -1,60 +0,38 @@ | ||
"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 = (0, printer_utils_1.sortModifiers)(ctx.interfaceModifier); | ||
var firstAnnotations = this.mapVisit(modifiers[0]); | ||
var otherModifiers = this.mapVisit(modifiers[1]); | ||
var declaration = ctx.normalInterfaceDeclaration | ||
import { concat, group, indent } from "./prettier-builder.js"; | ||
import { printTokenWithComments } from "./comments/format-comments.js"; | ||
import { displaySemicolon, getInterfaceBodyDeclarationsSeparator, isStatementEmptyStatement, printArrayList, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortModifiers } from "./printer-utils.js"; | ||
import { builders } from "prettier/doc"; | ||
import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; | ||
const { line, softline, hardline } = builders; | ||
export class InterfacesPrettierVisitor extends BaseCstPrettierPrinter { | ||
interfaceDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.interfaceModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
const declaration = ctx.normalInterfaceDeclaration | ||
? this.visit(ctx.normalInterfaceDeclaration) | ||
: this.visit(ctx.annotationTypeDeclaration); | ||
return (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [(0, printer_utils_1.rejectAndJoin)(" ", otherModifiers), declaration]) | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [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 = ""; | ||
} | ||
normalInterfaceDeclaration(ctx) { | ||
const typeIdentifier = this.visit(ctx.typeIdentifier); | ||
const typeParameters = this.visit(ctx.typeParameters); | ||
const extendsInterfaces = this.visit(ctx.extendsInterfaces); | ||
const optionalInterfacePermits = this.visit(ctx.interfacePermits); | ||
const interfaceBody = this.visit(ctx.interfaceBody); | ||
let extendsInterfacesPart = ""; | ||
if (extendsInterfaces) { | ||
extendsInterfacesPart = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([softline, extendsInterfaces])); | ||
extendsInterfacesPart = indent(rejectAndConcat([softline, extendsInterfaces])); | ||
} | ||
var interfacePermits = ""; | ||
let interfacePermits = ""; | ||
if (optionalInterfacePermits) { | ||
interfacePermits = (0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([softline, optionalInterfacePermits])); | ||
interfacePermits = indent(rejectAndConcat([softline, optionalInterfacePermits])); | ||
} | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.group)((0, printer_utils_1.rejectAndJoin)(" ", [ | ||
return rejectAndJoin(" ", [ | ||
group(rejectAndJoin(" ", [ | ||
ctx.Interface[0], | ||
(0, prettier_builder_1.concat)([typeIdentifier, typeParameters]), | ||
concat([typeIdentifier, typeParameters]), | ||
extendsInterfacesPart, | ||
@@ -65,119 +43,119 @@ interfacePermits | ||
]); | ||
}; | ||
InterfacesPrettierVisitor.prototype.interfaceModifier = function (ctx) { | ||
} | ||
interfaceModifier(ctx) { | ||
if (ctx.annotation) { | ||
return this.visitSingle(ctx); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
InterfacesPrettierVisitor.prototype.extendsInterfaces = function (ctx) { | ||
var interfaceTypeList = this.visit(ctx.interfaceTypeList); | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([ | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
extendsInterfaces(ctx) { | ||
const interfaceTypeList = this.visit(ctx.interfaceTypeList); | ||
return group(rejectAndConcat([ | ||
ctx.Extends[0], | ||
(0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndConcat)([line, interfaceTypeList])) | ||
indent(rejectAndConcat([line, interfaceTypeList])) | ||
])); | ||
}; | ||
InterfacesPrettierVisitor.prototype.interfacePermits = function (ctx) { | ||
} | ||
interfacePermits(ctx) { | ||
return this.classPermits(ctx); | ||
}; | ||
InterfacesPrettierVisitor.prototype.interfaceBody = function (ctx) { | ||
var joinedInterfaceMemberDeclaration = ""; | ||
} | ||
interfaceBody(ctx) { | ||
let joinedInterfaceMemberDeclaration = ""; | ||
if (ctx.interfaceMemberDeclaration !== undefined) { | ||
var interfaceMemberDeclaration = this.mapVisit(ctx.interfaceMemberDeclaration); | ||
var separators = (0, printer_utils_1.getInterfaceBodyDeclarationsSeparator)(ctx.interfaceMemberDeclaration); | ||
joinedInterfaceMemberDeclaration = (0, printer_utils_1.rejectAndJoinSeps)(separators, interfaceMemberDeclaration); | ||
const interfaceMemberDeclaration = this.mapVisit(ctx.interfaceMemberDeclaration); | ||
const separators = getInterfaceBodyDeclarationsSeparator(ctx.interfaceMemberDeclaration); | ||
joinedInterfaceMemberDeclaration = rejectAndJoinSeps(separators, interfaceMemberDeclaration); | ||
} | ||
return (0, printer_utils_1.putIntoBraces)(joinedInterfaceMemberDeclaration, hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
}; | ||
InterfacesPrettierVisitor.prototype.interfaceMemberDeclaration = function (ctx) { | ||
return putIntoBraces(joinedInterfaceMemberDeclaration, hardline, ctx.LCurly[0], ctx.RCurly[0]); | ||
} | ||
interfaceMemberDeclaration(ctx) { | ||
if (ctx.Semicolon) { | ||
return (0, printer_utils_1.displaySemicolon)(ctx.Semicolon[0]); | ||
return displaySemicolon(ctx.Semicolon[0]); | ||
} | ||
return this.visitSingle(ctx); | ||
}; | ||
InterfacesPrettierVisitor.prototype.constantDeclaration = function (ctx) { | ||
var modifiers = (0, 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 (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", otherModifiers), | ||
} | ||
constantDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.constantModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
const unannType = this.visit(ctx.unannType); | ||
const variableDeclaratorList = this.visit(ctx.variableDeclaratorList); | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", otherModifiers), | ||
unannType, | ||
(0, printer_utils_1.rejectAndConcat)([variableDeclaratorList, ctx.Semicolon[0]]) | ||
rejectAndConcat([variableDeclaratorList, ctx.Semicolon[0]]) | ||
]) | ||
]); | ||
}; | ||
InterfacesPrettierVisitor.prototype.constantModifier = function (ctx) { | ||
} | ||
constantModifier(ctx) { | ||
if (ctx.annotation) { | ||
return this.visitSingle(ctx); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
InterfacesPrettierVisitor.prototype.interfaceMethodDeclaration = function (ctx) { | ||
var modifiers = (0, 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 = (0, printer_utils_1.isStatementEmptyStatement)(methodBody) ? "" : " "; | ||
return (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", otherModifiers), | ||
(0, printer_utils_1.rejectAndJoin)(separator, [methodHeader, methodBody]) | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
interfaceMethodDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.interfaceMethodModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
const methodHeader = this.visit(ctx.methodHeader); | ||
const methodBody = this.visit(ctx.methodBody); | ||
const separator = isStatementEmptyStatement(methodBody) ? "" : " "; | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", otherModifiers), | ||
rejectAndJoin(separator, [methodHeader, methodBody]) | ||
]) | ||
]); | ||
}; | ||
InterfacesPrettierVisitor.prototype.interfaceMethodModifier = function (ctx) { | ||
} | ||
interfaceMethodModifier(ctx) { | ||
if (ctx.annotation) { | ||
return this.visitSingle(ctx); | ||
} | ||
return (0, 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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.concat)([ctx.At[0], ctx.Interface[0]]), | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
annotationTypeDeclaration(ctx) { | ||
const typeIdentifier = this.visit(ctx.typeIdentifier); | ||
const annotationTypeBody = this.visit(ctx.annotationTypeBody); | ||
return rejectAndJoin(" ", [ | ||
concat([ctx.At[0], ctx.Interface[0]]), | ||
typeIdentifier, | ||
annotationTypeBody | ||
]); | ||
}; | ||
InterfacesPrettierVisitor.prototype.annotationTypeBody = function (ctx) { | ||
var annotationTypeMemberDeclaration = this.mapVisit(ctx.annotationTypeMemberDeclaration); | ||
return (0, printer_utils_1.rejectAndJoin)(line, [ | ||
(0, prettier_builder_1.indent)((0, printer_utils_1.rejectAndJoin)(line, [ | ||
} | ||
annotationTypeBody(ctx) { | ||
const annotationTypeMemberDeclaration = this.mapVisit(ctx.annotationTypeMemberDeclaration); | ||
return rejectAndJoin(line, [ | ||
indent(rejectAndJoin(line, [ | ||
ctx.LCurly[0], | ||
(0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([line, line]), annotationTypeMemberDeclaration) | ||
rejectAndJoin(concat([line, line]), annotationTypeMemberDeclaration) | ||
])), | ||
ctx.RCurly[0] | ||
]); | ||
}; | ||
InterfacesPrettierVisitor.prototype.annotationTypeMemberDeclaration = function (ctx) { | ||
} | ||
annotationTypeMemberDeclaration(ctx) { | ||
if (ctx.Semicolon) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
return this.visitSingle(ctx); | ||
}; | ||
InterfacesPrettierVisitor.prototype.annotationTypeElementDeclaration = function (ctx) { | ||
var modifiers = (0, 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 | ||
? (0, prettier_builder_1.concat)([" ", this.visit(ctx.defaultValue)]) | ||
} | ||
annotationTypeElementDeclaration(ctx) { | ||
const modifiers = sortModifiers(ctx.annotationTypeElementModifier); | ||
const firstAnnotations = this.mapVisit(modifiers[0]); | ||
const otherModifiers = this.mapVisit(modifiers[1]); | ||
const unannType = this.visit(ctx.unannType); | ||
const identifier = ctx.Identifier[0]; | ||
const dims = this.visit(ctx.dims); | ||
const defaultValue = ctx.defaultValue | ||
? concat([" ", this.visit(ctx.defaultValue)]) | ||
: ""; | ||
return (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, firstAnnotations), | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", otherModifiers), | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, firstAnnotations), | ||
rejectAndJoin(" ", [ | ||
rejectAndJoin(" ", otherModifiers), | ||
unannType, | ||
(0, printer_utils_1.rejectAndConcat)([ | ||
rejectAndConcat([ | ||
identifier, | ||
(0, prettier_builder_1.concat)([ctx.LBrace[0], ctx.RBrace[0]]), | ||
concat([ctx.LBrace[0], ctx.RBrace[0]]), | ||
dims, | ||
@@ -189,42 +167,42 @@ defaultValue, | ||
]); | ||
}; | ||
InterfacesPrettierVisitor.prototype.annotationTypeElementModifier = function (ctx) { | ||
} | ||
annotationTypeElementModifier(ctx) { | ||
if (ctx.annotation) { | ||
return this.visitSingle(ctx); | ||
} | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
InterfacesPrettierVisitor.prototype.defaultValue = function (ctx) { | ||
var elementValue = this.visit(ctx.elementValue); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ctx.Default[0], elementValue]); | ||
}; | ||
InterfacesPrettierVisitor.prototype.annotation = function (ctx) { | ||
var fqn = this.visit(ctx.typeName); | ||
var annoArgs = ""; | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
defaultValue(ctx) { | ||
const elementValue = this.visit(ctx.elementValue); | ||
return rejectAndJoin(" ", [ctx.Default[0], elementValue]); | ||
} | ||
annotation(ctx) { | ||
const fqn = this.visit(ctx.typeName); | ||
let annoArgs = ""; | ||
if (ctx.LBrace) { | ||
if (ctx.elementValuePairList) { | ||
annoArgs = (0, printer_utils_1.putIntoBraces)(this.visit(ctx.elementValuePairList), softline, ctx.LBrace[0], ctx.RBrace[0]); | ||
annoArgs = putIntoBraces(this.visit(ctx.elementValuePairList), softline, ctx.LBrace[0], ctx.RBrace[0]); | ||
} | ||
else if (ctx.elementValue) { | ||
annoArgs = (0, printer_utils_1.putIntoBraces)(this.visit(ctx.elementValue), softline, ctx.LBrace[0], ctx.RBrace[0]); | ||
annoArgs = putIntoBraces(this.visit(ctx.elementValue), softline, ctx.LBrace[0], ctx.RBrace[0]); | ||
} | ||
} | ||
return (0, prettier_builder_1.group)((0, 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 (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(commas, elementValuePairs); | ||
}; | ||
InterfacesPrettierVisitor.prototype.elementValuePair = function (ctx) { | ||
var identifier = ctx.Identifier[0]; | ||
var elementValue = this.visit(ctx.elementValue); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [identifier, ctx.Equals[0], elementValue]); | ||
}; | ||
InterfacesPrettierVisitor.prototype.elementValue = function (ctx) { | ||
return group(rejectAndConcat([ctx.At[0], fqn, annoArgs])); | ||
} | ||
elementValuePairList(ctx) { | ||
const elementValuePairs = this.mapVisit(ctx.elementValuePair); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
return rejectAndJoinSeps(commas, elementValuePairs); | ||
} | ||
elementValuePair(ctx) { | ||
const identifier = ctx.Identifier[0]; | ||
const elementValue = this.visit(ctx.elementValue); | ||
return rejectAndJoin(" ", [identifier, ctx.Equals[0], elementValue]); | ||
} | ||
elementValue(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
InterfacesPrettierVisitor.prototype.elementValueArrayInitializer = function (ctx) { | ||
var elementValueList = this.visit(ctx.elementValueList); | ||
return (0, printer_utils_1.printArrayList)({ | ||
} | ||
elementValueArrayInitializer(ctx) { | ||
const elementValueList = this.visit(ctx.elementValueList); | ||
return printArrayList({ | ||
list: elementValueList, | ||
@@ -236,19 +214,8 @@ extraComma: ctx.Comma, | ||
}); | ||
}; | ||
InterfacesPrettierVisitor.prototype.elementValueList = function (ctx) { | ||
var elementValues = this.mapVisit(ctx.elementValue); | ||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
return (0, prettier_builder_1.group)((0, printer_utils_1.rejectAndConcat)([(0, 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; | ||
} | ||
elementValueList(ctx) { | ||
const elementValues = this.mapVisit(ctx.elementValue); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
return group(rejectAndConcat([rejectAndJoinSeps(commas, elementValues)])); | ||
} | ||
} |
@@ -1,63 +0,31 @@ | ||
"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, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LexicalStructurePrettierVisitor = void 0; | ||
var format_comments_1 = require("./comments/format-comments"); | ||
var prettier_builder_1 = require("./prettier-builder"); | ||
var base_cst_printer_1 = require("../base-cst-printer"); | ||
var doc_1 = require("prettier/doc"); | ||
var hardline = doc_1.builders.hardline; | ||
var LexicalStructurePrettierVisitor = /** @class */ (function (_super) { | ||
__extends(LexicalStructurePrettierVisitor, _super); | ||
function LexicalStructurePrettierVisitor() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
LexicalStructurePrettierVisitor.prototype.literal = function (ctx) { | ||
import { printTokenWithComments } from "./comments/format-comments.js"; | ||
import { join } from "./prettier-builder.js"; | ||
import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; | ||
import { builders } from "prettier/doc"; | ||
const { hardline } = builders; | ||
export class LexicalStructurePrettierVisitor extends BaseCstPrettierPrinter { | ||
literal(ctx) { | ||
if (ctx.TextBlock) { | ||
var lines = ctx.TextBlock[0].image.split("\n"); | ||
var open_1 = lines.shift(); | ||
var baseIndent_1 = Math.min.apply(Math, lines.map(function (line) { return line.search(/\S/); }).filter(function (indent) { return indent >= 0; })); | ||
return (0, prettier_builder_1.join)(hardline, __spreadArray([ | ||
open_1 | ||
], lines.map(function (line) { return line.slice(baseIndent_1); }), true)); | ||
const lines = ctx.TextBlock[0].image.split("\n"); | ||
const open = lines.shift(); | ||
const baseIndent = Math.min(...lines.map(line => line.search(/\S/)).filter(indent => indent >= 0)); | ||
return join(hardline, [ | ||
open, | ||
...lines.map(line => line.slice(baseIndent)) | ||
]); | ||
} | ||
if (ctx.CharLiteral || ctx.StringLiteral || ctx.Null) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
return this.visitSingle(ctx); | ||
}; | ||
LexicalStructurePrettierVisitor.prototype.integerLiteral = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
LexicalStructurePrettierVisitor.prototype.floatingPointLiteral = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
LexicalStructurePrettierVisitor.prototype.booleanLiteral = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
return LexicalStructurePrettierVisitor; | ||
}(base_cst_printer_1.BaseCstPrettierPrinter)); | ||
exports.LexicalStructurePrettierVisitor = LexicalStructurePrettierVisitor; | ||
} | ||
integerLiteral(ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
floatingPointLiteral(ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
booleanLiteral(ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
} |
@@ -1,53 +0,29 @@ | ||
"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; | ||
import { buildFqn } from "./printer-utils.js"; | ||
import { printTokenWithComments } from "./comments/format-comments.js"; | ||
import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; | ||
export class NamesPrettierVisitor extends BaseCstPrettierPrinter { | ||
typeIdentifier(ctx) { | ||
return printTokenWithComments(ctx.Identifier[0]); | ||
} | ||
NamesPrettierVisitor.prototype.typeIdentifier = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(ctx.Identifier[0]); | ||
}; | ||
NamesPrettierVisitor.prototype.moduleName = function (ctx) { | ||
return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot); | ||
}; | ||
NamesPrettierVisitor.prototype.packageName = function (ctx) { | ||
return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot); | ||
}; | ||
NamesPrettierVisitor.prototype.typeName = function (ctx) { | ||
return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot); | ||
}; | ||
NamesPrettierVisitor.prototype.expressionName = function (ctx) { | ||
return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot); | ||
}; | ||
NamesPrettierVisitor.prototype.methodName = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(ctx.Identifier[0]); | ||
}; | ||
NamesPrettierVisitor.prototype.packageOrTypeName = function (ctx) { | ||
return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot); | ||
}; | ||
NamesPrettierVisitor.prototype.ambiguousName = function (ctx) { | ||
return (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot); | ||
}; | ||
return NamesPrettierVisitor; | ||
}(base_cst_printer_1.BaseCstPrettierPrinter)); | ||
exports.NamesPrettierVisitor = NamesPrettierVisitor; | ||
moduleName(ctx) { | ||
return buildFqn(ctx.Identifier, ctx.Dot); | ||
} | ||
packageName(ctx) { | ||
return buildFqn(ctx.Identifier, ctx.Dot); | ||
} | ||
typeName(ctx) { | ||
return buildFqn(ctx.Identifier, ctx.Dot); | ||
} | ||
expressionName(ctx) { | ||
return buildFqn(ctx.Identifier, ctx.Dot); | ||
} | ||
methodName(ctx) { | ||
return printTokenWithComments(ctx.Identifier[0]); | ||
} | ||
packageOrTypeName(ctx) { | ||
return buildFqn(ctx.Identifier, ctx.Dot); | ||
} | ||
ambiguousName(ctx) { | ||
return buildFqn(ctx.Identifier, ctx.Dot); | ||
} | ||
} |
@@ -1,133 +0,111 @@ | ||
"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 = (0, utils_1.isOrdinaryCompilationUnitCtx)(ctx) | ||
import { concat, join } from "./prettier-builder.js"; | ||
import { printTokenWithComments } from "./comments/format-comments.js"; | ||
import { buildFqn, displaySemicolon, getBlankLinesSeparator, putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortImports } from "./printer-utils.js"; | ||
import { builders } from "prettier/doc"; | ||
import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; | ||
import { isOrdinaryCompilationUnitCtx } from "../types/utils.js"; | ||
const { line, hardline, indent, group } = builders; | ||
export class PackagesAndModulesPrettierVisitor extends BaseCstPrettierPrinter { | ||
compilationUnit(ctx) { | ||
const compilationUnit = isOrdinaryCompilationUnitCtx(ctx) | ||
? ctx.ordinaryCompilationUnit | ||
: ctx.modularCompilationUnit; | ||
return (0, prettier_builder_1.concat)([this.visit(compilationUnit[0]), line]); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.ordinaryCompilationUnit = function (ctx) { | ||
var packageDecl = this.visit(ctx.packageDeclaration); | ||
var sortedImportsDecl = (0, printer_utils_1.sortImports)(ctx.importDeclaration); | ||
var nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports); | ||
var staticImports = this.mapVisit(sortedImportsDecl.staticImports); | ||
var typesDecl = this.mapVisit(ctx.typeDeclaration); | ||
return concat([this.visit(compilationUnit[0]), line]); | ||
} | ||
ordinaryCompilationUnit(ctx) { | ||
const packageDecl = this.visit(ctx.packageDeclaration); | ||
const sortedImportsDecl = sortImports(ctx.importDeclaration); | ||
const nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports); | ||
const staticImports = this.mapVisit(sortedImportsDecl.staticImports); | ||
const typesDecl = this.mapVisit(ctx.typeDeclaration); | ||
// TODO: utility to add item+line (or multiple lines) but only if an item exists | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([hardline, hardline]), [ | ||
return rejectAndConcat([ | ||
rejectAndJoin(concat([hardline, hardline]), [ | ||
packageDecl, | ||
(0, printer_utils_1.rejectAndJoin)(hardline, staticImports), | ||
(0, printer_utils_1.rejectAndJoin)(hardline, nonStaticImports), | ||
(0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([hardline, hardline]), typesDecl) | ||
rejectAndJoin(hardline, staticImports), | ||
rejectAndJoin(hardline, nonStaticImports), | ||
rejectAndJoin(concat([hardline, hardline]), typesDecl) | ||
]) | ||
]); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.modularCompilationUnit = function (ctx) { | ||
var sortedImportsDecl = (0, 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 (0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)((0, prettier_builder_1.concat)([hardline, hardline]), [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, staticImports), | ||
(0, printer_utils_1.rejectAndJoin)(hardline, nonStaticImports), | ||
} | ||
modularCompilationUnit(ctx) { | ||
const sortedImportsDecl = sortImports(ctx.importDeclaration); | ||
const nonStaticImports = this.mapVisit(sortedImportsDecl.nonStaticImports); | ||
const staticImports = this.mapVisit(sortedImportsDecl.staticImports); | ||
const moduleDeclaration = this.visit(ctx.moduleDeclaration); | ||
return rejectAndConcat([ | ||
rejectAndJoin(concat([hardline, hardline]), [ | ||
rejectAndJoin(hardline, staticImports), | ||
rejectAndJoin(hardline, nonStaticImports), | ||
moduleDeclaration | ||
]) | ||
]); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.packageDeclaration = function (ctx) { | ||
var modifiers = this.mapVisit(ctx.packageModifier); | ||
var name = (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot); | ||
return (0, printer_utils_1.rejectAndJoin)(hardline, [ | ||
(0, printer_utils_1.rejectAndJoin)(hardline, modifiers), | ||
(0, prettier_builder_1.concat)([ctx.Package[0], " ", name, ctx.Semicolon[0]]) | ||
} | ||
packageDeclaration(ctx) { | ||
const modifiers = this.mapVisit(ctx.packageModifier); | ||
const name = buildFqn(ctx.Identifier, ctx.Dot); | ||
return rejectAndJoin(hardline, [ | ||
rejectAndJoin(hardline, modifiers), | ||
concat([ctx.Package[0], " ", name, ctx.Semicolon[0]]) | ||
]); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.packageModifier = function (ctx) { | ||
} | ||
packageModifier(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.importDeclaration = function (ctx) { | ||
} | ||
importDeclaration(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 ? (0, prettier_builder_1.concat)([ctx.Dot[0], ctx.Star[0]]) : ""; | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
const optionalStatic = ctx.Static ? ctx.Static[0] : ""; | ||
const packageOrTypeName = this.visit(ctx.packageOrTypeName); | ||
const optionalDotStar = ctx.Dot ? concat([ctx.Dot[0], ctx.Star[0]]) : ""; | ||
return rejectAndJoin(" ", [ | ||
ctx.Import[0], | ||
optionalStatic, | ||
(0, printer_utils_1.rejectAndConcat)([packageOrTypeName, optionalDotStar, ctx.Semicolon[0]]) | ||
rejectAndConcat([packageOrTypeName, optionalDotStar, ctx.Semicolon[0]]) | ||
]); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.typeDeclaration = function (ctx) { | ||
} | ||
typeDeclaration(ctx) { | ||
if (ctx.Semicolon) { | ||
return (0, printer_utils_1.displaySemicolon)(ctx.Semicolon[0]); | ||
return 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 = (0, printer_utils_1.buildFqn)(ctx.Identifier, ctx.Dot); | ||
var moduleDirectives = this.mapVisit(ctx.moduleDirective); | ||
var content = (0, printer_utils_1.rejectAndJoinSeps)((0, printer_utils_1.getBlankLinesSeparator)(ctx.moduleDirective), moduleDirectives); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.join)(" ", annotations), | ||
} | ||
moduleDeclaration(ctx) { | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const optionalOpen = ctx.Open ? ctx.Open[0] : ""; | ||
const name = buildFqn(ctx.Identifier, ctx.Dot); | ||
const moduleDirectives = this.mapVisit(ctx.moduleDirective); | ||
const content = rejectAndJoinSeps(getBlankLinesSeparator(ctx.moduleDirective), moduleDirectives); | ||
return rejectAndJoin(" ", [ | ||
join(" ", annotations), | ||
optionalOpen, | ||
ctx.Module[0], | ||
name, | ||
(0, printer_utils_1.putIntoBraces)(content, hardline, ctx.LCurly[0], ctx.RCurly[0]) | ||
putIntoBraces(content, hardline, ctx.LCurly[0], ctx.RCurly[0]) | ||
]); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.moduleDirective = function (ctx) { | ||
} | ||
moduleDirective(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.requiresModuleDirective = function (ctx) { | ||
var modifiers = this.mapVisit(ctx.requiresModifier); | ||
var moduleName = this.visit(ctx.moduleName); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
} | ||
requiresModuleDirective(ctx) { | ||
const modifiers = this.mapVisit(ctx.requiresModifier); | ||
const moduleName = this.visit(ctx.moduleName); | ||
return rejectAndJoin(" ", [ | ||
ctx.Requires[0], | ||
(0, prettier_builder_1.join)(" ", modifiers), | ||
(0, prettier_builder_1.concat)([moduleName, ctx.Semicolon[0]]) | ||
join(" ", modifiers), | ||
concat([moduleName, ctx.Semicolon[0]]) | ||
]); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.exportsModuleDirective = function (ctx) { | ||
var packageName = this.visit(ctx.packageName); | ||
var moduleNames = this.mapVisit(ctx.moduleName); | ||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
} | ||
exportsModuleDirective(ctx) { | ||
const packageName = this.visit(ctx.packageName); | ||
const moduleNames = this.mapVisit(ctx.moduleName); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
if (ctx.To) { | ||
return group((0, printer_utils_1.rejectAndConcat)([ | ||
indent((0, printer_utils_1.rejectAndJoin)(line, [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.Exports[0], packageName]), | ||
group(indent((0, printer_utils_1.rejectAndJoin)(line, [ | ||
return group(rejectAndConcat([ | ||
indent(rejectAndJoin(line, [ | ||
rejectAndJoin(" ", [ctx.Exports[0], packageName]), | ||
group(indent(rejectAndJoin(line, [ | ||
ctx.To[0], | ||
(0, printer_utils_1.rejectAndJoinSeps)(commas, moduleNames) | ||
rejectAndJoinSeps(commas, moduleNames) | ||
]))) | ||
@@ -138,20 +116,20 @@ ])), | ||
} | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.concat)([ctx.Exports[0], " "]), | ||
return rejectAndConcat([ | ||
concat([ctx.Exports[0], " "]), | ||
packageName, | ||
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 (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
} | ||
opensModuleDirective(ctx) { | ||
const packageName = this.visit(ctx.packageName); | ||
const to = ctx.To ? ctx.To[0] : ""; | ||
const moduleNames = this.mapVisit(ctx.moduleName); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
if (ctx.To) { | ||
return group((0, printer_utils_1.rejectAndConcat)([ | ||
indent((0, printer_utils_1.rejectAndJoin)(line, [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.Opens[0], packageName]), | ||
group(indent((0, printer_utils_1.rejectAndJoin)(line, [ | ||
return group(rejectAndConcat([ | ||
indent(rejectAndJoin(line, [ | ||
rejectAndJoin(" ", [ctx.Opens[0], packageName]), | ||
group(indent(rejectAndJoin(line, [ | ||
ctx.To[0], | ||
(0, printer_utils_1.rejectAndJoinSeps)(commas, moduleNames) | ||
rejectAndJoinSeps(commas, moduleNames) | ||
]))) | ||
@@ -162,26 +140,26 @@ ])), | ||
} | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.concat)([ctx.Opens[0], " "]), | ||
return rejectAndConcat([ | ||
concat([ctx.Opens[0], " "]), | ||
packageName, | ||
ctx.Semicolon[0] | ||
]); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.usesModuleDirective = function (ctx) { | ||
var typeName = this.visit(ctx.typeName); | ||
return (0, printer_utils_1.rejectAndConcat)([ | ||
(0, prettier_builder_1.concat)([ctx.Uses[0], " "]), | ||
} | ||
usesModuleDirective(ctx) { | ||
const typeName = this.visit(ctx.typeName); | ||
return rejectAndConcat([ | ||
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 (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
return group((0, printer_utils_1.rejectAndConcat)([ | ||
indent((0, printer_utils_1.rejectAndJoin)(line, [ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.Provides[0], firstTypeName]), | ||
group(indent((0, printer_utils_1.rejectAndJoin)(line, [ | ||
} | ||
providesModuleDirective(ctx) { | ||
const firstTypeName = this.visit(ctx.typeName[0]); | ||
const otherTypeNames = this.mapVisit(ctx.typeName.slice(1)); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
return group(rejectAndConcat([ | ||
indent(rejectAndJoin(line, [ | ||
rejectAndJoin(" ", [ctx.Provides[0], firstTypeName]), | ||
group(indent(rejectAndJoin(line, [ | ||
ctx.With[0], | ||
(0, printer_utils_1.rejectAndJoinSeps)(commas, otherTypeNames) | ||
rejectAndJoinSeps(commas, otherTypeNames) | ||
]))) | ||
@@ -191,11 +169,6 @@ ])), | ||
])); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.requiresModifier = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
PackagesAndModulesPrettierVisitor.prototype.isModuleCompilationUnit = function () { | ||
return "isModuleCompilationUnit"; | ||
}; | ||
return PackagesAndModulesPrettierVisitor; | ||
}(base_cst_printer_1.BaseCstPrettierPrinter)); | ||
exports.PackagesAndModulesPrettierVisitor = PackagesAndModulesPrettierVisitor; | ||
} | ||
requiresModifier(ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
} |
@@ -1,6 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.indentIfBreak = exports.ifBreak = exports.dedent = exports.indent = exports.fill = exports.group = exports.join = exports.concat = void 0; | ||
var doc_1 = require("prettier/doc"); | ||
var processComments = require("./comments/format-comments").processComments; | ||
import { builders } from "prettier/doc"; | ||
import * as formatComments from "./comments/format-comments.js"; | ||
const processComments = formatComments.processComments; | ||
/* | ||
@@ -11,4 +9,4 @@ * ------------------------------------------------------------------ | ||
*/ | ||
function concat(docs) { | ||
var concatenation = processComments(docs); | ||
export function concat(docs) { | ||
const concatenation = processComments(docs); | ||
if (!Array.isArray(docs)) { | ||
@@ -19,39 +17,31 @@ return ""; | ||
} | ||
exports.concat = concat; | ||
function join(sep, docs) { | ||
return doc_1.builders.join(processComments(sep), processComments(docs)); | ||
export function join(sep, docs) { | ||
return builders.join(processComments(sep), processComments(docs)); | ||
} | ||
exports.join = join; | ||
function group(docs, opts) { | ||
var group = doc_1.builders.group(processComments(docs), opts); | ||
export function group(docs, opts) { | ||
const group = builders.group(processComments(docs), opts); | ||
return group.contents === undefined ? "" : group; | ||
} | ||
exports.group = group; | ||
function fill(docs) { | ||
return doc_1.builders.fill(processComments(docs)); | ||
export function fill(docs) { | ||
return builders.fill(processComments(docs)); | ||
} | ||
exports.fill = fill; | ||
function indent(doc) { | ||
var processedDoc = processComments(doc); | ||
export function indent(doc) { | ||
const processedDoc = processComments(doc); | ||
if (processedDoc.length === 0) { | ||
return ""; | ||
} | ||
return doc_1.builders.indent(processedDoc); | ||
return builders.indent(processedDoc); | ||
} | ||
exports.indent = indent; | ||
function dedent(doc) { | ||
var processedDoc = processComments(doc); | ||
export function dedent(doc) { | ||
const processedDoc = processComments(doc); | ||
if (processedDoc.length === 0) { | ||
return ""; | ||
} | ||
return doc_1.builders.dedent(processComments(doc)); | ||
return builders.dedent(processComments(doc)); | ||
} | ||
exports.dedent = dedent; | ||
function ifBreak(breakContents, flatContents) { | ||
return doc_1.builders.ifBreak(processComments(breakContents), processComments(flatContents)); | ||
export function ifBreak(breakContents, flatContents) { | ||
return builders.ifBreak(processComments(breakContents), processComments(flatContents)); | ||
} | ||
exports.ifBreak = ifBreak; | ||
function indentIfBreak(contents, opts) { | ||
return doc_1.builders.indentIfBreak(processComments(contents), opts); | ||
export function indentIfBreak(contents, opts) { | ||
return builders.indentIfBreak(processComments(contents), opts); | ||
} | ||
exports.indentIfBreak = indentIfBreak; |
@@ -1,40 +0,14 @@ | ||
"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, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
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.binary = exports.putIntoBraces = exports.getInterfaceBodyDeclarationsSeparator = exports.getClassBodyDeclarationsSeparator = exports.getBlankLinesSeparator = exports.isExplicitLambdaParameter = exports.displaySemicolon = exports.findDeepElementInPartsArray = exports.sortModifiers = exports.sortClassTypeChildren = exports.matchCategory = exports.sortNodes = exports.sortTokens = exports.sortAnnotationIdentifier = exports.rejectAndConcat = exports.rejectAndJoin = exports.rejectSeparators = exports.reject = exports.rejectAndJoinSeps = exports.buildFqn = void 0; | ||
var findIndex_1 = __importDefault(require("lodash/findIndex")); | ||
var findLastIndex_1 = __importDefault(require("lodash/findLastIndex")); | ||
var forEach_1 = __importDefault(require("lodash/forEach")); | ||
var forEachRight_1 = __importDefault(require("lodash/forEachRight")); | ||
var includes_1 = __importDefault(require("lodash/includes")); | ||
var doc_1 = require("prettier/doc"); | ||
var utils_1 = require("../types/utils"); | ||
var utils_2 = require("../utils"); | ||
var comments_utils_1 = require("./comments/comments-utils"); | ||
var format_comments_1 = require("./comments/format-comments"); | ||
var prettier_builder_1 = require("./prettier-builder"); | ||
var indent = doc_1.builders.indent, hardline = doc_1.builders.hardline, line = doc_1.builders.line; | ||
var orderedModifiers = [ | ||
import findIndex from "lodash/findIndex.js"; | ||
import findLastIndex from "lodash/findLastIndex.js"; | ||
import forEach from "lodash/forEach.js"; | ||
import forEachRight from "lodash/forEachRight.js"; | ||
import includes from "lodash/includes.js"; | ||
import { builders } from "prettier/doc"; | ||
import { isCstNode } from "../types/utils.js"; | ||
import { isEmptyDoc } from "../utils/index.js"; | ||
import { hasComments, hasLeadingComments, hasTrailingComments } from "./comments/comments-utils.js"; | ||
import { getTokenLeadingComments, printTokenWithComments } from "./comments/format-comments.js"; | ||
import { concat, group, ifBreak, indentIfBreak, join } from "./prettier-builder.js"; | ||
const { indent, hardline, line } = builders; | ||
const orderedModifiers = [ | ||
"Public", | ||
@@ -55,13 +29,12 @@ "Protected", | ||
]; | ||
function buildFqn(tokens, dots) { | ||
export function buildFqn(tokens, dots) { | ||
return rejectAndJoinSeps(dots ? dots : [], tokens); | ||
} | ||
exports.buildFqn = buildFqn; | ||
function rejectAndJoinSeps(sepTokens, elems, sep) { | ||
export 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++) { | ||
const actualElements = reject(elems); | ||
const res = []; | ||
for (let i = 0; i < sepTokens.length; i++) { | ||
res.push(actualElements[i], sepTokens[i]); | ||
@@ -72,8 +45,7 @@ if (sep) { | ||
} | ||
res.push.apply(res, actualElements.slice(sepTokens.length)); | ||
return (0, prettier_builder_1.concat)(res); | ||
res.push(...actualElements.slice(sepTokens.length)); | ||
return concat(res); | ||
} | ||
exports.rejectAndJoinSeps = rejectAndJoinSeps; | ||
function reject(elems) { | ||
return elems.filter(function (item) { | ||
export function reject(elems) { | ||
return elems.filter(item => { | ||
if (typeof item === "string") { | ||
@@ -87,7 +59,6 @@ return item !== ""; | ||
} | ||
exports.reject = reject; | ||
function rejectSeparators(separators, elems) { | ||
var realElements = reject(elems); | ||
var realSeparators = []; | ||
for (var i = 0; i < realElements.length - 1; i++) { | ||
export function rejectSeparators(separators, elems) { | ||
const realElements = reject(elems); | ||
const realSeparators = []; | ||
for (let i = 0; i < realElements.length - 1; i++) { | ||
if (realElements[i] !== "") { | ||
@@ -99,23 +70,20 @@ realSeparators.push(separators[i]); | ||
} | ||
exports.rejectSeparators = rejectSeparators; | ||
function rejectAndJoin(sep, elems) { | ||
var actualElements = reject(elems); | ||
return (0, prettier_builder_1.join)(sep, actualElements); | ||
export function rejectAndJoin(sep, elems) { | ||
const actualElements = reject(elems); | ||
return join(sep, actualElements); | ||
} | ||
exports.rejectAndJoin = rejectAndJoin; | ||
function rejectAndConcat(elems) { | ||
var actualElements = reject(elems); | ||
return (0, prettier_builder_1.concat)(actualElements); | ||
export function rejectAndConcat(elems) { | ||
const actualElements = reject(elems); | ||
return concat(actualElements); | ||
} | ||
exports.rejectAndConcat = rejectAndConcat; | ||
function sortAnnotationIdentifier(annotations, identifiers) { | ||
var tokens = __spreadArray([], identifiers, true); | ||
export function sortAnnotationIdentifier(annotations, identifiers) { | ||
let tokens = [...identifiers]; | ||
if (annotations && annotations.length > 0) { | ||
tokens = __spreadArray(__spreadArray([], tokens, true), annotations, true); | ||
tokens = [...tokens, ...annotations]; | ||
} | ||
return tokens.sort(function (a, b) { | ||
var startOffset1 = (0, utils_1.isCstNode)(a) | ||
return tokens.sort((a, b) => { | ||
const startOffset1 = isCstNode(a) | ||
? a.children.At[0].startOffset | ||
: a.startOffset; | ||
var startOffset2 = (0, utils_1.isCstNode)(b) | ||
const startOffset2 = isCstNode(b) | ||
? b.children.At[0].startOffset | ||
@@ -126,6 +94,5 @@ : b.startOffset; | ||
} | ||
exports.sortAnnotationIdentifier = sortAnnotationIdentifier; | ||
function sortTokens(values) { | ||
var tokens = []; | ||
(0, forEach_1.default)(values, function (argument) { | ||
export function sortTokens(values) { | ||
let tokens = []; | ||
forEach(values, argument => { | ||
if (argument) { | ||
@@ -135,10 +102,9 @@ tokens = tokens.concat(argument); | ||
}); | ||
return tokens.sort(function (a, b) { | ||
return tokens.sort((a, b) => { | ||
return a.startOffset - b.startOffset; | ||
}); | ||
} | ||
exports.sortTokens = sortTokens; | ||
function sortNodes(values) { | ||
var nodes = []; | ||
(0, forEach_1.default)(values, function (argument) { | ||
export function sortNodes(values) { | ||
let nodes = []; | ||
forEach(values, argument => { | ||
if (argument) { | ||
@@ -148,11 +114,10 @@ nodes = nodes.concat(argument); | ||
}); | ||
return nodes.sort(function (a, b) { | ||
var aOffset = a.location.startOffset; | ||
var bOffset = b.location.startOffset; | ||
return nodes.sort((a, b) => { | ||
const aOffset = a.location.startOffset; | ||
const bOffset = b.location.startOffset; | ||
return aOffset - bOffset; | ||
}); | ||
} | ||
exports.sortNodes = sortNodes; | ||
function matchCategory(token, categoryName) { | ||
var labels = (token.tokenType.CATEGORIES || []).map(function (category) { | ||
export function matchCategory(token, categoryName) { | ||
const labels = (token.tokenType.CATEGORIES || []).map(category => { | ||
return category.LABEL; | ||
@@ -162,16 +127,15 @@ }); | ||
} | ||
exports.matchCategory = matchCategory; | ||
function sortClassTypeChildren(annotations, typeArguments, identifiers, dots) { | ||
var tokens = __spreadArray([], identifiers, true); | ||
export function sortClassTypeChildren(annotations, typeArguments, identifiers, dots) { | ||
let tokens = [...identifiers]; | ||
if (annotations && annotations.length > 0) { | ||
tokens = __spreadArray(__spreadArray([], tokens, true), annotations, true); | ||
tokens = [...tokens, ...annotations]; | ||
} | ||
if (typeArguments && typeArguments.length > 0) { | ||
tokens = __spreadArray(__spreadArray([], tokens, true), typeArguments, true); | ||
tokens = [...tokens, ...typeArguments]; | ||
} | ||
if (dots && dots.length > 0) { | ||
tokens = __spreadArray(__spreadArray([], tokens, true), dots, true); | ||
tokens = [...tokens, ...dots]; | ||
} | ||
return tokens.sort(function (a, b) { | ||
var startOffsetA = (0, utils_1.isCstNode)(a) | ||
return tokens.sort((a, b) => { | ||
const startOffsetA = isCstNode(a) | ||
? a.children.At | ||
@@ -181,3 +145,3 @@ ? a.children.At[0].startOffset | ||
: a.startOffset; | ||
var startOffsetB = (0, utils_1.isCstNode)(b) | ||
const startOffsetB = isCstNode(b) | ||
? b.children.At | ||
@@ -190,8 +154,7 @@ ? b.children.At[0].startOffset | ||
} | ||
exports.sortClassTypeChildren = sortClassTypeChildren; | ||
function sortModifiers(modifiers) { | ||
var firstAnnotations = []; | ||
var otherModifiers = []; | ||
var lastAnnotations = []; | ||
var hasOtherModifier = false; | ||
export function sortModifiers(modifiers) { | ||
let firstAnnotations = []; | ||
const otherModifiers = []; | ||
let lastAnnotations = []; | ||
let hasOtherModifier = false; | ||
/** | ||
@@ -202,5 +165,5 @@ * iterate in reverse order because we special-case | ||
*/ | ||
(0, forEachRight_1.default)(modifiers, function (modifier) { | ||
var isAnnotation = modifier.children.annotation !== undefined; | ||
var isTypeAnnotation = isAnnotation && | ||
forEachRight(modifiers, modifier => { | ||
const isAnnotation = modifier.children.annotation !== undefined; | ||
const isTypeAnnotation = isAnnotation && | ||
(modifier.name === "methodModifier" || | ||
@@ -230,5 +193,5 @@ modifier.name === "interfaceMethodModifier" || | ||
} | ||
otherModifiers.sort(function (a, b) { | ||
var modifierIndexA = orderedModifiers.indexOf(Object.keys(a.children)[0]); | ||
var modifierIndexB = orderedModifiers.indexOf(Object.keys(b.children)[0]); | ||
otherModifiers.sort((a, b) => { | ||
const modifierIndexA = orderedModifiers.indexOf(Object.keys(a.children)[0]); | ||
const modifierIndexB = orderedModifiers.indexOf(Object.keys(b.children)[0]); | ||
return modifierIndexA - modifierIndexB; | ||
@@ -238,9 +201,8 @@ }); | ||
} | ||
exports.sortModifiers = sortModifiers; | ||
function findDeepElementInPartsArray(item, elt) { | ||
export function findDeepElementInPartsArray(item, elt) { | ||
if (Array.isArray(item)) { | ||
if ((0, includes_1.default)(item, elt)) { | ||
if (includes(item, elt)) { | ||
return true; | ||
} | ||
for (var i = 0; i < item.length; i++) { | ||
for (let i = 0; i < item.length; i++) { | ||
if (findDeepElementInPartsArray(item[i], elt)) { | ||
@@ -252,3 +214,3 @@ return true; | ||
else { | ||
for (var key in item) { | ||
for (const key in item) { | ||
if (typeof item[key] === "object" && | ||
@@ -262,15 +224,13 @@ findDeepElementInPartsArray(item[key], elt)) { | ||
} | ||
exports.findDeepElementInPartsArray = findDeepElementInPartsArray; | ||
function displaySemicolon(token, params) { | ||
export function displaySemicolon(token, params) { | ||
if (params !== undefined && params.allowEmptyStatement) { | ||
return (0, format_comments_1.printTokenWithComments)(token); | ||
return printTokenWithComments(token); | ||
} | ||
if (!(0, comments_utils_1.hasComments)(token)) { | ||
if (!hasComments(token)) { | ||
return ""; | ||
} | ||
token.image = ""; | ||
return (0, format_comments_1.printTokenWithComments)(token); | ||
return printTokenWithComments(token); | ||
} | ||
exports.displaySemicolon = displaySemicolon; | ||
function isExplicitLambdaParameter(ctx) { | ||
export function isExplicitLambdaParameter(ctx) { | ||
return (ctx && | ||
@@ -282,16 +242,14 @@ ctx.lambdaParameterList && | ||
} | ||
exports.isExplicitLambdaParameter = isExplicitLambdaParameter; | ||
function getBlankLinesSeparator(ctx, separator) { | ||
if (separator === void 0) { separator = hardline; } | ||
export function getBlankLinesSeparator(ctx, separator = hardline) { | ||
if (ctx === undefined) { | ||
return []; | ||
} | ||
var separators = []; | ||
for (var i = 0; i < ctx.length - 1; i++) { | ||
var node = ctx[i]; | ||
var previousRuleEndLineWithComment = (0, comments_utils_1.hasTrailingComments)(node) | ||
const separators = []; | ||
for (let i = 0; i < ctx.length - 1; i++) { | ||
const node = ctx[i]; | ||
const previousRuleEndLineWithComment = hasTrailingComments(node) | ||
? node.trailingComments[node.trailingComments.length - 1].endLine | ||
: node.location.endLine; | ||
var nextNode = ctx[i + 1]; | ||
var nextRuleStartLineWithComment = (0, comments_utils_1.hasLeadingComments)(nextNode) | ||
const nextNode = ctx[i + 1]; | ||
const nextRuleStartLineWithComment = hasLeadingComments(nextNode) | ||
? nextNode.leadingComments[0].startLine | ||
@@ -308,4 +266,3 @@ : nextNode.location.startLine; | ||
} | ||
exports.getBlankLinesSeparator = getBlankLinesSeparator; | ||
var isTwoHardLine = function (userBlankLinesSeparator) { | ||
const isTwoHardLine = (userBlankLinesSeparator) => { | ||
if (!Array.isArray(userBlankLinesSeparator)) { | ||
@@ -319,12 +276,12 @@ return false; | ||
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++) { | ||
const declarationsWithoutEmptyStatements = declarations.filter(declaration => !isSemicolon(declaration)); | ||
const userBlankLinesSeparators = getBlankLinesSeparator(declarationsWithoutEmptyStatements); | ||
const additionalBlankLines = declarationsWithoutEmptyStatements.map(needLineDeclaration); | ||
const separators = []; | ||
let indexNextNotEmptyDeclaration = 0; | ||
for (let 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 ((0, comments_utils_1.hasComments)(declarations[i])) { | ||
if (hasComments(declarations[i])) { | ||
separators.push(hardline); | ||
@@ -335,4 +292,4 @@ } | ||
declarationsWithoutEmptyStatements.length - 1) { | ||
var isNextSeparatorTwoHardLine = isTwoHardLine(userBlankLinesSeparators[indexNextNotEmptyDeclaration]); | ||
var additionalSep = !isNextSeparatorTwoHardLine && | ||
const isNextSeparatorTwoHardLine = isTwoHardLine(userBlankLinesSeparators[indexNextNotEmptyDeclaration]); | ||
const additionalSep = !isNextSeparatorTwoHardLine && | ||
(additionalBlankLines[indexNextNotEmptyDeclaration + 1] || | ||
@@ -342,3 +299,3 @@ additionalBlankLines[indexNextNotEmptyDeclaration]) | ||
: ""; | ||
separators.push((0, prettier_builder_1.concat)([ | ||
separators.push(concat([ | ||
userBlankLinesSeparators[indexNextNotEmptyDeclaration], | ||
@@ -356,5 +313,5 @@ additionalSep | ||
} | ||
var classMemberDeclaration = declaration.children.classMemberDeclaration[0]; | ||
const classMemberDeclaration = declaration.children.classMemberDeclaration[0]; | ||
if (classMemberDeclaration.children.fieldDeclaration !== undefined) { | ||
var fieldDeclaration = classMemberDeclaration.children.fieldDeclaration[0]; | ||
const fieldDeclaration = classMemberDeclaration.children.fieldDeclaration[0]; | ||
if (fieldDeclaration.children.fieldModifier !== undefined && | ||
@@ -374,3 +331,3 @@ hasAnnotation(fieldDeclaration.children.fieldModifier) && | ||
if (declaration.children.constantDeclaration !== undefined) { | ||
var constantDeclaration = declaration.children.constantDeclaration[0]; | ||
const constantDeclaration = declaration.children.constantDeclaration[0]; | ||
if (constantDeclaration.children.constantModifier !== undefined && | ||
@@ -384,3 +341,3 @@ hasAnnotation(constantDeclaration.children.constantModifier) && | ||
else if (declaration.children.interfaceMethodDeclaration !== undefined) { | ||
var interfaceMethodDeclaration = declaration.children.interfaceMethodDeclaration[0]; | ||
const interfaceMethodDeclaration = declaration.children.interfaceMethodDeclaration[0]; | ||
if (interfaceMethodDeclaration.children.interfaceMethodModifier !== | ||
@@ -408,3 +365,3 @@ undefined && | ||
function hasAnnotation(modifiers) { | ||
return modifiers.some(function (modifier) { return modifier.children.annotation !== undefined; }); | ||
return modifiers.some(modifier => modifier.children.annotation !== undefined); | ||
} | ||
@@ -419,27 +376,25 @@ /** | ||
function hasNonTrailingAnnotation(modifiers) { | ||
var firstAnnotationIndex = (0, findIndex_1.default)(modifiers, function (modifier) { return modifier.children.annotation !== undefined; }); | ||
var lastNonAnnotationIndex = (0, findLastIndex_1.default)(modifiers, function (modifier) { return modifier.children.annotation === undefined; }); | ||
const firstAnnotationIndex = findIndex(modifiers, modifier => modifier.children.annotation !== undefined); | ||
const lastNonAnnotationIndex = findLastIndex(modifiers, modifier => modifier.children.annotation === undefined); | ||
return (firstAnnotationIndex < lastNonAnnotationIndex || | ||
lastNonAnnotationIndex === -1); | ||
} | ||
function getClassBodyDeclarationsSeparator(classBodyDeclarationContext) { | ||
export function getClassBodyDeclarationsSeparator(classBodyDeclarationContext) { | ||
return getDeclarationsSeparator(classBodyDeclarationContext, needLineClassBodyDeclaration, isClassBodyDeclarationASemicolon); | ||
} | ||
exports.getClassBodyDeclarationsSeparator = getClassBodyDeclarationsSeparator; | ||
function getInterfaceBodyDeclarationsSeparator(interfaceMemberDeclarationContext) { | ||
export function getInterfaceBodyDeclarationsSeparator(interfaceMemberDeclarationContext) { | ||
return getDeclarationsSeparator(interfaceMemberDeclarationContext, needLineInterfaceMemberDeclaration, isInterfaceMemberASemicolon); | ||
} | ||
exports.getInterfaceBodyDeclarationsSeparator = getInterfaceBodyDeclarationsSeparator; | ||
function getAndRemoveLeadingComment(doc) { | ||
var isTokenWithLeadingComment = typeof doc !== "string" && "leadingComments" in doc; | ||
const isTokenWithLeadingComment = typeof doc !== "string" && "leadingComments" in doc; | ||
if (!isTokenWithLeadingComment) { | ||
return []; | ||
} | ||
var leadingComments = (0, format_comments_1.getTokenLeadingComments)(doc); | ||
const leadingComments = getTokenLeadingComments(doc); | ||
delete doc.leadingComments; | ||
return leadingComments; | ||
} | ||
function putIntoBraces(argument, separator, LBrace, RBrace) { | ||
var rightBraceLeadingComments = getAndRemoveLeadingComment(RBrace); | ||
var lastBreakLine = | ||
export function putIntoBraces(argument, separator, LBrace, RBrace) { | ||
const rightBraceLeadingComments = getAndRemoveLeadingComment(RBrace); | ||
const lastBreakLine = | ||
// check if last element of the array is a line | ||
@@ -450,15 +405,16 @@ rightBraceLeadingComments.length !== 0 && | ||
: separator; | ||
var contentInsideBraces; | ||
if ((0, utils_2.isEmptyDoc)(argument)) { | ||
let contentInsideBraces; | ||
if (isEmptyDoc(argument)) { | ||
if (rightBraceLeadingComments.length === 0) { | ||
return (0, prettier_builder_1.concat)([LBrace, RBrace]); | ||
return concat([LBrace, RBrace]); | ||
} | ||
contentInsideBraces = __spreadArray([separator], rightBraceLeadingComments, true); | ||
contentInsideBraces = [separator, ...rightBraceLeadingComments]; | ||
} | ||
else if (rightBraceLeadingComments.length !== 0) { | ||
contentInsideBraces = __spreadArray([ | ||
contentInsideBraces = [ | ||
separator, | ||
argument, | ||
separator | ||
], rightBraceLeadingComments, true); | ||
separator, | ||
...rightBraceLeadingComments | ||
]; | ||
} | ||
@@ -468,5 +424,5 @@ else { | ||
} | ||
return (0, prettier_builder_1.group)(rejectAndConcat([ | ||
return group(rejectAndConcat([ | ||
LBrace, | ||
indent((0, prettier_builder_1.concat)(contentInsideBraces)), | ||
indent(concat(contentInsideBraces)), | ||
lastBreakLine, | ||
@@ -476,16 +432,14 @@ RBrace | ||
} | ||
exports.putIntoBraces = putIntoBraces; | ||
function binary(nodes, tokens, isRoot) { | ||
if (isRoot === void 0) { isRoot = false; } | ||
var levelOperator; | ||
var levelPrecedence; | ||
var level = []; | ||
export function binary(nodes, tokens, isRoot = false) { | ||
let levelOperator; | ||
let levelPrecedence; | ||
let level = []; | ||
while (tokens.length) { | ||
var nextOperator = getOperator(tokens); | ||
var nextPrecedence = getOperatorPrecedence(nextOperator); | ||
const nextOperator = getOperator(tokens); | ||
const nextPrecedence = getOperatorPrecedence(nextOperator); | ||
if (levelPrecedence === undefined || nextPrecedence === levelPrecedence) { | ||
var tokenLength = ["<<", ">>", ">>>"].includes(nextOperator) | ||
const tokenLength = ["<<", ">>", ">>>"].includes(nextOperator) | ||
? nextOperator.length | ||
: 1; | ||
var operator = (0, prettier_builder_1.concat)(tokens.splice(0, tokenLength)); | ||
const operator = concat(tokens.splice(0, tokenLength)); | ||
if (levelOperator !== undefined && | ||
@@ -495,7 +449,7 @@ needsParentheses(levelOperator, nextOperator)) { | ||
level = [ | ||
(0, prettier_builder_1.concat)(["(", (0, prettier_builder_1.group)(indent((0, prettier_builder_1.join)(line, level))), ") ", operator]) | ||
concat(["(", group(indent(join(line, level))), ") ", operator]) | ||
]; | ||
} | ||
else { | ||
level.push((0, prettier_builder_1.join)(" ", [nodes.shift(), operator])); | ||
level.push(join(" ", [nodes.shift(), operator])); | ||
} | ||
@@ -508,7 +462,7 @@ levelOperator = nextOperator; | ||
if (isRoot) { | ||
var content_1 = (0, prettier_builder_1.group)(indent((0, prettier_builder_1.join)(line, level))); | ||
const content = group(indent(join(line, level))); | ||
nodes.unshift(levelOperator !== undefined && | ||
needsParentheses(levelOperator, nextOperator) | ||
? (0, prettier_builder_1.concat)(["(", content_1, ")"]) | ||
: content_1); | ||
? concat(["(", content, ")"]) | ||
: content); | ||
level = []; | ||
@@ -519,18 +473,23 @@ levelOperator = undefined; | ||
else { | ||
return (0, prettier_builder_1.group)((0, prettier_builder_1.join)(line, level)); | ||
return group(join(line, level)); | ||
} | ||
} | ||
else { | ||
var content_2 = indent(binary(nodes, tokens)); | ||
const content = indent(binary(nodes, tokens)); | ||
nodes.unshift(levelOperator !== undefined && | ||
needsParentheses(nextOperator, levelOperator) | ||
? (0, prettier_builder_1.concat)(["(", content_2, ")"]) | ||
: content_2); | ||
? concat(["(", content, ")"]) | ||
: content); | ||
} | ||
} | ||
level.push(nodes.shift()); | ||
var content = (0, prettier_builder_1.group)((0, prettier_builder_1.join)(line, level)); | ||
return levelOperator === "=" ? indent(content) : content; | ||
const lineGroupId = Symbol("line"); | ||
return group(levelOperator === "=" | ||
? [ | ||
level[0], | ||
indent(group(line, { id: lineGroupId })), | ||
indentIfBreak(level[1], { groupId: lineGroupId }) | ||
] | ||
: join(line, level)); | ||
} | ||
exports.binary = binary; | ||
function getOperator(tokens) { | ||
@@ -540,9 +499,9 @@ if (!tokens.length) { | ||
} | ||
var _a = tokens[0], image = _a.image, startOffset = _a.startOffset; | ||
const [{ image, startOffset }] = tokens; | ||
if (!["<", ">"].includes(image)) { | ||
return image; | ||
} | ||
var repeatedTokenCount = 1; | ||
for (var i = 1; i < Math.min(3, tokens.length); i++) { | ||
var token = tokens[i]; | ||
let repeatedTokenCount = 1; | ||
for (let i = 1; i < Math.min(3, tokens.length); i++) { | ||
const token = tokens[i]; | ||
if (token.image !== image || token.startOffset !== startOffset + i) { | ||
@@ -566,3 +525,3 @@ break; | ||
} | ||
var PRECEDENCES_BY_OPERATOR = new Map([ | ||
const PRECEDENCES_BY_OPERATOR = new Map([ | ||
["||"], | ||
@@ -578,3 +537,3 @@ ["&&"], | ||
["*", "/", "%"] | ||
].flatMap(function (operators, index) { return operators.map(function (operator) { return [operator, index]; }); })); | ||
].flatMap((operators, index) => operators.map(operator => [operator, index]))); | ||
function getOperatorPrecedence(operator) { | ||
@@ -589,4 +548,4 @@ var _a; | ||
getOperatorPrecedence(parentOperator)) || | ||
[operator, parentOperator].every(function (o) { return ["==", "!="].includes(o); }) || | ||
[operator, parentOperator].every(function (o) { return ["<<", ">>", ">>>"].includes(o); }) || | ||
[operator, parentOperator].every(o => ["==", "!="].includes(o)) || | ||
[operator, parentOperator].every(o => ["<<", ">>", ">>>"].includes(o)) || | ||
(operator === "*" && parentOperator === "/") || | ||
@@ -597,11 +556,10 @@ (operator === "/" && parentOperator === "*") || | ||
} | ||
function isStatementEmptyStatement(statement) { | ||
export function isStatementEmptyStatement(statement) { | ||
return (statement === ";" || (Array.isArray(statement) && statement[0] === ";")); | ||
} | ||
exports.isStatementEmptyStatement = isStatementEmptyStatement; | ||
function sortImports(imports) { | ||
var staticImports = []; | ||
var nonStaticImports = []; | ||
export function sortImports(imports) { | ||
const staticImports = []; | ||
const nonStaticImports = []; | ||
if (imports !== undefined) { | ||
for (var i = 0; i < imports.length; i++) { | ||
for (let i = 0; i < imports.length; i++) { | ||
if (imports[i].children.Static !== undefined) { | ||
@@ -615,5 +573,3 @@ staticImports.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]); | ||
}; | ||
const comparator = (first, second) => compareFqn(first.children.packageOrTypeName[0], second.children.packageOrTypeName[0]); | ||
staticImports.sort(comparator); | ||
@@ -623,12 +579,11 @@ nonStaticImports.sort(comparator); | ||
return { | ||
staticImports: staticImports, | ||
nonStaticImports: nonStaticImports | ||
staticImports, | ||
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++) { | ||
const identifiersFirst = packageOrTypeNameFirst.children.Identifier; | ||
const identifiersSecond = packageOrTypeNameSecond.children.Identifier; | ||
const minParts = Math.min(identifiersFirst.length, identifiersSecond.length); | ||
for (let i = 0; i < minParts; i++) { | ||
if (identifiersFirst[i].image < identifiersSecond[i].image) { | ||
@@ -649,8 +604,8 @@ return -1; | ||
} | ||
function isUniqueMethodInvocation(primarySuffixes) { | ||
export function isUniqueMethodInvocation(primarySuffixes) { | ||
if (primarySuffixes === undefined) { | ||
return 0; | ||
} | ||
var count = 0; | ||
primarySuffixes.forEach(function (primarySuffix) { | ||
let count = 0; | ||
primarySuffixes.forEach(primarySuffix => { | ||
if (primarySuffix.children.methodInvocationSuffix !== undefined) { | ||
@@ -665,16 +620,13 @@ 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; | ||
export function printArrayList({ list, extraComma, LCurly, RCurly, trailingComma }) { | ||
let optionalComma; | ||
if (trailingComma !== "none" && list !== "") { | ||
optionalComma = extraComma | ||
? (0, prettier_builder_1.ifBreak)(extraComma[0], __assign(__assign({}, extraComma[0]), { image: "" })) | ||
: (0, prettier_builder_1.ifBreak)(",", ""); | ||
? ifBreak(extraComma[0], Object.assign(Object.assign({}, extraComma[0]), { image: "" })) | ||
: ifBreak(",", ""); | ||
} | ||
else { | ||
optionalComma = extraComma ? __assign(__assign({}, extraComma[0]), { image: "" }) : ""; | ||
optionalComma = extraComma ? Object.assign(Object.assign({}, extraComma[0]), { image: "" }) : ""; | ||
} | ||
return putIntoBraces(rejectAndConcat([list, optionalComma]), line, LCurly, RCurly); | ||
} | ||
exports.printArrayList = printArrayList; |
@@ -1,90 +0,55 @@ | ||
"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, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
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 doc_1 = require("prettier/doc"); | ||
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 line = doc_1.builders.line, softline = doc_1.builders.softline; | ||
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 | ||
import forEach from "lodash/forEach.js"; | ||
import { builders } from "prettier/doc"; | ||
import { concat, group, indent, join } from "./prettier-builder.js"; | ||
import { printTokenWithComments } from "./comments/format-comments.js"; | ||
import { putIntoBraces, rejectAndConcat, rejectAndJoin, rejectAndJoinSeps, sortClassTypeChildren } from "./printer-utils.js"; | ||
import { BaseCstPrettierPrinter } from "../base-cst-printer.js"; | ||
import { isAnnotationCstNode, isCstNode, isTypeArgumentsCstNode } from "../types/utils.js"; | ||
const { line, softline } = builders; | ||
export class TypesValuesAndVariablesPrettierVisitor extends BaseCstPrettierPrinter { | ||
primitiveType(ctx) { | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const type = ctx.numericType | ||
? this.visit(ctx.numericType) | ||
: this.getSingle(ctx); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [(0, prettier_builder_1.join)(" ", annotations), type]); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.numericType = function (ctx) { | ||
return rejectAndJoin(" ", [join(" ", annotations), type]); | ||
} | ||
numericType(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.integralType = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.floatingPointType = function (ctx) { | ||
return (0, format_comments_1.printTokenWithComments)(this.getSingle(ctx)); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.referenceType = function (ctx) { | ||
var annotations = this.mapVisit(ctx.annotation); | ||
var type = ctx.primitiveType | ||
} | ||
integralType(ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
floatingPointType(ctx) { | ||
return printTokenWithComments(this.getSingle(ctx)); | ||
} | ||
referenceType(ctx) { | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const type = ctx.primitiveType | ||
? this.visit(ctx.primitiveType) | ||
: this.visit(ctx.classOrInterfaceType); | ||
var dims = this.visit(ctx.dims); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [(0, prettier_builder_1.join)(" ", annotations), (0, prettier_builder_1.concat)([type, dims])]); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.classOrInterfaceType = function (ctx) { | ||
const dims = this.visit(ctx.dims); | ||
return rejectAndJoin(" ", [join(" ", annotations), concat([type, dims])]); | ||
} | ||
classOrInterfaceType(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.classType = function (ctx) { | ||
var _this = this; | ||
var tokens = (0, printer_utils_1.sortClassTypeChildren)(ctx.annotation, ctx.typeArguments, ctx.Identifier); | ||
var segments = []; | ||
var currentSegment = []; | ||
(0, forEach_1.default)(tokens, function (token, i) { | ||
if ((0, utils_1.isTypeArgumentsCstNode)(token)) { | ||
currentSegment.push(_this.visit([token])); | ||
segments.push((0, printer_utils_1.rejectAndConcat)(currentSegment)); | ||
} | ||
classType(ctx) { | ||
const tokens = sortClassTypeChildren(ctx.annotation, ctx.typeArguments, ctx.Identifier); | ||
const segments = []; | ||
let currentSegment = []; | ||
forEach(tokens, (token, i) => { | ||
if (isTypeArgumentsCstNode(token)) { | ||
currentSegment.push(this.visit([token])); | ||
segments.push(rejectAndConcat(currentSegment)); | ||
currentSegment = []; | ||
} | ||
else if ((0, utils_1.isAnnotationCstNode)(token)) { | ||
currentSegment.push(_this.visit([token]), " "); | ||
else if (isAnnotationCstNode(token)) { | ||
currentSegment.push(this.visit([token]), " "); | ||
} | ||
else { | ||
currentSegment.push(token); | ||
if ((i + 1 < tokens.length && !(0, utils_1.isTypeArgumentsCstNode)(tokens[i + 1])) || | ||
if ((i + 1 < tokens.length && !isTypeArgumentsCstNode(tokens[i + 1])) || | ||
i + 1 === tokens.length) { | ||
segments.push((0, printer_utils_1.rejectAndConcat)(currentSegment)); | ||
segments.push(rejectAndConcat(currentSegment)); | ||
currentSegment = []; | ||
@@ -94,23 +59,22 @@ } | ||
}); | ||
return (0, printer_utils_1.rejectAndJoinSeps)(ctx.Dot, segments); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.interfaceType = function (ctx) { | ||
return rejectAndJoinSeps(ctx.Dot, segments); | ||
} | ||
interfaceType(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.typeVariable = function (ctx) { | ||
var annotations = this.mapVisit(ctx.annotation); | ||
var identifier = this.getSingle(ctx); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [(0, prettier_builder_1.join)(" ", annotations), identifier]); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.dims = function (ctx) { | ||
var _this = this; | ||
var tokens = __spreadArray([], ctx.LSquare, true); | ||
} | ||
typeVariable(ctx) { | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const identifier = this.getSingle(ctx); | ||
return rejectAndJoin(" ", [join(" ", annotations), identifier]); | ||
} | ||
dims(ctx) { | ||
let tokens = [...ctx.LSquare]; | ||
if (ctx.annotation) { | ||
tokens = __spreadArray(__spreadArray([], tokens, true), ctx.annotation, true); | ||
tokens = [...tokens, ...ctx.annotation]; | ||
} | ||
tokens = tokens.sort(function (a, b) { | ||
var startOffset1 = (0, utils_1.isCstNode)(a) | ||
tokens = tokens.sort((a, b) => { | ||
const startOffset1 = isCstNode(a) | ||
? a.children.At[0].startOffset | ||
: a.startOffset; | ||
var startOffset2 = (0, utils_1.isCstNode)(b) | ||
const startOffset2 = isCstNode(b) | ||
? b.children.At[0].startOffset | ||
@@ -120,12 +84,12 @@ : b.startOffset; | ||
}); | ||
var segments = []; | ||
var currentSegment = []; | ||
(0, forEach_1.default)(tokens, function (token) { | ||
if ((0, utils_1.isCstNode)(token)) { | ||
currentSegment.push(_this.visit([token])); | ||
const segments = []; | ||
let currentSegment = []; | ||
forEach(tokens, token => { | ||
if (isCstNode(token)) { | ||
currentSegment.push(this.visit([token])); | ||
} | ||
else { | ||
segments.push((0, printer_utils_1.rejectAndConcat)([ | ||
(0, printer_utils_1.rejectAndJoin)(" ", currentSegment), | ||
(0, prettier_builder_1.concat)([ctx.LSquare[0], ctx.RSquare[0]]) | ||
segments.push(rejectAndConcat([ | ||
rejectAndJoin(" ", currentSegment), | ||
concat([ctx.LSquare[0], ctx.RSquare[0]]) | ||
])); | ||
@@ -135,60 +99,58 @@ currentSegment = []; | ||
}); | ||
return (0, 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 (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.join)(" ", typeParameterModifiers), | ||
return rejectAndConcat(segments); | ||
} | ||
typeParameter(ctx) { | ||
const typeParameterModifiers = this.mapVisit(ctx.typeParameterModifier); | ||
const typeIdentifier = this.visit(ctx.typeIdentifier); | ||
const typeBound = this.visit(ctx.typeBound); | ||
return rejectAndJoin(" ", [ | ||
join(" ", typeParameterModifiers), | ||
typeIdentifier, | ||
typeBound | ||
]); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.typeParameterModifier = function (ctx) { | ||
} | ||
typeParameterModifier(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.typeBound = function (ctx) { | ||
var classOrInterfaceType = this.visit(ctx.classOrInterfaceType); | ||
var additionalBound = this.mapVisit(ctx.additionalBound); | ||
return (0, prettier_builder_1.concat)([ | ||
(0, printer_utils_1.rejectAndJoin)(" ", [ctx.Extends[0], classOrInterfaceType]), | ||
(0, prettier_builder_1.indent)((0, prettier_builder_1.group)((0, prettier_builder_1.concat)([ | ||
} | ||
typeBound(ctx) { | ||
const classOrInterfaceType = this.visit(ctx.classOrInterfaceType); | ||
const additionalBound = this.mapVisit(ctx.additionalBound); | ||
return concat([ | ||
rejectAndJoin(" ", [ctx.Extends[0], classOrInterfaceType]), | ||
indent(group(concat([ | ||
additionalBound.length ? line : "", | ||
(0, printer_utils_1.rejectAndJoin)(line, additionalBound) | ||
rejectAndJoin(line, additionalBound) | ||
]))) | ||
]); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.additionalBound = function (ctx) { | ||
var interfaceType = this.visit(ctx.interfaceType); | ||
return (0, prettier_builder_1.join)(" ", [ctx.And[0], interfaceType]); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.typeArguments = function (ctx) { | ||
var typeArgumentList = this.visit(ctx.typeArgumentList); | ||
return (0, printer_utils_1.putIntoBraces)(typeArgumentList, softline, ctx.Less[0], ctx.Greater[0]); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.typeArgumentList = function (ctx) { | ||
var typeArguments = this.mapVisit(ctx.typeArgument); | ||
var commas = ctx.Comma ? ctx.Comma.map(function (elt) { return (0, prettier_builder_1.concat)([elt, line]); }) : []; | ||
return (0, printer_utils_1.rejectAndJoinSeps)(commas, typeArguments); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.typeArgument = function (ctx) { | ||
} | ||
additionalBound(ctx) { | ||
const interfaceType = this.visit(ctx.interfaceType); | ||
return join(" ", [ctx.And[0], interfaceType]); | ||
} | ||
typeArguments(ctx) { | ||
const typeArgumentList = this.visit(ctx.typeArgumentList); | ||
return putIntoBraces(typeArgumentList, softline, ctx.Less[0], ctx.Greater[0]); | ||
} | ||
typeArgumentList(ctx) { | ||
const typeArguments = this.mapVisit(ctx.typeArgument); | ||
const commas = ctx.Comma ? ctx.Comma.map(elt => concat([elt, line])) : []; | ||
return rejectAndJoinSeps(commas, typeArguments); | ||
} | ||
typeArgument(ctx) { | ||
return this.visitSingle(ctx); | ||
}; | ||
TypesValuesAndVariablesPrettierVisitor.prototype.wildcard = function (ctx) { | ||
var annotations = this.mapVisit(ctx.annotation); | ||
var wildcardBounds = this.visit(ctx.wildcardBounds); | ||
return (0, printer_utils_1.rejectAndJoin)(" ", [ | ||
(0, prettier_builder_1.join)(" ", annotations), | ||
} | ||
wildcard(ctx) { | ||
const annotations = this.mapVisit(ctx.annotation); | ||
const wildcardBounds = this.visit(ctx.wildcardBounds); | ||
return rejectAndJoin(" ", [ | ||
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 (0, prettier_builder_1.join)(" ", [keyWord, referenceType]); | ||
}; | ||
return TypesValuesAndVariablesPrettierVisitor; | ||
}(base_cst_printer_1.BaseCstPrettierPrinter)); | ||
exports.TypesValuesAndVariablesPrettierVisitor = TypesValuesAndVariablesPrettierVisitor; | ||
} | ||
wildcardBounds(ctx) { | ||
const keyWord = ctx.Extends ? ctx.Extends[0] : ctx.Super[0]; | ||
const referenceType = this.visit(ctx.referenceType); | ||
return join(" ", [keyWord, referenceType]); | ||
} | ||
} |
@@ -1,29 +0,20 @@ | ||
"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) { | ||
export function isCstNode(tokenOrNode) { | ||
return !isIToken(tokenOrNode); | ||
} | ||
exports.isCstNode = isCstNode; | ||
function isIToken(tokenOrNode) { | ||
export function isIToken(tokenOrNode) { | ||
return (tokenOrNode.tokenType !== undefined && | ||
tokenOrNode.image !== undefined); | ||
} | ||
exports.isIToken = isIToken; | ||
function isCstElementOrUndefinedIToken(tokenOrNode) { | ||
export function isCstElementOrUndefinedIToken(tokenOrNode) { | ||
return tokenOrNode !== undefined && isIToken(tokenOrNode); | ||
} | ||
exports.isCstElementOrUndefinedIToken = isCstElementOrUndefinedIToken; | ||
var isTypeArgumentsCstNode = function (cstElement) { | ||
export const isTypeArgumentsCstNode = (cstElement) => { | ||
return cstElement.name === "typeArguments"; | ||
}; | ||
exports.isTypeArgumentsCstNode = isTypeArgumentsCstNode; | ||
var isAnnotationCstNode = function (cstElement) { | ||
export const isAnnotationCstNode = (cstElement) => { | ||
return cstElement.name === "annotation"; | ||
}; | ||
exports.isAnnotationCstNode = isAnnotationCstNode; | ||
var isOrdinaryCompilationUnitCtx = function (ctx) { | ||
export const isOrdinaryCompilationUnitCtx = (ctx) => { | ||
return (ctx.ordinaryCompilationUnit !== | ||
undefined); | ||
}; | ||
exports.isOrdinaryCompilationUnitCtx = isOrdinaryCompilationUnitCtx; |
@@ -1,25 +0,21 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSingleArgumentLambdaExpressionWithBlock = exports.isArgumentListSingleLambda = void 0; | ||
function isArgumentListSingleLambda(argumentList) { | ||
export function isArgumentListSingleLambda(argumentList) { | ||
if (argumentList === undefined) { | ||
return false; | ||
} | ||
var args = argumentList[0].children.expression; | ||
const args = argumentList[0].children.expression; | ||
if (args.length !== 1) { | ||
return false; | ||
} | ||
var argument = args[0]; | ||
const argument = args[0]; | ||
return argument.children.lambdaExpression !== undefined; | ||
} | ||
exports.isArgumentListSingleLambda = isArgumentListSingleLambda; | ||
var isSingleArgumentLambdaExpressionWithBlock = function (argumentList) { | ||
export const isSingleArgumentLambdaExpressionWithBlock = (argumentList) => { | ||
if (argumentList === undefined) { | ||
return false; | ||
} | ||
var args = argumentList[0].children.expression; | ||
const args = argumentList[0].children.expression; | ||
if (args.length !== 1) { | ||
return false; | ||
} | ||
var argument = args[0]; | ||
const argument = args[0]; | ||
return (argument.children.lambdaExpression !== undefined && | ||
@@ -29,2 +25,2 @@ argument.children.lambdaExpression[0].children.lambdaBody[0].children | ||
}; | ||
exports.isSingleArgumentLambdaExpressionWithBlock = isSingleArgumentLambdaExpressionWithBlock; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhwcmVzc2lvbnMtdXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvZXhwcmVzc2lvbnMtdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsTUFBTSxVQUFVLDBCQUEwQixDQUN4QyxZQUErQztJQUUvQyxJQUFJLFlBQVksS0FBSyxTQUFTLEVBQUU7UUFDOUIsT0FBTyxLQUFLLENBQUM7S0FDZDtJQUVELE1BQU0sSUFBSSxHQUFHLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQyxRQUFRLENBQUMsVUFBVSxDQUFDO0lBQ2pELElBQUksSUFBSSxDQUFDLE1BQU0sS0FBSyxDQUFDLEVBQUU7UUFDckIsT0FBTyxLQUFLLENBQUM7S0FDZDtJQUVELE1BQU0sUUFBUSxHQUFHLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN6QixPQUFPLFFBQVEsQ0FBQyxRQUFRLENBQUMsZ0JBQWdCLEtBQUssU0FBUyxDQUFDO0FBQzFELENBQUM7QUFFRCxNQUFNLENBQUMsTUFBTSx5Q0FBeUMsR0FBRyxDQUN2RCxZQUErQyxFQUMvQyxFQUFFO0lBQ0YsSUFBSSxZQUFZLEtBQUssU0FBUyxFQUFFO1FBQzlCLE9BQU8sS0FBSyxDQUFDO0tBQ2Q7SUFFRCxNQUFNLElBQUksR0FBRyxZQUFZLENBQUMsQ0FBQyxDQUFDLENBQUMsUUFBUSxDQUFDLFVBQVUsQ0FBQztJQUNqRCxJQUFJLElBQUksQ0FBQyxNQUFNLEtBQUssQ0FBQyxFQUFFO1FBQ3JCLE9BQU8sS0FBSyxDQUFDO0tBQ2Q7SUFFRCxNQUFNLFFBQVEsR0FBRyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDekIsT0FBTyxDQUNMLFFBQVEsQ0FBQyxRQUFRLENBQUMsZ0JBQWdCLEtBQUssU0FBUztRQUNoRCxRQUFRLENBQUMsUUFBUSxDQUFDLGdCQUFnQixDQUFDLENBQUMsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDLENBQUMsUUFBUTthQUNsRSxLQUFLLEtBQUssU0FBUyxDQUN2QixDQUFDO0FBQ0osQ0FBQyxDQUFDIn0= |
@@ -1,12 +0,2 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isEmptyDoc = 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; } }); | ||
var isEmptyDoc_1 = require("./isEmptyDoc"); | ||
Object.defineProperty(exports, "isEmptyDoc", { enumerable: true, get: function () { return __importDefault(isEmptyDoc_1).default; } }); | ||
export { default as printArgumentListWithBraces } from "./printArgumentListWithBraces.js"; | ||
export { default as isEmptyDoc } from "./isEmptyDoc.js"; |
@@ -1,6 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var isEmptyDoc = function (argument) { | ||
const isEmptyDoc = (argument) => { | ||
return argument === "" || (Array.isArray(argument) && argument.length) === 0; | ||
}; | ||
exports.default = isEmptyDoc; | ||
export default isEmptyDoc; |
@@ -1,21 +0,31 @@ | ||
"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 = (0, expressions_utils_1.isArgumentListSingleLambda)(argumentListCtx); | ||
if (isSingleLambda) { | ||
return printSingleLambdaInvocation_1.default.call(this, argumentListCtx, rBrace, lBrace); | ||
import { builders, utils } from "prettier/doc"; | ||
import { putIntoBraces } from "../printers/printer-utils.js"; | ||
const { breakParent, conditionalGroup, softline } = builders; | ||
const { willBreak } = utils; | ||
export default function printArgumentListWithBraces(argumentListNodes, rBrace, lBrace) { | ||
if (argumentListNodes && | ||
!argumentListNodes[0].leadingComments && | ||
!rBrace.leadingComments && | ||
isArgumentListHuggable(argumentListNodes[0].children)) { | ||
const [flat, expanded] = [false, true].map(shouldBreak => { | ||
const argumentList = this.visit(argumentListNodes, { | ||
isHuggable: true, | ||
shouldBreak | ||
}); | ||
return putIntoBraces(argumentList, "", lBrace, rBrace); | ||
}); | ||
return [ | ||
willBreak(flat) ? breakParent : "", | ||
conditionalGroup([flat, expanded]) | ||
]; | ||
} | ||
var argumentList = this.visit(argumentListCtx, { | ||
isInsideMethodInvocationSuffix: true | ||
}); | ||
return (0, printer_utils_1.putIntoBraces)(argumentList, softline, lBrace, rBrace); | ||
const argumentList = this.visit(argumentListNodes); | ||
return putIntoBraces(argumentList, softline, lBrace, rBrace); | ||
} | ||
exports.default = printArgumentListWithBraces; | ||
function isArgumentListHuggable(argumentList) { | ||
var _a; | ||
const expressions = argumentList.expression; | ||
return ((expressions.length === 1 || | ||
((_a = expressions[expressions.length - 1].children.lambdaExpression) === null || _a === void 0 ? void 0 : _a[0].children.lambdaBody[0].children.block) !== undefined) && | ||
expressions.filter(({ children }) => children.lambdaExpression).length === 1); | ||
} |
@@ -1,20 +0,18 @@ | ||
"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, | ||
import { builders } from "prettier/doc"; | ||
import { isSingleArgumentLambdaExpressionWithBlock } from "./expressions-utils.js"; | ||
import { printTokenWithComments } from "../printers/comments/format-comments.js"; | ||
import { concat, dedent, indent } from "../printers/prettier-builder.js"; | ||
import { putIntoBraces } from "../printers/printer-utils.js"; | ||
const { softline, ifBreak } = builders; | ||
export default function printSingleLambdaInvocation(argumentListCtx, rBrace, lBrace) { | ||
const lambdaParametersGroupId = Symbol("lambdaParameters"); | ||
const argumentList = this.visit(argumentListCtx, { | ||
lambdaParametersGroupId, | ||
isInsideMethodInvocationSuffix: true | ||
}); | ||
var formattedRBrace = (0, expressions_utils_1.isSingleArgumentLambdaExpressionWithBlock)(argumentListCtx) | ||
? ifBreak((0, prettier_builder_1.indent)((0, prettier_builder_1.concat)([softline, rBrace])), (0, format_comments_1.printTokenWithComments)(rBrace), { groupId: lambdaParametersGroupId }) | ||
: (0, prettier_builder_1.indent)((0, prettier_builder_1.concat)([softline, rBrace])); | ||
return (0, prettier_builder_1.dedent)((0, printer_utils_1.putIntoBraces)(argumentList, "", lBrace, formattedRBrace)); | ||
const formattedRBrace = isSingleArgumentLambdaExpressionWithBlock(argumentListCtx) | ||
? ifBreak(indent(concat([softline, rBrace])), printTokenWithComments(rBrace), { groupId: lambdaParametersGroupId }) | ||
: indent(concat([softline, rBrace])); | ||
return dedent(putIntoBraces(argumentList, "", lBrace, formattedRBrace)); | ||
} | ||
exports.default = printSingleLambdaInvocation; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJpbnRTaW5nbGVMYW1iZGFJbnZvY2F0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL3ByaW50U2luZ2xlTGFtYmRhSW52b2NhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sY0FBYyxDQUFDO0FBQ3hDLE9BQU8sRUFBRSx5Q0FBeUMsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ25GLE9BQU8sRUFBRSxzQkFBc0IsRUFBRSxNQUFNLHlDQUF5QyxDQUFDO0FBQ2pGLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ3pFLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUU3RCxNQUFNLEVBQUUsUUFBUSxFQUFFLE9BQU8sRUFBRSxHQUFHLFFBQVEsQ0FBQztBQUV2QyxNQUFNLENBQUMsT0FBTyxVQUFVLDJCQUEyQixDQUNqRCxlQUFrRCxFQUNsRCxNQUFjLEVBQ2QsTUFBYztJQUVkLE1BQU0sdUJBQXVCLEdBQUcsTUFBTSxDQUFDLGtCQUFrQixDQUFDLENBQUM7SUFDM0QsTUFBTSxZQUFZLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxlQUFlLEVBQUU7UUFDL0MsdUJBQXVCO1FBQ3ZCLDhCQUE4QixFQUFFLElBQUk7S0FDckMsQ0FBQyxDQUFDO0lBRUgsTUFBTSxlQUFlLEdBQUcseUNBQXlDLENBQy9ELGVBQWUsQ0FDaEI7UUFDQyxDQUFDLENBQUMsT0FBTyxDQUNMLE1BQU0sQ0FBQyxNQUFNLENBQUMsQ0FBQyxRQUFRLEVBQUUsTUFBTSxDQUFDLENBQUMsQ0FBQyxFQUNsQyxzQkFBc0IsQ0FBQyxNQUFNLENBQUMsRUFDOUIsRUFBRSxPQUFPLEVBQUUsdUJBQXVCLEVBQUUsQ0FDckM7UUFDSCxDQUFDLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDLFFBQVEsRUFBRSxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDdkMsT0FBTyxNQUFNLENBQUMsYUFBYSxDQUFDLFlBQVksRUFBRSxFQUFFLEVBQUUsTUFBTSxFQUFFLGVBQWUsQ0FBQyxDQUFDLENBQUM7QUFDMUUsQ0FBQyJ9 |
{ | ||
"name": "prettier-plugin-java", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"description": "Prettier Java Plugin", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"exports": "./dist/index.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"homepage": "https://jhipster.github.io/prettier-java/", | ||
"repository": "https://github.com/jhipster/prettier-java", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"java-parser": "2.2.0", | ||
"java-parser": "2.3.0", | ||
"lodash": "4.17.21", | ||
"prettier": "3.0.3" | ||
"prettier": "3.2.5" | ||
}, | ||
@@ -24,12 +26,7 @@ "scripts": { | ||
"clone-samples": "node scripts/clone-samples.js", | ||
"build": "tsc -p tsconfig.build.json --outDir dist", | ||
"build:watch": "tsc -p tsconfig.build.json --inlineSourceMap --outDir dist -w" | ||
"build": "tsc", | ||
"build:watch": "tsc --inlineSourceMap -w" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "7.19.3", | ||
"@babel/core": "7.20.2", | ||
"@babel/preset-env": "7.20.2", | ||
"@babel/preset-typescript": "7.18.6", | ||
"@babel/register": "7.18.9", | ||
"@chevrotain/types": "9.0.2", | ||
"@chevrotain/types": "11.0.3", | ||
"@types/chai": "4.3.4", | ||
@@ -45,3 +42,3 @@ "@types/fs-extra": "9.0.13", | ||
}, | ||
"gitHead": "00a8585d20c56d933ce4c89dcb532d9e98d1a4cf" | ||
"gitHead": "30e1cad12e8936df43c25eeb9dad5aef20d9af6c" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
10
0
Yes
172131
3718
1
+ Added@chevrotain/cst-dts-gen@11.0.3(transitive)
+ Added@chevrotain/gast@11.0.3(transitive)
+ Added@chevrotain/regexp-to-ast@11.0.3(transitive)
+ Added@chevrotain/types@11.0.3(transitive)
+ Added@chevrotain/utils@11.0.3(transitive)
+ Addedchevrotain@11.0.3(transitive)
+ Addedchevrotain-allstar@0.3.1(transitive)
+ Addedjava-parser@2.3.0(transitive)
+ Addedlodash-es@4.17.21(transitive)
+ Addedprettier@3.2.5(transitive)
- Removedchevrotain@6.5.0(transitive)
- Removedjava-parser@2.2.0(transitive)
- Removedprettier@3.0.3(transitive)
- Removedregexp-to-ast@0.4.0(transitive)
Updatedjava-parser@2.3.0
Updatedprettier@3.2.5