aboutsummaryrefslogtreecommitdiffstats
path: root/queries/java
diff options
context:
space:
mode:
Diffstat (limited to 'queries/java')
-rw-r--r--queries/java/highlights.scm98
-rw-r--r--queries/java/indents.scm8
-rw-r--r--queries/java/injections.scm16
-rw-r--r--queries/java/locals.scm54
4 files changed, 107 insertions, 69 deletions
diff --git a/queries/java/highlights.scm b/queries/java/highlights.scm
index 4ff56641d..ee36bf0bf 100644
--- a/queries/java/highlights.scm
+++ b/queries/java/highlights.scm
@@ -1,20 +1,17 @@
; CREDITS @maxbrunsfeld (maxbrunsfeld@gmail.com)
-
; Variables
-
(identifier) @variable
; Methods
-
(method_declaration
name: (identifier) @function.method)
+
(method_invocation
name: (identifier) @function.method.call)
(super) @function.builtin
; Parameters
-
(formal_parameter
name: (identifier) @variable.parameter)
@@ -22,18 +19,17 @@
name: (identifier) @variable.parameter)
(spread_parameter
- (variable_declarator
- name: (identifier) @variable.parameter)) ; int... foo
+ (variable_declarator
+ name: (identifier) @variable.parameter)) ; int... foo
-;; Lambda parameter
-
-(inferred_parameters (identifier) @variable.parameter) ; (x,y) -> ...
+; Lambda parameter
+(inferred_parameters
+ (identifier) @variable.parameter) ; (x,y) -> ...
(lambda_expression
- parameters: (identifier) @variable.parameter) ; x -> ...
+ parameters: (identifier) @variable.parameter) ; x -> ...
; Operators
-
[
"+"
":"
@@ -73,41 +69,51 @@
] @operator
; Types
-
(interface_declaration
name: (identifier) @type)
+
(annotation_type_declaration
name: (identifier) @type)
+
(class_declaration
name: (identifier) @type)
+
(record_declaration
name: (identifier) @type)
+
(enum_declaration
name: (identifier) @type)
+
(constructor_declaration
name: (identifier) @type)
+
(type_identifier) @type
+
((type_identifier) @type.builtin
(#eq? @type.builtin "var"))
+
((method_invocation
object: (identifier) @type)
- (#lua-match? @type "^[A-Z]"))
+ (#lua-match? @type "^[A-Z]"))
+
((method_reference
- . (identifier) @type)
- (#lua-match? @type "^[A-Z]"))
+ .
+ (identifier) @type)
+ (#lua-match? @type "^[A-Z]"))
((field_access
object: (identifier) @type)
(#lua-match? @type "^[A-Z]"))
+
(scoped_identifier
(identifier) @type
(#lua-match? @type "^[A-Z]"))
; Fields
-
(field_declaration
- declarator: (variable_declarator
- name: (identifier) @variable.member))
+ declarator:
+ (variable_declarator
+ name: (identifier) @variable.member))
(field_access
field: (identifier) @variable.member)
@@ -120,23 +126,21 @@
] @type.builtin
; Variables
-
((identifier) @constant
(#lua-match? @constant "^[A-Z_][A-Z%d_]+$"))
(this) @variable.builtin
; Annotations
-
(annotation
"@" @attribute
name: (identifier) @attribute)
+
(marker_annotation
"@" @attribute
name: (identifier) @attribute)
; Literals
-
(string_literal) @string
(escape_sequence) @string.escape
@@ -163,7 +167,6 @@
(null_literal) @constant.builtin
; Keywords
-
[
"assert"
"class"
@@ -211,12 +214,9 @@
"yield"
] @keyword.return
-[
- "new"
-] @keyword.operator
+"new" @keyword.operator
; Conditionals
-
[
"if"
"else"
@@ -224,10 +224,13 @@
"case"
] @keyword.conditional
-(ternary_expression ["?" ":"] @keyword.conditional.ternary)
+(ternary_expression
+ [
+ "?"
+ ":"
+ ] @keyword.conditional.ternary)
; Loops
-
[
"for"
"while"
@@ -237,7 +240,6 @@
] @keyword.repeat
; Includes
-
[
"exports"
"import"
@@ -250,7 +252,6 @@
] @keyword.import
; Punctuation
-
[
";"
"."
@@ -258,19 +259,40 @@
","
] @punctuation.delimiter
-[ "{" "}" ] @punctuation.bracket
+[
+ "{"
+ "}"
+] @punctuation.bracket
-[ "[" "]" ] @punctuation.bracket
+[
+ "["
+ "]"
+] @punctuation.bracket
-[ "(" ")" ] @punctuation.bracket
+[
+ "("
+ ")"
+] @punctuation.bracket
-(type_arguments [ "<" ">" ] @punctuation.bracket)
-(type_parameters [ "<" ">" ] @punctuation.bracket)
+(type_arguments
+ [
+ "<"
+ ">"
+ ] @punctuation.bracket)
-(string_interpolation [ "\\{" "}" ] @punctuation.special)
+(type_parameters
+ [
+ "<"
+ ">"
+ ] @punctuation.bracket)
-; Exceptions
+(string_interpolation
+ [
+ "\\{"
+ "}"
+ ] @punctuation.special)
+; Exceptions
[
"throw"
"throws"
@@ -280,12 +302,10 @@
] @keyword.exception
; Labels
-
(labeled_statement
(identifier) @label)
; Comments
-
[
(line_comment)
(block_comment)
diff --git a/queries/java/indents.scm b/queries/java/indents.scm
index 8ce928eb8..9e4d0a5e1 100644
--- a/queries/java/indents.scm
+++ b/queries/java/indents.scm
@@ -15,7 +15,8 @@
(element_value_array_initializer) ; { a, b } inside @Annotation()
] @indent.begin
-(expression_statement (method_invocation) @indent.begin)
+(expression_statement
+ (method_invocation) @indent.begin)
[
"("
@@ -26,7 +27,9 @@
"]"
] @indent.branch
-(annotation_argument_list ")" @indent.end) ; This should be a special cased as `()` here doesn't have ending `;`
+(annotation_argument_list
+ ")" @indent.end) ; This should be a special cased as `()` here doesn't have ending `;`
+
"}" @indent.end
(line_comment) @indent.ignore
@@ -35,4 +38,3 @@
(ERROR)
(block_comment)
] @indent.auto
-
diff --git a/queries/java/injections.scm b/queries/java/injections.scm
index 8696c16ff..59e1be02b 100644
--- a/queries/java/injections.scm
+++ b/queries/java/injections.scm
@@ -1,8 +1,8 @@
([
(block_comment)
(line_comment)
- ] @injection.content
- (#set! injection.language "comment"))
+] @injection.content
+ (#set! injection.language "comment"))
((block_comment) @injection.content
(#lua-match? @injection.content "/[*][!<*][^a-zA-Z]")
@@ -10,7 +10,11 @@
((method_invocation
name: (identifier) @_method
- arguments: (argument_list
- . (string_literal . (_) @injection.content)))
- (#any-of? @_method "format" "printf")
- (#set! injection.language "printf"))
+ arguments:
+ (argument_list
+ .
+ (string_literal
+ .
+ (_) @injection.content)))
+ (#any-of? @_method "format" "printf")
+ (#set! injection.language "printf"))
diff --git a/queries/java/locals.scm b/queries/java/locals.scm
index 5de5f5ff5..ac0715c93 100644
--- a/queries/java/locals.scm
+++ b/queries/java/locals.scm
@@ -1,56 +1,62 @@
-;; SCOPES
-
+; SCOPES
; declarations
-
(program) @local.scope
+
(class_declaration
body: (_) @local.scope)
+
(record_declaration
body: (_) @local.scope)
+
(enum_declaration
body: (_) @local.scope)
+
(lambda_expression) @local.scope
+
(enhanced_for_statement) @local.scope
; block
-
(block) @local.scope
; if/else
-
(if_statement) @local.scope ; if+else
+
(if_statement
consequence: (_) @local.scope) ; if body in case there are no braces
+
(if_statement
alternative: (_) @local.scope) ; else body in case there are no braces
; try/catch
-
(try_statement) @local.scope ; covers try+catch, individual try and catch are covered by (block)
+
(catch_clause) @local.scope ; needed because `Exception` variable
; loops
-
(for_statement) @local.scope ; whole for_statement because loop iterator variable
-(for_statement ; "for" body in case there are no braces
+
+(for_statement
+ ; "for" body in case there are no braces
body: (_) @local.scope)
+
(do_statement
body: (_) @local.scope)
+
(while_statement
body: (_) @local.scope)
; Functions
-
(constructor_declaration) @local.scope
-(method_declaration) @local.scope
-;; DEFINITIONS
+(method_declaration) @local.scope
+; DEFINITIONS
(package_declaration
(identifier) @local.definition.namespace)
(class_declaration
name: (identifier) @local.definition.type)
+
(record_declaration
name: (identifier) @local.definition.type)
@@ -61,30 +67,36 @@
name: (identifier) @local.definition.method)
(local_variable_declaration
- declarator: (variable_declarator
- name: (identifier) @local.definition.var))
-(enhanced_for_statement ; for (var item : items) {
+ declarator:
+ (variable_declarator
+ name: (identifier) @local.definition.var))
+
+(enhanced_for_statement
+ ; for (var item : items) {
name: (identifier) @local.definition.var)
(formal_parameter
name: (identifier) @local.definition.parameter)
+
(catch_formal_parameter
name: (identifier) @local.definition.parameter)
-(inferred_parameters (identifier) @local.definition.parameter) ; (x,y) -> ...
+(inferred_parameters
+ (identifier) @local.definition.parameter) ; (x,y) -> ...
+
(lambda_expression
- parameters: (identifier) @local.definition.parameter) ; x -> ...
+ parameters: (identifier) @local.definition.parameter) ; x -> ...
((scoped_identifier
(identifier) @local.definition.import)
- (#has-ancestor? @local.definition.import import_declaration))
+ (#has-ancestor? @local.definition.import import_declaration))
(field_declaration
- declarator: (variable_declarator
- name: (identifier) @local.definition.field))
-
-;; REFERENCES
+ declarator:
+ (variable_declarator
+ name: (identifier) @local.definition.field))
+; REFERENCES
(identifier) @local.reference
(type_identifier) @local.reference