This repository provides a Java-based utility for generating source code from pseudo-UML diagrams exported as .drawio files. It parses the XML structure of your diagrams to automatically create class files, including support for inheritance and composition.
The CodeGenerator reads XML-based diagram files and converts visual components—such as "Things" and "Abstract Things"—into a structured Java project.
| File/Directory | Description |
|---|---|
Diagrams/*.drawio |
XML diagram files defining the classes and relationships. |
src/ |
The core Java logic for parsing and file generation. |
GeneratedCode/ |
The destination directory for the generated .java source files. |
To ensure successful code generation, diagrams must follow specific visual rules defined in the system legend:
- Classes: Represented by standard rectangles (rounded=0). These generate standard Java classes.
- Abstract Classes: Represented by rounded rectangles (rounded=1). These generate
public abstract classdefinitions. - "Has-a" (Composition): Use a flex arrow (shape=flexArrow) with cardinality (e.g.,
(1)or(N)) pointing from the owner to the component. These generate private fields in the parent class. - "Is-a" (Inheritance): Use a standard arrow pointing from the subclass to the superclass. These generate the
extendskeyword in the subclass.
git clone <repository-url>
cd CodeGenerator
Open src/Main.java and update the local file paths to match your environment:
final String filePath = "C:\\path\\to\\your\\Diagram.drawio";
final String outputDirectory = "C:\\path\\to\\output\\folder\\";Ensure you have a Java Development Kit (JDK) installed, then compile the project classes:
javac src/*.java
The tool is designed to process individual diagram files and generate a complete set of Java classes based on the detected vertices and edges.
Run the compiled Main class to execute the parsing and generation logic:
java -cp src Main
If processing a diagram with a "Restaurant" class composed of "Chef" and "Waiter", the tool will generate Restaurant.java with the following structure:
public class Restaurant {
private Chef chef;
private Waiter waiter;
// ...
}Tip
Cardinality Support: The generator uses flex arrows to determine which classes are "contained" within others, allowing for rapid prototyping of complex system architectures.