Skip to content

Commit

Permalink
Merge pull request #31 from DAINTINESS-Group/parser
Browse files Browse the repository at this point in the history
Merge branch parser into dev
  • Loading branch information
dimanyfantakis authored Jan 5, 2024
2 parents a9f4bf6 + 864d2dc commit eb175c8
Show file tree
Hide file tree
Showing 122 changed files with 3,534 additions and 3,694 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
A tool for the reverse engineering of Java object-oriented source code into Unified Modeling Language (UML) diagrams
</p>

![workflow][workflow-url]
[![Contributors][contributors-shield]][contributors-url]
[![Commits][commits-shield]][commits-url]
[![Forks][forks-shield]][forks-url]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public interface Controller {
SmartGraphPanel<String, String> 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
*/
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/controller/ControllerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

}
2 changes: 2 additions & 0 deletions src/main/java/controller/ControllerType.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public static ControllerType get(String controllerType) {
return CONTROLLER_TYPE.get(controllerType.toLowerCase());
}

@Override
public String toString() {
return super.toString().toLowerCase();
}

}
9 changes: 6 additions & 3 deletions src/main/java/manager/ClassDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -119,9 +118,11 @@ public SmartGraphPanel<String, String> applyLayout() {
if (!nodesGeometry.containsKey(vertex.element())) {
continue;
}

Pair<Double, Double> coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1());
}

return graphView;
}

Expand All @@ -131,9 +132,11 @@ public SmartGraphPanel<String, String> applySpecificLayout(String choice){
if (!nodesGeometry.containsKey(vertex.element())) {
continue;
}

Pair<Double, Double> coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1());
}

return graphView;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/manager/DiagramManagerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/manager/DiagramType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ public enum DiagramType {
for (DiagramType diagramType: DiagramType.values()) {
map.put(diagramType.toString().toLowerCase(), diagramType);
}

DIAGRAM_TYPE = Collections.unmodifiableMap(map);
}

public static DiagramType get(String diagramType) {
return DIAGRAM_TYPE.get(diagramType.toLowerCase().trim());
}

@Override
public String toString() {
return super.toString().toLowerCase();
}

}
13 changes: 8 additions & 5 deletions src/main/java/manager/PackageDiagramManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -52,7 +51,7 @@ public void convertTreeToDiagram(List<String> chosenFilesNames) {
}

@Override
public void arrangeDiagram(){
public void arrangeDiagram() {
packageDiagramArrangement = new PackageDiagramArrangementManager(packageDiagram);
DiagramGeometry diagramGeometry = packageDiagramArrangement.arrangeDiagram();
packageDiagram.setDiagramGeometry(diagramGeometry);
Expand Down Expand Up @@ -120,21 +119,25 @@ public SmartGraphPanel<String, String> applyLayout() {
logger.log(Level.INFO, vertex.element());
continue;
}

Pair<Double, Double> coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1());
}

return graphView;
}

