Skip to content

Commit

Permalink
Java: Added support for constants (#3507)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 authored Jul 29, 2022
1 parent 05ee042 commit 342a003
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 6 deletions.
3 changes: 2 additions & 1 deletion components/prism-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
'operator': {
pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
lookbehind: true
}
},
'constant': /\b[A-Z][A-Z_\d]+\b/
});

Prism.languages.insertBefore('java', 'string', {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-java.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/prism-scala.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ Prism.languages.insertBefore('scala', 'triple-quoted-string', {

delete Prism.languages.scala['class-name'];
delete Prism.languages.scala['function'];
delete Prism.languages.scala['constant'];
2 changes: 1 addition & 1 deletion components/prism-scala.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/languages/java/annotation_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
["punctuation", "("],
"value",
["operator", "="],
"SOURCE",
["constant", "SOURCE"],
["punctuation", ")"],

["annotation", "@Target"],
["punctuation", "("],
"value",
["operator", "="],
["punctuation", "{"],
"PACKAGE",
["constant", "PACKAGE"],
["punctuation", ","],
"TYPE",
["constant", "TYPE"],
["punctuation", "}"],
["punctuation", ")"]
]
61 changes: 61 additions & 0 deletions tests/languages/java/constant_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
public class Test {
private static final String AAAA = "aaaaaa";

private String str = "1";

public static void main(String[] args) {
str += AAAA + "AAAA";
}
}

----------------------------------------------------

[
["keyword", "public"],
["keyword", "class"],
["class-name", ["Test"]],
["punctuation", "{"],

["keyword", "private"],
["keyword", "static"],
["keyword", "final"],
["class-name", ["String"]],
["constant", "AAAA"],
["operator", "="],
["string", "\"aaaaaa\""],
["punctuation", ";"],

["keyword", "private"],
["class-name", ["String"]],
" str ",
["operator", "="],
["string", "\"1\""],
["punctuation", ";"],

["keyword", "public"],
["keyword", "static"],
["keyword", "void"],
["function", "main"],
["punctuation", "("],
["class-name", ["String"]],
["punctuation", "["],
["punctuation", "]"],
" args",
["punctuation", ")"],
["punctuation", "{"],

"\r\n str ",
["operator", "+="],
["constant", "AAAA"],
["operator", "+"],
["string", "\"AAAA\""],
["punctuation", ";"],

["punctuation", "}"],

["punctuation", "}"]
]

----------------------------------------------------

Checks for all constants.

0 comments on commit 342a003

Please sign in to comment.