use of org.erlide.engine.model.IErlElementVisitor in project erlide_eclipse by erlang.
the class ErlProject method dispose.
@Override
public void dispose() {
removeConfigurationChangeListeners();
clearCaches();
try {
accept(new IErlElementVisitor() {
@Override
public boolean visit(final IErlElement element) throws ErlModelException {
element.dispose();
return false;
}
}, EnumSet.of(AcceptFlags.CHILDREN_FIRST, AcceptFlags.LEAFS_ONLY), ErlElementKind.MODULE);
} catch (final ErlModelException e) {
}
super.dispose();
}
use of org.erlide.engine.model.IErlElementVisitor in project erlide_eclipse by erlang.
the class ErlProject method getExternalModules.
@Override
public Collection<IErlModule> getExternalModules() 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.getAncestorOfKind(ErlElementKind.PROJECT) == ErlProject.this) {
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.IErlElementVisitor 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.IErlElementVisitor in project erlide_eclipse by erlang.
the class IErlElementTest method accept.
// void accept(IErlElementVisitor visitor, EnumSet<AcceptFlags> flags,
// IErlElement.Kind leafKind) throws ErlModelException;
@Test
public void accept() throws Exception {
project.open(null);
// ErlLogger.debug(project.getChildren().toString());
module.open(null);
final List<IErlElement> elements = Lists.newArrayList();
final IErlElementVisitor visitor = new IErlElementVisitor() {
@Override
public boolean visit(final IErlElement element) throws ErlModelException {
if (element instanceof IErlExternal) {
// avoid digging through otp
return false;
}
final String name = element.getName();
if ("ebin".equals(name)) {
// avoid possible beam-files
return false;
} else if (name.startsWith(".")) {
// avoid eclipse internals
return false;
}
elements.add(element);
return true;
}
};
final EnumSet<AcceptFlags> noneOf = EnumSet.noneOf(AcceptFlags.class);
project.accept(visitor, noneOf, ErlElementKind.MODULE);
final List<IErlElement> kindModuleElementsVisited = Lists.newArrayList(elements);
elements.clear();
project.accept(visitor, noneOf, ErlElementKind.FUNCTION);
final List<IErlElement> kindFunctionElementsVisited = Lists.newArrayList(elements);
elements.clear();
project.accept(visitor, EnumSet.of(AcceptFlags.CHILDREN_FIRST), ErlElementKind.MODULE);
final List<IErlElement> childrenFirst = Lists.newArrayList(elements);
elements.clear();
project.accept(visitor, EnumSet.of(AcceptFlags.LEAFS_ONLY), ErlElementKind.MODULE);
final List<IErlElement> leafsOnly = Lists.newArrayList(elements);
elements.clear();
// assertEquals(4, kindModuleElementsVisited.size());
assertEquals(project, kindModuleElementsVisited.get(0));
// ErlLogger.debug(kindModuleElementsVisited.toString());
assertEquals("include", kindModuleElementsVisited.get(1).getName());
assertEquals("src", kindModuleElementsVisited.get(2).getName());
assertEquals(module, kindModuleElementsVisited.get(3));
assertEquals(7, kindFunctionElementsVisited.size());
final int projectIndex = childrenFirst.indexOf(project);
final int moduleIndex = childrenFirst.indexOf(module);
assertTrue(moduleIndex < projectIndex);
assertFalse(leafsOnly.contains(project));
assertTrue(leafsOnly.contains(module));
}
Aggregations