Skip to content

Commit 884fcb2

Browse files
committed
fix getting and setting lists
1 parent e852ae8 commit 884fcb2

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/main/java/fn10/bedrockr/windows/componets/RElementValue.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -854,16 +854,35 @@ else if (!InputType.isAssignableFrom(value.getClass())) {
854854
casted.setSelectedItem(value);
855855
} else if (List.class.isAssignableFrom(InputType)) {
856856
try {
857-
Object[] array;
858-
if (value instanceof List list)
859-
array = list.toArray();
860-
else if (value.getClass().isArray())
861-
array = ((Object[]) value);
862-
else
857+
Field field;
858+
try { // try to get field
859+
if (SourceFileClass != null) {
860+
field = SourceFileClass.getField(Target);
861+
} else {
862+
field = null;
863+
}
864+
} catch (Exception e) {
863865
return;
864-
865-
for (Object entry : array) {
866-
RElementValue toAdd = new RElementValue(parentFrame, InputType.getComponentType(),
866+
}
867+
final Class<?> genericType;
868+
if (!InputType.isArray()) {
869+
if (field == null) {
870+
return;
871+
}
872+
if (field.getGenericType() instanceof java.lang.reflect.ParameterizedType) {
873+
java.lang.reflect.ParameterizedType pt = (java.lang.reflect.ParameterizedType) field
874+
.getGenericType();
875+
genericType = (Class<?>) pt.getActualTypeArguments()[0];
876+
} else
877+
genericType = null;
878+
if (genericType == null) {
879+
throw new NullPointerException("This list doesnt have a type.");
880+
}
881+
} else {
882+
genericType = null;
883+
}
884+
for (Object entry : ((List<Object>) value)) {
885+
RElementValue toAdd = new RElementValue(parentFrame, genericType,
867886
Filter,
868887
null, "",
869888
false, null, WorkspaceName);
@@ -997,11 +1016,8 @@ public Object getValue() {
9971016

9981017
List<Object> listToBuild = new ArrayList<Object>();
9991018
for (Component comp : HashMapInnerPane.getComponents()) {
1000-
if (comp.getName() == null)
1001-
continue;
1002-
if (comp.getName().equals("E")) {
1003-
var mapElement = ((RElementValue) comp);
1004-
listToBuild.add(mapElement.getValue());
1019+
if (comp instanceof RElementValue rev) {
1020+
listToBuild.add(rev.getValue());
10051021
}
10061022
}
10071023
if (InputType.isArray())

0 commit comments

Comments
 (0)