forked from kevin.shehu/GGD
NEW : REBASE THE ENTIRE WORKING PROJECT
This commit is contained in:
29
node_modules/prettier-plugin-java/dist/printers/comments/comments-utils.js
generated
vendored
Normal file
29
node_modules/prettier-plugin-java/dist/printers/comments/comments-utils.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hasComments = exports.hasTrailingLineComments = exports.hasLeadingLineComments = exports.hasTrailingComments = exports.hasLeadingComments = void 0;
|
||||
function hasLeadingComments(token) {
|
||||
return token.leadingComments !== undefined;
|
||||
}
|
||||
exports.hasLeadingComments = hasLeadingComments;
|
||||
function hasTrailingComments(token) {
|
||||
return token.trailingComments !== undefined;
|
||||
}
|
||||
exports.hasTrailingComments = hasTrailingComments;
|
||||
function hasLeadingLineComments(token) {
|
||||
return (token.leadingComments !== undefined &&
|
||||
token.leadingComments.length !== 0 &&
|
||||
token.leadingComments[token.leadingComments.length - 1].tokenType.name ===
|
||||
"LineComment");
|
||||
}
|
||||
exports.hasLeadingLineComments = hasLeadingLineComments;
|
||||
function hasTrailingLineComments(token) {
|
||||
return (token.trailingComments !== undefined &&
|
||||
token.trailingComments.length !== 0 &&
|
||||
token.trailingComments[token.trailingComments.length - 1].tokenType.name ===
|
||||
"LineComment");
|
||||
}
|
||||
exports.hasTrailingLineComments = hasTrailingLineComments;
|
||||
function hasComments(token) {
|
||||
return hasLeadingComments(token) || hasTrailingComments(token);
|
||||
}
|
||||
exports.hasComments = hasComments;
|
179
node_modules/prettier-plugin-java/dist/printers/comments/format-comments.js
generated
vendored
Normal file
179
node_modules/prettier-plugin-java/dist/printers/comments/format-comments.js
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
"use strict";
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
||||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
||||
to[j] = from[i];
|
||||
return to;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.processComments = exports.getTokenLeadingComments = exports.printNodeWithComments = exports.printTokenWithComments = void 0;
|
||||
var doc_1 = require("prettier/doc");
|
||||
var utils_1 = require("../../types/utils");
|
||||
var concat = doc_1.builders.concat, hardline = doc_1.builders.hardline, lineSuffix = doc_1.builders.lineSuffix, breakParent = doc_1.builders.breakParent, literalline = doc_1.builders.literalline;
|
||||
/**
|
||||
* Takes a token and return a doc with:
|
||||
* - concatenated leading comments
|
||||
* - the token image
|
||||
* - concatenated trailing comments
|
||||
*
|
||||
* @param {IToken} token
|
||||
* @return a doc with the token and its comments
|
||||
*/
|
||||
function printTokenWithComments(token) {
|
||||
return printWithComments(token, token.image, getTokenLeadingComments, getTokenTrailingComments);
|
||||
}
|
||||
exports.printTokenWithComments = printTokenWithComments;
|
||||
/**
|
||||
* Takes a node and return a doc with:
|
||||
* - concatenated leading comments
|
||||
* - the node doc value
|
||||
* - concatenated trailing comments
|
||||
*
|
||||
* @param {CstNode} node
|
||||
* @param {Doc} value - the converted node value
|
||||
* @return a doc with the token and its comments
|
||||
*/
|
||||
function printNodeWithComments(node, value) {
|
||||
return printWithComments(node, value, getNodeLeadingComments, getNodeTrailingComments);
|
||||
}
|
||||
exports.printNodeWithComments = printNodeWithComments;
|
||||
function printWithComments(nodeOrToken, value, getLeadingComments, getTrailingComments) {
|
||||
var leadingComments = getLeadingComments(nodeOrToken);
|
||||
var trailingComments = getTrailingComments(nodeOrToken, value);
|
||||
return leadingComments.length === 0 && trailingComments.length === 0
|
||||
? value
|
||||
: concat(__spreadArray(__spreadArray(__spreadArray([], leadingComments), [value]), trailingComments));
|
||||
}
|
||||
/**
|
||||
* @param {IToken} token
|
||||
* @return an array containing processed leading comments and separators
|
||||
*/
|
||||
function getTokenLeadingComments(token) {
|
||||
return getLeadingComments(token, token);
|
||||
}
|
||||
exports.getTokenLeadingComments = getTokenLeadingComments;
|
||||
/**
|
||||
* @param {CstNode} node
|
||||
* @return an array containing processed leading comments and separators
|
||||
*/
|
||||
function getNodeLeadingComments(node) {
|
||||
return getLeadingComments(node, node.location);
|
||||
}
|
||||
function getLeadingComments(nodeOrToken, location) {
|
||||
var arr = [];
|
||||
if (nodeOrToken.leadingComments !== undefined) {
|
||||
var previousEndLine = nodeOrToken.leadingComments[0].endLine;
|
||||
var step = void 0;
|
||||
arr.push(concat(formatComment(nodeOrToken.leadingComments[0])));
|
||||
for (var i = 1; i < nodeOrToken.leadingComments.length; i++) {
|
||||
step = nodeOrToken.leadingComments[i].startLine - previousEndLine;
|
||||
if (step === 1 ||
|
||||
nodeOrToken.leadingComments[i].startOffset > location.startOffset) {
|
||||
arr.push(hardline);
|
||||
}
|
||||
else if (step > 1) {
|
||||
arr.push(hardline, hardline);
|
||||
}
|
||||
arr.push(concat(formatComment(nodeOrToken.leadingComments[i])));
|
||||
previousEndLine = nodeOrToken.leadingComments[i].endLine;
|
||||
}
|
||||
step = location.startLine - previousEndLine;
|
||||
if (step === 1 ||
|
||||
nodeOrToken.leadingComments[nodeOrToken.leadingComments.length - 1]
|
||||
.startOffset > location.startOffset) {
|
||||
arr.push(hardline);
|
||||
}
|
||||
else if (step > 1) {
|
||||
arr.push(hardline, hardline);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
/**
|
||||
* @param {IToken} token
|
||||
* @return an array containing processed trailing comments and separators
|
||||
*/
|
||||
function getTokenTrailingComments(token) {
|
||||
return getTrailingComments(token, token.image, token);
|
||||
}
|
||||
/**
|
||||
* @param {CstNode} node
|
||||
* @param {string} value
|
||||
* @return an array containing processed trailing comments and separators
|
||||
*/
|
||||
function getNodeTrailingComments(node, value) {
|
||||
return getTrailingComments(node, value, node.location);
|
||||
}
|
||||
function getTrailingComments(nodeOrToken, value, location) {
|
||||
var arr = [];
|
||||
var previousEndLine = location.endLine;
|
||||
if (nodeOrToken.trailingComments !== undefined) {
|
||||
nodeOrToken.trailingComments.forEach(function (comment, idx) {
|
||||
var separator = "";
|
||||
if (comment.startLine !== previousEndLine) {
|
||||
arr.push(hardline);
|
||||
}
|
||||
else if (value !== "" && idx === 0) {
|
||||
separator = " ";
|
||||
}
|
||||
if (comment.tokenType.name === "LineComment") {
|
||||
arr.push(lineSuffix(concat([separator, concat(formatComment(comment)), breakParent])));
|
||||
}
|
||||
else {
|
||||
arr.push(concat(formatComment(comment)));
|
||||
}
|
||||
previousEndLine = comment.endLine;
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
function isJavaDoc(comment, lines) {
|
||||
var isJavaDoc = true;
|
||||
if (comment.tokenType.name === "TraditionalComment" && lines.length > 1) {
|
||||
for (var i = 1; i < lines.length; i++) {
|
||||
if (lines[i].trim().charAt(0) !== "*") {
|
||||
isJavaDoc = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
isJavaDoc = false;
|
||||
}
|
||||
return isJavaDoc;
|
||||
}
|
||||
function formatJavaDoc(lines) {
|
||||
var res = [lines[0].trim()];
|
||||
for (var i = 1; i < lines.length; i++) {
|
||||
res.push(hardline);
|
||||
res.push(" " + lines[i].trim());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
function formatComment(comment) {
|
||||
var res = [];
|
||||
var lines = comment.image.split("\n");
|
||||
if (isJavaDoc(comment, lines)) {
|
||||
return formatJavaDoc(lines);
|
||||
}
|
||||
lines.forEach(function (line) {
|
||||
res.push(line);
|
||||
res.push(literalline);
|
||||
});
|
||||
res.pop();
|
||||
return res;
|
||||
}
|
||||
function processComments(docs) {
|
||||
if (!Array.isArray(docs)) {
|
||||
if (utils_1.isCstElementOrUndefinedIToken(docs)) {
|
||||
return printTokenWithComments(docs);
|
||||
}
|
||||
return docs;
|
||||
}
|
||||
return docs.map(function (elt) {
|
||||
if (utils_1.isCstElementOrUndefinedIToken(elt)) {
|
||||
return printTokenWithComments(elt);
|
||||
}
|
||||
return elt;
|
||||
});
|
||||
}
|
||||
exports.processComments = processComments;
|
38
node_modules/prettier-plugin-java/dist/printers/comments/handle-comments.js
generated
vendored
Normal file
38
node_modules/prettier-plugin-java/dist/printers/comments/handle-comments.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.handleCommentsBinaryExpression = void 0;
|
||||
var comments_utils_1 = require("./comments-utils");
|
||||
function handleCommentsBinaryExpression(ctx) {
|
||||
var unaryExpressionIndex = 1;
|
||||
if (ctx.BinaryOperator !== undefined) {
|
||||
ctx.BinaryOperator.forEach(function (binaryOperator) {
|
||||
var _a;
|
||||
if (comments_utils_1.hasLeadingComments(binaryOperator)) {
|
||||
while (ctx.unaryExpression[unaryExpressionIndex].location.startOffset <
|
||||
binaryOperator.endOffset) {
|
||||
unaryExpressionIndex++;
|
||||
}
|
||||
// Adapt the position of the operator and its leading comments
|
||||
var shiftUp = binaryOperator.leadingComments[0].startLine -
|
||||
1 -
|
||||
binaryOperator.startLine;
|
||||
if (binaryOperator.startLine !==
|
||||
ctx.unaryExpression[unaryExpressionIndex].location.startLine) {
|
||||
binaryOperator.leadingComments.forEach(function (comment) {
|
||||
comment.startLine += 1;
|
||||
comment.endLine += 1;
|
||||
});
|
||||
}
|
||||
binaryOperator.startLine += shiftUp;
|
||||
binaryOperator.endLine += shiftUp;
|
||||
// Assign the leading comments & trailing comments of the binaryOperator
|
||||
// to the following unaryExpression as leading comments
|
||||
ctx.unaryExpression[unaryExpressionIndex].leadingComments =
|
||||
ctx.unaryExpression[unaryExpressionIndex].leadingComments || [];
|
||||
(_a = ctx.unaryExpression[unaryExpressionIndex].leadingComments).unshift.apply(_a, binaryOperator.leadingComments);
|
||||
delete binaryOperator.leadingComments;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.handleCommentsBinaryExpression = handleCommentsBinaryExpression;
|
Reference in New Issue
Block a user