use of org.erlide.engine.model.IErlElement 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.IErlElement 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.IErlElement 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);
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ModelFindUtil method getLocalIncludes.
private Collection<IErlModule> getLocalIncludes(final IErlModule module) throws ErlModelException {
final List<IErlModule> result = Lists.newArrayList();
final IParent parent = module.getParent();
for (final IErlElement child : parent.getChildrenOfKind(ErlElementKind.MODULE)) {
if (child instanceof IErlModule && SourceKind.nameToModuleKind(child.getName()) == SourceKind.HRL) {
result.add((IErlModule) child);
}
}
return result;
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ModelInternalUtils method getModuleFromExternalModulePath.
@Override
public IErlModule getModuleFromExternalModulePath(final IErlModel model, final String modulePath) throws ErlModelException {
System.out.println(">> modulePath=" + modulePath);
final List<String> path = Lists.newArrayList(Splitter.on(ModelInternalUtils.DELIMITER).split(modulePath));
model.open(null);
final IErlElement childNamed = model.getChildNamed(path.get(0));
if (childNamed instanceof IParent) {
IParent parent = (IParent) childNamed;
final int n = path.size() - 1;
for (int i = 1; ; i++) {
if (parent == null) {
break;
}
if (parent instanceof IOpenable) {
final IOpenable openable = (IOpenable) parent;
openable.open(null);
}
if (i == n) {
break;
}
parent = getElementWithExternalName(parent, path.get(i));
}
if (parent != null) {
final IErlElement child = parent.getChildNamed(path.get(n));
if (child instanceof IErlModule) {
return (IErlModule) child;
}
}
}
return null;
}
Aggregations