Search in sources :

Example 1 with PenaltyCalculator

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

the class DependencyInfoMatrixSerializer method serialize.

public static String serialize(MethodOrder methodOrder, String javaSource, Configuration config) throws CheckstyleException {
    final VelocityEngine engine = new VelocityEngine();
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();
    final PenaltyCalculator calculator = getPenaltyCalculator();
    final int screenLinesCount = Integer.parseInt(config.getAttribute("screenLinesCount"));
    final VelocityContext context = new VelocityContext();
    context.put("info", methodOrder);
    context.put("javaScript", getJavaScript());
    context.put("css", getStyles());
    context.put("javaSource", javaSource);
    context.put("calculator", calculator);
    context.put("penaltyValue", calculator.getPenalty(methodOrder, screenLinesCount));
    context.put("configuration", config);
    final StringWriter writer = new StringWriter();
    final Template template = engine.getTemplate("com/github/sevntu/checkstyle/dsm/matrix.vm");
    template.merge(context, writer);
    return writer.toString();
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) ClasspathResourceLoader(org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader) PenaltyCalculator(com.github.sevntu.checkstyle.ordering.PenaltyCalculator) Template(org.apache.velocity.Template)

Aggregations

PenaltyCalculator (com.github.sevntu.checkstyle.ordering.PenaltyCalculator)1 StringWriter (java.io.StringWriter)1 Template (org.apache.velocity.Template)1 VelocityContext (org.apache.velocity.VelocityContext)1 VelocityEngine (org.apache.velocity.app.VelocityEngine)1 ClasspathResourceLoader (org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader)1