Search in sources :

Example 21 with ErlProject

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

the class IErlProjectTest method getExternalIncludes.

// Collection<IErlModule> getExternalIncludes() throws ErlModelException;
// void setExternalIncludesFile(String absolutePath)
// throws BackingStoreException;
@Test
public void getExternalIncludes() throws Exception {
    File externalFile = null;
    File externalsFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final String externalIncludesString = aProject.getProperties().getExternalIncludes();
    try {
        // given
        // an erlang project and an external file not in any project
        final String externalFileName = "external.hrl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-define(E, hej).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final String externalsFileName = IErlProjectTest.XX_ERLIDEX;
        externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath);
        aProject.open(null);
        final Collection<IErlModule> otpIncludes = aProject.getExternalIncludes();
        ((ErlProject) aProject).setExternalIncludesFile(externalsFile.getAbsolutePath());
        aProject.open(null);
        // when
        // fetching all external includes
        final Collection<IErlModule> externalIncludes = aProject.getExternalIncludes();
        // then
        // the external file should be returned
        final Set<IErlModule> otpSet = Sets.newHashSet(otpIncludes);
        final Set<IErlModule> externalSet = Sets.newHashSet(externalIncludes);
        final Set<IErlModule> difference = Sets.difference(externalSet, otpSet);
        assertEquals(1, difference.size());
        final IErlModule externalInclude = difference.iterator().next();
        assertNotNull(externalInclude);
        assertEquals(absolutePath, externalInclude.getFilePath());
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        if (externalsFile != null && externalsFile.exists()) {
            externalsFile.delete();
        }
        ((ErlProject) aProject).setExternalIncludesFile(externalIncludesString);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) File(java.io.File) Test(org.junit.Test)

Example 22 with ErlProject

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

the class ErlProjectTest method findExternalIncludeFileOnIncludePath.

