From 96874c52527b06aa09c73b9aedf076630f66f484 Mon Sep 17 00:00:00 2001 From: APickledWalrus Date: Mon, 2 Sep 2024 19:16:23 -0400 Subject: [PATCH] Return the constructed info for static registration methods --- .../conditions/base/PropertyCondition.java | 68 ++++++++----------- .../base/EventValueExpression.java | 23 ++++--- .../expressions/base/PropertyExpression.java | 60 ++++++++-------- .../registration/DefaultSyntaxInfos.java | 11 ++- 4 files changed, 84 insertions(+), 78 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java index 9bf30e459af..fc73f175dbc 100644 --- a/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java +++ b/src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java @@ -96,57 +96,45 @@ public enum PropertyType { } /** - * @param registry the SyntaxRegistry to register this PropertyCondition with. - * @param condition the class to register - * @param property the property name, for example fly in players can fly - * @param type must be plural, for example players in players can fly + * @param registry The SyntaxRegistry to register with. + * @param condition The class to register + * @param property The property name, for example fly in players can fly + * @param type Must be plural, for example players in players can fly + * @param The Condition type. + * @return The registered {@link SyntaxInfo}. */ @ApiStatus.Experimental - public static void register(SyntaxRegistry registry, Class condition, String property, String type) { - register(registry, condition, PropertyType.BE, property, type); + public static SyntaxInfo register(SyntaxRegistry registry, Class condition, String property, String type) { + return register(registry, condition, PropertyType.BE, property, type); } /** - * @param registry the SyntaxRegistry to register this PropertyCondition with. - * @param condition the class to register - * @param propertyType the property type, see {@link PropertyType} - * @param property the property name, for example fly in players can fly - * @param type must be plural, for example players in players can fly + * @param registry The SyntaxRegistry to register with. + * @param condition The class to register + * @param propertyType The property type, see {@link PropertyType} + * @param property The property name, for example fly in players can fly + * @param type Must be plural, for example players in players can fly + * @param The Condition type. + * @return The registered {@link SyntaxInfo}. */ @ApiStatus.Experimental - public static void register(SyntaxRegistry registry, Class condition, PropertyType propertyType, String property, String type) { + public static SyntaxInfo register(SyntaxRegistry registry, Class condition, PropertyType propertyType, String property, String type) { if (type.contains("%")) throw new SkriptAPIException("The type argument must not contain any '%'s"); - SyntaxInfo.Builder builder = SyntaxInfo.builder(condition).priority(DEFAULT_PRIORITY); + SyntaxInfo.Builder builder = SyntaxInfo.builder(condition).priority(DEFAULT_PRIORITY); switch (propertyType) { - case BE: - builder.addPatterns( - "%" + type + "% (is|are) " + property, - "%" + type + "% (isn't|is not|aren't|are not) " + property - ); - break; - case CAN: - builder.addPatterns( - "%" + type + "% can " + property, - "%" + type + "% (can't|cannot|can not) " + property - ); - break; - case HAVE: - builder.addPatterns( - "%" + type + "% (has|have) " + property, - "%" + type + "% (doesn't|does not|do not|don't) have " + property - ); - break; - case WILL: - builder.addPatterns( - "%" + type + "% will " + property, - "%" + type + "% (will (not|neither)|won't) " + property - ); - break; - default: - assert false; + case BE -> builder.addPatterns("%" + type + "% (is|are) " + property, + "%" + type + "% (isn't|is not|aren't|are not) " + property); + case CAN -> builder.addPatterns("%" + type + "% can " + property, + "%" + type + "% (can't|cannot|can not) " + property); + case HAVE -> builder.addPatterns("%" + type + "% (has|have) " + property, + "%" + type + "% (doesn't|does not|do not|don't) have " + property); + case WILL -> builder.addPatterns("%" + type + "% will " + property, + "%" + type + "% (will (not|neither)|won't) " + property); } - registry.register(SyntaxRegistry.CONDITION, builder.build()); + SyntaxInfo info = builder.build(); + registry.register(SyntaxRegistry.CONDITION, info); + return info; } /** diff --git a/src/main/java/ch/njol/skript/expressions/base/EventValueExpression.java b/src/main/java/ch/njol/skript/expressions/base/EventValueExpression.java index c938ceea7c4..32e6904c6e6 100644 --- a/src/main/java/ch/njol/skript/expressions/base/EventValueExpression.java +++ b/src/main/java/ch/njol/skript/expressions/base/EventValueExpression.java @@ -79,21 +79,26 @@ public class EventValueExpression extends SimpleExpression implements Defa /** * Registers an event value expression with the provided pattern. + * The syntax info will be forced to use the {@link #DEFAULT_PRIORITY} priority. * This also adds '[the]' to the start of the pattern. * - * @param registry the SyntaxRegistry to register this PropertyExpression with. - * @param expressionClass The class that represents this EventValueExpression. - * @param type The return type of the expression. - * @param pattern The pattern for this syntax. + * @param registry The SyntaxRegistry to register with. + * @param expressionClass The EventValueExpression class being registered. + * @param returnType The class representing the expression's return type. + * @param pattern The pattern to match for creating this expression. + * @param The return type. + * @param The Expression type. + * @return The registered {@link SyntaxInfo}. */ @ApiStatus.Experimental - public static void register(SyntaxRegistry registry, Class> expressionClass, Class type, String pattern) { - registry.register(SyntaxRegistry.EXPRESSION, SyntaxInfo.Expression.builder(expressionClass) - .returnType(type) + public static , T> SyntaxInfo.Expression register(SyntaxRegistry registry, Class expressionClass, Class returnType, String pattern) { + SyntaxInfo.Expression info = SyntaxInfo.Expression.builder(expressionClass) + .returnType(returnType) .priority(DEFAULT_PRIORITY) .addPattern("[the] " + pattern) - .build() - ); + .build(); + registry.register(SyntaxRegistry.EXPRESSION, info); + return info; } /** diff --git a/src/main/java/ch/njol/skript/expressions/base/PropertyExpression.java b/src/main/java/ch/njol/skript/expressions/base/PropertyExpression.java index dbea7c978fd..3ee5a4a307c 100644 --- a/src/main/java/ch/njol/skript/expressions/base/PropertyExpression.java +++ b/src/main/java/ch/njol/skript/expressions/base/PropertyExpression.java @@ -57,23 +57,25 @@ public abstract class PropertyExpression extends SimpleExpression { /** * Registers an expression with the two default property patterns "property of %types%" and "%types%'[s] property" * - * @param registry the SyntaxRegistry to register this PropertyExpression with. - * @param expressionClass the PropertyExpression class being registered. - * @param type the main expression type the property is based off of. - * @param property the name of the property. - * @param fromType should be plural to support multiple objects but doesn't have to be. + * @param registry The SyntaxRegistry to register with. + * @param expressionClass The PropertyExpression class being registered. + * @param returnType The class representing the expression's return type. + * @param property The name of the property. + * @param fromType Should be plural to support multiple objects but doesn't have to be. + * @param The return type. + * @param The Expression type. + * @return The registered {@link SyntaxInfo}. */ @ApiStatus.Experimental - public static void register(SyntaxRegistry registry, Class> expressionClass, Class type, String property, String fromType) { - registry.register(SyntaxRegistry.EXPRESSION, SyntaxInfo.Expression.builder(expressionClass) - .returnType(type) + public static , T> SyntaxInfo.Expression register(SyntaxRegistry registry, Class expressionClass, Class returnType, String property, String fromType) { + SyntaxInfo.Expression info = SyntaxInfo.Expression.builder(expressionClass) + .returnType(returnType) .priority(DEFAULT_PRIORITY) - .addPatterns( - "[the] " + property + " of %" + fromType + "%", - "%" + fromType + "%'[s] " + property - ) - .build() - ); + .addPatterns("[the] " + property + " of %" + fromType + "%", + "%" + fromType + "%'[s] " + property) + .build(); + registry.register(SyntaxRegistry.EXPRESSION, info); + return info; } /** @@ -92,23 +94,25 @@ public static void register(Class> expressionClass, * Registers an expression with the two default property patterns "property [of %types%]" and "%types%'[s] property" * This method also makes the expression type optional to force a default expression on the property expression. * - * @param registry the SyntaxRegistry to register this PropertyExpression with. - * @param expressionClass the PropertyExpression class being registered. - * @param type the main expression type the property is based off of. - * @param property the name of the property. - * @param fromType should be plural to support multiple objects but doesn't have to be. + * @param registry The SyntaxRegistry to register with. + * @param expressionClass The PropertyExpression class being registered. + * @param returnType The class representing the expression's return type. + * @param property The name of the property. + * @param fromType Should be plural to support multiple objects but doesn't have to be. + * @param The return type. + * @param The Expression type. + * @return The registered {@link SyntaxInfo}. */ @ApiStatus.Experimental - public static void registerDefault(SyntaxRegistry registry, Class> expressionClass, Class type, String property, String fromType) { - registry.register(SyntaxRegistry.EXPRESSION, SyntaxInfo.Expression.builder(expressionClass) - .returnType(type) + public static , T> SyntaxInfo.Expression registerDefault(SyntaxRegistry registry, Class expressionClass, Class returnType, String property, String fromType) { + SyntaxInfo.Expression info = SyntaxInfo.Expression.builder(expressionClass) + .returnType(returnType) .priority(DEFAULT_PRIORITY) - .addPatterns( - "[the] " + property + " [of %" + fromType + "%]", - "%" + fromType + "%'[s] " + property - ) - .build() - ); + .addPatterns("[the] " + property + " [of %" + fromType + "%]", + "%" + fromType + "%'[s] " + property) + .build(); + registry.register(SyntaxRegistry.EXPRESSION, info); + return info; } /** diff --git a/src/main/java/org/skriptlang/skript/registration/DefaultSyntaxInfos.java b/src/main/java/org/skriptlang/skript/registration/DefaultSyntaxInfos.java index eae8be088e6..ff174974c5a 100644 --- a/src/main/java/org/skriptlang/skript/registration/DefaultSyntaxInfos.java +++ b/src/main/java/org/skriptlang/skript/registration/DefaultSyntaxInfos.java @@ -1,12 +1,19 @@ package org.skriptlang.skript.registration; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.entry.EntryValidator; import org.skriptlang.skript.registration.DefaultSyntaxInfosImpl.ExpressionImpl; import org.skriptlang.skript.registration.DefaultSyntaxInfosImpl.StructureImpl; -interface DefaultSyntaxInfos { +/** + * This class is not safe to be directly referenced. + * Use {@link SyntaxInfo} instead. + */ +@ApiStatus.Internal +@ApiStatus.Experimental +public interface DefaultSyntaxInfos { /** * A syntax info to be used for {@link ch.njol.skript.lang.Expression}s. @@ -14,6 +21,7 @@ interface DefaultSyntaxInfos { * @param The class providing the implementation of the Expression this info represents. * @param The type of the return type of the Expression. */ + @ApiStatus.Experimental interface Expression, R> extends SyntaxInfo { /** @@ -66,6 +74,7 @@ interface Builder, E extends ch.njol.skript.lang.Expr * It contains additional details including the {@link EntryValidator} to use, if any. * @param The class providing the implementation of the Structure this info represents. */ + @ApiStatus.Experimental interface Structure extends SyntaxInfo { /**