Skip to content

Commit

Permalink
Java: Add support for generics. Fix #1351
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Mar 26, 2018
1 parent 094d546 commit a5cf302
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
11 changes: 11 additions & 0 deletions components/prism-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ Prism.languages.insertBefore('java','function', {
lookbehind: true
}
});

Prism.languages.insertBefore('java', 'class-name', {
'generics': {
pattern: /<\s*\w+(?:\.\w+)?(?:\s*,\s*\w+(?:\.\w+)?)*>/i,
alias: 'function',
inside: {
keyword: Prism.languages.java.keyword,
punctuation: /[<>(),.:]/
}
}
});
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.

65 changes: 65 additions & 0 deletions tests/languages/java/generics_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
public class Solo<T> {}
Solo<Integer> val = new Solo<Integer>();
Duo<Double, Character> dual = new Duo<Double, Character>(12.2585, 'C');

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

[
["keyword", "public"],
["keyword", "class"],
["class-name", ["Solo"]],
["generics", [
["punctuation", "<"],
"T",
["punctuation", ">"]
]],
["punctuation", "{"],
["punctuation", "}"],
"\r\nSolo",
["generics", [
["punctuation", "<"],
"Integer",
["punctuation", ">"]
]],
" val ",
["operator", "="],
["keyword", "new"],
["class-name", ["Solo"]],
["generics", [
["punctuation", "<"],
"Integer",
["punctuation", ">"]
]],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
"\r\nDuo",
["generics", [
["punctuation", "<"],
"Double",
["punctuation", ","],
" Character",
["punctuation", ">"]
]],
" dual ",
["operator", "="],
["keyword", "new"],
["class-name", ["Duo"]],
["generics", [
["punctuation", "<"],
"Double",
["punctuation", ","],
" Character",
["punctuation", ">"]
]],
["punctuation", "("],
["number", "12.2585"],
["punctuation", ","],
["string", "'C'"],
["punctuation", ")"],
["punctuation", ";"]
]

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

Checks for generics.
27 changes: 27 additions & 0 deletions tests/languages/java/issue1351.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class AllChangesIndexer extends SiteIndexer<Change.Id, ChangeData, ChangeIndex> {

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

[
["keyword", "public"],
["keyword", "class"],
["class-name", ["AllChangesIndexer"]],
["keyword", "extends"],
["class-name", ["SiteIndexer"]],
["generics", [
["punctuation", "<"],
"Change",
["punctuation", "."],
"Id",
["punctuation", ","],
" ChangeData",
["punctuation", ","],
" ChangeIndex",
["punctuation", ">"]
]],
["punctuation", "{"]
]

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

Checks for generics.

0 comments on commit a5cf302

Please sign in to comment.