Search in sources :

Example 16 with ErlProject

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

the class ErlProjectTest method findExternalModule.

@Test
public void findExternalModule() throws Exception {
    File externalFile = null;
    IErlProject project = null;
    try {
        // given
        // an erlang project with an external file
        project = ErlideTestUtils.createErlProject("testproject");
        final String externalFileName = "external5.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external5).\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);
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        // when
        // looking for it
        final IErlModule externalModule = model.findModuleFromProject(project, externalFileName, null, IErlElementLocator.Scope.PROJECT_ONLY);
        // then
        // we should find it
        assertThat(externalModule).isNotNull();
        assertThat(FilePathUtils.equalFilePaths(absolutePath, externalModule.getFilePath(), EFS.getLocalFileSystem().isCaseSensitive())).isTrue();
    } 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 17 with ErlProject

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

the class IErlFolderTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    ErlModelTestBase.setUpBeforeClass();
    IErlFolderTest.project2 = ErlModelTestBase.projects[1];
    final IProject workspaceProject = IErlFolderTest.project2.getWorkspaceProject();
    final String src = "src";
    final IFolder folder = workspaceProject.getFolder(src);
    final String below = "below";
    final IFolder folder2 = folder.getFolder(below);
    ErlideTestUtils.createFolderHelper(folder2);
    final IPath belowPath = new Path(src).append(below);
    final Collection<IPath> sourceDirs = Lists.newArrayList(belowPath);
    ((ErlProject) IErlFolderTest.project2).setSourceDirs(sourceDirs);
}
Also used : 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) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) BeforeClass(org.junit.BeforeClass)

Example 18 with ErlProject

use of org.erlide.engine.internal.model.root.ErlProject 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 19 with ErlProject

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

the class ModelUtilsTest method getExternalModuleWithPrefix.

@Test
public void getExternalModuleWithPrefix() 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 = "external3.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external3).\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 via prefix
        final List<String> moduleNames0 = modelUtilService.findUnitsWithPrefix("ex", project, false, false);
        final List<String> modules1 = modelUtilService.findUnitsWithPrefix("ex", project, true, false);
        final List<String> listModules = modelUtilService.findUnitsWithPrefix("list", project, true, false);
        // then
        // we should find it iff we check externals
        assertEquals(0, moduleNames0.size());
        assertEquals(1, modules1.size());
        assertEquals(SystemConfiguration.withoutExtension(externalFileName), modules1.get(0));
        assertEquals(1, listModules.size());
        assertEquals("lists", listModules.get(0));
    } 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) File(java.io.File) Test(org.junit.Test)

Example 20 with ErlProject

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

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