Skip to content

Commit 8fe9b7e

Browse files
committed
Updated support for blocks
1 parent 15981a1 commit 8fe9b7e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/main/scala/scales/coverage.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ class Coverage
1818
def add(stmt: MeasuredStatement): Unit = statements.append(stmt)
1919

2020
def avgClassesPerPackage = classCount / packageCount.toDouble
21+
def avgClassesPerPackageFormatted: String = "%.2f".format(avgClassesPerPackage * 100)
22+
2123
def avgMethodsPerClass = methodCount / classCount.toDouble
24+
def avgMethodsPerClassFormatted: String = "%.2f".format(avgMethodsPerClass * 100)
2225

2326
// returns the classes by least coverage
2427
def risks(limit: Int) = classes.toSeq.sortBy(_.statementCount).reverse.sortBy(_.statementCoverage).take(limit)
@@ -29,10 +32,10 @@ class Coverage
2932

3033
trait MethodBuilders {
3134
val statements: Iterable[MeasuredStatement]
32-
def methodCount = methods.size
3335
def methods: Seq[MeasuredMethod] = {
3436
statements.groupBy(_.location.method).map(arg => MeasuredMethod(arg._1, arg._2)).toSeq
3537
}
38+
def methodCount = methods.size
3639
}
3740

3841
trait PackageBuilders {

src/main/scala/scales/plugin.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ class ScalesComponent(val global: Global)
122122

123123
case EmptyTree => super.transform(tree)
124124

125-
// This AST node corresponds to the following Scala code: fun(args)
125+
// This AST node corresponds to the following Scala code: fun(args)
126126
case apply: Apply =>
127127
instrument(treeCopy.Apply(apply, apply.fun, transformStatements(apply.args)))
128128

129129
// just carry on as normal with a block, we'll process the children
130-
case _: Block => super.transform(tree)
130+
case b: Block =>
131+
treeCopy.Block(b, transformStatements(b.stats), transform(b.expr))
132+
131133
case _: Import => super.transform(tree)
132134
case p: PackageDef => super.transform(tree)
133135

@@ -183,9 +185,9 @@ class ScalesComponent(val global: Global)
183185
case i: If =>
184186
treeCopy.If(i, i.cond, transformIf(i.thenp), transformIf(i.elsep))
185187

186-
// handle function bodies. This AST node corresponds to the following Scala code: vparams => body
188+
// handle function bodies. This AST node corresponds to the following Scala code: vparams => body
187189
case f: Function =>
188-
treeCopy.Function(tree, f.vparams, transform(f.body))
190+
treeCopy.Function(tree, f.vparams, process(f.body))
189191

190192
// labeldefs are never written natively in scala
191193
case l: LabelDef =>

0 commit comments

Comments
 (0)