Skip to content

Commit 7c90f01

Browse files
committed
cleanup and move lookupPropertyInfo to override of get(Class)
1 parent cbc9107 commit 7c90f01

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

src/main/java/org/skriptlang/skript/lang/properties/PropertyBaseExpression.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is
7575
.toArray(size -> (Object[]) Array.newInstance(getReturnType(), size));
7676
}
7777

78-
protected void preConvert(Event event) {}
79-
8078
protected abstract <T> @Nullable Object convert(Event event, Handler handler, T source);
8179

8280
@Override
@@ -130,15 +128,8 @@ public Class<?>[] getTypes(ChangeMode mode, PropertyInfo<Handler> propertyInfo)
130128

131129
@Override
132130
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
133-
for (Object nameHaver : expr.getArray(event)) {
134-
PropertyInfo<Handler> propertyInfo;
135-
// check if we don't already know the right info for this class
136-
if (properties.containsKey(nameHaver.getClass())) {
137-
propertyInfo = properties.get(nameHaver.getClass());
138-
} else {
139-
// search for assignable property info
140-
propertyInfo = properties.lookupPropertyInfo(nameHaver.getClass());
141-
}
131+
for (Object propertyHaver : expr.getArray(event)) {
132+
PropertyInfo<Handler> propertyInfo = properties.get(propertyHaver.getClass());
142133
if (propertyInfo == null) {
143134
continue; // no property info found, skip
144135
}
@@ -157,10 +148,10 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
157148
// single type, compare to delta[0]
158149
if ((allowedType.isArray() && allowedType.isInstance(delta))
159150
|| (delta != null && allowedType.isInstance(delta[0]))) {
160-
// if the nameHaver is allowed, change
151+
// if the propertyHaver is allowed, change
161152
@SuppressWarnings("unchecked")
162-
var handler = (Property.NameHandler<Object, ?>) propertyInfo.handler();
163-
handler.change(nameHaver, delta, mode);
153+
var handler = (ExpressionPropertyHandler<Object, ?>) propertyInfo.handler();
154+
handler.change(propertyHaver, delta, mode);
164155
}
165156
// if allowed type is singular, take delta[0]
166157
}

src/main/java/org/skriptlang/skript/lang/properties/PropertyUtils.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ public static class PropertyMap<Handler> extends HashMap<Class<?>, PropertyInfo<
1717
public @Nullable Handler getHandler(Class<?> inputClass) {
1818
PropertyInfo<Handler> propertyInfo;
1919
// check if we don't already know the right info for this class
20-
if (containsKey(inputClass)) {
21-
propertyInfo = get(inputClass);
22-
} else {
23-
// search for assignable property info
24-
propertyInfo = lookupPropertyInfo(inputClass);
25-
}
20+
propertyInfo = get(inputClass);
2621
if (propertyInfo == null) {
2722
// no property info found, return null
2823
return null;
@@ -31,7 +26,11 @@ public static class PropertyMap<Handler> extends HashMap<Class<?>, PropertyInfo<
3126
return propertyInfo.handler();
3227
}
3328

34-
public PropertyInfo<Handler> lookupPropertyInfo(Class<?> actualClass) {
29+
public PropertyInfo<Handler> get(Class<?> actualClass) {
30+
if (super.containsKey(actualClass)) {
31+
return super.get(actualClass);
32+
}
33+
3534
Class<?> closestClass = null;
3635
for (Class<?> candidateClass : keySet()) {
3736
// need to make sure we get the closest match
@@ -42,7 +41,7 @@ public PropertyInfo<Handler> lookupPropertyInfo(Class<?> actualClass) {
4241
}
4342
}
4443

45-
var propertyInfo = get(closestClass);
44+
var propertyInfo = super.get(closestClass);
4645
// add to properties so we don't have to search again
4746
put(actualClass, propertyInfo);
4847
return propertyInfo;

0 commit comments

Comments
 (0)