use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.
the class CoverEventHandler method addModuleToTree.
// adds module to the statistics tree
private void addModuleToTree(final ModuleStats moduleStats) {
ICoverageObject root = StatsTreeModel.getInstance().getRoot();
final IConfiguration config = CoveragePerformer.getPerformer().getConfig();
final String ppath = ErlangEngine.getInstance().getModelUtilService().getProject(config.getProject()).getWorkspaceProject().getLocation().toString();
String mpath = config.getModule(moduleStats.getLabel()).getFilePath();
mpath = mpath.substring(ppath.length());
log.info(ppath);
log.info(mpath);
final String[] parts = mpath.split("/");
root.setLiniesCount(root.getLinesCount() + moduleStats.getLinesCount());
root.setCoverCount(root.getCoverCount() + moduleStats.getCoverCount());
for (int i = 1; i < parts.length - 1; i++) {
ICoverageObject tmp = root.findChild(parts[i]);
if (tmp == null) {
tmp = new StatsTreeObject(ObjectType.FOLDER);
tmp.setLabel(parts[i]);
}
tmp.setLiniesCount(tmp.getLinesCount() + moduleStats.getLinesCount());
tmp.setCoverCount(tmp.getCoverCount() + moduleStats.getCoverCount());
root.addChild(parts[i], tmp);
root = tmp;
}
root.addChild(moduleStats.getLabel(), moduleStats);
}
use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.
the class ExportReports method treeSave.
// saves reports as a tree
private void treeSave(final ICoverageObject obj, final String path, final String lPath) {
final String pathIn = obj.getHtmlPath();
final String pathOut = path + File.separator + obj.getLabel() + ".html";
log.info("pathOut");
obj.setRelativePath(lPath + File.separator + obj.getLabel() + ".html");
if (!obj.getType().equals(ObjectType.MODULE)) {
final String linkPath = "." + File.separator + obj.getLabel();
final String dirPath = path + File.separator + obj.getLabel();
final File dir = new File(dirPath);
dir.mkdir();
for (final ICoverageObject child : obj.getChildren()) {
treeSave(child, dirPath, linkPath);
}
try {
final String report = ReportGenerator.getInstance().getHTMLreport(obj, true);
log.info(report);
try (final FileWriter writer = new FileWriter(pathOut)) {
writer.write(report);
}
obj.setHtmlPath(pathOut);
} catch (final IOException e) {
ErlLogger.error(e);
}
} else {
final File input = new File(pathIn);
final File output = new File(pathOut);
try (final FileReader in = new FileReader(input);
final FileWriter out = new FileWriter(output)) {
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} catch (final IOException e) {
CoverageHelper.reportError("Could not export HTML reports");
ErlLogger.error(e);
}
}
}
use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.
the class HtmlReportAction method generateReportTree.
/**
* Generates html reports
*
* @param obj
* @param path
*/
private void generateReportTree(final ICoverageObject obj, final String path) {
if (obj.getType().equals(ObjectType.MODULE)) {
return;
}
final String reportPath = path + File.separator + obj.getLabel() + ".html";
log.info(reportPath);
final String dirPath = path + File.separator + obj.getLabel();
final File dir = new File(dirPath);
dir.mkdir();
for (final ICoverageObject child : obj.getChildren()) {
generateReportTree(child, dirPath);
}
try {
final String report = ReportGenerator.getInstance().getHTMLreport(obj, false);
log.info(report);
try (final FileWriter writer = new FileWriter(reportPath)) {
writer.write(report);
}
obj.setHtmlPath(reportPath);
} catch (final IOException e) {
ErlLogger.error(e);
}
for (final ICoverageObject child : obj.getChildren()) {
generateReportTree(child, dirPath);
}
}
use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.
the class ShowCoverageAction method perform.
@Override
protected void perform(final StatsTreeObject selection) {
if (selection instanceof ModuleStats) {
final ModuleStats module = (ModuleStats) selection;
final String name = module.getLabel() + ".erl";
if (ifMarkAnnotations(module)) {
module.couldBeMarked = true;
marker.addAnnotationsToFile(name);
}
} else if (selection instanceof FunctionStats) {
final FunctionStats fs = (FunctionStats) selection;
final ModuleStats module = (ModuleStats) fs.getParent();
final String name = module.getLabel() + ".erl";
if (ifMarkAnnotations(module)) {
log.info(fs.getLineStart());
log.info(fs.getLineEnd());
module.couldBeMarked = true;
marker.addAnnotationsFragment(name, fs.getLineStart(), fs.getLineEnd());
}
} else if (selection.equals(StatsTreeModel.getInstance().getRoot())) {
// TODO: check annotation tree, only if root mark all annotations
final Collection<ICoverageObject> col = selection.getModules();
for (final ICoverageObject module : col) {
if (ifMarkAnnotations((ModuleStats) module)) {
((ModuleStats) module).couldBeMarked = true;
} else {
((ModuleStats) module).couldBeMarked = false;
}
}
marker.addAnnotations();
} else {
final Collection<ICoverageObject> col = selection.getModules();
for (final ICoverageObject module : col) {
if (ifMarkAnnotations((ModuleStats) module)) {
final String name = module.getLabel() + ".erl";
((ModuleStats) module).couldBeMarked = true;
marker.addAnnotationsToFile(name);
}
}
}
}
use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.
the class StatsViewLabelProvider method getColumnImage.
@Override
public Image getColumnImage(final Object element, final int columnIndex) {
Image img = null;
final ICoverageObject statsEl = (ICoverageObject) element;
switch(columnIndex) {
case 0:
final ObjectType type = statsEl.getType();
switch(type) {
case FUNCTION:
img = Activator.getImageDescriptor(Images.FUNCTION).createImage();
break;
case MODULE:
IErlModule m;
try {
m = ErlangEngine.getInstance().getModel().findModule(statsEl.getLabel());
} catch (final ErlModelException e) {
ErlLogger.error(e);
return null;
}
img = ErlangElementImageProvider.getErlImageDescriptor(m, ErlangElementImageProvider.SMALL_ICONS).createImage();
break;
case FOLDER:
img = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER).createImage();
break;
case PROJECT:
img = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT).createImage();
break;
default:
break;
}
break;
case 3:
img = drawPercentage(statsEl.getPercentage());
break;
default:
}
return img;
}
Aggregations