Search in sources :

Example 11 with IParent

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

the class ErlangExternalsContentProvider method getParent.

@Override
public Object getParent(final Object element) {
    if (element instanceof IErlElement) {
        final IErlElement elt = (IErlElement) element;
        IParent parent = elt.getParent();
        final String filePath = elt.getFilePath();
        if (parent == ErlangEngine.getInstance().getModel() && filePath != null) {
            parent = elt.getParent();
        }
        if (parent instanceof IErlModule) {
            final IErlModule mod = (IErlModule) parent;
            final IResource resource = mod.getCorrespondingResource();
            if (resource != null) {
                return resource;
            }
        } else {
            return parent;
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IParent(org.erlide.engine.model.IParent) IErlModule(org.erlide.engine.model.root.IErlModule) IResource(org.eclipse.core.resources.IResource)

Example 12 with IParent

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

the class ErlangFileContentProvider method getChildren.

/**
 * Return the model elements for a *.erl IFile or NO_CHILDREN for otherwise.
 */
@Override
public Object[] getChildren(final Object parentElement0) {
    Object parentElement = parentElement0;
    try {
        if (parentElement instanceof IFile) {
            parentElement = ErlangEngine.getInstance().getModel().findModule((IFile) parentElement);
        }
        if (parentElement instanceof IOpenable) {
            final IOpenable openable = (IOpenable) parentElement;
            openable.open(null);
        }
        if (parentElement instanceof IParent) {
            final IParent parent = (IParent) parentElement;
            final Collection<IErlElement> children = parent.getChildren();
            return children.toArray();
        }
    } catch (final ErlModelException e) {
        ErlLogger.warn(e);
    }
    return ErlangFileContentProvider.NO_CHILDREN;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) IFile(org.eclipse.core.resources.IFile) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException)

Example 13 with IParent

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

the class SearchUtil method getWorkingSetsScope.

public static ErlSearchScope getWorkingSetsScope(final IWorkingSet[] workingSets, final boolean addExternals, final boolean addOTP) throws CoreException {
    final ErlSearchScope result = new ErlSearchScope();
    final Set<String> externalModulePaths = new HashSet<>();
    if (workingSets == null) {
        return result;
    }
    for (final IWorkingSet ws : workingSets) {
        final IAdaptable[] elements = ws.getElements();
        for (final IAdaptable a : elements) {
            final IResource r = a.getAdapter(IResource.class);
            SearchCoreUtil.addResourceToScope(result, r);
            IParent parent = null;
            Object o = a.getAdapter(IErlElement.class);
            if (o instanceof IParent) {
                parent = (IParent) o;
            } else {
                o = a.getAdapter(IResource.class);
                if (o != null) {
                    final IResource resource = (IResource) o;
                    final IErlElement element = ErlangEngine.getInstance().getModel().findElement(resource);
                    if (element instanceof IParent) {
                        parent = (IParent) element;
                    }
                }
            }
            if (parent != null) {
                SearchCoreUtil.addExternalModules(parent, result, externalModulePaths, addExternals, addOTP);
            }
        }
    }
    return result;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IAdaptable(org.eclipse.core.runtime.IAdaptable) IParent(org.erlide.engine.model.IParent) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IWorkingSet(org.eclipse.ui.IWorkingSet) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 14 with IParent

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

the class SearchUtil method getSelectionScope.

public static ErlSearchScope getSelectionScope(final ISelection selection, final boolean addExternals, final boolean addOtp) throws CoreException {
    final ErlSearchScope result = new ErlSearchScope();
    final Set<String> externalModulePaths = new HashSet<>();
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;
        for (final Object i : ss.toList()) {
            if (i instanceof IResource) {
                final IResource r = (IResource) i;
                SearchCoreUtil.addResourceToScope(result, r);
            } else if (i instanceof IErlModule) {
                final IErlModule module = (IErlModule) i;
                result.addModule(module);
            } else if (i instanceof IParent) {
                final IParent parent = (IParent) i;
                SearchCoreUtil.addExternalModules(parent, result, externalModulePaths, addExternals, addOtp);
            }
        }
    }
    return result;
}
Also used : IParent(org.erlide.engine.model.IParent) IErlModule(org.erlide.engine.model.root.IErlModule) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 15 with IParent

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

the class ErlElementDelta method getAncestors.

private List<IParent> getAncestors(final IErlElement element0) {
    IErlElement element = element0;
    IParent parent = element.getParent();
    if (parent == null) {
        return null;
    }
    final ArrayList<IParent> parents = Lists.newArrayList();
    while (!parent.equals(fElement)) {
        parents.add(parent);
        if (parent instanceof IErlElement) {
            element = (IErlElement) parent;
            parent = element.getParent();
        } else {
            break;
        }
        if (parent == null) {
            break;
        }
    }
    parents.trimToSize();
    return parents;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IParent(org.erlide.engine.model.IParent)

Aggregations

IParent (org.erlide.engine.model.IParent)24 IErlElement (org.erlide.engine.model.IErlElement)18 IErlModule (org.erlide.engine.model.root.IErlModule)10 IOpenable (org.erlide.engine.model.root.IOpenable)8 IResource (org.eclipse.core.resources.IResource)5 ErlModelException (org.erlide.engine.model.ErlModelException)5 IErlProject (org.erlide.engine.model.root.IErlProject)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 HashSet (java.util.HashSet)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 IErlExternal (org.erlide.engine.model.root.IErlExternal)2 IErlFolder (org.erlide.engine.model.root.IErlFolder)2 ErlSearchScope (org.erlide.engine.services.search.ErlSearchScope)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 Stopwatch (com.google.common.base.Stopwatch)1 IFileInfo (org.eclipse.core.filesystem.IFileInfo)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IContainer (org.eclipse.core.resources.IContainer)1