Search in sources :

Example 36 with IErlModule

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

the class ModelFindUtil method findTypespec.

@Override
public IErlTypespec findTypespec(final IErlModule module, final String name) throws CoreException {
    IErlTypespec typespec = module.findTypespec(name);
    if (typespec != null) {
        return typespec;
    }
    final Collection<IErlModule> includedFiles = findAllIncludedFiles(module);
    for (final IErlModule includedFile : includedFiles) {
        typespec = includedFile.findTypespec(name);
        if (typespec != null) {
            return typespec;
        }
    }
    return null;
}
Also used : IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 37 with IErlModule

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

the class ModelFindUtil method findAllIncludedFiles.

public Collection<IErlModule> findAllIncludedFiles(final IErlModule module, final List<IErlModule> checked) throws CoreException {
    final Collection<IErlModule> result = Sets.newHashSet();
    if (checked.contains(module)) {
        return result;
    }
    checked.add(module);
    final List<IErlModule> includedFilesForModule = ErlModelCache.getDefault().getIncludedFilesForModule(module);
    if (includedFilesForModule != null && !includedFilesForModule.isEmpty()) {
        return includedFilesForModule;
    }
    final Collection<ErlangIncludeFile> includedFiles = module.getIncludeFiles();
    final IErlProject project = modelUtilService.getProject(module);
    if (project == null) {
        return result;
    }
    final Collection<IErlModule> includes = project.getIncludes();
    includes.addAll(getLocalIncludes(module));
    Collection<IErlModule> externalIncludes = null;
    Collection<IErlModule> referencedIncludes = null;
    Collection<IErlModule> modules = null;
    for (final ErlangIncludeFile includeFile : includedFiles) {
        final String includeFileName = includeFile.getFilenameLastPart();
        if (findAllIncludedFilesAux(checked, result, includes, includeFileName)) {
            continue;
        }
        if (referencedIncludes == null) {
            referencedIncludes = Lists.newArrayList();
            final Collection<IErlProject> referencedProjects = project.getReferencedProjects();
            for (final IErlProject referencedProject : referencedProjects) {
                referencedIncludes.addAll(referencedProject.getIncludes());
            }
        }
        if (findAllIncludedFilesAux(checked, result, referencedIncludes, includeFileName)) {
            continue;
        }
        if (externalIncludes == null) {
            externalIncludes = project.getExternalIncludes();
        }
        if (findAllIncludedFilesAux(checked, result, externalIncludes, includeFileName)) {
            continue;
        }
        if (modules == null) {
            modules = project.getModules();
        }
        findAllIncludedFilesAux(checked, result, modules, includeFileName);
    }
    ErlModelCache.getDefault().putIncludedFilesForModule(module, result);
    return result;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlangIncludeFile(org.erlide.engine.model.erlang.ErlangIncludeFile) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 38 with IErlModule

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

the class ModelFindUtil method findExternalIncludeInOpenProjects.

public static IErlModule findExternalIncludeInOpenProjects(final IErlModule externalInclude) throws CoreException {
    final String filePath = externalInclude.getFilePath();
    final Collection<IErlProject> projects = ErlangEngine.getInstance().getModel().getErlangProjects();
    for (final IErlProject project : projects) {
        final Collection<IErlModule> includes = project.getIncludes();
        for (final IErlModule include : includes) {
            if (include.getFilePath().equals(filePath)) {
                return include;
            }
        }
    }
    return externalInclude;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 39 with IErlModule

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

the class ModelInternalUtils method findUnitsWithPrefix.

@Override
public List<String> findUnitsWithPrefix(final String prefix, final IErlProject project, final boolean checkExternals, final boolean includes) throws ErlModelException {
    final List<String> result = Lists.newArrayList();
    final Collection<IErlModule> units = getUnits(project, checkExternals, includes);
    addUnitNamesWithPrefix(prefix, result, units, false, includes);
    if (project != null) {
        for (final IErlProject p : project.getReferencedProjects()) {
            if (p != null) {
                p.open(null);
                addUnitNamesWithPrefix(prefix, result, getUnits(p, checkExternals, includes), false, includes);
            }
        }
        if (checkExternals) {
            final Collection<IErlModule> externalUnits = includes ? project.getExternalIncludes() : project.getExternalModules();
            addUnitNamesWithPrefix(prefix, result, externalUnits, true, includes);
        }
    }
    return result;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 40 with IErlModule

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

the class ModelInternalUtils method addUnitNamesWithPrefix.

private void addUnitNamesWithPrefix(final String prefix, final List<String> result, final Collection<IErlModule> modules, final boolean external, final boolean includes) {
    for (final IErlModule module : modules) {
        String moduleName = includes ? module.getName() : module.getModuleName();
        if (external && includes) {
            moduleName = getIncludeLibPath(module);
        }
        boolean nameMatches = moduleName.startsWith(prefix);
        if (!nameMatches && prefix.startsWith("'")) {
            nameMatches = moduleName.startsWith(prefix.substring(1));
        }
        if (nameMatches && (includes || !module.getName().endsWith(".hrl"))) {
            if (!result.contains(moduleName)) {
                final String name = new OtpErlangAtom(moduleName).toString();
                result.add(name);
            }
        }
    }
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

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