-
Couldn't load subscription status.
- Fork 664
[cmd3] Add a declarative state machine API on top of commands v3 #8297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2027
Are you sure you want to change the base?
[cmd3] Add a declarative state machine API on top of commands v3 #8297
Conversation
|
Looks good - I have a couple of suggestions:
|
This is already in place. The
Seems unnecessary. You can use
I'm not sure if I like this. It reads a little weirdly, and is a little awkward with |
Used to annotate methods that are required to be called after constructing a new object Methods with this annotation must be called directly on the field or variable; the plugin can't check for calls on objects returned by methods, or on objects returned by ternary expressions or similar
Makes usages that forget to set the initial state a compiler error, rather than just a runtime error Runtime error checking is left in place in case teams build their code without the compiler plugin enabled
Add an annotation processor to validate definitions of static initializer methods (requiring exactly one unambiguous input argument) DRY out suppression detections
This provides an API for writing a finite state machine compatible with the commands v3 framework. Individual states in the state machine are wrappers around command objects (which may themselves be state machines). Transitions between states are defined with a staged builder DSL similar to command builders, and uses
@NoDiscardto catch partially configured transitions.The FSM API is meant to handle highly complex cases that the fluent command chaining DSL and coroutine-based imperative commands cannot easily represent; specifically, where a command sequence may want to go back to an arbitrary previous state or skip forward to an arbitrary future state.
Here's an example from the design doc for a command that will drive to a known scoring location, aim at a scoring target, and repeatedly shoot balls until a storage hopper is empty. It also has conditions to stop shooting and move back to the scoring location if it's jostled away, and then automatically resume firing.
A compiler check is added to detect object construction that's not followed by post-construction initializer methods (as defined by the class by placing
@PostConstructionInitializeron such methods).StateMachine.setInitialStateuses this to detect team code that creates a state machine but does not set its initial state.