Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Fix primitive class literals #3858

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions Java/Java.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ contexts:
- include: punctuations
- include: operators
- include: type-comparisons
- include: primitive-types
- include: primitive-maybe-class-literals
- include: var-types
- include: array-modifiers
- include: storage-modifiers
Expand Down Expand Up @@ -985,11 +985,9 @@ contexts:
field-type-modifier:
- clear_scopes: 1
- meta_scope: meta.field.type.java
- include: array-modifiers
- include: annotations
- match: (?=[{(]|{{declaration_keywords}}{{break}})
fail: class-members
- include: else-pop
- include: maybe-only-array-modifiers

field-identifier-list:
- match: ','
Expand Down Expand Up @@ -2139,7 +2137,7 @@ contexts:
- include: else-pop

type-pattern-type:
- include: primitive-maybe-array-type
- include: primitive-maybe-class-literal
- include: var-type
- match: (?={{identifier}})
set:
Expand Down Expand Up @@ -3241,20 +3239,37 @@ contexts:

###[ PRIMITIVE TYPES ]#########################################################

primitive-types:
primitive-maybe-class-literals:
- match: '{{storage_types}}{{break}}'
scope: storage.type.primitive.java
push: maybe-only-array-modifiers
push: maybe-only-class-literal

primitive-type:
primitive-maybe-class-literal:
- match: '{{storage_types}}{{break}}'
scope: storage.type.primitive.java
set: maybe-only-class-literal

maybe-only-class-literal:
# https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.8.2
- match: '{{single_dot}}'
scope: punctuation.accessor.dot.java
set: maybe-class-literal
- include: array-modifiers
- include: annotation-else-pop

maybe-class-literal:
- match: class{{break}}
scope: variable.language.class.java
pop: 1
- match: '{{id}}'
scope: invalid.illegal.unexpected-member.java
set: maybe-only-class-literal
- include: else-pop

primitive-maybe-array-type:
primitive-type:
- match: '{{storage_types}}{{break}}'
scope: storage.type.primitive.java
set: maybe-only-array-modifiers
pop: 1

var-types:
- match: var{{break}}
Expand All @@ -3272,9 +3287,8 @@ contexts:

maybe-only-array-modifiers:
- include: array-modifiers
- include: annotations
- include: illegal-members
- include: else-pop
- include: annotation-else-pop

array-modifiers:
- match: \[\s*\]
Expand Down
142 changes: 140 additions & 2 deletions Java/tests/syntax_test_java.java
Original file line number Diff line number Diff line change
Expand Up @@ -1941,12 +1941,82 @@ public enum TokenKind<T> extends MyEnum, FooBaz<? super T<TT>> implements Foo, B
// ^ punctuation.section.group.end.java
// ^ punctuation.separator.comma.java

integerToken {};
integerToken {},
// ^^^^^^^^^^^^ meta.constant.identifier.java entity.name.constant.java
// ^ meta.constant.identifier.java - constant
// ^ meta.constant.java meta.block.java punctuation.section.block.begin.java
// ^ meta.constant.java meta.block.java punctuation.section.block.end.java
// ^ punctuation.terminator.java
// ^ punctuation.separator.comma.java

BYTE (0x01, Byte.FOO, Byte.FOO, Byte[].FOO, byte.FOO, byte[].FOO) {},
// ^^^^^ meta.constant.identifier.java
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.constant.arguments.java meta.group.java
// ^^^ meta.constant.java
// ^ - meta.constant
// ^^^^ entity.name.constant.java
// ^ punctuation.section.group.begin.java
// ^^^^ meta.number.integer.hexadecimal.java
// ^ punctuation.separator.comma.java
// ^^^^ support.class.java
// ^ punctuation.accessor.dot.java
// ^^^ constant.other.java
// ^ punctuation.separator.comma.java
// ^^^^ support.class.java
// ^ punctuation.accessor.dot.java
// ^^^ constant.other.java
// ^ punctuation.separator.comma.java
// ^^^^ support.class.java
// ^^ storage.modifier.array.java
// ^ punctuation.accessor.dot.java
// ^^^ constant.other.java
// ^ punctuation.separator.comma.java
// ^^^^ storage.type.primitive.java
// ^ punctuation.accessor.dot.java
// ^^^ invalid.illegal.unexpected-member.java
// ^ punctuation.separator.comma.java
// ^^^^ storage.type.primitive.java
// ^^ storage.modifier.array.java
// ^ punctuation.accessor.dot.java
// ^^^ invalid.illegal.unexpected-member.java
// ^ punctuation.section.group.end.java
// ^ meta.block.java punctuation.section.block.begin.java
// ^ meta.block.java punctuation.section.block.end.java
// ^ punctuation.separator.comma.java

BYTE (0x01, Byte.FOO, Byte.class, Byte[].class, byte.class, byte[].class) {};
// ^^^^^ meta.constant.identifier.java
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.constant.arguments.java meta.group.java
// ^^^ meta.constant.java
// ^ - meta.constant
// ^^^^ entity.name.constant.java
// ^ punctuation.section.group.begin.java
// ^^^^ meta.number.integer.hexadecimal.java
// ^ punctuation.separator.comma.java
// ^^^^ support.class.java
// ^ punctuation.accessor.dot.java
// ^^^ constant.other.java
// ^ punctuation.separator.comma.java
// ^^^^ support.class.java
// ^ punctuation.accessor.dot.java
// ^^^^^ variable.language.class.java
// ^ punctuation.separator.comma.java
// ^^^^ support.class.java
// ^^ storage.modifier.array.java
// ^ punctuation.accessor.dot.java
// ^^^^^ variable.language.class.java
// ^ punctuation.separator.comma.java
// ^^^^ storage.type.primitive.java
// ^ punctuation.accessor.dot.java
// ^^^^^ variable.language.class.java
// ^ punctuation.separator.comma.java
// ^^^^ storage.type.primitive.java
// ^^ storage.modifier.array.java
// ^ punctuation.accessor.dot.java
// ^^^^^ variable.language.class.java
// ^ punctuation.section.group.end.java
// ^ meta.block.java punctuation.section.block.begin.java
// ^ meta.block.java punctuation.section.block.end.java
// ^ punctuation.terminator.java

int {}
// ^^^ storage.type.primitive.java
Expand Down Expand Up @@ -2623,6 +2693,22 @@ class FieldDeclarationTests {
// ^ meta.field.identifier.java
// ^ punctuation.terminator.java - meta.field

int.foo bar
//^^^^^^^^ meta.field.type.java
// ^^^ meta.field.identifier.java
//^^^ storage.type.primitive.java
// ^ invalid.illegal.unexpected-accessor.java
// ^^^ invalid.illegal.unexpected-member.java
// ^^^ variable.other.member.java

int.class foo
//^^^^^^^^^^ meta.field.type.java
// ^^^ meta.field.identifier.java
//^^^ storage.type.primitive.java
// ^ invalid.illegal.unexpected-accessor.java
// ^^^^^ invalid.illegal.unexpected-member.java
// ^^^ variable.other.member.java

int[]
//^^^^^^ - meta.field meta.field
//^^^^^^ meta.field.type.java
Expand All @@ -2643,6 +2729,24 @@ class FieldDeclarationTests {
// ^^ storage.modifier.array.java
// ^^^ variable.other.member.java

int[].foo bar
//^^^^^^^^^^ meta.field.type.java
// ^^^ meta.field.identifier.java
//^^^ storage.type.primitive.java
// ^^ storage.modifier.array.java
// ^ invalid.illegal.unexpected-accessor.java
// ^^^ invalid.illegal.unexpected-member.java
// ^^^ variable.other.member.java

int[].class foo
//^^^^^^^^^^^^ meta.field.type.java
// ^^^ meta.field.identifier.java
//^^^ storage.type.primitive.java
// ^^ storage.modifier.array.java
// ^ invalid.illegal.unexpected-accessor.java
// ^^^^^ invalid.illegal.unexpected-member.java
// ^^^ variable.other.member.java

int foo[], []
//^^^^^^^^^^^^^ - meta.field meta.field
//^^^^ meta.field.type.java
Expand Down Expand Up @@ -4637,6 +4741,22 @@ void declarePrimitiveTypes() {
// ^^^^^ constant.other.java
// ^ punctuation.terminator.java

int.foo bar
// ^^^^^^^^ meta.declaration.type.java
// ^^^ meta.declaration.identifier.java
// ^^^ storage.type.primitive.java
// ^ invalid.illegal.unexpected-accessor.java
// ^^^ invalid.illegal.unexpected-member.java
// ^^^ variable.other.java

int.class foo
// ^^^^^^^^^^ meta.declaration.type.java
// ^^^ meta.declaration.identifier.java
// ^^^ storage.type.primitive.java
// ^ invalid.illegal.unexpected-accessor.java
// ^^^^^ invalid.illegal.unexpected-member.java
// ^^^ variable.other.java

int[]
// ^^^^^^ - meta.declaration
// ^^^ storage.type.primitive.java
Expand All @@ -4654,6 +4774,24 @@ void declarePrimitiveTypes() {
// ^^ storage.modifier.array.java
// ^^^ variable.other.java

int[].foo bar
// ^^^^^^^^^^ meta.declaration.type.java
// ^^^ meta.declaration.identifier.java
// ^^^ storage.type.primitive.java
// ^^ storage.modifier.array.java
// ^ invalid.illegal.unexpected-accessor.java
// ^^^ invalid.illegal.unexpected-member.java
// ^^^ variable.other.java

int[].class foo
// ^^^^^^^^^^^^ meta.declaration.type.java
// ^^^ meta.declaration.identifier.java
// ^^^ storage.type.primitive.java
// ^^ storage.modifier.array.java
// ^ invalid.illegal.unexpected-accessor.java
// ^^^^^ invalid.illegal.unexpected-member.java
// ^^^ variable.other.java

int foo[], [] ;
// ^^^^ meta.declaration.type.java
// ^^^^^ meta.declaration.identifier.java
Expand Down