Search in sources :

Example 1 with ErlangIncludeFile

use of org.erlide.engine.model.erlang.ErlangIncludeFile 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 2 with ErlangIncludeFile

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

the class ErlModule method getIncludeFiles.

@Override
public Collection<ErlangIncludeFile> getIncludeFiles() throws ErlModelException {
    if (!isStructureKnown()) {
        open(null);
    }
    final List<ErlangIncludeFile> r = Lists.newArrayList();
    synchronized (getModelLock()) {
        for (final IErlElement m : internalGetChildren()) {
            if (m instanceof IErlAttribute) {
                final IErlAttribute a = (IErlAttribute) m;
                final OtpErlangObject v = a.getValue();
                if (v instanceof OtpErlangString) {
                    final String s = ((OtpErlangString) v).stringValue();
                    if ("include".equals(a.getName())) {
                        r.add(new ErlangIncludeFile(false, s));
                    } else if ("include_lib".equals(a.getName())) {
                        r.add(new ErlangIncludeFile(true, s));
                    }
                }
            }
        }
    }
    return r;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlangIncludeFile(org.erlide.engine.model.erlang.ErlangIncludeFile) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 3 with ErlangIncludeFile

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

the class ErlModule method getDirectDependentModules.

@Override
public Set<ISourceUnit> getDirectDependentModules() throws ErlModelException {
    final Set<ISourceUnit> result = new HashSet<>();
    final IErlProject project = modelUtilService.getProject(this);
    for (final IErlModule module : project.getModules()) {
        final boolean wasOpen = module.isOpen();
        if (!wasOpen) {
            module.open(null);
        }
        final Collection<ErlangIncludeFile> incs = module.getIncludeFiles();
        for (final ErlangIncludeFile inc : incs) {
            if (inc.getFilename().equals(getName())) {
                result.add(module);
                break;
            }
        }
        if (!wasOpen) {
            module.close();
        }
    }
    return result;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlangIncludeFile(org.erlide.engine.model.erlang.ErlangIncludeFile) ISourceUnit(org.erlide.engine.model.root.ISourceUnit) IErlModule(org.erlide.engine.model.root.IErlModule) HashSet(java.util.HashSet)

Example 4 with ErlangIncludeFile

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

the class BuilderHelper method addDependents.

public void addDependents(final IResource resource, final IProject my_project, final Set<BuildResource> result) throws ErlModelException {
    final IErlProject eprj = ErlangEngine.getInstance().getModel().findProject(my_project);
    if (eprj != null) {
        final Collection<IErlModule> ms = eprj.getModules();
        for (final IErlModule m : ms) {
            final Collection<ErlangIncludeFile> incs = m.getIncludeFiles();
            for (final ErlangIncludeFile ifile : incs) {
                if (ResourceUtil.samePath(ifile.getFilename(), resource.getName())) {
                    if (m.getSourceKind() == SourceKind.ERL) {
                        final BuildResource bres = new BuildResource(m.getResource());
                        result.add(bres);
                    }
                    break;
                }
            }
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlangIncludeFile(org.erlide.engine.model.erlang.ErlangIncludeFile) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 5 with ErlangIncludeFile

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

the class BuilderHelper method shouldCompileModule.

private boolean shouldCompileModule(final IProject project, final IResource source, final IResource beam, final boolean shouldCompile0, final IErlProject eprj) throws ErlModelException {
    boolean shouldCompile = shouldCompile0;
    final IErlModule m = eprj.getModule(source.getName());
    if (m != null) {
        final Collection<ErlangIncludeFile> incs = m.getIncludeFiles();
        for (final ErlangIncludeFile ifile : incs) {
            final IResource rifile = ResourceUtil.findResourceByName(project, ifile.getFilename());
            if (rifile != null && rifile.getLocalTimeStamp() > beam.getLocalTimeStamp()) {
                shouldCompile = true;
                break;
            }
        }
    }
    return shouldCompile;
}
Also used : ErlangIncludeFile(org.erlide.engine.model.erlang.ErlangIncludeFile) IErlModule(org.erlide.engine.model.root.IErlModule) IResource(org.eclipse.core.resources.IResource)

Aggregations

ErlangIncludeFile (org.erlide.engine.model.erlang.ErlangIncludeFile)5 IErlModule (org.erlide.engine.model.root.IErlModule)4 IErlProject (org.erlide.engine.model.root.IErlProject)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 HashSet (java.util.HashSet)1 IResource (org.eclipse.core.resources.IResource)1 IErlElement (org.erlide.engine.model.IErlElement)1 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)1 ISourceUnit (org.erlide.engine.model.root.ISourceUnit)1