Search in sources :

Example 6 with LineData

use of com.intellij.rt.coverage.data.LineData in project intellij-community by JetBrains.

the class CoberturaLoaderUtil method load.

public static ProjectData load(final File sessionDataFile) {
    ProjectData projectInfo = new ProjectData();
    DataInputStream dataFile = null;
    try {
        dataFile = new DataInputStream(new FileInputStream(sessionDataFile));
        int classesCount = dataFile.read();
        for (int i = 0; i < classesCount; i++) {
            final String classFQName = dataFile.readUTF();
            //sourcefilename
            dataFile.readUTF();
            final ClassData classData = projectInfo.getOrCreateClassData(classFQName);
            final int numberOfLines = dataFile.read();
            for (int l = 0; l < numberOfLines; l++) {
                final int lineNumber = dataFile.read();
                //todo classData.getOrCreateLine(lineNumber, dataFile.readUTF() + dataFile.readUTF());
                final LineData lineData = null;
                long hits = dataFile.readLong();
                final int jumpsNumber = dataFile.read();
                int trueHits = 0;
                int falseHits = 0;
                int totalHits = 0;
                for (int j = 0; j < jumpsNumber; j++) {
                    //jump number
                    dataFile.read();
                    totalHits++;
                    if (dataFile.readLong() > 0)
                        trueHits++;
                    totalHits++;
                    if (dataFile.readLong() > 0)
                        falseHits++;
                }
                int defaultHitsNumber = 0;
                int branchHitNumber = 0;
                final int switchNumber = dataFile.read();
                for (int s = 0; s < switchNumber; s++) {
                    //switch number
                    dataFile.read();
                    //number of keys
                    dataFile.read();
                    long defaultHits = dataFile.readLong();
                    if (defaultHits > 0)
                        defaultHitsNumber++;
                    int coveredSwitchBranches = 0;
                    final int switchBranchesNumber = dataFile.read();
                    for (int b = 0; b < switchBranchesNumber; b++) {
                        final long branchHit = dataFile.readLong();
                        if (branchHit > 0)
                            coveredSwitchBranches++;
                    }
                    if (coveredSwitchBranches == switchBranchesNumber)
                        branchHitNumber++;
                }
                if (hits > 0) {
                    if (totalHits == trueHits + falseHits) {
                        if (defaultHitsNumber == switchNumber && branchHitNumber == switchNumber) {
                            lineData.setStatus(LineCoverage.FULL);
                            continue;
                        }
                    }
                    lineData.setStatus(LineCoverage.PARTIAL);
                } else {
                    lineData.setStatus(LineCoverage.NONE);
                }
            }
        }
    } catch (IOException e) {
        LOG.info(e);
    } finally {
        if (dataFile != null) {
            try {
                dataFile.close();
            } catch (IOException e) {
                LOG.error(e);
            }
        }
    }
    return projectInfo;
}
Also used : LineData(com.intellij.rt.coverage.data.LineData) ClassData(com.intellij.rt.coverage.data.ClassData) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ProjectData(com.intellij.rt.coverage.data.ProjectData) FileInputStream(java.io.FileInputStream)

Example 7 with LineData

use of com.intellij.rt.coverage.data.LineData in project intellij-community by JetBrains.

the class SimpleCoverageAnnotator method fileInfoForCoveredFile.

@Nullable
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
    // used thus count = length = 1
    final int count = lines.length - 1;
    if (count == 0) {
        return null;
    }
    final FileCoverageInfo info = new FileCoverageInfo();
    info.coveredLineCount = 0;
    info.totalLineCount = 0;
    // let's count covered lines
    for (int i = 1; i <= count; i++) {
        final LineData lineData = classData.getLineData(i);
        processLineData(info, lineData);
    }
    return info;
}
Also used : LineData(com.intellij.rt.coverage.data.LineData) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with LineData

use of com.intellij.rt.coverage.data.LineData in project intellij-plugins by JetBrains.

the class DartCoverageRunner method doLoadCoverageData.

