diff --git a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/JavaCommons.java b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/JavaCommons.java new file mode 100644 index 00000000..a678a698 --- /dev/null +++ b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/JavaCommons.java @@ -0,0 +1,10 @@ +package ru.progrm_jarvis.javacommons; + +import lombok.experimental.UtilityClass; + +/** + * Utilities mostly used by java-commons internals. + */ +@UtilityClass +public class JavaCommons { +} diff --git a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/classloading/extension/LegacyClassExtensions.java b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/classloading/extension/LegacyClassExtensions.java index fcb9bcf9..693b7ab1 100644 --- a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/classloading/extension/LegacyClassExtensions.java +++ b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/classloading/extension/LegacyClassExtensions.java @@ -57,14 +57,13 @@ public class LegacyClassExtensions { * * @param type raw-typed array-class object * @param exact wanted type of array-class object - * @return the provided array-class object with its type case to the specific one + * @return the provided array-class object with its type cast to the specific one * * @apiNote this is effectively no-op */ - // note: no nullability annotations are present on parameter and return type as cast of `null` is also safe @Contract("_ -> param1") @SuppressWarnings("unchecked") - private Class uncheckedArrayClassCast(final Class type) { + public Class uncheckedArrayClassCast(final Class type) { return (Class) type; } } diff --git a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/delegate/CachingGeneratingDelegateFactory.java b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/delegate/CachingGeneratingDelegateFactory.java index e141ac85..a9f9c5f3 100644 --- a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/delegate/CachingGeneratingDelegateFactory.java +++ b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/delegate/CachingGeneratingDelegateFactory.java @@ -64,7 +64,7 @@ protected interface DelegateWrapperFactory { * * @param type raw-typed delegate wrapper factory * @param exact wanted type of delegate wrapper factory - * @return the provided delegate wrapper factory with its type case to the specific one + * @return the provided delegate wrapper factory with its type cast to the specific one * * @apiNote this is effectively no-op */ diff --git a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/invoke/FullAccessLookupFactories.java b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/invoke/FullAccessLookupFactories.java index 14e4d382..b4378bce 100644 --- a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/invoke/FullAccessLookupFactories.java +++ b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/invoke/FullAccessLookupFactories.java @@ -144,7 +144,7 @@ public Optional getDefault() { * * @param type raw-typed constructor array * @param exact wanted type of constructor array - * @return the provided constructor array with its type case to the specific one + * @return the provided constructor array with its type cast to the specific one * * @apiNote this is effectively no-op */ diff --git a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/unchecked/UncheckedCasts.java b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/unchecked/UncheckedCasts.java new file mode 100644 index 00000000..864c2fa5 --- /dev/null +++ b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/unchecked/UncheckedCasts.java @@ -0,0 +1,29 @@ +package ru.progrm_jarvis.javacommons.unchecked; + +import lombok.experimental.UtilityClass; +import org.jetbrains.annotations.Contract; + +/** + * Commonly used unchecked cast operations. + * + * @apiNote no nullability annotations are present on parameters and return types + * because casts of {@code null} are always safe + */ +@UtilityClass +public class UncheckedCasts { + + /** + * Casts the given class object into the specific one. + * + * @param type raw-typed class object + * @param exact wanted type of class object + * @return the provided class object with its type cast to the specific one + * + * @apiNote this is effectively no-op + */ + @Contract("_ -> param1") + @SuppressWarnings("unchecked") + public Class uncheckedClassCast(final Class type) { + return (Class) type; + } +} diff --git a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/util/TypeHints.java b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/util/TypeHints.java index 7fbaf97c..65ff2c79 100644 --- a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/util/TypeHints.java +++ b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/util/TypeHints.java @@ -1,12 +1,13 @@ package ru.progrm_jarvis.javacommons.util; import lombok.experimental.UtilityClass; -import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.annotation.*; +import static ru.progrm_jarvis.javacommons.unchecked.UncheckedCasts.uncheckedClassCast; + /** * Utilities related to special hacks around Java's types, especially generics. */ @@ -26,22 +27,6 @@ public class TypeHints { return uncheckedClassCast(typeHint.getClass().getComponentType()); } - /** - * Casts the given class object into the specific one. - * - * @param type raw-typed class object - * @param exact wanted type of class object - * @return the provided class object with its type case to the specific one - * - * @apiNote this is effectively no-op - */ - // note: no nullability annotations are present on parameter and return type as cast of `null` is also safe - @Contract("_ -> param1") - @SuppressWarnings("unchecked") - private Class uncheckedClassCast(final Class type) { - return (Class) type; - } - /** * Marks the specified method argument as a type hint. */ diff --git a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/util/stream/extension/LegacyCollectorExtensions.java b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/util/stream/extension/LegacyCollectorExtensions.java index 95a3ef71..a414bfb0 100644 --- a/java-commons/src/main/java/ru/progrm_jarvis/javacommons/util/stream/extension/LegacyCollectorExtensions.java +++ b/java-commons/src/main/java/ru/progrm_jarvis/javacommons/util/stream/extension/LegacyCollectorExtensions.java @@ -70,7 +70,7 @@ public class LegacyCollectorExtensions { * * @param raw raw-types list * @param exact wanted type of list elements - * @return the provided list with its type case to the specific one + * @return the provided list with its type cast to the specific one * * @apiNote this is effectively no-op */ diff --git a/reflector/src/main/java/ru/progrm_jarvis/reflector/wrapper/invoke/InvokeConstructorWrapper.java b/reflector/src/main/java/ru/progrm_jarvis/reflector/wrapper/invoke/InvokeConstructorWrapper.java index 26669ded..1467f39c 100644 --- a/reflector/src/main/java/ru/progrm_jarvis/reflector/wrapper/invoke/InvokeConstructorWrapper.java +++ b/reflector/src/main/java/ru/progrm_jarvis/reflector/wrapper/invoke/InvokeConstructorWrapper.java @@ -159,7 +159,7 @@ BiFunction.class, uncheckedConstructorCast(constructor) * * @param type raw-typed constructor * @param exact wanted type of constructor - * @return the provided constructor with its type case to the specific one + * @return the provided constructor with its type cast to the specific one * * @apiNote this is effectively no-op */ diff --git a/ultimate-messenger/src/main/java/ru/progrm_jarvis/ultimatemessenger/format/model/AsmTextModelFactory.java b/ultimate-messenger/src/main/java/ru/progrm_jarvis/ultimatemessenger/format/model/AsmTextModelFactory.java index 3ccd26e1..494d6e4b 100644 --- a/ultimate-messenger/src/main/java/ru/progrm_jarvis/ultimatemessenger/format/model/AsmTextModelFactory.java +++ b/ultimate-messenger/src/main/java/ru/progrm_jarvis/ultimatemessenger/format/model/AsmTextModelFactory.java @@ -20,6 +20,7 @@ import ru.progrm_jarvis.javacommons.lazy.Lazy; import ru.progrm_jarvis.javacommons.object.valuestorage.SimpleValueStorage; import ru.progrm_jarvis.javacommons.object.valuestorage.ValueStorage; +import ru.progrm_jarvis.javacommons.unchecked.UncheckedCasts; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -32,6 +33,7 @@ import static org.objectweb.asm.Opcodes.*; import static org.objectweb.asm.Type.*; import static ru.progrm_jarvis.javacommons.bytecode.asm.AsmUtil.*; +import static ru.progrm_jarvis.javacommons.unchecked.UncheckedCasts.uncheckedClassCast; /** * Implementation of {@link TextModelFactory text model factory} which uses runtime class generation. @@ -577,22 +579,6 @@ protected void endModification(final @NotNull StaticAsmNode staticNode) { } } - /** - * Casts the given class object into the specific one. - * - * @param type raw-typed class object - * @param exact wanted type of class object - * @return the provided class object with its type cast to the specific one - * - * @apiNote this is effectively no-op - */ - // note: no nullability annotations are present on parameter and return type as cast of `null` is also safe - @Contract("_ -> param1") - @SuppressWarnings("unchecked") - private static Class uncheckedClassCast(final Class type) { - return (Class) type; - } - /** * Casts the given text model into the specific one. *