Search in sources :

Example 31 with IErlModule

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

the class ErlModel method tryFindModule.

private IErlModule tryFindModule(final Collection<IErlProject> projects, final String moduleName, final String modulePath, final List<IErlModule> allModules, final Set<String> paths, final boolean externalModules) throws ErlModelException {
    IErlModule module;
    for (final IErlProject project : projects) {
        final Collection<IErlModule> modules = Lists.newArrayList();
        final Collection<IErlModule> modulesOrExternals = externalModules ? project.getExternalModules() : project.getModules();
        ErlModel.getAllModulesAux(modulesOrExternals, modules, paths);
        allModules.addAll(modules);
        module = findModule(modules, moduleName, modulePath);
        if (module != null) {
            return module;
        }
    }
    return null;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 32 with IErlModule

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

the class ErlModel method findIncludeFromModule.

@Override
public IErlModule findIncludeFromModule(final IErlModule module, final String includeName, final String includePath, final IErlElementLocator.Scope scope) throws ErlModelException {
    final IParent parent = module.getParent();
    if (parent instanceof IErlFolder) {
        final IErlFolder folder = (IErlFolder) parent;
        folder.open(null);
        final IErlModule include = folder.findInclude(includeName, includePath);
        if (include != null) {
            return include;
        }
    }
    return findIncludeFromProject(ErlangEngine.getInstance().getModelUtilService().getProject(module), includeName, includePath, true, scope);
}
Also used : IParent(org.erlide.engine.model.IParent) IErlFolder(org.erlide.engine.model.root.IErlFolder) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 33 with IErlModule

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

the class ErlModel method findFunction.

@Override
public IErlFunction findFunction(final FunctionRef r) throws ErlModelException {
    final IErlModule module = findModule(r.module);
    if (module == null) {
        return null;
    }
    module.open(null);
    return module.findFunction(new ErlangFunction(r.function, r.arity));
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction)

Example 34 with IErlModule

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

the class ErlModel method findIncludeFromProject.

private IErlModule findIncludeFromProject(final IErlProject project, final String includeName, final String includePath, final boolean checkExternals, final IErlElementLocator.Scope scope) throws ErlModelException {
    if (project != null) {
        final IErlModule module = ErlModel.getModuleFromCacheByNameOrPath((ErlProject) project, includeName, includePath, scope);
        if (module != null && module.isOnIncludePath()) {
            return module;
        }
    }
    final Collection<IErlModule> includes = getAllIncludes(project, checkExternals, scope);
    ErlModelCache.getDefault().putModules(includes);
    if (includePath != null) {
        for (final IErlModule module2 : includes) {
            final String path2 = module2.getFilePath();
            if (path2 != null && includePath.equals(path2)) {
                return module2;
            }
        }
    }
    if (includeName != null) {
        final boolean hasExtension = SystemConfiguration.hasExtension(includeName);
        for (final IErlModule module2 : includes) {
            final String name = hasExtension ? module2.getName() : module2.getModuleName();
            if (ResourceUtil.samePath(includeName, name)) {
                return module2;
            }
        }
    }
    return null;
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 35 with IErlModule

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

the class ModelFindUtil method findPreprocessorDef.

@Override
public IErlPreprocessorDef findPreprocessorDef(final IErlModule module, final String definedName, final ErlElementKind kind) throws CoreException {
    String unquoted = StringUtils.unquote(definedName);
    final String quoted = StringUtils.quote(definedName);
    final Set<String> names = new HashSet<>(3);
    if (kind == ErlElementKind.RECORD_DEF) {
        while (names.add(unquoted)) {
            unquoted = resolveMacroValue(unquoted, module);
        }
    } else {
        names.add(unquoted);
    }
    names.add(quoted);
    names.add(definedName);
    final List<IErlModule> allIncludedFiles = Lists.newArrayList(findAllIncludedFiles(module));
    allIncludedFiles.add(0, module);
    for (final IErlModule includedFile : allIncludedFiles) {
        for (final String name : names) {
            includedFile.open(null);
            final IErlPreprocessorDef preprocessorDef = includedFile.findPreprocessorDef(name, kind);
            if (preprocessorDef != null) {
                return preprocessorDef;
            }
        }
    }
    return null;
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) HashSet(java.util.HashSet)

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