Search in sources :

Example 96 with IErlProject

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

the class ModelUtilsTest method findExternalIncludeFromPath.

@Test
public void findExternalIncludeFromPath() throws Exception {
    File externalFile = null;
    IErlProject project = null;
    try {
        // given
        // an erlang project and an external file not in any project
        project = ErlideTestUtils.createErlProject("testproject");
        final String externalFileName = "external1.hrl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-define(EX, ex).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final String externalsFileName = "x.erlidex";
        final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath + "\n");
        ((ErlProject) project).setExternalIncludesFile(externalsFile.getAbsolutePath());
        project.open(null);
        System.out.println("##### " + project);
        // when
        // looking for it
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlModule module = modelFindService.findInclude(model, project, null, externalFileName, absolutePath);
        // then
        // we should find it
        assertThat(module).isNotNull();
        assertThat(externalFileName).isEqualTo(module.getName());
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
    }
}
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) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) File(java.io.File) Test(org.junit.Test)

Example 97 with IErlProject

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

the class ModelUtilsTest method getModuleFromExternalModulePath.

@Test
public void getModuleFromExternalModulePath() throws Exception {
    File externalFile = null;
    IErlProject project = null;
    try {
        // given
        // an erlang project and an external file not in any project
        project = ErlideTestUtils.createErlProject("testproject");
        final String externalFileName = "external4.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external4).\nf([_ | _]=L ->\n    atom_to_list(L).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final String externalsFileName = "x.erlidex";
        final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath);
        ((ErlProject) project).setExternalModulesFile(externalsFile.getAbsolutePath());
        project.open(null);
        // when
        // looking for it with its external module path
        final IErlModel model = ErlangEngine.getInstance().getModel();
        final IErlModule module = modelFindService.findModule(model, null, null, absolutePath, IErlElementLocator.Scope.ALL_PROJECTS);
        assertNotNull(module);
        final String externalModulePath = ErlangEngine.getInstance().getModelUtilService().getExternalModulePath(model, module);
        System.out.println(" >> %s" + externalModulePath);
        final IErlModule module2 = modelUtilService.getModuleFromExternalModulePath(model, externalModulePath);
        // then
        // we should find it
        assertNotNull(module2);
        assertEquals(externalFileName, module.getName());
        assertEquals(module, module2);
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) 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 98 with IErlProject

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

the class ModelUtilsTest method findTypespec.

@Test
public void findTypespec() throws Exception {
    // given
    // a project with a module and an include with a typespec
    final IErlProject project = ModelUtilsTest.projects[0];
    final String includeName = "a.hrl";
    final IErlModule include = ErlideTestUtils.createModule(project, includeName, "-type date() :: {pos_integer(), pos_integer(), pos_integer()}.\n");
    include.open(null);
    final IErlModule module = ErlideTestUtils.createModule(project, "f.erl", "-module(f).\n-include(\"a.hrl\").\n-export([f/0]).\n-record(rec2, {a, b}).\n" + "f() ->\n    lists:reverse([1, 0]),\n    lists:reverse([1, 0], [2]).\n");
    module.open(null);
    // when
    // looking for the typespec
    final IErlTypespec typespec = modelFindService.findTypespec(module, "date");
    // then
    // it should be found
    assertNotNull(typespec);
    assertEquals(typespec.getParent(), include);
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec) IErlModule(org.erlide.engine.model.root.IErlModule) Test(org.junit.Test)

Example 99 with IErlProject

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

the class ModelUtilsTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    ErlideTestUtils.initProjects();
    final IErlProject erlProject1 = ErlideTestUtils.createErlProject("testproject1");
    final IErlProject erlProject2 = ErlideTestUtils.createErlProject("testproject2");
    ModelUtilsTest.projects = new IErlProject[] { erlProject1, erlProject2 };
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) BeforeClass(org.junit.BeforeClass)

Example 100 with IErlProject

use of org.erlide.engine.model.root.IErlProject 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)

Aggregations

IErlProject (org.erlide.engine.model.root.IErlProject)123 IErlModule (org.erlide.engine.model.root.IErlModule)57 Test (org.junit.Test)47 IPath (org.eclipse.core.runtime.IPath)30 IProject (org.eclipse.core.resources.IProject)29 ErlProject (org.erlide.engine.internal.model.root.ErlProject)25 File (java.io.File)19 Path (org.eclipse.core.runtime.Path)16 CoreException (org.eclipse.core.runtime.CoreException)13 ErlModelException (org.erlide.engine.model.ErlModelException)13 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)13 IErlModel (org.erlide.engine.model.root.IErlModel)13 ArrayList (java.util.ArrayList)11 IErlElement (org.erlide.engine.model.IErlElement)10 IFile (org.eclipse.core.resources.IFile)9 IResource (org.eclipse.core.resources.IResource)9 HashSet (java.util.HashSet)7 IProjectDescription (org.eclipse.core.resources.IProjectDescription)7 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)6 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)6