Skip to content

Commit

Permalink
Merge pull request #37 from DAINTINESS-Group/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
dimanyfantakis authored Apr 7, 2024
2 parents c104c8c + ffc3ac0 commit 288424c
Show file tree
Hide file tree
Showing 34 changed files with 942 additions and 1,304 deletions.
18 changes: 11 additions & 7 deletions src/main/java/parser/FileVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static parser.tree.ModifierType.PACKAGE_PRIVATE;
import static parser.tree.NodeType.ENUM;

/**
* This class is responsible for the creation of the AST of a Java source file using {@link JavaParser}.
* Using the different visitors, it parses the file's inheritance declarations,
Expand Down Expand Up @@ -183,11 +186,12 @@ public void visit(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, Void
.setImplementedInterface(innerImplementedInterfaces)
.build();
innerClasses.add(innerClass);

return;
}

nodeName = classOrInterfaceDeclaration.getNameAsString();
NodeType localNodeType = classOrInterfaceDeclaration.isInterface() ?
nodeType = classOrInterfaceDeclaration.isInterface() ?
NodeType.INTERFACE :
NodeType.CLASS;

Expand All @@ -196,8 +200,7 @@ public void visit(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, Void
baseClass = classOrInterfaceDeclaration.getExtendedTypes().get(0).getNameAsString();
}

nodeType = localNodeType;
ArrayList<String> implementedTypes =
List<String> implementedTypes =
classOrInterfaceDeclaration.getImplementedTypes()
.stream()
.map(NodeWithSimpleName::getNameAsString)
Expand All @@ -215,12 +218,13 @@ public void visit(ConstructorDeclaration constructorDeclaration, Void arg)
super.visit(constructorDeclaration, arg);

ModifierType modifierType = constructorDeclaration.getModifiers().isEmpty() ?
ModifierType.PACKAGE_PRIVATE :
PACKAGE_PRIVATE :
ModifierType.get(constructorDeclaration.getModifiers().get(0).toString());

Map<String, String> parameters = constructorDeclaration.getParameters().stream()
.collect(Collectors.toMap(NodeWithSimpleName::getNameAsString,
parameter -> getType(parameter.getTypeAsString())));

methods.add(new LeafNode.Method(constructorDeclaration.getNameAsString(),
"Constructor",
modifierType,
Expand All @@ -239,7 +243,7 @@ public void visit(FieldDeclaration fieldDeclaration, Void arg)
for (VariableDeclarator variable : fieldDeclaration.getVariables())
{
ModifierType modifierType = fieldDeclaration.getModifiers().isEmpty() ?
ModifierType.PACKAGE_PRIVATE :
PACKAGE_PRIVATE :
ModifierType.get(fieldDeclaration.getModifiers().get(0).toString());

fields.add(new LeafNode.Field(variable.getNameAsString(),
Expand Down Expand Up @@ -277,7 +281,7 @@ public void visit(MethodDeclaration methodDeclaration, Void arg)
super.visit(methodDeclaration, arg);

ModifierType modifierType = methodDeclaration.getModifiers().isEmpty() ?
ModifierType.PACKAGE_PRIVATE :
PACKAGE_PRIVATE :
ModifierType.get(methodDeclaration.getModifiers().get(0).toString());

Map<String, String> parameters = methodDeclaration.getParameters().stream()
Expand Down Expand Up @@ -312,7 +316,7 @@ public void visit(EnumDeclaration enumDeclaration, Void arg)
super.visit(enumDeclaration, arg);

nodeName = enumDeclaration.getNameAsString();
nodeType = NodeType.ENUM;
nodeType = ENUM;
}

}
Expand Down
167 changes: 58 additions & 109 deletions src/test/java/manager/ClassDiagramManagerTest.java

Large diffs are not rendered by default.

48 changes: 16 additions & 32 deletions src/test/java/manager/PackageDiagramManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import model.graph.PackageVertex;
import org.junit.jupiter.api.Test;
import utils.PathConstructor;
import utils.PathTemplate.LatexEditor;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -23,45 +21,31 @@ public class PackageDiagramManagerTest
void populateGraphMLPackageNodeTest()
{
PackageDiagramManager packageDiagramManager = new PackageDiagramManager();
SourceProject sourceProject = packageDiagramManager.createSourceProject(LatexEditor.SRC.path);

SourceProject sourceProject = packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s",
PathConstructor.getCurrentPath(),
File.separator,
PathConstructor.constructPath("src",
"test",
"resources",
"LatexEditor",
"src"))));
packageDiagramManager.convertTreeToDiagram(List.of("src.view",
"src.model",
"src.model.strategies",
"src.controller.commands",
"src.controller"));
Map<PackageVertex, Integer> graphNodes = packageDiagramManager.getPackageDiagram().getGraphNodes();
Map<Path, PackageVertex> packageNodes = sourceProject.getInterpreter().getVertices();
packageNodes.remove(Paths.get(String.format("%s%s%s",
PathConstructor.getCurrentPath(),
File.separator,
PathConstructor.constructPath("src",
"test",
"resources",
"LatexEditor",
"src"))));
packageNodes.remove(LatexEditor.SRC.path);
assertEquals(packageNodes.size(), graphNodes.size());
Iterator<Map.Entry<Path, PackageVertex>> iter1 = packageNodes.entrySet().iterator();
Iterator<Map.Entry<PackageVertex, Integer>> iter2 = graphNodes.entrySet().iterator();

List<String> l1 = new ArrayList<>();
List<String> l2 = new ArrayList<>();
while (iter1.hasNext() || iter2.hasNext())
{
Map.Entry<Path, PackageVertex> e1 = iter1.next();
Map.Entry<PackageVertex, Integer> e2 = iter2.next();
l1.add(e1.getValue().getName());
l2.add(e2.getKey().getName());
}
List<String> l1 = packageNodes.values().stream()
.map(PackageVertex::getName)
.collect(Collectors.toCollection(ArrayList::new));

List<String> l2 = graphNodes.keySet().stream()
.map(PackageVertex::getName)
.collect(Collectors.toCollection(ArrayList::new));

Collections.sort(l1);
Collections.sort(l2);
assertTrue(l1.size() == l2.size() && l1.containsAll(l2) && l2.containsAll(l1));

assertEquals(l1.size(), l2.size());
assertTrue(l1.containsAll(l2));
assertTrue(l2.containsAll(l1));
}
}
45 changes: 15 additions & 30 deletions src/test/java/model/GraphClassDiagramConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import model.graph.Arc;
import model.graph.ClassifierVertex;
import org.junit.jupiter.api.Test;
import utils.PathConstructor;
import utils.PathTemplate.LatexEditor;

import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -30,47 +30,32 @@ void convertGraphToClassDiagramTest()
List<String> chosenFiles = Arrays.asList("MainWindow",
"LatexEditorView",
"OpeningWindow");
classDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s",
PathConstructor.getCurrentPath(),
File.separator,
PathConstructor.constructPath("src",
"test",
"resources",
"LatexEditor",
"src"))));

classDiagramManager.createSourceProject(LatexEditor.SRC.path);
classDiagramManager.convertTreeToDiagram(chosenFiles);

Set<ClassifierVertex> graphNodes = classDiagramManager.getClassDiagram().getGraphNodes().keySet();
Map<ClassifierVertex, Set<Arc<ClassifierVertex>>> diagram = classDiagramManager.getClassDiagram().getDiagram();

List<Arc<ClassifierVertex>> arcs = new ArrayList<>();
for (Set<Arc<ClassifierVertex>> arcSet : diagram.values())
{
arcs.addAll(arcSet);
}
List<Arc<ClassifierVertex>> arcs = diagram.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toCollection(ArrayList::new));

GraphClassDiagramConverter graphClassDiagramConverter = new GraphClassDiagramConverter(diagram.keySet());
Map<ClassifierVertex, Set<Arc<ClassifierVertex>>> adjacencyList = graphClassDiagramConverter.convertGraphToClassDiagram();
classDiagramManager.getClassDiagram().setDiagram(adjacencyList);
ShadowCleaner shadowCleaner = new ShadowCleaner(classDiagramManager.getClassDiagram());
adjacencyList = shadowCleaner.shadowWeakRelationships();
adjacencyList = shadowCleaner.shadowWeakRelationships();

Set<Arc<ClassifierVertex>> actualArcs = new HashSet<>();
for (Set<Arc<ClassifierVertex>> value : adjacencyList.values())
{
actualArcs.addAll(value);
}
Set<Arc<ClassifierVertex>> actualArcs = adjacencyList.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toCollection(HashSet::new));

assertEquals(arcs.size(), actualArcs.size());
for (Arc<ClassifierVertex> arc : actualArcs)
{
assertTrue(arcs.contains(arc));
}
assertTrue(actualArcs.containsAll(arcs));

assertEquals(graphNodes.size(), adjacencyList.keySet().size());
for (ClassifierVertex classifierVertex : adjacencyList.keySet())
{
assertTrue(graphNodes.contains(classifierVertex));
}
assertTrue(graphNodes.containsAll(adjacencyList.keySet()));
}

}
36 changes: 11 additions & 25 deletions src/test/java/model/GraphPackageDiagramConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import model.graph.Arc;
import model.graph.PackageVertex;
import org.junit.jupiter.api.Test;
import utils.PathConstructor;
import utils.PathTemplate.LatexEditor;

import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -25,40 +25,26 @@ public class GraphPackageDiagramConverterTest
void convertGraphToPackageDiagramTest()
{
PackageDiagramManager packageDiagramManager = new PackageDiagramManager();
packageDiagramManager.createSourceProject(Paths.get(String.format("%s%s%s",
PathConstructor.getCurrentPath(),
File.separator,
PathConstructor.constructPath("src",
"test",
"resources",
"LatexEditor",
"src"))));
packageDiagramManager.createSourceProject(LatexEditor.SRC.path);
packageDiagramManager.convertTreeToDiagram(List.of("src.view",
"src.model",
"src.model.strategies",
"src.controller.commands",
"src.controller"));
Map<PackageVertex, Set<Arc<PackageVertex>>> diagram = packageDiagramManager.getPackageDiagram().getDiagram();

List<Arc<PackageVertex>> arcs = new ArrayList<>();
for (Set<Arc<PackageVertex>> arcSet : diagram.values())
{
arcs.addAll(arcSet);
}
List<Arc<PackageVertex>> arcs = diagram.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toCollection(ArrayList::new));

GraphPackageDiagramConverter graphPackageDiagramConverter = new GraphPackageDiagramConverter(diagram.keySet());
Map<PackageVertex, Set<Arc<PackageVertex>>> adjacencyList = graphPackageDiagramConverter.convertGraphToPackageDiagram();

Set<Arc<PackageVertex>> actualArcs = new HashSet<>();
for (Set<Arc<PackageVertex>> value : adjacencyList.values())
{
actualArcs.addAll(value);
}
Set<Arc<PackageVertex>> actualArcs = adjacencyList.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toCollection(HashSet::new));

assertEquals(arcs.size(), actualArcs.size());
for (Arc<PackageVertex> vertexArc : actualArcs)
{
assertTrue(arcs.contains(vertexArc));
}
assertTrue(arcs.containsAll(actualArcs));
}
}
Loading

0 comments on commit 288424c

Please sign in to comment.