use of org.erlide.engine.model.IErlElement.AcceptFlags 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