mirror of
https://github.com/Noratrieb/UMLetClassParser.git
synced 2026-01-14 16:45:05 +01:00
added uml parser classes
This commit is contained in:
parent
796e786d00
commit
09b837ca29
8 changed files with 398 additions and 0 deletions
6
.idea/discord.xml
generated
Normal file
6
.idea/discord.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="PROJECT_FILES" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
48
src/UMLClass.java
Normal file
48
src/UMLClass.java
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class UMLClass {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private ArrayList<UMLField> fields = new ArrayList<>();
|
||||||
|
private ArrayList<UMLMethod> methods = new ArrayList<>();
|
||||||
|
|
||||||
|
public UMLClass(String classDiagram) {
|
||||||
|
String[] lines = classDiagram.split("\n");
|
||||||
|
|
||||||
|
String[] linesBeheaded = new String[lines.length-1];
|
||||||
|
this.name = lines[0];
|
||||||
|
|
||||||
|
System.arraycopy(lines, 1, linesBeheaded, 0, linesBeheaded.length);
|
||||||
|
|
||||||
|
for (String line : linesBeheaded) {
|
||||||
|
if(line != null) {
|
||||||
|
if (line.matches("([+\\-~#]) (.+)\\((.*: .*,?)?\\):? ?(.+)?")) { //MATCHES METHOD
|
||||||
|
methods.add(new UMLMethod(line, name));
|
||||||
|
} else if (line.matches("([+\\-~#]) ((?:[a-z]|[A-Z]|[0-1])+): (.*)")) { //MATCHES FIELD
|
||||||
|
fields.add(new UMLField(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder s = new StringBuilder();
|
||||||
|
s.append("public class ").append(name).append(" {\n\n");
|
||||||
|
|
||||||
|
for (UMLField field : fields){
|
||||||
|
s.append(field.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
s.append("\n");
|
||||||
|
|
||||||
|
for (UMLMethod method : methods){
|
||||||
|
s.append(method.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
s.append("\n}");
|
||||||
|
|
||||||
|
return s.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/UMLClassView.form
Normal file
39
src/UMLClassView.form
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="UMLClassView">
|
||||||
|
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="500" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="aeb5e" class="javax.swing.JTextArea" binding="textArea1" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="66adb" class="javax.swing.JButton" binding="convertButton" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Convert"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="54ac1" class="javax.swing.JTextArea" binding="textArea2" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<editable value="false"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
||||||
39
src/UMLClassView.java
Normal file
39
src/UMLClassView.java
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class UMLClassView {
|
||||||
|
private JTextArea textArea1;
|
||||||
|
private JPanel panel1;
|
||||||
|
private JButton convertButton;
|
||||||
|
private JTextArea textArea2;
|
||||||
|
|
||||||
|
|
||||||
|
public UMLClassView() {
|
||||||
|
|
||||||
|
convertButton.addActionListener(e -> {
|
||||||
|
String text = textArea1.getText();
|
||||||
|
|
||||||
|
UMLClass umlClass = new UMLClass(text);
|
||||||
|
|
||||||
|
textArea2.setText(umlClass.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
textArea1.addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
String text = textArea1.getText();
|
||||||
|
|
||||||
|
UMLClass umlClass = new UMLClass(text);
|
||||||
|
|
||||||
|
textArea2.setText(umlClass.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public JPanel getPanel1() {
|
||||||
|
return panel1;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/UMLConverterMain.java
Normal file
18
src/UMLConverterMain.java
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class UMLConverterMain {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
frame.setContentPane( new UMLClassView().getPanel1());
|
||||||
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
44
src/UMLField.java
Normal file
44
src/UMLField.java
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
public class UMLField {
|
||||||
|
|
||||||
|
private String dataType;
|
||||||
|
private String name;
|
||||||
|
private String encapsulation;
|
||||||
|
|
||||||
|
private boolean valid;
|
||||||
|
|
||||||
|
public UMLField(String dataType, String name, String encapsulation) {
|
||||||
|
this.dataType = dataType;
|
||||||
|
this.name = name;
|
||||||
|
this.encapsulation = encapsulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New Field from UML line
|
||||||
|
*
|
||||||
|
* @param line Format: "- name: String"
|
||||||
|
*/
|
||||||
|
public UMLField(String line) {
|
||||||
|
|
||||||
|
String formatted = line.replaceAll("([+\\-~#]) ((?:[a-z]|[A-Z]|[0-1])+): (.*)", "$1;$3;$2");
|
||||||
|
System.out.println(formatted);
|
||||||
|
String[] formattedSplit = formatted.split(";");
|
||||||
|
|
||||||
|
this.encapsulation = switch (formattedSplit[0]) {
|
||||||
|
case "+" -> "public ";
|
||||||
|
case "-" -> "private ";
|
||||||
|
case "#" -> "protected ";
|
||||||
|
case "~" -> "";
|
||||||
|
default -> "[undefined] ";
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = formattedSplit[2];
|
||||||
|
this.dataType = formattedSplit[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return " " + encapsulation + dataType + " " + name + ";\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
80
src/UMLMethod.java
Normal file
80
src/UMLMethod.java
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class UMLMethod {
|
||||||
|
|
||||||
|
private String returnType;
|
||||||
|
private String name;
|
||||||
|
private String encapsulation;
|
||||||
|
|
||||||
|
private ArrayList<String> argsNames = new ArrayList<>();
|
||||||
|
private ArrayList<String> argsTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
public UMLMethod(String encapsulation, String returnType, String name, ArrayList<String> argsNames, ArrayList<String> argsTypes) {
|
||||||
|
this.returnType = returnType;
|
||||||
|
this.name = name;
|
||||||
|
this.argsNames = argsNames;
|
||||||
|
this.argsTypes = argsTypes;
|
||||||
|
this.encapsulation = encapsulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UMLMethod(String line, String className) {
|
||||||
|
|
||||||
|
//First, format it nicely
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formatted line:
|
||||||
|
* EncapsulationIndicator;
|
||||||
|
* retunType("" for void);
|
||||||
|
* name;
|
||||||
|
* args in the UML format
|
||||||
|
*/
|
||||||
|
String formatted = line.replaceAll("([+\\-~#]) (.+)\\((.*: .*,?)?\\):? ?(.+)?", "$1;$4;$2;$3");
|
||||||
|
String[] parts = formatted.split(";");
|
||||||
|
this.encapsulation = switch (parts[0]) {
|
||||||
|
case "+" -> "public ";
|
||||||
|
case "-" -> "private ";
|
||||||
|
case "#" -> "protected ";
|
||||||
|
case "~" -> "";
|
||||||
|
default -> "[undefined] ";
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = parts[2];
|
||||||
|
|
||||||
|
|
||||||
|
if(parts[1].equals("") && !className.equals(name)){
|
||||||
|
this.returnType = "void";
|
||||||
|
} else {
|
||||||
|
this.returnType = parts[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parts.length == 4) {
|
||||||
|
String args = parts[3];
|
||||||
|
String[] argsSplit = args.split(",");
|
||||||
|
|
||||||
|
for (String s : argsSplit) {
|
||||||
|
String argFormatted = s.replaceAll(" ?(.*): (.*)", "$1;$2");
|
||||||
|
String[] formattedSplit = argFormatted.split(";");
|
||||||
|
argsNames.add(formattedSplit[0]);
|
||||||
|
argsTypes.add(formattedSplit[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder returnString = new StringBuilder();
|
||||||
|
returnString.append("\n ").append(encapsulation).append(returnType).append(" ").append(name).append(" (");
|
||||||
|
|
||||||
|
for (int i = 0; i < argsNames.size(); i++) {
|
||||||
|
returnString.append(argsTypes.get(i)).append(" ").append(argsNames.get(i));
|
||||||
|
if (i != argsNames.size() - 1) {
|
||||||
|
returnString.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
returnString.append(") {\n \n }\n");
|
||||||
|
|
||||||
|
return returnString.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue