Search in sources :

Example 6 with IErlElementLocator

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

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

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

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

Example 10 with IErlElementLocator

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

the class ErlangElementImageProvider method computeDescriptor.

private ImageDescriptor computeDescriptor(final Object element, final int flags) {
    if (element instanceof IErlElement) {
        return ErlangElementImageProvider.getErlImageDescriptor((IErlElement) element, flags);
    } else if (element instanceof IFile) {
        final IFile file = (IFile) element;
        if ("erl".equals(file.getFileExtension())) {
            // $NON-NLS-1$
            return getErlResourceImageDescriptor(file, flags);
        // image for a CU not on the build path
        }
        return getWorkbenchImageDescriptor(file, flags);
    } else if (element instanceof IFolder) {
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        final IErlFolder ef = (IErlFolder) model.findElement((IResource) element);
        if (ef != null && (ef.isOnSourcePath() || ef.isOnIncludePath())) {
            return ErlangElementImageProvider.getErlImageDescriptor(ef, flags);
        }
    } else if (element instanceof IAdaptable) {
        return getWorkbenchImageDescriptor((IAdaptable) element, flags);
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) IErlFolder(org.erlide.engine.model.root.IErlFolder) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)33 IErlModule (org.erlide.engine.model.root.IErlModule)26 Test (org.junit.Test)17 IErlProject (org.erlide.engine.model.root.IErlProject)13 ErlProject (org.erlide.engine.internal.model.root.ErlProject)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)7 IErlElement (org.erlide.engine.model.IErlElement)6 IProject (org.eclipse.core.resources.IProject)5 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 IFolder (org.eclipse.core.resources.IFolder)3 CoreException (org.eclipse.core.runtime.CoreException)3 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)3 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)2 ArrayList (java.util.ArrayList)2 IMarker (org.eclipse.core.resources.IMarker)2 IResource (org.eclipse.core.resources.IResource)2