A command line program to generate PlantUML class diagrams from Java files.
Written in C#; uses ANTLR 4 and its reference Java grammar to parse Java files.
- Install .NET 5.0 SDK
git clone https://github.com/stephen-riley/JavaPlantUmlGenerator.git
cd JavaPlantUmlGenerator
dotnet run -- /path/to/*.java > diagram.puml
This is a very simple project that illustrates how to use a pre-existing grammar and language tools to construct a simple "transpiler"; in this case, from Java source code to PlantUML class diagrams.
The structure of the program is quite simple. ANTLR is used to generate a lexer, parser, and Visitor base class from a Java 9 grammar. The ClassExtractor class subclasses the Visitor base and overrides a minimal number of methods to intercept certain points of the grammar; namely:
These overrides record information such as class names and members, which are then emitted in .puml
syntax by the Emit() method.