Skip to content

Add gradle task for generating state machine diagrams#839

Open
Daniel1464 wants to merge 14 commits into
wpilibsuite:mainfrom
Daniel1464:stateMachineDiagram
Open

Add gradle task for generating state machine diagrams#839
Daniel1464 wants to merge 14 commits into
wpilibsuite:mainfrom
Daniel1464:stateMachineDiagram

Conversation

@Daniel1464

@Daniel1464 Daniel1464 commented Jun 1, 2026

Copy link
Copy Markdown

Uses javaparser to statically analyze state machine returning methods annotated with @MakeStateMachineGraph, and generates mermaid diagrams that map all of the possible states as well as the transitions between them. The mermaid files are generated inside of the deploy directory, allowing them to be logged in real-time or referenced as an asset by the user.

Here is an example of a state machine diagram generated by the gradle task (visualized in AdvantageScope):

image

Feedback would be appreciated in how this should be bundled with the wpilib java extension. Currently, the gradle task isn't linked to compileJava because the task itself analyzes every java file the user has, meaning that it might add add unwanted build time for users not using this feature.

Tangential PRs:

@OrenMic

OrenMic commented Jun 1, 2026

Copy link
Copy Markdown

Maybe you could add a toggle similar to?:

wpi.sim.addGui().defaultEnabled = false

But:

wpi.parsing.enableStateMachineLoging = true

@Daniel1464 Daniel1464 force-pushed the stateMachineDiagram branch from 0ffa5b6 to d916a94 Compare June 2, 2026 03:18
@Eeshwar-Krishnan

Eeshwar-Krishnan commented Jun 2, 2026

Copy link
Copy Markdown

@codex review

(from discord: Testing to see if a non owner of the PR can kick off a review with their own credits)

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@Daniel1464

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d916a94f4a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +4 to +5
import com.github.javaparser.JavaParser;
import com.github.javaparser.ParserConfiguration;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add JavaParser to the plugin dependencies

This new task imports com.github.javaparser.*, but the commit does not add a JavaParser artifact to build.gradle (repo-wide search only finds these new imports/usages). As a result, a clean build of the plugin fails before users can run any GradleRIO task with package com.github.javaparser does not exist; please add the dependency to the plugin compile classpath.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaParser is a builtin dependency to the java-gradle-plugin

Comment on lines +133 to +134
var stateMachineDef = stateMachineDefs.getFirst().getVariable(0).getInitializer().orElseThrow();
var rawGraphName = stateMachineDef.asObjectCreationExpr().getArgument(0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid Java 21-only collection APIs

GradleRIO is still configured with Java 17 compatibility, but List.getFirst() is a Java 21 API. In environments building or running the plugin on JDK 17, this either fails to compile or produces a plugin that can throw NoSuchMethodError; use get(0) or another Java 17-compatible access pattern here and at the other new getFirst() calls.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants