netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

Use a custom color for Java Annotations

Open lkishalmi opened this issue 2 years ago • 4 comments

I'm doing some small work with Micronaut lately, and wished that the annotations would be more distinctive in the editor.

It seemed it is not that easy to set a different color for them. First the @ and the ... tokens were marked as special, though no coloring support were assigned to that key. I've checked the Lang Spec, they are called as separators (at least in 8).

Also changing the color in the annotation use (or actually XXX Use) would make the import statements rainbow, so I had to skip those. Actually there is a possibility to use different colors for the imported identifiers, if someone would think that useful.

Lastly, added localization for the mod-keyword coloring. That is not in actual use as there are some bugs in the code. I do not know the correct intention of that modifier, How I'd get it that those are keywords that are keywords by their context, not a simple token in the Lexer.

Ides, feedback are welcome!

This is with FlatLaf Light: image

This is with FlatLaf Dark image

lkishalmi avatar Nov 25 '23 06:11 lkishalmi

I've marked the PR as a preview to have a discussion on this. There are a few test and test data to be fixed according to the outcome of this discussion.

Would it make sense to add coloring to the import statements?

To me it also would make sense to have the @ as normal separator and use the semantic highlighter to change that color when used together with an annotation type otherwise @interface might look odd. I do not know. Let's talk about this!

lkishalmi avatar Nov 26 '23 00:11 lkishalmi

@mbien The preview use the lexer only. I'm testing if I can add a highlighter there as well, that would come in a separate PR, if I can make that happen.

lkishalmi avatar Nov 26 '23 01:11 lkishalmi

Would it make sense to add coloring to the import statements?

you mean the fully qualified type behind import?

import java.util.ArrayList;
//     ^^^^^^^^^^^^^^^^^^^ this?

not sure. To me it is probably not necessary, since it should probably have the same color as:

list = new java.util.ArrayList<>();
//         ^^^^^^^^^^^^^^^^^^^ <- essentially the same thing

Or do you mean something else?

There are two separate questions to ask I think: what should the editor offer and which part should be used in the default theme. It could be nice to have an option to customize import statements but maybe it shouldn't be enabled by default. Although I think it would probably look nice to reduce saturation for the imports on some themes which have the contrast budget for that since those code areas are generally less import-ant :)

e.g I am experimenting with a higher contrast theme based on flatlaf dark which would probably have the contrast budget to tone imports down a bit: image

mbien avatar Nov 26 '23 15:11 mbien

  1. Yes, I mean the FQN after the import. Right now if you start use different colors by element kind it would look like this: image

  2. I have not really thought about the colors, defaults yet, other than I wish to put some emphasis/distinction on annotations.

lkishalmi avatar Nov 26 '23 17:11 lkishalmi