public IErlModule findModuleFromProject(final IErlProject project,
final String moduleName, final String modulePath,
final boolean checkExternals, final IErlElementLocator.Scope scope)
throws ErlModelException {
if (project != null) {
final IErlModule module = getModuleFromCacheByNameOrPath(
(ErlProject) project, moduleName, modulePath, scope);
if (module != null && module.isOnSourcePath()) {
return module;
}
}
final List<IErlModule> allModules = Lists.newArrayList();
final Set<String> paths = Sets.newHashSet();
try {
for (int i = 0; i < 2; ++i) {
final boolean externalModules = i > 0;
if (externalModules && !checkExternals) {
break;
}
if (project != null) {
final IErlModule module = tryFindModule(Sets.newHashSet(project),
moduleName, modulePath, allModules, paths, externalModules);
if (module != null) {
return module;
}
}
if ((scope == Scope.REFERENCED_PROJECTS || scope == Scope.ALL_PROJECTS)
&& project != null) {
final Collection<IErlProject> projects = project
.getReferencedProjects();
final IErlModule module = tryFindModule(projects, moduleName,
modulePath, allModules, paths, externalModules);
if (module != null) {
return module;
}
}
if (scope == Scope.ALL_PROJECTS) {
final Collection<IErlProject> projects = getErlangProjects();
final IErlModule module = tryFindModule(projects, moduleName,
modulePath, allModules, paths, externalModules);
if (module != null) {
return module;
}
}