Search in sources :

Example 11 with IErlModule

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

Example 12 with IErlModule

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

the class ErlProjectTest method findFunctionInExternalFilesTest.

@Test
public void findFunctionInExternalFilesTest() throws Exception {
    // given
    // a module with calls to the lists module
    final IErlProject project = ErlProjectTest.projects[0];
    final IErlModule moduleE = ErlideTestUtils.createModule(project, "e.erl", "-module(e).\n-export([f/0]).\nf() ->\n    lists:reverse([1, 0]),\n    lists:reverse([1, 0], [2]).\n");
    final ScannerService scanner = moduleE.getScanner();
    try {
        moduleE.open(null);
        // when
        // looking for lists:reverse/2 and lists:reverse/1
        final IErlModel model = ErlangEngine.getInstance().getModel();
        final OpenResult res = ErlangEngine.getInstance().getOpenService().open(moduleE.getScannerName(), 49, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(moduleE), project.getProperties().getExternalModules(), model.getPathVars());
        final IErlFunction function = ErlangEngine.getInstance().getModelFindService().findFunction(model, project, moduleE, res.getName(), res.getPath(), res.getFunction(), IErlElementLocator.Scope.PROJECT_ONLY);
        assertNotNull(function);
        final IErlElement module = model.findModuleFromProject(project, function.getModuleName(), res.getPath(), IErlElementLocator.Scope.PROJECT_ONLY);
        // then
        // the function should be returned and the module, in External Files
        assertNotNull(module);
        assertEquals(function.getParent(), module);
        assertEquals(ErlangEngine.getInstance().getModelUtilService().getProject(function), project);
    } finally {
        scanner.dispose();
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlElement(org.erlide.engine.model.IErlElement) IErlModel(org.erlide.engine.model.root.IErlModel) OpenResult(org.erlide.engine.services.search.OpenResult) IErlModule(org.erlide.engine.model.root.IErlModule) ScannerService(org.erlide.engine.services.parsing.ScannerService) Test(org.junit.Test)

Example 13 with IErlModule

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

the class ErlProjectTest method findIncludeFile.

@Test
public void findIncludeFile() throws Exception {
    // given
    // a project with a module and an include including file.hrl
    final IErlProject project = ErlProjectTest.projects[0];
    final String includeName = "a.hrl";
    final IErlModule include = ErlideTestUtils.createModule(project, includeName, "-include_lib(\"kernel/include/file.hrl\").\n-record(rec1, {field, another=def}).\n-define(MACRO(A), lists:reverse(A)).\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);
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    // when
    // looking for the include
    final IErlModule include1 = model.findIncludeFromModule(module, includeName, null, IErlElementLocator.Scope.PROJECT_ONLY);
    final IErlModule include2 = model.findIncludeFromProject(project, "file.hrl", null, IErlElementLocator.Scope.PROJECT_ONLY);
    // then
    // it should be found
    assertEquals(include, include1);
    assertNotNull(include2);
}
Also used : 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 14 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 15 with IErlModule

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

the class IErlElementTest method getCorrespondingResource.

// IResource getCorrespondingResource();
@Test
public void getCorrespondingResource() throws Exception {
    project.open(null);
    final IProject workspaceProject = project.getWorkspaceProject();
    final IFolder srcFolder = workspaceProject.getFolder("src");
    final IFile file = srcFolder.getFile("xx.erl");
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlModule otpFile = model.findModuleFromProject(project, "file.erl", null, IErlElementLocator.Scope.PROJECT_ONLY);
    module.open(null);
    final IErlElement element = module.getElementAtLine(3);
    assertEquals(file, module.getCorrespondingResource());
    assertNull(otpFile.getCorrespondingResource());
    assertNull(element.getCorrespondingResource());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IFile(org.eclipse.core.resources.IFile) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

IErlModule (org.erlide.engine.model.root.IErlModule)191 Test (org.junit.Test)66 IErlProject (org.erlide.engine.model.root.IErlProject)57 IErlElement (org.erlide.engine.model.IErlElement)35 IFile (org.eclipse.core.resources.IFile)26 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)26 ErlModelException (org.erlide.engine.model.ErlModelException)22 IPath (org.eclipse.core.runtime.IPath)21 ErlProject (org.erlide.engine.internal.model.root.ErlProject)21 File (java.io.File)20 IErlModel (org.erlide.engine.model.root.IErlModel)18 Path (org.eclipse.core.runtime.Path)17 IProject (org.eclipse.core.resources.IProject)16 IResource (org.eclipse.core.resources.IResource)14 ArrayList (java.util.ArrayList)13 CoreException (org.eclipse.core.runtime.CoreException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 IParent (org.erlide.engine.model.IParent)10 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)9