use of com.github.sevntu.checkstyle.domain.Dependencies in project methods-distance by sevntu-checkstyle.
the class MainServlet method processDsm.
private void processDsm(URL sourceUrl, HttpServletResponse resp) throws CheckstyleException, IOException {
class DsmDependencyInformationConsumer implements DependencyInformationConsumer {
private Configuration configuration;
@Override
public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}
@Override
public void accept(String filePath, Dependencies dependencies) {
try {
final String javaSource = FileUtils.getFileContents(filePath);
final MethodOrder methodOrder = new MethodOrder(dependencies);
final String html = DependencyInfoMatrixSerializer.serialize(methodOrder, javaSource, configuration);
resp.setContentType("text/html");
resp.getWriter().append(html);
} catch (final IOException | CheckstyleException ex) {
throw new ResponseGenerationException(ex);
}
}
}
final Map<String, String> config = getCheckConfiguration();
final DsmDependencyInformationConsumer consumer = new DsmDependencyInformationConsumer();
final MethodCallDependencyCheckInvoker invoker = new MethodCallDependencyCheckInvoker(config, consumer);
consumer.setConfiguration(invoker.getConfiguration());
invoker.invoke(Collections.singletonList(downloadSource(sourceUrl)));
}
use of com.github.sevntu.checkstyle.domain.Dependencies in project methods-distance by sevntu-checkstyle.
the class MethodCallDependenciesModuleTestSupport method mustBeSame.
private static void mustBeSame(final ExpectedDependencies expected, final MethodOrder actual) {
for (final String expectedMethod : expected.getMethods()) {
assertTrue("Method " + expectedMethod + " is not present is actual info", actual.getMethods().stream().anyMatch(md -> expectedMethod.equals(md.getSignature())));
}
for (final Method actualMethod : actual.getMethods()) {
assertTrue("Method " + actualMethod.getSignature() + " is not present in expected info", expected.getMethods().stream().anyMatch(mi -> mi.equals(actualMethod.getSignature())));
}
for (final String method : expected.getMethods()) {
final Method caller = actual.getMethods().stream().filter(m -> m.getSignature().equals(method)).findFirst().get();
final List<Method> dependencies = actual.getMethodDependenciesInAppearanceOrder(caller);
final List<ExpectedDependencies.MethodInvocation> invocations = expected.getInvocationsFromMethod(method);
assertEquals("Actual method dependencies count and count of invocations from method " + method + " does not match", invocations.size(), dependencies.size());
for (int i = 0; i < invocations.size(); ++i) {
final Method calledMethod = dependencies.get(i);
final ExpectedDependencies.MethodInvocation invocationOfMethod = invocations.get(i);
assertTrue("Method " + calledMethod.getSignature() + " is present as actual " + i + " dependency of " + method + " but should not be!", calledMethod.getSignature().equals(expected.getMethodByIndex(invocationOfMethod.callee)));
}
}
}
use of com.github.sevntu.checkstyle.domain.Dependencies 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.domain.Dependencies in project methods-distance by sevntu-checkstyle.
the class MainServlet method processDot.
private void processDot(URL sourceUrl, HttpServletResponse resp) throws CheckstyleException, IOException {
final DependencyInformationConsumer consumer = (filePath, dependencies) -> {
try {
final String dot = DependencyInfoGraphSerializer.serializeInfo(dependencies);
resp.setContentType("text/vnd.graphviz");
resp.getWriter().append(dot);
} catch (final IOException ex) {
throw new ResponseGenerationException(ex);
}
};
final Map<String, String> config = getCheckConfiguration();
final MethodCallDependencyCheckInvoker invoker = new MethodCallDependencyCheckInvoker(config, consumer);
invoker.invoke(Collections.singletonList(downloadSource(sourceUrl)));
}
use of com.github.sevntu.checkstyle.domain.Dependencies in project methods-distance by sevntu-checkstyle.
the class MethodCallDependencyCheckstyleModule method buildDependencies.
private static Dependencies buildDependencies(DetailAST topLevelClass, List<DetailAST> methodInvocations) {
final ClassDefinition classDefinition = new ClassDefinition(topLevelClass);
final List<ResolvedCall> callOccurrences = new ArrayList<>();
for (final DetailAST invocation : methodInvocations) {
if (classDefinition.isInsideMethodOfClass(invocation)) {
final Optional<ResolvedCall> occurrence = tryResolveCall(classDefinition, invocation);
occurrence.ifPresent(callOccurrences::add);
}
}
return new Dependencies(classDefinition, callOccurrences);
}
Aggregations