From 8e5471d2729443667ab47bec9ed2d71769193a89 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 21 Oct 2023 11:04:47 +0200 Subject: [PATCH 1/3] [Java] Fix illagal type members in field declarations --- Java/Java.sublime-syntax | 4 +--- Java/tests/syntax_test_java.java | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Java/Java.sublime-syntax b/Java/Java.sublime-syntax index 064a7af5e6..1c93c17c78 100644 --- a/Java/Java.sublime-syntax +++ b/Java/Java.sublime-syntax @@ -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: ',' diff --git a/Java/tests/syntax_test_java.java b/Java/tests/syntax_test_java.java index 2648a034cd..a19dda3bb0 100644 --- a/Java/tests/syntax_test_java.java +++ b/Java/tests/syntax_test_java.java @@ -2623,6 +2623,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 @@ -2643,6 +2659,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 From 35fe3a3879b5291bb5ab0ca4fbef75ba61ad958c Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 21 Oct 2023 11:18:33 +0200 Subject: [PATCH 2/3] [Java] Verify illegal type members in local declarations --- Java/tests/syntax_test_java.java | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Java/tests/syntax_test_java.java b/Java/tests/syntax_test_java.java index a19dda3bb0..60f00ffd05 100644 --- a/Java/tests/syntax_test_java.java +++ b/Java/tests/syntax_test_java.java @@ -4671,6 +4671,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 @@ -4688,6 +4704,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 From 7488ab7c48d4e7bd2c93ff1f88ffb674167800e7 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 21 Oct 2023 11:26:21 +0200 Subject: [PATCH 3/3] [Java] Fix class literals Fixes #3857 This commit fixes class literals of primitive/builtin types. --- Java/Java.sublime-syntax | 34 +++++++++++---- Java/tests/syntax_test_java.java | 74 +++++++++++++++++++++++++++++++- 2 files changed, 97 insertions(+), 11 deletions(-) diff --git a/Java/Java.sublime-syntax b/Java/Java.sublime-syntax index 1c93c17c78..9c78615598 100644 --- a/Java/Java.sublime-syntax +++ b/Java/Java.sublime-syntax @@ -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 @@ -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: @@ -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}} @@ -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*\] diff --git a/Java/tests/syntax_test_java.java b/Java/tests/syntax_test_java.java index 60f00ffd05..1f52b0b0ff 100644 --- a/Java/tests/syntax_test_java.java +++ b/Java/tests/syntax_test_java.java @@ -1941,12 +1941,82 @@ public enum TokenKind extends MyEnum, FooBaz> 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