diff --git a/src/main/java/carpet/script/annotation/SimpleTypeConverter.java b/src/main/java/carpet/script/annotation/SimpleTypeConverter.java index b5229071..aef8f363 100644 --- a/src/main/java/carpet/script/annotation/SimpleTypeConverter.java +++ b/src/main/java/carpet/script/annotation/SimpleTypeConverter.java @@ -25,6 +25,7 @@ import carpet.script.value.ValueConversions; *
{@link SimpleTypeConverter}s are reused whenever asked for one, since they don't have any complexity.
* * @see #registerType(Class, Class, Function, String) + * @see #registerType(Class, Class, BiFunction, String) * * @paramThe default constructor for {@link SimpleTypeConverter}.
+ * Same as {@link #SimpleTypeConverter(Class, BiFunction, String)}, but without the converter function taking a {@link Context} + * + * @param inputType The required type for the input {@link Value} + * @param converter The function to convert an instance of inputType into R, with the context of the call. + * @param typeName The name of the type for error messages + * + * @see #SimpleTypeConverter(Class, BiFunction, String) + */ + public SimpleTypeConverter(final ClassA constructor for {@link SimpleTypeConverter}.
* *This is public in order to provide an implementation to use when registering {@link ValueConverter}s for the {@link Param.Strict} annotation * registry, and it's not intended way to register new {@link SimpleTypeConverter}
Use {@link #registerType(Class, Class, Function, String)} for * that.
* * @param inputType The required type for the input {@link Value} - * @param converter The function to convert an instance of inputType into R. + * @param converter The function to convert an instance of inputType into R, with the context of the call. + * @param typeName The name of the type for error messages */ public SimpleTypeConverter(final ClassRegisters a new conversion from a {@link Value} subclass to a Java type, with the context of the call.
+ * + * @paramFunctions using the converter can use {@link #getTypeName()} to get the name of the type this was trying to convert to, in case they are not * trying to convert to anything else, where it would be recommended to tell the user the name of the final type instead.
* - * @param value The {@link Value} to convert - * @param context + * @param value The {@link Value} to convert + * @param context The {@link Context} of the call * @return The converted value, or {@code null} if the conversion failed in the process * @apiNoteWhile most implementations of this method should and will return the type from this method, implementations that require
* parameters from {@link #checkAndConvert(Iterator, Context, Context.Type)} or that require multiple parameters may decide to throw
@@ -65,10 +65,27 @@ public interface ValueConverter
+ *
+ * This shouldn't be used given converters now take a context in the convert function to allow for converting
+ * values in lists or other places without using static state.
+ *
+ * @param value The value to convert
+ * @return A converted value
+ * @deprecated Calling this method instead of {@link #convert(Value, Context)} may not return values for some converters
+ */
@Deprecated(forRemoval = true)
default R convert(final Value value)
{
- return convert(value, null);
+ try
+ {
+ return convert(value, null);
+ }
+ catch (NullPointerException e)
+ {
+ return null;
+ }
}
/**
@@ -185,8 +202,7 @@ public interface ValueConverter This method holds the same nullability
* constraints as {@link #convert(Value, Context)}