use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.
the class ViolationReporterDependencyInformationConsumer method accept.
@Override
public void accept(String filePath, Dependencies dependencies) {
final MethodOrder initialMethodOrder = new MethodOrder(dependencies);
final MethodOrder optimizedMethodOrder = reorderer.reorder(initialMethodOrder);
logFirstMethodOutOfOrder(module, optimizedMethodOrder);
}
use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.
the class TopologicalMethodReorderer method methodDependenciesDistanceOptimization.
private MethodOrder methodDependenciesDistanceOptimization(MethodOrder startingOrder) {
MethodOrder currentOrder = startingOrder;
for (final Method caller : startingOrder.getMethods()) {
final List<Method> dependencies = currentOrder.getMethodDependenciesInAppearanceOrder(caller);
if (!dependencies.isEmpty()) {
final int callerIndex = currentOrder.getMethodIndex(caller);
boolean allDependenciesLocatedAfterCaller = true;
for (final Method callee : dependencies) {
allDependenciesLocatedAfterCaller = allDependenciesLocatedAfterCaller && currentOrder.getMethodIndex(callee) > callerIndex;
}
if (allDependenciesLocatedAfterCaller) {
final List<Method> allMethods = new ArrayList<>(currentOrder.getMethods());
final List<Method> subList = allMethods.subList(callerIndex, allMethods.size());
subList.removeAll(dependencies);
subList.addAll(1, dependencies);
final MethodOrder optimizedMethodOrder = currentOrder.reorder(allMethods);
currentOrder = getBestOrdering(currentOrder, optimizedMethodOrder);
}
}
}
return currentOrder;
}
use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.
the class TopologicalMethodReorderer method methodGroupsGrouping.
private MethodOrder methodGroupsGrouping(MethodOrder startingMethodOrder, final List<List<Method>> groups) {
MethodOrder currentMethodOrder = startingMethodOrder;
for (final List<Method> methodsGroup : groups) {
final Method lastMethod = methodsGroup.stream().sorted(new MethodIndexComparator(currentMethodOrder).reversed()).findFirst().get();
final List<Method> nonLastMethodsInGroup = new ArrayList<>(methodsGroup);
nonLastMethodsInGroup.remove(lastMethod);
final List<Method> optimizedOrdering = new ArrayList<>(currentMethodOrder.getMethods());
optimizedOrdering.removeAll(nonLastMethodsInGroup);
optimizedOrdering.addAll(currentMethodOrder.getMethodIndex(lastMethod), nonLastMethodsInGroup);
currentMethodOrder = getBestOrdering(currentMethodOrder, currentMethodOrder.reorder(optimizedOrdering));
}
return currentMethodOrder;
}
use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.
the class TopologicalMethodReorderer method breadthFirstOrder.
private static List<Method> breadthFirstOrder(MethodOrder methodOrder, Method startMethod) {
final Queue<Method> queue = new LinkedList<>();
final List<Method> result = new ArrayList<>();
queue.add(startMethod);
while (result.size() < methodOrder.getMethods().size()) {
if (queue.isEmpty()) {
methodOrder.getMethods().stream().filter(method -> !result.contains(method)).findFirst().ifPresent(queue::add);
} else {
final Method head = queue.remove();
if (!result.contains(head)) {
result.add(head);
methodOrder.getMethodDependenciesInAppearanceOrder(head).stream().filter(callee -> !result.contains(callee)).forEach(queue::add);
}
}
}
return result;
}
use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.
the class DependencyInfoGraphSerializer method serializeInfo.
public static String serializeInfo(Dependencies dependencies) {
final MethodOrder info = new MethodOrder(dependencies);
final Graph graph = new Graph("dependencies");
graph.setRankdir(Rankdirs.LR);
final Cluster simpleMethods = new Cluster("simple");
final Map<Method, Node> methodToNode = info.getMethods().stream().filter(method -> !info.isInterfaceMethod(method)).collect(Collectors.toMap(Function.identity(), DependencyInfoGraphSerializer::createNode));
methodToNode.entrySet().stream().forEach(methodAndNode -> {
if (info.hasMethodDependencies(methodAndNode.getKey())) {
graph.addComponent(methodAndNode.getValue());
} else {
simpleMethods.addComponent(methodAndNode.getValue());
}
});
graph.addComponent(simpleMethods);
for (final Method caller : methodToNode.keySet()) {
for (final Method callee : info.getMethodDependenciesInAppearanceOrder(caller)) {
graph.addComponent(createEdge(caller, callee, methodToNode, info));
}
}
final Comment comment = new Comment(getDescription());
graph.addComponent(comment);
return serialize(graph);
}
Aggregations