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;
}
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;
}
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?
}
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;
}
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);
}
Aggregations