Skip to content

Commit

Permalink
[Java] Fix class literals
Browse files Browse the repository at this point in the history
Fixes #3857

This commit fixes class literals of primitive/builtin types.
  • Loading branch information
deathaxe committed Oct 21, 2023
1 parent 35fe3a3 commit 7488ab7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 11 deletions.
34 changes: 25 additions & 9 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 @@ -2137,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 @@ -3239,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 @@ -3270,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
74 changes: 72 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

0 comments on commit 7488ab7

Please sign in to comment.