use of com.intellij.rt.coverage.data.LineData in project intellij-community by JetBrains.
the class JaCoCoCoverageRunner method loadExecutionData.
private static void loadExecutionData(@NotNull final File sessionDataFile, ProjectData data, @NotNull Project project) throws IOException {
final ExecutionDataStore executionDataStore = new ExecutionDataStore();
FileInputStream fis = null;
try {
fis = new FileInputStream(sessionDataFile);
final ExecutionDataReader executionDataReader = new ExecutionDataReader(fis);
executionDataReader.setExecutionDataVisitor(executionDataStore);
executionDataReader.setSessionInfoVisitor(new ISessionInfoVisitor() {
public void visitSessionInfo(SessionInfo info) {
System.out.println(info.toString());
}
});
while (executionDataReader.read()) {
}
} finally {
if (fis != null) {
fis.close();
}
}
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
final Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
if (compilerModuleExtension != null) {
final VirtualFile[] roots = compilerModuleExtension.getOutputRoots(true);
for (VirtualFile root : roots) {
analyzer.analyzeAll(VfsUtil.virtualToIoFile(root));
}
}
}
for (IClassCoverage classCoverage : coverageBuilder.getClasses()) {
String className = classCoverage.getName();
className = className.replace('\\', '.').replace('/', '.');
final ClassData classData = data.getOrCreateClassData(className);
final Collection<IMethodCoverage> methods = classCoverage.getMethods();
LineData[] lines = new LineData[classCoverage.getLastLine() + 1];
for (IMethodCoverage method : methods) {
final String desc = method.getName() + method.getDesc();
// Line numbers are 1-based here.
final int firstLine = method.getFirstLine();
final int lastLine = method.getLastLine();
for (int i = firstLine; i <= lastLine; i++) {
final ILine methodLine = method.getLine(i);
final int methodLineStatus = methodLine.getStatus();
if (methodLineStatus == ICounter.EMPTY)
continue;
final LineData lineData = new LineData(i, desc) {
@Override
public int getStatus() {
switch(methodLineStatus) {
case ICounter.FULLY_COVERED:
return LineCoverage.FULL;
case ICounter.PARTLY_COVERED:
return LineCoverage.PARTIAL;
default:
return LineCoverage.NONE;
}
}
};
lineData.setHits(methodLineStatus == ICounter.FULLY_COVERED || methodLineStatus == ICounter.PARTLY_COVERED ? 1 : 0);
lines[i] = lineData;
}
}
classData.setLines(lines);
}
}
use of com.intellij.rt.coverage.data.LineData in project intellij-community by JetBrains.
the class CoverageDataManagerImpl method selectSubCoverage.
public void selectSubCoverage(@NotNull final CoverageSuitesBundle suite, final List<String> testNames) {
suite.restoreCoverageData();
final ProjectData data = suite.getCoverageData();
if (data == null)
return;
mySubCoverageIsActive = true;
final Map<String, Set<Integer>> executionTrace = new HashMap<>();
for (CoverageSuite coverageSuite : suite.getSuites()) {
final String fileName = coverageSuite.getCoverageDataFileName();
final File tracesDir = getTracesDirectory(fileName);
for (String testName : testNames) {
final File file = new File(tracesDir, FileUtil.sanitizeFileName(testName) + ".tr");
if (file.exists()) {
DataInputStream in = null;
try {
in = new DataInputStream(new FileInputStream(file));
int traceSize = in.readInt();
for (int i = 0; i < traceSize; i++) {
final String className = in.readUTF();
final int linesSize = in.readInt();
Set<Integer> lines = executionTrace.get(className);
if (lines == null) {
lines = new HashSet<>();
executionTrace.put(className, lines);
}
for (int l = 0; l < linesSize; l++) {
lines.add(in.readInt());
}
}
} catch (Exception e) {
LOG.error(e);
} finally {
try {
in.close();
} catch (IOException e) {
LOG.error(e);
}
}
}
}
}
final ProjectData projectData = new ProjectData();
for (String className : executionTrace.keySet()) {
ClassData loadedClassData = projectData.getClassData(className);
if (loadedClassData == null) {
loadedClassData = projectData.getOrCreateClassData(className);
}
final Set<Integer> lineNumbers = executionTrace.get(className);
final ClassData oldData = data.getClassData(className);
LOG.assertTrue(oldData != null, "missed className: \"" + className + "\"");
final Object[] oldLines = oldData.getLines();
LOG.assertTrue(oldLines != null);
int maxNumber = oldLines.length;
for (Integer lineNumber : lineNumbers) {
if (lineNumber >= maxNumber) {
maxNumber = lineNumber + 1;
}
}
final LineData[] lines = new LineData[maxNumber];
for (Integer line : lineNumbers) {
final int lineIdx = line.intValue() - 1;
String methodSig = null;
if (lineIdx < oldData.getLines().length) {
final LineData oldLineData = oldData.getLineData(lineIdx);
if (oldLineData != null) {
methodSig = oldLineData.getMethodSignature();
}
}
final LineData lineData = new LineData(lineIdx, methodSig);
if (methodSig != null) {
loadedClassData.registerMethodSignature(lineData);
}
lineData.setStatus(LineCoverage.FULL);
lines[lineIdx] = lineData;
}
loadedClassData.setLines(lines);
}
suite.setCoverageData(projectData);
renewCoverageData(suite);
}
use of com.intellij.rt.coverage.data.LineData in project intellij-community by JetBrains.
the class CoverageLineMarkerRenderer method paint.
public void paint(Editor editor, Graphics g, Rectangle r) {
final TextAttributes color = editor.getColorsScheme().getAttributes(myKey);
Color bgColor = color.getBackgroundColor();
if (bgColor == null) {
bgColor = color.getForegroundColor();
}
if (editor.getSettings().isLineNumbersShown() || ((EditorGutterComponentEx) editor.getGutter()).isAnnotationsShown()) {
if (bgColor != null) {
bgColor = ColorUtil.toAlpha(bgColor, 150);
}
}
if (bgColor != null) {
g.setColor(bgColor);
}
g.fillRect(r.x, r.y, r.width, r.height);
final LineData lineData = getLineData(editor.xyToLogicalPosition(new Point(0, r.y)).line);
if (lineData != null && lineData.isCoveredByOneTest()) {
g.drawImage(ImageLoader.loadFromResource("/gutter/unique.png"), r.x, r.y, 8, 8, editor.getComponent());
}
}
use of com.intellij.rt.coverage.data.LineData in project intellij-community by JetBrains.
the class CoverageLineMarkerRenderer method showHint.
private void showHint(final Editor editor, final Point point, final int lineNumber) {
final JPanel panel = new JPanel(new BorderLayout());
panel.add(createActionsToolbar(editor, lineNumber), BorderLayout.NORTH);
final LineData lineData = getLineData(lineNumber);
final EditorImpl uEditor;
if (lineData != null && lineData.getStatus() != LineCoverage.NONE && !mySubCoverageActive) {
final EditorFactory factory = EditorFactory.getInstance();
final Document doc = factory.createDocument(getReport(editor, lineNumber));
doc.setReadOnly(true);
uEditor = (EditorImpl) factory.createEditor(doc, editor.getProject());
panel.add(EditorFragmentComponent.createEditorFragmentComponent(uEditor, 0, doc.getLineCount(), false, false), BorderLayout.CENTER);
} else {
uEditor = null;
}
final LightweightHint hint = new LightweightHint(panel) {
@Override
public void hide() {
if (uEditor != null)
EditorFactory.getInstance().releaseEditor(uEditor);
super.hide();
}
};
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT | HintManagerImpl.HIDE_BY_SCROLLING, -1, false, new HintHint(editor, point));
}
use of com.intellij.rt.coverage.data.LineData in project intellij-community by JetBrains.
the class CoverageLineMarkerRenderer method getReport.
private String getReport(final Editor editor, final int lineNumber) {
final LineData lineData = getLineData(lineNumber);
final Document document = editor.getDocument();
final Project project = editor.getProject();
assert project != null;
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
assert psiFile != null;
final int lineStartOffset = document.getLineStartOffset(lineNumber);
final int lineEndOffset = document.getLineEndOffset(lineNumber);
return myCoverageSuite.getCoverageEngine().generateBriefReport(editor, psiFile, lineNumber, lineStartOffset, lineEndOffset, lineData);
}
Aggregations