mirror of
https://github.com/Noratrieb/UMLetClassParser.git
synced 2026-01-14 16:45:05 +01:00
Encapsulation optional (WIP)
This commit is contained in:
parent
b202f6b9ad
commit
f8e81462a5
7 changed files with 121 additions and 36 deletions
|
|
@ -57,4 +57,18 @@ public abstract class Regex {
|
|||
* </ul>
|
||||
*/
|
||||
public static final Pattern ARG_SPLIT_REGEX = Pattern.compile(" *(\\w+) *: *(\\w+)");
|
||||
|
||||
public static final Pattern FIELD_FIND_REGEX_NO_ENCAPSULATION = Pattern.compile(" *(?<capsule>[+\\-~#])* *(?<name>\\w+) *: *(?<type>\\w+)");
|
||||
|
||||
public static final Pattern METHOD_FIND_REGEX_NO_ENCAPSULATION = Pattern.compile(" *(?<capsule>[+\\-~#])* *(?<name>\\w+) *\\( *(?<args>(?: *\\w+ *: *\\w+ *,? *)*) *\\) *(?:: *(?<return>\\w+))?");
|
||||
|
||||
|
||||
public static String getMethodPattern(boolean encapsulation){
|
||||
return encapsulation ? METHOD_FIND_REGEX_NO_ENCAPSULATION.pattern() : METHOD_FIND_REGEX.pattern();
|
||||
}
|
||||
|
||||
public static String getFieldPattern(boolean encapsulation){
|
||||
return encapsulation ? FIELD_FIND_REGEX_NO_ENCAPSULATION.pattern() : FIELD_FIND_REGEX.pattern();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ public class UMLClass {
|
|||
|
||||
for (String line : linesBeheaded) {
|
||||
if (line != null) {
|
||||
if (line.matches(Regex.METHOD_FIND_REGEX.pattern())) { //MATCHES METHOD
|
||||
if (line.matches(Regex.getMethodPattern(manager.isIgnoreEcapsulation()))) { //MATCHES METHOD
|
||||
methods.add(new UMLMethod(line, name, manager));
|
||||
} else if (line.matches(Regex.FIELD_FIND_REGEX.pattern())) { //MATCHES FIELD
|
||||
fields.add(new UMLField(line));
|
||||
} else if (line.matches(Regex.getFieldPattern(manager.isIgnoreEcapsulation()))) { //MATCHES FIELD
|
||||
fields.add(new UMLField(line, manager));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?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="6" 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="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="3" left="3" bottom="3" right="3"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
<children>
|
||||
<tabbedpane id="97eb">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="200" height="200"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
|
|
@ -105,7 +105,7 @@
|
|||
</tabbedpane>
|
||||
<component id="fa538" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Settings:"/>
|
||||
|
|
@ -113,7 +113,7 @@
|
|||
</component>
|
||||
<component id="8f883" class="javax.swing.JCheckBox" binding="watermarkBox">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="false"/>
|
||||
|
|
@ -123,25 +123,43 @@
|
|||
</component>
|
||||
<vspacer id="5f3c8">
|
||||
<constraints>
|
||||
<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"/>
|
||||
<grid row="6" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="fe6ca" class="javax.swing.JCheckBox" binding="generateGetSetButton">
|
||||
<component id="fe6ca" class="javax.swing.JCheckBox" binding="generateGetSetBox">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Generate Getter/Setter"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9da58" class="javax.swing.JCheckBox" binding="autoFillConstructor">
|
||||
<component id="9da58" class="javax.swing.JCheckBox" binding="autoFillConstructorBox">
|
||||
<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"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="3" 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>
|
||||
<component id="af39e" class="javax.swing.JCheckBox" binding="ignoreEncapsulationBox">
|
||||
<constraints>
|
||||
<grid row="5" 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="Ignore Encapsulation"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9a1ec" class="javax.swing.JTextField" binding="defaultEncapsulationField">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@ public class UMLClassView {
|
|||
private JButton convertFileButton;
|
||||
private JTextField packagePathField;
|
||||
private JCheckBox watermarkBox;
|
||||
private JCheckBox generateGetSetButton;
|
||||
private JCheckBox autoFillConstructor;
|
||||
private JCheckBox generateGetSetBox;
|
||||
private JCheckBox autoFillConstructorBox;
|
||||
private JCheckBox ignoreEncapsulationBox;
|
||||
private JTextField defaultEncapsulationField;
|
||||
|
||||
private UMLManager manager;
|
||||
|
||||
|
|
@ -72,20 +74,45 @@ public class UMLClassView {
|
|||
refreshTextArea();
|
||||
});
|
||||
|
||||
generateGetSetButton.addActionListener(new ActionListener() {
|
||||
generateGetSetBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
manager.setGetSetAuto(generateGetSetButton.isSelected());
|
||||
manager.setGetSetAuto(generateGetSetBox.isSelected());
|
||||
refreshTextArea();
|
||||
}
|
||||
});
|
||||
autoFillConstructor.addActionListener(new ActionListener() {
|
||||
autoFillConstructorBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
manager.setAutoGenerateConstructor(autoFillConstructor.isSelected());
|
||||
manager.setAutoGenerateConstructor(autoFillConstructorBox.isSelected());
|
||||
refreshTextArea();
|
||||
}
|
||||
});
|
||||
ignoreEncapsulationBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
manager.setIgnoreEcapsulation(ignoreEncapsulationBox.isSelected());
|
||||
defaultEncapsulationField.setEnabled(ignoreEncapsulationBox.isSelected());
|
||||
refreshTextArea();
|
||||
}
|
||||
});
|
||||
|
||||
defaultEncapsulationField.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
UMLManager.setDefaultEncapsulation(defaultEncapsulationField.getText() + " ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
UMLManager.setDefaultEncapsulation(defaultEncapsulationField.getText() + " ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
UMLManager.setDefaultEncapsulation(defaultEncapsulationField.getText() + " ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshTextArea(){
|
||||
|
|
@ -107,10 +134,10 @@ public class UMLClassView {
|
|||
}
|
||||
|
||||
public boolean isGetSetAutoSelected() {
|
||||
return generateGetSetButton.isSelected();
|
||||
return generateGetSetBox.isSelected();
|
||||
}
|
||||
|
||||
public boolean isAutoConstructorSelected() {
|
||||
return autoFillConstructor.isSelected();
|
||||
return autoFillConstructorBox.isSelected();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ public class UMLField {
|
|||
private final String name;
|
||||
private final String encapsulation;
|
||||
|
||||
private UMLManager manager;
|
||||
|
||||
private boolean valid;
|
||||
|
||||
/**
|
||||
|
|
@ -14,11 +16,14 @@ public class UMLField {
|
|||
*
|
||||
* @param line Format: "- name: String"
|
||||
*/
|
||||
public UMLField(String line) {
|
||||
public UMLField(String line, UMLManager manager) {
|
||||
this.manager = manager;
|
||||
|
||||
String formatted = line.replaceAll(Regex.FIELD_FIND_REGEX.pattern(), "$1;$3;$2");
|
||||
String formatted = line.replaceAll(Regex.getFieldPattern(manager.isIgnoreEcapsulation()), "$1;$3;$2");
|
||||
String[] formattedSplit = formatted.split(";");
|
||||
|
||||
if(!manager.isIgnoreEcapsulation()) {
|
||||
System.out.println("not ignore");
|
||||
this.encapsulation = switch (formattedSplit[0]) {
|
||||
case "+" -> "public ";
|
||||
case "-" -> "private ";
|
||||
|
|
@ -26,6 +31,9 @@ public class UMLField {
|
|||
case "~" -> "";
|
||||
default -> "[undefined] ";
|
||||
};
|
||||
} else {
|
||||
this.encapsulation = UMLManager.DEFAULT_ENCAPSULATION;
|
||||
}
|
||||
|
||||
this.name = formattedSplit[2];
|
||||
this.dataType = formattedSplit[1];
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class UMLManager {
|
||||
|
||||
public static String DEFAULT_ENCAPSULATION = "";
|
||||
private UMLClassView view;
|
||||
private boolean showWatermark;
|
||||
private boolean getSetAuto;
|
||||
private boolean autoFillConstructor;
|
||||
private boolean ignoreEcapsulation;
|
||||
|
||||
public UMLManager(UMLClassView view) {
|
||||
this.view = view;
|
||||
|
|
@ -76,4 +78,16 @@ public class UMLManager {
|
|||
public void setAutoGenerateConstructor(boolean selected) {
|
||||
autoFillConstructor = selected;
|
||||
}
|
||||
|
||||
public boolean isIgnoreEcapsulation() {
|
||||
return ignoreEcapsulation;
|
||||
}
|
||||
|
||||
public void setIgnoreEcapsulation(boolean ignoreEcapsulation) {
|
||||
this.ignoreEcapsulation = ignoreEcapsulation;
|
||||
}
|
||||
|
||||
public static void setDefaultEncapsulation(String defaultEncapsulation) {
|
||||
DEFAULT_ENCAPSULATION = defaultEncapsulation;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public class UMLMethod {
|
|||
|
||||
String formatted = line.replaceAll(Regex.METHOD_FIND_REGEX.pattern(), "$1;$4;$2;$3");
|
||||
String[] parts = formatted.split(";");
|
||||
if(!manager.isIgnoreEcapsulation()) {
|
||||
this.encapsulation = switch (parts[0]) {
|
||||
case "+" -> "public ";
|
||||
case "-" -> "private ";
|
||||
|
|
@ -39,6 +40,9 @@ public class UMLMethod {
|
|||
case "~" -> "";
|
||||
default -> "[undefined] ";
|
||||
};
|
||||
} else {
|
||||
this.encapsulation = UMLManager.DEFAULT_ENCAPSULATION;
|
||||
}
|
||||
|
||||
this.name = parts[2];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue