Search in sources :

Example 26 with IErlModel

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

Example 27 with IErlModel

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

the class ErlideTestUtils method deleteProject.

public static void deleteProject(final IErlProject erlProject) throws CoreException {
    final IProject project = erlProject.getWorkspaceProject();
    final IPath location = project.getLocation();
    project.delete(true, null);
    if (location != null) {
        new File(location.toPortableString()).delete();
    }
    if (ErlideTestUtils.modulesAndIncludes != null) {
        final List<IErlModule> list = Lists.newArrayList(ErlideTestUtils.modulesAndIncludes);
        for (final IErlModule module : list) {
            if (ErlangEngine.getInstance().getModelUtilService().getProject(module) == erlProject) {
                ErlideTestUtils.deleteModule(module);
            }
        }
    }
    erlProject.dispose();
    if (ErlideTestUtils.projects != null) {
        ErlideTestUtils.projects.remove(ErlangEngine.getInstance().getModel().findProject(project));
    }
    final IErlModel model = ErlangEngine.getInstance().getModel();
    model.resourceChanged(null);
    model.open(null);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IErlModel(org.erlide.engine.model.root.IErlModel) IErlModule(org.erlide.engine.model.root.IErlModule) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 28 with IErlModel

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

the class InterpretedModuleListContentProvider method addModules.

/**
 * Find modules from string list add to IFile-list
 *
 * @param interpret
 *            the list of strings from prefs (projectName:fileName;... or
 *            moduleName;...)
 */
public void addModules(final Collection<String> interpret) {
    final IErlModel model = ErlangEngine.getInstance().getModel();
    for (final String projectColonModule : interpret) {
        // project:module | module
        final String[] projectModule = projectColonModule.split(":");
        IErlModule module = null;
        if (projectModule.length > 1) {
            final IErlProject project = (IErlProject) model.getChildNamed(projectModule[0]);
            if (project != null) {
                final String mName = projectModule[1];
                try {
                    final boolean isErlangFile = CommonUtils.isErlangFileContentFileName(mName);
                    final String s = isErlangFile ? mName : mName + ".erl";
                    module = project.getModule(s);
                } catch (final ErlModelException e) {
                    ErlLogger.warn(e);
                }
            }
        } else {
            try {
                module = model.findModule(projectColonModule);
            } catch (final ErlModelException e) {
            }
        }
        addModule(module);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 29 with IErlModel

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

the class RunDialyzerHandler method collectModulesFromSelection.

private Set<IErlModule> collectModulesFromSelection(final ISelection selection) {
    final Set<IErlModule> modules = Sets.newHashSet();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        final IErlModel model = ErlangEngine.getInstance().getModel();
        try {
            model.open(null);
            for (final Object i : structuredSelection.toList()) {
                if (i instanceof IResource) {
                    final IResource r = (IResource) i;
                    modules.addAll(DialyzerUtils.collectModulesFromResource(model, r));
                }
            }
        } catch (final ErlModelException e) {
            ErlLogger.debug(e);
        }
    }
    return modules;
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource)

Example 30 with IErlModel

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

the class OpenAction method run.

@Override
public void run(final ITextSelection selection) {
    try {
        final IEditorPart activeEditor = getSite().getPage().getActiveEditor();
        final int offset = selection.getOffset();
        ITextEditor textEditor = null;
        OpenResult openResult = null;
        IErlElement element = null;
        IErlProject project = null;
        IErlModule module = null;
        final IErlModel model = ErlangEngine.getInstance().getModel();
        if (activeEditor instanceof AbstractErlangEditor) {
            final AbstractErlangEditor editor = (AbstractErlangEditor) activeEditor;
            textEditor = editor;
            editor.reconcileNow();
            final String scannerName = editor.getScannerName();
            module = editor.getModule();
            project = editor.getProject();
            openResult = ErlangEngine.getInstance().getOpenService().open(scannerName, offset, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module), project.getProperties().getExternalModules(), model.getPathVars());
            ErlLogger.debug("open " + openResult);
            element = editor.getElementAt(offset, true);
        } else if (activeEditor instanceof ITextEditor) {
            textEditor = (ITextEditor) activeEditor;
            final String text = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()).get();
            openResult = ErlangEngine.getInstance().getOpenService().openText(text, offset);
            final IFile file = textEditor.getEditorInput().getAdapter(IFile.class);
            if (file != null) {
                final IProject p = file.getProject();
                if (p != null) {
                    project = model.findProject(p);
                }
            }
        }
        if (openResult != null) {
            helper.openOpenResult(textEditor, module, offset, project, openResult, element);
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) IErlElement(org.erlide.engine.model.IErlElement) OpenResult(org.erlide.engine.services.search.OpenResult) IErlModule(org.erlide.engine.model.root.IErlModule)

Aggregations

IErlModel (org.erlide.engine.model.root.IErlModel)36 IErlModule (org.erlide.engine.model.root.IErlModule)18 IErlProject (org.erlide.engine.model.root.IErlProject)13 IFile (org.eclipse.core.resources.IFile)11 ErlModelException (org.erlide.engine.model.ErlModelException)11 IProject (org.eclipse.core.resources.IProject)10 CoreException (org.eclipse.core.runtime.CoreException)8 IErlElement (org.erlide.engine.model.IErlElement)8 IResource (org.eclipse.core.resources.IResource)7 IPath (org.eclipse.core.runtime.IPath)5 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)4 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 IBackend (org.erlide.backend.api.IBackend)3 OpenResult (org.erlide.engine.services.search.OpenResult)3 File (java.io.File)2 IOException (java.io.IOException)2 IContainer (org.eclipse.core.resources.IContainer)2