Skip to content

Commit 85122a3

Browse files
committed
add base handler class
1 parent 5160466 commit 85122a3

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/main/java/ch/njol/skript/classes/ClassInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public String toString(final @Nullable Event event, final boolean debug) {
479479

480480
private final Map<Property<?>, PropertyInfo<?>> propertyInfos = new HashMap<>();
481481

482-
public <Handler> ClassInfo<T> property(Property<Handler> property, @NotNull Handler handler) {
482+
public <Handler extends Property.PropertyHandler<T>> ClassInfo<T> property(Property<? super Handler> property, @NotNull Handler handler) {
483483
if (propertyInfos.containsKey(property)) {
484484
throw new IllegalStateException("Property " + property.name() + " is already registered for the " + c.getName() + " type.");
485485
}
@@ -492,7 +492,7 @@ public boolean hasProperty(Property<?> property) {
492492
return propertyInfos.containsKey(property);
493493
}
494494

495-
public <Handler> @Nullable PropertyInfo<Handler> getPropertyInfo(Property<Handler> property) {
495+
public <Handler extends Property.PropertyHandler<?>> @Nullable PropertyInfo<Handler> getPropertyInfo(Property<Handler> property) {
496496
if (!propertyInfos.containsKey(property)) {
497497
return null;
498498
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import java.util.Locale;
1111

12-
public record Property<Handler>(
12+
public record Property<Handler extends Property.PropertyHandler<?>>(
1313
String name,
1414
SkriptAddon provider,
1515
@NotNull Class<? extends Handler> handler
@@ -20,7 +20,7 @@ public Property(@NotNull String name, SkriptAddon provider, @NotNull Class<? ext
2020
this.handler = handler;
2121
}
2222

23-
public static <HandlerClass, Handler extends HandlerClass> Property<Handler> of(
23+
public static <HandlerClass extends PropertyHandler<?>, Handler extends HandlerClass> Property<Handler> of(
2424
@NotNull String name,
2525
@NotNull SkriptAddon provider,
2626
@NotNull Class<HandlerClass> handler) {
@@ -52,7 +52,10 @@ public static void registerDefaultProperties() {
5252
propertyRegistry.register(CONTAINS);
5353
}
5454

55-
public interface ExpressionPropertyHandler<Type, ReturnType> {
55+
@SuppressWarnings("unused")
56+
public interface PropertyHandler<Type> {}
57+
58+
public interface ExpressionPropertyHandler<Type, ReturnType> extends PropertyHandler<Type> {
5659
// Handler for the NAME property
5760
default Class<?> @Nullable [] acceptChange(ChangeMode mode) {
5861
return null;
@@ -72,7 +75,7 @@ public interface NameHandler<Named, Name> extends ExpressionPropertyHandler<Name
7275
Name name(Named named);
7376
}
7477

75-
public interface ContainsHandler<Container, Element> {
78+
public interface ContainsHandler<Container, Element> extends PropertyHandler<Container> {
7679
boolean contains(Container container, Element element);
7780
Class<? extends Element>[] elementTypes();
7881
default boolean canContain(Class<?> type) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package org.skriptlang.skript.lang.properties;
22

3-
public record PropertyInfo<Handler>(Property<Handler> property, Handler handler) {
3+
public record PropertyInfo<Handler extends Property.PropertyHandler<?>>(Property<Handler> property, Handler handler) {
44
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class PropertyUtils {
1313

1414

1515

16-
public static class PropertyMap<Handler> extends HashMap<Class<?>, PropertyInfo<Handler>> {
16+
public static class PropertyMap<Handler extends Property.PropertyHandler<?>> extends HashMap<Class<?>, PropertyInfo<Handler>> {
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
@@ -63,7 +63,7 @@ public static Expression<?> asProperty(Property<?> property, Expression<?> expr)
6363
}
6464

6565

66-
public static <Handler> PropertyMap<Handler> getPossiblePropertyInfos(
66+
public static <Handler extends Property.PropertyHandler<?>> PropertyMap<Handler> getPossiblePropertyInfos(
6767
Property<Handler> property,
6868
Expression<?> expr
6969
) {

0 commit comments

Comments
 (0)