Miha-x64 / Mikes_IDEA_extensions

IntelliJ IDEA: missing parts.
Apache License 2.0
34 stars 7 forks source link

Request: in Kotlin, offer inspection to replace negative hex values of colors to positive ones #35

Open AndroidDeveloperLB opened 2 years ago

AndroidDeveloperLB commented 2 years ago

When Android Studio converts from Java to Kotlin, it often converts numbers that were supposed to be of colors.

So, it creates something like:

var someColor = -0x555556

The safe way to find what color this is, is to use Integer.toHexString(), which would result in 0xffaaaaaa for this case.

After I do this, the IDE has a tiny preview of the color on the side, so it helps me read it in both ARGB format and visually:

image

This is a bit tricky for an inspection, so maybe offer it by default only to places that have the @ColorInt annotation, and an option to expand it even for places that the value doesn't have it.

Please offer such an inspection, and auto-add "0x" and ".toInt()" if needed (IDE says it's an Int already), and if ".toInt()" isn't needed, add the type of the field instead. Or maybe always add the type. This will make sure that if we change the value with some mistake, it won't change the type so easily to Long type instead.