Search in sources :

Example 1 with StatsTreeObject

use of org.erlide.cover.views.model.StatsTreeObject 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);
}
Also used : ICoverageObject(org.erlide.cover.views.model.ICoverageObject) StatsTreeObject(org.erlide.cover.views.model.StatsTreeObject) IConfiguration(org.erlide.cover.api.IConfiguration)

Example 2 with StatsTreeObject

use of org.erlide.cover.views.model.StatsTreeObject in project erlide_eclipse by erlang.

the class HtmlReportAction method run.

@Override
public void run() {
    log.info("html report!");
    if (StatsTreeModel.getInstance().getRoot().getHtmlPath() == null) {
        final IPath location = Activator.getDefault().getStateLocation().append(CoverConstants.REPORT_DIR);
        final File dir = location.toFile();
        if (!dir.exists() && !dir.mkdir()) {
            CoverageHelper.reportError("Can not save results!");
            return;
        }
        generateReportTree(StatsTreeModel.getInstance().getRoot(), dir.getAbsolutePath());
    }
    final ISelection selection = viewer.getSelection();
    log.info(selection.getClass().getName());
    if (!(selection instanceof ITreeSelection)) {
        final IStatus executionStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Internall error occured: bad sellection type", null);
        StatusManager.getManager().handle(executionStatus, StatusManager.SHOW);
        return;
    }
    final ITreeSelection treeSelection = (ITreeSelection) selection;
    log.info(treeSelection.getFirstElement());
    log.info(treeSelection.getFirstElement().getClass().getName());
    log.info(treeSelection.getPaths());
    final StatsTreeObject selObj = (StatsTreeObject) treeSelection.getFirstElement();
    final BrowserDialog browser = new BrowserDialog(shell);
    if (selObj instanceof FunctionStats) {
        final ModuleStats module = (ModuleStats) selObj.getParent();
        browser.setObject(module);
    } else {
        browser.setObject(selObj);
    }
    browser.open();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IPath(org.eclipse.core.runtime.IPath) ISelection(org.eclipse.jface.viewers.ISelection) FunctionStats(org.erlide.cover.views.model.FunctionStats) BrowserDialog(org.erlide.cover.ui.views.util.BrowserDialog) StatsTreeObject(org.erlide.cover.views.model.StatsTreeObject) ModuleStats(org.erlide.cover.views.model.ModuleStats) File(java.io.File)

Example 3 with StatsTreeObject

use of org.erlide.cover.views.model.StatsTreeObject in project erlide_eclipse by erlang.

the class OpenItemAction method run.

@Override
public void run() {
    log.info("Open item!");
    final ISelection selection = viewer.getSelection();
    if (!(selection instanceof ITreeSelection)) {
        final IStatus executionStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Internall error occured: bad sellection type", null);
        StatusManager.getManager().handle(executionStatus, StatusManager.SHOW);
        return;
    }
    final ITreeSelection treeSelection = (ITreeSelection) selection;
    final StatsTreeObject obj = (StatsTreeObject) treeSelection.getFirstElement();
    if (obj.getClass().equals(ModuleStats.class)) {
        openInEditor(obj.getLabel() + ".erl");
    } else if (obj.getClass().equals(FunctionStats.class)) {
        final FunctionStats fs = (FunctionStats) obj;
        final String moduleName = ((StatsTreeObject) fs.getParent()).getLabel();
        final IEditorPart p = openInEditor(moduleName + ".erl");
        if (p == null || !(p instanceof ErlangEditor)) {
            return;
        }
        final ErlangEditor editor = (ErlangEditor) p;
        IErlModule module;
        try {
            module = ErlangEngine.getInstance().getModel().findModule(moduleName);
            final IErlFunction f = module.findFunction(new ErlangFunction(fs.getLabel(), fs.getArity()));
            editor.setSelection(f);
        } catch (final ErlModelException e) {
            ErlLogger.error(e);
        }
    } else {
    // disabled
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction) IEditorPart(org.eclipse.ui.IEditorPart) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ErlModelException(org.erlide.engine.model.ErlModelException) ISelection(org.eclipse.jface.viewers.ISelection) IErlModule(org.erlide.engine.model.root.IErlModule) FunctionStats(org.erlide.cover.views.model.FunctionStats) StatsTreeObject(org.erlide.cover.views.model.StatsTreeObject) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor)

Aggregations

StatsTreeObject (org.erlide.cover.views.model.StatsTreeObject)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ISelection (org.eclipse.jface.viewers.ISelection)2 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)2 FunctionStats (org.erlide.cover.views.model.FunctionStats)2 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IConfiguration (org.erlide.cover.api.IConfiguration)1 BrowserDialog (org.erlide.cover.ui.views.util.BrowserDialog)1 ICoverageObject (org.erlide.cover.views.model.ICoverageObject)1 ModuleStats (org.erlide.cover.views.model.ModuleStats)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 ErlangFunction (org.erlide.engine.model.erlang.ErlangFunction)1 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)1 IErlModule (org.erlide.engine.model.root.IErlModule)1 ErlangEditor (org.erlide.ui.editors.erl.ErlangEditor)1