highlight.js icon indicating copy to clipboard operation
highlight.js copied to clipboard

(Java) Generic type variable not highlighted

Open amichair opened this issue 1 year ago • 8 comments

Describe the issue In a Java statement that declares and assigns a variable with a generic type, the type and variable don't get highlighted. Without the generic type they are properly highlighted.

Which language seems to have the issue? java

Are you using highlight or highlightAuto? highlightElement ...

Sample Code to Reproduce

Map<String, String> params = request.getParams();

Expected behavior Without the generic type, the type (Map) and variable (params) get highlighted. They should be similarly highlighted also when the generic type is present (and the generic type itself should be highlighted as well).

Additional context The example shows two generic types, but the issue also occurs with a single type such as List<String>. This is the proper way of defining such collections.

amichair avatar Mar 15 '24 06:03 amichair

Are all types in Java CamelCase?

joshgoebel avatar Mar 15 '24 19:03 joshgoebel

As the example shows, types in this case are all a capitalized single words, and variables are lowercase single words.

amichair avatar Mar 17 '24 06:03 amichair

Here it is on the demo site: https://highlightjs.org/demo#lang=java&v=1&theme=atom-one-dark&code=TGlzdDxTdHJpbmc%2BIGxpc3QgPSBuZXcgQXJyYXnFHT4oKTsgLy8gbm90IGhpZ2hsaWdodGVkCsQdxTIy2TPML01hcMdoLCDIcG1hcMc8SGFzaMQi2G1NYXDELshr0C%2FMKwo%3D

amichair avatar Mar 17 '24 06:03 amichair

Are all types in Java CamelCase?

The question was about Java, not your example. Are types always CamelCase in the Java language?

joshgoebel avatar Mar 18 '24 00:03 joshgoebel

Sorry, I misunderstood. By convention, types/classes are PascalCase, while variables/parameters/fields/methods are camelCase. Constructors are PascalCase because they are equal to the class name. Constants are all uppercase SNAKE_CASE. And a generic type can also be specified as a question mark, as in List<?>, and can be recursive as in List<Map<String, Integer>>, or use two special hierarchy tokens as in List<? extends Something> or List<? super Something>, though you probably don't get into such resolution for highlighting. I hope this helps...

amichair avatar Mar 19 '24 19:03 amichair

So if we just chose to highlight every occurrence of PascalCase as title.class, where would that leave us?

joshgoebel avatar Mar 20 '24 00:03 joshgoebel

Probably ok, as long as it's not in strings or comments etc.

amichair avatar Mar 20 '24 06:03 amichair

Should be simple then, you interested in working on the issue? Lots of other grammars already have this type of "named class" support - Ruby, Wren, etc...

joshgoebel avatar Oct 31 '24 23:10 joshgoebel