Commit 187bbf92 authored by Johannes Salentin's avatar Johannes Salentin
Browse files

minor modifications

cleanup of different versions of detection
parent 98193691
Pipeline #161622 passed with stages
in 1 minute and 26 seconds
......@@ -5,6 +5,9 @@ import de.example.smells.*;
import java.util.ArrayList;
import java.util.List;
/**
* main class that manages the different detectors
*/
public class EASmellDetector {
public static void main(String[] args) {
// parsing of input xml to this ModelAdapter
......
......@@ -8,6 +8,9 @@ import javax.xml.namespace.QName;
import java.util.*;
import java.util.stream.Collectors;
/**
* adapt the more complex generated model and extend the functionality
*/
public class ModelAdapter {
private static ModelType model;
......@@ -31,7 +34,8 @@ public class ModelAdapter {
}
public ElementType getElementByIdentifier(String id) {
List<ElementType> elements = model.getElements().getElement().stream().filter(e -> e.getIdentifier().equals(id)).collect(Collectors.toList());
List<ElementType> elements = model.getElements().getElement().stream().filter(e -> e.getIdentifier().equals(id))
.collect(Collectors.toList());
if (elements.isEmpty()) {
return null;
} else {
......@@ -144,7 +148,8 @@ public class ModelAdapter {
if (model.getOrganizations().isEmpty()) {
return getElementsInLayerAlternative(layer);
} else {
List<OrganizationType> l = model.getOrganizations().get(0).getItem().stream().filter(e -> e.getLabelGroup().get(0).getValue().toLowerCase().contains(layer.toLowerCase())).collect(Collectors.toList());
List<OrganizationType> l = model.getOrganizations().get(0).getItem().stream().filter(e ->
e.getLabelGroup().get(0).getValue().toLowerCase().contains(layer.toLowerCase())).collect(Collectors.toList());
if (l.isEmpty()) {
return new ArrayList<>();
} else if (l.get(0).getItem().isEmpty()) {
......@@ -177,13 +182,19 @@ public class ModelAdapter {
String[] types;
switch (layer) {
case "Business":
types = new String[]{"BusinessActor", "BusinessRole", "BusinessCollaboration", "BusinessInterface", "BusinessProcess", "BusinessFunction", "BusinessInteraction", "BusinessEvent", "BusinessService", "BusinessObject", "Contract", "Representation", "Product"};
types = new String[]{"BusinessActor", "BusinessRole", "BusinessCollaboration", "BusinessInterface",
"BusinessProcess", "BusinessFunction", "BusinessInteraction", "BusinessEvent", "BusinessService",
"BusinessObject", "Contract", "Representation", "Product"};
break;
case "Application":
types = new String[]{"ApplicationComponent", "ApplicationCollaboration", "ApplicationInterface", "ApplicationFunction", "ApplicationInteraction", "ApplicationProcess", "ApplicationEvent", "ApplicationService", "DataObject"};
types = new String[]{"ApplicationComponent", "ApplicationCollaboration", "ApplicationInterface",
"ApplicationFunction", "ApplicationInteraction", "ApplicationProcess", "ApplicationEvent",
"ApplicationService", "DataObject"};
break;
case "Technology":
types = new String[]{"Node", "Device", "SystemSoftware", "TechnologyCollaboration", "TechnologyInterface", "Path", "CommunicationNetwork", "TechnologyFunction", "TechnologyProcess", "TechnologyInteraction", "TechnologyEvent", "TechnologyService", "Artifact", "Equipment", "Facility", "DistributionNetwork", "Material"};
types = new String[]{"Node", "Device", "SystemSoftware", "TechnologyCollaboration", "TechnologyInterface", "Path",
"CommunicationNetwork", "TechnologyFunction", "TechnologyProcess", "TechnologyInteraction", "TechnologyEvent",
"TechnologyService", "Artifact", "Equipment", "Facility", "DistributionNetwork", "Material"};
break;
default:
types = new String[]{};
......
......@@ -15,7 +15,8 @@ public class ChattyService extends Detector {
}
public List<EASmell> detect() {
List<ElementType> serviceElements = model.getElements().stream().filter(e -> e.getClass().getSimpleName().contains("Service")).collect(Collectors.toList());
List<ElementType> serviceElements = model.getElements().stream().filter(e ->
e.getClass().getSimpleName().contains("Service")).collect(Collectors.toList());
for (ElementType serviceElement : serviceElements) {
int relationCount = 0;
for (RelationshipType relationship : model.getRelationships()) {
......
......@@ -12,7 +12,6 @@ class Constants {
static final int MAX_DOCUMENTATION_LENGTH = 256;
// Duplication
static final int DUPLICATED_WORDS = 2;
static final double DUPLICATED_WORDS_RATIO = 0.75;
// Hub-like Modularization
......
......@@ -12,7 +12,8 @@ public class DataService extends Detector {
}
public List<EASmell> detect() {
List<ElementType> serviceElements = model.getElements().stream().filter(e -> e.getClass().getSimpleName().contains("Service")).collect(Collectors.toList());
List<ElementType> serviceElements = model.getElements().stream().filter(e ->
e.getClass().getSimpleName().contains("Service")).collect(Collectors.toList());
List<ElementType> dataElements = model.getElementsOfType(new String[]{"BusinessObject", "DataObject", "SystemSoftware"});
for (ElementType serviceElement : serviceElements) {
List<ElementType> referencedElements = model.getReferencedElementsOf(serviceElement);
......
......@@ -12,7 +12,7 @@ public abstract class Detector {
static ModelAdapter model;
// detected smells of all different detectors
static List<EASmell> smells;
// detected smells of this detector
// detected smells of this detector [can be returned by detect()]
List<EASmell> result;
private String smellName;
......
......@@ -27,11 +27,9 @@ public class Duplication extends Detector {
duplicatedWords++;
}
}
// if (duplicatedWords > DUPLICATED_WORDS) {
// addToSmells(new EASmell(getSmellName(), elements.get(i), " together with" + " \"" + elements.get(j).getNameGroup().get(0).getValue() + "\" (" + elements.get(j).getIdentifier() + ")"));
// }
if (((double) 2 * duplicatedWords) / (ei.size() + ej.size()) > DUPLICATED_WORDS_RATIO) {
addToSmells(new EASmell(getSmellName(), elements.get(i), " together with" + " \"" + elements.get(j).getNameGroup().get(0).getValue() + "\" (" + elements.get(j).getIdentifier() + ")"));
addToSmells(new EASmell(getSmellName(), elements.get(i), " together with" + " \"" +
elements.get(j).getNameGroup().get(0).getValue() + "\" (" + elements.get(j).getIdentifier() + ")"));
}
}
}
......
......@@ -36,6 +36,7 @@ public class EASmell {
}
public String toString() {
return smellName + " detected" + ((element == null) ? "" : " at the " + element.getClass().getSimpleName() + " \"" + getElementName() + "\" (" + element.getIdentifier() + ")") + (context == null ? "" : context);
return smellName + " detected" + ((element == null) ? "" : " at the " + element.getClass().getSimpleName() + " \"" +
getElementName() + "\" (" + element.getIdentifier() + ")") + (context == null ? "" : context);
}
}
......@@ -16,7 +16,8 @@ public class MessageChain extends Detector {
// restricted to Service Chains
public List<EASmell> detect() {
List<ElementType> serviceElements = model.getElements().stream().filter(e -> e.getClass().getSimpleName().contains("Service")).collect(Collectors.toList());
List<ElementType> serviceElements = model.getElements().stream().filter(e ->
e.getClass().getSimpleName().contains("Service")).collect(Collectors.toList());
for (ElementType element : serviceElements) {
List<ElementType> chain = getServiceChain(element);
if (chain.size() > MAX_SERVICE_CHAIN_LENGTH) {
......@@ -38,7 +39,8 @@ public class MessageChain extends Detector {
}
private List<ElementType> getServiceChain(ElementType start, List<ElementType> current) {
List<ElementType> referencedServiceElements = model.getReferencedElementsOf(start).stream().filter(e -> e.getClass().getSimpleName().contains("Service")).collect(Collectors.toList());
List<ElementType> referencedServiceElements = model.getReferencedElementsOf(start).stream().filter(e ->
e.getClass().getSimpleName().contains("Service")).collect(Collectors.toList());
List<ElementType> res = new ArrayList<>();
// no further referenced services
if (referencedServiceElements.isEmpty()) {
......
......@@ -12,7 +12,8 @@ public class SharedPersistency extends Detector {
}
public List<EASmell> detect() {
List<ElementType> databaseElements = model.getElements().stream().filter(e -> e.getClass().getSimpleName().equals("SystemSoftware") && (e.getNameGroup().get(0).getValue().contains("database") || e.getNameGroup().get(0).getValue().contains("DBMS"))).collect(Collectors.toList());
List<ElementType> databaseElements = model.getElements().stream().filter(e -> e.getClass().getSimpleName().equals("SystemSoftware") &&
(e.getNameGroup().get(0).getValue().contains("database") || e.getNameGroup().get(0).getValue().contains("DBMS"))).collect(Collectors.toList());
for (ElementType databaseElement : databaseElements) {
String[] types = {"Association", "Realization", "Assignment"};
List<ElementType> referencedElements = model.getReferencedElementsOf(databaseElement, types);
......
......@@ -18,8 +18,10 @@ public class StrictLayersViolation extends Detector {
for (RelationshipType relationship : model.getRelationships()) {
ElementType source = (ElementType) relationship.getSource();
ElementType target = (ElementType) relationship.getTarget();
if ((businessElements.contains(source) && technologyElements.contains(target) || (businessElements.contains(target) && technologyElements.contains(source)))) {
addToSmells(new EASmell(getSmellName(), source, " with the " + target.getClass().getSimpleName() + " \"" + target.getNameGroup().get(0).getValue() + "\" (" + target.getIdentifier() + ")"));
if ((businessElements.contains(source) && technologyElements.contains(target) ||
(businessElements.contains(target) && technologyElements.contains(source)))) {
addToSmells(new EASmell(getSmellName(), source, " with the " + target.getClass().getSimpleName() + " \"" +
target.getNameGroup().get(0).getValue() + "\" (" + target.getIdentifier() + ")"));
}
}
}
......
......@@ -15,27 +15,6 @@ public class WeakenedModularity extends Detector {
super("Weakened Modularity");
}
// public List<EASmell> detect() {
// List<ElementType> elements = model.getElements();
// for (ElementType element : elements) {
// //String type = element.getClass().getSimpleName();
// //if (!(type.contains("Process") || type.contains("Event") || type.contains("Function"))) {
// String[] internalReferencedElements = {"Composition", "Aggregation", "Realization"};
// String[] internalElementsWithReference = {"Assignment"};
// int internal = model.getReferencedElementsOf(element, internalReferencedElements).size() + model.getElementsWithReferenceTo(element, internalElementsWithReference).size();
// String[] externalReferencedElements = {"Influence", "Access", "Serving", "Triggering", "Flow", "Association"};
// String[] externalElementsWithReference = {"Composition", "Triggering"};
// int external = model.getElementsWithReferenceTo(element, externalReferencedElements).size() + model.getReferencedElementsOf(element, externalReferencedElements).size();
// double mr = (double) internal / (double) external;
// if (mr < MODULARITY_RATIO && mr > 0) {
// addToSmells(new EASmell("Weakened Modularity", element, " with a modularity ratio of " + mr));
// }
// //}
// }
// return result;
// }
// cluster scope
public List<EASmell> detect() {
for (ElementType element : model.getElements()) {
Set<ElementType> cluster = model.getCluster(element);
......@@ -46,12 +25,11 @@ public class WeakenedModularity extends Detector {
ElementType source = (ElementType) relationship.getSource();
if (cluster.contains(source) && cluster.contains(target)) {
internal++;
} else if (model.isNotStructural(relationship) && ((cluster.contains(source) && !cluster.contains(target)) || (cluster.contains(target) && !cluster.contains(source)))) {
} else if (model.isNotStructural(relationship) &&
((cluster.contains(source) && !cluster.contains(target)) || (cluster.contains(target) && !cluster.contains(source)))) {
external++;
}
}
// String[] externalReferencedElements = {"Influence", "Access", "Serving", "Triggering", "Flow", "Association"};
// int external = model.getElementsWithReferenceTo(element, externalReferencedElements).size() + model.getReferencedElementsOf(element, externalReferencedElements).size();
double mr = (double) internal / (double) external;
if (mr < MODULARITY_RATIO && internal > MIN_INTERNAL_RELATIONS) {
addToSmells(new EASmell("Weakened Modularity", element, " with a modularity ratio of " + mr));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment