Search in sources :

Example 16 with IErlModel

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

the class CompilerPreferencePage method doLinkActivated.

void doLinkActivated(final Link widget) {
    if (isProjectPreferencePage()) {
        openWorkspacePreferences(null);
    } else {
        final List<IProject> erlProjects = new ArrayList<>();
        final Set<IProject> projectsWithSpecifics = new HashSet<>();
        final IErlModel model = ErlangEngine.getInstance().getModel();
        try {
            for (final IErlProject ep : model.getErlangProjects()) {
                final IProject p = ep.getWorkspaceProject();
                if (hasProjectSpecificOptions(p)) {
                    projectsWithSpecifics.add(p);
                }
                erlProjects.add(p);
            }
        } catch (final ErlModelException e) {
        }
        final ProjectSelectionDialog dialog = new ProjectSelectionDialog(getShell(), erlProjects, projectsWithSpecifics);
        if (dialog.open() == Window.OK) {
            final IProject res = (IProject) dialog.getFirstResult();
            openProjectProperties(res);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelException(org.erlide.engine.model.ErlModelException) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet)

Example 17 with IErlModel

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

the class ErlangExternalEditorInputFactory method createElement.

@Override
public IAdaptable createElement(final IMemento memento) {
    // Get the file name.
    final String externalModulePath = memento.getString(ErlangExternalEditorInputFactory.TAG_EXTERNAL_MODULE_PATH);
    if (externalModulePath == null) {
        return null;
    }
    IErlModule module;
    try {
        final IErlModel model = ErlangEngine.getInstance().getModel();
        module = ErlangEngine.getInstance().getModelUtilService().getModuleFromExternalModulePath(model, externalModulePath);
    } catch (final ErlModelException e1) {
        return null;
    }
    if (module == null) {
        return null;
    }
    // Get the file name.
    final String uriString = memento.getString(ErlangExternalEditorInputFactory.TAG_URI);
    if (uriString == null) {
        return null;
    }
    URI uri;
    try {
        uri = new URI(uriString);
    } catch (final URISyntaxException e) {
        return null;
    }
    try {
        return new ErlangExternalEditorInput(EFS.getStore(uri), module);
    } catch (final CoreException e) {
        return null;
    }
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 18 with IErlModel

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

the class WranglerUtils method notifyErlide.

/**
 * Notifies Erlide about the changed files.
 *
 * @param changedFiles
 *            changed files
 */
public static void notifyErlide(final List<ChangedFile> changedFiles) {
    final IErlModel model = ErlangEngine.getInstance().getModel();
    for (final ChangedFile f : changedFiles) {
        IFile file;
        try {
            file = WranglerUtils.getFileFromPath(f.getNewPath());
            final IErlElement element = model.findElement(file);
            final IErlModule m = (IErlModule) element;
            m.resourceChanged(null);
            final IEditorPart editor = GlobalParameters.getEditor();
            if (editor instanceof ErlangEditor) {
                ((ErlangEditor) editor).resetAndCacheScannerAndParser();
            }
            model.notifyChange(m);
        } catch (final Exception e) {
            ErlLogger.error(e);
        }
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) IErlModule(org.erlide.engine.model.root.IErlModule) IEditorPart(org.eclipse.ui.IEditorPart) ChangedFile(org.erlide.wrangler.refactoring.backend.ChangedFile) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor)

Example 19 with IErlModel

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

the class AbstractErlSelection method getSearchPath.

@Override
public OtpErlangList getSearchPath() {
    final IProject project = file.getProject();
    final IErlModel model = ErlangEngine.getInstance().getModel();
    final IErlProject actualProject = model.getErlangProject(project);
    final IPath projectLocation = actualProject.getWorkspaceProject().getLocation();
    final Collection<IPath> sourcDirs = actualProject.getProperties().getSourceDirs();
    final OtpErlangString[] searchPath = new OtpErlangString[sourcDirs.size()];
    int i = 0;
    for (final IPath src : sourcDirs) {
        searchPath[i++] = new OtpErlangString(projectLocation.append(src).toOSString());
    }
    return new OtpErlangList(searchPath);
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) IPath(org.eclipse.core.runtime.IPath) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) IProject(org.eclipse.core.resources.IProject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 20 with IErlModel

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

the class ErlModelUtils method getModule.

public static IErlModule getModule(final IEditorInput editorInput) throws CoreException {
    if (editorInput instanceof IFileEditorInput) {
        final IFileEditorInput input = (IFileEditorInput) editorInput;
        final IFile file = input.getFile();
        final IErlModel model = ErlangEngine.getInstance().getModel();
        IErlModule module = model.findModule(file);
        if (module != null) {
            return module;
        }
        final IPath path = file.getLocation();
        Charset encoding;
        try {
            encoding = Charset.forName(file.getCharset());
        } catch (Exception e) {
            encoding = Charsets.UTF_8;
        }
        module = model.getModuleFromFile(model, file.getName(), path, encoding);
        module.setResource(file);
        return module;
    }
    if (editorInput instanceof ErlangExternalEditorInput) {
        final ErlangExternalEditorInput erlangExternalEditorInput = (ErlangExternalEditorInput) editorInput;
        return erlangExternalEditorInput.getModule();
    }
    final String path = ErlModelUtils.getPathForInput(editorInput);
    if (path == null) {
        return null;
    }
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlModule module = ErlangEngine.getInstance().getModelFindService().findModule(model, null, null, path, IErlElementLocator.Scope.ALL_PROJECTS);
    if (module != null) {
        return module;
    }
    final Charset encoding = ErlModelUtils.getEncodingForInput(editorInput);
    final IPath p = new Path(path);
    return ErlangEngine.getInstance().getModel().getModuleFromFile(null, p.lastSegment(), p, encoding);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ErlangExternalEditorInput(org.erlide.ui.editors.util.ErlangExternalEditorInput) IErlModel(org.erlide.engine.model.root.IErlModel) IPath(org.eclipse.core.runtime.IPath) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IErlModule(org.erlide.engine.model.root.IErlModule) Charset(java.nio.charset.Charset) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

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