Skip to content

Commit af55768

Browse files
committed
Check for presence of newer kotlin-reflect classes instead of kotlin version
As they are separate dependencies
1 parent 7ea7d7f commit af55768

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

BotCommands-core/src/main/java/io/github/freya022/botcommands/internal/utils/ReflectionMetadataAccessor.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.freya022.botcommands.internal.utils;
22

3-
import kotlin.KotlinVersion;
43
import kotlin.jvm.internal.PropertyReference;
54
import kotlin.reflect.*;
65
import kotlin.reflect.jvm.internal.KClassImpl;
@@ -24,17 +23,20 @@ class ReflectionMetadataAccessor {
2423
try {
2524
var lookup = MethodHandles.publicLookup();
2625
Class<?> kParameter;
26+
Class<?> tmpKPropertyClass;
2727
Class<?> kCallableClass;
28-
if (KotlinVersion.CURRENT.isAtLeast(2, 3)) {
28+
29+
try {
2930
kParameter = Class.forName("kotlin.reflect.jvm.internal.ReflectKParameter");
30-
kPropertyClass = Class.forName("kotlin.reflect.jvm.internal.ReflectKProperty");
31+
tmpKPropertyClass = Class.forName("kotlin.reflect.jvm.internal.ReflectKProperty");
3132
kCallableClass = Class.forName("kotlin.reflect.jvm.internal.ReflectKCallable");
32-
} else {
33+
} catch (ClassNotFoundException e) {
3334
kParameter = Class.forName("kotlin.reflect.jvm.internal.KParameterImpl");
34-
kPropertyClass = Class.forName("kotlin.reflect.jvm.internal.KPropertyImpl");
35+
tmpKPropertyClass = Class.forName("kotlin.reflect.jvm.internal.KPropertyImpl");
3536
kCallableClass = Class.forName("kotlin.reflect.jvm.internal.KCallableImpl");
3637
}
3738

39+
kPropertyClass = tmpKPropertyClass;
3840
getCallable = lookup.findVirtual(kParameter, "getCallable", MethodType.methodType(kCallableClass));
3941
getContainer = lookup.findVirtual(kPropertyClass, "getContainer", MethodType.methodType(KDeclarationContainerImpl.class));
4042
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) {

0 commit comments

Comments
 (0)