@Test
public void findExternalIncludeFileOnIncludePath() throws Exception {
    File externalInclude = null;
    IErlProject project = null;
    // a project with an include dir outside the model
    try {
        final String projectName = "testprojectx";
        project = ErlideTestUtils.createErlProject(projectName);
        final String includeName = "x.hrl";
        externalInclude = ErlideTestUtils.createTmpFile(includeName, "-record(rec2, {field, another=def}.");
        final String includePath = externalInclude.getAbsolutePath();
        final IPath p = new Path(includePath).removeLastSegments(1);
        ((ErlProject) project).setIncludeDirs(Lists.newArrayList(p));
        // when
        // looking for the include file
        // String includeFile =
        // ErlangEngine.getInstance().getModelUtilService().findIncludeFile(erlProject,
        // "x.hrl", "");
        project.open(null);
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlModule module = model.findIncludeFromProject(project, null, includePath, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final IErlModule module2 = model.findModuleFromProject(project, includeName, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        // then
        // it should be found in the model
        assertNotNull(module);
        assertEquals(module, module2);
    } finally {
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
        if (externalInclude != null && externalInclude.exists()) {
            externalInclude.delete();
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) File(java.io.File) Test(org.junit.Test)

Example 23 with ErlProject

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

the class ErlProjectTest method findIncludeFileOnIncludePathInOtherProject.

@Test
public void findIncludeFileOnIncludePathInOtherProject() throws Exception {
    // http://www.assembla.com/spaces/erlide/tickets/756-navigation--external-include-files-are-not-found
    IErlModule externalInclude = null;
    IErlProject project = null;
    IErlProject project2 = null;
    // a project with an include dir outside the model
    try {
        final String projectName = "testprojectx";
        project = ErlideTestUtils.createErlProject(projectName);
        final String projectName2 = "testprojecty";
        project2 = ErlideTestUtils.createErlProject(projectName2);
        final String includeName = "x.hrl";
        externalInclude = ErlideTestUtils.createInclude(project2, "x.hrl", "-record(rec2, {field, another=def}.");
        final String includePath = externalInclude.getFilePath();
        final IPath p = new Path(includePath).removeLastSegments(1);
        ((ErlProject) project).setIncludeDirs(Lists.newArrayList(p));
        // when
        // looking for the include file
        project.open(null);
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlModule module = model.findIncludeFromProject(project, includeName, null, IErlElementLocator.Scope.ALL_PROJECTS);
        // then
        // it should be found in the project defining it
        assertNotNull(module);
        assertEquals(project2, ErlangEngine.getInstance().getModelUtilService().getProject(module));
    } finally {
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
        if (project2 != null) {
            ErlideTestUtils.deleteProject(project2);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) 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)

Example 24 with ErlProject

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

the class IErlModelTest method findIncludeFromProject.

// IErlModule findIncludeFromProject(IErlProject project, String
// includeName, String includePath, Scope scope) throws ErlModelException;
@Test
public void findIncludeFromProject() throws Exception {
    File externalIncludeFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final IProject workspaceProject = aProject.getWorkspaceProject();
    final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
    final Collection<IPath> includeDirs = aProject.getProperties().getIncludeDirs();
    // referenced project with an include
    try {
        final String xxHrl = "xx.hrl";
        externalIncludeFile = ErlideTestUtils.createTmpFile(xxHrl, "-record(rec2, {field, another=def}.");
        final String externalIncludePath = externalIncludeFile.getAbsolutePath();
        final IPath p = new Path(externalIncludePath).removeLastSegments(1);
        final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
        newIncludeDirs.add(p);
        ((ErlProject) aProject).setIncludeDirs(newIncludeDirs);
        final IErlModule include = ErlideTestUtils.createInclude(aProject, "yy.hrl", "-define(Y, include).\n");
        final IErlProject project1 = ErlModelTestBase.projects[1];
        final IErlModule referencedInclude = ErlideTestUtils.createInclude(project1, "zz.hrl", "-define(Z, referenced).\n");
        aProject.open(null);
        // when
        // looking for includes
        final String xx = "xx";
        final IErlModule x1 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule x2 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule x3 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String yy = "yy";
        final IErlModule y1 = model.findIncludeFromProject(aProject, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule y2 = model.findIncludeFromProject(aProject, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule y3 = model.findIncludeFromProject(aProject, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final IErlModule y4 = model.findIncludeFromProject(project1, yy, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule y5 = model.findIncludeFromProject(project1, yy, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule y6 = model.findIncludeFromProject(project1, yy, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final String zz = "zz";
        final IErlModule z1 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule z2 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule z3 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
        workspaceProject.setDescription(description, null);
        aProject.open(null);
        final IErlModule z4 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule z5 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule z6 = model.findIncludeFromProject(aProject, zz, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        // then
        // scope should be respected
        assertNotNull(x1);
        assertEquals(xxHrl, x1.getName());
        assertNotNull(x2);
        assertEquals(xxHrl, x2.getName());
        assertNotNull(x3);
        assertEquals(xxHrl, x3.getName());
        assertEquals(include, y1);
        assertEquals(include, y2);
        assertEquals(include, y3);
        assertNull(y4);
        assertEquals(include, y5);
        assertNull(y6);
        assertNull(z1);
        assertEquals(referencedInclude, z2);
        assertNull(z3);
        assertNull(z4);
        assertEquals(referencedInclude, z5);
        assertEquals(referencedInclude, z6);
    } finally {
        if (externalIncludeFile != null && externalIncludeFile.exists()) {
            externalIncludeFile.delete();
        }
        ((ErlProject) aProject).setIncludeDirs(includeDirs);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(referencedProjects);
        workspaceProject.setDescription(description, null);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 25 with ErlProject

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

the class IErlModelTest method findInclude_preferProjectFile.

@Test
public void findInclude_preferProjectFile() throws Exception {
    File externalIncludeFile = null;
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final IProject workspaceProject = aProject.getWorkspaceProject();
    final IProject[] referencedProjects = workspaceProject.getReferencedProjects();
    final Collection<IPath> includeDirs = aProject.getProperties().getIncludeDirs();
    // referenced project with an include, both have same name
    try {
        final String xxHrl = "xx.hrl";
        externalIncludeFile = ErlideTestUtils.createTmpFile(xxHrl, "-record(rec2, {field, another=def}.");
        final String externalIncludePath = externalIncludeFile.getAbsolutePath();
        final IPath p = new Path(externalIncludePath).removeLastSegments(1);
        final List<IPath> newIncludeDirs = Lists.newArrayList(includeDirs);
        newIncludeDirs.add(p);
        ((ErlProject) aProject).setIncludeDirs(newIncludeDirs);
        final IErlProject project1 = ErlModelTestBase.projects[1];
        final IErlModule referencedInclude = ErlideTestUtils.createInclude(project1, xxHrl, "-define(Z, referenced).\n");
        aProject.open(null);
        // when
        // looking for includes
        final String xx = "xx";
        final IErlModule x1 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule x2 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule x3 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(new IProject[] { project1.getWorkspaceProject() });
        workspaceProject.setDescription(description, null);
        aProject.open(null);
        final IErlModule x4 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.PROJECT_ONLY);
        final IErlModule x5 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.ALL_PROJECTS);
        final IErlModule x6 = model.findIncludeFromProject(aProject, xx, null, IErlElementLocator.Scope.REFERENCED_PROJECTS);
        // then
        // the non-external should be preferred
        assertNotNull(x1);
        assertEquals(xxHrl, x1.getName());
        assertNotSame(referencedInclude, x1);
        assertEquals(referencedInclude, x2);
        assertNotNull(x3);
        assertEquals(xxHrl, x3.getName());
        assertNotSame(referencedInclude, x3);
        assertNotNull(x4);
        assertNotSame(referencedInclude, x4);
        assertEquals(referencedInclude, x5);
        assertEquals(referencedInclude, x6);
    } finally {
        if (externalIncludeFile != null && externalIncludeFile.exists()) {
            externalIncludeFile.delete();
        }
        ((ErlProject) aProject).setIncludeDirs(includeDirs);
        final IProjectDescription description = workspaceProject.getDescription();
        description.setReferencedProjects(referencedProjects);
        workspaceProject.setDescription(description, null);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

ErlProject (org.erlide.engine.internal.model.root.ErlProject)28 IErlProject (org.erlide.engine.model.root.IErlProject)27 Test (org.junit.Test)25 IErlModule (org.erlide.engine.model.root.IErlModule)21 File (java.io.File)18 IPath (org.eclipse.core.runtime.IPath)12 Path (org.eclipse.core.runtime.Path)12 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)8 IProject (org.eclipse.core.resources.IProject)6 IFile (org.eclipse.core.resources.IFile)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)2 IFolder (org.eclipse.core.resources.IFolder)1 ErlModelCache (org.erlide.engine.internal.model.cache.ErlModelCache)1 ErlangProjectProperties (org.erlide.engine.model.root.ErlangProjectProperties)1 IErlExternal (org.erlide.engine.model.root.IErlExternal)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1