Skip to content

Commit 451e3d4

Browse files
committed
Fix #37: Gutter Color display support for hexadecimal Color(int) constructor.
Version 1.24.7.
1 parent 19ab0a4 commit 451e3d4

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### 1.24.7
2+
* Fix [#37](https://github.com/BlueBoxWare/LibGDXPlugin/issues/37): Gutter Color display support for hexadecimal Color(int) constructor in Kotlin.
23
* Fix "doing work on EDT" errors.
34
* Compatibility with IntelliJ 2023.3.
45

src/main/kotlin/com/gmail/blueboxware/libgdxplugin/utils/ColorPsiElementsUtils.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,18 @@ private fun PsiElement.findInitializer(): PsiElement? {
453453

454454
private fun PsiElement.ktInt(): Int? {
455455

456+
val txt = text ?: return null
457+
456458
if (this is KtConstantExpression) {
457459

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

460462
if (KotlinBuiltIns.isInt(type)) {
461463

462464
return try {
463-
text.toInt()
465+
if (StringUtil.startsWithIgnoreCase(txt, "0x")) StringUtil.trimStart(txt.lowercase(), "0x")
466+
.toInt(16)
467+
else txt.toInt()
464468
} catch (e: NumberFormatException) {
465469
null
466470
}

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
<change-notes><![CDATA[
3333
<ul>
34+
<li>Fix 37: Gutter Color display support for hexadecimal Color(int) constructor in Kotlin.</li>
3435
<li>Fix "doing work on EDT" errors.</li>
3536
</ul>
3637
]]>

src/test/testdata/annotators/colorAnnotator/Kotlin1.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const val c = "RED"
1919
val s = "ff00ff"
2020
val c1 = <weak_warning descr="#ff0000ff">"#ff0000"</weak_warning>
2121
val c2 = <weak_warning descr="#00006443">Color(25667)</weak_warning>
22+
val c21 = <weak_warning descr="#5300ffff">Color(0x5300ffff)</weak_warning>
23+
val c22 = <weak_warning descr="#002ce60b">Color(0x2ce60b)</weak_warning>
2224
val c3 = <weak_warning descr="#00ff00ff">Color(0f, 1f, 0f, 1f)</weak_warning>
2325
val c4 = <weak_warning descr="#00ffff99">Color.valueOf("00ffff99")</weak_warning>
2426
val c5 = <weak_warning descr="#ff69b4ff">Color.PINK</weak_warning>
@@ -211,4 +213,4 @@ val m = mapOf<Any, Any>(
211213
)
212214

213215
val i = 3456
214-
val ci = <weak_warning descr="#00000d80">Color(i)</weak_warning>
216+
val ci = <weak_warning descr="#00000d80">Color(i)</weak_warning>

0 commit comments

Comments
 (0)