use of com.github.sevntu.checkstyle.ordering.Method 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.Method 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.Method 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);
}
use of com.github.sevntu.checkstyle.ordering.Method in project methods-distance by sevntu-checkstyle.
the class MethodDefinitionTest method testGetterSetterRecognitionsWithCtors.
@Test
public void testGetterSetterRecognitionsWithCtors() throws Exception {
final MethodOrder dc = withDefaultConfigOrdering("InputMethodDefinition2.java");
final Method noArgCtor = dc.getMethodByInitialIndex(0);
assertFalse(noArgCtor.isGetter());
assertFalse(noArgCtor.isSetter());
final Method singleArgCtor = dc.getMethodByInitialIndex(1);
assertFalse(singleArgCtor.isGetter());
assertFalse(singleArgCtor.isSetter());
}
use of com.github.sevntu.checkstyle.ordering.Method in project methods-distance by sevntu-checkstyle.
the class TopologicalMethodReorderer method methodDependenciesRelativeOrderOptimization.
private MethodOrder methodDependenciesRelativeOrderOptimization(MethodOrder methodOrder) {
MethodOrder currentMethodOrder = methodOrder;
for (final Method caller : currentMethodOrder.getMethods()) {
final List<Method> dependenciesInAppearanceOrder = currentMethodOrder.getMethodDependenciesInAppearanceOrder(caller);
if (dependenciesInAppearanceOrder.size() > 1) {
final List<Integer> dependenciesIndices = dependenciesInAppearanceOrder.stream().map(currentMethodOrder::getMethodIndex).sorted(Integer::compare).collect(Collectors.toList());
final List<Method> optimized = new ArrayList<>(currentMethodOrder.getMethods());
optimized.removeAll(dependenciesInAppearanceOrder);
for (int i = 0; i < dependenciesIndices.size(); ++i) {
optimized.add(dependenciesIndices.get(i), dependenciesInAppearanceOrder.get(i));
}
final MethodOrder optimizedMethodOrder = currentMethodOrder.reorder(optimized);
currentMethodOrder = getBestOrdering(currentMethodOrder, optimizedMethodOrder);
}
}
return currentMethodOrder;
}
Aggregations