Search in sources :

Example 1 with ErlModelStatus

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

the class ErlProject method buildStructure.

@Override
public boolean buildStructure(final IProgressMonitor pm) throws ErlModelException {
    final IResource r = getCorrespondingResource();
    // check whether the Erlang project can be opened
    if (!(r instanceof IContainer) || !r.isAccessible()) {
        ErlLogger.warn("Project %s has no resources: res:%s acc:%s cont:%s", getName(), r, r == null ? "?" : r.isAccessible(), r instanceof IContainer);
        throw new ErlModelException(new ErlModelStatus(ErlModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
    }
    addConfigurationChangeListeners();
    try {
        final IContainer c = (IContainer) r;
        final IResource[] elems = c.members();
        final List<IErlElement> children = new ArrayList<>(elems.length + 1);
        // ErlLogger.debug(">>adding externals");
        addExternals(children);
        // ErlLogger.debug("childcount %d", children.size());
        // ErlLogger.debug(">>adding otp");
        addOtpExternals(children);
        // ErlLogger.debug("childcount %d", children.size());
        final IErlModel model = ErlangEngine.getInstance().getModel();
        for (final IResource element : elems) {
            if (element instanceof IFolder) {
                final IFolder folder = (IFolder) element;
                final IErlFolder erlFolder = (IErlFolder) model.create(folder);
                children.add(erlFolder);
            } else if (element instanceof IFile) {
                final IFile file = (IFile) element;
                if (CommonUtils.isErlangFileContentFileName(file.getName())) {
                    final IErlModule m = (IErlModule) model.create(file);
                    children.add(m);
                }
            }
        }
        setChildren(children);
    } catch (final CoreException e) {
        ErlLogger.error(e);
        setChildren(new ArrayList<IErlModule>());
        return false;
    }
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelStatus(org.erlide.engine.model.ErlModelStatus) ArrayList(java.util.ArrayList) IErlFolder(org.erlide.engine.model.root.IErlFolder) IErlElement(org.erlide.engine.model.IErlElement) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with ErlModelStatus

use of org.erlide.engine.model.ErlModelStatus 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 3 with ErlModelStatus

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

the class ErlModel method newProject.

@Override
public final IErlProject newProject(final String name) throws ErlModelException {
    final IWorkspace ws = ResourcesPlugin.getWorkspace();
    final IProject project = ws.getRoot().getProject(name);
    try {
        if (!project.exists()) {
            project.create(null);
            project.open(null);
            final IProjectDescription description = project.getDescription();
            description.setNatureIds(new String[] { ModelPlugin.NATURE_ID });
            description.setName(name);
            project.setDescription(description, null);
        }
        if (!project.isOpen()) {
            project.open(null);
        }
        return findProject(project);
    } catch (final CoreException e) {
        e.printStackTrace();
        throw new ErlModelException(e, new ErlModelStatus(e));
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) ErlModelStatus(org.erlide.engine.model.ErlModelStatus) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)3 ErlModelException (org.erlide.engine.model.ErlModelException)3 ErlModelStatus (org.erlide.engine.model.ErlModelStatus)3 IContainer (org.eclipse.core.resources.IContainer)2 IResource (org.eclipse.core.resources.IResource)2 IErlModel (org.erlide.engine.model.root.IErlModel)2 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IErlElement (org.erlide.engine.model.IErlElement)1 IErlFolder (org.erlide.engine.model.root.IErlFolder)1 IErlModule (org.erlide.engine.model.root.IErlModule)1