%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: java-new
file_extensions:
- java
- bsh
scope: source.java
variables:
primitives: (?:boolean|byte|char|short|int|float|long|double|var)
storage_modifiers: (?:public|private|protected|static|final|native|synchronized|strictfp|abstract|transient|default|volatile)
id: (?:[\p{L}_$][\p{L}\p{N}_$]*)
classcase_id: (?:\p{Lu}[\p{L}\p{N}_$]*)
lowercase_id: (?:[_$]*\p{Ll}[\p{Ll}\p{N}_$]*\b)
uppercase_id: (?:[_$]*\p{Lu}[\p{Lu}\p{N}_$]*\b)
# One dot is mandatory to not compete with other regexes that match an id.
before_fqn: (?={{lowercase_id}}\s*\.)
# utility lookaround
lambda_lookahead: (?:\(.*\)|{{id}})\s*->
# digits
ddigits0: '\d[\d_]*?(_*)'
ddigits: (?:(_*){{ddigits0}})
hdigits: (?:(_*)\h[\h_]*?(_*))
exponent: '[-+]?{{ddigits}}'
eexponent: (?:[eE]{{exponent}})
pexponent: (?:[pP]{{exponent}})
contexts:
prototype:
- match: (?=%>)
pop: true
- include: comments
- include: illegal-keywords
any_POP:
- match: (?=\S)
pop: true
immediate_POP:
- match: ''
pop: true
main:
- include: prototype
- include: package-statement
- include: import-statement
- include: module
- include: class
- include: annotations
# Get modifiers defined on a different line than the class
- include: storage-modifiers
- include: stray-braces
- include: code
punctuation-accessor-dot:
- match: \.
scope: punctuation.accessor.dot.java
punctuation-separator-comma:
- match: \,
scope: punctuation.separator.comma.java
punctuation-terminator-semicolon:
- match: ;
scope: punctuation.terminator.java
dot-separated-identifier:
- match: '{{id}}'
- include: punctuation-accessor-dot
- include: immediate_POP
package-statement:
- match: \bpackage\b
scope: keyword.other.package.java
push:
- - meta_scope: meta.package-declaration.java
- include: immediate_POP
- - match: '{{id}}'
set:
- meta_scope: meta.path.java entity.name.namespace.java
- include: dot-separated-identifier
- include: any_POP
import-statement:
- match: \bimport\b
scope: keyword.control.import.java
push:
- - meta_scope: meta.import.java
- include: immediate_POP
- import-statement-body
import-statement-body:
- match: \bstatic\b
scope: keyword.control.import.static.java
set: static-import-statement-body
- include: before-next-import
- match: '{{lowercase_id}}'
scope: meta.path.java support.type.package.java
set:
- meta_content_scope: meta.path.java
- include: before-next-import
- include: package
- match: \*
scope: meta.path.java keyword.operator.wildcard.asterisk.java
pop: true
- match: '{{classcase_id}}'
scope: support.class.import.java
set:
- include: before-next-import
- include: punctuation-accessor-dot
- include: import-class
- include: import-wildcard
- include: any_POP
- include: any_POP
- include: any_POP
static-import-statement-body:
- include: before-next-import
- match: '{{lowercase_id}}'
scope: meta.path.java support.type.package.java
set:
- meta_content_scope: meta.path.java
- include: before-next-import
- include: package
- match: '{{classcase_id}}'
scope: support.class.import.java
set:
- include: before-next-import
- include: punctuation-accessor-dot
- include: import-constant
- include: import-class
- include: import-function
- include: import-wildcard
- include: any_POP
- include: any_POP
- include: any_POP
before-next-import:
# Prevent next import statement to be consumed when a current statement isn't terminated with ';'.
- match: (?=\bimport\b)
pop: true
# For a case of a statement immediately before a class definition.
- match: (?=\b(?:{{storage_modifiers}}|class|interface|enum)\b)
pop: true
package:
- match: '{{lowercase_id}}'
scope: support.type.package.java
- include: punctuation-accessor-dot
all-types:
- include: primitive-types
- include: object-types
import-constant:
- match: '{{uppercase_id}}'
scope: constant.other.import.java
import-class:
- match: '{{classcase_id}}'
scope: support.class.import.java
import-function:
- match: '{{id}}'
scope: support.function.import.java
import-wildcard:
- match: \*
scope: keyword.operator.wildcard.asterisk.java
annotations:
- match: \@
scope: punctuation.definition.annotation.java
push:
- - meta_scope: meta.annotation.java
- include: immediate_POP
- annotation-parameters
- - meta_content_scope: meta.annotation.identifier.java
- include: immediate_POP
- annotation-type-reference
annotation-type-reference:
- match: '{{before_fqn}}'
set:
- meta_scope: meta.path.java
- match: '{{lowercase_id}}'
scope: variable.annotation.package.java
- include: punctuation-accessor-dot
- include: annotation-type-no-fqn
- include: annotation-type-no-fqn
annotation-type-no-fqn:
- match: '{{classcase_id}}'
scope: variable.annotation.java
set: after-annotation-type-reference
- include: any_POP
after-annotation-type-reference:
- match: \.
scope: punctuation.accessor.dot.java
set: annotation-type-no-fqn
- include: any_POP
annotation-parameters:
- match: \(
scope: punctuation.section.parens.begin.java
set:
- meta_scope: meta.annotation.parameters.java
- match: \)
scope: punctuation.section.parens.end.java
pop: true
- match: ({{id}})\s*(=)
captures:
1: variable.parameter.java
2: keyword.operator.assignment.java
push:
- match: (?=[,})])
pop: true
- include: annotations
- include: code
- include: annotation-array-initialization
- include: annotations
- include: code
- include: any_POP
annotation-array-initialization:
- match: \{
scope: punctuation.section.braces.begin.java
push:
- meta_scope: meta.braces.annotation-array-initialization.java
- include: array-initialization-common
- include: annotations
anonymous-classes-and-new:
- match: \bnew\b
scope: keyword.other.storage.new.java
push:
- - meta_scope: meta.instantiation.java
- include: immediate_POP
- instantiation
instantiation:
- match: \b{{primitives}}\b
scope: storage.type.primitive.java
set: array-definition
- match: '{{before_fqn}}'
set: [after-object-type-in-instantiation, object-type-fqn]
- include: object-type-instantiation-no-fqn
object-type-instantiation-no-fqn:
- match: '{{classcase_id}}'
scope: support.class.java
set: after-object-type-in-instantiation
- include: any_POP
after-object-type-in-instantiation:
- match: (?=\[)
set: array-definition
- match: (?=\()
set: object-construction
- match: <>
scope: punctuation.definition.generic.diamond.java
set: object-construction
- match: (?=<)
set: [after-generic-in-instantiation, generic-type-invocation]
- match: \.
scope: punctuation.accessor.dot.java
set: object-type-instantiation-no-fqn
- include: any_POP
after-generic-in-instantiation:
- match: (?=\[)
set: array-definition
- include: object-construction
object-construction:
- match: \(
scope: punctuation.section.parens.begin.java
set:
- meta_scope: meta.parens.constructor-arguments.java
- match: \)
scope: punctuation.section.parens.end.java
set:
- match: \{
scope: punctuation.section.braces.begin.java
set:
- meta_scope: meta.class.body.anonymous.java
- match: \}
scope: punctuation.section.braces.end.java
pop: true
- include: class-body
- include: any_POP
- include: illegal-parens-terminators
- include: code
- include: any_POP
array-definition:
- match: \[
scope: punctuation.section.brackets.begin.java
set:
- meta_scope: meta.brackets.array-initialization.java
- match: \]
scope: punctuation.section.brackets.end.java
set:
- match: (?=\[)
set: array-definition
- match: \{
scope: punctuation.section.braces.begin.java
set: array-initialization
- include: any_POP
- include: code
- include: any_POP
array-initialization:
- meta_scope: meta.braces.array-initialization.java
- include: array-initialization-common
array-initialization-common:
- match: \}
scope: punctuation.section.braces.end.java
pop: true
- match: \{
scope: punctuation.section.braces.begin.java
push: array-initialization
- include: code
class:
- match: (?=({{storage_modifiers}}\s+)*(?:class|(?:@)?interface|enum)\b)
push: [class-meta, class-type]
class-meta:
- meta_scope: meta.class.java
- include: immediate_POP
class-type:
- include: storage-modifiers
- match: (?:class|(\@?)interface)\b
scope: storage.type.java
captures:
1: punctuation.definition.type.java
set:
- class-block
- class-extends
- generic-type-declaration
- class-name
- match: enum\b
scope: storage.type.java
set:
- enum-block
- class-extends
- generic-type-declaration
- class-name
- include: any_POP
class-name:
- meta_scope: meta.class.identifier.java
- match: (?!extends|implements){{id}}\b
scope: entity.name.class.java
pop: true
- include: any_POP
class-extends:
- match: extends\b
scope: keyword.declaration.extends.java
push:
- - meta_scope: meta.class.extends.java
- match: \,
scope: punctuation.separator.comma.java
push: inherited-object-type-reference
- include: any_POP
- inherited-object-type-reference
- match: implements\b
scope: keyword.declaration.implements.java
push:
- - meta_scope: meta.class.implements.java
- match: \,
scope: punctuation.separator.comma.java
push: inherited-object-type-reference
- include: any_POP
- inherited-object-type-reference
- include: any_POP
class-block:
- match: \{
scope: punctuation.section.block.begin.java
set:
- meta_scope: meta.class.body.java meta.block.java
- match: \}
scope: punctuation.section.block.end.java
pop: true
- include: class-body
- include: any_POP
class-body:
- include: class
- include: annotations
- include: fields-and-methods
- include: constants-and-special-vars
- include: storage-modifiers
- include: all-types
- include: static-code-block
- include: punctuation-separator-comma
- include: punctuation-terminator-semicolon
- match: (?=<)
push: generic-type-declaration
enum-block:
- match: \{
scope: punctuation.section.block.begin.java
set:
- meta_scope: meta.class.body.java meta.block.java
- match: \}
scope: punctuation.section.block.end.java
pop: true
- include: enum-body
- include: any_POP
enum-body:
- match: ^(?=\s*([[:upper:]_][[:upper:][:digit:]_]*|(?!{{primitives}}|{{storage_modifiers}})[[:lower:]_][[:alnum:]_]*)\s*[,;{(])
push:
- match: (?=[;}])
pop: true
- match: \w+
scope: constant.other.enum.java
push:
- meta_scope: meta.enum.java
- match: \{
scope: punctuation.section.block.begin.java
push:
- meta_scope: meta.enum.body.java meta.block.java
- match: \}
scope: punctuation.section.block.end.java
pop: true
- include: enum-body
- include: parens
- include: any_POP
- include: punctuation-separator-comma
- include: class-body
code:
- include: constants-and-special-vars
- include: assignment
- include: lambdas
- include: strings
- include: anonymous-classes-and-new
- include: keywords-control
- include: method-invocations
- include: uppercase-identifiers
- include: all-types
- include: keywords
- include: code-block-include
- include: parens
code-block-include:
- match: \{
scope: punctuation.section.block.begin.java
push:
- meta_scope: meta.block.java
- match: \}
scope: punctuation.section.block.end.java
pop: true
- include: code-block
code-block:
- include: storage-modifiers
- include: var-type
- include: code
- include: annotations
- include: code-block-include
- include: stray-parens
comments:
- match: /\*\*/
scope: comment.block.empty.java punctuation.definition.comment.java
- include: scope:text.html.javadoc
- include: comments-inline
comments-inline:
- match: /\*
scope: punctuation.definition.comment.java
push:
- meta_scope: comment.block.java
- match: \*/
scope: punctuation.definition.comment.java
pop: true
- match: //
scope: punctuation.definition.comment.java
push:
- meta_scope: comment.line.double-slash.java
- match: \n
pop: true
- match: (?=%>)
pop: true
constants-and-special-vars:
- match: \b(true|false|null)\b
scope: constant.language.java
- match: \b(this|super)\b
scope: variable.language.java
# hexadecimal floats
- match: |-
\b(0[xX])(?x:
# 0x1., 0x1.1, 0x1.1p1, 0x1.1p-1, 0x1.p1, 0x1.p-1 | 0x1p1
{{hdigits}} (?: (\.) (?: {{hdigits}}? {{pexponent}}? \b )? | {{pexponent}} \b )
# 0x.1, 0x.1p1, 0x.1p-1
| (\.) {{hdigits}} {{pexponent}}? \b
)
scope: constant.numeric.float.hexadecimal.java
captures:
1: punctuation.definition.numeric.hexadecimal.java
2: invalid.illegal.numeric.java
3: invalid.illegal.numeric.java
4: punctuation.separator.decimal.java
5: invalid.illegal.numeric.java
6: invalid.illegal.numeric.java
7: invalid.illegal.numeric.java
8: invalid.illegal.numeric.java
9: invalid.illegal.numeric.java
10: invalid.illegal.numeric.java
11: punctuation.separator.decimal.java
12: invalid.illegal.numeric.java
13: invalid.illegal.numeric.java
14: invalid.illegal.numeric.java
15: invalid.illegal.numeric.java
# decimal floats
- match: |-
(?x:
\b{{ddigits0}}
(?:
# 1., 1.1, 1.1e1, 1.1e-1, 1.e1, 1.e-1, 1.d, 1.1d, 1.1e1d, 1.1e-1d, 1.e1d, 1.e-1d
(\.) (?: {{ddigits}}? {{eexponent}}? ([dDfF])? \b )?
# 1e1 1e1d
| {{eexponent}} ([dDfF])? \b
# 1d
| ([dDfF]) \b
)
# .1, .1e1, .1e-1
| (\.) {{ddigits}} {{eexponent}}? ([dDfF])? \b
)
scope: constant.numeric.float.decimal.java
captures:
1: invalid.illegal.numeric.java
2: punctuation.separator.decimal.java
3: invalid.illegal.numeric.java
4: invalid.illegal.numeric.java
5: invalid.illegal.numeric.java
6: invalid.illegal.numeric.java
7: storage.type.numeric.java
8: invalid.illegal.numeric.java
9: invalid.illegal.numeric.java
10: storage.type.numeric.java
11: storage.type.numeric.java
12: punctuation.separator.decimal.java
13: invalid.illegal.numeric.java
14: invalid.illegal.numeric.java
15: invalid.illegal.numeric.java
16: invalid.illegal.numeric.java
17: storage.type.numeric.java
# binary integers
- match: \b(0[bB])(_*)[01][01_]*?(_*)([lL])?\b
scope: constant.numeric.integer.binary.java
captures:
1: punctuation.definition.numeric.binary.java
2: invalid.illegal.numeric.java
3: invalid.illegal.numeric.java
4: storage.type.numeric.java
# hexadecimal integers
- match: \b(0[xX]){{hdigits}}([lL])?\b
scope: constant.numeric.integer.hexadecimal.java
captures:
1: punctuation.definition.numeric.hexadecimal.java
2: invalid.illegal.numeric.java
3: invalid.illegal.numeric.java
4: storage.type.numeric.java
# octal integers
- match: \b(0)(?:(_+)|[0-7_]+?(_*)|([\d_]+))([lL])?\b
scope: constant.numeric.integer.octal.java
captures:
1: punctuation.definition.numeric.octal.java
2: invalid.illegal.numeric.java
3: invalid.illegal.numeric.java
4: invalid.illegal.numeric.java
5: storage.type.numeric.java
# decimal integers
- match: \b{{ddigits0}}([lL])?\b
scope: constant.numeric.integer.decimal.java
captures:
1: invalid.illegal.numeric.java
2: storage.type.numeric.java
keywords:
- match: '::'
scope: punctuation.accessor.double-colon.java
push:
- match: '{{id}}'
scope: variable.function.reference.java
pop: true
- include: any_POP
- match: '\?|:'
scope: keyword.operator.ternary.java
- match: \binstanceof\b
scope: keyword.operator.word.instanceof.java
- match: (<<|>>>?)
scope: keyword.operator.bitshift.java
- match: (==|!=|<=|>=|<>|<|>)
scope: keyword.operator.comparison.java
- match: (\-\-|\+\+)
scope: keyword.operator.increment-decrement.java
- match: (\-|\+|\*|\/|%)
scope: keyword.operator.arithmetic.java
- match: (!|&&|\|\|)
scope: keyword.operator.logical.java
- match: (~|\^|&|\|)
scope: keyword.operator.bitwise.java
- match: (\.)(class\b)?
captures:
1: punctuation.accessor.dot.java
2: variable.language.java
- include: punctuation-separator-comma
- include: punctuation-terminator-semicolon
keywords-control:
# exceptions
- match: \bcatch\b
scope: keyword.control.exception.catch.java
push:
- meta_scope: meta.catch.java
- match: (?=\()
set:
- match: \(
scope: punctuation.section.parens.begin.java
set:
- meta_scope: meta.catch.parameters.java meta.parens.java
- match: \)
scope: punctuation.section.parens.end.java
pop: true
- match: \|
scope: punctuation.separator.bar.java
- include: parameters
- include: any_POP
- match: \bfinally\b
scope: keyword.control.exception.finally.java
- match: \btry\b
scope: keyword.control.exception.try.java
push: declaration-statement-parens
# flow
- match: \bassert\b
scope: keyword.control.flow.assert.java
push:
- meta_scope: meta.assertion.java
- match: (?=;)
pop: true
- match: ':'
scope: punctuation.separator.expressions.java
- include: code
- match: \bbreak\b
scope: keyword.control.flow.break.java
- match: \bcontinue\b
scope: keyword.control.flow.continue.java
- match: \breturn\b
scope: keyword.control.flow.return.java
- match: \bthrow\b
scope: keyword.control.flow.throw.java
# conditional
- match: \bif\b
scope: keyword.control.conditional.if.java
- match: \belse\b
scope: keyword.control.conditional.else.java
- match: \bswitch\b
scope: keyword.control.conditional.switch.java
- match: \bcase\b
scope: keyword.control.conditional.case.java
- match: \bdefault\b
scope: keyword.control.conditional.default.java
# loop
- match: \bdo\b
scope: keyword.control.loop.do-while.java
- match: \bfor\b
scope: keyword.control.loop.for.java
push: declaration-statement-parens
- match: \bwhile\b
scope: keyword.control.loop.while.java
illegal-keywords:
- match: \b(goto|const)\b
scope: invalid.illegal.keyword.java
illegal-open-block:
- match: \s?(?={)
scope: invalid.illegal.stray-terminator-end
pop: true
illegal-semicolon:
- match: ;
scope: invalid.illegal.stray-terminator-end
pop: true
illegal-parens-terminators:
# Pops the stack if anything matches
- include: illegal-semicolon
- include: illegal-open-block
method-invocations:
- match: (\.)\s*(?=<)
captures:
1: punctuation.accessor.dot.java
push: generic-type-invocation
- match: ({{id}})\s*(\()
captures:
1: variable.function.java
2: punctuation.section.parens.begin.java
push:
- meta_scope: meta.function-call.java
- match: \)
scope: punctuation.section.parens.end.java
pop: true
- include: illegal-parens-terminators
- include: code
fields-and-methods:
- match: \bvoid\b
scope: storage.type.void.java
push: method
- match: (?={{id}}\s*\()
push: method
- match: '{{before_fqn}}'
push: [field-or-method, after-object-and-array-types, object-type-fqn]
- match: \b{{classcase_id}}
scope: support.class.java
push: [field-or-method, after-object-and-array-types]
- match: \b{{primitives}}\b
scope: storage.type.primitive.java
push: [field-or-method, array-brackets]
field-or-method:
- match: (?={{id}}\s*\()
set: method
- match: (?=\S)
set:
- include: before-next-field
- match: (?:({{uppercase_id}})|({{id}}))
captures:
1: entity.name.constant.java
2: meta.field.java
push: [static-assignment, array-brackets]
- include: punctuation-separator-comma
- include: any_POP
before-next-field:
# Prevent style from being removed from whole file when making a new expression
- match: (?=\b(?:{{storage_modifiers}}|{{primitives}}|void)\b)
pop: true
method:
- meta_scope: meta.method.java
- match: ({{classcase_id}})\s*(?=\()
captures:
1: meta.method.identifier.java entity.name.function.constructor.java
- match: ({{id}})\s*(?=\()
captures:
1: meta.method.identifier.java entity.name.function.java
- match: \(
scope: punctuation.section.parens.begin.java
push:
- meta_scope: meta.method.parameters.java meta.parens.java
- match: \)
scope: punctuation.section.parens.end.java
pop: true
- include: parameters
- match: \S
scope: invalid.illegal.missing-parameter-end
pop: true
- include: throws
- include: annotation-default
- match: \{
scope: punctuation.section.block.begin.java
set:
- meta_scope: meta.method.java meta.method.body.java
- match: \}
scope: punctuation.section.block.end.java
pop: true
- include: code-block
- include: any_POP
throws:
- match: \bthrows\b
scope: keyword.declaration.throws.java
push:
- - meta_scope: meta.method.throws.java
- match: \,
scope: punctuation.separator.comma.java
push: object-type-reference
- include: any_POP
- object-type-reference
# Stand-along uppercase id, either type or constant.
# Should be used only inside code blocks.
uppercase-identifiers:
# Popular JDK classes
- match: \b(?:UUID|UR[LI])\b
scope: support.class.java
push: after-object-type
# Generic type variable
- match: \b\p{Lu}\b
scope: support.class.java
push: after-object-type
# Uppercase constants
- match: \b{{uppercase_id}}
scope: constant.other.java
# Stand-alone type, maybe type of the variable or class object reference.
# Should be used only inside code blocks.
object-types:
# Here the match is more complex than 'before_fqn'.
# In code block we can't simply distinguish package from variable.
- match: (?=\b(?:{{lowercase_id}}\.)+\p{Lu})
push: [after-object-type, object-type-fqn]
- match: \b{{classcase_id}}\b
scope: support.class.java
push: after-object-type
object-type-fqn:
- meta_scope: meta.path.java
- include: package
- match: '{{classcase_id}}'
scope: support.class.java
pop: true
- include: any_POP
after-object-type:
- match: (?=<)
set: [array-brackets, generic-type-invocation]
- match: \.(?!\.)
scope: punctuation.accessor.dot.java
set:
- match: (?=<)
set: generic-type-invocation
- match: (?:(class)\b|({{uppercase_id}}))
captures:
1: variable.language.java
2: constant.other.java
pop: true
- match: '{{classcase_id}}'
scope: support.class.java
set: after-object-type
- include: any_POP
- include: array-brackets
# Used in 'throws' and generic bounds
object-type-reference:
- match: '{{before_fqn}}'
set:
- meta_scope: meta.path.java
- include: package
- include: object-type-reference-no-fqn
- include: object-type-reference-no-fqn
object-type-reference-no-fqn:
- match: '{{classcase_id}}'
scope: support.class.java
set: after-object-type-reference
- include: any_POP
after-object-type-reference:
- match: (?=<)
set: generic-type-invocation
- match: \.
scope: punctuation.accessor.dot.java
set: object-type-reference-no-fqn
- include: any_POP
# Used in method's and generic's parameters
object-and-array-types:
- match: '{{before_fqn}}'
push:
- meta_scope: meta.path.java
- include: package
- include: object-and-array-types-no-fqn
- match: \b({{primitives}})(?=\s*\[)
scope: storage.type.primitive.java
push: array-brackets
- match: \b{{classcase_id}}
scope: support.class.java
push: after-object-and-array-types
object-and-array-types-no-fqn:
- match: '{{classcase_id}}'
scope: support.class.java
set: after-object-and-array-types
- include: any_POP
after-object-and-array-types:
- match: (?=<)
set: [array-brackets, generic-type-invocation]
- match: \.(?!\.)
scope: punctuation.accessor.dot.java
set: object-and-array-types-no-fqn
- include: array-brackets
# Used in class-level 'extends' and 'implements'
inherited-object-type-reference:
- match: '{{before_fqn}}'
set:
- meta_scope: meta.path.java
- match: '{{lowercase_id}}'
scope: entity.other.inherited-class.package.java
- include: punctuation-accessor-dot
- include: inherited-object-type-reference-no-fqn
- include: inherited-object-type-reference-no-fqn
inherited-object-type-reference-no-fqn:
- match: (?!class|extends|implements|interface){{id}}
scope: entity.other.inherited-class.java
set: after-inherited-object-type-reference
- include: any_POP
after-inherited-object-type-reference:
- match: (?=<)
set: generic-type-invocation
- match: \.
scope: punctuation.accessor.dot.java
set: inherited-object-type-reference-no-fqn
- include: any_POP
generic-type-declaration:
- match: <
scope: punctuation.definition.generic.begin.java
push: generic-type-parameter
- include: any_POP
generic-type-terminator:
- include: illegal-semicolon
# These characters can't appear in a generic. If we've matched
# them then someone forgot to close it.
- match: (?=[{}()])
pop: true
- match: '>'
scope: punctuation.definition.generic.end.java
pop: true
generic-type-parameter:
- meta_scope: meta.generic.declaration.java
- match: \b{{id}}\b
scope: variable.parameter.type.java
push: generic-type-bounds
- include: generic-type-terminator
generic-type-bounds:
- match: (,)|(?=>)
captures:
1: punctuation.separator.comma.java
pop: true
- match: \bextends\b
scope: keyword.declaration.extends.java
push: [generic-type-extends-multiple-bounds, object-type-reference]
- match: \bsuper\b
scope: keyword.declaration.super.java
push: object-type-reference
generic-type-extends-multiple-bounds:
- match: '&'
scope: keyword.operator.multiple-bounds.java
set: [generic-type-extends-multiple-bounds, object-type-reference]
- include: any_POP
generic-type-invocation:
- match: <
scope: punctuation.definition.generic.begin.java
set: generic-type-argument
- include: any_POP
generic-type-argument:
- meta_scope: meta.generic.java
- match: \?
scope: keyword.operator.wildcard.java
push: generic-type-bounds
- include: generic-type-terminator
- include: object-and-array-types
- include: punctuation-separator-comma
annotation-default:
- match: \bdefault\b
scope: keyword.declaration.default.java
push:
- meta_scope: meta.annotation.default.java
- match: (?=;)
pop: true
- include: code
parameters:
- match: \bfinal\b
scope: storage.modifier.java
- include: annotations
- include: primitive-types
- include: object-and-array-types
- match: \.\.\.
scope: keyword.operator.variadic.java
- match: '{{id}}'
scope: variable.parameter.java
push: array-brackets
- include: punctuation-separator-comma
lambdas:
- match: (?={{lambda_lookahead}})
push: lambda-params
lambda-params:
- meta_scope: meta.function.anonymous.parameters.java
- match: \(
scope: punctuation.section.parens.begin.java
set:
- meta_scope: meta.function.anonymous.parameters.java
- match: \)
scope: punctuation.section.parens.end.java
set: lambda-arrow
- include: parameters
- match: '{{id}}'
scope: variable.parameter.java
set: lambda-arrow
lambda-arrow:
- match: ->
scope: storage.type.function.anonymous.java
set:
- meta_scope: meta.function.anonymous.body.java
- match: (?=[)};])
pop: true
- include: code
parens:
- match: \(
scope: punctuation.section.parens.begin.java
push:
- meta_scope: meta.parens.java
- match: \)
scope: punctuation.section.parens.end.java
pop: true
- include: illegal-parens-terminators
- include: code
declaration-statement-parens:
- match: \(
scope: punctuation.section.parens.begin.java
set:
- meta_scope: meta.parens.java
- match: \)
scope: punctuation.section.parens.end.java
pop: true
- include: illegal-open-block
- include: code-block
- include: any_POP
primitive-types:
- match: \b{{primitives}}\b
scope: storage.type.primitive.java
push: array-brackets
var-type:
- match: \bvar\b
scope: storage.type.var.java
array-brackets:
- match: \[\s*\]
scope: storage.modifier.array.java
- include: any_POP
static-assignment:
- match: \=
scope: keyword.operator.assignment.java
set:
- meta_scope: meta.assignment.rhs.java
- match: (?=[,;])
pop: true
- include: before-next-field
- include: code
- include: stray-parens
- include: any_POP
assignment:
- match: ([|&^*/+-]\=|\=(?!=))
scope: keyword.operator.assignment.java
push:
- meta_scope: meta.assignment.rhs.java
- match: (?=;|\)|\}|,)
pop: true
- include: code
static-code-block:
- match: \{
scope: punctuation.section.block.begin.java
push:
- meta_scope: meta.static.body.java
- match: \}
scope: punctuation.section.block.end.java
pop: true
- include: code-block
storage-modifiers:
- match: \b{{storage_modifiers}}\b
scope: storage.modifier.java
stray-braces:
- match: \}
scope: invalid.illegal.stray-brace-end
stray-parens:
- match: \)
scope: invalid.illegal.stray-parens-end
strings:
- match: \"
scope: punctuation.definition.string.begin.java
push:
- meta_include_prototype: false
- meta_scope: string.quoted.double.java
- match: \"
scope: punctuation.definition.string.end.java
pop: true
- include: strings-common
- match: \'
scope: punctuation.definition.string.begin.java
push:
- meta_include_prototype: false
- meta_scope: string.quoted.single.java
- match: \'
scope: punctuation.definition.string.end.java
pop: true
- include: strings-common
strings-common:
- match: \n
scope: invalid.illegal.newline.java
pop: true
- match: \\.
scope: constant.character.escape.java
module:
- match: (?=\b(?:open\s+)?module\b)
push:
- - meta_scope: meta.module.java
- include: immediate_POP
- - match: \bopen\b
scope: storage.modifier.java
- match: \bmodule\b
scope: storage.type.java
set: [module-body, module-identifier-scope, module-identifier]
module-identifier-scope:
- meta_scope: meta.module.identifier.java
- include: immediate_POP
module-identifier:
- match: '{{id}}'
set:
- - meta_scope: entity.name.module.java
- include: immediate_POP
- dot-separated-identifier
- include: any_POP
module-body:
- match: \{
scope: punctuation.section.braces.begin.java
set:
- meta_scope: meta.module.body.java
- include: module-body-content
- match: \}
scope: punctuation.section.braces.end.java
pop: true
- include: any_POP
module-body-content:
- match: \bexports\b
scope: keyword.other.module.exports.java
push: [exports-statement-scope, exports-or-opens-statement]
- match: \bopens\b
scope: keyword.other.module.opens.java
push: [opens-statement-scope, exports-or-opens-statement]
- match: \brequires\b
scope: keyword.other.module.requires.java
push: requires-statement
- match: \buses\b
scope: keyword.other.module.uses.java
push: [uses-statement-scope, object-type-reference]
- match: \bprovides\b
scope: keyword.other.module.provides.java
push: [provides-statement-scope, provides-with-statement, object-type-reference]
- include: punctuation-terminator-semicolon
# Should always come before module/package patterns
module-statement-terminator:
- match: (?=[;\}])
pop: true
- match: (?=\b(?:requires|exports|uses|provides|opens)\b)
pop: true
support-type-module:
- match: '{{id}}'
push:
- - meta_scope: support.type.module.java
- include: immediate_POP
- dot-separated-identifier
exports-statement-scope:
- meta_scope: meta.exports.java
- include: immediate_POP
opens-statement-scope:
- meta_scope: meta.opens.java
- include: immediate_POP
exports-or-opens-statement:
- match: \bto\b
scope: keyword.other.module.to.java
set:
- include: module-statement-terminator
- include: support-type-module
- include: punctuation-separator-comma
- include: module-statement-terminator
- match: '{{id}}'
push:
- - meta_scope: support.type.package.java
- include: immediate_POP
- dot-separated-identifier
requires-statement:
- meta_scope: meta.requires.java
- match: \btransitive\b
scope: keyword.other.module.transitive.java
- include: module-statement-terminator
- include: support-type-module
uses-statement-scope:
- meta_scope: meta.uses.java
- include: immediate_POP
provides-statement-scope:
- meta_scope: meta.provides.java
- include: immediate_POP
provides-with-statement:
- match: \bwith\b
scope: keyword.other.module.with.java
set:
- - match: \,
scope: punctuation.separator.comma.java
push: object-type-reference
- include: any_POP
- object-type-reference
- include: any_POP