Skip to content

Commit

Permalink
CoberturaParser: extract loop invariant
Browse files Browse the repository at this point in the history
before:

```python
  for each package:
     for each file in package:
         for each class in file:
             for each branch in class:
                 Pattern.compile("\\((.*?)\\)")
```
  • Loading branch information
ivangalkin committed Apr 24, 2018
1 parent 2eeb8ca commit 29374f4
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public class CoberturaParser extends CxxCoverageParser {

private static final Logger LOG = Loggers.get(CoberturaParser.class);
private String baseDir;
private static final Pattern conditionsPattern = Pattern.compile("\\((.*?)\\)");

public CoberturaParser() {
// no operation but necessary for list of coverage parsers
// no operation but necessary for list of coverage parsers
}

/**
Expand Down Expand Up @@ -103,6 +104,7 @@ private static void collectFileMeasures(final String baseDir, SMInputCursor claz

private static void collectFileData(SMInputCursor clazz, CoverageMeasures builder) throws XMLStreamException {
SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line");

while (line.getNext() != null) {
int lineId = Integer.parseInt(line.getAttrValue("number"));
long noHits = Long.parseLong(line.getAttrValue("hits"));
Expand All @@ -116,8 +118,7 @@ private static void collectFileData(SMInputCursor clazz, CoverageMeasures builde
String isBranch = line.getAttrValue("branch");
String text = line.getAttrValue("condition-coverage");
if (text != null && "true".equals(isBranch) && !text.trim().isEmpty()) {
Pattern p = Pattern.compile("\\((.*?)\\)");
Matcher m = p.matcher(text);
Matcher m = conditionsPattern.matcher(text);
if (m.find()) {
String[] conditions = m.group(1).split("/");
builder.setConditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0]));
Expand Down

0 comments on commit 29374f4

Please sign in to comment.