Skip to content

Commit 3fbf30e

Browse files
committed
Fix #23: Compatibility with Kotlin plugin 1.4.20+
And use JVM target 1.8
1 parent a723573 commit 3fbf30e

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ sourceSets {
8282
}
8383
}
8484

85+
compileJava {
86+
sourceCompatibility = 1.8
87+
targetCompatibility = 1.8
88+
}
89+
8590
compileAnnotationsJava {
8691
sourceCompatibility = 1.6
8792
targetCompatibility = 1.6

src/main/kotlin/com/gmail/blueboxware/libgdxplugin/inspections/kotlin/KotlinFlushInsideLoopInspection.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.gmail.blueboxware.libgdxplugin.inspections.kotlin
1717

1818
import com.gmail.blueboxware.libgdxplugin.inspections.getFlushingMethods
1919
import com.gmail.blueboxware.libgdxplugin.message
20+
import com.gmail.blueboxware.libgdxplugin.utils.compat.isGetter
2021
import com.intellij.codeInspection.LocalInspectionToolSession
2122
import com.intellij.codeInspection.ProblemsHolder
2223
import com.intellij.psi.PsiElement
@@ -148,26 +149,19 @@ private class LoopBodyChecker(val holder: ProblemsHolder, session: LocalInspecti
148149
//
149150
// Are we using a property accessor which contains a flushing call?
150151
//
152+
val spars = refs.filterIsInstance<SyntheticPropertyAccessorReference>()
151153

152-
var getter: Boolean? = null
153-
154-
for (ref in refs) {
155-
if (ref is SyntheticPropertyAccessorReference) {
156-
if (ref is SyntheticPropertyAccessorReference.Getter) {
157-
getter = true
158-
} else if (ref is SyntheticPropertyAccessorReference.Setter) {
159-
getter = false
160-
}
161-
}
154+
if (spars.isEmpty()) {
155+
return
162156
}
163157

164-
if (getter == null) return
158+
val isGetter = spars.any { it.isGetter() }
165159

166160
for (ref in refs) {
167161
val target = ref.resolve()
168162
if (target is KtProperty) {
169163
// Kotlin accessor
170-
val accessor = if (getter) target.getter else target.setter
164+
val accessor = if (isGetter) target.getter else target.setter
171165
if (accessor != null && allFlushingMethods.contains(accessor)) {
172166
registerProblem(expression)
173167
return

src/main/kotlin/com/gmail/blueboxware/libgdxplugin/inspections/kotlin/KotlinLogLevelInspection.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.gmail.blueboxware.libgdxplugin.inspections.kotlin
22

33
import com.gmail.blueboxware.libgdxplugin.utils.isSetLogLevel
44
import com.gmail.blueboxware.libgdxplugin.message
5+
import com.gmail.blueboxware.libgdxplugin.utils.compat.isGetter
56
import com.intellij.codeInspection.ProblemsHolder
67
import com.intellij.psi.PsiMethod
78
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
@@ -70,7 +71,7 @@ class KotlinLogLevelInspection: LibGDXKotlinBaseInspection() {
7071

7172
for (ref in refs) {
7273

73-
if (ref is SyntheticPropertyAccessorReference.Setter) {
74+
if ((ref as? SyntheticPropertyAccessorReference)?.isGetter() == false) {
7475
val target = ref.resolve()
7576
if (target is PsiMethod) {
7677
val clazz = target.containingClass ?: continue
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.gmail.blueboxware.libgdxplugin.utils.compat
2+
3+
import org.jetbrains.kotlin.idea.references.SyntheticPropertyAccessorReference
4+
import org.jetbrains.kotlin.utils.addToStdlib.cast
5+
import kotlin.reflect.KProperty1
6+
import kotlin.reflect.full.memberProperties
7+
8+
9+
/*
10+
* Copyright 2020 Blue Box Ware
11+
*
12+
* Licensed under the Apache License, Version 2.0 (the "License");
13+
* you may not use this file except in compliance with the License.
14+
* You may obtain a copy of the License at
15+
*
16+
* http://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an "AS IS" BASIS,
20+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*/
24+
fun SyntheticPropertyAccessorReference.isGetter(): Boolean {
25+
if (this::class.simpleName == "Getter") {
26+
return true
27+
} else if (this::class.simpleName == "Setter") {
28+
return false
29+
}
30+
return this::class
31+
.memberProperties
32+
.firstOrNull { it.name == "getter" }
33+
?.cast<KProperty1<SyntheticPropertyAccessorReference, Boolean>>()
34+
?.get(this)
35+
?: false
36+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<id>com.gmail.blueboxware.libgdxplugin</id>
1919
<!--suppress PluginXmlCapitalization -->
2020
<name>libGDX</name>
21-
<version>1.21</version>
21+
<version>1.22</version>
2222
<vendor url="https://github.com/BlueBoxWare/LibGDXPlugin">Blue Box Ware</vendor>
2323

2424
<description><![CDATA[
@@ -31,6 +31,11 @@
3131
]]></description>
3232

3333
<change-notes><![CDATA[
34+
<b>1.22</b>
35+
<ul>
36+
<li>Compatibility with Kotlin plugin 1.4.20+ (<a href="https://github.com/BlueBoxWare/LibGDXPlugin/issues/23">#23</a>)</li>
37+
<li>Build for Java target 1.8 (fixes compatibility with Android Studio)</li>
38+
</ul>
3439
<b>1.21</b>
3540
<ul>
3641
<li>Changed plugin name to libGDX (<a href="https://github.com/BlueBoxWare/LibGDXPlugin/issues/22">#22</a>).</li>

versions.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
ext {
22

3-
pluginVersion = '1.21'
3+
pluginVersion = '1.22'
44

55
kotlinVersion = '1.4.10'
6-
6+
77
intellijPluginVersion = '0.4.26'
88

99
// ideaVersion = '2019.3.3'

0 commit comments

Comments
 (0)