Search in sources :

Example 11 with ErlProject

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

the class ModelUtilsTest method findExternalModuleFromPath.

@Test
public void findExternalModuleFromPath() 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 = "external2.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external2).\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
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlModule module = modelFindService.findModule(model, null, null, absolutePath, IErlElementLocator.Scope.ALL_PROJECTS);
        // 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 12 with ErlProject

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

the class ModelUtilsTest method findPreprocessorDefExternalIncludePathTest.

@Test
public void findPreprocessorDefExternalIncludePathTest() throws Exception {
    File externalInclude = null;
    IErlProject project = null;
    // contains a record def
    try {
        final String projectName = "testprojectx";
        project = ErlideTestUtils.createErlProject(projectName);
        final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-include(\"y.hrl\").\n");
        final String includeName = "y.hrl";
        externalInclude = ErlideTestUtils.createTmpFile(includeName, "-record(rec2, {field, another=def}.");
        final String includePath = externalInclude.getAbsolutePath();
        final String externalsFileName = "x.erlidex";
        final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, includePath);
        ((ErlProject) project).setExternalIncludesFile(externalsFile.getAbsolutePath());
        project.open(null);
        // when
        // looking for the record def
        final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "rec2", ErlElementKind.RECORD_DEF);
        final Collection<IErlProject> myprojects = Lists.newArrayList(project);
        modelFindService.findPreprocessorDef(myprojects, "a.erl", "rec2", ErlElementKind.RECORD_DEF);
        // then
        // it should be found
        assertNotNull(preprocessorDef);
    } finally {
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
        if (externalInclude != null && externalInclude.exists()) {
            externalInclude.delete();
        }
    }
}
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) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Test(org.junit.Test)

Example 13 with ErlProject

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

the class ModelUtilsTest method findPreprocessorDefExternalIncludeOnIncludePathTest.

@Test
public void findPreprocessorDefExternalIncludeOnIncludePathTest() throws Exception {
    File externalInclude = null;
    IErlProject project = null;
    // given
    // a project with an include dir outside the model, the include file
    // contains a record def
    final String projectName = "testprojectx";
    try {
        // ErlModelCache.getDefault().setNoModelCache(true);
        // ErlModelCache.getDefault().clearModelCache();
        project = ErlideTestUtils.createErlProject(projectName);
        final IErlModule module = ErlideTestUtils.createModule(project, "a.erl", "-include(\"z.hrl\").\n");
        final String includeName = "z.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));
        project.open(null);
        // when
        // looking for the record def
        final IErlPreprocessorDef preprocessorDef = modelFindService.findPreprocessorDef(module, "rec2", ErlElementKind.RECORD_DEF);
        final Collection<IErlProject> myprojects = Lists.newArrayList(project);
        ErlangEngine.getInstance().getModelFindService().findPreprocessorDef(myprojects, "a.erl", "rec2", ErlElementKind.RECORD_DEF);
        // then
        // it should be found
        assertNotNull(preprocessorDef);
    } finally {
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
        if (externalInclude != null && externalInclude.exists()) {
            externalInclude.delete();
        }
        new File(ErlideTestUtils.getTmpPath(projectName).removeLastSegments(1).toPortableString()).delete();
    // ErlModelCache.getDefault().setNoModelCache(false);
    }
}
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) File(java.io.File) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) Test(org.junit.Test)

Example 14 with ErlProject

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

the class IErlProjectTest method getModule.

// IErlModule getModule(String name) throws ErlModelException;
@Test
public void getModule() throws Exception {
    final IErlProject aProject = ErlModelTestBase.projects[0];
    final Collection<IPath> sourceDirs = aProject.getProperties().getSourceDirs();
    try {
        // given
        // an Erlang project and a module
        final IErlModule aModule = ErlideTestUtils.createModule(aProject, "aa.erl", "-module(aa).\n");
        final IPath srcxPath = new Path("srcx");
        final List<IPath> srcxDirs = Lists.newArrayList(srcxPath);
        aProject.open(null);
        // when
        // setting source dirs so the module is on source path
        final IErlModule module2 = aProject.getModule("aa");
        final IErlModule nullModule = aProject.getModule("aa.hrl");
        final IErlModule nullModule2 = aProject.getModule("AA");
        final IErlModule nullModule3 = aProject.getModule("aA");
        final IErlModule nullModule4 = aProject.getModule("AA.erl");
        final IErlModule module4 = aProject.getModule("aa.erl");
        ((ErlProject) aProject).setSourceDirs(srcxDirs);
        aProject.open(null);
        final IErlModule srcxModule = aProject.getModule("aa");
        ((ErlProject) aProject).setSourceDirs(sourceDirs);
        aProject.open(null);
        final IErlModule module3 = aProject.getModule("aa");
        // then
        // the it should be returned, but not otherwise
        assertEquals(aModule, module2);
        assertNull(srcxModule);
        assertNull(nullModule);
        assertNull(nullModule2);
        assertNull(nullModule3);
        assertNull(nullModule4);
        assertEquals(aModule, module3);
        assertEquals(aModule, module4);
    } finally {
        ((ErlProject) aProject).setSourceDirs(sourceDirs);
    }
}
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) Test(org.junit.Test)

Example 15 with ErlProject

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

the class ErlModelCacheTest method checkThatNewModulesInNewProjectsAreCorrect.

@Test
public void checkThatNewModulesInNewProjectsAreCorrect() throws Exception {
    IErlProject project = null;
    IErlProject project2 = null;
    try {
        // given
        // a project with an external module and searching for it so the
        // cache
        // is updated
        final String projectName = "testprojecta";
        project = ErlideTestUtils.createErlProject(projectName);
        final String externalName = "xyz.erl";
        final File externalFile = ErlideTestUtils.createTmpFile(externalName, "-module(xyz).\nf([_ | _]=L ->\n    atom_to_list(L).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final File externalsFile = ErlideTestUtils.createTmpFile("x.erlidex", absolutePath);
        ((ErlProject) project).setExternalModulesFile(externalsFile.getAbsolutePath());
        project.open(null);
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlModule findModule = model.findModuleFromProject(project, externalName, null, IErlElementLocator.Scope.PROJECT_ONLY);
        // final ErlModelCache cache = ErlModelCache.getDefault();
        // final Set<IErlModule> modulesByName = cache
        // .getModulesByName(ListsUtils
        // .withoutExtension(externalName));
        // when
        // creating a new project with a module with the same name and
        // searching
        // for it
        final String projectName2 = "testprojectb";
        project2 = ErlideTestUtils.createErlProject(projectName2);
        final IErlModule module = ErlideTestUtils.createModule(project2, externalName, "-module(xyz).\n");
        final IErlModule findModule2 = model.findModuleFromProject(project, externalName, null, IErlElementLocator.Scope.ALL_PROJECTS);
        // final Set<IErlModule> modulesByName2 = cache
        // .getModulesByName(ListsUtils
        // .withoutExtension(externalName));
        // then
        // the new module should be found
        assertNotNull(findModule);
        assertEquals(module, findModule2);
    // assertTrue(modulesByName2.contains(module));
    // final SetView<IErlModule> difference = Sets.difference(
    // modulesByName2, modulesByName);
    // assertEquals(1, difference.size());
    // assertEquals(module, difference.toArray()[0]);
    } finally {
        if (project != null && project.exists()) {
            ErlideTestUtils.deleteProject(project);
        }
        if (project2 != null && project2.exists()) {
            ErlideTestUtils.deleteProject(project2);
        }
    }
}
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)

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