Search in sources :

Example 1 with IErlElementVisitor

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();
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor)

Example 2 with IErlElementVisitor

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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor)

Example 3 with IErlElementVisitor

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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor)

Example 4 with IErlElementVisitor

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));
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) AcceptFlags(org.erlide.engine.model.IErlElement.AcceptFlags) IErlExternal(org.erlide.engine.model.root.IErlExternal) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor) Test(org.junit.Test)

Aggregations

IErlElement (org.erlide.engine.model.IErlElement)4 IErlElementVisitor (org.erlide.engine.model.IErlElementVisitor)4 ErlModelException (org.erlide.engine.model.ErlModelException)3 IErlModule (org.erlide.engine.model.root.IErlModule)2 IOpenable (org.erlide.engine.model.root.IOpenable)2 AcceptFlags (org.erlide.engine.model.IErlElement.AcceptFlags)1 IErlExternal (org.erlide.engine.model.root.IErlExternal)1 Test (org.junit.Test)1