Search in sources :

Example 1 with IErlModule

use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.

the class ParserDB method run.

private void run(final IErlModel model, final Collection<SourcePathProvider> sourcePathProviders, final boolean includeTests) throws ErlModelException {
    // we include all projects in workspace - create one for OTP too
    int normal = 0;
    int test = 0;
    final Collection<IErlProject> projects = model.getErlangProjects();
    for (final IErlProject project : projects) {
        final Collection<IErlModule> modules = project.getModulesAndIncludes();
        for (final IErlModule module : modules) {
            if (isTest(module.getResource().getLocation().toPortableString())) {
                test++;
            } else {
                normal++;
            }
            handleModule(module);
        }
        if (includeTests) {
        // final TestCodeBuilder builder = new TestCodeBuilder();
        // try {
        // final Set<BuildResource> resources = builder
        // .getAffectedResources(
        // (IProject) project.getResource(),
        // new NullProgressMonitor(), false);
        // for (final BuildResource res : resources) {
        // if (res.getResource().isLinked()
        // || res.getResource().isDerived()) {
        // System.out.println("SKIP!!!! " + res.getResource());
        // continue;
        // }
        // test++;
        // final IErlModule module = ErlModelManager
        // .getInstance().getModel().findModule(
        // (IFile) res.getResource());
        // handleModule(module);
        // }
        // } catch (final CoreException e) {
        // ErlLogger.error(e);
        // }
        }
    }
    ParserDB.out.println("--- " + normal + " " + test);
    System.out.println("--- " + normal + " " + test);
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 2 with IErlModule

use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.

the class SearchCoreUtil method addFileToScope.

static void addFileToScope(final IFile file, final ErlSearchScope result) {
    if (SourceKind.hasModuleExtension(file.getName())) {
        final IErlModule module = ErlangEngine.getInstance().getModel().findModule(file);
        result.addModule(module);
    }
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule)

Example 3 with IErlModule

use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.

the class SearchCoreUtil method getWorkspaceScope.

public static ErlSearchScope getWorkspaceScope(final boolean addExternals, final boolean addOtp) throws ErlModelException {
    final ErlSearchScope result = new ErlSearchScope();
    final Collection<IErlProject> erlangProjects = ErlangEngine.getInstance().getModel().getErlangProjects();
    for (final IErlProject i : erlangProjects) {
        final Collection<IErlModule> modules = i.getModulesAndIncludes();
        for (final IErlModule j : modules) {
            result.addModule(j);
        }
    // addProjectEbin(i, result);
    }
    final Set<String> externalModulePaths = new HashSet<>();
    for (final IErlProject project : erlangProjects) {
        SearchCoreUtil.addExternalModules(project, result, externalModulePaths, addExternals, addOtp);
    }
    return result;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) HashSet(java.util.HashSet)

Example 4 with IErlModule

use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.

the class DialyzerUtils method doDialyze.

public static void doDialyze(final IProgressMonitor monitor, final Set<IErlModule> modules, final Set<IErlProject> projects, final IBackend backend) throws InvocationTargetException, DialyzerErrorException {
    if (backend == null) {
        ErlLogger.warn("Trying to dialyze with null backend");
        return;
    }
    try {
        for (final IErlModule module : modules) {
            DialyzerMarkerUtils.removeDialyzerMarkersFor(module.getResource());
        }
        // TODO handle preferences from multiple projects
        final DialyzerPreferences prefs = DialyzerPreferences.get(null);
        final Collection<String> pltPaths = prefs.getPltPaths();
        // prefs.getFromSource();
        final boolean fromSource = false;
        // prefs.getNoCheckPLT();
        final boolean noCheckPLT = true;
        final List<String> files = Lists.newArrayList();
        final List<IPath> includeDirs = Lists.newArrayList();
        final List<String> names = Lists.newArrayList();
        DialyzerUtils.collectFilesAndIncludeDirs(modules, projects, files, names, includeDirs, fromSource);
        if (names.isEmpty()) {
            return;
        }
        final String fileNames = names.size() + " modules [" + DialyzerUtils.getFileNames(names) + "]";
        monitor.subTask(fileNames);
        ErlLogger.trace("dialyzer", "run %s", fileNames);
        final IOtpRpc b = backend.getOtpRpc();
        final RpcFuture future = ErlideDialyze.dialyze(b, files, pltPaths, includeDirs, fromSource, noCheckPLT);
        while (!future.isDone()) {
            // check cancellation
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            // check backend down
            if (!backend.isRunning()) {
                throw new BackendException("Dialyzer: backend " + backend.getName() + " is down");
            }
            OtpErlangObject r = null;
            try {
                r = future.checkedGet(500, TimeUnit.MILLISECONDS);
            } catch (final TimeoutException e) {
            } catch (final RpcTimeoutException e) {
            }
            if (r != null) {
                DialyzerUtils.processResult(b, r);
            }
        }
    } catch (final RpcException e) {
        throw new InvocationTargetException(e);
    } catch (final BackendException e) {
        throw new InvocationTargetException(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc) BackendException(org.erlide.backend.api.BackendException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) IErlModule(org.erlide.engine.model.root.IErlModule) RpcFuture(org.erlide.runtime.rpc.RpcFuture) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with IErlModule

use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.

the class DialyzerUtils method collectModulesFromResource.

public static Set<IErlModule> collectModulesFromResource(final IErlElementLocator model, final IResource resource) throws ErlModelException {
    final Set<IErlModule> result = Sets.newHashSet();
    final IErlElement element = model.findElement(resource, true);
    if (element == null) {
        return result;
    }
    if (element instanceof IErlFolder) {
        final IErlFolder folder = (IErlFolder) element;
        folder.open(null);
        result.addAll(folder.getModules());
    } else if (element instanceof IErlModule) {
        final IErlModule module = (IErlModule) element;
        result.add(module);
    } else if (element instanceof IErlProject) {
        final IErlProject project = (IErlProject) element;
        project.open(null);
        result.addAll(project.getModules());
    }
    return result;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlFolder(org.erlide.engine.model.root.IErlFolder)

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