Search in sources :

Example 1 with ExternalTreeEntry

use of org.erlide.engine.services.search.ExternalTreeEntry in project erlide_eclipse by erlang.

the class ErlExternalReferenceEntryList method addExternalEntries.

private void addExternalEntries(final IProgressMonitor pm, final List<ExternalTreeEntry> externalTree, final IErlModel model, final String rootName, final List<String> otherItems, final boolean includeDir) throws ErlModelException {
    final Map<IPath, IErlExternal> pathToEntryMap = Maps.newHashMap();
    pathToEntryMap.put(new Path("root"), this);
    IErlExternal parent = null;
    if (externalTree != null && !externalTree.isEmpty()) {
        for (final ExternalTreeEntry entry : externalTree) {
            final IPath path = entry.getPath();
            parent = pathToEntryMap.get(entry.getParentPath());
            if (entry.isModule()) {
                final IErlModule module = model.getModuleFromFile(parent, getNameFromPath(path), path, null);
                parent.addChild(module);
            } else {
                final String name = ErlExternalReferenceEntryList.getNameFromExternalPath(path);
                final ErlExternalReferenceEntry externalReferenceEntry = new ErlExternalReferenceEntry(parent, name, path, true, includeDir);
                pathToEntryMap.put(path, externalReferenceEntry);
                externalReferenceEntry.open(pm);
                parent.addChild(externalReferenceEntry);
            }
        }
    }
    if (otherItems != null) {
        if (parent == null) {
            parent = new ErlExternalReferenceEntry(this, rootName, new Path("." + rootName + "."), true, includeDir);
            addChild(parent);
        }
        for (final String path : otherItems) {
            IPath apath = new Path(path);
            final IErlModule module = model.getModuleFromFile(parent, getNameFromPath(apath), apath, null);
            parent.addChild(module);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IErlExternal(org.erlide.engine.model.root.IErlExternal) IPath(org.eclipse.core.runtime.IPath) IErlModule(org.erlide.engine.model.root.IErlModule) ExternalTreeEntry(org.erlide.engine.services.search.ExternalTreeEntry)

Example 2 with ExternalTreeEntry

use of org.erlide.engine.services.search.ExternalTreeEntry in project erlide_eclipse by erlang.

the class ErlExternalReferenceEntryList method buildStructure.

@Override
public boolean buildStructure(final IProgressMonitor pm) throws ErlModelException {
    // TODO some code duplication within this function
    // ErlLogger.debug("ErlExternalReferenceEntryList.buildStructure %s",
    // getName());
    final IErlProject project = ErlangEngine.getInstance().getModelUtilService().getProject(this);
    final ErlModelCache cache = ErlModelCache.getDefault();
    List<ExternalTreeEntry> externalModuleTree = cache.getExternalTree(externalModules);
    List<ExternalTreeEntry> externalIncludeTree = cache.getExternalTree(externalIncludes);
    if (externalModuleTree == null || externalIncludeTree == null) {
        final OtpErlangList pathVars = ErlangEngine.getInstance().getModel().getPathVars();
        final IOtpRpc backend = OtpRpcFactory.getOtpRpcForProject(project);
        if (externalModuleTree == null && !externalModules.isEmpty()) {
            if (pm != null) {
                pm.worked(1);
            }
            externalModuleTree = ErlangEngine.getInstance().getOpenService().getExternalModuleTree(backend, externalModules, pathVars);
        }
        if (externalIncludeTree == null && !externalIncludes.isEmpty()) {
            if (pm != null) {
                pm.worked(1);
            }
            externalIncludeTree = ErlangEngine.getInstance().getOpenService().getExternalModuleTree(backend, externalIncludes, pathVars);
        }
    }
    setChildren(null);
    final IErlModel model = ErlangEngine.getInstance().getModel();
    if (externalModuleTree != null && !externalModuleTree.isEmpty()) {
        addExternalEntries(pm, externalModuleTree, model, "modules", null, false);
        cache.putExternalTree(externalModules, project, externalModuleTree);
    }
    if (externalIncludeTree != null && !externalIncludeTree.isEmpty() || !projectIncludes.isEmpty()) {
        addExternalEntries(pm, externalIncludeTree, model, "includes", projectIncludes, true);
        if (externalIncludeTree != null) {
            cache.putExternalTree(externalIncludes, project, externalIncludeTree);
        }
    }
    return true;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) ErlModelCache(org.erlide.engine.internal.model.cache.ErlModelCache) ExternalTreeEntry(org.erlide.engine.services.search.ExternalTreeEntry) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Example 3 with ExternalTreeEntry

use of org.erlide.engine.services.search.ExternalTreeEntry in project erlide_eclipse by erlang.

the class ErlModelCache method removeProject.

public void removeProject(final IErlProject project) {
    // ErlLogger.debug("removeForProject %s", project.getName());
    final List<IErlModule> includes = projectIncludeCache.getIfPresent(project);
    if (includes != null) {
        for (final IErlModule module : includes) {
            moduleIncludeCache.invalidate(module);
        }
    }
    final List<IErlModule> modules = projectModuleCache.getIfPresent(project);
    if (modules != null) {
        for (final IErlModule module : modules) {
            moduleIncludeCache.invalidate(module);
        }
    }
    projectIncludeCache.invalidate(project);
    projectModuleCache.invalidate(project);
    final Set<String> keysToRemove = Sets.newHashSet();
    final Set<Entry<String, Pair<IErlProject, List<ExternalTreeEntry>>>> entrySet = externalTreeCache.asMap().entrySet();
    for (final Entry<String, Pair<IErlProject, List<ExternalTreeEntry>>> entry : entrySet) {
        if (entry.getValue().getKey() == project) {
            keysToRemove.add(entry.getKey());
        }
    }
    for (final String keyToRemove : keysToRemove) {
        externalTreeCache.invalidate(keyToRemove);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ExternalTreeEntry(org.erlide.engine.services.search.ExternalTreeEntry) Entry(java.util.Map.Entry) IErlModule(org.erlide.engine.model.root.IErlModule) ExternalTreeEntry(org.erlide.engine.services.search.ExternalTreeEntry) List(java.util.List) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 4 with ExternalTreeEntry

use of org.erlide.engine.services.search.ExternalTreeEntry in project erlide_eclipse by erlang.

the class ErlideOpen method getExternalModuleTree.

@Override
public List<ExternalTreeEntry> getExternalModuleTree(final IOtpRpc backend, final String externalModules, final OtpErlangList pathVars) {
    ErlLogger.debug("open:external_module_tree -> " + externalModules);
    final Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        final OtpErlangObject res = backend.call(ErlideOpen.ERLIDE_OPEN, "get_external_module_tree", "x", mkContext(externalModules, null, pathVars, null, null));
        if (Util.isOk(res)) {
            OtpErlangTuple t = (OtpErlangTuple) res;
            final OtpErlangList l = (OtpErlangList) t.elementAt(1);
            final List<ExternalTreeEntry> result = Lists.newArrayListWithCapacity(l.arity());
            for (final OtpErlangObject i : l) {
                t = (OtpErlangTuple) i;
                final String parentPath = Util.stringValue(t.elementAt(0));
                final String path = Util.stringValue(t.elementAt(1));
                final OtpErlangAtom isModuleA = (OtpErlangAtom) t.elementAt(2);
                result.add(new ExternalTreeEntry(new Path(parentPath), new Path(path), "module".equals(isModuleA.atomValue())));
            }
            final String msg = "open:external_module_tree <- " + stopwatch;
            if (stopwatch.elapsed(TimeUnit.SECONDS) > 5) {
                ErlLogger.warn("WARNING " + msg);
            } else {
                ErlLogger.debug(msg);
            }
            return result;
        }
    } catch (final RpcException e) {
        ErlLogger.warn("open:external_module_tree TIMEOUT <- " + stopwatch);
        ErlLogger.warn(e);
    }
    return Lists.newArrayList();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) Stopwatch(com.google.common.base.Stopwatch) ExternalTreeEntry(org.erlide.engine.services.search.ExternalTreeEntry) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Aggregations

ExternalTreeEntry (org.erlide.engine.services.search.ExternalTreeEntry)4 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 IErlModule (org.erlide.engine.model.root.IErlModule)2 IErlProject (org.erlide.engine.model.root.IErlProject)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 Stopwatch (com.google.common.base.Stopwatch)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1 ErlModelCache (org.erlide.engine.internal.model.cache.ErlModelCache)1 IErlExternal (org.erlide.engine.model.root.IErlExternal)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 IOtpRpc (org.erlide.runtime.rpc.IOtpRpc)1 RpcException (org.erlide.runtime.rpc.RpcException)1