use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class CoveragePerformer method recompileModules.
// cover compilation of chosen modules
private void recompileModules() throws CoverException {
final List<OtpErlangObject> paths = new ArrayList<>(config.getModules().size());
for (final IErlModule module : config.getModules()) {
if (module == null) {
final String msg = "No such module at given project. Check your configuration";
CoverBackend.getInstance().handleError(msg);
throw new CoverException(msg);
}
log.info(module.getFilePath());
paths.add(new OtpErlangList(module.getFilePath()));
}
try {
CoverBackend.getInstance().getBackend().getOtpRpc().call(CoverConstants.COVER_ERL_BACKEND, CoverConstants.FUN_PREP, "x", paths);
} catch (final RpcException e) {
ErlLogger.error(e);
throw new CoverException(e.getMessage());
}
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class DialyzerBuilder method build.
public void build(final BuildNotifier notifier) throws CoreException {
if (project == null) {
return;
}
DialyzerPreferences prefs = null;
prefs = DialyzerPreferences.get(project);
if (prefs == null || !prefs.getDialyzeOnCompile()) {
return;
}
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final Set<IErlModule> modules = DialyzerUtils.collectModulesFromResource(model, project);
final Set<IErlProject> projects = Sets.newHashSet();
projects.add(model.findProject(project));
DialyzerMarkerUtils.removeDialyzerMarkersFor(project);
if (!modules.isEmpty()) {
try {
final IErlProject eproject = model.findProject(project);
if (eproject == null) {
return;
}
final IBackend backend = BackendCore.getBackendManager().getBuildBackend(eproject);
DialyzerUtils.doDialyze(notifier.monitor, modules, projects, backend);
} catch (final InvocationTargetException e) {
ErlLogger.error(e);
} catch (final DialyzerErrorException e) {
ErlLogger.error(e);
final String msg = NLS.bind(BuilderMessages.build_dialyzerProblem, e.getLocalizedMessage());
DialyzerMarkerUtils.addProblemMarker(project, null, null, msg, 0, IMarker.SEVERITY_ERROR);
}
}
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class Configuration method addModule.
/**
* Add new module to cover configuration. The coverage of added module is
* going to be analized.
*
* @param name
* Erlang module name
* @throws ErlModelException
* when there is no such module in the project
* @throws CoverException
* if project is not set
*/
public void addModule(final String name) throws ErlModelException, CoverException {
if (project == null) {
throw new CoverException("no project set");
}
IErlModule module = null;
module = project.getModule(name);
modules.put(name, module);
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class DialyzerUtilsTest method dialyzeMarkerOnFile.
@Test
public void dialyzeMarkerOnFile() throws Exception {
IErlProject erlProject = null;
try {
// given
// an erlang module in an erlang project
final String projectName = "testproject";
erlProject = ErlideTestUtils.createErlProject(projectName);
final String moduleName = "test.erl";
final IErlModule erlModule = ErlideTestUtils.createModule(erlProject, moduleName, "-module(test).\n-export([f/0]).\n-f() ->\n atom_to_list(\"hej\").\n");
IMarker[] markers = erlProject.getWorkspaceProject().findMarkers(DialyzerMarkerUtils.DIALYZE_WARNING_MARKER, true, IResource.DEPTH_INFINITE);
assertEquals(0, markers.length);
// when
// putting a dialyzer warning on it
final int lineNumber = 3;
final String message = "test message";
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
DialyzerMarkerUtils.addDialyzerWarningMarker(model, erlModule.getResource().getLocation().toPortableString(), lineNumber, message);
// then
// there should be a marker with proper file name and the proper
// line number
markers = erlProject.getWorkspaceProject().findMarkers(DialyzerMarkerUtils.DIALYZE_WARNING_MARKER, true, IResource.DEPTH_INFINITE);
assertEquals(1, markers.length);
final IMarker marker = markers[0];
assertEquals(moduleName, marker.getResource().getName());
assertEquals(lineNumber, marker.getAttribute(IMarker.LINE_NUMBER));
assertEquals(message, marker.getAttribute(IMarker.MESSAGE));
} finally {
if (erlProject != null) {
ErlideTestUtils.deleteProject(erlProject);
}
}
}
use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.
the class ErlModelCacheTest method checkThatCachesAreEmptyWhenProjectIsRemoved.
@Test
public void checkThatCachesAreEmptyWhenProjectIsRemoved() throws CoreException {
IErlProject project = null;
try {
// given
// a project with a module, and some searches that fills the model
// cache
final String projectName = "testprojectx";
project = ErlideTestUtils.createErlProject(projectName);
final String moduleName = "f.erl";
final IErlModule module = ErlideTestUtils.createModule(project, moduleName, "-module(f).\n-include(\"a.hrl\").\n-export([f/0]).\n-record(rec2, {a, b}).\n" + "f() ->\n lists:reverse([1, 0]),\n lists:reverse([1, 0], [2]).\n");
module.open(null);
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule module2 = model.findModuleFromProject(project, moduleName, null, IErlElementLocator.Scope.PROJECT_ONLY);
// final ErlModelCache cache = ErlModelCache.getDefault();
// final Set<IErlModule> modulesByName2 = cache
// .getModulesByName(ListsUtils.withoutExtension(moduleName));
// when
// deleting the project
ErlideTestUtils.deleteProject(project);
// then
// the model cache shouldn't know about the module anymore
assertEquals(module2, module);
// final Set<IErlModule> modulesByName = cache
// .getModulesByName(ListsUtils.withoutExtension(moduleName));
// assertTrue(!modulesByName2.isEmpty());
// assertTrue(modulesByName.isEmpty());
} finally {
if (project != null && project.exists()) {
ErlideTestUtils.deleteProject(project);
}
}
}
Aggregations