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);
}
}
}
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;
}
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);
}
}
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();
}
Aggregations