From 9ebc4b32ae0f7d371561af37ec3bb331c498f59d Mon Sep 17 00:00:00 2001 From: Jade Date: Thu, 2 Jan 2025 07:11:39 +0800 Subject: [PATCH] [commands] Undeprecate deferredProxy (#7417) This changes the way deferred proxy is implemented to not use the deprecated ProxyCommand constructor. This function serves a good purpose that should be kept IMO. The constructor was confusing but this is just good syntactic sugar over `defer(() -> supplier.get().asProxy())`. Signed-off-by: Jade Turner --- .../edu/wpi/first/wpilibj2/command/Commands.java | 8 ++------ .../src/main/native/cpp/frc2/command/Commands.cpp | 15 +++++++++++---- .../main/native/include/frc2/command/Commands.h | 13 +++---------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index c53409a033..8ba81cfb16 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -198,15 +198,11 @@ public final class Commands { * * @param supplier the command supplier * @return the command - * @deprecated The ProxyCommand supplier constructor has been deprecated in favor of directly - * proxying a {@link DeferredCommand}, see ProxyCommand documentation for more details. As a - * replacement, consider using `defer(supplier).asProxy()`. * @see ProxyCommand + * @see DeferredCommand */ - @Deprecated(since = "2025", forRemoval = true) - @SuppressWarnings("removal") public static Command deferredProxy(Supplier supplier) { - return new ProxyCommand(supplier); + return defer(() -> supplier.get().asProxy(), Set.of()); } // Command Groups diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp index bc4bd39da7..84c056f1f7 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include "frc2/command/ConditionalCommand.h" @@ -73,15 +74,21 @@ CommandPtr cmd::Print(std::string_view msg) { return PrintCommand(msg).ToPtr(); } -WPI_IGNORE_DEPRECATED CommandPtr cmd::DeferredProxy(wpi::unique_function supplier) { - return ProxyCommand(std::move(supplier)).ToPtr(); + return Defer( + [supplier = std::move(supplier)]() mutable { + // There is no non-owning version of AsProxy(), so use the non-owning + // ProxyCommand constructor instead. + return ProxyCommand{supplier()}.ToPtr(); + }, + {}); } CommandPtr cmd::DeferredProxy(wpi::unique_function supplier) { - return ProxyCommand(std::move(supplier)).ToPtr(); + return Defer([supplier = std::move( + supplier)]() mutable { return supplier().AsProxy(); }, + {}); } -WPI_UNIGNORE_DEPRECATED CommandPtr cmd::Wait(units::second_t duration) { return WaitCommand(duration).ToPtr(); diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h index 6cfad01b1f..b0dcda022f 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h @@ -169,15 +169,11 @@ CommandPtr Defer(wpi::unique_function supplier, /** * Constructs a command that schedules the command returned from the supplier * when initialized, and ends when it is no longer scheduled. The supplier is - * called when the command is initialized. As a replacement, consider using - * `Defer(supplier).AsProxy()`. + * called when the command is initialized. * * @param supplier the command supplier */ -WPI_IGNORE_DEPRECATED -[[nodiscard]] [[deprecated( - "The ProxyCommand supplier constructor has been deprecated. Use " - "Defer(supplier).AsProxy() instead.")]] +[[nodiscard]] CommandPtr DeferredProxy(wpi::unique_function supplier); /** @@ -187,11 +183,8 @@ CommandPtr DeferredProxy(wpi::unique_function supplier); * * @param supplier the command supplier */ -[[nodiscard]] [[deprecated( - "The ProxyCommand supplier constructor has been deprecated. Use " - "Defer(supplier).AsProxy() instead.")]] +[[nodiscard]] CommandPtr DeferredProxy(wpi::unique_function supplier); -WPI_UNIGNORE_DEPRECATED // Command Groups namespace impl {