@Nullable
private static ProjectData doLoadCoverageData(@NotNull final File sessionDataFile, @NotNull final DartCoverageSuite coverageSuite) {
    final ProcessHandler coverageProcess = coverageSuite.getCoverageProcess();
    // coverageProcess == null means that we are switching to data gathered earlier
    if (coverageProcess != null) {
        for (int i = 0; i < 100; ++i) {
            ProgressManager.checkCanceled();
            if (coverageProcess.waitFor(100)) {
                break;
            }
        }
        if (!coverageProcess.isProcessTerminated()) {
            coverageProcess.destroyProcess();
            return null;
        }
    }
    final Project project = coverageSuite.getProject();
    final String contextFilePath = coverageSuite.getContextFilePath();
    if (project == null || contextFilePath == null) {
        return null;
    }
    final String contextId = DartAnalysisServerService.getInstance(project).execution_createContext(contextFilePath);
    if (contextId == null) {
        return null;
    }
    final ProjectData projectData = new ProjectData();
    try {
        DartCoverageData data = new Gson().fromJson(new BufferedReader(new FileReader(sessionDataFile)), DartCoverageData.class);
        if (data == null) {
            LOG.warn("Coverage file does not contain valid data.");
            return null;
        }
        for (Map.Entry<String, SortedMap<Integer, Integer>> entry : data.getMergedDartFileCoverageData().entrySet()) {
            ProgressManager.checkCanceled();
            String filePath = getFileForUri(project, contextId, entry.getKey());
            if (filePath == null) {
                // File is not found.
                continue;
            }
            SortedMap<Integer, Integer> lineHits = entry.getValue();
            ClassData classData = projectData.getOrCreateClassData(filePath);
            if (lineHits.size() == 0) {
                classData.setLines(new LineData[1]);
                continue;
            }
            LineData[] lines = new LineData[lineHits.lastKey() + 1];
            for (Map.Entry<Integer, Integer> hit : lineHits.entrySet()) {
                LineData lineData = new LineData(hit.getKey(), null);
                lineData.setHits(hit.getValue());
                lines[hit.getKey()] = lineData;
            }
            classData.setLines(lines);
        }
    } catch (FileNotFoundException | JsonSyntaxException e) {
        LOG.warn(e);
    } finally {
        DartAnalysisServerService.getInstance(project).execution_deleteContext(contextId);
    }
    return projectData;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) Project(com.intellij.openapi.project.Project) LineData(com.intellij.rt.coverage.data.LineData) JsonSyntaxException(com.google.gson.JsonSyntaxException) ClassData(com.intellij.rt.coverage.data.ClassData) SortedMap(java.util.SortedMap) BufferedReader(java.io.BufferedReader) ProcessHandler(com.intellij.execution.process.ProcessHandler) FileReader(java.io.FileReader) Map(java.util.Map) SortedMap(java.util.SortedMap) ProjectData(com.intellij.rt.coverage.data.ProjectData) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with LineData

use of com.intellij.rt.coverage.data.LineData in project Perl5-IDEA by Camelcade.

the class PerlCoverageRunner method parsePerlFileData.

@NotNull
private static ProjectData parsePerlFileData(@NotNull PerlFileData[] filesData) {
    ProjectData projectData = new ProjectData();
    for (PerlFileData perlFileData : filesData) {
        if (StringUtil.isEmpty(perlFileData.name) || perlFileData.lines == null) {
            continue;
        }
        ClassData classData = projectData.getOrCreateClassData(FileUtil.toSystemIndependentName(perlFileData.name));
        Set<Map.Entry<Integer, PerlLineData>> linesEntries = perlFileData.lines.entrySet();
        Integer maxLineNumber = linesEntries.stream().map(Map.Entry::getKey).max(Integer::compare).orElse(0);
        LineData[] linesData = new LineData[maxLineNumber + 1];
        for (Map.Entry<Integer, PerlLineData> lineEntry : linesEntries) {
            PerlLineData perlLineData = lineEntry.getValue();
            final Integer lineNumber = lineEntry.getKey();
            LineData lineData = new LineData(lineNumber, null) {

                @Override
                public int getStatus() {
                    if (perlLineData.cover == 0) {
                        return LineCoverage.NONE;
                    } else if (perlLineData.cover < perlLineData.data) {
                        return LineCoverage.PARTIAL;
                    }
                    return LineCoverage.FULL;
                }
            };
            lineData.setHits(perlLineData.cover);
            linesData[lineNumber] = lineData;
        }
        classData.setLines(linesData);
    }
    return projectData;
}
Also used : LineData(com.intellij.rt.coverage.data.LineData) ClassData(com.intellij.rt.coverage.data.ClassData) Map(java.util.Map) ProjectData(com.intellij.rt.coverage.data.ProjectData) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with LineData

use of com.intellij.rt.coverage.data.LineData in project intellij by bazelbuild.

the class BlazeCoverageRunnerTest method testIgnoreUnrecognizedPrefixes.

@Test
public void testIgnoreUnrecognizedPrefixes() throws IOException {
    ProjectData data = BlazeCoverageRunner.parseCoverage(mockResolver, inputStream("SF:path/to/file.txt", "DA:4,0", "DA:8,0", "FS:0", "unrecognized junk", "DA:9,1", "DA:23,3", "end_of_record"));
    assertThat(data.getClasses()).hasSize(1);
    LineData[] lines = (LineData[]) data.getClassData("/root/path/to/file.txt").getLines();
    assertThat(lines).hasLength(24);
    assertEquals(lines[4], lineData(4, 0));
    assertEquals(lines[9], lineData(9, 1));
    assertEquals(lines[23], lineData(23, 3));
}
Also used : LineData(com.intellij.rt.coverage.data.LineData) ProjectData(com.intellij.rt.coverage.data.ProjectData) Test(org.junit.Test)

Aggregations

LineData (com.intellij.rt.coverage.data.LineData)21 ClassData (com.intellij.rt.coverage.data.ClassData)11 ProjectData (com.intellij.rt.coverage.data.ProjectData)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Document (com.intellij.openapi.editor.Document)4 PsiFile (com.intellij.psi.PsiFile)4 Map (java.util.Map)4 NotNull (org.jetbrains.annotations.NotNull)4 Module (com.intellij.openapi.module.Module)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 CoverageReport (com.google.jstestdriver.idea.rt.coverage.CoverageReport)2 Editor (com.intellij.openapi.editor.Editor)2 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)2 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2