use of org.erlide.engine.model.root.IErlElementLocator in project erlide_eclipse by erlang.
the class DialyzerMarkerUtils method addDialyzerWarningMarkersFromResultList.
public static void addDialyzerWarningMarkersFromResultList(final IOtpRpc backend, final OtpErlangList result) {
if (result == null || result.arity() == 0) {
return;
}
final List<String> warnings = ErlideDialyze.formatWarnings(backend, result);
for (int i = 0; i < warnings.size(); i++) {
final OtpErlangTuple t = (OtpErlangTuple) result.elementAt(i);
final OtpErlangTuple fileLine = (OtpErlangTuple) t.elementAt(1);
final String filename = Util.stringValue(fileLine.elementAt(0));
final OtpErlangLong lineL = (OtpErlangLong) fileLine.elementAt(1);
if (!filename.isEmpty()) {
int line = 1;
try {
line = lineL.intValue();
} catch (final OtpErlangRangeException e) {
ErlLogger.error(e);
}
if (line <= 0) {
line = 1;
}
String msg = warnings.get(i);
final int j = msg.indexOf(": ");
if (j != -1) {
msg = msg.substring(j + 1);
}
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
DialyzerMarkerUtils.addDialyzerWarningMarker(model, filename, line, msg);
}
}
}
use of org.erlide.engine.model.root.IErlElementLocator 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.IErlElementLocator in project erlide_eclipse by erlang.
the class DialyzerUtilsTest method dialyzeWithExternalInclude.
@Test
public void dialyzeWithExternalInclude() throws Exception {
// http://www.assembla.com/spaces/erlide/tickets/608-dialyzer---navigate-to-external-includes-from-markers
File externalFile = null;
IErlProject erlProject = null;
File externalIncludesFile = null;
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
try {
// given
// an erlang project and an external file not in any project
final String projectName = "testproject";
erlProject = ErlideTestUtils.createErlProject(projectName);
final String externalFileName = "external9.hrl";
externalFile = ErlideTestUtils.createTmpFile(externalFileName, "f([_ | _]=L) ->\n atom_to_list(L).\n");
externalIncludesFile = ErlideTestUtils.createTmpFile("external_includes", externalFile.getAbsolutePath());
DialyzerMarkerUtils.removeDialyzerMarkersFor(root);
final IProject project = erlProject.getWorkspaceProject();
if (!project.isOpen()) {
project.open(null);
}
final IPath location = new Path(externalFile.getAbsolutePath());
final IFile file = project.getFile(location.lastSegment());
file.createLink(location, IResource.NONE, null);
// when
// putting dialyzer warning markers on the external file
final String message = "test message";
final int lineNumber = 2;
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
DialyzerMarkerUtils.addDialyzerWarningMarker(model, externalFile.getAbsolutePath(), lineNumber, message);
// then
// the marker should have the proper file name and the include file
// should appear in External Files
final IMarker[] markers = root.findMarkers(DialyzerMarkerUtils.DIALYZE_WARNING_MARKER, true, IResource.DEPTH_INFINITE);
assertWithMessage("Markers count").that(markers.length).isGreaterThan(0);
for (final IMarker marker : markers) {
// for some reason, when running on Hudson, we get two identical
// markers...
final String path = (String) marker.getAttribute(DialyzerMarkerUtils.PATH_ATTRIBUTE);
final IPath p = new Path(path);
assertEquals(externalFileName, p.lastSegment());
assertWithMessage("line number").that(lineNumber).isEqualTo(marker.getAttribute(IMarker.LINE_NUMBER));
assertEquals(message, marker.getAttribute(IMarker.MESSAGE));
}
} finally {
DialyzerMarkerUtils.removeDialyzerMarkersFor(root);
if (externalIncludesFile != null && externalIncludesFile.exists()) {
externalIncludesFile.delete();
}
if (externalFile != null && externalFile.exists()) {
externalFile.delete();
}
if (erlProject != null) {
ErlideTestUtils.deleteProject(erlProject);
}
}
}
use of org.erlide.engine.model.root.IErlElementLocator 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.IErlElementLocator 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