mirror of
https://github.com/Noratrieb/UMLetClassParser.git
synced 2026-01-14 16:45:05 +01:00
fixed package and constructor bugs
This commit is contained in:
parent
7e703aad33
commit
e6088b3547
3 changed files with 19 additions and 10 deletions
|
|
@ -16,9 +16,9 @@ public class UMLClass {
|
||||||
/**
|
/**
|
||||||
* Contains all information about a Java class loaded from a UMLet XML file
|
* Contains all information about a Java class loaded from a UMLet XML file
|
||||||
* Use the {@link #toString()} method to get the class as compilable, valid Java Code
|
* Use the {@link #toString()} method to get the class as compilable, valid Java Code
|
||||||
* @param classDiagram
|
* @param classDiagram The Class as UMLet text
|
||||||
* @param packageString
|
* @param packageString The String of the package, "" for no package
|
||||||
* @param manager
|
* @param manager The UMLManager
|
||||||
*/
|
*/
|
||||||
public UMLClass(String classDiagram, String packageString, UMLManager manager) {
|
public UMLClass(String classDiagram, String packageString, UMLManager manager) {
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class UMLClass {
|
||||||
this.fullName = name;
|
this.fullName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.name = lines[0].split(" ")[0];
|
this.name = fullName.split(" ")[0];
|
||||||
|
|
||||||
System.arraycopy(lines, 1, linesBeheaded, 0, linesBeheaded.length);
|
System.arraycopy(lines, 1, linesBeheaded, 0, linesBeheaded.length);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,13 @@ public class UMLManager {
|
||||||
*/
|
*/
|
||||||
public void parseClasses(ArrayList<String> classesText, String packagePath) {
|
public void parseClasses(ArrayList<String> classesText, String packagePath) {
|
||||||
|
|
||||||
String packageString = packagePath.replaceAll(".*src\\\\(.*)", "$1");
|
String packageString;
|
||||||
packageString = packageString.replaceAll("\\\\", ".");
|
if(packagePath.matches(".src\\\\.+")){
|
||||||
|
packageString = packagePath.replaceAll(".*src\\\\(.*)", "$1");
|
||||||
|
packageString = packageString.replaceAll("\\\\", ".");
|
||||||
|
} else {
|
||||||
|
packageString = "";
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<UMLClass> classes = new ArrayList<>();
|
ArrayList<UMLClass> classes = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -43,6 +48,7 @@ public class UMLManager {
|
||||||
|
|
||||||
for (UMLClass c : classes) {
|
for (UMLClass c : classes) {
|
||||||
try {
|
try {
|
||||||
|
System.err.println(packagePath + "/" + c.getName() + ".java");
|
||||||
String path = packagePath + "/" + c.getName() + ".java";
|
String path = packagePath + "/" + c.getName() + ".java";
|
||||||
FileWriter fw = new FileWriter(path);
|
FileWriter fw = new FileWriter(path);
|
||||||
BufferedWriter bw = new BufferedWriter(fw);
|
BufferedWriter bw = new BufferedWriter(fw);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores all information about a method in a class and converts it into Java code using the {@link #toString()} method
|
* Stores all information about a method in a class and converts it into Java code using the {@link #toString()} method
|
||||||
|
|
@ -31,7 +30,7 @@ public class UMLMethod {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
||||||
//check whether it's abstract
|
//check whether it's abstract
|
||||||
if(line.matches("/.+/")){
|
if (line.matches("/.+/")) {
|
||||||
isAbstract = true;
|
isAbstract = true;
|
||||||
line = line.replaceAll("/(.+)/", "$1");
|
line = line.replaceAll("/(.+)/", "$1");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -41,7 +40,7 @@ public class UMLMethod {
|
||||||
//First, format it nicely
|
//First, format it nicely
|
||||||
String formatted = line.replaceAll(Regex.METHOD_FIND_REGEX.pattern(), "$1;$4;$2;$3");
|
String formatted = line.replaceAll(Regex.METHOD_FIND_REGEX.pattern(), "$1;$4;$2;$3");
|
||||||
String[] parts = formatted.split(";");
|
String[] parts = formatted.split(";");
|
||||||
if(!manager.isIgnoreEcapsulation()) {
|
if (!manager.isIgnoreEcapsulation()) {
|
||||||
this.encapsulation = switch (parts[0]) {
|
this.encapsulation = switch (parts[0]) {
|
||||||
case "+" -> "public ";
|
case "+" -> "public ";
|
||||||
case "-" -> "private ";
|
case "-" -> "private ";
|
||||||
|
|
@ -57,8 +56,11 @@ public class UMLMethod {
|
||||||
|
|
||||||
isConstructor = className.equals(name);
|
isConstructor = className.equals(name);
|
||||||
|
|
||||||
|
//parts[1] = returnType
|
||||||
if (parts[1].equals("") && !isConstructor) {
|
if (parts[1].equals("") && !isConstructor) {
|
||||||
this.returnType = "void ";
|
this.returnType = "void ";
|
||||||
|
} else if (isConstructor) {
|
||||||
|
this.returnType = "";
|
||||||
} else {
|
} else {
|
||||||
this.returnType = parts[1] + " ";
|
this.returnType = parts[1] + " ";
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +107,7 @@ public class UMLMethod {
|
||||||
|
|
||||||
returnString.append(")");
|
returnString.append(")");
|
||||||
|
|
||||||
if(isAbstract){
|
if (isAbstract) {
|
||||||
returnString.append(";\n\n");
|
returnString.append(";\n\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
@ -137,6 +139,7 @@ public class UMLMethod {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a line to the method body
|
* Add a line to the method body
|
||||||
|
*
|
||||||
* @param line The line (not containing any linebreaks)
|
* @param line The line (not containing any linebreaks)
|
||||||
*/
|
*/
|
||||||
public void addBodyLine(String line) {
|
public void addBodyLine(String line) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue