From f4c5c0f5b5d0640485aee3c3acb42fafb5e3e97e Mon Sep 17 00:00:00 2001 From: Starlight220 <53231611+Starlight220@users.noreply.github.com> Date: Mon, 6 Apr 2020 02:11:23 +0300 Subject: [PATCH] [command] Add withName inline decorator to Java (#2420) This is an inline decorator for setting the name of a command (equivalent to calling setName()). It's not possible to implement this for C++, as it would slice the derived class to return it by value. --- .../wpi/first/wpilibj2/command/CommandBase.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java index ba2c68f46f..49180a87c3 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -56,6 +56,18 @@ public abstract class CommandBase implements Sendable, Command { SendableRegistry.setName(this, name); } + /** + * Decorates this Command with a name. + * Is an inline function for #setName(String); + * + * @param name name + * @return the decorated Command + */ + public Command withName(String name) { + this.setName(name); + return this; + } + /** * Gets the subsystem name of this Command. *