Skip to content

Commit 3bd8fdb

Browse files
authoredMar 4, 2022
Java: Fixed record false positives (#3348)
1 parent 499b1fa commit 3bd8fdb

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed
 

‎components/prism-java.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function (Prism) {
22

3-
var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
3+
var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
44

55
// full package (optional) + parent classes (optional)
66
var classNamePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;

‎components/prism-java.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/languages/java/issue3345.test

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
public class Main {
2+
// "record" is used as variable name, but Prism marked it keyword
3+
public static void main(String[] record) {
4+
System.out.println(record);
5+
}
6+
// "record" is used as method name, but Prism marked it keyword
7+
public void record(String aaa){
8+
}
9+
// "record" is keyword since java 14
10+
public static record A() {
11+
}
12+
// it cannot be used as class name in java syntax
13+
public static class record {
14+
}
15+
}
16+
17+
----------------------------------------------------
18+
19+
[
20+
["keyword", "public"],
21+
["keyword", "class"],
22+
["class-name", ["Main"]],
23+
["punctuation", "{"],
24+
25+
["comment", "// \"record\" is used as variable name, but Prism marked it keyword"],
26+
27+
["keyword", "public"],
28+
["keyword", "static"],
29+
["keyword", "void"],
30+
["function", "main"],
31+
["punctuation", "("],
32+
["class-name", ["String"]],
33+
["punctuation", "["],
34+
["punctuation", "]"],
35+
" record",
36+
["punctuation", ")"],
37+
["punctuation", "{"],
38+
39+
["class-name", ["System"]],
40+
["punctuation", "."],
41+
"out",
42+
["punctuation", "."],
43+
["function", "println"],
44+
["punctuation", "("],
45+
"record",
46+
["punctuation", ")"],
47+
["punctuation", ";"],
48+
49+
["punctuation", "}"],
50+
51+
["comment", "// \"record\" is used as method name, but Prism marked it keyword"],
52+
53+
["keyword", "public"],
54+
["keyword", "void"],
55+
["function", "record"],
56+
["punctuation", "("],
57+
["class-name", ["String"]],
58+
" aaa",
59+
["punctuation", ")"],
60+
["punctuation", "{"],
61+
62+
["punctuation", "}"],
63+
64+
["comment", "// \"record\" is keyword since java 14"],
65+
66+
["keyword", "public"],
67+
["keyword", "static"],
68+
["keyword", "record"],
69+
["class-name", ["A"]],
70+
["punctuation", "("],
71+
["punctuation", ")"],
72+
["punctuation", "{"],
73+
74+
["punctuation", "}"],
75+
76+
["comment", "// it cannot be used as class name in java syntax"],
77+
78+
["keyword", "public"],
79+
["keyword", "static"],
80+
["keyword", "class"],
81+
" record ",
82+
["punctuation", "{"],
83+
84+
["punctuation", "}"],
85+
86+
["punctuation", "}"]
87+
]

0 commit comments

Comments
 (0)
Please sign in to comment.