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
|
||||
* Use the {@link #toString()} method to get the class as compilable, valid Java Code
|
||||
* @param classDiagram
|
||||
* @param packageString
|
||||
* @param manager
|
||||
* @param classDiagram The Class as UMLet text
|
||||
* @param packageString The String of the package, "" for no package
|
||||
* @param manager The UMLManager
|
||||
*/
|
||||
public UMLClass(String classDiagram, String packageString, UMLManager manager) {
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ public class UMLClass {
|
|||
this.fullName = name;
|
||||
}
|
||||
|
||||
this.name = lines[0].split(" ")[0];
|
||||
this.name = fullName.split(" ")[0];
|
||||
|
||||
System.arraycopy(lines, 1, linesBeheaded, 0, linesBeheaded.length);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,13 @@ public class UMLManager {
|
|||
*/
|
||||
public void parseClasses(ArrayList<String> classesText, String packagePath) {
|
||||
|
||||
String packageString = packagePath.replaceAll(".*src\\\\(.*)", "$1");
|
||||
packageString = packageString.replaceAll("\\\\", ".");
|
||||
String packageString;
|
||||
if(packagePath.matches(".src\\\\.+")){
|
||||
packageString = packagePath.replaceAll(".*src\\\\(.*)", "$1");
|
||||
packageString = packageString.replaceAll("\\\\", ".");
|
||||
} else {
|
||||
packageString = "";
|
||||
}
|
||||
|
||||
ArrayList<UMLClass> classes = new ArrayList<>();
|
||||
|
||||
|
|
@ -43,6 +48,7 @@ public class UMLManager {
|
|||
|
||||
for (UMLClass c : classes) {
|
||||
try {
|
||||
System.err.println(packagePath + "/" + c.getName() + ".java");
|
||||
String path = packagePath + "/" + c.getName() + ".java";
|
||||
FileWriter fw = new FileWriter(path);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
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
|
||||
|
|
@ -31,7 +30,7 @@ public class UMLMethod {
|
|||
this.manager = manager;
|
||||
|
||||
//check whether it's abstract
|
||||
if(line.matches("/.+/")){
|
||||
if (line.matches("/.+/")) {
|
||||
isAbstract = true;
|
||||
line = line.replaceAll("/(.+)/", "$1");
|
||||
} else {
|
||||
|
|
@ -41,7 +40,7 @@ public class UMLMethod {
|
|||
//First, format it nicely
|
||||
String formatted = line.replaceAll(Regex.METHOD_FIND_REGEX.pattern(), "$1;$4;$2;$3");
|
||||
String[] parts = formatted.split(";");
|
||||
if(!manager.isIgnoreEcapsulation()) {
|
||||
if (!manager.isIgnoreEcapsulation()) {
|
||||
this.encapsulation = switch (parts[0]) {
|
||||
case "+" -> "public ";
|
||||
case "-" -> "private ";
|
||||
|
|
@ -57,8 +56,11 @@ public class UMLMethod {
|
|||
|
||||
isConstructor = className.equals(name);
|
||||
|
||||
//parts[1] = returnType
|
||||
if (parts[1].equals("") && !isConstructor) {
|
||||
this.returnType = "void ";
|
||||
} else if (isConstructor) {
|
||||
this.returnType = "";
|
||||
} else {
|
||||
this.returnType = parts[1] + " ";
|
||||
}
|
||||
|
|
@ -105,7 +107,7 @@ public class UMLMethod {
|
|||
|
||||
returnString.append(")");
|
||||
|
||||
if(isAbstract){
|
||||
if (isAbstract) {
|
||||
returnString.append(";\n\n");
|
||||
} else {
|
||||
|
||||
|
|
@ -137,6 +139,7 @@ public class UMLMethod {
|
|||
|
||||
/**
|
||||
* Add a line to the method body
|
||||
*
|
||||
* @param line The line (not containing any linebreaks)
|
||||
*/
|
||||
public void addBodyLine(String line) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue