mirror of
https://github.com/Noratrieb/UMLetClassParser.git
synced 2026-01-14 16:45:05 +01:00
Auto Generate constructor
This commit is contained in:
parent
e3643765ec
commit
b202f6b9ad
5 changed files with 51 additions and 5 deletions
|
|
@ -36,7 +36,7 @@ public class UMLClass {
|
||||||
for (String line : linesBeheaded) {
|
for (String line : linesBeheaded) {
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
if (line.matches(Regex.METHOD_FIND_REGEX.pattern())) { //MATCHES METHOD
|
if (line.matches(Regex.METHOD_FIND_REGEX.pattern())) { //MATCHES METHOD
|
||||||
methods.add(new UMLMethod(line, name));
|
methods.add(new UMLMethod(line, name, manager));
|
||||||
} else if (line.matches(Regex.FIELD_FIND_REGEX.pattern())) { //MATCHES FIELD
|
} else if (line.matches(Regex.FIELD_FIND_REGEX.pattern())) { //MATCHES FIELD
|
||||||
fields.add(new UMLField(line));
|
fields.add(new UMLField(line));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="UMLClassView">
|
<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="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="3" left="3" bottom="3" right="3"/>
|
<margin top="3" left="3" bottom="3" right="3"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="20" y="20" width="500" height="400"/>
|
<xy x="20" y="20" width="500" height="400"/>
|
||||||
|
|
@ -123,7 +123,7 @@
|
||||||
</component>
|
</component>
|
||||||
<vspacer id="5f3c8">
|
<vspacer id="5f3c8">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</vspacer>
|
</vspacer>
|
||||||
<component id="fe6ca" class="javax.swing.JCheckBox" binding="generateGetSetButton">
|
<component id="fe6ca" class="javax.swing.JCheckBox" binding="generateGetSetButton">
|
||||||
|
|
@ -134,6 +134,14 @@
|
||||||
<text value="Generate Getter/Setter"/>
|
<text value="Generate Getter/Setter"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
|
<component id="9da58" class="javax.swing.JCheckBox" binding="autoFillConstructor">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Auto-Fill Contructor"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ public class UMLClassView {
|
||||||
private JTextField packagePathField;
|
private JTextField packagePathField;
|
||||||
private JCheckBox watermarkBox;
|
private JCheckBox watermarkBox;
|
||||||
private JCheckBox generateGetSetButton;
|
private JCheckBox generateGetSetButton;
|
||||||
|
private JCheckBox autoFillConstructor;
|
||||||
|
|
||||||
private UMLManager manager;
|
private UMLManager manager;
|
||||||
|
|
||||||
|
|
@ -78,6 +79,13 @@ public class UMLClassView {
|
||||||
refreshTextArea();
|
refreshTextArea();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
autoFillConstructor.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
manager.setAutoGenerateConstructor(autoFillConstructor.isSelected());
|
||||||
|
refreshTextArea();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshTextArea(){
|
private void refreshTextArea(){
|
||||||
|
|
@ -101,4 +109,8 @@ public class UMLClassView {
|
||||||
public boolean isGetSetAutoSelected() {
|
public boolean isGetSetAutoSelected() {
|
||||||
return generateGetSetButton.isSelected();
|
return generateGetSetButton.isSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAutoConstructorSelected() {
|
||||||
|
return autoFillConstructor.isSelected();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,13 @@ public class UMLManager {
|
||||||
private UMLClassView view;
|
private UMLClassView view;
|
||||||
private boolean showWatermark;
|
private boolean showWatermark;
|
||||||
private boolean getSetAuto;
|
private boolean getSetAuto;
|
||||||
|
private boolean autoFillConstructor;
|
||||||
|
|
||||||
public UMLManager(UMLClassView view) {
|
public UMLManager(UMLClassView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.showWatermark = view.isWatermarkSelected();
|
this.showWatermark = view.isWatermarkSelected();
|
||||||
this.getSetAuto = view.isGetSetAutoSelected();
|
this.getSetAuto = view.isGetSetAutoSelected();
|
||||||
|
this.autoFillConstructor = view.isAutoConstructorSelected();
|
||||||
view.setManager(this);
|
view.setManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,4 +68,12 @@ public class UMLManager {
|
||||||
public boolean isGetSetAuto() {
|
public boolean isGetSetAuto() {
|
||||||
return getSetAuto;
|
return getSetAuto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAutoFillConstructor(){
|
||||||
|
return autoFillConstructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoGenerateConstructor(boolean selected) {
|
||||||
|
autoFillConstructor = selected;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,10 @@ public class UMLMethod {
|
||||||
private final ArrayList<String> argsNames = new ArrayList<>();
|
private final ArrayList<String> argsNames = new ArrayList<>();
|
||||||
private final ArrayList<String> argsTypes = new ArrayList<>();
|
private final ArrayList<String> argsTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
private boolean isConstructor;
|
||||||
|
|
||||||
|
private UMLManager manager;
|
||||||
|
|
||||||
private String methodBody = "";
|
private String methodBody = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -20,7 +24,9 @@ public class UMLMethod {
|
||||||
* @param line The line in the UML diagram
|
* @param line The line in the UML diagram
|
||||||
* @param className The name of the class
|
* @param className The name of the class
|
||||||
*/
|
*/
|
||||||
public UMLMethod(String line, String className) {
|
public UMLMethod(String line, String className, UMLManager manager) {
|
||||||
|
|
||||||
|
this.manager = manager;
|
||||||
|
|
||||||
//First, format it nicely
|
//First, format it nicely
|
||||||
|
|
||||||
|
|
@ -36,8 +42,11 @@ public class UMLMethod {
|
||||||
|
|
||||||
this.name = parts[2];
|
this.name = parts[2];
|
||||||
|
|
||||||
|
if(className.equals(name)){
|
||||||
|
isConstructor = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (parts[1].equals("") && !className.equals(name)) {
|
if (parts[1].equals("") && !isConstructor) {
|
||||||
this.returnType = "void ";
|
this.returnType = "void ";
|
||||||
} else {
|
} else {
|
||||||
this.returnType = parts[1] + " ";
|
this.returnType = parts[1] + " ";
|
||||||
|
|
@ -82,6 +91,13 @@ public class UMLMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
returnString.append(") {\n ");
|
returnString.append(") {\n ");
|
||||||
|
|
||||||
|
if(isConstructor && manager.isAutoFillConstructor()){
|
||||||
|
for (String argsName : argsNames) {
|
||||||
|
addBodyLine("this." + argsName + " = " + argsName + ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
returnString.append(methodBody);
|
returnString.append(methodBody);
|
||||||
returnString.append("\n }\n");
|
returnString.append("\n }\n");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue