Skip to content

Commit

Permalink
Fix interface finding not recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
anhcraft committed May 3, 2024
1 parent 691d82f commit dd12391
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions common/src/main/java/dev/anhcraft/config/ConfigDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.*;

public class ConfigDeserializer extends ConfigHandler {
private final List<Middleware> middlewares = new ArrayList<>();
Expand Down Expand Up @@ -67,23 +65,20 @@ public <T> T transform(@NotNull Type targetType, @Nullable SimpleForm simpleForm
return transformArray(Objects.requireNonNull(TypeUtil.getElementType(targetType)), simpleForm);
}
}
Class<?> type = rawType;
while (true) {
Stack<Class<?>> stack = new Stack<>();
stack.add(rawType);
while (!stack.isEmpty()) {
Class<?> type = stack.pop();
if (type == null || type == Object.class)
continue;
TypeAdapter<?> typeAdapter = getTypeAdapter(type);
if (typeAdapter != null) {
//noinspection unchecked
return (T) typeAdapter.complexify(this, targetType, simpleForm);
}
for (Class<?> clazz : type.getInterfaces()) {
typeAdapter = getTypeAdapter(clazz);
if (typeAdapter != null) {
//noinspection unchecked
return (T) typeAdapter.complexify(this, targetType, simpleForm);
}
}
type = type.getSuperclass();
if (!shouldCallSuperAdapter() || type == null || type.equals(Object.class)) {
break;
stack.addAll(Arrays.asList(type.getInterfaces()));
if (shouldCallSuperAdapter()) {
stack.add(type.getSuperclass());
}
}
//noinspection unchecked
Expand Down

0 comments on commit dd12391

Please sign in to comment.