Search in sources :

Example 26 with ErlModelException

use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.

the class OpenItemAction method openInEditor.

private IEditorPart openInEditor(final String name) {
    // search
    IErlModule module;
    try {
        module = ErlangEngine.getInstance().getModel().findModule(name);
    } catch (final ErlModelException e1) {
        e1.printStackTrace();
        return null;
    }
    log.info(module.getFilePath());
    final File fileToOpen = new File(module.getFilePath());
    final IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        final IEditorPart p = IDE.openEditorOnFileStore(page, fileStore);
        log.info(p.getClass());
        return p;
    } catch (final PartInitException e) {
        ErlLogger.error(e);
        return null;
    }
}
Also used : ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IFileStore(org.eclipse.core.filesystem.IFileStore) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File)

Example 27 with ErlModelException

use of org.erlide.engine.model.ErlModelException 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)

Example 28 with ErlModelException

use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.

the class CoverMainTab method createModuleArray.

private Object[] createModuleArray(final IErlProject p) {
    Object[] array;
    try {
        final List<ProjectElement> res = new LinkedList<>();
        final Collection<IErlModule> modules = p.getModules();
        for (final IErlModule m : modules) {
            final ProjectElement elem = new ProjectElement(m.getName(), ErlangElementImageProvider.getErlImageDescriptor(m, ErlangElementImageProvider.SMALL_ICONS).createImage());
            res.add(elem);
        }
        array = res.toArray();
    } catch (final ErlModelException e) {
        array = new Object[0];
        ErlLogger.error(e);
    }
    return array;
}
Also used : ErlModelException(org.erlide.engine.model.ErlModelException) ProjectElement(org.erlide.cover.ui.launch.helpers.ProjectElement) IErlModule(org.erlide.engine.model.root.IErlModule) LinkedList(java.util.LinkedList)

Example 29 with ErlModelException

use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.

the class FunctionStats method getLineStart.

/**
 * First line of the function
 *
 * @return
 */
public int getLineStart() {
    if (lineStart != 0) {
        return lineStart;
    }
    final String mName = ((StatsTreeObject) getParent()).getLabel();
    IErlModule m;
    try {
        m = ErlangEngine.getInstance().getModel().findModule(mName);
        final IErlFunction f = m.findFunction(new ErlangFunction(getLabel(), getArity()));
        lineStart = f.getLineStart();
    } catch (final ErlModelException e) {
        ErlLogger.error(e);
    }
    return lineStart;
}
Also used : ErlModelException(org.erlide.engine.model.ErlModelException) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction)

Example 30 with ErlModelException

use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.

the class ErlFolder method buildStructure.

@Override
public boolean buildStructure(final IProgressMonitor pm) throws ErlModelException {
    final IErlModel model = ErlangEngine.getInstance().getModel();
    final IContainer c = (IContainer) getResource();
    try {
        // FIXME this is general stuff -> model or model manager?
        final IResource[] members = c.members();
        for (final IResource resource : members) {
            model.create(resource);
        }
    } catch (final CoreException e) {
        throw new ErlModelException(new ErlModelStatus(ErlModelStatusConstants.CORE_EXCEPTION, e));
    }
    return true;
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) ErlModelStatus(org.erlide.engine.model.ErlModelStatus) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

ErlModelException (org.erlide.engine.model.ErlModelException)45 IErlElement (org.erlide.engine.model.IErlElement)21 IErlModule (org.erlide.engine.model.root.IErlModule)21 IErlModel (org.erlide.engine.model.root.IErlModel)9 IErlProject (org.erlide.engine.model.root.IErlProject)9 ArrayList (java.util.ArrayList)8 IOpenable (org.erlide.engine.model.root.IOpenable)7 CoreException (org.eclipse.core.runtime.CoreException)6 IProject (org.eclipse.core.resources.IProject)5 IResource (org.eclipse.core.resources.IResource)5 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)4 IFile (org.eclipse.core.resources.IFile)4 IParent (org.erlide.engine.model.IParent)4 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)4 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)4 Composite (org.eclipse.swt.widgets.Composite)3 ErlangEditor (org.erlide.ui.editors.erl.ErlangEditor)3 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2