Search in sources :

Example 21 with MethodOrder

use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.

the class MethodOrderTest method testOverrideSplit1.

@Test
public void testOverrideSplit1() throws Exception {
    final MethodOrder ds = withDefaultConfigOrdering("InputDependenciesOverrideSplit1.java");
    assertEquals(3, ds.getOverrideGroupSplitCases());
}
Also used : MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) Test(org.junit.Test)

Example 22 with MethodOrder

use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.

the class MethodOrderTest method testTotalSumOfMethodDistances1.

@Test
public void testTotalSumOfMethodDistances1() throws Exception {
    final MethodOrder ds = withDefaultConfigOrdering("InputDependenciesDistance1.java");
    assertEquals(12, ds.getTotalSumOfMethodDistances());
}
Also used : MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) Test(org.junit.Test)

Example 23 with MethodOrder

use of com.github.sevntu.checkstyle.ordering.MethodOrder 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;
}
Also used : ArrayList(java.util.ArrayList) MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) Method(com.github.sevntu.checkstyle.ordering.Method)

Aggregations

MethodOrder (com.github.sevntu.checkstyle.ordering.MethodOrder)23 Test (org.junit.Test)15 Method (com.github.sevntu.checkstyle.ordering.Method)10 ArrayList (java.util.ArrayList)4 Dependencies (com.github.sevntu.checkstyle.domain.Dependencies)3 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)3 List (java.util.List)3 Map (java.util.Map)3 DependencyInformationConsumer (com.github.sevntu.checkstyle.module.DependencyInformationConsumer)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 DependencyInformationConsumerInjector (com.github.sevntu.checkstyle.common.DependencyInformationConsumerInjector)1 MethodCallDependencyCheckInvoker (com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker)1 BaseCheckTestSupport (com.github.sevntu.checkstyle.domain.BaseCheckTestSupport)1 ExpectedDependencies (com.github.sevntu.checkstyle.domain.ExpectedDependencies)1 AttributeHolder (com.github.sevntu.checkstyle.dot.domain.AttributeHolder)1 Cluster (com.github.sevntu.checkstyle.dot.domain.Cluster)1 Colors (com.github.sevntu.checkstyle.dot.domain.Colors)1 Comment (com.github.sevntu.checkstyle.dot.domain.Comment)1 Edge (com.github.sevntu.checkstyle.dot.domain.Edge)1