diff --git a/README.md b/README.md
index 0da5389..f0fb96c 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,7 @@
A tool for the reverse engineering of Java object-oriented source code into Unified Modeling Language (UML) diagrams
+![workflow][workflow-url]
[![Contributors][contributors-shield]][contributors-url]
[![Commits][commits-shield]][commits-url]
[![Forks][forks-shield]][forks-url]
@@ -152,6 +153,7 @@ See [License][license-url] for more information regarding the license
## Acknowledgments
+[workflow-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer/actions/workflows/maven.yml/badge.svg
[contributors-shield]: https://img.shields.io/github/contributors/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer
[contributors-url]: https://github.com/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer/graphs/contributors
[commits-shield]: https://img.shields.io/github/last-commit/DAINTINESS-Group/ObjectOrientedArchitectureDiagrammer
diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java
index bef78d6..87c9bc6 100644
--- a/src/main/java/controller/Controller.java
+++ b/src/main/java/controller/Controller.java
@@ -68,7 +68,7 @@ public interface Controller {
SmartGraphPanel visualizeJavaFXGraph();
/**
- * This method creates the Loaded Diagram's JavaFX graphView by calling the DiagramManager's visualizeLoadedJavaFXGraph method.
+ * This method creates the loaded Diagram's JavaFX graphView by calling the DiagramManager's visualizeLoadedJavaFXGraph method.
*
* @return the created graphView
*/
diff --git a/src/main/java/controller/ControllerFactory.java b/src/main/java/controller/ControllerFactory.java
index 9a8510f..74f2e0b 100644
--- a/src/main/java/controller/ControllerFactory.java
+++ b/src/main/java/controller/ControllerFactory.java
@@ -3,10 +3,9 @@
public class ControllerFactory {
public static Controller createController(String controllerType, String diagramType) {
- if (ControllerType.get(controllerType) == ControllerType.UML) {
- return new DiagramController(diagramType);
- }else {
- throw new RuntimeException();
- }
+ return switch (ControllerType.get(controllerType)) {
+ case UML -> new DiagramController(diagramType);
+ };
}
+
}
diff --git a/src/main/java/controller/ControllerType.java b/src/main/java/controller/ControllerType.java
index df9a9a8..af21026 100644
--- a/src/main/java/controller/ControllerType.java
+++ b/src/main/java/controller/ControllerType.java
@@ -21,7 +21,9 @@ public static ControllerType get(String controllerType) {
return CONTROLLER_TYPE.get(controllerType.toLowerCase());
}
+ @Override
public String toString() {
return super.toString().toLowerCase();
}
+
}
diff --git a/src/main/java/manager/ClassDiagramManager.java b/src/main/java/manager/ClassDiagramManager.java
index 88b4407..ce840be 100644
--- a/src/main/java/manager/ClassDiagramManager.java
+++ b/src/main/java/manager/ClassDiagramManager.java
@@ -36,9 +36,8 @@ public ClassDiagramManager() {
@Override
public SourceProject createSourceProject(Path sourcePackagePath) {
- SourceProject sourceProject = new SourceProject(classDiagram);
- sourceProject.createGraph(sourcePackagePath);
- sourceProject.setClassDiagramSinkVertices();
+ SourceProject sourceProject = new SourceProject();
+ sourceProject.createClassGraph(sourcePackagePath, classDiagram);
return sourceProject;
}
@@ -119,9 +118,11 @@ public SmartGraphPanel applyLayout() {
if (!nodesGeometry.containsKey(vertex.element())) {
continue;
}
+
Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1());
}
+
return graphView;
}
@@ -131,9 +132,11 @@ public SmartGraphPanel applySpecificLayout(String choice){
if (!nodesGeometry.containsKey(vertex.element())) {
continue;
}
+
Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1());
}
+
return graphView;
}
diff --git a/src/main/java/manager/DiagramManagerFactory.java b/src/main/java/manager/DiagramManagerFactory.java
index fd6242d..cf7dd24 100644
--- a/src/main/java/manager/DiagramManagerFactory.java
+++ b/src/main/java/manager/DiagramManagerFactory.java
@@ -4,7 +4,7 @@ public class DiagramManagerFactory {
public static DiagramManager createDiagramManager(String diagramType) {
return switch (DiagramType.get(diagramType)) {
- case CLASS -> new ClassDiagramManager();
+ case CLASS -> new ClassDiagramManager();
case PACKAGE -> new PackageDiagramManager();
};
}
diff --git a/src/main/java/manager/DiagramType.java b/src/main/java/manager/DiagramType.java
index e0166b8..471e97b 100644
--- a/src/main/java/manager/DiagramType.java
+++ b/src/main/java/manager/DiagramType.java
@@ -15,6 +15,7 @@ public enum DiagramType {
for (DiagramType diagramType: DiagramType.values()) {
map.put(diagramType.toString().toLowerCase(), diagramType);
}
+
DIAGRAM_TYPE = Collections.unmodifiableMap(map);
}
@@ -22,7 +23,9 @@ public static DiagramType get(String diagramType) {
return DIAGRAM_TYPE.get(diagramType.toLowerCase().trim());
}
+ @Override
public String toString() {
return super.toString().toLowerCase();
}
+
}
diff --git a/src/main/java/manager/PackageDiagramManager.java b/src/main/java/manager/PackageDiagramManager.java
index be64d92..d44aed4 100644
--- a/src/main/java/manager/PackageDiagramManager.java
+++ b/src/main/java/manager/PackageDiagramManager.java
@@ -40,9 +40,8 @@ public PackageDiagramManager() {
@Override
public SourceProject createSourceProject(Path sourcePackagePath) {
- SourceProject sourceProject = new SourceProject(packageDiagram);
- sourceProject.createGraph(sourcePackagePath);
- sourceProject.setPackageDiagramVertices();
+ SourceProject sourceProject = new SourceProject();
+ sourceProject.createPackageGraph(sourcePackagePath, packageDiagram);
return sourceProject;
}
@@ -52,7 +51,7 @@ public void convertTreeToDiagram(List chosenFilesNames) {
}
@Override
- public void arrangeDiagram(){
+ public void arrangeDiagram() {
packageDiagramArrangement = new PackageDiagramArrangementManager(packageDiagram);
DiagramGeometry diagramGeometry = packageDiagramArrangement.arrangeDiagram();
packageDiagram.setDiagramGeometry(diagramGeometry);
@@ -120,21 +119,25 @@ public SmartGraphPanel applyLayout() {
logger.log(Level.INFO, vertex.element());
continue;
}
+
Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1());
}
+
return graphView;
}
public SmartGraphPanel applySpecificLayout(String choice){
DiagramGeometry nodesGeometry = packageDiagramArrangement.applyNewLayout(choice);
for(Vertex vertex : vertexCollection) {
- if(!nodesGeometry.containsKey(vertex.element())) {
+ if (!nodesGeometry.containsKey(vertex.element())) {
continue;
}
+
Pair coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1());
}
+
return graphView;
}
diff --git a/src/main/java/manager/SourceProject.java b/src/main/java/manager/SourceProject.java
index c859ab8..e476a00 100644
--- a/src/main/java/manager/SourceProject.java
+++ b/src/main/java/manager/SourceProject.java
@@ -8,31 +8,17 @@
public class SourceProject {
- private static Interpreter interpreter;
- private static ClassDiagram classDiagram;
- private static PackageDiagram packageDiagram;
+ private final Interpreter interpreter = new Interpreter();
- public SourceProject(ClassDiagram classDiagram) {
- interpreter = new Interpreter();
- SourceProject.classDiagram = classDiagram;
- }
-
- public SourceProject(PackageDiagram packageDiagram) {
- interpreter = new Interpreter();
- SourceProject.packageDiagram = packageDiagram;
- }
-
-
- public void createGraph(Path sourcePackagePath) {
+ public void createClassGraph(Path sourcePackagePath, ClassDiagram classDiagram) {
interpreter.parseProject(sourcePackagePath);
interpreter.convertTreeToGraph();
- }
-
- public void setClassDiagramSinkVertices() {
classDiagram.setSinkVertices(interpreter.getSinkVertices());
}
- public void setPackageDiagramVertices() {
+ public void createPackageGraph(Path sourcePackagePath, PackageDiagram packageDiagram) {
+ interpreter.parseProject(sourcePackagePath);
+ interpreter.convertTreeToGraph();
packageDiagram.setVertices(interpreter.getVertices());
}
diff --git a/src/main/java/model/diagram/ClassDiagram.java b/src/main/java/model/diagram/ClassDiagram.java
index 2de35ef..c4c9226 100644
--- a/src/main/java/model/diagram/ClassDiagram.java
+++ b/src/main/java/model/diagram/ClassDiagram.java
@@ -27,7 +27,7 @@ public ClassDiagram() {
public void createNewDiagram(List chosenFilesNames) {
createGraphNodes(chosenFilesNames);
- createDiagram(this.graphNodes.keySet());
+ createDiagram(graphNodes.keySet());
}
public void createDiagram(Set sinkVertices) {
@@ -38,7 +38,7 @@ public void createDiagram(Set sinkVertices) {
private void createGraphNodes(List chosenFileNames) {
int nodeId = 0;
for (ClassifierVertex classifierVertex : getChosenNodes(chosenFileNames)) {
- this.graphNodes.put(classifierVertex, nodeId);
+ graphNodes.put(classifierVertex, nodeId);
nodeId++;
}
}
diff --git a/src/main/java/model/diagram/GraphClassDiagramConverter.java b/src/main/java/model/diagram/GraphClassDiagramConverter.java
index 8095c29..9527311 100644
--- a/src/main/java/model/diagram/GraphClassDiagramConverter.java
+++ b/src/main/java/model/diagram/GraphClassDiagramConverter.java
@@ -15,20 +15,20 @@ public class GraphClassDiagramConverter {
public GraphClassDiagramConverter(Set sinkVertices) {
this.sinkVertices = sinkVertices;
- this.adjacencyList = new HashMap<>();
+ adjacencyList = new HashMap<>();
}
public Map>> convertGraphToClassDiagram() {
- for (ClassifierVertex classifierVertex : this.sinkVertices) {
- this.adjacencyList.put(classifierVertex, new HashSet<>());
+ for (ClassifierVertex classifierVertex : sinkVertices) {
+ adjacencyList.put(classifierVertex, new HashSet<>());
for (Arc arc: classifierVertex.getArcs()) {
- if (!this.sinkVertices.contains(arc.targetVertex())) {
+ if (!sinkVertices.contains(arc.targetVertex())) {
continue;
}
- this.adjacencyList.get(arc.sourceVertex()).add(arc);
+ adjacencyList.get(arc.sourceVertex()).add(arc);
}
}
- return this.adjacencyList;
+ return adjacencyList;
}
}
diff --git a/src/main/java/model/diagram/GraphPackageDiagramConverter.java b/src/main/java/model/diagram/GraphPackageDiagramConverter.java
index a13f513..7479498 100644
--- a/src/main/java/model/diagram/GraphPackageDiagramConverter.java
+++ b/src/main/java/model/diagram/GraphPackageDiagramConverter.java
@@ -15,20 +15,21 @@ public class GraphPackageDiagramConverter {
public GraphPackageDiagramConverter(Set vertices) {
this.vertices = vertices;
- this.adjacencyList = new HashMap<>();
+ adjacencyList = new HashMap<>();
}
public Map>> convertGraphToPackageDiagram() {
- for (PackageVertex vertex: this.vertices) {
- this.adjacencyList.put(vertex, new HashSet<>());
+ for (PackageVertex vertex: vertices) {
+ adjacencyList.put(vertex, new HashSet<>());
for (Arc arc: vertex.getArcs()) {
- if (!this.vertices.contains(arc.targetVertex())) {
+ if (!vertices.contains(arc.targetVertex())) {
continue;
}
- this.adjacencyList.get(arc.sourceVertex()).add(arc);
+ adjacencyList.get(arc.sourceVertex()).add(arc);
}
}
- return this.adjacencyList;
+
+ return adjacencyList;
}
}
diff --git a/src/main/java/model/diagram/PackageDiagram.java b/src/main/java/model/diagram/PackageDiagram.java
index 3ee5f51..6f854dd 100644
--- a/src/main/java/model/diagram/PackageDiagram.java
+++ b/src/main/java/model/diagram/PackageDiagram.java
@@ -10,7 +10,7 @@
public class PackageDiagram {
- private final Map graphNodes;
+ private final Map graphNodes;
private static Map>> diagram;
private static Map vertices;
private static Map> diagramGeometryGraphML;
@@ -22,7 +22,7 @@ public PackageDiagram() {
public void createNewDiagram(List chosenFileNames) {
createGraphNodes(chosenFileNames);
- createDiagram(this.graphNodes.keySet());
+ createDiagram(graphNodes.keySet());
}
public void createDiagram(Set vertices) {
@@ -33,7 +33,7 @@ public void createDiagram(Set vertices) {
private void createGraphNodes(List chosenFileNames) {
int nodeId = 0;
for (PackageVertex vertex: getChosenNodes(chosenFileNames)) {
- this.graphNodes.put(vertex, nodeId);
+ graphNodes.put(vertex, nodeId);
nodeId++;
}
}
diff --git a/src/main/java/model/diagram/ShadowCleaner.java b/src/main/java/model/diagram/ShadowCleaner.java
index 923d3bf..cebd1f1 100644
--- a/src/main/java/model/diagram/ShadowCleaner.java
+++ b/src/main/java/model/diagram/ShadowCleaner.java
@@ -14,21 +14,22 @@ public class ShadowCleaner {
ArcType.AGGREGATION,
ArcType.ASSOCIATION);
- private final ClassDiagram classDiagram;
+ private final ClassDiagram classDiagram;
public ShadowCleaner(ClassDiagram diagram) {
this.classDiagram = diagram;
}
public Map>> shadowWeakRelationships() {
- for (Set> arcs: this.classDiagram.getDiagram().values()) {
+ for (Set> arcs: classDiagram.getDiagram().values()) {
Map>> shadowedArcs = new HashMap<>();
for (Arc arc: arcs) {
- shadowedArcs.computeIfAbsent(arc.targetVertex(), sinkVertex -> new ArrayList<>()).add(arc);
+ shadowedArcs.computeIfAbsent(arc.targetVertex(),
+ sinkVertex -> new ArrayList<>()).add(arc);
}
for (Map.Entry>> arc: shadowedArcs.entrySet()) {
- if (!doWeakRelationshipsExist(arc)) {
+ if (!(arc.getValue().size() > 1)) {
continue;
}
for (ArcType arcType: strongerToWeakerArcTypes) {
@@ -40,14 +41,12 @@ public Map>> shadowWeakRelationships
}
}
}
- return this.classDiagram.getDiagram();
- }
- private boolean doWeakRelationshipsExist(Map.Entry>> arc) {
- return arc.getValue().size() > 1;
+ return classDiagram.getDiagram();
}
- private boolean doesStrongerRelationshipExist(List> arc, ArcType arcType) {
+ private boolean doesStrongerRelationshipExist(List> arc,
+ ArcType arcType) {
Optional> inheritanceArc = arc
.stream()
.filter(sinkVertexArc -> sinkVertexArc.arcType().equals(arcType))
@@ -55,7 +54,11 @@ private boolean doesStrongerRelationshipExist(List> arc, A
return inheritanceArc.isPresent();
}
- private void removeWeakerRelationships(Set> arcs, ClassifierVertex classifierVertex, ArcType arcType) {
- arcs.removeIf(arc -> arc.targetVertex().equals(classifierVertex) && !arc.arcType().equals(arcType));
+ private void removeWeakerRelationships(Set> arcs,
+ ClassifierVertex classifierVertex,
+ ArcType arcType) {
+ arcs.removeIf(arc ->
+ arc.targetVertex().equals(classifierVertex) &&
+ !arc.arcType().equals(arcType));
}
}
diff --git a/src/main/java/model/diagram/arrangement/ClassDiagramArrangementManager.java b/src/main/java/model/diagram/arrangement/ClassDiagramArrangementManager.java
index 6517965..dffd5c9 100644
--- a/src/main/java/model/diagram/arrangement/ClassDiagramArrangementManager.java
+++ b/src/main/java/model/diagram/arrangement/ClassDiagramArrangementManager.java
@@ -24,6 +24,8 @@
public class ClassDiagramArrangementManager implements DiagramArrangementManagerInterface{
public static final LayoutAlgorithmType LAYOUT_ALGORITHM_TYPE = LayoutAlgorithmType.SUGIYAMA;
+ public static final int WIDTH = 1500;
+ public static final int HEIGHT = 1000;
private final ClassDiagram classDiagram;
private final Graph graph;
@@ -34,68 +36,70 @@ public ClassDiagramArrangementManager(ClassDiagram classDiagram) {
@Override
public Map> arrangeGraphMLDiagram() {
- Map> nodesGeometryGraphML = new HashMap<>();
- Graph graph = createGraph();
- AbstractLayout layout = new SpringLayout<>(graph);
- layout.setSize(new Dimension(1500, 1000));
- for (Integer i : this.classDiagram.getGraphNodes().values()) {
+ Map> nodesGeometryGraphML = new HashMap<>();
+ Graph graph = createGraph();
+ AbstractLayout layout = new SpringLayout<>(graph);
+ layout.setSize(new Dimension(WIDTH, HEIGHT));
+ for (Integer i : classDiagram.getGraphNodes().values()) {
nodesGeometryGraphML.put(i, new Pair<>(layout.getX(i), layout.getY(i)));
}
+
return nodesGeometryGraphML;
}
@Override
public DiagramGeometry arrangeDiagram() {
LayoutAlgorithm layoutAlgorithm = LayoutAlgorithmFactory.createLayoutAlgorithm(LAYOUT_ALGORITHM_TYPE);
- layoutAlgorithm.setGraph(this.graph);
+ layoutAlgorithm.setGraph(graph);
return layoutAlgorithm.arrangeDiagram();
}
@Override
public DiagramGeometry applyNewLayout(String algorithmType){
LayoutAlgorithmType algorithmEnumType = LayoutAlgorithmType.valueOf(algorithmType.toUpperCase());
- LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType);
- layout.setGraph(this.graph);
+ LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType);
+ layout.setGraph(graph);
return layout.arrangeDiagram();
}
private Graph createGraph(){
Graph graph = new SparseGraph<>();
- for (Integer nodeId: this.classDiagram.getGraphNodes().values()) {
+ for (Integer nodeId: classDiagram.getGraphNodes().values()) {
graph.addVertex(nodeId);
}
List> arcs = new ArrayList<>();
- for (Set> arcSet: this.classDiagram.getDiagram().values()) {
+ for (Set> arcSet: classDiagram.getDiagram().values()) {
arcs.addAll(arcSet);
}
for (Arc arc: arcs) {
- graph.addEdge(
- this.classDiagram.getGraphNodes().get(arc.sourceVertex()) + " " + this.classDiagram.getGraphNodes().get(arc.targetVertex()),
- this.classDiagram.getGraphNodes().get(arc.sourceVertex()),
- this.classDiagram.getGraphNodes().get(arc.targetVertex()), EdgeType.DIRECTED);
+ graph.addEdge(classDiagram.getGraphNodes().get(arc.sourceVertex()) + " " + classDiagram.getGraphNodes().get(arc.targetVertex()),
+ classDiagram.getGraphNodes().get(arc.sourceVertex()),
+ classDiagram.getGraphNodes().get(arc.targetVertex()),
+ EdgeType.DIRECTED);
}
+
return graph;
}
private Graph createGraphWithStrings(){
Graph graph = new SparseGraph<>();
- for (ClassifierVertex vertex: this.classDiagram.getGraphNodes().keySet()) {
+ for (ClassifierVertex vertex: classDiagram.getGraphNodes().keySet()) {
graph.addVertex(vertex.getName());
}
List> arcs = new ArrayList<>();
- for (Set> arcSet: this.classDiagram.getDiagram().values()) {
+ for (Set> arcSet: classDiagram.getDiagram().values()) {
arcs.addAll(arcSet);
}
for (Arc arc: arcs) {
- graph.addEdge(
- arc.sourceVertex().getName() + " " + arc.targetVertex().getName(),
- arc.sourceVertex().getName(),
- arc.targetVertex().getName(), EdgeType.DIRECTED);
+ graph.addEdge(arc.sourceVertex().getName() + " " + arc.targetVertex().getName(),
+ arc.sourceVertex().getName(),
+ arc.targetVertex().getName(), EdgeType.DIRECTED);
}
+
return graph;
}
diff --git a/src/main/java/model/diagram/arrangement/PackageDiagramArrangementManager.java b/src/main/java/model/diagram/arrangement/PackageDiagramArrangementManager.java
index 559ae3b..fb0ab66 100644
--- a/src/main/java/model/diagram/arrangement/PackageDiagramArrangementManager.java
+++ b/src/main/java/model/diagram/arrangement/PackageDiagramArrangementManager.java
@@ -24,6 +24,8 @@
public class PackageDiagramArrangementManager implements DiagramArrangementManagerInterface {
public static final LayoutAlgorithmType LAYOUT_ALGORITHM_TYPE = LayoutAlgorithmType.SUGIYAMA;
+ public static final int WIDTH = 1500;
+ public static final int HEIGHT = 1000;
private final Graph graph;
private final PackageDiagram packageDiagram;
@@ -37,17 +39,18 @@ public Map> arrangeGraphMLDiagram() {
Map> nodesGeometryGraphML = new HashMap<>();
Graph graph = populatePackageGraph();
AbstractLayout layout = new SpringLayout<>(graph);
- layout.setSize(new Dimension(1500, 1000));
- for (Integer i : this.packageDiagram.getGraphNodes().values()) {
+ layout.setSize(new Dimension(WIDTH, HEIGHT));
+ for (Integer i : packageDiagram.getGraphNodes().values()) {
nodesGeometryGraphML.put(i, new Pair<>(layout.getX(i), layout.getY(i)));
}
+
return nodesGeometryGraphML;
}
@Override
public DiagramGeometry arrangeDiagram() {
LayoutAlgorithm layoutAlgorithm = LayoutAlgorithmFactory.createLayoutAlgorithm(LAYOUT_ALGORITHM_TYPE);
- layoutAlgorithm.setGraph(this.graph);
+ layoutAlgorithm.setGraph(graph);
return layoutAlgorithm.arrangeDiagram();
}
@@ -55,26 +58,25 @@ public DiagramGeometry arrangeDiagram() {
public DiagramGeometry applyNewLayout(String algorithmType){
LayoutAlgorithmType algorithmEnumType = LayoutAlgorithmType.valueOf(algorithmType.toUpperCase());
LayoutAlgorithm layout = LayoutAlgorithmFactory.createLayoutAlgorithm(algorithmEnumType);
- layout.setGraph(this.graph);
+ layout.setGraph(graph);
return layout.arrangeDiagram();
}
private Graph populatePackageGraph() {
Graph graph = new SparseGraph<>();
- for (Integer i : this.packageDiagram.getGraphNodes().values()) {
+ for (Integer i : packageDiagram.getGraphNodes().values()) {
graph.addVertex(i);
}
List> arcs = new ArrayList<>();
- for (Set> arcSet: this.packageDiagram.getDiagram().values()) {
+ for (Set> arcSet: packageDiagram.getDiagram().values()) {
arcs.addAll(arcSet);
}
for (Arc arc: arcs) {
- graph.addEdge(
- this.packageDiagram.getGraphNodes().get(arc.sourceVertex()) + " " + this.packageDiagram.getGraphNodes().get(arc.targetVertex()),
- this.packageDiagram.getGraphNodes().get(arc.sourceVertex()),
- this.packageDiagram.getGraphNodes().get(arc.targetVertex()), EdgeType.DIRECTED);
+ graph.addEdge(packageDiagram.getGraphNodes().get(arc.sourceVertex()) + " " + packageDiagram.getGraphNodes().get(arc.targetVertex()),
+ packageDiagram.getGraphNodes().get(arc.sourceVertex()),
+ packageDiagram.getGraphNodes().get(arc.targetVertex()), EdgeType.DIRECTED);
}
return graph;
@@ -82,20 +84,21 @@ private Graph populatePackageGraph() {
private Graph populatePackageGraphWithStrings(){
Graph graph = new SparseGraph<>();
- for (PackageVertex vertex: this.packageDiagram.getGraphNodes().keySet()) {
+ for (PackageVertex vertex: packageDiagram.getGraphNodes().keySet()) {
graph.addVertex(vertex.getName());
}
List> arcs = new ArrayList<>();
- for (Set> arcSet: this.packageDiagram.getDiagram().values()) {
+ for (Set> arcSet: packageDiagram.getDiagram().values()) {
arcs.addAll(arcSet);
}
for (Arc arc: arcs) {
- graph.addEdge(
- String.join(" ", arc.sourceVertex().getName(), arc.targetVertex().getName()),
- arc.sourceVertex().getName(),
- arc.targetVertex().getName(), EdgeType.DIRECTED);
+ graph.addEdge(String.join(" ",
+ arc.sourceVertex().getName(),
+ arc.targetVertex().getName()),
+ arc.sourceVertex().getName(),
+ arc.targetVertex().getName(), EdgeType.DIRECTED);
}
return graph;
diff --git a/src/main/java/model/diagram/arrangement/algorithms/AdvancedFruchtermanReingold.java b/src/main/java/model/diagram/arrangement/algorithms/AdvancedFruchtermanReingold.java
index b5ae758..b6184ea 100644
--- a/src/main/java/model/diagram/arrangement/algorithms/AdvancedFruchtermanReingold.java
+++ b/src/main/java/model/diagram/arrangement/algorithms/AdvancedFruchtermanReingold.java
@@ -8,6 +8,8 @@
import model.diagram.arrangement.geometry.GeometryNode;
public class AdvancedFruchtermanReingold implements LayoutAlgorithm{
+ private final static int MIN_X_WINDOW_VALUE = 25;
+ private final static int MIN_Y_WINDOW_VALUE = 25;
private Graph graph;
@@ -31,13 +33,13 @@ public DiagramGeometry arrangeDiagram() {
double y = layout.getY(vertex);
if (x < MIN_X_WINDOW_VALUE) {
double difference = MIN_X_WINDOW_VALUE - x;
- if(difference > maxXdistance) {
+ if (difference > maxXdistance) {
maxXdistance = difference;
}
}
if (y < MIN_Y_WINDOW_VALUE) {
double difference = MIN_Y_WINDOW_VALUE - y;
- if(difference > maxYdistance) {
+ if (difference > maxYdistance) {
maxYdistance = difference;
}
}
diff --git a/src/main/java/model/diagram/arrangement/algorithms/AdvancedSpring.java b/src/main/java/model/diagram/arrangement/algorithms/AdvancedSpring.java
index 1380458..99fe725 100644
--- a/src/main/java/model/diagram/arrangement/algorithms/AdvancedSpring.java
+++ b/src/main/java/model/diagram/arrangement/algorithms/AdvancedSpring.java
@@ -7,6 +7,8 @@
import model.diagram.arrangement.geometry.GeometryNode;
public class AdvancedSpring implements LayoutAlgorithm{
+ private final static int MIN_X_WINDOW_VALUE = 25;
+ private final static int MIN_Y_WINDOW_VALUE = 25;
private Graph graph;
@@ -32,13 +34,13 @@ public DiagramGeometry arrangeDiagram() {
double y = layout.getY(vertex);
if (x < MIN_X_WINDOW_VALUE) {
double difference = MIN_X_WINDOW_VALUE - x;
- if(difference > maxXdistance) {
+ if (difference > maxXdistance) {
maxXdistance = difference;
}
}
if (y < MIN_Y_WINDOW_VALUE) {
double difference = MIN_Y_WINDOW_VALUE - y;
- if(difference > maxYdistance) {
+ if (difference > maxYdistance) {
maxYdistance = difference;
}
}
diff --git a/src/main/java/model/diagram/arrangement/algorithms/FruchtermanReingold.java b/src/main/java/model/diagram/arrangement/algorithms/FruchtermanReingold.java
index c93898c..2dc93be 100644
--- a/src/main/java/model/diagram/arrangement/algorithms/FruchtermanReingold.java
+++ b/src/main/java/model/diagram/arrangement/algorithms/FruchtermanReingold.java
@@ -8,6 +8,8 @@
import model.diagram.arrangement.geometry.GeometryNode;
public class FruchtermanReingold implements LayoutAlgorithm{
+ private final static int MIN_X_WINDOW_VALUE = 25;
+ private final static int MIN_Y_WINDOW_VALUE = 25;
private Graph graph;
@@ -31,13 +33,13 @@ public DiagramGeometry arrangeDiagram() {
double y = layout.getY(vertex);
if (x < MIN_X_WINDOW_VALUE) {
double difference = MIN_X_WINDOW_VALUE - x;
- if(difference > maxXdistance) {
+ if (difference > maxXdistance) {
maxXdistance = difference;
}
}
if (y < MIN_Y_WINDOW_VALUE) {
double difference = MIN_Y_WINDOW_VALUE - y;
- if(difference > maxYdistance) {
+ if (difference > maxYdistance) {
maxYdistance = difference;
}
}
diff --git a/src/main/java/model/diagram/arrangement/algorithms/KamadaKawai.java b/src/main/java/model/diagram/arrangement/algorithms/KamadaKawai.java
index fb96610..36311ab 100644
--- a/src/main/java/model/diagram/arrangement/algorithms/KamadaKawai.java
+++ b/src/main/java/model/diagram/arrangement/algorithms/KamadaKawai.java
@@ -10,8 +10,10 @@
public class KamadaKawai implements LayoutAlgorithm{
- private final static int GRAPH_X_SIZE = 1200;
- private final static int GRAPH_Y_SIZE = 725;
+ private final static int GRAPH_X_SIZE = 1200;
+ private final static int GRAPH_Y_SIZE = 725;
+ private final static int MIN_X_WINDOW_VALUE = 25;
+ private final static int MIN_Y_WINDOW_VALUE = 25;
private Graph graph;
@@ -37,13 +39,13 @@ public DiagramGeometry arrangeDiagram() {
double y = layout.getY(vertex);
if (x < MIN_X_WINDOW_VALUE) {
double difference = MIN_X_WINDOW_VALUE - x;
- if(difference > maxXdistance) {
+ if (difference > maxXdistance) {
maxXdistance = difference;
}
}
if (y < MIN_Y_WINDOW_VALUE) {
double difference = MIN_Y_WINDOW_VALUE - y;
- if(difference > maxYdistance) {
+ if (difference > maxYdistance) {
maxYdistance = difference;
}
}
diff --git a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithm.java b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithm.java
index 09d3081..fe0edb3 100644
--- a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithm.java
+++ b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithm.java
@@ -4,9 +4,6 @@
import model.diagram.arrangement.geometry.DiagramGeometry;
public interface LayoutAlgorithm {
- int MIN_X_WINDOW_VALUE = 25;
- int MIN_Y_WINDOW_VALUE = 25;
-
// TODO Update JavaDoc
/**
* This method is responsible for the arrangement of the graph by creating a graph of the Jung library
diff --git a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmType.java b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmType.java
index fb117f2..6cc8853 100644
--- a/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmType.java
+++ b/src/main/java/model/diagram/arrangement/algorithms/LayoutAlgorithmType.java
@@ -25,4 +25,5 @@ public enum LayoutAlgorithmType {
public static LayoutAlgorithmType get(String algorithmType) {
return ALGORITHM_TYPE_MAP.get(algorithmType.toLowerCase());
}
+
}
diff --git a/src/main/java/model/diagram/arrangement/algorithms/Spring.java b/src/main/java/model/diagram/arrangement/algorithms/Spring.java
index ce2baa1..fbf9a9b 100644
--- a/src/main/java/model/diagram/arrangement/algorithms/Spring.java
+++ b/src/main/java/model/diagram/arrangement/algorithms/Spring.java
@@ -8,6 +8,8 @@
public class Spring implements LayoutAlgorithm{
+ private final static int MIN_X_WINDOW_VALUE = 25;
+ private final static int MIN_Y_WINDOW_VALUE = 25;
private Graph graph;
@@ -33,13 +35,13 @@ public DiagramGeometry arrangeDiagram() {
double y = layout.getY(vertex);
if (x < MIN_X_WINDOW_VALUE) {
double difference = MIN_X_WINDOW_VALUE - x;
- if(difference > maxXdistance) {
+ if (difference > maxXdistance) {
maxXdistance = difference;
}
}
if (y < MIN_Y_WINDOW_VALUE) {
double difference = MIN_Y_WINDOW_VALUE - y;
- if(difference > maxYdistance) {
+ if (difference > maxYdistance) {
maxYdistance = difference;
}
}
diff --git a/src/main/java/model/diagram/arrangement/algorithms/Sugiyama.java b/src/main/java/model/diagram/arrangement/algorithms/Sugiyama.java
index 01b9d87..a09ab20 100644
--- a/src/main/java/model/diagram/arrangement/algorithms/Sugiyama.java
+++ b/src/main/java/model/diagram/arrangement/algorithms/Sugiyama.java
@@ -16,7 +16,8 @@
import model.diagram.arrangement.geometry.GeometryNode;
public class Sugiyama implements LayoutAlgorithm{
-
+ private final static int MIN_X_WINDOW_VALUE = 25;
+ private final static int MIN_Y_WINDOW_VALUE = 25;
private final static int VERTEX_X_SIZE = 20;
private final static int VERTEX_Y_SIZE = 20;
private final static int HORIZONTAL_SPACING = 125;
@@ -50,20 +51,20 @@ public DiagramGeometry arrangeDiagram() {
DigrpahLayoutBuilder builder = new SugiyamaBuilder<>(HORIZONTAL_SPACING, VERTICAL_SPACING);
DigraphLayout layout = builder.build(digraph, dimensionProvider);
for (DigraphLayoutNode vertex : layout.getLayoutGraph().vertices()) {
- for (Map.Entry entryVertex : this.verticesMap.entrySet()) {
+ for (Map.Entry entryVertex : verticesMap.entrySet()) {
if (entryVertex.getValue().equals(vertex.getVertex())) {
double x = vertex.getPoint().x;
double y = vertex.getPoint().y;
GeometryNode geometryNode = new GeometryNode(entryVertex.getKey());
if (vertex.getPoint().x < MIN_X_WINDOW_VALUE) {
double difference = MIN_X_WINDOW_VALUE - x;
- if(difference > maxXdistance) {
+ if (difference > maxXdistance) {
maxXdistance = difference;
}
}
if (vertex.getPoint().y < MIN_Y_WINDOW_VALUE) {
double difference = MIN_Y_WINDOW_VALUE - y;
- if(difference > maxYdistance) {
+ if (difference > maxYdistance) {
maxYdistance = difference;
}
}
diff --git a/src/main/java/model/diagram/arrangement/geometry/DiagramGeometry.java b/src/main/java/model/diagram/arrangement/geometry/DiagramGeometry.java
index 1bce16e..47f9991 100644
--- a/src/main/java/model/diagram/arrangement/geometry/DiagramGeometry.java
+++ b/src/main/java/model/diagram/arrangement/geometry/DiagramGeometry.java
@@ -20,18 +20,17 @@ public void addGeometry(GeometryNode key, double x, double y) {
geometryMap.put(key.nodeName(), new Pair<>(x, y));
}
-
public Pair getVertexGeometry(String stringKey){
return geometryMap.get(stringKey);
}
-
public boolean containsKey(String stringKey) {
return geometryMap.containsKey(stringKey);
}
public void correctPositions(double x, double y) {
- // We store minX and minY coordinates of the system, in order to bring the graph to match the left side and upper side of the window.
+ // We store minX and minY coordinates of the system, in order to bring the graph to match the left side
+ // and upper side of the window.
double minX = Double.POSITIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY;
double xDifference;
@@ -40,10 +39,10 @@ public void correctPositions(double x, double y) {
double newX = entry.getValue().getValue0() + x;
double newY = entry.getValue().getValue1() + y;
geometryMap.put(entry.getKey(), new Pair<>(entry.getValue().getValue0() + x, entry.getValue().getValue1() + y));
- if( newX < minX) {
+ if (newX < minX) {
minX = newX;
}
- if( newY < minY) {
+ if (newY < minY) {
minY = newY;
}
}
diff --git a/src/main/java/model/diagram/exportation/ClassifierVertexSerializer.java b/src/main/java/model/diagram/exportation/ClassifierVertexSerializer.java
index e90ee09..9b712f8 100644
--- a/src/main/java/model/diagram/exportation/ClassifierVertexSerializer.java
+++ b/src/main/java/model/diagram/exportation/ClassifierVertexSerializer.java
@@ -17,18 +17,18 @@
public class ClassifierVertexSerializer implements JsonSerializer {
@Override
- public JsonElement serialize(ClassifierVertex classifierVertex,
- Type type,
- JsonSerializationContext jsonSerializationContext) {
+ public JsonElement serialize(ClassifierVertex classifierVertex,
+ Type type,
+ JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject();
- String name = classifierVertex.getName();
- Path path = classifierVertex.getPath();
- String vertexType = classifierVertex.getVertexType().toString();
+ String name = classifierVertex.getName();
+ Path path = classifierVertex.getPath();
+ String vertexType = classifierVertex.getVertexType().toString();
jsonObject.addProperty("name", name);
jsonObject.addProperty("path", path.toString());
jsonObject.addProperty("vertexType", vertexType);
- jsonObject.addProperty("coordinate_x", classifierVertex.getCoordinates().getValue0());
- jsonObject.addProperty("coordinate_y", classifierVertex.getCoordinates().getValue1());
+ jsonObject.addProperty("coordinate_x", classifierVertex.getCoordinate().getX());
+ jsonObject.addProperty("coordinate_y", classifierVertex.getCoordinate().getY());
jsonObject.add("methods", serializeMethods(classifierVertex));
jsonObject.add("fields", serializeFields(classifierVertex));
jsonObject.add("arcs", serializeArcs(classifierVertex));
diff --git a/src/main/java/model/diagram/exportation/CoordinatesUpdater.java b/src/main/java/model/diagram/exportation/CoordinatesUpdater.java
index 7376ece..eca0e96 100644
--- a/src/main/java/model/diagram/exportation/CoordinatesUpdater.java
+++ b/src/main/java/model/diagram/exportation/CoordinatesUpdater.java
@@ -12,10 +12,10 @@
import java.util.logging.Logger;
public class CoordinatesUpdater {
- private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
+ private static final Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
- private PackageDiagram packageDiagram;
- private ClassDiagram classDiagram;
+ private PackageDiagram packageDiagram;
+ private ClassDiagram classDiagram;
public CoordinatesUpdater(PackageDiagram packageDiagram) {
this.packageDiagram = packageDiagram;
@@ -28,18 +28,19 @@ public CoordinatesUpdater(ClassDiagram classDiagram) {
public void updatePackageCoordinates(Collection> vertexCollection,
SmartGraphPanel graphView) {
if (vertexCollection == null) {
- logger.log(Level.INFO, "Vertex Collection is null");
+ logger.log(Level.WARNING, "Vertex Collection is null");
return;
}
for(Vertex vertex : vertexCollection) {
double x = graphView.getVertexPositionX(vertex);
double y = graphView.getVertexPositionY(vertex);
- for(PackageVertex packageVertex : this.packageDiagram.getGraphNodes().keySet()) {
- if(!packageVertex.getName().equals(vertex.element())) {
+ for (PackageVertex packageVertex : packageDiagram.getGraphNodes().keySet()) {
+ if (!packageVertex.getName().equals(vertex.element())) {
continue;
}
- packageVertex.setCoordinates(x, y);
+
+ packageVertex.createCoordinate(x, y);
}
}
}
@@ -47,18 +48,19 @@ public void updatePackageCoordinates(Collection> vertexCollecti
public void updateClassCoordinates(Collection> vertexCollection,
SmartGraphPanel graphView) {
if (vertexCollection == null) {
- logger.log(Level.INFO, "Vertex Collection is null");
+ logger.log(Level.WARNING, "Vertex Collection is null");
return;
}
for(Vertex vertex : vertexCollection) {
double x = graphView.getVertexPositionX(vertex);
double y = graphView.getVertexPositionY(vertex);
- for(ClassifierVertex classifierVertex : this.classDiagram.getGraphNodes().keySet()) {
+ for (ClassifierVertex classifierVertex : classDiagram.getGraphNodes().keySet()) {
if (!classifierVertex.getName().equals(vertex.element())) {
continue;
}
- classifierVertex.setCoordinates(x, y);
+
+ classifierVertex.updateCoordinate(x, y);
}
}
}
diff --git a/src/main/java/model/diagram/exportation/GraphMLClassDiagramExporter.java b/src/main/java/model/diagram/exportation/GraphMLClassDiagramExporter.java
index 881c558..9c3c483 100644
--- a/src/main/java/model/diagram/exportation/GraphMLClassDiagramExporter.java
+++ b/src/main/java/model/diagram/exportation/GraphMLClassDiagramExporter.java
@@ -15,19 +15,20 @@ public class GraphMLClassDiagramExporter implements DiagramExporter {
public GraphMLClassDiagramExporter(ClassDiagram classDiagram) {
GraphMLClassifierVertex graphMLClassifierVertex = new GraphMLClassifierVertex(classDiagram);
- this.graphMLNodeBuffer = graphMLClassifierVertex.convertSinkVertex();
GraphMLClassifierVertexArc graphMLClassifierVertexArc = new GraphMLClassifierVertexArc(classDiagram);
- this.graphMLEdgeBuffer = graphMLClassifierVertexArc.convertSinkVertexArc();
- this.graphMLFile = new GraphMLFile();
+
+ graphMLNodeBuffer = graphMLClassifierVertex.convertSinkVertex();
+ graphMLEdgeBuffer = graphMLClassifierVertexArc.convertSinkVertexArc();
+ graphMLFile = new GraphMLFile();
}
@Override
public File exportDiagram(Path exportPath) {
- this.graphMLFile.createGraphMLFile(exportPath);
- this.graphMLFile.writeToBuffer(this.graphMLNodeBuffer);
- this.graphMLFile.writeToBuffer(this.graphMLEdgeBuffer);
- this.graphMLFile.closeGraphMLFile();
- return this.graphMLFile.getGraphMLFile();
+ graphMLFile.createGraphMLFile(exportPath);
+ graphMLFile.writeToBuffer(graphMLNodeBuffer);
+ graphMLFile.writeToBuffer(graphMLEdgeBuffer);
+ graphMLFile.closeGraphMLFile();
+ return graphMLFile.getGraphMLFile();
}
}
diff --git a/src/main/java/model/diagram/exportation/GraphMLFile.java b/src/main/java/model/diagram/exportation/GraphMLFile.java
index 89c2852..003b060 100644
--- a/src/main/java/model/diagram/exportation/GraphMLFile.java
+++ b/src/main/java/model/diagram/exportation/GraphMLFile.java
@@ -15,34 +15,34 @@ public class GraphMLFile {
public void createGraphMLFile(Path graphMLSavePath) {
try {
- this.graphMLFile = graphMLSavePath.toFile();
- this.graphMLWriter = new FileWriter(this.graphMLFile);
- this.graphMLBuffer = new StringBuilder();
- this.graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLPrefix());
- }
- catch (IOException e) {
+ graphMLFile = graphMLSavePath.toFile();
+ graphMLWriter = new FileWriter(graphMLFile);
+ graphMLBuffer = new StringBuilder();
+ graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLPrefix());
+ } catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e);
}
}
public void closeGraphMLFile() {
try {
- this.graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLSuffix());
- this.graphMLWriter.write(this.graphMLBuffer.toString());
- this.graphMLWriter.close();
- }
- catch (IOException e) {
+ graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLSuffix());
+ graphMLWriter.write(graphMLBuffer.toString());
+ graphMLWriter.close();
+ } catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e);
}
}
public void writeToBuffer(StringBuilder buffer) {
- this.graphMLBuffer.append(buffer);
+ graphMLBuffer.append(buffer);
}
public File getGraphMLFile() {
- return this.graphMLFile;
+ return graphMLFile;
}
}
diff --git a/src/main/java/model/diagram/exportation/GraphMLPackageDiagramExporter.java b/src/main/java/model/diagram/exportation/GraphMLPackageDiagramExporter.java
index a1eecf1..084dc25 100644
--- a/src/main/java/model/diagram/exportation/GraphMLPackageDiagramExporter.java
+++ b/src/main/java/model/diagram/exportation/GraphMLPackageDiagramExporter.java
@@ -14,24 +14,25 @@ public class GraphMLPackageDiagramExporter implements DiagramExporter {
private final StringBuilder graphMLEdgeBuffer;
public GraphMLPackageDiagramExporter(PackageDiagram packageDiagram) {
- GraphMLPackageVertex graphMLPackageVertex = new GraphMLPackageVertex(packageDiagram);
- this.graphMLNodeBuffer = graphMLPackageVertex.convertVertex();
+ GraphMLPackageVertex graphMLPackageVertex = new GraphMLPackageVertex(packageDiagram);
GraphMLPackageVertexArc graphMLPackageVertexArc = new GraphMLPackageVertexArc(packageDiagram);
- this.graphMLEdgeBuffer = graphMLPackageVertexArc.convertVertexArc();
- this.graphMLFile = new GraphMLFile();
+
+ graphMLNodeBuffer = graphMLPackageVertex.convertVertex();
+ graphMLEdgeBuffer = graphMLPackageVertexArc.convertVertexArc();
+ graphMLFile = new GraphMLFile();
}
@Override
public File exportDiagram(Path exportPath) {
- this.graphMLFile.createGraphMLFile(exportPath);
- generateGraphMLGraph(this.graphMLNodeBuffer, this.graphMLEdgeBuffer);
- this.graphMLFile.closeGraphMLFile();
- return this.graphMLFile.getGraphMLFile();
+ graphMLFile.createGraphMLFile(exportPath);
+ generateGraphMLGraph(graphMLNodeBuffer, graphMLEdgeBuffer);
+ graphMLFile.closeGraphMLFile();
+ return graphMLFile.getGraphMLFile();
}
private void generateGraphMLGraph(StringBuilder nodeBuffer,
StringBuilder edgeBuffer) {
- this.graphMLFile.writeToBuffer(nodeBuffer);
- this.graphMLFile.writeToBuffer(edgeBuffer);
+ graphMLFile.writeToBuffer(nodeBuffer);
+ graphMLFile.writeToBuffer(edgeBuffer);
}
}
diff --git a/src/main/java/model/diagram/exportation/JavaFXClassDiagramExporter.java b/src/main/java/model/diagram/exportation/JavaFXClassDiagramExporter.java
index 6372bc0..f7806ef 100644
--- a/src/main/java/model/diagram/exportation/JavaFXClassDiagramExporter.java
+++ b/src/main/java/model/diagram/exportation/JavaFXClassDiagramExporter.java
@@ -22,14 +22,18 @@ public JavaFXClassDiagramExporter(ClassDiagram diagram) {
public File exportDiagram(Path exportPath) {
File graphSaveFile = exportPath.toFile();
try (FileWriter fileWriter = new FileWriter(graphSaveFile)) {
- Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class,
- new ClassifierVertexSerializer())
- .create();
- String json = gson.toJson(this.classDiagram.getDiagram().keySet());
+ Gson gson = new GsonBuilder()
+ .registerTypeAdapter(ClassifierVertex.class,
+ new ClassifierVertexSerializer())
+ .create();
+
+ String json = gson.toJson(classDiagram.getDiagram().keySet());
fileWriter.write(json);
} catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e);
}
+
return graphSaveFile;
}
diff --git a/src/main/java/model/diagram/exportation/JavaFXPackageDiagramExporter.java b/src/main/java/model/diagram/exportation/JavaFXPackageDiagramExporter.java
index 311add9..f6baf95 100644
--- a/src/main/java/model/diagram/exportation/JavaFXPackageDiagramExporter.java
+++ b/src/main/java/model/diagram/exportation/JavaFXPackageDiagramExporter.java
@@ -22,14 +22,17 @@ public JavaFXPackageDiagramExporter(PackageDiagram packageDiagram) {
public File exportDiagram(Path exportPath) {
File graphSaveFile = exportPath.toFile();
try (FileWriter fileWriter = new FileWriter(graphSaveFile)) {
- Gson gson = new GsonBuilder().registerTypeAdapter(PackageVertex.class,
- new PackageVertexSerializer())
- .create();
- String json = gson.toJson(this.packageDiagram.getDiagram().keySet());
+ Gson gson = new GsonBuilder()
+ .registerTypeAdapter(PackageVertex.class,
+ new PackageVertexSerializer())
+ .create();
+ String json = gson.toJson(packageDiagram.getDiagram().keySet());
fileWriter.write(json);
} catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e);
}
+
return graphSaveFile;
}
diff --git a/src/main/java/model/diagram/exportation/PackageVertexSerializer.java b/src/main/java/model/diagram/exportation/PackageVertexSerializer.java
index c90be57..ec7b13f 100644
--- a/src/main/java/model/diagram/exportation/PackageVertexSerializer.java
+++ b/src/main/java/model/diagram/exportation/PackageVertexSerializer.java
@@ -22,15 +22,15 @@ public JsonElement serialize(PackageVertex packageVertex,
Type type,
JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject();
- String name = packageVertex.getName();
- Path path = packageVertex.getPath();
- String vertexType = packageVertex.getVertexType().toString();
+ String name = packageVertex.getName();
+ Path path = packageVertex.getPath();
+ String vertexType = packageVertex.getVertexType().toString();
jsonObject.addProperty("name", name);
jsonObject.addProperty("path", path.toString());
jsonObject.addProperty("vertexType", vertexType);
- jsonObject.addProperty("coordinate_x", packageVertex.getCoordinates().getValue0());
- jsonObject.addProperty("coordinate_y", packageVertex.getCoordinates().getValue1());
+ jsonObject.addProperty("coordinate_x", packageVertex.getCoordinate().getX());
+ jsonObject.addProperty("coordinate_y", packageVertex.getCoordinate().getY());
jsonObject.add("sinkVertices", serializeSinkVertices(packageVertex));
jsonObject.add("parent", serializeParentVertex(packageVertex));
jsonObject.add("neighbours", serializeNeighbourVertices(packageVertex));
@@ -40,24 +40,24 @@ public JsonElement serialize(PackageVertex packageVertex,
}
private JsonArray serializeSinkVertices(PackageVertex packageVertex) {
- List sinkVertices = packageVertex.getSinkVertices();
- JsonArray sinkVerticesArray = new JsonArray(sinkVertices.size());
+ List sinkVertices = packageVertex.getSinkVertices();
+ JsonArray sinkVerticesArray = new JsonArray(sinkVertices.size());
for (ClassifierVertex classifierVertex : sinkVertices) {
- Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class,
- new ClassifierVertexSerializer())
- .create();
- String json = gson.toJson(classifierVertex);
- sinkVerticesArray.add(json);
+ Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class,
+ new ClassifierVertexSerializer())
+ .create();
+ String json = gson.toJson(classifierVertex);
+ sinkVerticesArray.add(json);
}
return sinkVerticesArray;
}
private JsonObject serializeParentVertex(PackageVertex packageVertex) {
PackageVertex parentPackageVertex = packageVertex.getParentVertex();
- JsonObject parentObject = new JsonObject();
- String name = parentPackageVertex.getName();
- String path = parentPackageVertex.getPath().toString();
- String type = parentPackageVertex.getModifierType().toString();
+ JsonObject parentObject = new JsonObject();
+ String name = parentPackageVertex.getName();
+ String path = parentPackageVertex.getPath().toString();
+ String type = parentPackageVertex.getModifierType().toString();
parentObject.addProperty("name", name);
parentObject.addProperty("path", path);
@@ -71,11 +71,11 @@ private JsonArray serializeNeighbourVertices(PackageVertex packageVertex) {
JsonArray neighbourVerticesArray = new JsonArray(neighbourVertices.size());
for (PackageVertex v: neighbourVertices) {
- JsonObject neighbourVertexObject = new JsonObject();
- String name = v.getName();
- String path = v.getPath().toString();
- String vertexType = v.getVertexType().toString();
- String parentName = v.getParentVertex().getName();
+ JsonObject neighbourVertexObject = new JsonObject();
+ String name = v.getName();
+ String path = v.getPath().toString();
+ String vertexType = v.getVertexType().toString();
+ String parentName = v.getParentVertex().getName();
neighbourVertexObject.addProperty("name", name);
neighbourVertexObject.addProperty("path", path);
@@ -87,14 +87,14 @@ private JsonArray serializeNeighbourVertices(PackageVertex packageVertex) {
}
private JsonArray serializeArcs(PackageVertex packageVertex) {
- List> arcs = packageVertex.getArcs();
- JsonArray arcsArray = new JsonArray(arcs.size());
+ List> arcs = packageVertex.getArcs();
+ JsonArray arcsArray = new JsonArray(arcs.size());
for (Arc vertexArc : arcs) {
- JsonObject arcObject = new JsonObject();
- String source = vertexArc.sourceVertex().getName();
- String target = vertexArc.targetVertex().getName();
- String arcType = vertexArc.arcType().toString();
+ JsonObject arcObject = new JsonObject();
+ String source = vertexArc.sourceVertex().getName();
+ String target = vertexArc.targetVertex().getName();
+ String arcType = vertexArc.arcType().toString();
arcObject.addProperty("source", source);
arcObject.addProperty("target", target);
diff --git a/src/main/java/model/diagram/exportation/PlantUMLClassDiagramImageExporter.java b/src/main/java/model/diagram/exportation/PlantUMLClassDiagramImageExporter.java
index e5c9773..ca795dd 100644
--- a/src/main/java/model/diagram/exportation/PlantUMLClassDiagramImageExporter.java
+++ b/src/main/java/model/diagram/exportation/PlantUMLClassDiagramImageExporter.java
@@ -19,20 +19,21 @@ public class PlantUMLClassDiagramImageExporter implements DiagramExporter {
private final StringBuilder bufferBody;
public PlantUMLClassDiagramImageExporter(ClassDiagram diagram) {
- PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(diagram);
- StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex();
- PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(diagram);
- StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc();
- this.bufferBody = plantUMLNodeBuffer.append("\n\n")
- .append(plantUMLEdgeBuffer)
- .append("\n @enduml");
+ PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(diagram);
+ StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex();
+ PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(diagram);
+ StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc();
+ bufferBody = plantUMLNodeBuffer
+ .append("\n\n")
+ .append(plantUMLEdgeBuffer)
+ .append("\n @enduml");
}
@Override
public File exportDiagram(Path exportPath) {
- File plantUMLFile = exportPath.toFile();
+ File plantUMLFile = exportPath.toFile();
String plantUMLCode = getClassText();
- plantUMLCode += this.bufferBody;
+ plantUMLCode += bufferBody;
exportImage(plantUMLFile, plantUMLCode);
return plantUMLFile;
}
@@ -41,11 +42,12 @@ private void exportImage(File plantUMLFile, String plantCode) {
try (ByteArrayOutputStream png = new ByteArrayOutputStream()) {
SourceStringReader reader = new SourceStringReader(plantCode);
reader.outputImage(png).getDescription();
- byte [] data = png.toByteArray();
- InputStream in = new ByteArrayInputStream(data);
- BufferedImage convImg = ImageIO.read(in);
- int width = convImg.getWidth();
- int wrapWidth = 150;
+
+ byte[] data = png.toByteArray();
+ InputStream in = new ByteArrayInputStream(data);
+ BufferedImage convImg = ImageIO.read(in);
+ int width = convImg.getWidth();
+ int wrapWidth = 150;
if (width == 4096) {
try (ByteArrayOutputStream newPng = new ByteArrayOutputStream())
{
@@ -60,16 +62,17 @@ private void exportImage(File plantUMLFile, String plantCode) {
ImageIO.write(convImg, "png", plantUMLFile);
} catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e);
}
}
private String wrapWidthChanger(String plantCode, int wrapWidth){
String updatedString;
//if (counter == 0) {
- int indexOfNewLine = plantCode.indexOf("\n");
- String firstPart = plantCode.substring(0, indexOfNewLine + 1);
- String secondPart = plantCode.substring(indexOfNewLine + 1);
- updatedString = firstPart + "skinparam wrapWidth " + wrapWidth + "\n" + secondPart;
+ int indexOfNewLine = plantCode.indexOf("\n");
+ String firstPart = plantCode.substring(0, indexOfNewLine + 1);
+ String secondPart = plantCode.substring(indexOfNewLine + 1);
+ updatedString = firstPart + "skinparam wrapWidth " + wrapWidth + "\n" + secondPart;
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// KEEP REDUCING THE WRAPWIDTH PARAMETER IN ORDER TO FIT PROPERLY THE IMAGE //
// DOESNT WORK PROPERLY, COMMENTED JUST TO KEEP THE IDEA. //
@@ -86,8 +89,7 @@ private String wrapWidthChanger(String plantCode, int wrapWidth){
}
private String getClassText() {
- return
- """
+ return """
@startuml
skinparam class {
BackgroundColor lightyellow
diff --git a/src/main/java/model/diagram/exportation/PlantUMLClassDiagramTextExporter.java b/src/main/java/model/diagram/exportation/PlantUMLClassDiagramTextExporter.java
index e84e6a9..b687fac 100644
--- a/src/main/java/model/diagram/exportation/PlantUMLClassDiagramTextExporter.java
+++ b/src/main/java/model/diagram/exportation/PlantUMLClassDiagramTextExporter.java
@@ -15,20 +15,21 @@ public class PlantUMLClassDiagramTextExporter implements DiagramExporter {
private final StringBuilder bufferBody;
public PlantUMLClassDiagramTextExporter(ClassDiagram diagram) {
- PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(diagram);
- StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex();
- PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(diagram);
- StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc();
- this.bufferBody = plantUMLNodeBuffer.append("\n\n")
- .append(plantUMLEdgeBuffer)
- .append("\n @enduml");
+ PlantUMLClassifierVertex plantUMLClassifierVertex = new PlantUMLClassifierVertex(diagram);
+ StringBuilder plantUMLNodeBuffer = plantUMLClassifierVertex.convertSinkVertex();
+ PlantUMLClassifierVertexArc plantUMLEdge = new PlantUMLClassifierVertexArc(diagram);
+ StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertSinkVertexArc();
+ bufferBody = plantUMLNodeBuffer
+ .append("\n\n")
+ .append(plantUMLEdgeBuffer)
+ .append("\n @enduml");
}
@Override
public File exportDiagram(Path exportPath) {
- File plantUMLFile = exportPath.toFile();
- String plantUMLCode = getClassText();
- plantUMLCode += this.bufferBody;
+ File plantUMLFile = exportPath.toFile();
+ String plantUMLCode = getClassText();
+ plantUMLCode += bufferBody;
writeFile(plantUMLFile, plantUMLCode);
return plantUMLFile;
}
@@ -38,12 +39,12 @@ private void writeFile(File plantUMLFile, String plantCode) {
writer.write(plantCode);
} catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e);
}
}
private String getClassText() {
- return
- """
+ return """
@startuml
skinparam class {
BackgroundColor lightyellow
diff --git a/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramImageExporter.java b/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramImageExporter.java
index bc598d5..04bd202 100644
--- a/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramImageExporter.java
+++ b/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramImageExporter.java
@@ -19,34 +19,36 @@ public class PlantUMLPackageDiagramImageExporter implements DiagramExporter {
private final StringBuilder bufferBody;
public PlantUMLPackageDiagramImageExporter(PackageDiagram diagram) {
- PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram);
- StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex();
- PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram);
- StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc();
- this.bufferBody = plantUMLNodeBuffer.append("\n\n")
- .append(plantUMLEdgeBuffer)
- .append("\n @enduml");
+ PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram);
+ StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex();
+ PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram);
+ StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc();
+ bufferBody = plantUMLNodeBuffer
+ .append("\n\n")
+ .append(plantUMLEdgeBuffer)
+ .append("\n @enduml");
}
@Override
public File exportDiagram(Path exportPath) {
- File plantUMLFile = exportPath.toFile();
- String plantUMLCode = getPackageText();
- plantUMLCode += this.bufferBody;
- plantUMLCode = dotChanger(plantUMLCode);
+ File plantUMLFile = exportPath.toFile();
+ String plantUMLCode = getPackageText();
+ plantUMLCode += bufferBody;
+ plantUMLCode = dotChanger(plantUMLCode);
exportImage(plantUMLFile, plantUMLCode);
return plantUMLFile;
}
private void exportImage(File plantUMLFile, String plantCode) {
- try (ByteArrayOutputStream png = new ByteArrayOutputStream()) {
- SourceStringReader reader = new SourceStringReader(plantCode);
+ try (ByteArrayOutputStream png = new ByteArrayOutputStream()) {
+ SourceStringReader reader = new SourceStringReader(plantCode);
reader.outputImage(png).getDescription();
- byte [] data = png.toByteArray();
- InputStream in = new ByteArrayInputStream(data);
- BufferedImage convImg = ImageIO.read(in);
- int width = convImg.getWidth();
- int wrapWidth = 150;
+
+ byte[] data = png.toByteArray();
+ InputStream in = new ByteArrayInputStream(data);
+ BufferedImage convImg = ImageIO.read(in);
+ int width = convImg.getWidth();
+ int wrapWidth = 150;
//int stringChangerCounter = 0;
if (width == 4096) {
try (ByteArrayOutputStream newPng = new ByteArrayOutputStream())
@@ -63,15 +65,16 @@ private void exportImage(File plantUMLFile, String plantCode) {
ImageIO.write(convImg, "png", plantUMLFile);
} catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e);
}
}
private String wrapWidthChanger(String plantCode, int wrapWidth){
String updatedString;
- int indexOfNewLine = plantCode.indexOf("\n");
- String firstPart = plantCode.substring(0, indexOfNewLine + 1);
- String secondPart = plantCode.substring(indexOfNewLine + 1);
- updatedString = firstPart + "skinparam wrapWidth " + wrapWidth + "\n" + secondPart;
+ int indexOfNewLine = plantCode.indexOf("\n");
+ String firstPart = plantCode.substring(0, indexOfNewLine + 1);
+ String secondPart = plantCode.substring(indexOfNewLine + 1);
+ updatedString = firstPart + "skinparam wrapWidth " + wrapWidth + "\n" + secondPart;
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// KEEP REDUCING THE WRAPWIDTH PARAMETER IN ORDER TO FIT PROPERLY THE IMAGE //
// DOESNT WORK PROPERLY, COMMENTED JUST TO KEEP THE IDEA. //
@@ -89,12 +92,12 @@ private String wrapWidthChanger(String plantCode, int wrapWidth){
private String dotChanger(String plantUMLCode) {
StringBuilder newString = new StringBuilder();
- String[] lines = plantUMLCode.split("\n");
+ String[] lines = plantUMLCode.split("\n");
for (String line: lines) {
String[] splittedLine = line.split(" ");
for (String word: splittedLine) {
String newWord = word;
- if(word.contains(".") && !word.contains("..")) {
+ if (word.contains(".") && !word.contains("..")) {
newWord = word.replace(".", "_");
newWord = newWord.replace("-", "_");
}
@@ -106,8 +109,7 @@ private String dotChanger(String plantUMLCode) {
}
private String getPackageText() {
- return
- """
+ return """
@startuml
skinparam package {
BackgroundColor lightyellow
diff --git a/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramTextExporter.java b/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramTextExporter.java
index af55915..8fe5c42 100644
--- a/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramTextExporter.java
+++ b/src/main/java/model/diagram/exportation/PlantUMLPackageDiagramTextExporter.java
@@ -15,21 +15,22 @@ public class PlantUMLPackageDiagramTextExporter implements DiagramExporter {
private final StringBuilder bufferBody;
public PlantUMLPackageDiagramTextExporter(PackageDiagram diagram) {
- PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram);
- StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex();
- PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram);
- StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc();
- this.bufferBody = plantUMLNodeBuffer.append("\n\n")
- .append(plantUMLEdgeBuffer)
- .append("\n @enduml");
+ PlantUMLPackageVertex plantUMLPackageVertex = new PlantUMLPackageVertex(diagram);
+ StringBuilder plantUMLNodeBuffer = plantUMLPackageVertex.convertVertex();
+ PlantUMLPackageVertexArc plantUMLEdge = new PlantUMLPackageVertexArc(diagram);
+ StringBuilder plantUMLEdgeBuffer = plantUMLEdge.convertVertexArc();
+ bufferBody = plantUMLNodeBuffer
+ .append("\n\n")
+ .append(plantUMLEdgeBuffer)
+ .append("\n @enduml");
}
@Override
public File exportDiagram(Path exportPath) {
- File plantUMLFile = exportPath.toFile();
- String plantUMLCode = getPackageText();
- plantUMLCode += this.bufferBody;
- plantUMLCode = dotChanger(plantUMLCode);
+ File plantUMLFile = exportPath.toFile();
+ String plantUMLCode = getPackageText();
+ plantUMLCode += bufferBody;
+ plantUMLCode = dotChanger(plantUMLCode);
writeFile(plantUMLFile, plantUMLCode);
return plantUMLFile;
}
@@ -39,17 +40,18 @@ private void writeFile(File plantUMLFile, String plantCode) {
writer.write(plantCode);
} catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e);
}
}
private String dotChanger(String plantUMLCode) {
StringBuilder newString = new StringBuilder();
- String[] lines = plantUMLCode.split("\n");
+ String[] lines = plantUMLCode.split("\n");
for (String line: lines) {
String[] splittedLine = line.split(" ");
for (String word: splittedLine) {
String newWord = word;
- if(word.contains(".") && !word.contains("..")) {
+ if (word.contains(".") && !word.contains("..")) {
newWord = word.replace(".", "_");
newWord = newWord.replace("-", "_");
}
@@ -61,8 +63,7 @@ private String dotChanger(String plantUMLCode) {
}
private String getPackageText() {
- return
- """
+ return """
@startuml
skinparam package {
BackgroundColor lightyellow
diff --git a/src/main/java/model/diagram/graphml/GraphMLClassifierVertex.java b/src/main/java/model/diagram/graphml/GraphMLClassifierVertex.java
index 493178c..85043f8 100644
--- a/src/main/java/model/diagram/graphml/GraphMLClassifierVertex.java
+++ b/src/main/java/model/diagram/graphml/GraphMLClassifierVertex.java
@@ -20,44 +20,51 @@ public class GraphMLClassifierVertex {
public GraphMLClassifierVertex(ClassDiagram classDiagram) {
this.classDiagram = classDiagram;
- this.graphMLBuffer = new StringBuilder();
+ graphMLBuffer = new StringBuilder();
}
public StringBuilder convertSinkVertex() {
- for (Map.Entry sinkVertex: this.classDiagram.getGraphNodes().entrySet()) {
- this.graphMLBuffer.append(GraphMLSyntax.getInstance()
- .getGraphMLSinkVertexSyntax(getSinkVertexDescription(sinkVertex.getKey(),
- sinkVertex.getValue(),
- this.classDiagram.getGraphMLDiagramGeometry().get(sinkVertex.getValue()))));
+ for (Map.Entry sinkVertex: classDiagram.getGraphNodes().entrySet()) {
+ graphMLBuffer.append(GraphMLSyntax.getInstance()
+ .getGraphMLSinkVertexSyntax(getSinkVertexDescription(sinkVertex.getKey(),
+ sinkVertex.getValue(),
+ classDiagram.getGraphMLDiagramGeometry().get(sinkVertex.getValue()))));
}
- return this.graphMLBuffer;
+ return graphMLBuffer;
}
- private List getSinkVertexDescription(ClassifierVertex classifierVertex, int nodeId, Pair nodeGeometry) {
- return Arrays.asList(String.valueOf(nodeId), getSinkVertexColor(classifierVertex), classifierVertex.getName(), getSinkVertexFields(classifierVertex),
- getSinkVertexMethods(classifierVertex), String.valueOf(nodeGeometry.getValue0()), String.valueOf(nodeGeometry.getValue1()));
+ private List getSinkVertexDescription(ClassifierVertex classifierVertex,
+ int nodeId,
+ Pair nodeGeometry) {
+ return Arrays.asList(String.valueOf(nodeId),
+ getSinkVertexColor(classifierVertex),
+ classifierVertex.getName(),
+ getSinkVertexFields(classifierVertex),
+ getSinkVertexMethods(classifierVertex),
+ String.valueOf(nodeGeometry.getValue0()),
+ String.valueOf(nodeGeometry.getValue1()));
}
private String getSinkVertexMethods(ClassifierVertex classifierVertex) {
if (classifierVertex.getMethods().isEmpty()) {
return "";
}
- return
- classifierVertex.getMethods()
- .stream()
- .map(method -> method.returnType() + " " + method.name())
- .collect(Collectors.joining("\n"));
+ return classifierVertex.getMethods()
+ .stream()
+ .map(method -> method.returnType() + " " + method.name())
+ .collect(Collectors.joining("\n"));
}
private String getSinkVertexFields(ClassifierVertex classifierVertex) {
if (classifierVertex.getFields().isEmpty()) {
return "";
}
- return
- classifierVertex.getFields()
- .stream()
- .map(field -> String.join(" ", field.type(), field.name()))
- .collect(Collectors.joining("\n"));
+ return classifierVertex.getFields()
+ .stream()
+ .map(field -> String.join(" ",
+ field.type(),
+ field.name()))
+ .collect(Collectors.joining("\n"));
}
private String getSinkVertexColor(ClassifierVertex leafNode) {
diff --git a/src/main/java/model/diagram/graphml/GraphMLClassifierVertexArc.java b/src/main/java/model/diagram/graphml/GraphMLClassifierVertexArc.java
index 8e63767..500ef6d 100644
--- a/src/main/java/model/diagram/graphml/GraphMLClassifierVertexArc.java
+++ b/src/main/java/model/diagram/graphml/GraphMLClassifierVertexArc.java
@@ -19,29 +19,28 @@ public class GraphMLClassifierVertexArc {
private final ClassDiagram classDiagram;
public GraphMLClassifierVertexArc(ClassDiagram classDiagram) {
- this.classDiagram = classDiagram;
- this.graphMLBuffer = new StringBuilder();
+ this.classDiagram = classDiagram;
+ graphMLBuffer = new StringBuilder();
}
public StringBuilder convertSinkVertexArc() {
List> arcs = new ArrayList<>();
- for (Set> arcSet: this.classDiagram.getDiagram().values()) {
+ for (Set> arcSet: classDiagram.getDiagram().values()) {
arcs.addAll(arcSet);
}
int edgeId = 0;
for (Arc arc: arcs) {
- this.graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLSinkVertexArcSyntax(getEdgesProperties(arc, edgeId)));
+ graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLSinkVertexArcSyntax(getEdgesProperties(arc, edgeId)));
edgeId++;
}
- return this.graphMLBuffer;
+ return graphMLBuffer;
}
private List getEdgesProperties(Arc relationship, Integer edgeId) {
- return
- Arrays.asList(String.valueOf(edgeId), String.valueOf(this.classDiagram.getGraphNodes().get(relationship.sourceVertex())),
- String.valueOf(this.classDiagram.getGraphNodes().get(relationship.targetVertex())), identifyEdgeType(relationship).get(EDGE_TYPE),
- identifyEdgeType(relationship).get(EDGES_SOURCE_TYPE), identifyEdgeType(relationship).get(EDGES_TARGET_TYPE));
+ return Arrays.asList(String.valueOf(edgeId), String.valueOf(classDiagram.getGraphNodes().get(relationship.sourceVertex())),
+ String.valueOf(classDiagram.getGraphNodes().get(relationship.targetVertex())), identifyEdgeType(relationship).get(EDGE_TYPE),
+ identifyEdgeType(relationship).get(EDGES_SOURCE_TYPE), identifyEdgeType(relationship).get(EDGES_TARGET_TYPE));
}
private List identifyEdgeType(Arc relationship){
diff --git a/src/main/java/model/diagram/graphml/GraphMLPackageVertex.java b/src/main/java/model/diagram/graphml/GraphMLPackageVertex.java
index fd2d618..de65706 100644
--- a/src/main/java/model/diagram/graphml/GraphMLPackageVertex.java
+++ b/src/main/java/model/diagram/graphml/GraphMLPackageVertex.java
@@ -15,25 +15,25 @@ public class GraphMLPackageVertex {
public GraphMLPackageVertex(PackageDiagram packageDiagram) {
this.packageDiagram = packageDiagram;
- this.graphMLBuffer = new StringBuilder();
+ graphMLBuffer = new StringBuilder();
}
public StringBuilder convertVertex() {
- for (Map.Entry entry: this.packageDiagram.getGraphNodes().entrySet()) {
- this.graphMLBuffer.append(GraphMLSyntax.getInstance()
- .getGraphMLVertexSyntax(getVertexDescription(entry.getKey(),
- entry.getValue(),
- this.packageDiagram.getGraphMLDiagramGeometry().get(entry.getValue()))));
+ for (Map.Entry entry: packageDiagram.getGraphNodes().entrySet()) {
+ graphMLBuffer.append(GraphMLSyntax.getInstance()
+ .getGraphMLVertexSyntax(getVertexDescription(entry.getKey(),
+ entry.getValue(),
+ packageDiagram.getGraphMLDiagramGeometry().get(entry.getValue()))));
}
- return this.graphMLBuffer;
+ return graphMLBuffer;
}
- private List getVertexDescription(PackageVertex packageNode, int nodeId, Pair nodeGeometry) {
- return Arrays.asList(
- String.valueOf(nodeId), packageNode.getName(),
- String.valueOf(nodeGeometry.getValue0()),
- String.valueOf(nodeGeometry.getValue1())
- );
+ private List getVertexDescription(PackageVertex packageNode,
+ int nodeId,
+ Pair nodeGeometry) {
+ return Arrays.asList(String.valueOf(nodeId), packageNode.getName(),
+ String.valueOf(nodeGeometry.getValue0()),
+ String.valueOf(nodeGeometry.getValue1()));
}
}
diff --git a/src/main/java/model/diagram/graphml/GraphMLPackageVertexArc.java b/src/main/java/model/diagram/graphml/GraphMLPackageVertexArc.java
index 83ef893..ccece9a 100644
--- a/src/main/java/model/diagram/graphml/GraphMLPackageVertexArc.java
+++ b/src/main/java/model/diagram/graphml/GraphMLPackageVertexArc.java
@@ -15,27 +15,27 @@ public class GraphMLPackageVertexArc {
public GraphMLPackageVertexArc(PackageDiagram packageDiagram) {
this.packageDiagram = packageDiagram;
- this.graphMLBuffer = new StringBuilder();
+ graphMLBuffer = new StringBuilder();
}
public StringBuilder convertVertexArc() {
List> arcs = new ArrayList<>();
- for (Set> arcSet: this.packageDiagram.getDiagram().values()) {
+ for (Set> arcSet: packageDiagram.getDiagram().values()) {
arcs.addAll(arcSet);
}
int edgeId = 0;
for (Arc arc: arcs) {
- this.graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLVertexArcSyntax(getVertexArcProperties(arc, edgeId)));
+ graphMLBuffer.append(GraphMLSyntax.getInstance().getGraphMLVertexArcSyntax(getVertexArcProperties(arc, edgeId)));
edgeId++;
}
- return this.graphMLBuffer;
+ return graphMLBuffer;
}
private List getVertexArcProperties(Arc relationship, Integer edgeId) {
return
Arrays.asList(String.valueOf(edgeId),
- String.valueOf(this.packageDiagram.getGraphNodes().get(relationship.sourceVertex())),
- String.valueOf(this.packageDiagram.getGraphNodes().get(relationship.targetVertex())));
+ String.valueOf(packageDiagram.getGraphNodes().get(relationship.sourceVertex())),
+ String.valueOf(packageDiagram.getGraphNodes().get(relationship.targetVertex())));
}
}
diff --git a/src/main/java/model/diagram/graphml/GraphMLSyntax.java b/src/main/java/model/diagram/graphml/GraphMLSyntax.java
index 5c14846..151dac6 100644
--- a/src/main/java/model/diagram/graphml/GraphMLSyntax.java
+++ b/src/main/java/model/diagram/graphml/GraphMLSyntax.java
@@ -9,119 +9,122 @@ public class GraphMLSyntax {
private GraphMLSyntax() {}
public String getGraphMLPrefix(){
- return
- """
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- """;
+ return """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """;
}
public String getGraphMLSuffix() {
- return
- """
-
-
-
-
-
- """;
+ return """
+
+
+
+
+
+ """;
}
public String getGraphMLSinkVertexSyntax(List sinkVertexDescription) {
- return String.format(
- """
-
-
-
-
-
-
-
-
- %s
-
- %s
- %s
-
-
-
-
- """,
- sinkVertexDescription.get(GraphMLSyntaxIds.NODE_ID.getId()), sinkVertexDescription.get(GraphMLSyntaxIds.NODE_X_COORDINATE.getId()),
- sinkVertexDescription.get(GraphMLSyntaxIds.NODE_Y_COORDINATE.getId()), sinkVertexDescription.get(GraphMLSyntaxIds.NODE_COLOR.getId()),
- sinkVertexDescription.get(GraphMLSyntaxIds.NODE_NAME.getId()), sinkVertexDescription.get(GraphMLSyntaxIds.NODE_FIELDS.getId()),
- sinkVertexDescription.get(GraphMLSyntaxIds.NODE_METHODS.getId()));
+ return String.format("""
+
+
+
+
+
+
+
+
+ %s
+
+ %s
+ %s
+
+
+
+
+ """,
+ sinkVertexDescription.get(GraphMLSyntaxIds.NODE_ID.getId()),
+ sinkVertexDescription.get(GraphMLSyntaxIds.NODE_X_COORDINATE.getId()),
+ sinkVertexDescription.get(GraphMLSyntaxIds.NODE_Y_COORDINATE.getId()),
+ sinkVertexDescription.get(GraphMLSyntaxIds.NODE_COLOR.getId()),
+ sinkVertexDescription.get(GraphMLSyntaxIds.NODE_NAME.getId()),
+ sinkVertexDescription.get(GraphMLSyntaxIds.NODE_FIELDS.getId()),
+ sinkVertexDescription.get(GraphMLSyntaxIds.NODE_METHODS.getId()));
}
public String getGraphMLVertexSyntax(List vertexDescription) {
- return String.format(
- """
-
-
-
-
-
-
-
- %s
-
-
-
- """,
- vertexDescription.get(GraphMLSyntaxIds.NODE_ID.getId()), vertexDescription.get(GraphMLSyntaxIds.PACKAGE_X_COORDINATE.getId()),
- vertexDescription.get(GraphMLSyntaxIds.PACKAGE_Y_COORDINATE.getId()), vertexDescription.get(GraphMLSyntaxIds.PACKAGE_NAME.getId()));
+ return String.format("""
+
+
+
+
+
+
+
+ %s
+
+
+
+ """,
+ vertexDescription.get(GraphMLSyntaxIds.NODE_ID.getId()),
+ vertexDescription.get(GraphMLSyntaxIds.PACKAGE_X_COORDINATE.getId()),
+ vertexDescription.get(GraphMLSyntaxIds.PACKAGE_Y_COORDINATE.getId()),
+ vertexDescription.get(GraphMLSyntaxIds.PACKAGE_NAME.getId()));
}
public String getGraphMLSinkVertexArcSyntax(List sinkVertexArcDescription) {
- return String.format(
- """
-
-
-
-
-
-
-
-
-
-
- """,
- sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_ID.getId()), sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_SOURCE.getId()),
- sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_TARGET.getId()), sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_TYPE.getId()),
- sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGES_SOURCE_TYPE.getId()), sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGES_TARGET_TYPE.getId()));
+ return String.format("""
+
+
+
+
+
+
+
+
+
+
+ """,
+ sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_ID.getId()),
+ sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_SOURCE.getId()),
+ sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_TARGET.getId()),
+ sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGE_TYPE.getId()),
+ sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGES_SOURCE_TYPE.getId()),
+ sinkVertexArcDescription.get(GraphMLSyntaxIds.EDGES_TARGET_TYPE.getId()));
}
public String getGraphMLVertexArcSyntax(List vertexArcDescription) {
- return String.format(
- """
-
-
-
-
-
-
-
-
-
-
- \
- """,
- vertexArcDescription.get(GraphMLSyntaxIds.EDGE_ID.getId()), vertexArcDescription.get(GraphMLSyntaxIds.EDGE_SOURCE.getId()),
- vertexArcDescription.get(GraphMLSyntaxIds.EDGE_TARGET.getId()));
+ return String.format("""
+
+
+
+
+
+
+
+
+
+
+ \
+ """,
+ vertexArcDescription.get(GraphMLSyntaxIds.EDGE_ID.getId()),
+ vertexArcDescription.get(GraphMLSyntaxIds.EDGE_SOURCE.getId()),
+ vertexArcDescription.get(GraphMLSyntaxIds.EDGE_TARGET.getId()));
}
public static GraphMLSyntax getInstance(){
diff --git a/src/main/java/model/diagram/javafx/ClassifierVertexDeserializer.java b/src/main/java/model/diagram/javafx/ClassifierVertexDeserializer.java
index 78234d2..3a97b72 100644
--- a/src/main/java/model/diagram/javafx/ClassifierVertexDeserializer.java
+++ b/src/main/java/model/diagram/javafx/ClassifierVertexDeserializer.java
@@ -17,7 +17,6 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
public class ClassifierVertexDeserializer implements JsonDeserializer {
private ClassifierVertex classifierVertex;
@@ -26,40 +25,40 @@ public class ClassifierVertexDeserializer implements JsonDeserializer() {}.getType())
+ JsonObject method = methods.get(i).getAsJsonObject();
+ String methodName = method.get("name").getAsString();
+ String returnType = method.get("returnType").getAsString();
+ String modifier = method.get("modifier").getAsString();
+ String parameters = method.get("parameters").getAsString();
+ classifierVertex.addMethod(methodName,
+ returnType,
+ ModifierType.get(modifier),
+ gson.fromJson(parameters,
+ new TypeToken<>() {}.getType())
);
}
}
@@ -67,28 +66,30 @@ private void deserializeMethods(JsonObject jsonObject) {
private void deserializeFields(JsonObject jsonObject) {
JsonArray fields = jsonObject.get("fields").getAsJsonArray();
for (int i = 0; i < fields.size(); i++) {
- JsonObject fieldObject = fields.get(i).getAsJsonObject();
- String fieldName = fieldObject.get("name").getAsString();
- String returnType = fieldObject.get("returnType").getAsString();
- String modifierType = fieldObject.get("modifier").getAsString();
- this.classifierVertex.addField(fieldName,
- returnType,
- ModifierType.get(modifierType)
+ JsonObject fieldObject = fields.get(i).getAsJsonObject();
+ String fieldName = fieldObject.get("name").getAsString();
+ String returnType = fieldObject.get("returnType").getAsString();
+ String modifierType = fieldObject.get("modifier").getAsString();
+ classifierVertex.addField(fieldName,
+ returnType,
+ ModifierType.get(modifierType)
);
}
}
private void deserializeArcs(JsonObject jsonObject) {
- List> arcs = new ArrayList<>();
- JsonArray arcsArray = jsonObject.get("arcs").getAsJsonArray();
+ List> arcs = new ArrayList<>();
+ JsonArray arcsArray = jsonObject.get("arcs").getAsJsonArray();
for (int i = 0; i < arcsArray.size(); i++) {
- JsonObject arcObject = arcsArray.get(i).getAsJsonObject();
- String sourceVertex = arcObject.get("source").getAsString();
- String targetVertex = arcObject.get("target").getAsString();
- String arcType = arcObject.get("arcType").getAsString();
- arcs.add(new Triplet<>(sourceVertex, targetVertex, arcType));
+ JsonObject arcObject = arcsArray.get(i).getAsJsonObject();
+ String sourceVertex = arcObject.get("source").getAsString();
+ String targetVertex = arcObject.get("target").getAsString();
+ String arcType = arcObject.get("arcType").getAsString();
+ arcs.add(new Triplet<>(sourceVertex,
+ targetVertex,
+ arcType));
}
- this.classifierVertex.setDeserializedArcs(arcs);
+ classifierVertex.setDeserializedArcs(arcs);
}
}
diff --git a/src/main/java/model/diagram/javafx/JavaFXClassDiagramLoader.java b/src/main/java/model/diagram/javafx/JavaFXClassDiagramLoader.java
index 4f66d3a..dfa104c 100644
--- a/src/main/java/model/diagram/javafx/JavaFXClassDiagramLoader.java
+++ b/src/main/java/model/diagram/javafx/JavaFXClassDiagramLoader.java
@@ -26,18 +26,20 @@ public JavaFXClassDiagramLoader(Path graphSavePath) {
}
public Set loadDiagram() throws JsonParseException {
- Set sinkVertices = new HashSet<>();
+ Set sinkVertices = new HashSet<>();
try {
- byte[] encodedBytes = Files.readAllBytes(this.graphSavePath);
- String json = new String(encodedBytes, StandardCharsets.ISO_8859_1);
- Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class,
- new ClassifierVertexDeserializer())
- .create();
+ byte[] encodedBytes = Files.readAllBytes(graphSavePath);
+ String json = new String(encodedBytes, StandardCharsets.ISO_8859_1);
+ Gson gson = new GsonBuilder().registerTypeAdapter(ClassifierVertex.class,
+ new ClassifierVertexDeserializer())
+ .create();
+
ClassifierVertex[] sinkVerticesArray = gson.fromJson(json, ClassifierVertex[].class);
Collections.addAll(sinkVertices, sinkVerticesArray);
deserializeArcs(sinkVertices);
} catch (IOException e) {
e.printStackTrace();
+ throw new RuntimeException(e);
}
return sinkVertices;
}
diff --git a/src/main/java/model/diagram/javafx/JavaFXClassVisualization.java b/src/main/java/model/diagram/javafx/JavaFXClassVisualization.java
index 5217551..e7c9c2d 100644
--- a/src/main/java/model/diagram/javafx/JavaFXClassVisualization.java
+++ b/src/main/java/model/diagram/javafx/JavaFXClassVisualization.java
@@ -42,7 +42,7 @@ public Collection> getVertexCollection(){
private Graph createGraph() {
Digraph directedGraph = new DigraphEdgeList<>();
- for (ClassifierVertex classifierVertex : this.classDiagram.getDiagram().keySet()) {
+ for (ClassifierVertex classifierVertex : classDiagram.getDiagram().keySet()) {
directedGraph.insertVertex(classifierVertex.getName());
}
insertSinkVertexArcs(directedGraph);
@@ -50,13 +50,13 @@ private Graph createGraph() {
}
private void insertSinkVertexArcs(Digraph directedGraph){
- for (Set> arcs : this.classDiagram.getDiagram().values()) {
+ for (Set> arcs : classDiagram.getDiagram().values()) {
for (Arc arc: arcs) {
if (arc.arcType().equals(ArcType.AGGREGATION)) {
directedGraph.insertEdge(arc.targetVertex().getName(),
arc.sourceVertex().getName(),
arc.targetVertex().getName() + "_" + arc.sourceVertex().getName() + "_" + arc.arcType());
- }else {
+ } else {
directedGraph.insertEdge(arc.sourceVertex().getName(),
arc.targetVertex().getName(),
arc.sourceVertex().getName() + "_" + arc.targetVertex().getName() + "_" + arc.arcType());
@@ -66,10 +66,10 @@ private void insertSinkVertexArcs(Digraph directedGraph){
}
private void setSinkVertexCustomStyle() {
- for (ClassifierVertex classifierVertex : this.classDiagram.getDiagram().keySet()){
+ for (ClassifierVertex classifierVertex : classDiagram.getDiagram().keySet()){
if (classifierVertex.getVertexType().equals(VertexType.INTERFACE)) {
graphView.getStylableVertex(classifierVertex.getName()).setStyleClass("vertexInterface");
- }else {
+ } else {
graphView.getStylableVertex(classifierVertex.getName()).setStyleClass("vertexPackage");
}
}
@@ -78,16 +78,17 @@ private void setSinkVertexCustomStyle() {
@Override
public SmartGraphPanel getLoadedGraph() {
for (Vertex vertex : vertexCollection) {
- for (ClassifierVertex classifierVertex: this.classDiagram.getDiagram().keySet()){
+ for (ClassifierVertex classifierVertex: classDiagram.getDiagram().keySet()){
if (!classifierVertex.getName().equals(vertex.element())) {
continue;
}
graphView.setVertexPosition(vertex,
- classifierVertex.getCoordinates().getValue0(),
- classifierVertex.getCoordinates().getValue1());
+ classifierVertex.getCoordinate().getX(),
+ classifierVertex.getCoordinate().getY());
break;
}
}
+
return graphView;
}
diff --git a/src/main/java/model/diagram/javafx/JavaFXPackageDiagramLoader.java b/src/main/java/model/diagram/javafx/JavaFXPackageDiagramLoader.java
index d677bc1..390f287 100644
--- a/src/main/java/model/diagram/javafx/JavaFXPackageDiagramLoader.java
+++ b/src/main/java/model/diagram/javafx/JavaFXPackageDiagramLoader.java
@@ -28,11 +28,11 @@ public JavaFXPackageDiagramLoader(Path graphSavePath) {
public Set loadDiagram() throws JsonParseException {
Set vertices = new HashSet<>();
try {
- byte[] encodedBytes = Files.readAllBytes(this.graphSavePath);
- String json = new String(encodedBytes, StandardCharsets.ISO_8859_1);
- Gson gson = new GsonBuilder().registerTypeAdapter(PackageVertex.class,
- new PackageVertexDeserializer())
- .create();
+ byte[] encodedBytes = Files.readAllBytes(graphSavePath);
+ String json = new String(encodedBytes, StandardCharsets.ISO_8859_1);
+ Gson gson = new GsonBuilder().registerTypeAdapter(PackageVertex.class,
+ new PackageVertexDeserializer())
+ .create();
PackageVertex[] verticesArray = gson.fromJson(json, PackageVertex[].class);
Collections.addAll(vertices, verticesArray);
deserializeArcs(vertices);
diff --git a/src/main/java/model/diagram/javafx/JavaFXPackageVisualization.java b/src/main/java/model/diagram/javafx/JavaFXPackageVisualization.java
index e480442..a5388aa 100644
--- a/src/main/java/model/diagram/javafx/JavaFXPackageVisualization.java
+++ b/src/main/java/model/diagram/javafx/JavaFXPackageVisualization.java
@@ -18,8 +18,8 @@
public class JavaFXPackageVisualization implements JavaFXVisualization {
private final PackageDiagram packageDiagram;
- private static SmartGraphPanel graphView;
- private static Collection> vertexCollection;
+ private SmartGraphPanel graphView;
+ private Collection> vertexCollection;
public JavaFXPackageVisualization(PackageDiagram diagram) {
this.packageDiagram = diagram;
@@ -42,7 +42,7 @@ public Collection> getVertexCollection(){
private Graph createGraph() {
Digraph directedGraph = new DigraphEdgeList<>();
- for (PackageVertex vertex: this.packageDiagram.getDiagram().keySet()) {
+ for (PackageVertex vertex: packageDiagram.getDiagram().keySet()) {
if (vertex.getSinkVertices().isEmpty()) {
continue;
}
@@ -53,13 +53,13 @@ private Graph createGraph() {
}
private void insertVertexArcs(Digraph directedGraph){
- for (Set> arcs : this.packageDiagram.getDiagram().values()) {
+ for (Set> arcs : packageDiagram.getDiagram().values()) {
for (Arc arc: arcs) {
if (arc.arcType().equals(ArcType.AGGREGATION)) {
directedGraph.insertEdge(arc.targetVertex().getName(),
arc.sourceVertex().getName(),
arc.targetVertex().getName() + "_" + arc.sourceVertex().getName() + "_" + arc.arcType());
- }else {
+ } else {
directedGraph.insertEdge(arc.sourceVertex().getName(),
arc.targetVertex().getName(),
arc.sourceVertex().getName() + "_" +arc.targetVertex().getName() + "_" + arc.arcType());
@@ -69,11 +69,11 @@ private void insertVertexArcs(Digraph directedGraph){
}
private void setVertexCustomStyle() {
- for (PackageVertex vertex: this.packageDiagram.getDiagram().keySet()){
+ for (PackageVertex vertex: packageDiagram.getDiagram().keySet()){
if (vertex.getVertexType().equals(VertexType.INTERFACE)) {
graphView.getStylableVertex(vertex.getName()).setStyleClass("vertexInterface");
- }else {
- if(vertex.getSinkVertices().isEmpty()) {
+ } else {
+ if (vertex.getSinkVertices().isEmpty()) {
continue;
}
graphView.getStylableVertex(vertex.getName()).setStyleClass("vertexPackage");
@@ -84,13 +84,13 @@ private void setVertexCustomStyle() {
@Override
public SmartGraphPanel getLoadedGraph() {
for (Vertex vertex : vertexCollection) {
- for (PackageVertex packageVertex: this.packageDiagram.getDiagram().keySet()){
- if(!packageVertex.getName().equals(vertex.element())) {
+ for (PackageVertex packageVertex: packageDiagram.getDiagram().keySet()){
+ if (!packageVertex.getName().equals(vertex.element())) {
continue;
}
graphView.setVertexPosition(vertex,
- packageVertex.getCoordinates().getValue0(),
- packageVertex.getCoordinates().getValue1());
+ packageVertex.getCoordinate().getX(),
+ packageVertex.getCoordinate().getY());
break;
}
}
diff --git a/src/main/java/model/diagram/javafx/PackageVertexDeserializer.java b/src/main/java/model/diagram/javafx/PackageVertexDeserializer.java
index 8da9f5f..a5d64d7 100644
--- a/src/main/java/model/diagram/javafx/PackageVertexDeserializer.java
+++ b/src/main/java/model/diagram/javafx/PackageVertexDeserializer.java
@@ -26,39 +26,39 @@ public class PackageVertexDeserializer implements JsonDeserializer> arcs = new ArrayList<>();
+ JsonArray arcsArray = jsonObject.get("arcs").getAsJsonArray();
+ List> arcs = new ArrayList<>();
for (int i = 0; i < arcsArray.size(); i++) {
JsonObject arcObject = arcsArray.get(i).getAsJsonObject();
String sourceVertex = arcObject.get("source").getAsString();
@@ -85,7 +85,7 @@ private void deserializeArcs(JsonObject jsonObject) {
String arcType = arcObject.get("arcType").getAsString();
arcs.add(new Triplet<>(sourceVertex, targetVertex, arcType));
}
- this.packageVertex.setDeserializedArcs(arcs);
+ packageVertex.setDeserializedArcs(arcs);
}
}
diff --git a/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertex.java b/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertex.java
index 66176ad..e6f4701 100644
--- a/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertex.java
+++ b/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertex.java
@@ -18,7 +18,7 @@ public PlantUMLClassifierVertex(ClassDiagram diagram) {
public StringBuilder convertSinkVertex() {
return new StringBuilder(
- this.classDiagram.getDiagram().keySet()
+ classDiagram.getDiagram().keySet()
.stream()
.map(sinkVertex ->
sinkVertex.getVertexType() + " " + sinkVertex.getName() + " {\n" +
diff --git a/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertexArc.java b/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertexArc.java
index b0cee52..f59b6af 100644
--- a/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertexArc.java
+++ b/src/main/java/model/diagram/plantuml/PlantUMLClassifierVertexArc.java
@@ -19,7 +19,7 @@ public PlantUMLClassifierVertexArc(ClassDiagram diagram) {
}
public StringBuilder convertSinkVertexArc() {
- return new StringBuilder(this.classDiagram.getDiagram().values()
+ return new StringBuilder(classDiagram.getDiagram().values()
.stream().flatMap(sinkVertexStream -> sinkVertexStream
.stream()
.map(sinkVertexArc -> String.join(" ",
diff --git a/src/main/java/model/diagram/plantuml/PlantUMLPackageVertex.java b/src/main/java/model/diagram/plantuml/PlantUMLPackageVertex.java
index b48cf47..a2cae18 100644
--- a/src/main/java/model/diagram/plantuml/PlantUMLPackageVertex.java
+++ b/src/main/java/model/diagram/plantuml/PlantUMLPackageVertex.java
@@ -13,7 +13,7 @@ public PlantUMLPackageVertex(PackageDiagram diagram) {
}
public StringBuilder convertVertex() {
- return new StringBuilder(this.packageDiagram.getDiagram().keySet()
+ return new StringBuilder(packageDiagram.getDiagram().keySet()
.stream()
.map(vertex -> vertex.getVertexType() + " " + vertex.getName() + " {\n" + "}\n")
.collect(Collectors.joining("\n")));
diff --git a/src/main/java/model/diagram/plantuml/PlantUMLPackageVertexArc.java b/src/main/java/model/diagram/plantuml/PlantUMLPackageVertexArc.java
index c50c969..a0dc037 100644
--- a/src/main/java/model/diagram/plantuml/PlantUMLPackageVertexArc.java
+++ b/src/main/java/model/diagram/plantuml/PlantUMLPackageVertexArc.java
@@ -19,8 +19,7 @@ public PlantUMLPackageVertexArc(PackageDiagram diagram) {
}
public StringBuilder convertVertexArc() {
-
- return new StringBuilder(this.packageDiagram.getDiagram().values()
+ return new StringBuilder(packageDiagram.getDiagram().values()
.stream()
.flatMap(vertexArcStream -> vertexArcStream
.stream()
diff --git a/src/main/java/model/graph/Arc.java b/src/main/java/model/graph/Arc.java
index a7d77f6..1ae3f11 100644
--- a/src/main/java/model/graph/Arc.java
+++ b/src/main/java/model/graph/Arc.java
@@ -2,4 +2,4 @@
public record Arc (T sourceVertex,
T targetVertex,
- ArcType arcType) { }
\ No newline at end of file
+ ArcType arcType) {}
\ No newline at end of file
diff --git a/src/main/java/model/graph/ArcType.java b/src/main/java/model/graph/ArcType.java
index 9ecbcd2..1c79de3 100644
--- a/src/main/java/model/graph/ArcType.java
+++ b/src/main/java/model/graph/ArcType.java
@@ -7,11 +7,11 @@
public enum ArcType implements Comparator
{
- DEPENDENCY(0),
- EXTENSION(1),
+ DEPENDENCY (0),
+ EXTENSION (1),
IMPLEMENTATION(2),
- AGGREGATION(3),
- ASSOCIATION(4);
+ AGGREGATION (3),
+ ASSOCIATION (4);
private static final Map DEGREE_MAP;
@@ -33,10 +33,12 @@ public static ArcType get(String arcTypeName) {
return DEGREE_MAP.get(arcTypeName.toLowerCase().trim());
}
+ @Override
public String toString() {
return super.toString().toLowerCase();
}
+ @Override
public int compare(ArcType o1, ArcType o2)
{
return Integer.compare(o1.degree, o2.degree);
diff --git a/src/main/java/model/graph/ClassifierVertex.java b/src/main/java/model/graph/ClassifierVertex.java
index 51e4a4d..f943047 100644
--- a/src/main/java/model/graph/ClassifierVertex.java
+++ b/src/main/java/model/graph/ClassifierVertex.java
@@ -1,6 +1,5 @@
package model.graph;
-import org.javatuples.Pair;
import org.javatuples.Triplet;
import java.nio.file.Path;
@@ -16,9 +15,8 @@ public class ClassifierVertex {
private final VertexType vertexType;
private final Path path;
private final String name;
+ private final VertexCoordinate coordinate;
private List> deserializedArcs;
- private double x;
- private double y;
public ClassifierVertex(Path path,
String name,
@@ -26,21 +24,28 @@ public ClassifierVertex(Path path,
this.vertexType = vertexType;
this.path = path;
this.name = name;
- this.arcs = new ArrayList<>();
- this.methods = new ArrayList<>();
- this.fields = new ArrayList<>();
+ arcs = new ArrayList<>();
+ methods = new ArrayList<>();
+ fields = new ArrayList<>();
+ coordinate = new VertexCoordinate();
+ }
+
+
+ public void updateCoordinate(double x, double y) {
+ coordinate.x = x;
+ coordinate.y = y;
}
public void addArc(ClassifierVertex sourceVertex, ClassifierVertex targetVertex, ArcType arcType) {
- this.arcs.add(new Arc<>(sourceVertex, targetVertex, arcType));
+ arcs.add(new Arc<>(sourceVertex, targetVertex, arcType));
}
public void addMethod(String name, String returnType, ModifierType modifier, Map parameters) {
- this.methods.add(new Method(name, returnType, modifier, parameters));
+ methods.add(new Method(name, returnType, modifier, parameters));
}
public void addField(String name, String type, ModifierType modifier) {
- this.fields.add(new Field(name, type, modifier));
+ fields.add(new Field(name, type, modifier));
}
public void setDeserializedArcs(List> deserializedArcs) {
@@ -48,48 +53,45 @@ public void setDeserializedArcs(List> deserializ
}
public List> getDeserializedArcs() {
- return this.deserializedArcs;
+ return deserializedArcs;
}
public VertexType getVertexType() {
- return this.vertexType;
+ return vertexType;
}
public List> getArcs() {
- return this.arcs;
+ return arcs;
}
public Path getPath() {
- return this.path;
+ return path;
}
public String getName() {
- return this.name;
+ return name;
}
public List getMethods() {
- return this.methods;
+ return methods;
}
public List getFields() {
- return this.fields;
+ return fields;
}
- public void setCoordinates(double x, double y) {
- this.x = x;
- this.y = y;
+ public VertexCoordinate getCoordinate() {
+ return coordinate;
}
- public Pair getCoordinates() {
- return new Pair<>(x, y);
- }
- public record Method (String name,
- String returnType,
- ModifierType modifier,
- Map parameters) {}
+ public record Method(String name,
+ String returnType,
+ ModifierType modifier,
+ Map parameters) {}
- public record Field(String name,
- String type,
+ public record Field(String name,
+ String type,
ModifierType modifier) {}
+
}
diff --git a/src/main/java/model/graph/ModifierType.java b/src/main/java/model/graph/ModifierType.java
index 4adc75e..02c3545 100644
--- a/src/main/java/model/graph/ModifierType.java
+++ b/src/main/java/model/graph/ModifierType.java
@@ -5,10 +5,10 @@
import java.util.Map;
public enum ModifierType {
- PRIVATE(),
- PUBLIC(),
- PROTECTED(),
- PACKAGE_PRIVATE();
+ PRIVATE,
+ PUBLIC,
+ PROTECTED,
+ PACKAGE_PRIVATE;
private static final Map MODIFIER_TYPE;
@@ -19,12 +19,14 @@ public enum ModifierType {
}
MODIFIER_TYPE = Collections.unmodifiableMap(temp);
}
+
public static ModifierType get(String modifier) {
return MODIFIER_TYPE.get(modifier.toLowerCase().trim());
}
-
+ @Override
public String toString() {
return super.toString().toLowerCase();
}
+
}
diff --git a/src/main/java/model/graph/PackageVertex.java b/src/main/java/model/graph/PackageVertex.java
index f661e5d..31c6e0c 100644
--- a/src/main/java/model/graph/PackageVertex.java
+++ b/src/main/java/model/graph/PackageVertex.java
@@ -1,6 +1,5 @@
package model.graph;
-import org.javatuples.Pair;
import org.javatuples.Triplet;
import java.nio.file.Path;
@@ -17,10 +16,9 @@ public class PackageVertex {
private final VertexType vertexType;
private final Path path;
private final String name;
+ private final VertexCoordinate coordinate;
private List> deserializedArcs;
private PackageVertex parentPackageVertex;
- private double x;
- private double y;
public PackageVertex(Path path,
VertexType vertexType,
@@ -30,19 +28,28 @@ public PackageVertex(Path path,
this.arcs = new ArrayList<>();
this.sinkVertices = new ArrayList<>();
this.neighbourVertices = new ArrayList<>();
- this.name = (parentName.isEmpty()) ? path.getFileName().toString() : parentName + "." + path.getFileName().toString();
+ this.coordinate = new VertexCoordinate();
+ this.name = parentName.isEmpty() ? path.getFileName().toString() : String.join(".",
+ parentName,
+ path.getFileName().toString());
+ }
+
+
+ public void createCoordinate(double x, double y) {
+ coordinate.x = x;
+ coordinate.y = y;
}
public void addArc(PackageVertex sourceVertex, PackageVertex targetVertex, ArcType arcType) {
- this.arcs.add(new Arc<>(sourceVertex, targetVertex, arcType));
+ arcs.add(new Arc<>(sourceVertex, targetVertex, arcType));
}
public void addSinkVertex(ClassifierVertex classifierVertex) {
- this.sinkVertices.add(classifierVertex);
+ sinkVertices.add(classifierVertex);
}
public void addNeighbourVertex(PackageVertex vertex) {
- this.neighbourVertices.add(vertex);
+ neighbourVertices.add(vertex);
}
public void setParentNode(PackageVertex parentPackageVertex) {
@@ -54,45 +61,41 @@ public void setDeserializedArcs(List> deserializ
}
public List> getDeserializedArcs() {
- return this.deserializedArcs;
+ return deserializedArcs;
}
public List> getArcs() {
- return this.arcs;
+ return arcs;
}
public List getSinkVertices() {
- return this.sinkVertices;
+ return sinkVertices;
}
public List getNeighbourVertices() {
- return this.neighbourVertices;
+ return neighbourVertices;
}
public Path getPath() {
- return this.path;
+ return path;
}
public String getName() {
- return this.name;
+ return name;
}
public VertexType getVertexType() {
- return this.vertexType;
+ return vertexType;
}
public PackageVertex getParentVertex() {
- return this.parentPackageVertex;
+ return parentPackageVertex;
}
public ModifierType getModifierType() { return VERTEX_MODIFIER_TYPE; }
- public void setCoordinates(double x, double y) {
- this.x = x;
- this.y = y;
+ public VertexCoordinate getCoordinate() {
+ return coordinate;
}
- public Pair getCoordinates() {
- return new Pair<>(x, y);
- }
}
diff --git a/src/main/java/model/graph/VertexCoordinate.java b/src/main/java/model/graph/VertexCoordinate.java
new file mode 100644
index 0000000..ce6412e
--- /dev/null
+++ b/src/main/java/model/graph/VertexCoordinate.java
@@ -0,0 +1,18 @@
+package model.graph;
+
+public class VertexCoordinate {
+ public double x;
+ public double y;
+
+ public VertexCoordinate() {}
+
+
+ public double getX() {
+ return x;
+ }
+
+ public double getY() {
+ return y;
+ }
+
+}
diff --git a/src/main/java/model/graph/VertexType.java b/src/main/java/model/graph/VertexType.java
index f5289f7..9896f73 100644
--- a/src/main/java/model/graph/VertexType.java
+++ b/src/main/java/model/graph/VertexType.java
@@ -24,7 +24,9 @@ public static VertexType get(String vertexType) {
return VERTEX_TYPE.get(vertexType.toLowerCase().trim());
}
+ @Override
public String toString() {
return super.toString().toLowerCase();
}
+
}
diff --git a/src/main/java/parser/FileVisitor.java b/src/main/java/parser/FileVisitor.java
new file mode 100644
index 0000000..7d2a5f6
--- /dev/null
+++ b/src/main/java/parser/FileVisitor.java
@@ -0,0 +1,338 @@
+package parser;
+
+import com.github.javaparser.ParserConfiguration;
+import com.github.javaparser.StaticJavaParser;
+import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.ast.ImportDeclaration;
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.body.ConstructorDeclaration;
+import com.github.javaparser.ast.body.EnumDeclaration;
+import com.github.javaparser.ast.body.FieldDeclaration;
+import com.github.javaparser.ast.body.MethodDeclaration;
+import com.github.javaparser.ast.body.RecordDeclaration;
+import com.github.javaparser.ast.expr.ObjectCreationExpr;
+import com.github.javaparser.ast.expr.VariableDeclarationExpr;
+import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
+import parser.tree.LeafNode;
+import parser.tree.LeafNodeBuilder;
+import parser.tree.ModifierType;
+import parser.tree.NodeType;
+import parser.tree.PackageNode;
+
+import java.io.FileNotFoundException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * This class is responsible for the creation of the AST of a Java source file using Javaparser.
+ * Using the different visitors, it parses the file's inheritance declarations, constructor, methods parameters,
+ * return types, field & local variable declarations as well as the instantiated objects that aren't assigned to a variable.
+ */
+public class FileVisitor {
+ private final InheritanceVisitor inheritanceVisitor = new InheritanceVisitor();
+ private final ConstructorVisitor constructorVisitor = new ConstructorVisitor();
+ private final FieldVisitor fieldNameVisitor = new FieldVisitor();
+ private final MethodVisitor methodNameVisitor = new MethodVisitor();
+ private final EnumVisitor enumVisitor = new EnumVisitor();
+ private final MemberVisitor memberVisitor = new MemberVisitor();
+ private final VariableVisitor variableVisitor = new VariableVisitor();
+ private final ObjectCreationVisitor objectCreationVisitor = new ObjectCreationVisitor();
+ private final ImportVisitor importVisitor = new ImportVisitor();
+ private final LeafNodeBuilder leafNodeBuilder;
+ private final Map variablesMap;
+ private final List objectTypes;
+ private final List methods;
+ private final List fields;
+ private final Path path;
+ private final List imports;
+ private final List createdObjects;
+ private final List unassignedObjects;
+ private final List implementedInterfaces;
+ private final List innerClasses;
+ private final List enums;
+ private final List records;
+ private NodeType nodeType;
+ private boolean isClassOrInterface;
+ private String baseClass;
+ private String nodeName;
+
+ /**
+ * The FileVisitor's default constructor
+ *
+ * @param parentNode the LeafNode representing the Java source file that we are visiting
+ */
+ public FileVisitor(PackageNode parentNode, Path path) {
+ this.leafNodeBuilder = new LeafNodeBuilder(parentNode, path);
+ this.createdObjects = new ArrayList<>();
+ this.unassignedObjects = new ArrayList<>();
+ this.imports = new ArrayList<>();
+ this.implementedInterfaces = new ArrayList<>();
+ this.objectTypes = new ArrayList<>();
+ this.methods = new ArrayList<>();
+ this.fields = new ArrayList<>();
+ this.enums = new ArrayList<>();
+ this.records = new ArrayList<>();
+ this.variablesMap = new HashMap<>();
+ this.innerClasses = new ArrayList<>();
+ this.path = path;
+ this.baseClass = "";
+ this.nodeName = "";
+ this.nodeType = null;
+ }
+
+ /**
+ * This method is responsible for the creation of the AST.
+ */
+ public LeafNode createAST() {
+ try {
+ StaticJavaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_17);
+ CompilationUnit compilationUnit = StaticJavaParser.parse(path.toFile());
+
+ isClassOrInterface = false;
+ compilationUnit.accept(inheritanceVisitor, null);
+
+ if (!isClassOrInterface) {
+ compilationUnit.accept(enumVisitor, null);
+ } else {
+ compilationUnit.accept(importVisitor, null);
+ compilationUnit.accept(memberVisitor, null);
+ compilationUnit.accept(constructorVisitor, null);
+ compilationUnit.accept(fieldNameVisitor, null);
+ compilationUnit.accept(variableVisitor, null);
+ compilationUnit.accept(methodNameVisitor, null);
+ compilationUnit.accept(objectCreationVisitor, null);
+ unassignedObjects.addAll(populateCreatedObjects());
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ return leafNodeBuilder.setNodeType(nodeType)
+ .setBaseClass(baseClass)
+ .setFields(fields)
+ .setCreatedObjects(unassignedObjects)
+ .setMethods(methods)
+ .setNodeName(nodeName)
+ .setVariables(variablesMap)
+ .setImports(imports)
+ .setRecords(records)
+ .setInnerClasses(innerClasses)
+ .setImplementedInterface(implementedInterfaces)
+ .setInnerEnums(enums)
+ .build();
+ }
+
+ private class InheritanceVisitor extends VoidVisitorAdapter {
+
+ @Override
+ public void visit(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, Void arg) {
+ super.visit(classOrInterfaceDeclaration, arg);
+
+ if (!path.endsWith(classOrInterfaceDeclaration.getNameAsString() + ".java")) {
+ innerClasses.add(classOrInterfaceDeclaration.getNameAsString());
+ return;
+ }
+ nodeName = classOrInterfaceDeclaration.getNameAsString();
+ isClassOrInterface = true;
+ NodeType localnodeType;
+ if (classOrInterfaceDeclaration.isInterface()) {
+ localnodeType = NodeType.INTERFACE;
+ } else {
+ localnodeType = NodeType.CLASS;
+ classOrInterfaceDeclaration.getExtendedTypes()
+ .forEach(classOrInterfaceType -> baseClass = classOrInterfaceType.getNameAsString());
+ }
+
+ nodeType = localnodeType;
+ classOrInterfaceDeclaration.getImplementedTypes()
+ .forEach(classOrInterfaceType -> implementedInterfaces.add(classOrInterfaceType.getNameAsString()));
+
+ }
+ }
+
+ private class ConstructorVisitor extends VoidVisitorAdapter {
+
+ @Override
+ public void visit(ConstructorDeclaration constructorDeclaration, Void arg) {
+ super.visit(constructorDeclaration, arg);
+
+ ModifierType modifierType;
+ if (constructorDeclaration.getModifiers().isEmpty()) {
+ modifierType = ModifierType.PACKAGE_PRIVATE;
+ } else {
+ modifierType = ModifierType.get(constructorDeclaration.getModifiers().get(0).toString());
+ }
+
+ Map parameters = new HashMap<>();
+ constructorDeclaration.getParameters()
+ .forEach(parameter -> parameters.put(parameter.getNameAsString(),
+ getType(parameter.getTypeAsString())));
+ methods.add(new LeafNode.Method(constructorDeclaration.getNameAsString(),
+ "Constructor",
+ modifierType,
+ parameters));
+ }
+ }
+
+ private class FieldVisitor extends VoidVisitorAdapter {
+ private ModifierType modifierType;
+
+ @Override
+ public void visit(FieldDeclaration fieldDeclaration, Void arg) {
+ super.visit(fieldDeclaration, arg);
+
+ fieldDeclaration.getVariables().forEach(variable -> {
+ if (fieldDeclaration.getModifiers().isEmpty()) {
+ this.modifierType = ModifierType.PACKAGE_PRIVATE;
+ } else {
+ this.modifierType = ModifierType.get(fieldDeclaration.getModifiers().get(0).toString());
+ }
+ fields.add(new LeafNode.Field(variable.getNameAsString(),
+ getType(variable.getTypeAsString()),
+ modifierType));
+ });
+ }
+ }
+
+ private class VariableVisitor extends VoidVisitorAdapter {
+
+ @Override
+ public void visit(VariableDeclarationExpr variableDeclarationExpr, Void arg) {
+ super.visit(variableDeclarationExpr, null);
+
+ Pattern pattern = Pattern.compile("[A-Za-z0-9]+ [A-Za-z0-9]+ = new ([A-Za-z0-9]+)\\([A-Za-z0-9]*[, A-Za-z0-9*]*\\)");
+ Matcher matcher = pattern.matcher(variableDeclarationExpr.toString());
+ if (!matcher.find()) {
+ return;
+ }
+ objectTypes.add(matcher.group(1));
+ variableDeclarationExpr.getVariables()
+ .forEach(variableDeclaration -> variablesMap.put(variableDeclaration.getNameAsString(),
+ getType(variableDeclaration.getTypeAsString())));
+ }
+ }
+
+ private class MethodVisitor extends VoidVisitorAdapter {
+
+ @Override
+ public void visit(MethodDeclaration methodDeclaration, Void arg) {
+ super.visit(methodDeclaration, arg);
+
+ ModifierType modifierType;
+ if (methodDeclaration.getModifiers().isEmpty()) {
+ modifierType = ModifierType.PACKAGE_PRIVATE;
+ } else {
+ modifierType = ModifierType.get(methodDeclaration.getModifiers().get(0).toString());
+ }
+ Map parameters = new HashMap<>();
+ methodDeclaration.getParameters()
+ .forEach(parameter -> parameters.put(parameter.getNameAsString(),
+ getType(parameter.getTypeAsString())));
+ methods.add(new LeafNode.Method(methodDeclaration.getNameAsString(),
+ getType(methodDeclaration.getTypeAsString()),
+ modifierType,
+ parameters));
+ }
+ }
+
+ private class ObjectCreationVisitor extends VoidVisitorAdapter {
+
+ @Override
+ public void visit(ObjectCreationExpr objectCreationExpr, Void arg) {
+ super.visit(objectCreationExpr, arg);
+
+ createdObjects.add(getType(objectCreationExpr.asObjectCreationExpr().getType().asString()));
+ }
+
+ }
+
+ private class EnumVisitor extends VoidVisitorAdapter {
+
+ @Override
+ public void visit(EnumDeclaration enumDeclaration, Void arg) {
+ super.visit(enumDeclaration, arg);
+
+ nodeName = enumDeclaration.getNameAsString();
+ nodeType = NodeType.ENUM;
+ }
+
+ }
+
+ private class MemberVisitor extends VoidVisitorAdapter {
+
+ public void visit(EnumDeclaration enumDeclaration, Void arg) {
+ super.visit(enumDeclaration, arg);
+
+ enums.add(enumDeclaration.getNameAsString());
+ }
+
+ public void visit(RecordDeclaration n, Void arg) {
+ super.visit(n, arg);
+
+ records.add(n.getNameAsString());
+ }
+
+ }
+
+ private class ImportVisitor extends VoidVisitorAdapter {
+
+ public void visit(ImportDeclaration importDeclaration, Void arg) {
+ super.visit(importDeclaration, arg);
+
+ imports.add(importDeclaration
+ .getNameAsString()
+ .replaceFirst("^import ", "").trim()
+ .replaceAll(";$", ""));
+ }
+
+ }
+
+ private List populateCreatedObjects() {
+ List notAssignedCreatedObjects = filterAssignedCreatedObjects(fields.stream().map(LeafNode.Field::fieldType).collect(Collectors.toCollection(ArrayList::new)),
+ createdObjects);
+ notAssignedCreatedObjects = filterAssignedCreatedObjects(new ArrayList<>(variablesMap.values()),
+ notAssignedCreatedObjects);
+ notAssignedCreatedObjects = filterAssignedCreatedObjects(objectTypes,
+ notAssignedCreatedObjects);
+ return notAssignedCreatedObjects;
+ }
+
+ private List filterAssignedCreatedObjects(List assignedObjects,
+ List createdObjects) {
+ List newList = new ArrayList<>();
+ Collections.sort(assignedObjects);
+ Collections.sort(createdObjects);
+ int i = 0;
+ int j = 0;
+
+ main:
+ while (i < createdObjects.size()) {
+ while (j < assignedObjects.size()) {
+ if (createdObjects.get(i).equals(assignedObjects.get(j))) {
+ j++;
+ } else {
+ newList.add(createdObjects.get(i));
+ }
+ i++;
+ if (i == createdObjects.size()) {
+ break main;
+ }
+ }
+ newList.add(createdObjects.get(i));
+ i++;
+ }
+ return newList;
+ }
+
+ private static String getType(String type) {
+ return type.replaceAll("<", "[").replaceAll(">", "]");
+ }
+}
diff --git a/src/main/java/parser/IRelationshipIdentifier.java b/src/main/java/parser/IRelationshipIdentifier.java
new file mode 100644
index 0000000..9bdefea
--- /dev/null
+++ b/src/main/java/parser/IRelationshipIdentifier.java
@@ -0,0 +1,35 @@
+package parser;
+
+import parser.factory.Parser;
+import parser.tree.LeafNode;
+import parser.tree.PackageNode;
+import parser.tree.Relationship;
+
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This class is responsible for the creation of the branches between the Java
+ * source files. The branches have a type, e.g., inheritance, implementation.
+ * The branches are also directed with a starting and an ending node.
+ */
+public interface IRelationshipIdentifier {
+
+ /**
+ * This method is responsible for creating the relationships of the package and leaf nodes.
+ *
+ * @param packageNodes The collection of package nodes that have been parsed.
+ * @return The collection of relationships that were created.
+ */
+ Map>> createLeafNodesRelationships(Map packageNodes);
+
+ /**
+ * This method identifies the package node relationships by parsing the created leaf node relationships.
+ *
+ * @param leafNodeRelationships The relationships that were created by {@link Parser#createRelationships(Map)}.
+ * @return The package node relationships that were created by parsing the leaf node relationships.
+ */
+ Map>> identifyPackageNodeRelationships(Map>> leafNodeRelationships);
+}
diff --git a/src/main/java/parser/Interpreter.java b/src/main/java/parser/Interpreter.java
index 418f739..39fb5cc 100644
--- a/src/main/java/parser/Interpreter.java
+++ b/src/main/java/parser/Interpreter.java
@@ -16,100 +16,113 @@
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
public class Interpreter {
private static final ParserType PARSER_TYPE = ParserType.JAVAPARSER;
- private final Map packageNodeVertexMap;
- private final Map leafNodeSinkVertexMap;
- private final Map vertices;
- private final Map sinkVertices;
- private Map packageNodes;
+ private final Map packageNodeVertexMap;
+ private final Map leafNodeSinkVertexMap;
+ private final Map vertices;
+ private final Map sinkVertices;
+ private Map>> packageNodeRelationships;
+ private Map>> leafNodeRelationships;
+ private Map packageNodes;
public Interpreter() {
- this.vertices = new HashMap<>();
- this.sinkVertices = new HashMap<>();
- this.packageNodeVertexMap = new HashMap<>();
- this.leafNodeSinkVertexMap = new HashMap<>();
+ vertices = new HashMap<>();
+ sinkVertices = new HashMap<>();
+ packageNodeVertexMap = new HashMap<>();
+ leafNodeSinkVertexMap = new HashMap<>();
}
public void parseProject(Path sourcePackagePath) {
- Parser projectParser = ProjectParserFactory.createProjectParser(PARSER_TYPE);
- this.packageNodes = projectParser.parseSourcePackage(sourcePackagePath);
+ Parser projectParser = ProjectParserFactory.createProjectParser(PARSER_TYPE);
+ packageNodes = projectParser.parseSourcePackage(sourcePackagePath);
+ leafNodeRelationships = projectParser.createRelationships(packageNodes);
+ packageNodeRelationships = projectParser.identifyPackageNodeRelationships(leafNodeRelationships);
}
public void convertTreeToGraph() {
- PackageNodeCleaner packageNodeCleaner = new PackageNodeCleaner(this.packageNodes);
- this.packageNodes = packageNodeCleaner.removeNonPackageNodes();
+ packageNodes = PackageNodeCleaner.removeNonPackageNodes(packageNodes);
populateVertexMaps();
addVertexArcs();
- this.leafNodeSinkVertexMap.values().forEach(sinkVertex -> sinkVertices.put(sinkVertex.getPath(), sinkVertex));
- this.packageNodeVertexMap.values().forEach(vertex -> vertices.put(vertex.getPath(), vertex));
+ leafNodeSinkVertexMap.values()
+ .forEach(sinkVertex -> sinkVertices.put(sinkVertex.getPath(), sinkVertex));
+ packageNodeVertexMap.values()
+ .forEach(vertex -> vertices.put(vertex.getPath(), vertex));
}
private void populateVertexMaps() {
- for (PackageNode packageNode: this.packageNodes.values()) {
- PackageVertex vertex = this.packageNodeVertexMap
+ for (PackageNode packageNode: packageNodes.values()) {
+ PackageVertex vertex = packageNodeVertexMap
.computeIfAbsent(packageNode, k ->
- new PackageVertex(packageNode.getPackageNodesPath(),
- EnumMapper.vertexTypeEnumMap.get(packageNode.getType()),
- packageNode.getParentNode().getName())
- );
+ new PackageVertex(packageNode.getPath(),
+ TypeConverter.convertVertexType(packageNode.getNodeType()),
+ packageNode.getParentNode().getNodeName()));
+
for (LeafNode leafNode: packageNode.getLeafNodes().values()) {
- vertex.addSinkVertex(this.leafNodeSinkVertexMap.computeIfAbsent(leafNode, k -> createSinkVertex(leafNode)));
+ vertex.addSinkVertex(leafNodeSinkVertexMap.computeIfAbsent(leafNode, k -> createSinkVertex(leafNode)));
}
}
- for (PackageNode packageNode: this.packageNodes.values()) {
- this.packageNodeVertexMap.get(packageNode)
- .setParentNode(
- this.packageNodeVertexMap.getOrDefault(packageNode.getParentNode(),
- new PackageVertex(Paths.get(""),
- VertexType.PACKAGE,
- ""))
- );
+ for (PackageNode packageNode: packageNodes.values()) {
+ packageNodeVertexMap.get(packageNode)
+ .setParentNode(packageNodeVertexMap.getOrDefault(packageNode.getParentNode(),
+ new PackageVertex(Paths.get(""),
+ VertexType.PACKAGE,
+ "")));
+
for (PackageNode subNode: packageNode.getSubNodes().values()) {
- this.packageNodeVertexMap.get(packageNode).addNeighbourVertex(this.packageNodeVertexMap.get(subNode));
+ packageNodeVertexMap.get(packageNode).addNeighbourVertex(packageNodeVertexMap.get(subNode));
}
}
}
private void addVertexArcs() {
- for (PackageNode packageNode: this.packageNodes.values()) {
- PackageVertex vertex = this.packageNodeVertexMap.get(packageNode);
- for (Relationship relationship: packageNode.getPackageNodeRelationships()) {
- vertex.addArc(vertex, this.packageNodeVertexMap.get(relationship.endingNode()), EnumMapper.edgeEnumMap.get(relationship.relationshipType()));
+ for (PackageNode packageNode: packageNodes.values()) {
+ PackageVertex vertex = packageNodeVertexMap.get(packageNode);
+ if (packageNodeRelationships.containsKey(packageNode)) {
+ for (Relationship relationship : packageNodeRelationships.get(packageNode)) {
+ vertex.addArc(vertex,
+ packageNodeVertexMap.get(relationship.endingNode()),
+ TypeConverter.convertRelationshipType(relationship.relationshipType()));
+ }
+ addSinkVertexArcs(packageNode);
}
- addSinkVertexArcs(packageNode);
}
}
private void addSinkVertexArcs(PackageNode packageNode) {
for (LeafNode leafNode: packageNode.getLeafNodes().values()) {
- ClassifierVertex classifierVertex = this.leafNodeSinkVertexMap.get(leafNode);
- for (Relationship relationship: leafNode.getLeafNodeRelationships()) {
- classifierVertex.addArc(classifierVertex, this.leafNodeSinkVertexMap.get(relationship.endingNode()), EnumMapper.edgeEnumMap.get(relationship.relationshipType()));
+ ClassifierVertex classifierVertex = leafNodeSinkVertexMap.get(leafNode);
+ if (leafNodeRelationships.containsKey(leafNode)) {
+ for (Relationship relationship : leafNodeRelationships.get(leafNode)) {
+ classifierVertex.addArc(classifierVertex,
+ leafNodeSinkVertexMap.get(relationship.endingNode()),
+ TypeConverter.convertRelationshipType(relationship.relationshipType()));
+ }
}
}
}
private ClassifierVertex createSinkVertex(LeafNode leafNode) {
- ClassifierVertex classifierVertex = new ClassifierVertex(leafNode.getLeafNodesPath(), leafNode.getName(), EnumMapper.vertexTypeEnumMap.get(leafNode.getType()));
- leafNode.getFields()
+ ClassifierVertex classifierVertex = new ClassifierVertex(leafNode.path(),
+ leafNode.nodeName(),
+ TypeConverter.convertVertexType(leafNode.nodeType()));
+ leafNode.fields()
.forEach(field ->
- classifierVertex.addField(field.getValue0(),
- field.getValue1(),
- EnumMapper.modifierTypeEnumMap.get(field.getValue2()))
- );
- leafNode.getMethods()
- .forEach((method, parameters) ->
- classifierVertex.addMethod(method.getValue0().split("\\$")[0],
- method.getValue1(), EnumMapper.modifierTypeEnumMap.get(method.getValue2()),
- parameters)
- );
+ classifierVertex.addField(field.fieldNames(),
+ field.fieldType(),
+ TypeConverter.convertModifierType(field.modifierType())));
+ leafNode.methods()
+ .forEach((method) ->
+ classifierVertex.addMethod(method.methodName(),
+ method.returnType(),
+ TypeConverter.convertModifierType(method.modifierType()),
+ method.parameters()));
return classifierVertex;
}
@@ -125,35 +138,43 @@ public Map getSinkVertices() {
return sinkVertices;
}
- private static class EnumMapper {
-
- private static final EnumMap vertexTypeEnumMap = new EnumMap<>(
- Map.of(
- NodeType.CLASS, VertexType.CLASS,
- NodeType.INTERFACE, VertexType.INTERFACE,
- NodeType.ENUM, VertexType.ENUM,
- NodeType.PACKAGE, VertexType.PACKAGE
- )
- );
-
- private static final EnumMap edgeEnumMap = new EnumMap<>(
- Map.of(
- RelationshipType.DEPENDENCY, ArcType.DEPENDENCY,
- RelationshipType.ASSOCIATION, ArcType.ASSOCIATION,
- RelationshipType.AGGREGATION, ArcType.AGGREGATION,
- RelationshipType.IMPLEMENTATION, ArcType.IMPLEMENTATION,
- RelationshipType.EXTENSION, ArcType.EXTENSION
- )
- );
-
- private static final EnumMap modifierTypeEnumMap = new EnumMap<>(
- Map.of(
- ModifierType.PRIVATE, model.graph.ModifierType.PRIVATE,
- ModifierType.PUBLIC, model.graph.ModifierType.PUBLIC,
- ModifierType.PROTECTED, model.graph.ModifierType.PROTECTED,
- ModifierType.PACKAGE_PRIVATE, model.graph.ModifierType.PACKAGE_PRIVATE
- )
- );
+ public Map>> getPackageNodeRelationships() {
+ return packageNodeRelationships;
+ }
+
+ public Map>> getLeafNodeRelationships() {
+ return leafNodeRelationships;
+ }
+
+ private static class TypeConverter {
+
+ private static VertexType convertVertexType(NodeType nodeType) {
+ return switch (nodeType) {
+ case CLASS -> VertexType.CLASS;
+ case INTERFACE -> VertexType.INTERFACE;
+ case ENUM -> VertexType.ENUM;
+ case PACKAGE -> VertexType.PACKAGE;
+ };
+ }
+
+ private static ArcType convertRelationshipType(RelationshipType relationshipType) {
+ return switch (relationshipType) {
+ case DEPENDENCY -> ArcType.DEPENDENCY;
+ case ASSOCIATION -> ArcType.ASSOCIATION;
+ case AGGREGATION -> ArcType.AGGREGATION;
+ case IMPLEMENTATION -> ArcType.IMPLEMENTATION;
+ case EXTENSION -> ArcType.EXTENSION;
+ };
+ }
+
+ private static model.graph.ModifierType convertModifierType(ModifierType modifierType) {
+ return switch (modifierType) {
+ case PRIVATE -> model.graph.ModifierType.PRIVATE;
+ case PUBLIC -> model.graph.ModifierType.PUBLIC;
+ case PROTECTED -> model.graph.ModifierType.PROTECTED;
+ case PACKAGE_PRIVATE -> model.graph.ModifierType.PACKAGE_PRIVATE;
+ };
+ }
}
}
diff --git a/src/main/java/parser/PackageNodeCleaner.java b/src/main/java/parser/PackageNodeCleaner.java
index 5aeb5ab..25f7183 100644
--- a/src/main/java/parser/PackageNodeCleaner.java
+++ b/src/main/java/parser/PackageNodeCleaner.java
@@ -7,30 +7,25 @@
import java.util.Map;
public class PackageNodeCleaner {
- private final Map packageNodes;
- public PackageNodeCleaner(Map packageNodes) {
- this.packageNodes = packageNodes;
- }
-
- public Map removeNonPackageNodes() {
+ public static Map removeNonPackageNodes(Map