fix static class handling

lua-profiles
Mike Barry 2023-12-07 20:25:57 -05:00
rodzic e23c637dec
commit aa9d7b7993
2 zmienionych plików z 28 dodań i 9 usunięć

Wyświetl plik

@ -243,19 +243,21 @@ public class GenerateLuaTypes {
TypeToken<?> type = TypeToken.of(clazz);
var definition = new LuaTypeDefinition(type, suffix, isStatic);
Type superclass = clazz.getGenericSuperclass();
if (superclass != null && superclass != Object.class) {
definition.addParent(type.resolveType(superclass));
}
for (var iface : clazz.getGenericInterfaces()) {
definition.addParent(type.resolveType(iface));
if (!isStatic) {
Type superclass = clazz.getGenericSuperclass();
if (superclass != null && superclass != Object.class) {
definition.addParent(type.resolveType(superclass));
}
for (var iface : clazz.getGenericInterfaces()) {
definition.addParent(type.resolveType(iface));
}
}
for (var field : clazz.getFields()) {
TypeToken<?> rawType = TypeToken.of(field.getDeclaringClass()).resolveType(field.getGenericType());
TypeToken<?> typeOnThisClass = type.resolveType(field.getGenericType());
if (Modifier.isPublic(field.getModifiers()) && isStatic == Modifier.isStatic(field.getModifiers()) &&
(field.getDeclaringClass() == clazz || !rawType.equals(typeOnThisClass))) {
(isStatic || field.getDeclaringClass() == clazz || !rawType.equals(typeOnThisClass))) {
definition.addField(field);
}
}
@ -268,7 +270,7 @@ public class GenerateLuaTypes {
for (var method : clazz.getMethods()) {
if (Modifier.isPublic(method.getModifiers()) && isStatic == Modifier.isStatic(method.getModifiers())) {
Invokable<?, ?> invokable = type.method(method);
if (!invokable.getOwnerType().equals(type) && !differentFromParents(invokable, type)) {
if (!isStatic && !invokable.getOwnerType().equals(type) && !differentFromParents(invokable, type)) {
continue;
}
if (hasMethod(Object.class, method)) {

Wyświetl plik

@ -342,7 +342,20 @@ class GenerateLuaTypesTest {
LuaValues.class);
}
public static class StaticClass {
public static class StaticClassSuper {
public static final int SUPER_CONSTANT = 1;
public final int superInstanceField = 1;
public int superInstance(int arg) {
return 1;
}
public static String superStaticMethod(String arg) {
return "";
}
}
public static class StaticClass extends StaticClassSuper {
public static final int CONSTANT = 1;
public static int staticField;
public int instanceField;
@ -366,6 +379,7 @@ class GenerateLuaTypesTest {
"""
---@class (exact) com_onthegomap_planetiler_experimental_lua_GenerateLuaTypesTest_StaticClass__class
---@field CONSTANT integer
---@field SUPER_CONSTANT integer
---@field static_field integer
types.com_onthegomap_planetiler_experimental_lua_GenerateLuaTypesTest_StaticClass__class = {}
---@param i integer
@ -376,6 +390,9 @@ class GenerateLuaTypesTest {
---@param arg integer
---@return integer
function types.com_onthegomap_planetiler_experimental_lua_GenerateLuaTypesTest_StaticClass__class:static_method(arg) end
---@param arg string
---@return string
function types.com_onthegomap_planetiler_experimental_lua_GenerateLuaTypesTest_StaticClass__class:super_static_method(arg) end
"""
.trim(),
StaticClass.class);