Skip to content

Commit

Permalink
Fix #37: Gutter Color display support for hexadecimal Color(int) cons…
Browse files Browse the repository at this point in the history
…tructor.

Version 1.24.7.
  • Loading branch information
BlueBoxWare committed Oct 7, 2023
1 parent 19ab0a4 commit 451e3d4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### 1.24.7
* Fix [#37](https://github.com/BlueBoxWare/LibGDXPlugin/issues/37): Gutter Color display support for hexadecimal Color(int) constructor in Kotlin.
* Fix "doing work on EDT" errors.
* Compatibility with IntelliJ 2023.3.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,18 @@ private fun PsiElement.findInitializer(): PsiElement? {

private fun PsiElement.ktInt(): Int? {

val txt = text ?: return null

if (this is KtConstantExpression) {

getType(analyzePartial())?.let { type ->

if (KotlinBuiltIns.isInt(type)) {

return try {
text.toInt()
if (StringUtil.startsWithIgnoreCase(txt, "0x")) StringUtil.trimStart(txt.lowercase(), "0x")
.toInt(16)
else txt.toInt()
} catch (e: NumberFormatException) {
null
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<change-notes><![CDATA[
<ul>
<li>Fix 37: Gutter Color display support for hexadecimal Color(int) constructor in Kotlin.</li>
<li>Fix "doing work on EDT" errors.</li>
</ul>
]]>
Expand Down
4 changes: 3 additions & 1 deletion src/test/testdata/annotators/colorAnnotator/Kotlin1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const val c = "RED"
val s = "ff00ff"
val c1 = <weak_warning descr="#ff0000ff">"#ff0000"</weak_warning>
val c2 = <weak_warning descr="#00006443">Color(25667)</weak_warning>
val c21 = <weak_warning descr="#5300ffff">Color(0x5300ffff)</weak_warning>
val c22 = <weak_warning descr="#002ce60b">Color(0x2ce60b)</weak_warning>
val c3 = <weak_warning descr="#00ff00ff">Color(0f, 1f, 0f, 1f)</weak_warning>
val c4 = <weak_warning descr="#00ffff99">Color.valueOf("00ffff99")</weak_warning>
val c5 = <weak_warning descr="#ff69b4ff">Color.PINK</weak_warning>
Expand Down Expand Up @@ -211,4 +213,4 @@ val m = mapOf<Any, Any>(
)

val i = 3456
val ci = <weak_warning descr="#00000d80">Color(i)</weak_warning>
val ci = <weak_warning descr="#00000d80">Color(i)</weak_warning>

0 comments on commit 451e3d4

Please sign in to comment.