@Test @TestCode( fileName = "src/test/resources/metrics/6Lines.java", detail = "A class with 6 line of codes") public void SixLineOfCode() { MetricCalculator calculator = new MetricCalculator(); MetricReport report = calculator.calculateMetrics(testCode); assertEquals(6, report.getNumberOfLines()); }
@Override public void enterStatement(JavaParser.StatementContext ctx) { ctx.getChildCount(); String text = ctx.getStart().getText(); if (!text.equals("if") && !text.equals("while") && !text.equals("for") && !text.equals("do")) { return; } int depth = 1; ParserRuleContext tempContext = ctx.getParent(); while (!(tempContext instanceof JavaParser.MethodDeclarationContext)) { if (tempContext instanceof JavaParser.StatementContext) { text = tempContext.getStart().getText(); if (text.equals("if") || text.equals("while") || text.equals("for") || text.equals("do")) { depth++; } } tempContext = tempContext.getParent(); } report.setDepthOfConditionNesting(depth); }