Skip to content
This repository was archived by the owner on Nov 9, 2025. It is now read-only.

Commit f18bfef

Browse files
committed
(not tested) support for kotlin ::class syntax (currently only supported syntax was ::class.java)
1 parent ad3fea5 commit f18bfef

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

common/src/main/java/org/screamingsandals/nms/generator/configuration/RequiredClass.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,36 @@
2727
import org.screamingsandals.nms.generator.build.AccessorClassGenerator;
2828
import org.screamingsandals.nms.generator.utils.GroovyUtils;
2929

30+
import java.lang.reflect.Method;
3031
import java.util.ArrayList;
3132
import java.util.List;
3233
import java.util.function.Consumer;
3334

3435
@ToString(callSuper = true)
3536
public class RequiredClass extends RequiredSymbol implements RequiredArgumentType {
37+
@Nullable
38+
private static Class<?> kotlinJvmInternalClassBasedDeclarationContainer;
39+
@Nullable
40+
private static Method cBDCJClassMethod;
41+
42+
static {
43+
// Please Jetbrains, don't rename it in the future :)
44+
try {
45+
kotlinJvmInternalClassBasedDeclarationContainer = Class.forName("kotlin.jvm.internal.ClassBasedDeclarationContainer"); // DeclarationContainerImpl
46+
} catch (Throwable ignored) {
47+
try {
48+
kotlinJvmInternalClassBasedDeclarationContainer = Class.forName("kotlin.jvm.internal.DeclarationContainerImpl");
49+
} catch (Throwable ignored2) {
50+
}
51+
}
52+
try {
53+
if (kotlinJvmInternalClassBasedDeclarationContainer != null) {
54+
cBDCJClassMethod = kotlinJvmInternalClassBasedDeclarationContainer.getMethod("getJClass");
55+
}
56+
} catch (Throwable ignored) {
57+
}
58+
}
59+
3660
@Getter
3761
private final List<RequiredClassMember> requiredSymbols = new ArrayList<>();
3862

@@ -125,6 +149,13 @@ private RequiredArgumentType[] parseParams(Object[] params) {
125149
list.add((RequiredArgumentType) p);
126150
} else if (p instanceof Class) {
127151
list.add(new RequiredArgumentJvmClass((Class<?>) p));
152+
} else if (kotlinJvmInternalClassBasedDeclarationContainer != null && cBDCJClassMethod != null && kotlinJvmInternalClassBasedDeclarationContainer.isInstance(p)) {
153+
try {
154+
var javaClass = cBDCJClassMethod.invoke(p);
155+
list.add(new RequiredArgumentJvmClass((Class<?>) javaClass));
156+
} catch (Throwable throwable) {
157+
throw new RuntimeException("Invalid configuration: Can't convert kotlin KClass to java Class", throwable);
158+
}
128159
} else if (p instanceof CharSequence) {
129160
var unifiedString = p.toString();
130161
if (unifiedString.startsWith("@")) {

0 commit comments

Comments
 (0)