added uml parser classes

This commit is contained in:
nora 2020-11-19 19:14:00 +01:00
parent 796e786d00
commit 09b837ca29
8 changed files with 398 additions and 0 deletions

44
src/UMLField.java Normal file
View 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";
}
}