Search in sources :

Example 6 with IOpenable

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;
}
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 7 with IOpenable

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

Example 8 with IOpenable

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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) IPath(org.eclipse.core.runtime.IPath) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IResource(org.eclipse.core.resources.IResource)

Example 9 with IOpenable

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

Example 10 with IOpenable

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

Aggregations

IOpenable (org.erlide.engine.model.root.IOpenable)11 IErlElement (org.erlide.engine.model.IErlElement)10 IParent (org.erlide.engine.model.IParent)8 ErlModelException (org.erlide.engine.model.ErlModelException)7 IErlModule (org.erlide.engine.model.root.IErlModule)5 IProject (org.eclipse.core.resources.IProject)2 IErlElementVisitor (org.erlide.engine.model.IErlElementVisitor)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 Stopwatch (com.google.common.base.Stopwatch)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 IErlExternalRoot (org.erlide.engine.model.root.IErlExternalRoot)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 IErlProject (org.erlide.engine.model.root.IErlProject)1