Search in sources :

Example 16 with IParent

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

the class ErlElementDelta method createDeltaTree.

/**
 * Creates the nested delta deltas based on the affected element its delta, and the
 * root of this delta tree. Returns the root of the created delta tree.
 */
protected ErlElementDelta createDeltaTree(final IErlElement element, final ErlElementDelta delta) {
    ErlElementDelta childDelta = delta;
    final List<IParent> ancestors = getAncestors(element);
    if (ancestors == null) {
        if (equalsAndSameParent(delta.getElement(), getElement())) {
            // handle case of two jars that can be equals but not in the
            // same project
            // the element being changed is the root element
            fKind = delta.fKind;
            fFlags = delta.fFlags;
            fMovedToElement = delta.fMovedToElement;
            fMovedFromElement = delta.fMovedFromElement;
        } else {
        // the given delta is not the root or a child - illegal
        // Assert.isTrue(false);
        }
    } else {
        for (final IParent ancestor : ancestors) {
            final IErlElement element2 = (IErlElement) ancestor;
            final ErlElementDelta ancestorDelta = new ErlElementDelta(0, 0, element2);
            ancestorDelta.addAffectedChild(childDelta);
            childDelta = ancestorDelta;
        }
    }
    return childDelta;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IParent(org.erlide.engine.model.IParent) IErlElementDelta(org.erlide.engine.model.root.IErlElementDelta)

Example 17 with IParent

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

the class ErlModel method findElement.

@Override
public IErlElement findElement(final IResource rsrc, final boolean openElements) {
    if (rsrc == null) {
        return null;
    }
    final IPath path = rsrc.getFullPath();
    IParent p = this;
    for (final String segment : path.segments()) {
        IErlElement c = p.getChildWithResource(rsrc);
        if (c != null) {
            return c;
        }
        c = p.getChildNamed(segment);
        if (c == null) {
            return null;
        }
        if (openElements && c instanceof IOpenable) {
            final IOpenable o = (IOpenable) c;
            try {
                o.open(null);
            } catch (final ErlModelException e) {
                return null;
            }
        }
        final IResource resource = c.getResource();
        if (resource != null && resource.equals(rsrc)) {
            return c;
        }
        p = (IParent) c;
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) IPath(org.eclipse.core.runtime.IPath) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IResource(org.eclipse.core.resources.IResource)

Example 18 with IParent

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

the class ErlModel method remove.

void remove(final IResource rsrc) {
    final IErlElement element = findElement(rsrc);
    if (element != null) {
        final IParent p = element.getParent();
        p.removeChild(element);
        if (element instanceof IOpenable) {
            final IOpenable openable = (IOpenable) element;
            try {
                openable.close();
            } catch (final ErlModelException e) {
                ErlLogger.error(e);
            }
        }
    }
// TODO should we make Erlidemodelevents and fire them?
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException)

Example 19 with IParent

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

the class ErlModel method getModuleWithoutResource.

private IErlModule getModuleWithoutResource(final IParent parent, final String name, final IPath path, final Charset encoding, final String initialText) {
    IErlModule m = moduleMap.get(path);
    if (m == null) {
        final IParent parent2 = parent == null ? this : parent;
        if (path != null) {
            m = new ErlModule(parent2, name, path.toPortableString(), encoding, initialText);
            moduleMap.put(path, m);
            mapModule.put(m, path);
        } else {
            m = new ErlModule(parent2, name, null, encoding, initialText);
        }
    }
    return m;
}
Also used : ErlModule(org.erlide.engine.internal.model.root.ErlModule) IErlModule(org.erlide.engine.model.root.IErlModule) IParent(org.erlide.engine.model.IParent) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 20 with IParent

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

the class ErlModel method create.

/**
 * Returns the Erlang element corresponding to the given resource, or
 * <code>null</code> if unable to associate the given resource with a Erlang element.
 * <p>
 * The resource must be one of:
 * <ul>
 * <li>a project - the element returned is the corresponding
 * <code>IErlProject</code></li>
 * <li>a <code>.erl</code> file - the element returned is the corresponding
 * <code>IErlModule</code></li>
 * <li>a folder - the element returned is the corresponding
 * <code>IErlFolder</code></li>
 * <li>the workspace root resource - the element returned is the
 * <code>IErlModel</code></li>
 * </ul>
 * <p>
 * Creating a Erlang element has the side effect of creating and opening all of the
 * element's parents if they are not yet open.
 *
 * @param resource
 *            the given resource
 * @return the Erlang element corresponding to the given resource, or
 *         <code>null</code> if unable to associate the given resource with a Erlang
 *         element
 */
@Override
public IErlElement create(final IResource resource) {
    IParent parent = null;
    final IContainer resourceParent = resource.getParent();
    if (resourceParent != null) {
        IErlElement element = findElement(resourceParent);
        if (element == null) {
            element = create(resourceParent);
        }
        if (element instanceof IParent) {
            parent = (IParent) element;
        }
    }
    return create(resource, parent);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IParent(org.erlide.engine.model.IParent) IContainer(org.eclipse.core.resources.IContainer)

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