atom/language-java

JAVA syntax highlighting breaks for type names ending with 'class'

Closed this issue · 4 comments

From @Zenoo on October 24, 2018 14:11

class ZoneSuperclass {
  
}

public static void main(String[] args) {
  Zonesuperclass zone = null;
}

Issue Type: Bug

  1. Have a Java class with a name ending with 'class'
  2. Try to reference this class elsewhere like ZoneSuperclass zone = null;

vsc_color_highlighting_error
Copied from original issue: microsoft/vscode#61727
Example code to copy and paste:

class ZoneSuperclass {

}

public static void main(String[] args) {
	ZoneSuperclass testVal = null;
}

@Zenoo, I can't reproduce this. I tried with:
VS Code version: Code 1.28.2 (7f3ce96, 2018-10-17T00:23:51.859Z)
VS Code version: 1.29.0-insider (4a29bd373)
And built out of master from 3dd2b19b2ab73

This is my test code:
image

Does this reproduce if you disable all extensions? Can you provide more details for me to reproduce with?

From @Zenoo on October 25, 2018 9:22

@alexr00 You mistyped the class name, it only happens when it ends with class, not Class.

Try it by naming the class ZoneSuperclass, not ZoneSuperClass

@Zenoo, I see it now, thank you for catching. This also repros in Atom, which is where we're getting the language grammar from.

Thanks for reporting!

This should do it:

C02W6HZLHTD5:language-java ivansadikov$ git diff
diff --git a/grammars/java.cson b/grammars/java.cson
index df32209..5045385 100644
--- a/grammars/java.cson
+++ b/grammars/java.cson
@@ -243,7 +243,7 @@
       }
     ]
   'class':
-    'begin': '(?=\\w?[\\w\\s]*(?:class|(?<!@)interface|enum)\\s+\\w+)'
+    'begin': '(?=\\w?[\\w\\s]*\\b(?:class|(?<!@)interface|enum)\\s+\\w+)'
     'end': '}'
     'endCaptures':
       '0':

I will open a PR to fix it.