Search in sources :

Example 1 with IErlFolder

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

the class DialyzerUtils method collectModulesFromResource.

public static Set<IErlModule> collectModulesFromResource(final IErlElementLocator model, final IResource resource) throws ErlModelException {
    final Set<IErlModule> result = Sets.newHashSet();
    final IErlElement element = model.findElement(resource, true);
    if (element == null) {
        return result;
    }
    if (element instanceof IErlFolder) {
        final IErlFolder folder = (IErlFolder) element;
        folder.open(null);
        result.addAll(folder.getModules());
    } else if (element instanceof IErlModule) {
        final IErlModule module = (IErlModule) element;
        result.add(module);
    } else if (element instanceof IErlProject) {
        final IErlProject project = (IErlProject) element;
        project.open(null);
        result.addAll(project.getModules());
    }
    return result;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlFolder(org.erlide.engine.model.root.IErlFolder)

Example 2 with IErlFolder

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

the class ErlangElementImageProvider method computeDescriptor.

private ImageDescriptor computeDescriptor(final Object element, final int flags) {
    if (element instanceof IErlElement) {
        return ErlangElementImageProvider.getErlImageDescriptor((IErlElement) element, flags);
    } else if (element instanceof IFile) {
        final IFile file = (IFile) element;
        if ("erl".equals(file.getFileExtension())) {
            // $NON-NLS-1$
            return getErlResourceImageDescriptor(file, flags);
        // image for a CU not on the build path
        }
        return getWorkbenchImageDescriptor(file, flags);
    } else if (element instanceof IFolder) {
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlFolder ef = (IErlFolder) model.findElement((IResource) element);
        if (ef != null && (ef.isOnSourcePath() || ef.isOnIncludePath())) {
            return ErlangElementImageProvider.getErlImageDescriptor(ef, flags);
        }
    } else if (element instanceof IAdaptable) {
        return getWorkbenchImageDescriptor((IAdaptable) element, flags);
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) IErlFolder(org.erlide.engine.model.root.IErlFolder) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with IErlFolder

use of org.erlide.engine.model.root.IErlFolder 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 4 with IErlFolder

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

the class ErlModel method createFolder.

public IErlFolder createFolder(final IFolder folder, final IParent parent) {
    if (folder == null) {
        return null;
    }
    final IErlFolder f = new ErlFolder(folder, parent);
    final IParent p = parent;
    if (p != null) {
        p.addChild(f);
    } else {
    // ErlLogger.warn("creating folder %s in null parent?!", folder
    // .getName());
    }
    return f;
}
Also used : IParent(org.erlide.engine.model.IParent) ErlFolder(org.erlide.engine.internal.model.root.ErlFolder) IErlFolder(org.erlide.engine.model.root.IErlFolder) IErlFolder(org.erlide.engine.model.root.IErlFolder)

Example 5 with IErlFolder

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

the class ErlModel method findIncludeFromModule.

@Override
public IErlModule findIncludeFromModule(final IErlModule module, final String includeName, final String includePath, final IErlElementLocator.Scope scope) throws ErlModelException {
    final IParent parent = module.getParent();
    if (parent instanceof IErlFolder) {
        final IErlFolder folder = (IErlFolder) parent;
        folder.open(null);
        final IErlModule include = folder.findInclude(includeName, includePath);
        if (include != null) {
            return include;
        }
    }
    return findIncludeFromProject(ErlangEngine.getInstance().getModelUtilService().getProject(module), includeName, includePath, true, scope);
}
Also used : IParent(org.erlide.engine.model.IParent) IErlFolder(org.erlide.engine.model.root.IErlFolder) IErlModule(org.erlide.engine.model.root.IErlModule)

Aggregations

IErlFolder (org.erlide.engine.model.root.IErlFolder)8 IErlElement (org.erlide.engine.model.IErlElement)5 IErlModule (org.erlide.engine.model.root.IErlModule)4 IFolder (org.eclipse.core.resources.IFolder)3 IResource (org.eclipse.core.resources.IResource)3 IFile (org.eclipse.core.resources.IFile)2 IParent (org.erlide.engine.model.IParent)2 IErlModel (org.erlide.engine.model.root.IErlModel)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 IContainer (org.eclipse.core.resources.IContainer)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IPath (org.eclipse.core.runtime.IPath)1 ErlFolder (org.erlide.engine.internal.model.root.ErlFolder)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 ErlModelStatus (org.erlide.engine.model.ErlModelStatus)1 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)1 IErlProject (org.erlide.engine.model.root.IErlProject)1