Skip to content

Commit e061681

Browse files
author
Joshua Wood
committed
Add correct grammar hierarchy for better customization
Add support for punctuation and lambdas
1 parent f54d71c commit e061681

File tree

1 file changed

+49
-24
lines changed

1 file changed

+49
-24
lines changed

queries/java/highlights.scm

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
; Methods
22

3-
(method_declaration
4-
name: (identifier) @function.method)
5-
(method_invocation
6-
name: (identifier) @function.method)
3+
(package_declaration (scoped_identifier (identifier) @constant))
4+
5+
((identifier) @constant (.match? @constant "^[A-Z_][A-Z_\\d]*$"))
6+
(scoped_identifier (identifier) @type (.match? @type "^[A-Z]") )
7+
(scoped_identifier (scoped_identifier) @constant)
8+
(scoped_identifier (identifier) @property)
9+
10+
(field_access ( identifier ) @type (.match? @type "^[A-Z]"))
11+
(field_access ( identifier ) @property)
12+
13+
(formal_parameter (identifier) @variable.parameter)
14+
(method_declaration name: (identifier) @function.method)
715
(super) @function.builtin
816

917
; Annotations
1018

11-
(annotation
12-
name: (identifier) @attribute)
13-
(marker_annotation
14-
name: (identifier) @attribute)
19+
(annotation (identifier) @constructor)
20+
(marker_annotation (identifier) @constructor)
21+
22+
"@" @constant
1523

16-
"@" @operator
24+
(annotation_argument_list (element_value_pair (identifier) @variable.parameter))
1725

1826
; Types
1927

20-
(interface_declaration
21-
name: (identifier) @type)
22-
(class_declaration
23-
name: (identifier) @type)
24-
(enum_declaration
25-
name: (identifier) @type)
28+
(interface_declaration (identifier) @type)
29+
(class_declaration (identifier) @type)
30+
(enum_declaration (identifier) @type)
2631

27-
((scoped_identifier
28-
scope: (identifier) @type)
29-
(.match? @type "^[A-Z]"))
3032

31-
(constructor_declaration
32-
name: (identifier) @type)
33+
(constructor_declaration (identifier) @constructor)
3334

3435
(type_identifier) @type
36+
(variable_declarator (identifier) @constant)
3537
(boolean_type) @type.builtin
3638
(integral_type) @type.builtin
3739
(floating_point_type) @type.builtin
3840
(void_type) @type.builtin
3941

4042
; Variables
4143

42-
((identifier) @constant
43-
(.match? @constant "^[A-Z_][A-Z_\\d]*$"))
4444

4545
(this) @variable.builtin
4646

@@ -53,8 +53,8 @@
5353
(hex_floating_point_literal) @number
5454
(character_literal) @string
5555
(string_literal) @string
56-
(true) @constant.builtin
57-
(false) @constant.builtin
56+
(true) @constant
57+
(false) @constant
5858
(null_literal) @constant.builtin
5959

6060
(line_comment) @comment
@@ -109,3 +109,28 @@
109109
"volatile" @keyword
110110
"while" @keyword
111111
"with" @keyword
112+
"=" @operator
113+
"==" @operator
114+
"!" @operator
115+
"->" @operator
116+
"?" @operator
117+
":" @operator
118+
"::" @operator
119+
"&&" @operator
120+
121+
[
122+
"("
123+
")"
124+
"{"
125+
"}"
126+
"["
127+
"]"
128+
] @punctuation.bracket
129+
130+
(lambda_expression (identifier) @variable.parameter)
131+
(((method_invocation (identifier) @type)) . (.match? @type "^[A-Z]"))
132+
(method_invocation ( argument_list ( identifier ) @constant))
133+
134+
(method_invocation name: (identifier) @function.call)
135+
136+
((identifier) @constant (.match? @constant "^[A-Z_][A-Z_\\d]*$"))

0 commit comments

Comments
 (0)