Commit a5cf3025b99cfc2d6a757c77400dea1d7cb3606b

Golmote 2018-03-26T08:53:43

Java: Add support for generics. Fix #1351

diff --git a/components/prism-java.js b/components/prism-java.js
index da3e9c6..881b306 100644
--- a/components/prism-java.js
+++ b/components/prism-java.js
@@ -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: /[<>(),.:]/
+		}
+	}
+});
diff --git a/components/prism-java.min.js b/components/prism-java.min.js
index d6c921a..e583b73 100644
--- a/components/prism-java.min.js
+++ b/components/prism-java.min.js
@@ -1 +1 @@
-Prism.languages.java=Prism.languages.extend("clike",{keyword:/\b(?:abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,number:/\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp-]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?[df]?/i,operator:{pattern:/(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,lookbehind:!0}}),Prism.languages.insertBefore("java","function",{annotation:{alias:"punctuation",pattern:/(^|[^.])@\w+/,lookbehind:!0}});
\ No newline at end of file
+Prism.languages.java=Prism.languages.extend("clike",{keyword:/\b(?:abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,number:/\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp-]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?[df]?/i,operator:{pattern:/(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,lookbehind:!0}}),Prism.languages.insertBefore("java","function",{annotation:{alias:"punctuation",pattern:/(^|[^.])@\w+/,lookbehind:!0}}),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:/[<>(),.:]/}}});
\ No newline at end of file
diff --git a/tests/languages/java/generics_feature.test b/tests/languages/java/generics_feature.test
new file mode 100644
index 0000000..66bfef5
--- /dev/null
+++ b/tests/languages/java/generics_feature.test
@@ -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.
\ No newline at end of file
diff --git a/tests/languages/java/issue1351.test b/tests/languages/java/issue1351.test
new file mode 100644
index 0000000..2f95e6b
--- /dev/null
+++ b/tests/languages/java/issue1351.test
@@ -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.
\ No newline at end of file