public SmartGraphPanel<String, String> applySpecificLayout(String choice){
DiagramGeometry nodesGeometry = packageDiagramArrangement.applyNewLayout(choice);
for(Vertex<String> vertex : vertexCollection) {
if(!nodesGeometry.containsKey(vertex.element())) {
if (!nodesGeometry.containsKey(vertex.element())) {
continue;
}

Pair<Double, Double> coordinates = nodesGeometry.getVertexGeometry(vertex.element());
graphView.setVertexPosition(vertex, coordinates.getValue0(), coordinates.getValue1());
}

return graphView;
}

Expand Down
24 changes: 5 additions & 19 deletions src/main/java/manager/SourceProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/model/diagram/ClassDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ClassDiagram() {

public void createNewDiagram(List<String> chosenFilesNames) {
createGraphNodes(chosenFilesNames);
createDiagram(this.graphNodes.keySet());
createDiagram(graphNodes.keySet());
}

public void createDiagram(Set<ClassifierVertex> sinkVertices) {
Expand All @@ -38,7 +38,7 @@ public void createDiagram(Set<ClassifierVertex> sinkVertices) {
private void createGraphNodes(List<String> chosenFileNames) {
int nodeId = 0;
for (ClassifierVertex classifierVertex : getChosenNodes(chosenFileNames)) {
this.graphNodes.put(classifierVertex, nodeId);
graphNodes.put(classifierVertex, nodeId);
nodeId++;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/model/diagram/GraphClassDiagramConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ public class GraphClassDiagramConverter {

public GraphClassDiagramConverter(Set<ClassifierVertex> sinkVertices) {
this.sinkVertices = sinkVertices;
this.adjacencyList = new HashMap<>();
adjacencyList = new HashMap<>();
}

public Map<ClassifierVertex, Set<Arc<ClassifierVertex>>> convertGraphToClassDiagram() {
for (ClassifierVertex classifierVertex : this.sinkVertices) {
this.adjacencyList.put(classifierVertex, new HashSet<>());
for (ClassifierVertex classifierVertex : sinkVertices) {
adjacencyList.put(classifierVertex, new HashSet<>());
for (Arc<ClassifierVertex> 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;
}

}
13 changes: 7 additions & 6 deletions src/main/java/model/diagram/GraphPackageDiagramConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ public class GraphPackageDiagramConverter {

public GraphPackageDiagramConverter(Set<PackageVertex> vertices) {
this.vertices = vertices;
this.adjacencyList = new HashMap<>();
adjacencyList = new HashMap<>();
}

public Map<PackageVertex, Set<Arc<PackageVertex>>> convertGraphToPackageDiagram() {
for (PackageVertex vertex: this.vertices) {
this.adjacencyList.put(vertex, new HashSet<>());
for (PackageVertex vertex: vertices) {
adjacencyList.put(vertex, new HashSet<>());
for (Arc<PackageVertex> 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;
}

}
6 changes: 3 additions & 3 deletions src/main/java/model/diagram/PackageDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class PackageDiagram {

private final Map<PackageVertex, Integer> graphNodes;
private final Map<PackageVertex, Integer> graphNodes;
private static Map<PackageVertex, Set<Arc<PackageVertex>>> diagram;
private static Map<Path, PackageVertex> vertices;
private static Map<Integer, Pair<Double, Double>> diagramGeometryGraphML;
Expand All @@ -22,7 +22,7 @@ public PackageDiagram() {

public void createNewDiagram(List<String> chosenFileNames) {
createGraphNodes(chosenFileNames);
createDiagram(this.graphNodes.keySet());
createDiagram(graphNodes.keySet());
}

public void createDiagram(Set<PackageVertex> vertices) {
Expand All @@ -33,7 +33,7 @@ public void createDiagram(Set<PackageVertex> vertices) {
private void createGraphNodes(List<String> chosenFileNames) {
int nodeId = 0;
for (PackageVertex vertex: getChosenNodes(chosenFileNames)) {
this.graphNodes.put(vertex, nodeId);
graphNodes.put(vertex, nodeId);
nodeId++;
}
}
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/model/diagram/ShadowCleaner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClassifierVertex, Set<Arc<ClassifierVertex>>> shadowWeakRelationships() {
for (Set<Arc<ClassifierVertex>> arcs: this.classDiagram.getDiagram().values()) {
for (Set<Arc<ClassifierVertex>> arcs: classDiagram.getDiagram().values()) {
Map<ClassifierVertex, List<Arc<ClassifierVertex>>> shadowedArcs = new HashMap<>();
for (Arc<ClassifierVertex> arc: arcs) {
shadowedArcs.computeIfAbsent(arc.targetVertex(), sinkVertex -> new ArrayList<>()).add(arc);
shadowedArcs.computeIfAbsent(arc.targetVertex(),
sinkVertex -> new ArrayList<>()).add(arc);
}

for (Map.Entry<ClassifierVertex, List<Arc<ClassifierVertex>>> arc: shadowedArcs.entrySet()) {
if (!doWeakRelationshipsExist(arc)) {
if (!(arc.getValue().size() > 1)) {
continue;
}
for (ArcType arcType: strongerToWeakerArcTypes) {
Expand All @@ -40,22 +41,24 @@ public Map<ClassifierVertex, Set<Arc<ClassifierVertex>>> shadowWeakRelationships
}
}
}
return this.classDiagram.getDiagram();
}

private boolean doWeakRelationshipsExist(Map.Entry<ClassifierVertex, List<Arc<ClassifierVertex>>> arc) {
return arc.getValue().size() > 1;
return classDiagram.getDiagram();
}

private boolean doesStrongerRelationshipExist(List<Arc<ClassifierVertex>> arc, ArcType arcType) {
private boolean doesStrongerRelationshipExist(List<Arc<ClassifierVertex>> arc,
ArcType arcType) {
Optional<Arc<ClassifierVertex>> inheritanceArc = arc
.stream()
.filter(sinkVertexArc -> sinkVertexArc.arcType().equals(arcType))
.findFirst();
return inheritanceArc.isPresent();
}

private void removeWeakerRelationships(Set<Arc<ClassifierVertex>> arcs, ClassifierVertex classifierVertex, ArcType arcType) {
arcs.removeIf(arc -> arc.targetVertex().equals(classifierVertex) && !arc.arcType().equals(arcType));
private void removeWeakerRelationships(Set<Arc<ClassifierVertex>> arcs,
ClassifierVertex classifierVertex,
ArcType arcType) {
arcs.removeIf(arc ->
arc.targetVertex().equals(classifierVertex) &&
!arc.arcType().equals(arcType));
}
}
Loading

0 comments on commit eb175c8

Please sign in to comment.