use of org.erlide.engine.model.root.IOpenable in project erlide_eclipse by erlang.
the class ErlProject method getExternalIncludes.
@Override
public Collection<IErlModule> getExternalIncludes() throws ErlModelException {
final List<IErlModule> result = Lists.newArrayList();
accept(new IErlElementVisitor() {
@Override
public boolean visit(final IErlElement element) throws ErlModelException {
final boolean isExternalOrProject = element.getKind() == ErlElementKind.EXTERNAL_ROOT || element.getKind() == ErlElementKind.EXTERNAL_APP || element.getKind() == ErlElementKind.EXTERNAL_FOLDER || element.getKind() == ErlElementKind.PROJECT;
if (element instanceof IErlModule) {
final IErlModule module = (IErlModule) element;
if (module.getSourceKind() == SourceKind.HRL && (module.getAncestorOfKind(ErlElementKind.PROJECT) == ErlProject.this || element.getKind() == ErlElementKind.EXTERNAL_APP || element.getKind() == ErlElementKind.EXTERNAL_FOLDER)) {
result.add(module);
}
return false;
} else if (isExternalOrProject && element instanceof IOpenable) {
final IOpenable openable = (IOpenable) element;
openable.open(null);
}
return isExternalOrProject;
}
}, EnumSet.noneOf(AcceptFlags.class), ErlElementKind.MODULE);
return result;
}
use of org.erlide.engine.model.root.IOpenable in project erlide_eclipse by erlang.
the class Openable method close.
@Override
public void close() throws ErlModelException {
for (final IErlElement child : getChildren()) {
if (child instanceof IOpenable) {
final IOpenable openable = (IOpenable) child;
if (openable.isOpen()) {
openable.close();
}
}
}
internalGetChildren().clear();
setStructureKnown(false);
}
use of org.erlide.engine.model.root.IOpenable 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.root.IOpenable 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.root.IOpenable 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