Count missed branches in case of partial coverage in total ration denominator (PY...
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 18 Oct 2016 18:01:23 +0000 (20:01 +0200)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Tue, 18 Oct 2016 18:01:23 +0000 (20:01 +0200)
plugins/coverage-common/src/com/intellij/coverage/SimpleCoverageAnnotator.java

index eb41bcfe34a9a2464b77382b9608dd82453b87f4..98c4d88becba990c93a1c0ad1aa10a5bc62a90de 100644 (file)
@@ -140,8 +140,7 @@ public abstract class SimpleCoverageAnnotator extends BaseCoverageAnnotator {
   protected FileCoverageInfo collectBaseFileCoverage(@NotNull final VirtualFile file,
                                                      @NotNull final Annotator annotator,
                                                      @NotNull final ProjectData projectData,
-                                                     @NotNull final Map<String, String> normalizedFiles2Files)
-  {
+                                                     @NotNull final Map<String, String> normalizedFiles2Files) {
     final String filePath = normalizeFilePath(file.getPath());
 
     // process file
@@ -166,8 +165,7 @@ public abstract class SimpleCoverageAnnotator extends BaseCoverageAnnotator {
   private static @Nullable ClassData getClassData(
     final @NotNull String filePath,
     final @NotNull ProjectData data,
-    final @NotNull Map<String, String> normalizedFiles2Files)
-  {
+    final @NotNull Map<String, String> normalizedFiles2Files) {
     final String originalFileName = normalizedFiles2Files.get(filePath);
     if (originalFileName == null) {
       return null;
@@ -272,8 +270,7 @@ public abstract class SimpleCoverageAnnotator extends BaseCoverageAnnotator {
                        @NotNull final CoverageSuitesBundle suite,
                        final @NotNull CoverageDataManager dataManager, @NotNull final ProjectData data,
                        final Project project,
-                       final Annotator annotator)
-  {
+                       final Annotator annotator) {
     if (!contentRoot.isValid()) {
       return;
     }
@@ -395,7 +392,7 @@ public abstract class SimpleCoverageAnnotator extends BaseCoverageAnnotator {
   }
 
   @Nullable
-  private static FileCoverageInfo fileInfoForCoveredFile(@NotNull final ClassData classData) {
+  private FileCoverageInfo fileInfoForCoveredFile(@NotNull final ClassData classData) {
     final Object[] lines = classData.getLines();
 
     // class data lines = [0, 1, ... count] but first element with index = #0 is fake and isn't
@@ -408,27 +405,31 @@ public abstract class SimpleCoverageAnnotator extends BaseCoverageAnnotator {
 
     final FileCoverageInfo info = new FileCoverageInfo();
 
-    int srcLinesCount = 0;
-    int coveredLinesCount = 0;
+    info.coveredLineCount = 0;
+    info.totalLineCount = 0;
     // let's count covered lines
     for (int i = 1; i <= count; i++) {
       final LineData lineData = classData.getLineData(i);
-      if (lineData == null) {
-        // Ignore not src code
-        continue;
-      }
-      final int status = lineData.getStatus();
-      // covered - if src code & covered (or inferred covered)
-      if (status != LineCoverage.NONE) {
-        coveredLinesCount++;
-      }
-      srcLinesCount++;
+
+      processLineData(info, lineData);
     }
-    info.totalLineCount = srcLinesCount;
-    info.coveredLineCount = coveredLinesCount;
     return info;
   }
 
+  protected void processLineData(@NotNull  FileCoverageInfo info, @Nullable  LineData lineData) {
+    if (lineData == null) {
+      // Ignore not src code
+      return;
+    }
+    final int status = lineData.getStatus();
+    // covered - if src code & covered (or inferred covered)
+
+    if (status != LineCoverage.NONE) {
+      info.coveredLineCount++;
+    }
+    info.totalLineCount++;
+  }
+
   @Nullable
   protected FileCoverageInfo fillInfoForUncoveredFile(@NotNull File file) {
     return null;