Search in sources :

Example 6 with IErlModule

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());
    }
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) CoverException(org.erlide.cover.api.CoverException) RpcException(org.erlide.runtime.rpc.RpcException) ArrayList(java.util.ArrayList) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 7 with IErlModule

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);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IBackend(org.erlide.backend.api.IBackend) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) DialyzerPreferences(org.erlide.dialyzer.builder.DialyzerPreferences) InvocationTargetException(java.lang.reflect.InvocationTargetException) DialyzerErrorException(org.erlide.dialyzer.builder.DialyzerUtils.DialyzerErrorException)

Example 8 with IErlModule

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);
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule)

Example 9 with IErlModule

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);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IMarker(org.eclipse.core.resources.IMarker) Test(org.junit.Test)

Example 10 with IErlModule

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);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) Test(org.junit.Test)

Aggregations

IErlModule (org.erlide.engine.model.root.IErlModule)191 Test (org.junit.Test)66 IErlProject (org.erlide.engine.model.root.IErlProject)57 IErlElement (org.erlide.engine.model.IErlElement)35 IFile (org.eclipse.core.resources.IFile)26 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)26 ErlModelException (org.erlide.engine.model.ErlModelException)22 IPath (org.eclipse.core.runtime.IPath)21 ErlProject (org.erlide.engine.internal.model.root.ErlProject)21 File (java.io.File)20 IErlModel (org.erlide.engine.model.root.IErlModel)18 Path (org.eclipse.core.runtime.Path)17 IProject (org.eclipse.core.resources.IProject)16 IResource (org.eclipse.core.resources.IResource)14 ArrayList (java.util.ArrayList)13 CoreException (org.eclipse.core.runtime.CoreException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 IParent (org.erlide.engine.model.IParent)10 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)9