Commit 57d3cd7c authored by Johannes Salentin's avatar Johannes Salentin
Browse files

improved Hub and Weakened Modularity

relation to cluster
new constant
parent 168e58a8
Pipeline #160201 passed with stages
in 1 minute and 23 seconds
......@@ -196,4 +196,9 @@ public class ModelAdapter {
return res;
}
public boolean isNotStructural(RelationshipType relationship) {
String type = relationship.getClass().getSimpleName();
return !type.contains("Realization") && !type.contains("Assignment") && !type.contains("Aggregation") && !type.contains("Composition");
}
}
......@@ -2,18 +2,25 @@ package de.example.smells;
class Constants {
// Dense Structure
static final double MAX_AVG_DEGREE = 2;
// Documentation
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
static final int LARGE_FAN_IN = 10;
static final int LARGE_FAN_OUT = 10;
// Message Chain
static final int MAX_SERVICE_CHAIN_LENGTH = 4;
// Weakened Modularity
static final int MIN_INTERNAL_RELATIONS = 3;
static final double MODULARITY_RATIO = 1;
}
package de.example.smells;
import de.example.model.ElementType;
import de.example.model.RelationshipType;
import java.util.List;
import java.util.Set;
import static de.example.smells.Constants.LARGE_FAN_IN;
import static de.example.smells.Constants.LARGE_FAN_OUT;
......@@ -15,8 +17,20 @@ public class HubLikeModularization extends Detector {
public List<EASmell> detect() {
for (ElementType element : model.getElements()) {
int fanIn = model.getElementsWithReferenceTo(element).size();
int fanOut = model.getReferencedElementsOf(element).size();
Set<ElementType> cluster = model.getCluster(element);
int fanOut = 0;
int fanIn = 0;
for (RelationshipType relationship : model.getRelationships()) {
if (model.isNotStructural(relationship)) {
ElementType target = (ElementType) relationship.getTarget();
ElementType source = (ElementType) relationship.getSource();
if (cluster.contains(source) && !cluster.contains(target)) {
fanOut++;
} else if (cluster.contains(target) && !cluster.contains(source)) {
fanIn++;
}
}
}
if (fanIn > LARGE_FAN_IN && fanOut > LARGE_FAN_OUT) {
addToSmells(new EASmell("Hub-like Modularization", element, " with a total of " + (fanIn + fanOut) + " relations"));
}
......
......@@ -6,6 +6,7 @@ import de.example.model.RelationshipType;
import java.util.List;
import java.util.Set;
import static de.example.smells.Constants.MIN_INTERNAL_RELATIONS;
import static de.example.smells.Constants.MODULARITY_RATIO;
public class WeakenedModularity extends Detector {
......@@ -45,23 +46,18 @@ public class WeakenedModularity extends Detector {
ElementType source = (ElementType) relationship.getSource();
if (cluster.contains(source) && cluster.contains(target)) {
internal++;
} else if (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 > 3) {
if (mr < MODULARITY_RATIO && internal > MIN_INTERNAL_RELATIONS) {
addToSmells(new EASmell("Weakened Modularity", element, " with a modularity ratio of " + mr));
}
}
return result;
}
private boolean isNotStructural(RelationshipType relationship) {
String type = relationship.getClass().getSimpleName();
return !type.contains("Realization") && !type.contains("Assignment") && !type.contains("Aggregation") && !type.contains("Composition");
}
}
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