forked from jhipster/prettier-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.ts
More file actions
30 lines (29 loc) · 880 Bytes
/
parser.ts
File metadata and controls
30 lines (29 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { parse } from "java-parser";
import type { Parser } from "prettier";
import { determinePrettierIgnoreRanges } from "./comments.js";
import {
isTerminal,
type JavaNode,
type JavaNonTerminal,
type JavaParserOptions
} from "./printers/helpers.js";
export default {
parse(text, options: JavaParserOptions) {
const cst = parse(text, options.entrypoint) as JavaNonTerminal;
cst.comments?.forEach(comment => {
comment.value = comment.image;
});
determinePrettierIgnoreRanges(cst);
return cst;
},
astFormat: "java",
hasPragma(text) {
return /^\/\*\*\n\s+\*\s@(format|prettier)\n\s+\*\//.test(text);
},
locStart(node) {
return isTerminal(node) ? node.startOffset : node.location.startOffset;
},
locEnd(node) {
return (isTerminal(node) ? node.endOffset : node.location.endOffset) + 1;
}
} satisfies Parser<JavaNode>;